@aurora-ds/theme 1.5.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +195 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +234 -51
- package/dist/index.d.ts +234 -51
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -262,6 +262,94 @@ type DeepPartial<T> = {
|
|
|
262
262
|
* Type for theme overrides
|
|
263
263
|
*/
|
|
264
264
|
type ThemeOverride<T extends Theme = Theme> = DeepPartial<T>;
|
|
265
|
+
/**
|
|
266
|
+
* Base structure for custom themes with user-defined color tokens
|
|
267
|
+
* Use this when you want to completely replace the default color tokens
|
|
268
|
+
* with your own semantic tokens
|
|
269
|
+
*/
|
|
270
|
+
type CustomThemeBase<TColors extends Record<string, string>> = {
|
|
271
|
+
colors: TColors;
|
|
272
|
+
spacing: BaseSpacing;
|
|
273
|
+
radius: BaseRadius;
|
|
274
|
+
shadows: BaseShadows;
|
|
275
|
+
fontSize: BaseFontSize;
|
|
276
|
+
fontWeight: BaseFontWeight;
|
|
277
|
+
lineHeight: BaseLineHeight;
|
|
278
|
+
zIndex: BaseZIndex;
|
|
279
|
+
transition: BaseTransition;
|
|
280
|
+
opacity: BaseOpacity;
|
|
281
|
+
breakpoints: BaseBreakpoints;
|
|
282
|
+
};
|
|
283
|
+
/**
|
|
284
|
+
* Fully customizable theme where ALL token categories can be replaced
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* ```ts
|
|
288
|
+
* // Define your own color tokens
|
|
289
|
+
* type MyColors = {
|
|
290
|
+
* brand: string
|
|
291
|
+
* brandHover: string
|
|
292
|
+
* surface: string
|
|
293
|
+
* textPrimary: string
|
|
294
|
+
* textSecondary: string
|
|
295
|
+
* }
|
|
296
|
+
*
|
|
297
|
+
* // Create your theme type
|
|
298
|
+
* type MyTheme = CustomTheme<MyColors>
|
|
299
|
+
*
|
|
300
|
+
* // Use with createCustomTheme()
|
|
301
|
+
* const myTheme = createCustomTheme<MyColors>({
|
|
302
|
+
* colors: {
|
|
303
|
+
* brand: '#007bff',
|
|
304
|
+
* brandHover: '#0056b3',
|
|
305
|
+
* surface: '#ffffff',
|
|
306
|
+
* textPrimary: '#212529',
|
|
307
|
+
* textSecondary: '#6c757d',
|
|
308
|
+
* },
|
|
309
|
+
* // ... other tokens use defaults or custom
|
|
310
|
+
* })
|
|
311
|
+
* ```
|
|
312
|
+
*/
|
|
313
|
+
type CustomTheme<TColors extends Record<string, string> = Record<string, string>, TSpacing extends Record<string, string> = BaseSpacing, TRadius extends Record<string, string> = BaseRadius, TShadows extends Record<string, string> = BaseShadows, TFontSize extends Record<string, string> = BaseFontSize, TFontWeight extends Record<string, number> = BaseFontWeight, TLineHeight extends Record<string, number> = BaseLineHeight, TZIndex extends Record<string, number> = BaseZIndex, TTransition extends Record<string, string> = BaseTransition, TOpacity extends Record<string, number> = BaseOpacity, TBreakpoints extends Record<string, string> = BaseBreakpoints> = {
|
|
314
|
+
colors: TColors;
|
|
315
|
+
spacing: TSpacing;
|
|
316
|
+
radius: TRadius;
|
|
317
|
+
shadows: TShadows;
|
|
318
|
+
fontSize: TFontSize;
|
|
319
|
+
fontWeight: TFontWeight;
|
|
320
|
+
lineHeight: TLineHeight;
|
|
321
|
+
zIndex: TZIndex;
|
|
322
|
+
transition: TTransition;
|
|
323
|
+
opacity: TOpacity;
|
|
324
|
+
breakpoints: TBreakpoints;
|
|
325
|
+
};
|
|
326
|
+
/**
|
|
327
|
+
* Options for theme creation
|
|
328
|
+
*/
|
|
329
|
+
type CreateThemeOptions = {
|
|
330
|
+
/**
|
|
331
|
+
* How to handle the merge of overrides with the base theme
|
|
332
|
+
* - 'merge': Deep merge overrides into base (default, preserves base tokens)
|
|
333
|
+
* - 'replace': Replace entire categories when specified in overrides
|
|
334
|
+
*/
|
|
335
|
+
mode?: 'merge' | 'replace';
|
|
336
|
+
};
|
|
337
|
+
/**
|
|
338
|
+
* Options for custom theme creation
|
|
339
|
+
*/
|
|
340
|
+
type CreateCustomThemeOptions<T> = {
|
|
341
|
+
/**
|
|
342
|
+
* Use defaults from the standard theme for non-color tokens
|
|
343
|
+
* If false, you must provide all tokens
|
|
344
|
+
* @default true
|
|
345
|
+
*/
|
|
346
|
+
useDefaults?: boolean;
|
|
347
|
+
/**
|
|
348
|
+
* Partial overrides for non-color tokens
|
|
349
|
+
* Only used when useDefaults is true
|
|
350
|
+
*/
|
|
351
|
+
overrides?: Partial<Omit<T, 'colors'>>;
|
|
352
|
+
};
|
|
265
353
|
|
|
266
354
|
/**
|
|
267
355
|
* Color scale type - 12 shades from 25 to 950
|
|
@@ -335,56 +423,6 @@ declare const ThemeProvider: <T extends Theme>({ theme, children }: ThemeProvide
|
|
|
335
423
|
*/
|
|
336
424
|
declare const useTheme: <T extends Theme = Theme>() => T;
|
|
337
425
|
|
|
338
|
-
/**
|
|
339
|
-
* Create a theme by merging a base theme with overrides
|
|
340
|
-
*
|
|
341
|
-
* @example
|
|
342
|
-
* ```ts
|
|
343
|
-
* const myTheme = createTheme(defaultTheme, {
|
|
344
|
-
* colors: {
|
|
345
|
-
* primary: '#ff0000',
|
|
346
|
-
* // Only override what you need
|
|
347
|
-
* },
|
|
348
|
-
* spacing: {
|
|
349
|
-
* md: '1.5rem',
|
|
350
|
-
* },
|
|
351
|
-
* })
|
|
352
|
-
* ```
|
|
353
|
-
*/
|
|
354
|
-
declare const createTheme: <T extends Theme>(baseTheme: T, overrides: DeepPartial<T>) => T;
|
|
355
|
-
/**
|
|
356
|
-
* Merge multiple theme overrides into one
|
|
357
|
-
* Later overrides take precedence
|
|
358
|
-
*
|
|
359
|
-
* @example
|
|
360
|
-
* ```ts
|
|
361
|
-
* const theme = mergeThemes(
|
|
362
|
-
* baseTheme,
|
|
363
|
-
* brandOverrides,
|
|
364
|
-
* darkModeOverrides,
|
|
365
|
-
* userPreferences
|
|
366
|
-
* )
|
|
367
|
-
* ```
|
|
368
|
-
*/
|
|
369
|
-
declare const mergeThemes: <T extends Theme>(baseTheme: T, ...overrides: DeepPartial<T>[]) => T;
|
|
370
|
-
/**
|
|
371
|
-
* Create a theme extension factory
|
|
372
|
-
* Useful for creating theme variants (dark mode, high contrast, etc.)
|
|
373
|
-
*
|
|
374
|
-
* @example
|
|
375
|
-
* ```ts
|
|
376
|
-
* const createDarkVariant = createThemeVariant({
|
|
377
|
-
* colors: {
|
|
378
|
-
* background: '#1a1a1a',
|
|
379
|
-
* text: '#ffffff',
|
|
380
|
-
* },
|
|
381
|
-
* })
|
|
382
|
-
*
|
|
383
|
-
* const darkTheme = createDarkVariant(lightTheme)
|
|
384
|
-
* ```
|
|
385
|
-
*/
|
|
386
|
-
declare const createThemeVariant: <T extends Theme>(variantOverrides: DeepPartial<T>) => (baseTheme: T) => T;
|
|
387
|
-
|
|
388
426
|
/**
|
|
389
427
|
* Default spacing scale
|
|
390
428
|
*/
|
|
@@ -442,6 +480,125 @@ declare const defaultTheme: Theme;
|
|
|
442
480
|
*/
|
|
443
481
|
declare const defaultDarkTheme: Theme;
|
|
444
482
|
|
|
483
|
+
/**
|
|
484
|
+
* Create a theme by merging a base theme with overrides
|
|
485
|
+
*
|
|
486
|
+
* @param baseTheme - The base theme to extend
|
|
487
|
+
* @param overrides - Partial overrides to apply
|
|
488
|
+
* @param options - Optional configuration
|
|
489
|
+
* @param options.mode - 'merge' (default) deep merges, 'replace' replaces entire categories
|
|
490
|
+
*
|
|
491
|
+
* @example
|
|
492
|
+
* ```ts
|
|
493
|
+
* // Default behavior: deep merge (extends existing tokens)
|
|
494
|
+
* const myTheme = createTheme(defaultTheme, {
|
|
495
|
+
* colors: {
|
|
496
|
+
* primary: '#ff0000',
|
|
497
|
+
* // Other color tokens from defaultTheme are preserved
|
|
498
|
+
* },
|
|
499
|
+
* })
|
|
500
|
+
*
|
|
501
|
+
* // Replace mode: completely replace categories
|
|
502
|
+
* const myTheme = createTheme(defaultTheme, {
|
|
503
|
+
* colors: {
|
|
504
|
+
* // This becomes the ENTIRE colors object
|
|
505
|
+
* brand: '#ff0000',
|
|
506
|
+
* surface: '#ffffff',
|
|
507
|
+
* text: '#000000',
|
|
508
|
+
* },
|
|
509
|
+
* }, { mode: 'replace' })
|
|
510
|
+
* ```
|
|
511
|
+
*/
|
|
512
|
+
declare const createTheme: <T extends Theme>(baseTheme: T, overrides: DeepPartial<T>, options?: CreateThemeOptions) => T;
|
|
513
|
+
/**
|
|
514
|
+
* Merge multiple theme overrides into one
|
|
515
|
+
* Later overrides take precedence
|
|
516
|
+
*
|
|
517
|
+
* @example
|
|
518
|
+
* ```ts
|
|
519
|
+
* const theme = mergeThemes(
|
|
520
|
+
* baseTheme,
|
|
521
|
+
* brandOverrides,
|
|
522
|
+
* darkModeOverrides,
|
|
523
|
+
* userPreferences
|
|
524
|
+
* )
|
|
525
|
+
* ```
|
|
526
|
+
*/
|
|
527
|
+
declare const mergeThemes: <T extends Theme>(baseTheme: T, ...overrides: DeepPartial<T>[]) => T;
|
|
528
|
+
/**
|
|
529
|
+
* Create a theme extension factory
|
|
530
|
+
* Useful for creating theme variants (dark mode, high contrast, etc.)
|
|
531
|
+
*
|
|
532
|
+
* @example
|
|
533
|
+
* ```ts
|
|
534
|
+
* const createDarkVariant = createThemeVariant({
|
|
535
|
+
* colors: {
|
|
536
|
+
* background: '#1a1a1a',
|
|
537
|
+
* text: '#ffffff',
|
|
538
|
+
* },
|
|
539
|
+
* })
|
|
540
|
+
*
|
|
541
|
+
* const darkTheme = createDarkVariant(lightTheme)
|
|
542
|
+
* ```
|
|
543
|
+
*/
|
|
544
|
+
declare const createThemeVariant: <T extends Theme>(variantOverrides: DeepPartial<T>) => (baseTheme: T) => T;
|
|
545
|
+
/**
|
|
546
|
+
* Create a fully custom theme with your own color tokens
|
|
547
|
+
* This allows you to define a completely different color token structure
|
|
548
|
+
* without being constrained by BaseColors
|
|
549
|
+
*
|
|
550
|
+
* @param config - Full theme configuration with custom colors
|
|
551
|
+
*
|
|
552
|
+
* @example
|
|
553
|
+
* ```ts
|
|
554
|
+
* // Define your custom color tokens
|
|
555
|
+
* type MyBrandColors = {
|
|
556
|
+
* brand: string
|
|
557
|
+
* brandHover: string
|
|
558
|
+
* brandActive: string
|
|
559
|
+
* surface: string
|
|
560
|
+
* surfaceElevated: string
|
|
561
|
+
* textPrimary: string
|
|
562
|
+
* textSecondary: string
|
|
563
|
+
* border: string
|
|
564
|
+
* }
|
|
565
|
+
*
|
|
566
|
+
* // Create a theme with ONLY your color tokens
|
|
567
|
+
* const myTheme = createCustomTheme<MyBrandColors>({
|
|
568
|
+
* colors: {
|
|
569
|
+
* brand: '#007bff',
|
|
570
|
+
* brandHover: '#0056b3',
|
|
571
|
+
* brandActive: '#004085',
|
|
572
|
+
* surface: '#ffffff',
|
|
573
|
+
* surfaceElevated: '#f8f9fa',
|
|
574
|
+
* textPrimary: '#212529',
|
|
575
|
+
* textSecondary: '#6c757d',
|
|
576
|
+
* border: '#dee2e6',
|
|
577
|
+
* },
|
|
578
|
+
* // Uses defaults for other tokens, or provide your own:
|
|
579
|
+
* // spacing: { ... },
|
|
580
|
+
* // radius: { ... },
|
|
581
|
+
* })
|
|
582
|
+
*
|
|
583
|
+
* // TypeScript knows your theme has only YOUR color tokens:
|
|
584
|
+
* myTheme.colors.brand // ✅ OK
|
|
585
|
+
* myTheme.colors.primary // ❌ Error - doesn't exist
|
|
586
|
+
* ```
|
|
587
|
+
*/
|
|
588
|
+
declare const createCustomTheme: <TColors extends Record<string, string>, TSpacing extends Record<string, string> = typeof defaultSpacing, TRadius extends Record<string, string> = typeof defaultRadius, TShadows extends Record<string, string> = typeof defaultShadows, TFontSize extends Record<string, string> = typeof defaultFontSize, TFontWeight extends Record<string, number> = typeof defaultFontWeight, TLineHeight extends Record<string, number> = typeof defaultLineHeight, TZIndex extends Record<string, number> = typeof defaultZIndex, TTransition extends Record<string, string> = typeof defaultTransition, TOpacity extends Record<string, number> = typeof defaultOpacity, TBreakpoints extends Record<string, string> = typeof defaultBreakpoints>(config: {
|
|
589
|
+
colors: TColors;
|
|
590
|
+
spacing?: TSpacing;
|
|
591
|
+
radius?: TRadius;
|
|
592
|
+
shadows?: TShadows;
|
|
593
|
+
fontSize?: TFontSize;
|
|
594
|
+
fontWeight?: TFontWeight;
|
|
595
|
+
lineHeight?: TLineHeight;
|
|
596
|
+
zIndex?: TZIndex;
|
|
597
|
+
transition?: TTransition;
|
|
598
|
+
opacity?: TOpacity;
|
|
599
|
+
breakpoints?: TBreakpoints;
|
|
600
|
+
}) => CustomTheme<TColors, TSpacing, TRadius, TShadows, TFontSize, TFontWeight, TLineHeight, TZIndex, TTransition, TOpacity, TBreakpoints>;
|
|
601
|
+
|
|
445
602
|
declare const gray: ColorScale;
|
|
446
603
|
|
|
447
604
|
declare const slate: ColorScale;
|
|
@@ -741,6 +898,32 @@ type FontFaceOptions = {
|
|
|
741
898
|
* ```
|
|
742
899
|
*/
|
|
743
900
|
declare const createStyles: <TTheme extends Theme = Theme, T extends Record<string, StyleWithPseudos | StyleFunction> = Record<string, StyleWithPseudos | StyleFunction>>(stylesOrCreator: T | ((theme: TTheme) => T)) => { [K in keyof T]: T[K] extends (...args: infer TArgs) => StyleWithPseudos ? (...args: TArgs) => string : string; };
|
|
901
|
+
/**
|
|
902
|
+
* Create a typed createStyles function pre-configured with your custom theme type.
|
|
903
|
+
* This eliminates the need to specify the theme type on every createStyles call.
|
|
904
|
+
*
|
|
905
|
+
* @example
|
|
906
|
+
* ```ts
|
|
907
|
+
* // 1. Define your custom theme
|
|
908
|
+
* type MyTheme = CustomTheme<{
|
|
909
|
+
* brand: string
|
|
910
|
+
* brandHover: string
|
|
911
|
+
* surface: string
|
|
912
|
+
* }>
|
|
913
|
+
*
|
|
914
|
+
* // 2. Create a pre-typed createStyles function (do this once)
|
|
915
|
+
* export const createStyles = createTypedStyles<MyTheme>()
|
|
916
|
+
*
|
|
917
|
+
* // 3. Use it everywhere without specifying the type!
|
|
918
|
+
* const STYLES = createStyles((theme) => ({
|
|
919
|
+
* button: {
|
|
920
|
+
* backgroundColor: theme.colors.brand, // ✅ TypeScript knows!
|
|
921
|
+
* // backgroundColor: theme.colors.primary, // ❌ Error - doesn't exist
|
|
922
|
+
* },
|
|
923
|
+
* }))
|
|
924
|
+
* ```
|
|
925
|
+
*/
|
|
926
|
+
declare const createTypedStyles: <TTheme extends Record<string, unknown>>() => <T extends Record<string, StyleWithPseudos | StyleFunction>>(stylesOrCreator: T | ((theme: TTheme) => T)) => { [K in keyof T]: T[K] extends (...args: infer TArgs) => StyleWithPseudos ? (...args: TArgs) => string : string; };
|
|
744
927
|
|
|
745
928
|
/**
|
|
746
929
|
* Create and inject keyframes
|
|
@@ -1011,4 +1194,4 @@ declare const checkThemeContrast: (theme: {
|
|
|
1011
1194
|
*/
|
|
1012
1195
|
declare const suggestContrastColor: (foreground: string, background: string, targetRatio?: number) => string | null;
|
|
1013
1196
|
|
|
1014
|
-
export { type BaseBreakpoints, type BaseColors, type BaseFontSize, type BaseFontWeight, type BaseLineHeight, type BaseOpacity, type BaseRadius, type BaseShadows, type BaseSpacing, type BaseTransition, type BaseZIndex, type ColorName, type ColorScale, type ColorShade, type ContrastResult, type DeepPartial, type ExtendTheme, type ExtendedTheme, type FontFaceOptions, type PaletteName, type StyleFunction, type StyleWithPseudos, type Theme, type ThemeContrastIssue, type ThemeOverride, ThemeProvider, type ThemeProviderProps, type WCAGLevel, amber, amberDark, amberLight, black, blue, blueDark, blueLight, checkContrast, checkThemeContrast, clearSSRRules, colors, createStyles, createTheme, createThemeVariant, cssVar, cssVariables, current, cyan, cyanDark, cyanLight, defaultBreakpoints, defaultColors, defaultDarkColors, defaultDarkTheme, defaultFontSize, defaultFontWeight, defaultLineHeight, defaultOpacity, defaultRadius, defaultShadows, defaultSpacing, defaultTheme, defaultTransition, defaultZIndex, emerald, emeraldDark, emeraldLight, fontFace, fuchsia, getContrastRatio, getSSRRulesArray, getSSRStyleTag, getSSRStyles, getTheme, gray, grayDark, grayLight, green, indigo, indigoDark, indigoLight, injectCssVariables, insertRule, keyframes, lime, meetsWCAG, mergeThemes, orange, palettes, pink, purple, red, rose, roseDark, roseLight, sanitizeCssValue, setThemeContextGetter, sky, slate, slateDark, slateLight, stone, suggestContrastColor, teal, tealDark, tealLight, transparent, useTheme, violet, violetDark, violetLight, white, yellow };
|
|
1197
|
+
export { type BaseBreakpoints, type BaseColors, type BaseFontSize, type BaseFontWeight, type BaseLineHeight, type BaseOpacity, type BaseRadius, type BaseShadows, type BaseSpacing, type BaseTransition, type BaseZIndex, type ColorName, type ColorScale, type ColorShade, type ContrastResult, type CreateCustomThemeOptions, type CreateThemeOptions, type CustomTheme, type CustomThemeBase, type DeepPartial, type ExtendTheme, type ExtendedTheme, type FontFaceOptions, type PaletteName, type StyleFunction, type StyleWithPseudos, type Theme, type ThemeContrastIssue, type ThemeOverride, ThemeProvider, type ThemeProviderProps, type WCAGLevel, amber, amberDark, amberLight, black, blue, blueDark, blueLight, checkContrast, checkThemeContrast, clearSSRRules, colors, createCustomTheme, createStyles, createTheme, createThemeVariant, createTypedStyles, cssVar, cssVariables, current, cyan, cyanDark, cyanLight, defaultBreakpoints, defaultColors, defaultDarkColors, defaultDarkTheme, defaultFontSize, defaultFontWeight, defaultLineHeight, defaultOpacity, defaultRadius, defaultShadows, defaultSpacing, defaultTheme, defaultTransition, defaultZIndex, emerald, emeraldDark, emeraldLight, fontFace, fuchsia, getContrastRatio, getSSRRulesArray, getSSRStyleTag, getSSRStyles, getTheme, gray, grayDark, grayLight, green, indigo, indigoDark, indigoLight, injectCssVariables, insertRule, keyframes, lime, meetsWCAG, mergeThemes, orange, palettes, pink, purple, red, rose, roseDark, roseLight, sanitizeCssValue, setThemeContextGetter, sky, slate, slateDark, slateLight, stone, suggestContrastColor, teal, tealDark, tealLight, transparent, useTheme, violet, violetDark, violetLight, white, yellow };
|
package/dist/index.d.ts
CHANGED
|
@@ -262,6 +262,94 @@ type DeepPartial<T> = {
|
|
|
262
262
|
* Type for theme overrides
|
|
263
263
|
*/
|
|
264
264
|
type ThemeOverride<T extends Theme = Theme> = DeepPartial<T>;
|
|
265
|
+
/**
|
|
266
|
+
* Base structure for custom themes with user-defined color tokens
|
|
267
|
+
* Use this when you want to completely replace the default color tokens
|
|
268
|
+
* with your own semantic tokens
|
|
269
|
+
*/
|
|
270
|
+
type CustomThemeBase<TColors extends Record<string, string>> = {
|
|
271
|
+
colors: TColors;
|
|
272
|
+
spacing: BaseSpacing;
|
|
273
|
+
radius: BaseRadius;
|
|
274
|
+
shadows: BaseShadows;
|
|
275
|
+
fontSize: BaseFontSize;
|
|
276
|
+
fontWeight: BaseFontWeight;
|
|
277
|
+
lineHeight: BaseLineHeight;
|
|
278
|
+
zIndex: BaseZIndex;
|
|
279
|
+
transition: BaseTransition;
|
|
280
|
+
opacity: BaseOpacity;
|
|
281
|
+
breakpoints: BaseBreakpoints;
|
|
282
|
+
};
|
|
283
|
+
/**
|
|
284
|
+
* Fully customizable theme where ALL token categories can be replaced
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* ```ts
|
|
288
|
+
* // Define your own color tokens
|
|
289
|
+
* type MyColors = {
|
|
290
|
+
* brand: string
|
|
291
|
+
* brandHover: string
|
|
292
|
+
* surface: string
|
|
293
|
+
* textPrimary: string
|
|
294
|
+
* textSecondary: string
|
|
295
|
+
* }
|
|
296
|
+
*
|
|
297
|
+
* // Create your theme type
|
|
298
|
+
* type MyTheme = CustomTheme<MyColors>
|
|
299
|
+
*
|
|
300
|
+
* // Use with createCustomTheme()
|
|
301
|
+
* const myTheme = createCustomTheme<MyColors>({
|
|
302
|
+
* colors: {
|
|
303
|
+
* brand: '#007bff',
|
|
304
|
+
* brandHover: '#0056b3',
|
|
305
|
+
* surface: '#ffffff',
|
|
306
|
+
* textPrimary: '#212529',
|
|
307
|
+
* textSecondary: '#6c757d',
|
|
308
|
+
* },
|
|
309
|
+
* // ... other tokens use defaults or custom
|
|
310
|
+
* })
|
|
311
|
+
* ```
|
|
312
|
+
*/
|
|
313
|
+
type CustomTheme<TColors extends Record<string, string> = Record<string, string>, TSpacing extends Record<string, string> = BaseSpacing, TRadius extends Record<string, string> = BaseRadius, TShadows extends Record<string, string> = BaseShadows, TFontSize extends Record<string, string> = BaseFontSize, TFontWeight extends Record<string, number> = BaseFontWeight, TLineHeight extends Record<string, number> = BaseLineHeight, TZIndex extends Record<string, number> = BaseZIndex, TTransition extends Record<string, string> = BaseTransition, TOpacity extends Record<string, number> = BaseOpacity, TBreakpoints extends Record<string, string> = BaseBreakpoints> = {
|
|
314
|
+
colors: TColors;
|
|
315
|
+
spacing: TSpacing;
|
|
316
|
+
radius: TRadius;
|
|
317
|
+
shadows: TShadows;
|
|
318
|
+
fontSize: TFontSize;
|
|
319
|
+
fontWeight: TFontWeight;
|
|
320
|
+
lineHeight: TLineHeight;
|
|
321
|
+
zIndex: TZIndex;
|
|
322
|
+
transition: TTransition;
|
|
323
|
+
opacity: TOpacity;
|
|
324
|
+
breakpoints: TBreakpoints;
|
|
325
|
+
};
|
|
326
|
+
/**
|
|
327
|
+
* Options for theme creation
|
|
328
|
+
*/
|
|
329
|
+
type CreateThemeOptions = {
|
|
330
|
+
/**
|
|
331
|
+
* How to handle the merge of overrides with the base theme
|
|
332
|
+
* - 'merge': Deep merge overrides into base (default, preserves base tokens)
|
|
333
|
+
* - 'replace': Replace entire categories when specified in overrides
|
|
334
|
+
*/
|
|
335
|
+
mode?: 'merge' | 'replace';
|
|
336
|
+
};
|
|
337
|
+
/**
|
|
338
|
+
* Options for custom theme creation
|
|
339
|
+
*/
|
|
340
|
+
type CreateCustomThemeOptions<T> = {
|
|
341
|
+
/**
|
|
342
|
+
* Use defaults from the standard theme for non-color tokens
|
|
343
|
+
* If false, you must provide all tokens
|
|
344
|
+
* @default true
|
|
345
|
+
*/
|
|
346
|
+
useDefaults?: boolean;
|
|
347
|
+
/**
|
|
348
|
+
* Partial overrides for non-color tokens
|
|
349
|
+
* Only used when useDefaults is true
|
|
350
|
+
*/
|
|
351
|
+
overrides?: Partial<Omit<T, 'colors'>>;
|
|
352
|
+
};
|
|
265
353
|
|
|
266
354
|
/**
|
|
267
355
|
* Color scale type - 12 shades from 25 to 950
|
|
@@ -335,56 +423,6 @@ declare const ThemeProvider: <T extends Theme>({ theme, children }: ThemeProvide
|
|
|
335
423
|
*/
|
|
336
424
|
declare const useTheme: <T extends Theme = Theme>() => T;
|
|
337
425
|
|
|
338
|
-
/**
|
|
339
|
-
* Create a theme by merging a base theme with overrides
|
|
340
|
-
*
|
|
341
|
-
* @example
|
|
342
|
-
* ```ts
|
|
343
|
-
* const myTheme = createTheme(defaultTheme, {
|
|
344
|
-
* colors: {
|
|
345
|
-
* primary: '#ff0000',
|
|
346
|
-
* // Only override what you need
|
|
347
|
-
* },
|
|
348
|
-
* spacing: {
|
|
349
|
-
* md: '1.5rem',
|
|
350
|
-
* },
|
|
351
|
-
* })
|
|
352
|
-
* ```
|
|
353
|
-
*/
|
|
354
|
-
declare const createTheme: <T extends Theme>(baseTheme: T, overrides: DeepPartial<T>) => T;
|
|
355
|
-
/**
|
|
356
|
-
* Merge multiple theme overrides into one
|
|
357
|
-
* Later overrides take precedence
|
|
358
|
-
*
|
|
359
|
-
* @example
|
|
360
|
-
* ```ts
|
|
361
|
-
* const theme = mergeThemes(
|
|
362
|
-
* baseTheme,
|
|
363
|
-
* brandOverrides,
|
|
364
|
-
* darkModeOverrides,
|
|
365
|
-
* userPreferences
|
|
366
|
-
* )
|
|
367
|
-
* ```
|
|
368
|
-
*/
|
|
369
|
-
declare const mergeThemes: <T extends Theme>(baseTheme: T, ...overrides: DeepPartial<T>[]) => T;
|
|
370
|
-
/**
|
|
371
|
-
* Create a theme extension factory
|
|
372
|
-
* Useful for creating theme variants (dark mode, high contrast, etc.)
|
|
373
|
-
*
|
|
374
|
-
* @example
|
|
375
|
-
* ```ts
|
|
376
|
-
* const createDarkVariant = createThemeVariant({
|
|
377
|
-
* colors: {
|
|
378
|
-
* background: '#1a1a1a',
|
|
379
|
-
* text: '#ffffff',
|
|
380
|
-
* },
|
|
381
|
-
* })
|
|
382
|
-
*
|
|
383
|
-
* const darkTheme = createDarkVariant(lightTheme)
|
|
384
|
-
* ```
|
|
385
|
-
*/
|
|
386
|
-
declare const createThemeVariant: <T extends Theme>(variantOverrides: DeepPartial<T>) => (baseTheme: T) => T;
|
|
387
|
-
|
|
388
426
|
/**
|
|
389
427
|
* Default spacing scale
|
|
390
428
|
*/
|
|
@@ -442,6 +480,125 @@ declare const defaultTheme: Theme;
|
|
|
442
480
|
*/
|
|
443
481
|
declare const defaultDarkTheme: Theme;
|
|
444
482
|
|
|
483
|
+
/**
|
|
484
|
+
* Create a theme by merging a base theme with overrides
|
|
485
|
+
*
|
|
486
|
+
* @param baseTheme - The base theme to extend
|
|
487
|
+
* @param overrides - Partial overrides to apply
|
|
488
|
+
* @param options - Optional configuration
|
|
489
|
+
* @param options.mode - 'merge' (default) deep merges, 'replace' replaces entire categories
|
|
490
|
+
*
|
|
491
|
+
* @example
|
|
492
|
+
* ```ts
|
|
493
|
+
* // Default behavior: deep merge (extends existing tokens)
|
|
494
|
+
* const myTheme = createTheme(defaultTheme, {
|
|
495
|
+
* colors: {
|
|
496
|
+
* primary: '#ff0000',
|
|
497
|
+
* // Other color tokens from defaultTheme are preserved
|
|
498
|
+
* },
|
|
499
|
+
* })
|
|
500
|
+
*
|
|
501
|
+
* // Replace mode: completely replace categories
|
|
502
|
+
* const myTheme = createTheme(defaultTheme, {
|
|
503
|
+
* colors: {
|
|
504
|
+
* // This becomes the ENTIRE colors object
|
|
505
|
+
* brand: '#ff0000',
|
|
506
|
+
* surface: '#ffffff',
|
|
507
|
+
* text: '#000000',
|
|
508
|
+
* },
|
|
509
|
+
* }, { mode: 'replace' })
|
|
510
|
+
* ```
|
|
511
|
+
*/
|
|
512
|
+
declare const createTheme: <T extends Theme>(baseTheme: T, overrides: DeepPartial<T>, options?: CreateThemeOptions) => T;
|
|
513
|
+
/**
|
|
514
|
+
* Merge multiple theme overrides into one
|
|
515
|
+
* Later overrides take precedence
|
|
516
|
+
*
|
|
517
|
+
* @example
|
|
518
|
+
* ```ts
|
|
519
|
+
* const theme = mergeThemes(
|
|
520
|
+
* baseTheme,
|
|
521
|
+
* brandOverrides,
|
|
522
|
+
* darkModeOverrides,
|
|
523
|
+
* userPreferences
|
|
524
|
+
* )
|
|
525
|
+
* ```
|
|
526
|
+
*/
|
|
527
|
+
declare const mergeThemes: <T extends Theme>(baseTheme: T, ...overrides: DeepPartial<T>[]) => T;
|
|
528
|
+
/**
|
|
529
|
+
* Create a theme extension factory
|
|
530
|
+
* Useful for creating theme variants (dark mode, high contrast, etc.)
|
|
531
|
+
*
|
|
532
|
+
* @example
|
|
533
|
+
* ```ts
|
|
534
|
+
* const createDarkVariant = createThemeVariant({
|
|
535
|
+
* colors: {
|
|
536
|
+
* background: '#1a1a1a',
|
|
537
|
+
* text: '#ffffff',
|
|
538
|
+
* },
|
|
539
|
+
* })
|
|
540
|
+
*
|
|
541
|
+
* const darkTheme = createDarkVariant(lightTheme)
|
|
542
|
+
* ```
|
|
543
|
+
*/
|
|
544
|
+
declare const createThemeVariant: <T extends Theme>(variantOverrides: DeepPartial<T>) => (baseTheme: T) => T;
|
|
545
|
+
/**
|
|
546
|
+
* Create a fully custom theme with your own color tokens
|
|
547
|
+
* This allows you to define a completely different color token structure
|
|
548
|
+
* without being constrained by BaseColors
|
|
549
|
+
*
|
|
550
|
+
* @param config - Full theme configuration with custom colors
|
|
551
|
+
*
|
|
552
|
+
* @example
|
|
553
|
+
* ```ts
|
|
554
|
+
* // Define your custom color tokens
|
|
555
|
+
* type MyBrandColors = {
|
|
556
|
+
* brand: string
|
|
557
|
+
* brandHover: string
|
|
558
|
+
* brandActive: string
|
|
559
|
+
* surface: string
|
|
560
|
+
* surfaceElevated: string
|
|
561
|
+
* textPrimary: string
|
|
562
|
+
* textSecondary: string
|
|
563
|
+
* border: string
|
|
564
|
+
* }
|
|
565
|
+
*
|
|
566
|
+
* // Create a theme with ONLY your color tokens
|
|
567
|
+
* const myTheme = createCustomTheme<MyBrandColors>({
|
|
568
|
+
* colors: {
|
|
569
|
+
* brand: '#007bff',
|
|
570
|
+
* brandHover: '#0056b3',
|
|
571
|
+
* brandActive: '#004085',
|
|
572
|
+
* surface: '#ffffff',
|
|
573
|
+
* surfaceElevated: '#f8f9fa',
|
|
574
|
+
* textPrimary: '#212529',
|
|
575
|
+
* textSecondary: '#6c757d',
|
|
576
|
+
* border: '#dee2e6',
|
|
577
|
+
* },
|
|
578
|
+
* // Uses defaults for other tokens, or provide your own:
|
|
579
|
+
* // spacing: { ... },
|
|
580
|
+
* // radius: { ... },
|
|
581
|
+
* })
|
|
582
|
+
*
|
|
583
|
+
* // TypeScript knows your theme has only YOUR color tokens:
|
|
584
|
+
* myTheme.colors.brand // ✅ OK
|
|
585
|
+
* myTheme.colors.primary // ❌ Error - doesn't exist
|
|
586
|
+
* ```
|
|
587
|
+
*/
|
|
588
|
+
declare const createCustomTheme: <TColors extends Record<string, string>, TSpacing extends Record<string, string> = typeof defaultSpacing, TRadius extends Record<string, string> = typeof defaultRadius, TShadows extends Record<string, string> = typeof defaultShadows, TFontSize extends Record<string, string> = typeof defaultFontSize, TFontWeight extends Record<string, number> = typeof defaultFontWeight, TLineHeight extends Record<string, number> = typeof defaultLineHeight, TZIndex extends Record<string, number> = typeof defaultZIndex, TTransition extends Record<string, string> = typeof defaultTransition, TOpacity extends Record<string, number> = typeof defaultOpacity, TBreakpoints extends Record<string, string> = typeof defaultBreakpoints>(config: {
|
|
589
|
+
colors: TColors;
|
|
590
|
+
spacing?: TSpacing;
|
|
591
|
+
radius?: TRadius;
|
|
592
|
+
shadows?: TShadows;
|
|
593
|
+
fontSize?: TFontSize;
|
|
594
|
+
fontWeight?: TFontWeight;
|
|
595
|
+
lineHeight?: TLineHeight;
|
|
596
|
+
zIndex?: TZIndex;
|
|
597
|
+
transition?: TTransition;
|
|
598
|
+
opacity?: TOpacity;
|
|
599
|
+
breakpoints?: TBreakpoints;
|
|
600
|
+
}) => CustomTheme<TColors, TSpacing, TRadius, TShadows, TFontSize, TFontWeight, TLineHeight, TZIndex, TTransition, TOpacity, TBreakpoints>;
|
|
601
|
+
|
|
445
602
|
declare const gray: ColorScale;
|
|
446
603
|
|
|
447
604
|
declare const slate: ColorScale;
|
|
@@ -741,6 +898,32 @@ type FontFaceOptions = {
|
|
|
741
898
|
* ```
|
|
742
899
|
*/
|
|
743
900
|
declare const createStyles: <TTheme extends Theme = Theme, T extends Record<string, StyleWithPseudos | StyleFunction> = Record<string, StyleWithPseudos | StyleFunction>>(stylesOrCreator: T | ((theme: TTheme) => T)) => { [K in keyof T]: T[K] extends (...args: infer TArgs) => StyleWithPseudos ? (...args: TArgs) => string : string; };
|
|
901
|
+
/**
|
|
902
|
+
* Create a typed createStyles function pre-configured with your custom theme type.
|
|
903
|
+
* This eliminates the need to specify the theme type on every createStyles call.
|
|
904
|
+
*
|
|
905
|
+
* @example
|
|
906
|
+
* ```ts
|
|
907
|
+
* // 1. Define your custom theme
|
|
908
|
+
* type MyTheme = CustomTheme<{
|
|
909
|
+
* brand: string
|
|
910
|
+
* brandHover: string
|
|
911
|
+
* surface: string
|
|
912
|
+
* }>
|
|
913
|
+
*
|
|
914
|
+
* // 2. Create a pre-typed createStyles function (do this once)
|
|
915
|
+
* export const createStyles = createTypedStyles<MyTheme>()
|
|
916
|
+
*
|
|
917
|
+
* // 3. Use it everywhere without specifying the type!
|
|
918
|
+
* const STYLES = createStyles((theme) => ({
|
|
919
|
+
* button: {
|
|
920
|
+
* backgroundColor: theme.colors.brand, // ✅ TypeScript knows!
|
|
921
|
+
* // backgroundColor: theme.colors.primary, // ❌ Error - doesn't exist
|
|
922
|
+
* },
|
|
923
|
+
* }))
|
|
924
|
+
* ```
|
|
925
|
+
*/
|
|
926
|
+
declare const createTypedStyles: <TTheme extends Record<string, unknown>>() => <T extends Record<string, StyleWithPseudos | StyleFunction>>(stylesOrCreator: T | ((theme: TTheme) => T)) => { [K in keyof T]: T[K] extends (...args: infer TArgs) => StyleWithPseudos ? (...args: TArgs) => string : string; };
|
|
744
927
|
|
|
745
928
|
/**
|
|
746
929
|
* Create and inject keyframes
|
|
@@ -1011,4 +1194,4 @@ declare const checkThemeContrast: (theme: {
|
|
|
1011
1194
|
*/
|
|
1012
1195
|
declare const suggestContrastColor: (foreground: string, background: string, targetRatio?: number) => string | null;
|
|
1013
1196
|
|
|
1014
|
-
export { type BaseBreakpoints, type BaseColors, type BaseFontSize, type BaseFontWeight, type BaseLineHeight, type BaseOpacity, type BaseRadius, type BaseShadows, type BaseSpacing, type BaseTransition, type BaseZIndex, type ColorName, type ColorScale, type ColorShade, type ContrastResult, type DeepPartial, type ExtendTheme, type ExtendedTheme, type FontFaceOptions, type PaletteName, type StyleFunction, type StyleWithPseudos, type Theme, type ThemeContrastIssue, type ThemeOverride, ThemeProvider, type ThemeProviderProps, type WCAGLevel, amber, amberDark, amberLight, black, blue, blueDark, blueLight, checkContrast, checkThemeContrast, clearSSRRules, colors, createStyles, createTheme, createThemeVariant, cssVar, cssVariables, current, cyan, cyanDark, cyanLight, defaultBreakpoints, defaultColors, defaultDarkColors, defaultDarkTheme, defaultFontSize, defaultFontWeight, defaultLineHeight, defaultOpacity, defaultRadius, defaultShadows, defaultSpacing, defaultTheme, defaultTransition, defaultZIndex, emerald, emeraldDark, emeraldLight, fontFace, fuchsia, getContrastRatio, getSSRRulesArray, getSSRStyleTag, getSSRStyles, getTheme, gray, grayDark, grayLight, green, indigo, indigoDark, indigoLight, injectCssVariables, insertRule, keyframes, lime, meetsWCAG, mergeThemes, orange, palettes, pink, purple, red, rose, roseDark, roseLight, sanitizeCssValue, setThemeContextGetter, sky, slate, slateDark, slateLight, stone, suggestContrastColor, teal, tealDark, tealLight, transparent, useTheme, violet, violetDark, violetLight, white, yellow };
|
|
1197
|
+
export { type BaseBreakpoints, type BaseColors, type BaseFontSize, type BaseFontWeight, type BaseLineHeight, type BaseOpacity, type BaseRadius, type BaseShadows, type BaseSpacing, type BaseTransition, type BaseZIndex, type ColorName, type ColorScale, type ColorShade, type ContrastResult, type CreateCustomThemeOptions, type CreateThemeOptions, type CustomTheme, type CustomThemeBase, type DeepPartial, type ExtendTheme, type ExtendedTheme, type FontFaceOptions, type PaletteName, type StyleFunction, type StyleWithPseudos, type Theme, type ThemeContrastIssue, type ThemeOverride, ThemeProvider, type ThemeProviderProps, type WCAGLevel, amber, amberDark, amberLight, black, blue, blueDark, blueLight, checkContrast, checkThemeContrast, clearSSRRules, colors, createCustomTheme, createStyles, createTheme, createThemeVariant, createTypedStyles, cssVar, cssVariables, current, cyan, cyanDark, cyanLight, defaultBreakpoints, defaultColors, defaultDarkColors, defaultDarkTheme, defaultFontSize, defaultFontWeight, defaultLineHeight, defaultOpacity, defaultRadius, defaultShadows, defaultSpacing, defaultTheme, defaultTransition, defaultZIndex, emerald, emeraldDark, emeraldLight, fontFace, fuchsia, getContrastRatio, getSSRRulesArray, getSSRStyleTag, getSSRStyles, getTheme, gray, grayDark, grayLight, green, indigo, indigoDark, indigoLight, injectCssVariables, insertRule, keyframes, lime, meetsWCAG, mergeThemes, orange, palettes, pink, purple, red, rose, roseDark, roseLight, sanitizeCssValue, setThemeContextGetter, sky, slate, slateDark, slateLight, stone, suggestContrastColor, teal, tealDark, tealLight, transparent, useTheme, violet, violetDark, violetLight, white, yellow };
|