|
| 1 | +import * as CSS from 'csstype' |
| 2 | +import { SystemStyleObject } from '@styled-system/css' |
| 3 | +import { Theme as StyledSystemTheme } from 'styled-system' |
| 4 | + |
| 5 | +/** |
| 6 | + * The `sx` prop accepts a `SxStyleProp` object and properties that are part of |
| 7 | + * the `Theme` will be transformed to their corresponding values. Other valid |
| 8 | + * CSS properties are also allowed. |
| 9 | + */ |
| 10 | +export type SxStyleProp = SystemStyleObject |
| 11 | + |
| 12 | +export interface SxProps { |
| 13 | + /** |
| 14 | + * The sx prop lets you style elements inline, using values from your |
| 15 | + * theme. To use the sx prop, add the custom pragma as a comment to the |
| 16 | + * top of your module and import the jsx function. |
| 17 | + * |
| 18 | + * ```ts |
| 19 | + * // @jsx jsx |
| 20 | + * |
| 21 | + * import { jsx } from 'theme-ui' |
| 22 | + * ``` |
| 23 | + */ |
| 24 | + sx?: SxStyleProp |
| 25 | +} |
| 26 | + |
| 27 | +export interface IntrinsicSxElements { |
| 28 | + p: JSX.IntrinsicElements['p'] & SxProps |
| 29 | + b: JSX.IntrinsicElements['b'] & SxProps |
| 30 | + i: JSX.IntrinsicElements['i'] & SxProps |
| 31 | + a: JSX.IntrinsicElements['a'] & SxProps |
| 32 | + h1: JSX.IntrinsicElements['h1'] & SxProps |
| 33 | + h2: JSX.IntrinsicElements['h2'] & SxProps |
| 34 | + h3: JSX.IntrinsicElements['h3'] & SxProps |
| 35 | + h4: JSX.IntrinsicElements['h4'] & SxProps |
| 36 | + h5: JSX.IntrinsicElements['h5'] & SxProps |
| 37 | + h6: JSX.IntrinsicElements['h6'] & SxProps |
| 38 | + img: JSX.IntrinsicElements['img'] & SxProps |
| 39 | + pre: JSX.IntrinsicElements['pre'] & SxProps |
| 40 | + code: JSX.IntrinsicElements['code'] & SxProps |
| 41 | + ol: JSX.IntrinsicElements['ol'] & SxProps |
| 42 | + ul: JSX.IntrinsicElements['ul'] & SxProps |
| 43 | + li: JSX.IntrinsicElements['li'] & SxProps |
| 44 | + blockquote: JSX.IntrinsicElements['blockquote'] & SxProps |
| 45 | + hr: JSX.IntrinsicElements['hr'] & SxProps |
| 46 | + table: JSX.IntrinsicElements['table'] & SxProps |
| 47 | + tr: JSX.IntrinsicElements['tr'] & SxProps |
| 48 | + th: JSX.IntrinsicElements['th'] & SxProps |
| 49 | + td: JSX.IntrinsicElements['td'] & SxProps |
| 50 | + em: JSX.IntrinsicElements['em'] & SxProps |
| 51 | + strong: JSX.IntrinsicElements['strong'] & SxProps |
| 52 | + div: JSX.IntrinsicElements['div'] & SxProps |
| 53 | + delete: JSX.IntrinsicElements['div'] & SxProps |
| 54 | + inlineCode: JSX.IntrinsicElements['div'] & SxProps |
| 55 | + thematicBreak: JSX.IntrinsicElements['div'] & SxProps |
| 56 | + root: JSX.IntrinsicElements['div'] & SxProps |
| 57 | +} |
| 58 | +type ObjectOrArray<T> = T[] | { [K: string]: T | ObjectOrArray<T> } |
| 59 | +type StyledTags = keyof IntrinsicSxElements |
| 60 | + |
| 61 | +/** |
| 62 | + * To use Theme UI color modes, color scales should include at least a text |
| 63 | + * and background color. These values are used in the ColorMode component to |
| 64 | + * set body foreground and background colors. Color modes should be defined as |
| 65 | + * nested objects within a theme.colors.modes object. Each key in this object |
| 66 | + * should correspond to a color mode name, where the name can be anything, but |
| 67 | + * typically light and dark are used for applications with a dark mode. The |
| 68 | + * initialColorModeName key is required to enable color modes and will be used as |
| 69 | + * the name for the root color palette. |
| 70 | + */ |
| 71 | +export type ColorMode = { |
| 72 | + [k: string]: CSS.ColorProperty | ObjectOrArray<CSS.ColorProperty> |
| 73 | +} & { |
| 74 | + /** |
| 75 | + * Body background color |
| 76 | + */ |
| 77 | + background: CSS.ColorProperty |
| 78 | + |
| 79 | + /** |
| 80 | + * Body foreground color |
| 81 | + */ |
| 82 | + text: CSS.ColorProperty |
| 83 | + |
| 84 | + /** |
| 85 | + * Primary brand color for links, buttons, etc. |
| 86 | + */ |
| 87 | + primary?: CSS.ColorProperty |
| 88 | + |
| 89 | + /** |
| 90 | + * A secondary brand color for alternative styling |
| 91 | + */ |
| 92 | + secondary?: CSS.ColorProperty |
| 93 | + |
| 94 | + /** |
| 95 | + * A faint color for backgrounds, borders, and accents that do not require |
| 96 | + * high contrast with the background color |
| 97 | + */ |
| 98 | + muted?: CSS.ColorProperty |
| 99 | + |
| 100 | + /** |
| 101 | + * A contrast color for emphasizing UI |
| 102 | + */ |
| 103 | + accent?: CSS.ColorProperty |
| 104 | +} |
| 105 | + |
| 106 | +export interface Theme extends Omit<StyledSystemTheme, 'colors'> { |
| 107 | + /** |
| 108 | + * Enable/disable custom CSS properties/variables if lower browser |
| 109 | + * support is required (for eg. IE 11). |
| 110 | + * |
| 111 | + * References: https://theme-ui.com/color-modes/#turn-off-custom-properties |
| 112 | + */ |
| 113 | + useCustomProperties?: boolean |
| 114 | + |
| 115 | + /** |
| 116 | + * Provide a value here to enable color modes |
| 117 | + */ |
| 118 | + initialColorModeName?: string |
| 119 | + |
| 120 | + /** |
| 121 | + * Adds styles defined in theme.styles.root to the <body> element along with color and background-color |
| 122 | + */ |
| 123 | + useBodyStyles?: boolean |
| 124 | + |
| 125 | + /** |
| 126 | + * Initializes the color mode based on the prefers-color-scheme media query |
| 127 | + */ |
| 128 | + useColorSchemeMediaQuery?: boolean |
| 129 | + |
| 130 | + /** |
| 131 | + * Adds a global box-sizing: border-box style |
| 132 | + */ |
| 133 | + useBoxSizing?: boolean |
| 134 | + |
| 135 | + /** |
| 136 | + * Define the colors that are available through this theme |
| 137 | + */ |
| 138 | + colors?: ColorMode & { |
| 139 | + /** |
| 140 | + * Nested color modes can provide overrides when used in conjunction with |
| 141 | + * `Theme.initialColorModeName and `useColorMode()` |
| 142 | + */ |
| 143 | + modes?: { |
| 144 | + [k: string]: ColorMode |
| 145 | + } |
| 146 | + } |
| 147 | + |
| 148 | + /** |
| 149 | + * Styles for elements rendered in MDX can be added to the theme.styles |
| 150 | + * object. This is the primary, low-level way to control typographic and |
| 151 | + * other styles in markdown content. Styles within this object are processed |
| 152 | + * with @styled-system/css and have access to base theme values like colors, |
| 153 | + * fonts, etc. |
| 154 | + */ |
| 155 | + styles?: { |
| 156 | + [P in StyledTags]?: SystemStyleObject |
| 157 | + } |
| 158 | +} |
0 commit comments