-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support {token.ref} syntax & add a few tests
- Loading branch information
Showing
15 changed files
with
941 additions
and
26 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
packages/language-server/__tests__/fixtures/create-config-result.ts
This file contains 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,108 @@ | ||
import { mergeConfigs } from '@pandacss/config' | ||
import { PandaContext } from '@pandacss/node' | ||
import presetBase from '@pandacss/preset-base' | ||
import presetPanda from '@pandacss/preset-panda' | ||
import { parseJson, stringifyJson } from '@pandacss/shared' | ||
import type { Config, LoadConfigResult, PresetCore, UserConfig } from '@pandacss/types' | ||
import { utils } from './utils' | ||
|
||
const buttonRecipe = { | ||
className: 'button', | ||
description: 'The styles for the Button component', | ||
base: { | ||
display: 'flex', | ||
cursor: 'pointer', | ||
fontWeight: 'bold', | ||
}, | ||
variants: { | ||
visual: { | ||
funky: { bg: 'red.200', color: 'slate.800' }, | ||
edgy: { border: '1px solid {colors.red.500}' }, | ||
}, | ||
size: { | ||
sm: { padding: '4', fontSize: '12px' }, | ||
lg: { padding: '8', fontSize: '40px' }, | ||
}, | ||
shape: { | ||
square: { borderRadius: '0' }, | ||
circle: { borderRadius: 'full' }, | ||
}, | ||
}, | ||
defaultVariants: { | ||
visual: 'funky', | ||
size: 'sm', | ||
shape: 'circle', | ||
}, | ||
} | ||
|
||
const fixturePreset: Omit<PresetCore, 'globalCss' | 'staticCss'> = { | ||
...presetBase, | ||
...presetPanda, | ||
theme: { | ||
...presetPanda.theme, | ||
recipes: { | ||
button: buttonRecipe, | ||
}, | ||
}, | ||
} | ||
|
||
const config: UserConfig = { | ||
...fixturePreset, | ||
optimize: true, | ||
cwd: '', | ||
outdir: 'styled-system', | ||
include: [], | ||
// | ||
cssVarRoot: ':where(html)', | ||
jsxFramework: 'react', | ||
} | ||
|
||
const fixtureDefaults = { | ||
dependencies: [], | ||
config, | ||
path: '', | ||
hooks: {}, | ||
serialized: stringifyJson(config), | ||
deserialize: () => parseJson(stringifyJson(config)), | ||
} as LoadConfigResult | ||
|
||
export const createConfigResult = (userConfig?: Config) => { | ||
const resolvedConfig = ( | ||
userConfig ? mergeConfigs([userConfig, fixtureDefaults.config]) : fixtureDefaults.config | ||
) as UserConfig | ||
|
||
return { ...fixtureDefaults, config: resolvedConfig } | ||
} | ||
|
||
export const createContext = (userConfig?: Config) => { | ||
let resolvedConfig = ( | ||
userConfig ? mergeConfigs([userConfig, fixtureDefaults.config]) : fixtureDefaults.config | ||
) as UserConfig | ||
|
||
const hooks = userConfig?.hooks ?? {} | ||
|
||
// This allows editing the config before the context is created | ||
// since this function is only used in tests, we only look at the user hooks | ||
// not the presets hooks, so that we can keep this fn sync | ||
if (hooks['config:resolved']) { | ||
const result = hooks['config:resolved']({ | ||
config: resolvedConfig, | ||
path: fixtureDefaults.path, | ||
dependencies: fixtureDefaults.dependencies, | ||
utils: utils, | ||
}) | ||
if (result) { | ||
resolvedConfig = result as UserConfig | ||
} | ||
} | ||
|
||
return new PandaContext({ | ||
...fixtureDefaults, | ||
hooks, | ||
config: resolvedConfig, | ||
tsconfig: { | ||
// @ts-expect-error | ||
useInMemoryFileSystem: true, | ||
}, | ||
}) | ||
} |
This file contains 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 @@ | ||
export * from './create-config-result' |
This file contains 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,18 @@ | ||
import { traverse } from '@pandacss/shared' | ||
|
||
const omit = <T, K extends keyof T | (string & {})>(obj: T, paths: K[]): Omit<T, K> => { | ||
const result = { ...obj } | ||
|
||
traverse(result, ({ path, parent, key }) => { | ||
if (paths.includes(path as K)) { | ||
delete (parent as any)[key] | ||
} | ||
}) | ||
|
||
return result as Omit<T, K> | ||
} | ||
|
||
export const utils = { | ||
omit, | ||
traverse, | ||
} |
Oops, something went wrong.