-
Notifications
You must be signed in to change notification settings - Fork 35
fix: updateCSSVariable inside scoped theme #502
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
614d787
fix: updateCSSVariable scoped web
Brentlok 78b1487
fix: updateCSSVariables scoped on native
Brentlok 22ca1f8
test: updateCSSVariable scoped native
Brentlok d1c2e85
chore: clear web cssRules cache on reinit
Brentlok 72e4373
test: updateCSSVariables web
Brentlok 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,9 @@ | ||
| export const isDefined = <T>(value: T): value is NonNullable<T> => value !== undefined && value !== null | ||
|
|
||
| export const arrayEquals = <T>(a: Array<T>, b: Array<T>) => { | ||
| if (a.length !== b.length) { | ||
| return false | ||
| } | ||
|
|
||
| return a.every((value, index) => value === b[index]) | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import { Uniwind } from '../../../src/core/config/config' | ||
|
|
||
| type UniwindForTest = { | ||
| updateCSSVariables: typeof Uniwind.updateCSSVariables | ||
| __reinit: (_: () => {}, themes: Array<string>) => void | ||
| cssRules?: Array<unknown> | ||
| } | ||
|
|
||
| const uniwind = Uniwind as unknown as UniwindForTest | ||
|
|
||
| const getDynamicStyleElement = () => document.getElementById('uniwind-dynamic-styles') as HTMLStyleElement | null | ||
|
|
||
| const getDynamicRules = () => | ||
| Array.from(getDynamicStyleElement()?.sheet?.cssRules ?? []) | ||
| .filter((rule): rule is CSSStyleRule => 'selectorText' in rule && 'style' in rule) | ||
|
|
||
| const getRule = (selectorText: string) => getDynamicRules().find(rule => rule.selectorText === selectorText) | ||
|
|
||
| const resetUniwind = (themes: Array<string> = ['light', 'dark']) => { | ||
| uniwind.cssRules = undefined | ||
| getDynamicStyleElement()?.remove() | ||
| uniwind.__reinit(() => ({}), themes) | ||
| } | ||
|
|
||
| describe('Uniwind web config', () => { | ||
| beforeAll(() => { | ||
| Object.defineProperty(HTMLStyleElement.prototype, 'innerText', { | ||
| configurable: true, | ||
| get() { | ||
| return this.textContent ?? '' | ||
| }, | ||
| set(value: string) { | ||
| this.textContent = value | ||
| }, | ||
| }) | ||
| }) | ||
|
|
||
| beforeEach(() => { | ||
| resetUniwind() | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| resetUniwind() | ||
| }) | ||
|
|
||
| test('updateCSSVariables creates scoped rules', () => { | ||
| uniwind.updateCSSVariables('dark', { '--color-background': '#123456' }) | ||
|
|
||
| expect(getDynamicStyleElement()).not.toBeNull() | ||
| expect(getDynamicRules().map(rule => rule.selectorText)).toEqual(['.light', '.dark']) | ||
| expect(getRule('.dark')?.style.getPropertyValue('--color-background')).toBe('#123456') | ||
| }) | ||
|
|
||
| test('__reinit rebuilds dynamic rules when themes change', () => { | ||
| uniwind.updateCSSVariables('dark', { '--color-background': '#123456' }) | ||
|
|
||
| uniwind.__reinit(() => ({}), ['light', 'dark', 'premium']) | ||
| uniwind.updateCSSVariables('premium', { '--color-background': '#abcdef' }) | ||
|
|
||
| expect(document.querySelectorAll('#uniwind-dynamic-styles')).toHaveLength(1) | ||
| expect(getDynamicRules().map(rule => rule.selectorText)).toEqual(['.light', '.dark', '.premium']) | ||
| expect(getRule('.premium')?.style.getPropertyValue('--color-background')).toBe('#abcdef') | ||
| }) | ||
| }) |
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.
Uh oh!
There was an error while loading. Please reload this page.