Skip to content
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

fix(studio): can't render semantic color tokens without base definition #3058

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wild-lizards-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@pandacss/studio': patch
---

fix(studio): can't render semantic color token without base definition
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
"@typescript-eslint/parser": "7.0.1",
"eslint": "8.56.0",
"eslint-config-prettier": "9.1.0",
"prettier": "3.2.5"
"prettier": "3.2.5",
"vite-plugin-virtual": "^0.3.0"
},
"lint-staged": {
"packages/**/*.{ts,tsx}": [
Expand Down
47 changes: 47 additions & 0 deletions packages/studio/__tests__/components/colors.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react'
import { describe, expect, it } from 'vitest'
import { render } from '@testing-library/react'
import type { TokenExtensions } from '@pandacss/token-dictionary'
import { SemanticToken, sortSemanticTokens } from '../../src/components/colors'
import rawSemanticTokens from '../fixtures/semantic-tokens-park-ui.json'

const semanticTokens = rawSemanticTokens as [string, TokenExtensions][]

describe('sortSemanticTokens', () => {
it('should sort tokens', () => {
const tokens = ['c', '_dark', 'a', '_light', 'base', 'b']
const expected = ['base', '_light', '_dark', 'a', 'b', 'c']
expect(sortSemanticTokens(tokens)).toEqual(expected)
})
})

describe('SemanticToken', () => {
it('should render semantic tokens', () => {
const token = {
base: { value: '#fff' },
dark: { value: '#000' },
extensions: {
conditions: {
base: '#fff',
dark: '#000',
},
},
} as any

const { container } = render(<SemanticToken name="bg.default" tokens={token} />)

expect(container.textContent).toBe('base#fff dark#000 bg.default')
})

it('should render semantic tokens without base token', () => {
const { container } = render(
<>
{semanticTokens.map(([name, token]) => (
<SemanticToken key={name} name={name} tokens={token} />
))}
</>,
)

expect(container.firstChild?.textContent).toBe('lightvar(--colors-gray-1) darkvar(--colors-gray-1) bg.canvas')
})
})
Loading