-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #475 from omnifed/474-feat-add-new-gradients
474 feat add new gradients
- Loading branch information
Showing
21 changed files
with
458 additions
and
115 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,32 @@ | ||
import { css } from '@cerberus-design/styled-system/css' | ||
import type { PropsWithChildren } from 'react' | ||
import SyntaxHighlighter from 'react-syntax-highlighter' | ||
import { nightOwl } from 'react-syntax-highlighter/dist/esm/styles/hljs' | ||
|
||
interface CodeProps { | ||
showLineNumbers?: boolean | ||
language?: string | ||
} | ||
|
||
export function Code(props: PropsWithChildren<CodeProps>) { | ||
return ( | ||
<SyntaxHighlighter | ||
className={css({ | ||
border: '3px solid', | ||
borderColor: '#272B3B', | ||
rounded: 'xl', | ||
'& :is(.linenumber)': { | ||
color: '#4b6479', | ||
borderInlineEnd: '1px solid', | ||
borderInlineEndColor: '#272B3B', | ||
marginInlineEnd: '4', | ||
}, | ||
})} | ||
language={props.language ?? 'typescript'} | ||
showLineNumbers={props.showLineNumbers} | ||
style={nightOwl} | ||
> | ||
{props.children} | ||
</SyntaxHighlighter> | ||
) | ||
} |
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
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,30 @@ | ||
'use client' | ||
|
||
import { css } from '@cerberus-design/styled-system/css' | ||
import { AnimatingMoonIcon } from './icons/AnimatingMoonIcon' | ||
import { AnimatingSunIcon } from './icons/AnimatingSunIcon' | ||
import { Show, useThemeContext } from '@cerberus-design/react' | ||
import { focusStates } from '@cerberus-design/panda-preset' | ||
import { useMemo } from 'react' | ||
|
||
export function ModeToggle() { | ||
const { mode, updateMode } = useThemeContext() | ||
const ariaLabel = useMemo(() => { | ||
return mode === 'light' ? 'Switch to dark mode' : 'Switch to light mode' | ||
}, [mode]) | ||
|
||
return ( | ||
<button | ||
className={css({ | ||
rounded: 'sm', | ||
_focusVisible: focusStates._focusVisible, | ||
})} | ||
aria-label={ariaLabel} | ||
onClick={updateMode} | ||
> | ||
<Show when={mode === 'light'} fallback={<AnimatingMoonIcon />}> | ||
<AnimatingSunIcon /> | ||
</Show> | ||
</button> | ||
) | ||
} |
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
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
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
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
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,123 @@ | ||
import { cq, hstack, vstack } from '@cerberus/styled-system/patterns' | ||
import { PAGE, gradientValues } from '@cerberus-design/panda-preset' | ||
import { css } from '@cerberus/styled-system/css' | ||
import { LogoFigma } from '@cerberus-design/icons' | ||
import { Code } from '@/app/components/Code' | ||
import { PAGE_TEXT_INITIAL } from '@/app/utils/const' | ||
|
||
export default function GradientList() { | ||
return ( | ||
<div | ||
className={cq({ | ||
mt: 6, | ||
})} | ||
> | ||
<ul | ||
className={hstack({ | ||
gap: 4, | ||
flexWrap: 'wrap', | ||
})} | ||
> | ||
{gradientValues.map((gradient, index) => ( | ||
<li | ||
className={css({ | ||
flexShrink: 0, | ||
w: { | ||
'@/sm': 'full', | ||
'@/xl': 'calc(50% - 1rem)', | ||
'@/4xl': 'calc(33.3333% - 1rem)', | ||
}, | ||
})} | ||
key={index} | ||
> | ||
<div | ||
className={css({ | ||
bgColor: 'page.surface.100', | ||
border: '2px solid', | ||
borderColor: 'page.border.initial', | ||
p: 2, | ||
rounded: 'xl', | ||
})} | ||
> | ||
<section | ||
data-gradient={gradient} | ||
className={css({ | ||
h: '15rem', | ||
rounded: 'lg', | ||
'&:is([data-gradient=dark-purple])': { | ||
cerbGradient: 'dark-purple', | ||
}, | ||
'&:is([data-gradient=light-purple])': { | ||
cerbGradient: 'light-purple', | ||
}, | ||
'&:is([data-gradient=green])': { | ||
cerbGradient: 'green', | ||
}, | ||
'&:is([data-gradient=light-blue])': { | ||
cerbGradient: 'light-blue', | ||
}, | ||
'&:is([data-gradient=red])': { | ||
cerbGradient: 'red', | ||
}, | ||
'&:is([data-gradient=neutral])': { | ||
cerbGradient: 'neutral', | ||
}, | ||
'&:is([data-gradient=yellow])': { | ||
cerbGradient: 'yellow', | ||
}, | ||
'&:is([data-gradient=light-teal])': { | ||
cerbGradient: 'light-teal', | ||
}, | ||
'&:is([data-gradient=teal])': { | ||
cerbGradient: 'teal', | ||
}, | ||
})} | ||
/> | ||
<footer | ||
className={vstack({ | ||
alignItems: 'flex-start', | ||
pb: 4, | ||
pxi: '5', | ||
pt: 3, | ||
})} | ||
> | ||
<h2 | ||
className={css({ | ||
color: PAGE_TEXT_INITIAL, | ||
textStyle: 'h3', | ||
textTransform: 'capitalize', | ||
})} | ||
> | ||
{gradient.replace(/-/g, ' ')} | ||
</h2> | ||
<p | ||
className={hstack({ | ||
color: PAGE_TEXT_INITIAL, | ||
gap: 1, | ||
})} | ||
> | ||
<span | ||
className={css({ | ||
color: 'page.text.100', | ||
})} | ||
> | ||
<LogoFigma /> | ||
</span> | ||
Gradient Fills/{gradient} | ||
</p> | ||
<span | ||
className={css({ | ||
color: PAGE_TEXT_INITIAL, | ||
mt: 3, | ||
})} | ||
> | ||
<Code>{gradient}</Code> | ||
</span> | ||
</footer> | ||
</div> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
) | ||
} |
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,20 @@ | ||
import GradientList from '@/app/preset/gradients/components/gradient-list' | ||
|
||
|
||
# Gradients | ||
|
||
Cerberus provides a set of predefined gradients that can be used in both design and development. | ||
|
||
## Usage | ||
|
||
To apply a gradient in code, just use the `cerbGradient` utility in any of your style objects. | ||
|
||
```tsx | ||
<div className={css({ cerbGradient: 'yellow' })}> | ||
This is a yellow gradient | ||
</div> | ||
``` | ||
|
||
## Options | ||
|
||
<GradientList /> |
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,85 @@ | ||
import { | ||
actionTokens, | ||
dangerTokens, | ||
infoTokens, | ||
pageTokens, | ||
secondaryActionTokens, | ||
successTokens, | ||
warningTokens, | ||
type SemanticToken, | ||
type Sentiment, | ||
type SentimentConfig, | ||
type ThemeSelectors, | ||
} from '@cerberus-design/panda-preset' | ||
|
||
export function getTokenList(palette: Sentiment): SentimentConfig[Sentiment] { | ||
switch (palette) { | ||
case 'page': | ||
return pageTokens.page | ||
case 'action': | ||
return actionTokens.action | ||
case 'secondaryAction': | ||
return secondaryActionTokens.secondaryAction | ||
case 'info': | ||
return infoTokens.info | ||
case 'success': | ||
return successTokens.success | ||
case 'warning': | ||
return warningTokens.warning | ||
case 'danger': | ||
return dangerTokens.danger | ||
default: | ||
throw new Error('Invalid color palette') | ||
} | ||
} | ||
|
||
export function normalizeTokens( | ||
tokens: SentimentConfig[Sentiment], | ||
palette: Sentiment, | ||
) { | ||
const usage = Object.keys(tokens!) | ||
return usage.reduce((acc, key) => { | ||
const token = tokens![key as keyof typeof tokens] | ||
const tokenKeys = Object.keys(token!) | ||
const nestedTokenKeys = tokenKeys.filter( | ||
(tokenKey) => typeof token![tokenKey as keyof typeof token] === 'object', | ||
) | ||
|
||
const nestedTokens = normalizeNestedTokens({ | ||
nestedTokenKeys, | ||
token, | ||
key, | ||
palette, | ||
}) | ||
|
||
return { ...acc, ...nestedTokens } | ||
}, {}) | ||
} | ||
|
||
interface NormalizeNestedTokensProps { | ||
nestedTokenKeys: string[] | ||
token: SemanticToken | ||
key: string | ||
palette: Sentiment | ||
} | ||
|
||
export function normalizeNestedTokens(data: NormalizeNestedTokensProps) { | ||
const { token, key, palette } = data | ||
return data.nestedTokenKeys.reduce((acc, tokenKey) => { | ||
const nestedToken = token![tokenKey as keyof typeof token] as ThemeSelectors | ||
|
||
if (nestedToken.hasOwnProperty('value')) | ||
return { ...acc, [`${palette}-${key}-${tokenKey}`]: nestedToken } | ||
|
||
const nestedTokenKeys = Object.keys(nestedToken) | ||
const normalizedNestedToken = nestedTokenKeys.reduce( | ||
(acc, nestedTokenKey) => { | ||
const value = nestedToken[nestedTokenKey as keyof typeof nestedToken] | ||
const tokenName = `${palette}-${key}-${tokenKey}-${nestedTokenKey}` | ||
return { ...acc, [tokenName]: value } | ||
}, | ||
{}, | ||
) | ||
return { ...acc, ...normalizedNestedToken } | ||
}, {}) | ||
} |
Oops, something went wrong.