diff --git a/src/internals/index.js b/src/internals/index.js index 547a695..f6c1d9f 100644 --- a/src/internals/index.js +++ b/src/internals/index.js @@ -12,9 +12,13 @@ import React, { import * as utils from './utils'; import * as constants from './constants'; +/** @typedef {import('../types').__Stitches__} Stitches */ +/** @typedef {import('../types').CreateStitches} CreateStitches */ + // eslint-disable-next-line const ReactNative = require('react-native'); +/** @type {CreateStitches} */ export function createStitches(config = {}) { const themes = []; @@ -26,6 +30,7 @@ export function createStitches(config = {}) { themes.push(constants.EMPTY_THEME); } + /** @type {Stitches['createTheme']} */ function createTheme(theme) { const t = { id: `theme-${themes.length + 1}`, @@ -44,6 +49,7 @@ export function createStitches(config = {}) { const ThemeContext = createContext(themes[0]); + /** @type {Stitches['ThemeProvider']} */ function ThemeProvider({ theme = themes[0], children }) { return ( {children} @@ -56,12 +62,14 @@ export function createStitches(config = {}) { return t; } + /** @type {Stitches['useTheme']} */ function useTheme() { const t = useContext(ThemeContext); if (!t) throw new Error(constants.THEME_PROVIDER_MISSING_MESSAGE); return t.values; } + /** @type {Stitches['styled']} */ function styled(component, ...styleObjects) { const styleObject = styleObjects.reduce((a, v) => merge(a, v), {}); @@ -221,6 +229,7 @@ export function createStitches(config = {}) { return memo(Comp); } + /** @type {Stitches['css']} */ function css(...cssObjects) { return cssObjects.reduce((a, v) => merge(a, v), {}); } diff --git a/src/types/index.d.ts b/src/types/index.d.ts index ce9f748..ea67487 100644 --- a/src/types/index.d.ts +++ b/src/types/index.d.ts @@ -7,6 +7,7 @@ import type * as StyledComponent from './styled-component'; export type CreateStitches = Config.CreateStitches; export type CSSProperties = CSSUtil.CSSProperties; export type DefaultThemeMap = Config.DefaultThemeMap; +export type __Stitches__ = Stitches; /** Returns a Style interface from a configuration, leveraging the given media and style map. */