Skip to content

Commit

Permalink
Add jsdoc comments for internal types
Browse files Browse the repository at this point in the history
  • Loading branch information
Temzasse committed Jan 7, 2022
1 parent 31eac4c commit c0c4bba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/internals/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand All @@ -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}`,
Expand All @@ -44,6 +49,7 @@ export function createStitches(config = {}) {

const ThemeContext = createContext(themes[0]);

/** @type {Stitches['ThemeProvider']} */
function ThemeProvider({ theme = themes[0], children }) {
return (
<ThemeContext.Provider value={theme}>{children}</ThemeContext.Provider>
Expand All @@ -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), {});

Expand Down Expand Up @@ -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), {});
}
Expand Down
1 change: 1 addition & 0 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */

Expand Down

0 comments on commit c0c4bba

Please sign in to comment.