Created
October 19, 2021 23:08
-
-
Save juice49/0b11bc1b769ef63850b45a00d364062b to your computer and use it in GitHub Desktop.
Stitches Create Scale Variant
This file contains hidden or 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 { CSS } from '@stitches/react' | |
import { theme } from './stitches.config' | |
function createScaleVariant<Scale extends string & keyof typeof theme>( | |
property: string, | |
scale: Scale, | |
): Record<keyof typeof theme[Scale], CSS> { | |
return Object.keys(theme.space).reduce( | |
(reduced, value) => ({ | |
...reduced, | |
[value]: { | |
[property]: `$${scale}$${value}`, | |
}, | |
}), | |
{} as Record<keyof typeof theme[Scale], CSS>, | |
) | |
} | |
/* m: createScaleVariant('margin', 'space'), | |
mi: createScaleVariant('marginInline', 'space'), | |
mis: createScaleVariant('marginInlineStart', 'space'), | |
mie: createScaleVariant('marginInlineEnd', 'space'), | |
mb: createScaleVariant('marginBlock', 'space'), | |
mbs: createScaleVariant('marginBlockStart', 'space'), | |
mbe: createScaleVariant('marginBlockEnd', 'space'), | |
p: createScaleVariant('padding', 'space'), | |
pi: createScaleVariant('paddingInline', 'space'), | |
pis: createScaleVariant('paddingInlineStart', 'space'), | |
pie: createScaleVariant('paddingInlineEnd', 'space'), | |
pb: createScaleVariant('paddingBlock', 'space'), | |
pbs: createScaleVariant('paddingBlockStart', 'space'), | |
pbe: createScaleVariant('paddingBlockEnd', 'space'), */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment