I have a object with all of our design tokens like this:
const Tokens = {
neutralColor: {
dark: {
'100': #123456,
'200': #223456,
},
medium: {
'100': #654321,
'200': #876543,
},
light: {
'100': #009988,
'200': #334411,
}
},
feedbackColor: {
// similar like above
},
// other color family here
}
In my componente I need to limit the color
props to only accept values in the tokens, like:
<Typography color={Tokens.neutralColor.dark["100"]}>label</Typography>
// or
<Typography color="#123456">label</Typography>
// since Tokens.neutralColor.dark["100"] = #123456
As I should, I should create a type like:
type Color = "#123456" | "#223456" | "#654321" | "and so on"
type TypographyProps = {
color: Color
}
function Typography(props: TypographyProps) { ... }
Is there a way to create this Typescript type dynamically based on my token object?