feat: more built in safe area utilities#280
Conversation
📝 WalkthroughWalkthroughThe changes expand the safe-area insets system by introducing comprehensive directional CSS utilities (top-safe, bottom-safe, left-safe, right-safe and variants for safe-or-* and safe-offset-*), refactoring the underlying TypeScript generation logic to support these multiple safe-area modes, and adding test coverage for the new inset-safe-offset functionality. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
packages/uniwind/src/css/insets.ts (2)
57-83: String manipulation ingetStylesForSafeAreaTypeis fragile.The regex replacement assumes a specific format
": env(...)"and only replaces the first occurrence due toreplace()without thegflag. This works correctly for single-property styles but could behave unexpectedly if the style format changes.The use of
replace(';', '')on line 63/72 also only removes the first semicolon, which is fine for single declarations but worth noting for future maintenance.Overall, the logic is correct for the current use case.
93-99: Double blank lines between utilities.Lines 97-98 add two empty strings, resulting in double blank lines between each utility block. This is likely intentional for readability in the generated CSS, but verify this matches the existing format in
uniwind.css.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
packages/uniwind/src/css/insets.tspackages/uniwind/tests/styles-parsing/safe-area.test.tsxpackages/uniwind/uniwind.css
🔇 Additional comments (10)
packages/uniwind/src/css/insets.ts (4)
1-10: Clean type definitions.The use of
as constarrays with derived types ensures type safety and exhaustiveness checking. TheInsettype correctly represents the four CSS inset directions.
17-37: Good exhaustiveness check withsatisfies never.The switch statement properly covers all
Sidecases and uses TypeScript'ssatisfies neverpattern to ensure compile-time exhaustiveness. Returning an empty array in the default branch is a safe fallback.
39-47: Potential naming inconsistency forinsettype withinsetside.When
typeName === 'inset'andside === 'inset', the utility name becomesinset-safe(etc.), which is correct. However, whentypeName !== 'inset'andside === 'inset', thesideSuffixbecomesundefineddue to'inset'.at(0)returning'i', not empty string as intended.Wait, let me re-check: Line 44 checks
side === 'inset'and setssideSuffix = '', which is correct. The logic appears sound for generating names likem-safe,p-safe,mx-safe,mt-safe, etc.
85-102: Generation loop correctly produces all utility combinations.The nested iteration over
types,sides, andsafeAreaTypesgenerates all required CSS utilities. The composition usinggetStylesForSafeAreaTypeproperly transforms the base styles for each safe-area variant.packages/uniwind/tests/styles-parsing/safe-area.test.tsx (2)
13-13: Good test coverage for the newinset-safe-offset-*utility.The test validates that arbitrary length values (
[10px]) work correctly with the new inset safe area offset utilities, covering all four directional properties.
23-26: No action needed. The test expectations are correct. TheSAFE_AREA_INSET_LEFTandSAFE_AREA_INSET_RIGHTconstants do not exist; the test setup explicitly configures left and right insets as0while using theSAFE_AREA_INSET_TOPandSAFE_AREA_INSET_BOTTOMconstants for vertical insets. The asymmetry in the assertions reflects this intentional design.Likely an incorrect or invalid review comment.
packages/uniwind/uniwind.css (4)
256-283: Newinset-safeutilities correctly implement the requested feature.The utilities properly set all four positioning properties (
top,bottom,left,right) usingenv(safe-area-inset-*). The-or-*and-offset-*variants correctly usemax()andcalc()respectively, supporting both integer spacing and arbitrary length values.This directly addresses issue #246's request for safe-area inset classNames.
285-321: Axis utilities (x-safe,y-safe) provide convenient shorthand.These utilities complement the directional utilities by allowing developers to apply safe area insets to horizontal (
left/right) or vertical (top/bottom) axes simultaneously.
323-377: Directional utilities (top-safe,bottom-safe,left-safe,right-safe) fulfill the issue request.These utilities directly implement the classNames requested in issue #246, providing granular control over individual safe area inset directions with all three safe-area type variants.
379-380: Minor formatting change on dark variant.The dark variant declaration now has a preceding blank line (line 378 is new). This is a minor formatting adjustment that improves visual separation.
closes #246
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.