-
Notifications
You must be signed in to change notification settings - Fork 43
feat: add support for variables in media queries #335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
packages/uniwind/tests/media-queries/color-scheme.test.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| @import 'tailwindcss'; | ||
| @import 'uniwind'; | ||
|
|
||
| @layer theme { | ||
| :root { | ||
| --color-primary: #000000; | ||
| } | ||
| } | ||
|
|
||
| @media (prefers-color-scheme: dark) { | ||
| :root { | ||
| --color-primary: #ffffff; | ||
| } | ||
| } | ||
|
|
||
| .text-color-primary { | ||
| color: var(--color-primary); | ||
| } | ||
|
|
84 changes: 84 additions & 0 deletions
84
packages/uniwind/tests/media-queries/color-scheme.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import { act } from '@testing-library/react-native' | ||
| import { readFileSync } from 'fs' | ||
| import { resolve } from 'path' | ||
| import * as React from 'react' | ||
| import View from '../../src/components/native/View' | ||
| import { UniwindListener } from '../../src/core/listener' | ||
| import { UniwindStore } from '../../src/core/native/store' | ||
| import { compileVirtual } from '../../src/metro/compileVirtual' | ||
| import { Platform } from '../../src/metro/types' | ||
| import { ColorScheme, Orientation, StyleDependency } from '../../src/types' | ||
| import { renderUniwind } from '../utils' | ||
|
|
||
| describe('CSS Variables - Color Scheme Media Queries', () => { | ||
| beforeAll(async () => { | ||
| const cssPath = resolve('./tests/media-queries/color-scheme.test.css') | ||
| const css = readFileSync(cssPath, 'utf-8') | ||
| const virtualCode = await compileVirtual({ | ||
| css, | ||
| cssPath, | ||
| debug: true, | ||
| platform: Platform.iOS, | ||
| themes: ['light', 'dark'], | ||
| polyfills: undefined, | ||
| }) | ||
|
|
||
| eval( | ||
| `const { Uniwind } = require('../../src/core/config/config.native'); | ||
| Uniwind.__reinit(rt => ${virtualCode}, ['light', 'dark']); | ||
| `, | ||
| ) | ||
| }) | ||
|
|
||
| beforeEach(() => { | ||
| UniwindStore.runtime.screen = { width: 375, height: 667 } | ||
| UniwindStore.runtime.orientation = Orientation.Portrait | ||
| UniwindStore.runtime.colorScheme = ColorScheme.Light | ||
| UniwindStore.runtime.currentThemeName = ColorScheme.Light | ||
| UniwindStore.reinit() | ||
| }) | ||
|
|
||
| test('uses default value in light color scheme', () => { | ||
| const { getStylesFromId } = renderUniwind( | ||
| <View className="text-color-primary" testID="color-primary" />, | ||
| ) | ||
|
|
||
| expect(getStylesFromId('color-primary').color).toBe('#000000') | ||
| }) | ||
|
|
||
| test('uses media query value in dark color scheme', () => { | ||
| UniwindStore.runtime.currentThemeName = ColorScheme.Dark | ||
| UniwindStore.runtime.colorScheme = ColorScheme.Dark | ||
| UniwindListener.notify([StyleDependency.Theme, StyleDependency.ColorScheme]) | ||
|
|
||
| const { getStylesFromId } = renderUniwind( | ||
| <View className="text-color-primary" testID="color-primary" />, | ||
| ) | ||
|
|
||
| expect(getStylesFromId('color-primary').color).toBe('#ffffff') | ||
| }) | ||
|
|
||
| test('updates when color scheme changes', () => { | ||
| UniwindStore.runtime.currentThemeName = ColorScheme.Light | ||
| UniwindStore.runtime.colorScheme = ColorScheme.Light | ||
| UniwindListener.notify([StyleDependency.Theme, StyleDependency.ColorScheme]) | ||
|
|
||
| let { getStylesFromId } = renderUniwind( | ||
| <View className="text-color-primary" testID="color-primary" />, | ||
| ) | ||
|
|
||
| expect(getStylesFromId('color-primary').color).toBe('#000000') | ||
|
|
||
| UniwindStore.runtime.currentThemeName = ColorScheme.Dark | ||
| UniwindStore.runtime.colorScheme = ColorScheme.Dark | ||
| act(() => { | ||
| UniwindListener.notify([StyleDependency.Theme, StyleDependency.ColorScheme]) | ||
| }) | ||
|
|
||
| const { getStylesFromId: getStylesFromId2 } = renderUniwind( | ||
| <View className="text-color-primary" testID="color-primary" />, | ||
| ) | ||
|
|
||
| expect(getStylesFromId2('color-primary').color).toBe('#ffffff') | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| @import 'tailwindcss'; | ||
| @import 'uniwind'; | ||
|
|
||
| @layer theme { | ||
| :root { | ||
| --text-xl: 1.5rem; | ||
| --border-width: 1px; | ||
| } | ||
| } | ||
|
|
||
| @media (min-width: 768px) and (orientation: landscape) { | ||
| :root { | ||
| --text-xl: 6rem; | ||
| } | ||
| } | ||
|
|
||
| @media (min-width: 640px) and (prefers-color-scheme: dark) { | ||
| :root { | ||
| --border-width: 2px; | ||
| } | ||
| } | ||
|
|
||
| .text-xl { | ||
| font-size: var(--text-xl); | ||
| } | ||
|
|
||
| .border-custom { | ||
| border-width: var(--border-width); | ||
| } | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: uni-stack/uniwind
Length of output: 85
🏁 Script executed:
cat -n packages/uniwind/tests/media-queries/color-scheme.test.tsx | head -50Repository: uni-stack/uniwind
Length of output: 2334
🏁 Script executed:
Repository: uni-stack/uniwind
Length of output: 73
🏁 Script executed:
Repository: uni-stack/uniwind
Length of output: 375
🏁 Script executed:
Repository: uni-stack/uniwind
Length of output: 1835
🏁 Script executed:
Repository: uni-stack/uniwind
Length of output: 43
🏁 Script executed:
Repository: uni-stack/uniwind
Length of output: 5015
🏁 Script executed:
Repository: uni-stack/uniwind
Length of output: 43
🏁 Script executed:
Repository: uni-stack/uniwind
Length of output: 5399
🏁 Script executed:
Repository: uni-stack/uniwind
Length of output: 1118
🏁 Script executed:
Repository: uni-stack/uniwind
Length of output: 111
🏁 Script executed:
Repository: uni-stack/uniwind
Length of output: 3037
🏁 Script executed:
Repository: uni-stack/uniwind
Length of output: 6109
🏁 Script executed:
Repository: uni-stack/uniwind
Length of output: 43
🏁 Script executed:
Repository: uni-stack/uniwind
Length of output: 2416
🏁 Script executed:
Repository: uni-stack/uniwind
Length of output: 43
🏁 Script executed:
Repository: uni-stack/uniwind
Length of output: 128
🏁 Script executed:
Repository: uni-stack/uniwind
Length of output: 43
🏁 Script executed:
Repository: uni-stack/uniwind
Length of output: 417
🏁 Script executed:
Repository: uni-stack/uniwind
Length of output: 1776
🏁 Script executed:
Repository: uni-stack/uniwind
Length of output: 1871
🏁 Script executed:
Repository: uni-stack/uniwind
Length of output: 111
🏁 Script executed:
Repository: uni-stack/uniwind
Length of output: 43
🏁 Script executed:
Repository: uni-stack/uniwind
Length of output: 4389
🏁 Script executed:
Repository: uni-stack/uniwind
Length of output: 79
🏁 Script executed:
Repository: uni-stack/uniwind
Length of output: 43
🏁 Script executed:
Repository: uni-stack/uniwind
Length of output: 418
🏁 Script executed:
Repository: uni-stack/uniwind
Length of output: 43
🏁 Script executed:
Repository: uni-stack/uniwind
Length of output: 43
Use
new Function()instead ofeval()to avoid linting failure.The proposed fix is functionally correct, but requires linting disable comments to match the production code pattern. Update to:
🔧 Proposed fix (with linting disables)
Note: This pattern appears in 6 other test files (variables, orientation, min-width, max-width, combined, setup.ts) that should be updated consistently.
🧰 Tools
🪛 Biome (2.1.2)
[error] 26-26: eval() exposes to security risks and performance issues.
See the MDN web docs for more details.
Refactor the code so that it doesn't need to call eval().
(lint/security/noGlobalEval)
🤖 Prompt for AI Agents