Make it possible for adding custom selector utilities in typescript #969
Unanswered
joseDaKing
asked this question in
Ideas
Replies: 2 comments 1 reply
-
i have a silly solution: import { createStitches } from '@stitches/core'
import type * as Stitches from '@stitches/core'
const theme = {
space: {
sm: '16px',
md: '32px',
lg: '64px'
}
}
const utils = {
'@hover': (styles: CSS) => ({
'@media (hover: hover)': {
'&:hover': styles
}
})
}
const { config } = createStitches({
theme
})
export const { getCssText, css } = createStitches({
theme,
utils
})
type CSS = Stitches.CSS<typeof config> |
Beta Was this translation helpful? Give feedback.
1 reply
-
Here is another approach that will work with nested selector utility types import {
slate,
slateA,
gray,
grayA,
violet,
violetA,
crimson,
crimsonA,
amber,
amberA,
blue,
blueA,
red,
redA,
green,
greenA,
}
from "@radix-ui/colors";
import { CSS, PropertyValue } from "@stitches/react";
import Stitches from "@stitches/react/types/stitches";
const media = {...};
const themeMap = {...} as const;
const theme = {};
type ThemedCSS = CSS<Stitches<"", typeof media, typeof theme, typeof themeMap, Utils>["config"]>;
type Utils = {
borderXColor: (value: PropertyValue<"borderColor">) => {},
hover: (styles: ThemedCSS) => {};
}
const utils: Utils = () => {
borderXColor: value => ({ borderLeftColor: value, borderRightColor: value }),
hover: styles => ({ "@media (hover: hover)": { "&:hover": styles }})
}
const stitches = createStitches({
media,
theme,
themeMap,
utils
}); But is still think direct support for this would yield better dev experience |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Add custom selector utilities in typescript will yield the wrong type.
This wont work because of self refercing type
The only way to make it work is by using the CSS type without passing in the theme, but the theme tokens won't be typed anymore
Beta Was this translation helpful? Give feedback.
All reactions