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

216 feature add cerberusconfig helper #522

Merged
merged 12 commits into from
Sep 27, 2024
7 changes: 6 additions & 1 deletion docs/app/preset/colors/components/AvatarSwatch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ export default function ColorSwatch(props: ColorSwatchProps) {
const modeValue = useMemo(() => {
return mode === 'dark' ? '_darkMode' : '_lightMode'
}, [mode])
const color = _cerberusTheme[modeValue]
const color = useMemo(() => {
if (props.tokenName === 'action-border-focus') {
return _cerberusTheme[modeValue]
}
return `var(--cerberus-${_cerberusTheme[modeValue].replace(/\./g, '-').replace(/[{}]/g, '')})`
}, [modeValue, _cerberusTheme, props.tokenName])

const bgColor = {
backgroundColor: color,
Expand Down
176 changes: 0 additions & 176 deletions docs/app/preset/colors/components/ColorSwatch.tsx

This file was deleted.

18 changes: 12 additions & 6 deletions docs/app/preset/colors/components/color-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ interface FigmaScope {
}
}

interface ColorDetailsProps {}

export default function ColorDetails(props: ColorDetailsProps) {
export default function ColorDetails() {
const { mode } = useThemeContext()
const searchParams = useSearchParams()
const paramsToken = searchParams.get('token') ?? 'page-backdrop-initial'
Expand Down Expand Up @@ -145,12 +143,20 @@ export default function ColorDetails(props: ColorDetailsProps) {
}, [scope, splitToken])

const userMode = mode === 'dark' ? '_darkMode' : '_lightMode'
const tokenValue = token.value._cerberusTheme[userMode]
const rawColor = useMemo(() => {
return token.value._cerberusTheme[userMode]
}, [token.value._cerberusTheme, userMode])
const color = useMemo(() => {
if (paramsToken === 'action-border-focus') {
return rawColor
}
return `var(--cerberus-${rawColor.replace(/\./g, '-').replace(/[{}]/g, '')})`
}, [rawColor, paramsToken])
const swatchColor = useMemo(
() => ({
backgroundColor: tokenValue,
backgroundColor: color,
}),
[tokenValue],
[color],
)

return (
Expand Down
1 change: 1 addition & 0 deletions docs/app/preset/conditions/doc.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Cerberus extends the [built-in conditions](https://panda-css.com/docs/concepts/c
| Name | Selector |
| ------------------ | ------------------------- |
| _cerberusTheme | `[data-theme=cerberus] &` |
| _acheronTheme | `[data-theme=acheron] &` |
| _lightMode | `[data-color-mode=light] &, &.light, .light &` |
| _darkMode | `[data-color-mode=dark] &, &.dark, .dark &` |
| _modalOpen | `&:is([data-modal-open=true])` |
Expand Down
2 changes: 1 addition & 1 deletion docs/app/react/checkbox/components/live-preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function CheckboxPreview() {
const { size, text, id, mixed, ...fieldState } = selectedProps
const [checked, setChecked] = useState<boolean>(false)

const handleChange = useCallback((e: ChangeEvent<HTMLInputElement>) => {
const handleChange = useCallback((_: ChangeEvent<HTMLInputElement>) => {
setChecked((prev) => !prev)
}, [])

Expand Down
16 changes: 16 additions & 0 deletions docs/app/react/side-nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ const overviewGroup: CategoriesList = {
new: ['Loading States'],
},
}
const hooksGroup: CategoriesList = {
overview: {
name: 'Hooks & Helpers',
description: 'React hooks and helper functions for Cerberus',
items: [
'trap-focus',
'use-modal',
'use-theme',
'use-theme-context',
'use-toggle',
],
next: [],
new: [''],
},
}

function createSideNavData(categories: CategoriesList): NavList {
const navList: NavList = []
Expand Down Expand Up @@ -54,4 +69,5 @@ function getCategoryItemTags(
export const sideNavData: NavList = [
...createSideNavData(overviewGroup),
...createSideNavData(categoriesData),
...createSideNavData(hooksGroup),
]
1 change: 1 addition & 0 deletions packages/panda-preset/src/conditions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const conditions = {
// themes
cerberusTheme: '[data-theme=cerberus] &',
acheronTheme: '[data-theme=acheron] &',

// modes
lightMode: '[data-color-mode=light] &, &.light, .light &',
Expand Down
32 changes: 7 additions & 25 deletions packages/panda-preset/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
import {
defineConfig,
definePreset,
defineSemanticTokens,
type Config,
type Preset,
} from '@pandacss/dev'
import { globalCss } from './globalCss'
import { conditions } from './conditions'
import { utilities } from './utilities'
import { patterns } from './patterns'
import {
actionTokens,
dangerTokens,
infoTokens,
keyframes,
pageTokens,
secondaryActionTokens,
successTokens,
textStyles,
tokens,
warningTokens,
} from './theme/index'
import { keyframes, textStyles, tokens } from './theme'
import { recipes, slotRecipes } from './recipes'
import { semanticTokens } from './theme/semantic-tokens/config'

/**
* This module contains the Cerberus preset and configuration options.
Expand All @@ -36,6 +25,7 @@ export const cerberusPreset: Preset = definePreset({
utilities,
patterns,

// main theme: cerberus
theme: {
extend: {
keyframes,
Expand All @@ -44,19 +34,11 @@ export const cerberusPreset: Preset = definePreset({
textStyles,
tokens,
},

semanticTokens: defineSemanticTokens({
colors: {
...pageTokens,
...actionTokens,
...secondaryActionTokens,
...infoTokens,
...successTokens,
...warningTokens,
...dangerTokens,
},
}),
semanticTokens,
},

// additional themes
themes: {},
})

export const cerberusConfig: Config = defineConfig({
Expand Down
8 changes: 8 additions & 0 deletions packages/panda-preset/src/theme/colors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { formatPrimitiveColors, type PandaColor } from '../tokens'

/**
* This module contains the primitive colors used in the main theme.
* @module
*/

export const colors: PandaColor = formatPrimitiveColors()
1 change: 1 addition & 0 deletions packages/panda-preset/src/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './colors'
export * from './keyframes'
export * from './tokens'
export * from './textStyles'
Expand Down
Loading