stitchesjs / stitches

[Not Actively Maintained] CSS-in-JS with near-zero runtime, SSR, multi-variant support, and a best-in-class developer experience.
https://stitches.dev
MIT License
7.72k stars 251 forks source link

export type of `css` function #1151

Open majidsajadi opened 1 year ago

majidsajadi commented 1 year ago

Is your feature request related to a problem? Please describe. Im using React context API for exposing created stitches config to the components. I want to store css in context but there is no exported type.

Describe the solution you'd like Export css and styled types.

Describe alternatives you've considered Im currently using typeof css operator.

aaort commented 1 year ago

If I understood your intentions properly you can get the type of css object returned from the createStitches method by importing Stitches as default and accessing css property like this: Stitches['css'].

wbobeirne commented 1 year ago

Because the css function & component prop is dynamic based on the configuration you pass to createStitches, it can't be provided as a static import. What I've done for my project is export a type in my stitches.config.ts:

import { CSS, createStitches } from '@stitches/react'

export const {
    styled,
    css,
    globalCss,
    keyframes,
    getCssText,
    theme,
    createTheme,
    config,
} = createStitches({ /* your config here */ })

export type CSSProp = CSS<typeof config>