import type { Token } from '@pandacss/token-dictionary' import * as React from 'react' import { Grid, HStack, Stack, panda } from '../../styled-system/jsx' import { ColorWrapper } from '../components/color-wrapper' import { TokenContent } from '../components/token-content' import { TokenGroup } from '../components/token-group' import { useColorDocs, type ColorToken } from '../lib/use-color-docs' import { Input } from './input' import { SemanticColorDisplay } from './semantic-color' import { StickyTop } from './sticky-top' const UNCATEGORIZED_ID = 'uncategorized' as const function getColorFromReference(reference: string, name: string) { if (!reference?.match) { throw new Error(`Invalid reference for semantic token ${name}`) } return reference.match(/{colors\.(.*?)}/)?.[1] } const SEMANTIC_TOKEN_PRIORITY = ['base', 'light', '_light', 'dark', '_dark'] export function sortSemanticTokens(tokens: string[]) { const ret = tokens.slice() ret.sort((a, b) => { const _a = SEMANTIC_TOKEN_PRIORITY.indexOf(a) const _b = SEMANTIC_TOKEN_PRIORITY.indexOf(b) if (_a !== -1 && _b !== -1) return _a - _b if (_a !== -1) return -1 if (_b !== -1) return 1 return a.localeCompare(b) }) return ret } export interface SemanticTokenProps { name: string tokens: Record } export function SemanticToken(props: SemanticTokenProps) { const { name, tokens } = props const conditions: string[] = [] if (tokens.extensions.conditions) { conditions.push( ...sortSemanticTokens(Object.keys(tokens.extensions.conditions).filter((cond) => tokens[cond] != null)), ) } return ( {conditions.map((cond) => ( ))} {name} ) } interface ColorsProps { theme?: string } export function Colors({ theme }: ColorsProps) { const { filterQuery, setFilterQuery, semanticTokens, hasResults, uncategorizedColors, categorizedColors } = useColorDocs(theme) return ( setFilterQuery(e.target.value)} placeholder="Filter tokens by text, property or value" /> {categorizedColors.map(([category, colors]) => ( ))} {!!semanticTokens.length && ( {semanticTokens.map(([name, colors], i) => ( ))} )} {!hasResults &&
No result found! 🐼
}
) } function PrimitiveColors(props: { values?: Token[] }) { const { values = [] } = props return values.map((color, i) => { return ( {color.extensions.prop} {color.value} ) }) } function ColorGroup(props: { colors?: Token[]; title: string; children?: React.ReactNode }) { const { children, colors, title } = props const isEmpty = colors == null || colors.length === 0 if (!children && isEmpty) return null return (
{title} {children ? ( {children} ) : ( )}
) }