|
| 1 | +import * as t from 'io-ts'; |
| 2 | +import { ColorSchemeType } from './ColorTheme'; |
| 3 | +import { DeepPartial } from './DeepPartial'; |
| 4 | +import { SistentThemeColorsType } from './SistentColor'; |
| 5 | +import { SistentSizesType } from './SistentSizes'; |
| 6 | + |
| 7 | +const SISTENT_SIZES = { |
| 8 | + xs: null, |
| 9 | + sm: null, |
| 10 | + md: null, |
| 11 | + lg: null, |
| 12 | + xl: null |
| 13 | +}; |
| 14 | + |
| 15 | +type ThemeComponent = {}; |
| 16 | + |
| 17 | +export type SistentThemeOther = Record<string, any>; |
| 18 | +export type SistentThemeComponents = Record<string, ThemeComponent>; |
| 19 | + |
| 20 | +/* |
| 21 | +export type HeadingStyle = { |
| 22 | + fontSize: string; |
| 23 | + fontWeight: CSSProperties['fontWeight']; |
| 24 | + lineHeight: CSSProperties['lineHeight']; |
| 25 | +} |
| 26 | +*/ |
| 27 | + |
| 28 | +const HeadingStyleType = t.type({ |
| 29 | + fontSize: t.string, |
| 30 | + fontWeight: t.string, |
| 31 | + lineHeight: t.string |
| 32 | +}); |
| 33 | + |
| 34 | +const HeadingsType = t.type({ |
| 35 | + fontFamily: t.string, |
| 36 | + fontWeight: t.string, |
| 37 | + sizes: t.type({ |
| 38 | + h1: HeadingStyleType, |
| 39 | + h2: HeadingStyleType, |
| 40 | + h3: HeadingStyleType, |
| 41 | + h4: HeadingStyleType, |
| 42 | + h5: HeadingStyleType, |
| 43 | + h6: HeadingStyleType |
| 44 | + }) |
| 45 | +}); |
| 46 | + |
| 47 | +const ShadeType = t.keyof({ |
| 48 | + '0': null, |
| 49 | + '1': null, |
| 50 | + '2': null, |
| 51 | + '3': null, |
| 52 | + '4': null, |
| 53 | + '5': null, |
| 54 | + '6': null, |
| 55 | + '7': null, |
| 56 | + '8': null, |
| 57 | + '9': null |
| 58 | +}); |
| 59 | + |
| 60 | +type Shade = t.TypeOf<typeof ShadeType>; |
| 61 | +/** |
| 62 | + * type Shade = keyof typeof allowedShades; |
| 63 | +const allowedShades = { |
| 64 | + 0: true, 1: true, 2: true, 3: true, 4: true, |
| 65 | + 5: true, 6: true, 7: true, 8: true, 9: true, |
| 66 | +}; |
| 67 | +
|
| 68 | +type FontFamilyType = CSSProperties['fontFamily']; |
| 69 | +type LineHeightType = CSSProperties['lineHeight']; |
| 70 | +*/ |
| 71 | + |
| 72 | +const SistentPrimaryShade = t.type({ |
| 73 | + light: ShadeType, |
| 74 | + dark: ShadeType |
| 75 | +}); |
| 76 | + |
| 77 | +const SistentThemeType = t.type({ |
| 78 | + dir: t.union([t.literal('ltr'), t.literal('rtl')]), |
| 79 | + fontFamily: t.string, |
| 80 | + lineHeight: t.string, |
| 81 | + primaryShade: t.union([ShadeType, SistentPrimaryShade]), |
| 82 | + other: t.record(t.string, t.any), |
| 83 | + white: t.string, |
| 84 | + black: t.string, |
| 85 | + components: t.record(t.string, t.unknown), |
| 86 | + colors: t.record(t.string, t.tuple([t.string, t.number])), |
| 87 | + primaryColor: t.keyof(SistentThemeColorsType), |
| 88 | + colorScheme: ColorSchemeType, |
| 89 | + fontSizes: SistentSizesType, |
| 90 | + radius: SistentSizesType, |
| 91 | + spacing: SistentSizesType, |
| 92 | + breakpoints: SistentSizesType, |
| 93 | + shadows: t.record(t.keyof(SISTENT_SIZES), t.string), |
| 94 | + headings: HeadingsType |
| 95 | +}); |
| 96 | + |
| 97 | +export type SistentTheme = t.TypeOf<typeof SistentThemeType>; |
| 98 | + |
| 99 | +export type SistentThemeBase = Omit<SistentTheme, 'fn'>; |
| 100 | + |
| 101 | +export type SistentThemeOverride = DeepPartial<Omit<SistentThemeBase, 'other' | 'components'>> & |
| 102 | + Partial<Pick<SistentThemeBase, 'other' | 'components'>>; |
0 commit comments