Created
November 24, 2023 18:47
-
-
Save gbozee/d845edef15114f496b64642ecfe6f129 to your computer and use it in GitHub Desktop.
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
import { mergeProps } from "../helpers" | |
const tokens = { | |
"colors.red.500": { | |
value: "#f00", | |
}, | |
} | |
const utilities = { | |
bg: { | |
transform(value, { token, raw }) { | |
return { | |
backgroundColor: token.raw(`colors.${raw}`), | |
} | |
}, | |
}, | |
} | |
export function css(styles) { | |
let transformedStyles = {} | |
Object.keys(styles).forEach((key) => { | |
if (utilities[key]) { | |
const { transform } = utilities[key] | |
const value = styles[key] | |
const result = transform(value, { | |
token: { | |
raw: (path) => tokens[path].value || value, | |
}, | |
raw: value, | |
}) | |
transformedStyles = { ...transformedStyles, ...result } | |
} else { | |
transformedStyles[key] = styles[key] | |
} | |
}) | |
return transformedStyles | |
} | |
export function mergeCss(...styles) { | |
return mergeProps(...styles) | |
} |
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
import { cva } from "../css" | |
export function styled(Element, recipe) { | |
const styling = cva(recipe) | |
return function (props) { | |
return <Element style={styling()} {...props} /> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment