From 03447caffcbcdf063b54f5bd92f910e2bca731c8 Mon Sep 17 00:00:00 2001 From: Brijesh Bittu Date: Mon, 27 May 2024 22:03:56 +0530 Subject: [PATCH] [fix] Make theme requirement optional in Pigment CSS config Fixes #48 --- packages/pigment-css-react/src/utils/generateCss.ts | 7 +++++-- packages/pigment-css-vite-plugin/src/index.ts | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/pigment-css-react/src/utils/generateCss.ts b/packages/pigment-css-react/src/utils/generateCss.ts index 99203736..b8d9394e 100644 --- a/packages/pigment-css-react/src/utils/generateCss.ts +++ b/packages/pigment-css-react/src/utils/generateCss.ts @@ -1,13 +1,16 @@ import { serializeStyles } from '@emotion/serialize'; import { Theme } from './extendTheme'; -export function generateTokenCss(theme: Theme) { +export function generateTokenCss(theme?: Theme) { + if (!theme) { + return ''; + } // use emotion to serialize the object to css string const { styles } = serializeStyles(theme.generateStyleSheets?.() || []); return styles; } -export function generateThemeTokens(theme: Theme) { +export function generateThemeTokens(theme?: Theme) { if (!theme || typeof theme !== 'object') { return {}; } diff --git a/packages/pigment-css-vite-plugin/src/index.ts b/packages/pigment-css-vite-plugin/src/index.ts index a3772fce..0e4e0583 100644 --- a/packages/pigment-css-vite-plugin/src/index.ts +++ b/packages/pigment-css-vite-plugin/src/index.ts @@ -13,7 +13,7 @@ export interface PigmentOptions extends Omit { /** * The theme object that you want to be passed to the `styled` function */ - theme: Theme; + theme?: Theme; } const VIRTUAL_CSS_FILE = `\0zero-runtime-styles.css`;