feat: layout direction component#577
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds a subtree-scoped LayoutDirection component that sets nullable UniwindContext.rtl, threads that context into web/native style resolution and cache keys, updates ScopedTheme to merge context, and adds tests, entry re-exports, and docs for scoped RTL/LTR behavior. ChangesScoped Layout Direction Support
Sequence Diagram(s)sequenceDiagram
participant LayoutDirection
participant UniwindContextProvider
participant getWebStyles
participant NativeStyleStore
LayoutDirection->>UniwindContextProvider: provide { rtl: true|false|null }
UniwindContextProvider->>getWebStyles: used by getWebStyles/getWebVariable (dir on dummyParent)
UniwindContextProvider->>NativeStyleStore: used by native store cacheKey & validateDir
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/uniwind/tests/web/components/layout-direction.test.tsx (1)
5-25: ⚡ Quick winAdd a test for omitted
rtlprop (dirshould be absent).Current tests cover explicit
rtlandltr, but not the optional-prop path. Artl-omitted case would lock in inheritance behavior and prevent regressions.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/uniwind/tests/web/components/layout-direction.test.tsx` around lines 5 - 25, Add a new test in the LayoutDirection test suite that renders <LayoutDirection> without the rtl prop (e.g., <LayoutDirection><span>Default content</span></LayoutDirection>) and assert that the span's parentElement does NOT have a "dir" attribute (use getByText('Default content').parentElement and expect(...).not.toHaveAttribute('dir')); keep test name descriptive like "omits dir attribute when rtl prop is not provided".
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/uniwind/src/components/LayoutDirection/LayoutDirection.tsx`:
- Around line 11-16: The current useMemo sets rtl to rtl ?? null which wipes out
parent direction when the prop is omitted; change the logic in LayoutDirection
(and mirror in LayoutDirection.native.tsx) to derive the effective rtl from the
parent context when the rtl prop is undefined—e.g., compute const effectiveRtl =
rtl === undefined ? uniwindContext.rtl : rtl and use that in the useMemo ({
...uniwindContext, rtl: effectiveRtl }) and for dir compute const dir =
effectiveRtl === undefined ? undefined : effectiveRtl ? 'rtl' : 'ltr' so the
subtree inherits parent direction unless explicitly overridden.
---
Nitpick comments:
In `@packages/uniwind/tests/web/components/layout-direction.test.tsx`:
- Around line 5-25: Add a new test in the LayoutDirection test suite that
renders <LayoutDirection> without the rtl prop (e.g.,
<LayoutDirection><span>Default content</span></LayoutDirection>) and assert that
the span's parentElement does NOT have a "dir" attribute (use getByText('Default
content').parentElement and expect(...).not.toHaveAttribute('dir')); keep test
name descriptive like "omits dir attribute when rtl prop is not provided".
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 3e8c8805-1f88-4b85-92e4-ef94697df37b
📒 Files selected for processing (16)
CONTEXT.mdpackages/uniwind/src/components/LayoutDirection/LayoutDirection.native.tsxpackages/uniwind/src/components/LayoutDirection/LayoutDirection.tsxpackages/uniwind/src/components/LayoutDirection/index.tspackages/uniwind/src/components/ScopedTheme/ScopedTheme.native.tsxpackages/uniwind/src/components/ScopedTheme/ScopedTheme.tsxpackages/uniwind/src/core/config/config.common.tspackages/uniwind/src/core/config/config.tspackages/uniwind/src/core/context.tspackages/uniwind/src/core/native/store.tspackages/uniwind/src/core/web/getWebStyles.tspackages/uniwind/src/index.tspackages/uniwind/tests/consts.tspackages/uniwind/tests/e2e/getWebStyles.test.tspackages/uniwind/tests/native/styles-parsing/dir.test.tsxpackages/uniwind/tests/web/components/layout-direction.test.tsx
|
🚀 This pull request is included in v1.9.0. See Release v1.9.0 for release notes. |
fixes #573
Summary by CodeRabbit
New Features
Improvements
Documentation
Tests