Skip to content

Commit 5237195

Browse files
authored
fix(studio): can't render semantic color tokens without base definition (#3058)
* test(studio): add test case for park ui * feat(studio): sort and render arbitrary semantic tokens * feat: adjust token priority * chore: add changeset * chore: update lock file
1 parent 8dfcc1e commit 5237195

10 files changed

Lines changed: 2022 additions & 43 deletions

File tree

.changeset/wild-lizards-look.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@pandacss/studio': patch
3+
---
4+
5+
fix(studio): can't render semantic color token without base definition

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@
6060
"@typescript-eslint/parser": "7.0.1",
6161
"eslint": "8.56.0",
6262
"eslint-config-prettier": "9.1.0",
63-
"prettier": "3.2.5"
63+
"prettier": "3.2.5",
64+
"vite-plugin-virtual": "^0.3.0"
6465
},
6566
"lint-staged": {
6667
"packages/**/*.{ts,tsx}": [
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React from 'react'
2+
import { describe, expect, it } from 'vitest'
3+
import { render } from '@testing-library/react'
4+
import type { TokenExtensions } from '@pandacss/token-dictionary'
5+
import { SemanticToken, sortSemanticTokens } from '../../src/components/colors'
6+
import rawSemanticTokens from '../fixtures/semantic-tokens-park-ui.json'
7+
8+
const semanticTokens = rawSemanticTokens as [string, TokenExtensions][]
9+
10+
describe('sortSemanticTokens', () => {
11+
it('should sort tokens', () => {
12+
const tokens = ['c', '_dark', 'a', '_light', 'base', 'b']
13+
const expected = ['base', '_light', '_dark', 'a', 'b', 'c']
14+
expect(sortSemanticTokens(tokens)).toEqual(expected)
15+
})
16+
})
17+
18+
describe('SemanticToken', () => {
19+
it('should render semantic tokens', () => {
20+
const token = {
21+
base: { value: '#fff' },
22+
dark: { value: '#000' },
23+
extensions: {
24+
conditions: {
25+
base: '#fff',
26+
dark: '#000',
27+
},
28+
},
29+
} as any
30+
31+
const { container } = render(<SemanticToken name="bg.default" tokens={token} />)
32+
33+
expect(container.textContent).toBe('base#fff dark#000 bg.default')
34+
})
35+
36+
it('should render semantic tokens without base token', () => {
37+
const { container } = render(
38+
<>
39+
{semanticTokens.map(([name, token]) => (
40+
<SemanticToken key={name} name={name} tokens={token} />
41+
))}
42+
</>,
43+
)
44+
45+
expect(container.firstChild?.textContent).toBe('lightvar(--colors-gray-1) darkvar(--colors-gray-1) bg.canvas')
46+
})
47+
})

0 commit comments

Comments
 (0)