@marigold/system 0.0.2 → 0.3.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.
Files changed (47) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/dist/Box.d.ts +14 -0
  3. package/dist/Global.d.ts +2 -0
  4. package/dist/SVG.d.ts +6 -0
  5. package/dist/index.d.ts +7 -4
  6. package/dist/normalize.d.ts +143 -5
  7. package/dist/system.cjs.development.js +334 -159
  8. package/dist/system.cjs.development.js.map +1 -1
  9. package/dist/system.cjs.production.min.js +1 -1
  10. package/dist/system.cjs.production.min.js.map +1 -1
  11. package/dist/system.esm.js +324 -156
  12. package/dist/system.esm.js.map +1 -1
  13. package/dist/theme.d.ts +136 -0
  14. package/dist/types.d.ts +8 -0
  15. package/dist/useTheme.d.ts +15 -5
  16. package/dist/variant.d.ts +29 -0
  17. package/package.json +6 -8
  18. package/src/Box.test.tsx +308 -0
  19. package/src/Box.tsx +199 -0
  20. package/src/Colors.stories.mdx +492 -448
  21. package/src/Global.test.tsx +57 -0
  22. package/src/Global.tsx +34 -0
  23. package/src/SVG.stories.mdx +55 -0
  24. package/src/SVG.test.tsx +82 -0
  25. package/src/SVG.tsx +24 -0
  26. package/src/concepts-principles.mdx +1 -1
  27. package/src/index.ts +7 -4
  28. package/src/normalize.test.tsx +15 -0
  29. package/src/normalize.ts +79 -93
  30. package/src/theme.ts +157 -0
  31. package/src/types.ts +14 -0
  32. package/src/useTheme.test.tsx +92 -17
  33. package/src/useTheme.tsx +45 -6
  34. package/src/variant.test.ts +93 -0
  35. package/src/variant.ts +54 -0
  36. package/dist/categories.d.ts +0 -169
  37. package/dist/system.d.ts +0 -37
  38. package/dist/useClassname.d.ts +0 -2
  39. package/dist/useStyles.d.ts +0 -10
  40. package/src/categories.ts +0 -203
  41. package/src/system.test.tsx +0 -84
  42. package/src/system.tsx +0 -55
  43. package/src/useClassname.test.tsx +0 -61
  44. package/src/useClassname.ts +0 -8
  45. package/src/useStyles.test.tsx +0 -313
  46. package/src/useStyles.ts +0 -56
  47. package/src/writeComponent.stories.mdx +0 -126
@@ -1 +1 @@
1
- {"version":3,"file":"system.esm.js","sources":["../src/categories.ts","../src/system.tsx","../src/useTheme.tsx","../src/useClassname.ts","../src/normalize.ts","../src/useStyles.ts"],"sourcesContent":["import { PropertiesFallback } from 'csstype';\n\n/**\n * System categories are based on https://primer.style/components/docs/system-props\n */\n\n// Spacing\n// ---------------\nexport const SPACE_PROPS = [\n 'm',\n 'margin',\n 'mt',\n 'marginTop',\n 'mr',\n 'marginRight',\n 'mb',\n 'marginBottom',\n 'ml',\n 'marginLeft',\n 'mx',\n 'marginX',\n 'my',\n 'marginY',\n 'p',\n 'padding',\n 'pt',\n 'paddingTop',\n 'pr',\n 'paddingRight',\n 'pb',\n 'paddingBottom',\n 'pl',\n 'paddingLeft',\n 'px',\n 'paddingX',\n 'py',\n 'paddingY',\n];\n\ntype StandardCSSProperties = PropertiesFallback<number | string>;\n\nexport type SpacingProps = {\n /**\n * The **`margin`** CSS property sets the margin area on all four sides of an element. It is a shorthand for `margin-top`, `margin-right`, `margin-bottom`, and `margin-left`.\n *\n * @see https://developer.mozilla.org/docs/Web/CSS/margin\n */\n m?: StandardCSSProperties['margin'];\n /**\n * The **`margin-top`** CSS property sets the margin area on the top of an element. A positive value places it farther from its neighbors, while a negative value places it closer.\n *\n * **Initial value**: `0`\n *\n * @see https://developer.mozilla.org/docs/Web/CSS/margin-top\n */\n mt?: StandardCSSProperties['marginTop'];\n /**\n * The **`margin-right`** CSS property sets the margin area on the right side of an element. A positive value places it farther from its neighbors, while a negative value places it closer.\n *\n * **Initial value**: `0`\n *\n * @see https://developer.mozilla.org/docs/Web/CSS/margin-right\n */\n mr?: StandardCSSProperties['marginRight'];\n /**\n * The **`margin-bottom`** CSS property sets the margin area on the bottom of an element. A positive value places it farther from its neighbors, while a negative value places it closer.\n *\n * **Initial value**: `0`\n *\n * @see https://developer.mozilla.org/docs/Web/CSS/margin-bottom\n */\n mb?: StandardCSSProperties['marginBottom'];\n /**\n * The **`margin-left`** CSS property sets the margin area on the left side of an element. A positive value places it farther from its neighbors, while a negative value places it closer.\n *\n * **Initial value**: `0`\n *\n * @see https://developer.mozilla.org/docs/Web/CSS/margin-left\n */\n ml?: StandardCSSProperties['marginLeft'];\n /**\n * The **`mx`** is shorthand for using both **`margin-left`** and **`margin-right`** CSS properties. They set the margin area on the left and right side of an element. A positive value placesit\n * farther from its neighbors, while a negative value places it closer.\n *\n * **Initial value**: `0`\n *\n * @see https://styled-system.com/#margin-props\n * @see https://developer.mozilla.org/docs/Web/CSS/margin-left\n * @see https://developer.mozilla.org/docs/Web/CSS/margin-right\n */\n mx?: StandardCSSProperties['marginLeft'];\n /**\n * The **`marginX`** is shorthand for using both **`margin-left`** and **`margin-right`** CSS properties. They set the margin area on the left and right side of an element. A positive value\n * places it farther from its neighbors, while a negative value places it closer.\n *\n * **Initial value**: `0`\n *\n * @see https://styled-system.com/#margin-props\n * @see https://developer.mozilla.org/docs/Web/CSS/margin-left\n * @see https://developer.mozilla.org/docs/Web/CSS/margin-right\n */\n marginX?: StandardCSSProperties['marginLeft'];\n /**\n * The **`my`** is shorthard for using both **`margin-top`** and **`margin-bottom`** CSS properties. They set the margin area on the top and bottom of an element. A positive value places it\n * farther from its neighbors, while a negative value places it closer.\n *\n * **Initial value**: `0`\n *\n * @see https://styled-system.com/#margin-props\n * @see https://developer.mozilla.org/docs/Web/CSS/margin-top\n * @see https://developer.mozilla.org/docs/Web/CSS/margin-bottom\n */\n my?: StandardCSSProperties['marginTop'];\n /**\n * The **`marginY`** is shorthard for using both **`margin-top`** and **`margin-bottom`** CSS properties. They set the margin area on the top and bottom of an element. A positive value places\n * it farther from its neighbors, while a negative value places it closer.\n *\n * **Initial value**: `0`\n *\n * @see https://styled-system.com/#margin-props\n * @see https://developer.mozilla.org/docs/Web/CSS/margin-top\n * @see https://developer.mozilla.org/docs/Web/CSS/margin-bottom\n */\n marginY?: StandardCSSProperties['marginTop'];\n /**\n * The **`padding`** CSS property sets the padding area on all four sides of an element. It is a shorthand for `padding-top`, `padding-right`, `padding-bottom`, and `padding-left`.\n *\n * @see https://developer.mozilla.org/docs/Web/CSS/padding\n */\n p?: StandardCSSProperties['padding'];\n /**\n * The **`padding-top`** padding area on the top of an element.\n *\n * **Initial value**: `0`\n *\n * @see https://developer.mozilla.org/docs/Web/CSS/padding-top\n */\n pt?: StandardCSSProperties['paddingTop'];\n /**\n * The **`padding-right`** CSS property sets the width of the padding area on the right side of an element.\n *\n * **Initial value**: `0`\n *\n * @see https://developer.mozilla.org/docs/Web/CSS/padding-right\n */\n pr?: StandardCSSProperties['paddingRight'];\n /**\n * The **`padding-bottom`** CSS property sets the height of the padding area on the bottom of an element.\n *\n * **Initial value**: `0`\n *\n * @see https://developer.mozilla.org/docs/Web/CSS/padding-bottom\n */\n pb?: StandardCSSProperties['paddingBottom'];\n /**\n * The **`padding-left`** CSS property sets the width of the padding area on the left side of an element.\n *\n * **Initial value**: `0`\n *\n * @see https://developer.mozilla.org/docs/Web/CSS/padding-left\n */\n pl?: StandardCSSProperties['paddingLeft'];\n /**\n * The **`px`** is shorthand property for CSS properties **`padding-left`** and **`padding-right`**. They set the width of the padding area on the left and right side of an element.\n *\n * **Initial value**: `0`\n *\n * @see https://styled-system.com/#padding-props\n * @see https://developer.mozilla.org/docs/Web/CSS/padding-left\n * @see https://developer.mozilla.org/docs/Web/CSS/padding-right\n */\n px?: StandardCSSProperties['paddingLeft'];\n /**\n * The **`paddingX`** is shorthand property for CSS properties **`padding-left`** and **`padding-right`**. They set the width of the padding area on the left and right side of an element.\n *\n * **Initial value**: `0`\n *\n * @see https://styled-system.com/#padding-props\n * @see https://developer.mozilla.org/docs/Web/CSS/padding-left\n * @see https://developer.mozilla.org/docs/Web/CSS/padding-right\n */\n paddingX?: StandardCSSProperties['paddingLeft'];\n /**\n * The **`py`** is shorthand property for CSS properties **`padding-top`** and **`padding-bottom`**. They set the width of the padding area on the top and bottom of an element.\n *\n * **Initial value**: `0`\n *\n * @see https://styled-system.com/#padding-props\n * @see https://developer.mozilla.org/docs/Web/CSS/padding-top\n * @see https://developer.mozilla.org/docs/Web/CSS/padding-bottom\n */\n py?: StandardCSSProperties['paddingTop'];\n /**\n * The **`paddingY`** is shorthand property for CSS properties **`padding-top`** and **`padding-bottom`**. They set the width of the padding area on the top and bottom of an element.\n *\n * **Initial value**: `0`\n *\n * @see https://styled-system.com/#padding-props\n * @see https://developer.mozilla.org/docs/Web/CSS/padding-top\n * @see https://developer.mozilla.org/docs/Web/CSS/padding-bottom\n */\n paddingY?: StandardCSSProperties['paddingTop'];\n};\n","/**\n * Typings are based on [Reach UI](https://github.com/reach/reach-ui/blob/4cb497f530b0f83f80c6f6f2da46ab55b1160cb6/packages/utils/src/types.tsx).\n */\nimport {\n forwardRef,\n ComponentPropsWithRef,\n ElementType,\n ReactElement,\n ValidationMap,\n WeakValidationMap,\n} from 'react';\n\n/**\n * SystemProps support the `as` and `variant` prop. The former\n * is used to changed the rendered root element of a component.\n *\n * These props also infer additional allowed props based on the\n * value of the `as` prop. For example, setting `as=\"button\"` will\n * allow to use HTMLButtonAttributes on the component.\n */\nexport type SystemProps<P, T extends ElementType> = P &\n Omit<ComponentPropsWithRef<T>, 'as' | keyof P> & {\n as?: T;\n variant?: string;\n };\n\n/**\n * Enhanced version of `React.FunctionComponent` that accepts `SystemProps`\n * and infers allowed properties based on the `as` prop.\n */\nexport interface SystemComponent<P, T extends ElementType> {\n /**\n * These types are a bit of a hack, but cover us in cases where the `as` prop\n * is not a JSX string type. Makes the compiler happy so 🤷‍♂️\n */\n <TT extends ElementType>(props: SystemProps<P, TT>): ReactElement | null;\n (props: SystemProps<P, T>): ReactElement | null;\n\n displayName?: string;\n propTypes?: WeakValidationMap<SystemProps<P, T>>;\n contextTypes?: ValidationMap<any>;\n defaultProps?: Partial<SystemProps<P, T>>;\n}\n\n/**\n * Helper to write components that adhere to a common design system API,\n * which includes the `as` and `variant` prop.\n */\nexport function system<P, T extends ElementType>(\n render: (props: SystemProps<P, T>) => ReactElement | null\n) {\n return forwardRef((props: any, ref) =>\n render({ ...props, ref })\n ) as SystemComponent<P, T>;\n}\n","import React, { createContext, useContext } from 'react';\n\nconst Context = createContext({});\n\nexport const useTheme = () => useContext(Context);\n\nexport type ThemeProviderProps = { theme: any };\nexport const ThemeProvider: React.FC<ThemeProviderProps> = ({\n theme,\n children,\n}) => <Context.Provider value={theme}>{children}</Context.Provider>;\n","import { css as emotion } from 'emotion';\nimport { css, ThemeUIStyleObject } from '@theme-ui/css';\nimport { useTheme } from './useTheme';\n\nexport const useClassname = (...styles: ThemeUIStyleObject[]) => {\n const theme = useTheme();\n return styles.map(style => emotion(css(style)(theme))).join(' ');\n};\n","import { CSSObject } from '@marigold/components/src';\n\nconst base = {\n boxSizing: 'border-box',\n margin: 0,\n padding: 0,\n minWidth: 0,\n fontSize: '100%',\n font: 'inherit',\n verticalAlign: 'baseline',\n WebkitTapHighlightColor: 'transparent',\n};\n\nconst block = {\n display: 'block',\n};\n\nconst body = {\n lineHeight: 1,\n};\n\nconst list = {\n listStyle: 'none',\n};\n\nconst quote = {\n quotes: 'none',\n selectors: {\n '&:before, &:after': {\n content: \"''\",\n },\n },\n};\n\nconst table = {\n borderCollapse: 'collapse',\n borderSpacing: 0,\n};\n\nconst appearance = {\n appearance: 'none',\n};\n\nconst field = [block, appearance];\n\nconst mark = {\n backgroundColor: 'transparent',\n color: 'inherit',\n};\n\nconst select = [\n ...field,\n {\n selectors: {\n '&::-ms-expand': {\n display: 'none',\n },\n },\n },\n];\n\nconst input = [\n ...field,\n {\n selectors: {\n '&::-ms-clear': {\n display: 'none',\n },\n '&::-webkit-search-cancel-button': {\n WebkitAppearance: 'none',\n },\n },\n },\n];\n\nconst button = {\n background: 'none',\n};\n\nconst a = {\n textDecoration: 'none',\n};\n\nexport const el: BaseNormalization = {\n article: block,\n aside: block,\n details: block,\n figcaption: block,\n figure: block,\n footer: block,\n header: block,\n hgroup: block,\n menu: block,\n nav: block,\n section: block,\n ul: list,\n ol: list,\n blockquote: quote,\n q: quote,\n body,\n a,\n base,\n table,\n mark,\n select,\n p: list,\n button,\n textarea: field,\n input,\n};\n\ntype BaseNormalization = {\n [key: string]: CSSObject;\n};\n","import { useClassname } from './useClassname';\n\nimport * as resetStyleRefs from './normalize';\nimport { ElementType } from 'react';\n\nexport type StylesProps = {\n element?: ElementType[];\n variant?: string | string[];\n [key: string]: any;\n};\n\n/**\n * Hook function that can add base styles, normalization, variant and custom styles\n */\nexport const useStyles = (\n { element, variant, ...styles }: StylesProps,\n classNames?: string\n) => {\n /**\n * Normalization styles looked up by html tag name(s). Base normalization\n * is always applied.\n */\n var elementArray: ElementType[] = [];\n if (element) {\n element.push('base'); // always apply base styles\n elementArray = element;\n } else {\n elementArray = ['base'];\n }\n const resetStyles = resetStyleRefs.el;\n const elements: { [key: string]: any }[] = elementArray.map(\n styleObject => resetStyles[styleObject as keyof typeof resetStyleRefs.el]\n );\n\n const elementObject = Object.assign({}, ...elements);\n\n const basedOnNormalize = useClassname(elementObject);\n\n /**\n * Variants are retrieved from the theme.\n */\n const variants = Array.isArray(variant)\n ? variant.map(v => ({ variant: v }))\n : [{ variant }];\n\n const basedOnVariants = useClassname(...variants);\n\n /**\n * Custom styles are applied \"on runtime\". They are usually controlled via component\n * props and can change between component instances. They are more or less the `css`\n * prop of `emotion`.\n */\n const custom = useClassname(styles);\n\n return [basedOnNormalize, basedOnVariants, custom, classNames].join(' ');\n};\n"],"names":["SPACE_PROPS","system","render","forwardRef","props","ref","Context","createContext","useTheme","useContext","ThemeProvider","theme","children","React","Provider","value","useClassname","styles","map","style","emotion","css","join","base","boxSizing","margin","padding","minWidth","fontSize","font","verticalAlign","WebkitTapHighlightColor","block","display","body","lineHeight","list","listStyle","quote","quotes","selectors","content","table","borderCollapse","borderSpacing","appearance","field","mark","backgroundColor","color","select","input","WebkitAppearance","button","background","a","textDecoration","el","article","aside","details","figcaption","figure","footer","header","hgroup","menu","nav","section","ul","ol","blockquote","q","p","textarea","useStyles","classNames","element","variant","elementArray","push","resetStyles","resetStyleRefs","elements","styleObject","elementObject","Object","assign","basedOnNormalize","variants","Array","isArray","v","basedOnVariants","custom"],"mappings":";;;;AAEA;;;AAIA;AACA;IACaA,WAAW,GAAG,CACzB,GADyB,EAEzB,QAFyB,EAGzB,IAHyB,EAIzB,WAJyB,EAKzB,IALyB,EAMzB,aANyB,EAOzB,IAPyB,EAQzB,cARyB,EASzB,IATyB,EAUzB,YAVyB,EAWzB,IAXyB,EAYzB,SAZyB,EAazB,IAbyB,EAczB,SAdyB,EAezB,GAfyB,EAgBzB,SAhByB,EAiBzB,IAjByB,EAkBzB,YAlByB,EAmBzB,IAnByB,EAoBzB,cApByB,EAqBzB,IArByB,EAsBzB,eAtByB,EAuBzB,IAvByB,EAwBzB,aAxByB,EAyBzB,IAzByB,EA0BzB,UA1ByB,EA2BzB,IA3ByB,EA4BzB,UA5ByB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACoC3B;;;;;AAIA,SAAgBC,OACdC;AAEA,SAAOC,UAAU,CAAC,UAACC,KAAD,EAAaC,GAAb;AAAA,WAChBH,MAAM,cAAME,KAAN;AAAaC,MAAAA,GAAG,EAAHA;AAAb,OADU;AAAA,GAAD,CAAjB;AAGD;;ACpDD,IAAMC,OAAO,gBAAGC,aAAa,CAAC,EAAD,CAA7B;AAEA,IAAaC,QAAQ,GAAG,SAAXA,QAAW;AAAA,SAAMC,UAAU,CAACH,OAAD,CAAhB;AAAA,CAAjB;AAGP,IAAaI,aAAa,GAAiC,SAA9CA,aAA8C;AAAA,MACzDC,KADyD,QACzDA,KADyD;AAAA,MAEzDC,QAFyD,QAEzDA,QAFyD;AAAA,SAGrDC,mBAAA,CAACP,OAAO,CAACQ,QAAT;AAAkBC,IAAAA,KAAK,EAAEJ;GAAzB,EAAiCC,QAAjC,CAHqD;AAAA,CAApD;;ICHMI,YAAY,GAAG,SAA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AAwDtD,IAAxD,CAA6D,GAA7D,CAAP;AACD,CAzCM;;;;"}
1
+ {"version":3,"file":"system.esm.js","sources":["../src/normalize.ts","../src/variant.ts","../src/Box.tsx","../src/useTheme.tsx","../src/Global.tsx","../src/SVG.tsx"],"sourcesContent":["/**\n * Normalize styling of certain elements between browsers.\n * Based on https://www.joshwcomeau.com/css/custom-css-reset/\n */\nimport { ElementType } from 'react';\n\nconst base = {\n boxSizing: 'border-box',\n margin: 0,\n minWidth: 0,\n} as const;\n\nconst a = {\n ...base,\n textDecoration: 'none',\n} as const;\n\nconst text = {\n ...base,\n overflowWrap: 'break-word',\n} as const;\n\nconst media = {\n ...base,\n display: 'block',\n maxWidth: '100%',\n} as const;\n\nconst button = {\n ...base,\n display: 'block',\n appearance: 'none',\n font: 'inherit',\n background: 'transparent',\n textAlign: 'center',\n} as const;\n\nconst input = {\n ...base,\n display: 'block',\n appearance: 'none',\n font: 'inherit',\n '&::-ms-clear': {\n display: 'none',\n },\n '&::-webkit-search-cancel-button': {\n WebkitAppearance: 'none',\n },\n} as const;\n\nconst select = {\n ...base,\n display: 'block',\n appearance: 'none',\n font: 'inherit',\n '&::-ms-expand': {\n display: 'none',\n },\n} as const;\n\nconst textarea = {\n ...base,\n display: 'block',\n appearance: 'none',\n font: 'inherit',\n} as const;\n\n// Normalize\n// ---------------\nexport const normalize = {\n base,\n a,\n p: text,\n h1: text,\n h2: text,\n h3: text,\n h4: text,\n h5: text,\n h6: text,\n img: media,\n picture: media,\n video: media,\n canvas: media,\n svg: media,\n select,\n button,\n textarea,\n input,\n} as const;\n\nexport type NormalizedElement = keyof typeof normalize;\n\n/**\n * Type-safe helper to get normalization. If no normalization is found,\n * returns the *base* normalization.\n */\nexport const getNormalizedStyles = (val?: ElementType) =>\n typeof val === 'string' && val in normalize\n ? normalize[val as NormalizedElement] // Typescript doesn't infer this correctly\n : normalize.base;\n","const isNil = (value: any): value is null | undefined =>\n value === null || value === undefined;\n\n/**\n * Ensures that the `val` is an array. Will return an empty array if `val` is falsy.\n */\nexport const ensureArray = <T>(val?: T | T[]) =>\n isNil(val) ? [] : Array.isArray(val) ? val : [val];\n\n/**\n * Removes trailing dot from variant, if necessary. This is necessary to support\n * `__default` styles. See https://github.com/system-ui/theme-ui/pull/951\n */\nexport const ensureVariantDefault = (val: string) => val.replace(/\\.$/, '');\n\n/**\n * Ensures that the `variant` is an array and supports the `__default` key.\n */\nexport const ensureArrayVariant = <T extends string>(variant?: T | T[]) =>\n ensureArray(variant).map(ensureVariantDefault);\n\nexport type State = {\n checked?: boolean;\n focus?: boolean;\n hover?: boolean;\n disabled?: boolean;\n error?: boolean;\n};\n\n/**\n * Appends given `state` to a `variant`.\n */\nexport const appendVariantState = (variant: string, state: keyof State) => {\n return `${ensureVariantDefault(variant)}.:${state}`;\n};\n\n/**\n * Create a variant array from a `variant` and `state` containing\n * passed states, if they are truthy.\n */\nexport const conditional = (\n variant: string,\n { disabled = false, ...states }: State\n) => {\n const entries = [...Object.entries(states), ['disabled', disabled]] as [\n keyof State,\n boolean\n ][];\n const stateVariants = entries\n .filter(([, val]) => Boolean(val))\n .map(([key]) => appendVariantState(variant, key));\n\n return [variant, ...stateVariants];\n};\n","import { jsx, Theme } from '@emotion/react';\nimport { css as transformStyleObject } from '@theme-ui/css';\nimport { forwardRef } from 'react';\nimport {\n PolymorphicPropsWithRef,\n PolymorphicComponentWithRef,\n} from '@marigold/types';\n\nimport { getNormalizedStyles } from './normalize';\nimport { CSSObject } from './types';\nimport { ensureArrayVariant } from './variant';\n\nexport type StyleProps = Pick<\n CSSObject,\n | 'display'\n | 'height'\n | 'width'\n | 'minWidth'\n | 'maxWidth'\n | 'position'\n | 'top'\n | 'bottom'\n | 'right'\n | 'left'\n | 'zIndex'\n | 'p'\n | 'px'\n | 'py'\n | 'pt'\n | 'pb'\n | 'pl'\n | 'pr'\n | 'm'\n | 'mx'\n | 'my'\n | 'mt'\n | 'mb'\n | 'ml'\n | 'mr'\n | 'flexDirection'\n | 'flexWrap'\n | 'flexShrink'\n | 'flexGrow'\n | 'alignItems'\n | 'justifyContent'\n | 'bg'\n | 'border'\n | 'borderRadius'\n | 'boxShadow'\n | 'opacity'\n | 'overflow'\n | 'transition'\n>;\n\nexport type BoxOwnProps = {\n css?: CSSObject;\n variant?: string | string[];\n /**\n * Use to set base styles for the component\n * @internal Used to set default styles for Marigold components\n */\n __baseCSS?: CSSObject;\n} & StyleProps;\n\nexport type BoxProps = PolymorphicPropsWithRef<BoxOwnProps, 'div'>;\n\n/**\n * Check if there is any falsy value or empty object\n */\nconst isNotEmpty = (val: any) =>\n !(val && Object.keys(val).length === 0 && val.constructor === Object);\n\ntype CreateStyleProps = {\n as?: BoxProps['as'];\n __baseCSS?: BoxOwnProps['__baseCSS'];\n variant?: BoxOwnProps['variant'];\n css?: BoxOwnProps['css'];\n styles?: StyleProps;\n};\n\nconst createThemedStyle =\n ({ as, __baseCSS, variant, styles, css }: CreateStyleProps) =>\n (theme: Theme) => {\n return [\n getNormalizedStyles(as),\n transformStyleObject(__baseCSS)(theme),\n ...ensureArrayVariant(variant).map(v =>\n transformStyleObject({ variant: v })(theme)\n ),\n transformStyleObject(styles)(theme),\n transformStyleObject(css)(theme),\n ].filter(isNotEmpty);\n };\n\nexport const Box: PolymorphicComponentWithRef<BoxOwnProps, 'div'> = forwardRef(\n (\n {\n as = 'div',\n children,\n __baseCSS,\n variant,\n css = {},\n display,\n height,\n width,\n minWidth,\n maxWidth,\n position,\n top,\n bottom,\n right,\n left,\n zIndex,\n p,\n px,\n py,\n pt,\n pb,\n pl,\n pr,\n m,\n mx,\n my,\n mt,\n mb,\n ml,\n mr,\n flexDirection,\n flexWrap,\n flexShrink,\n flexGrow,\n alignItems,\n justifyContent,\n bg,\n border,\n borderRadius,\n boxShadow,\n opacity,\n overflow,\n transition,\n ...props\n },\n ref\n ) =>\n jsx(\n as,\n {\n ...props,\n css: createThemedStyle({\n as,\n __baseCSS,\n variant,\n css,\n styles: {\n display,\n height,\n width,\n minWidth,\n maxWidth,\n position,\n top,\n bottom,\n right,\n left,\n zIndex,\n p,\n px,\n py,\n pt,\n pb,\n pl,\n pr,\n m,\n mx,\n my,\n mt,\n mb,\n ml,\n mr,\n flexDirection,\n flexWrap,\n flexShrink,\n flexGrow,\n alignItems,\n justifyContent,\n bg,\n border,\n borderRadius,\n boxShadow,\n opacity,\n overflow,\n transition,\n },\n }),\n ref,\n },\n children\n )\n);\n","import React, {\n createContext,\n ReactNode,\n useCallback,\n useContext,\n} from 'react';\nimport { css as transformStyleObject } from '@theme-ui/css';\nimport { ThemeProvider as EmotionProvider } from '@emotion/react';\n\nimport { Theme } from './theme';\nimport { StyleObject } from './types';\n\n/**\n * @internal\n */\nexport const __defaultTheme: Theme = {};\n\nconst InternalContext = createContext<Theme>(__defaultTheme);\n\nexport const useTheme = () => {\n const theme = useContext(InternalContext);\n /**\n * We cast the theme here to `any` since our subset is not\n * compatible with the typings of `theme-ui`, since they\n * also support arrays as scale values, while we don't.\n */\n const css = useCallback(\n (style: StyleObject) => transformStyleObject(style)(theme as any),\n [theme]\n );\n return { theme, css };\n};\n\nexport type ThemeProviderProps<T extends Theme> = {\n theme: T;\n children: ReactNode;\n};\n\nexport function ThemeProvider<T extends Theme>({\n theme,\n children,\n}: ThemeProviderProps<T>) {\n return (\n <EmotionProvider theme={theme}>\n <InternalContext.Provider value={theme}>\n {children}\n </InternalContext.Provider>\n </EmotionProvider>\n );\n}\n","import React from 'react';\nimport { Global as EmotionGlobal } from '@emotion/react';\nimport { useTheme } from './useTheme';\n\n/**\n * CSS snippet and idea from:\n * https://css-tricks.com/revisiting-prefers-reduced-motion-the-reduced-motion-media-query/\n */\nconst reduceMotionStyles = {\n '@media screen and (prefers-reduced-motion: reduce), (update: slow)': {\n '*': {\n animationDuration: '0.001ms !important',\n animationIterationCount: '1 !important',\n transitionDuration: '0.001ms !important',\n },\n },\n};\n\nexport const Global = () => {\n const { css } = useTheme();\n const styles = css({\n html: {\n height: '100%',\n variant: 'root.html',\n },\n body: {\n height: '100%',\n lineHeight: 1.5,\n WebkitFontSmoothing: 'antialiased',\n variant: 'root.body',\n },\n });\n return <EmotionGlobal styles={{ reduceMotionStyles, ...styles }} />;\n};\n","import React from 'react';\nimport { jsx } from '@emotion/react';\nimport { ComponentProps } from '@marigold/types';\nimport { getNormalizedStyles } from '@marigold/system';\n\nconst css = getNormalizedStyles('svg');\n\nexport type SVGProps = {\n size?: number;\n} & ComponentProps<'svg'>;\n\nexport const SVG: React.FC<SVGProps> = ({ size = 24, children, ...props }) =>\n jsx(\n 'svg',\n {\n width: size,\n height: size,\n viewBox: '0 0 24 24',\n fill: 'currentcolor',\n ...props,\n css,\n },\n children\n );\n"],"names":["base","boxSizing","margin","minWidth","a","textDecoration","text","overflowWrap","media","display","maxWidth","button","appearance","font","background","textAlign","input","WebkitAppearance","select","textarea","normalize","p","h1","h2","h3","h4","h5","h6","img","picture","video","canvas","svg","getNormalizedStyles","val","isNil","value","undefined","ensureArray","Array","isArray","ensureVariantDefault","replace","ensureArrayVariant","variant","map","appendVariantState","state","conditional","disabled","states","entries","Object","stateVariants","filter","Boolean","key","isNotEmpty","keys","length","constructor","createThemedStyle","as","__baseCSS","styles","css","theme","transformStyleObject","v","Box","forwardRef","ref","children","height","width","position","top","bottom","right","left","zIndex","px","py","pt","pb","pl","pr","m","mx","my","mt","mb","ml","mr","flexDirection","flexWrap","flexShrink","flexGrow","alignItems","justifyContent","bg","border","borderRadius","boxShadow","opacity","overflow","transition","props","jsx","__defaultTheme","InternalContext","createContext","useTheme","useContext","useCallback","style","ThemeProvider","React","EmotionProvider","Provider","reduceMotionStyles","animationDuration","animationIterationCount","transitionDuration","Global","html","body","lineHeight","WebkitFontSmoothing","EmotionGlobal","SVG","size","viewBox","fill"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,IAAMA,IAAI,GAAG;AACXC,EAAAA,SAAS,EAAE,YADA;AAEXC,EAAAA,MAAM,EAAE,CAFG;AAG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A,MAAM,EAAE,MADJ;AAEJ7B,MAAAA,OAAO,EAAE;AAFL,KADW;AAKjBkF,IAAAA,IAAI,EAAE;AACJrD,MAAAA,MAAM,EAAE,MADJ;AAEJsD,MAAAA,UAAU,EAAE,GAFR;AAGJC,MAAAA,mBAAmB,EAAE,aAHjB;AAIJpF,MAAAA,OAAO,EAAE;AAJL;AALW,GAAD,CAAlB;AAYA,SAAOyE,mBAAA,CAACY,QAAD;AAAejE,IAAAA,MAAM;AAAIwD,MAAAA,kBAAkB,EAAlBA;AAAJ,OAA2BxD,MAA3B;GAArB,CAAP;AACD,CAfM;;;ACjBP,AAIA,IAAMC,GAAG,gBAAGhC,qBAAmB,CAAC,KAAD,CAA/B;AAMA,IAAaiG,GAAG,GAAuB,SAA1BA,GAA0B;AAAA,uBAAGC,IAAH;AAAA,MAAGA,IAAH,0BAAU,EAAV;AAAA,MAAc3D,QAAd,QAAcA,QAAd;AAAA,MAA2BmC,KAA3B;;AAAA,SACrCC,GAAG,CACD,KADC;AAGClC,IAAAA,KAAK,EAAEyD,IAHR;AAIC1D,IAAAA,MAAM,EAAE0D,IAJT;AAKCC,IAAAA,OAAO,EAAE,WALV;AAMCC,IAAAA,IAAI,EAAE;AANP,KAOI1B,KAPJ;AAQC1C,IAAAA,GAAG,EAAHA;AARD,MAUDO,QAVC,CADkC;AAAA,CAAhC;;;;"}
@@ -0,0 +1,136 @@
1
+ import * as CSS from 'csstype';
2
+ import { NestedScaleDict } from '@theme-ui/css';
3
+ /**
4
+ * Value used to define a scale.
5
+ *
6
+ * Can be nested to support a default value.
7
+ *
8
+ * @example
9
+ * Given a theme
10
+ * ```
11
+ * {
12
+ * colors: {
13
+ * primary: { __default: '#00f', light: '#33f' }
14
+ * }
15
+ * }
16
+ * ```
17
+ * `css{{ color: 'primary' }}` resolves to `color: #00f`.
18
+ */
19
+ export declare type ScaleValue<T> = T | T[] | NestedScaleDict<T> | undefined;
20
+ /**
21
+ * Scales are a set of named, pre-defined CSS values which are used
22
+ * to create consitency in sizing across visual elements. They give
23
+ * plain values semantics meaning.
24
+ *
25
+ * Marigold uses a plain object to define scales, where the key should be a
26
+ * descriptive name for the scale (e.g. `small`/`medium`/.. or `body`/`heading`/...),
27
+ * and the value is the CSS value.
28
+ */
29
+ export declare type Scale<T> = {
30
+ [key: string]: ScaleValue<T>;
31
+ };
32
+ /**
33
+ * Predefined {@link Scale} scale which uses size values.
34
+ */
35
+ export declare type SizeScale<T> = {
36
+ xxsmall?: ScaleValue<T>;
37
+ xsmall?: ScaleValue<T>;
38
+ small?: ScaleValue<T>;
39
+ medium?: ScaleValue<T>;
40
+ large?: ScaleValue<T>;
41
+ xlarge?: ScaleValue<T>;
42
+ xxlarge?: ScaleValue<T>;
43
+ };
44
+ /**
45
+ * A {@link SizeScale} that also includes a required `none` value, which is
46
+ * usually used to define the blank value (e.g `0`).
47
+ */
48
+ export declare type ZeroScale<T> = {
49
+ none: ScaleValue<T>;
50
+ } & Scale<T>;
51
+ /**
52
+ * Base theme with typings for available scales properties.
53
+ */
54
+ export interface Theme {
55
+ /**
56
+ * To configure the default breakpoints used in responsive array values,
57
+ * add a breakpoints array to your theme.
58
+ *
59
+ * Each breakpoint should be a string with a CSS length unit included or a
60
+ * string including a CSS media query. String values with a CSS length unit
61
+ * will be used to generate a mobile-first (i.e. min-width) media query.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * {
66
+ * breakpoints: [
67
+ * '40em', '@media (min-width: 56em) and (orientation: landscape)', '64em',
68
+ * ],
69
+ * }
70
+ * ```
71
+ */
72
+ breakpoints?: Array<string>;
73
+ colors?: Scale<CSS.Property.Color | NestedScaleDict<CSS.Property.Color>>;
74
+ /**
75
+ * Used to define a scale for whitspace values,
76
+ * like `padding`, `margin`, `gap`, etc.
77
+ */
78
+ space?: ZeroScale<CSS.Property.Margin<number | string>>;
79
+ /**
80
+ * Used to define a `font-size` scale.
81
+ */
82
+ fontSizes?: Scale<CSS.Property.FontSize<number>>;
83
+ /**
84
+ * Used to define a `font-family` scale.
85
+ */
86
+ fonts?: Scale<CSS.Property.FontFamily>;
87
+ /**
88
+ * Used to define a `font-weight` scale.
89
+ */
90
+ fontWeights?: Scale<CSS.Property.FontWeight>;
91
+ /**
92
+ * Used to define a `line-height` scale.
93
+ */
94
+ lineHeights?: Scale<CSS.Property.LineHeight<string | 0 | number>>;
95
+ /**
96
+ * Used to define a `letter-spacing` scale.
97
+ */
98
+ letterSpacings?: ZeroScale<CSS.Property.LetterSpacing<string | 0 | number>>;
99
+ /**
100
+ * Used to define a scale for size values,
101
+ * like `height`, `width`, `flexBasis`, etc.
102
+ */
103
+ sizes?: ZeroScale<CSS.Property.Height<{}> | CSS.Property.Width<{}>>;
104
+ /**
105
+ * Used to define different `border` styles.
106
+ */
107
+ borders?: ZeroScale<CSS.Property.Border<{}>>;
108
+ /**
109
+ * Used to define `border-style` styles.
110
+ */
111
+ borderStyles?: Scale<CSS.Property.Border<{}>>;
112
+ /**
113
+ * Used to define `border-width` styles.
114
+ */
115
+ borderWidths?: ZeroScale<CSS.Property.BorderWidth<string | 0 | number>>;
116
+ /**
117
+ * Used to define `border-radius` styles.
118
+ */
119
+ radii?: ZeroScale<CSS.Property.BorderRadius<string | 0 | number>>;
120
+ /**
121
+ * Used to define `Shadow` styles.
122
+ */
123
+ shadows?: ZeroScale<CSS.Property.BoxShadow>;
124
+ /**
125
+ * Used to define a `z-index` scake.
126
+ */
127
+ zIndices?: Scale<CSS.Property.ZIndex>;
128
+ /**
129
+ * Used to define a `opacity` scale.
130
+ */
131
+ opacities?: Scale<CSS.Property.Opacity>;
132
+ /**
133
+ * Used to define a `transition` styles.
134
+ */
135
+ transitions?: ZeroScale<CSS.Property.Transition>;
136
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Create type aliases for `theme-ui` so that it doesn't leak too much into our code.
3
+ */
4
+ import { ThemeUIStyleObject, ThemeUICSSObject, ThemeUICSSProperties, ResponsiveStyleValue as RSV } from '@theme-ui/css';
5
+ export declare type ResponsiveStyleValue<T> = RSV<T>;
6
+ export declare type StyleObject = ThemeUIStyleObject;
7
+ export declare type CSSObject = ThemeUICSSObject;
8
+ export declare type CSSProperties = ThemeUICSSProperties;
@@ -1,6 +1,16 @@
1
- import React from 'react';
2
- export declare const useTheme: () => {};
3
- export declare type ThemeProviderProps = {
4
- theme: any;
1
+ import { ReactNode } from 'react';
2
+ import { Theme } from './theme';
3
+ import { StyleObject } from './types';
4
+ /**
5
+ * @internal
6
+ */
7
+ export declare const __defaultTheme: Theme;
8
+ export declare const useTheme: () => {
9
+ theme: Theme;
10
+ css: (style: StyleObject) => import("@theme-ui/css").CSSObject;
5
11
  };
6
- export declare const ThemeProvider: React.FC<ThemeProviderProps>;
12
+ export declare type ThemeProviderProps<T extends Theme> = {
13
+ theme: T;
14
+ children: ReactNode;
15
+ };
16
+ export declare function ThemeProvider<T extends Theme>({ theme, children, }: ThemeProviderProps<T>): JSX.Element;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Ensures that the `val` is an array. Will return an empty array if `val` is falsy.
3
+ */
4
+ export declare const ensureArray: <T>(val?: T | T[] | undefined) => T[];
5
+ /**
6
+ * Removes trailing dot from variant, if necessary. This is necessary to support
7
+ * `__default` styles. See https://github.com/system-ui/theme-ui/pull/951
8
+ */
9
+ export declare const ensureVariantDefault: (val: string) => string;
10
+ /**
11
+ * Ensures that the `variant` is an array and supports the `__default` key.
12
+ */
13
+ export declare const ensureArrayVariant: <T extends string>(variant?: T | T[] | undefined) => string[];
14
+ export declare type State = {
15
+ checked?: boolean;
16
+ focus?: boolean;
17
+ hover?: boolean;
18
+ disabled?: boolean;
19
+ error?: boolean;
20
+ };
21
+ /**
22
+ * Appends given `state` to a `variant`.
23
+ */
24
+ export declare const appendVariantState: (variant: string, state: keyof State) => string;
25
+ /**
26
+ * Create a variant array from a `variant` and `state` containing
27
+ * passed states, if they are truthy.
28
+ */
29
+ export declare const conditional: (variant: string, { disabled, ...states }: State) => string[];
package/package.json CHANGED
@@ -1,21 +1,19 @@
1
1
  {
2
2
  "name": "@marigold/system",
3
- "version": "0.0.2",
3
+ "version": "0.3.0",
4
4
  "description": "Marigold System Library",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/system.esm.js",
7
7
  "typings": "dist/index.d.ts",
8
8
  "license": "MIT",
9
9
  "dependencies": {
10
- "emotion": "10.0.27",
11
- "@theme-ui/css": "0.4.0-rc.13"
10
+ "@emotion/react": "11.7.1",
11
+ "@theme-ui/css": "0.13.1",
12
+ "csstype": "3.0.10"
12
13
  },
13
14
  "peerDependencies": {
14
- "react": "^16.x",
15
- "react-dom": "^16.x"
16
- },
17
- "devDependencies": {
18
- "csstype": "3.0.6"
15
+ "react": "^16.x || ^17.0.0",
16
+ "react-dom": "^16.x || ^17.0.0"
19
17
  },
20
18
  "scripts": {
21
19
  "build": "tsdx build --tsconfig tsconfig.build.json --transpileOnly",
@@ -0,0 +1,308 @@
1
+ import React from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
+ import { ThemeProvider } from './useTheme';
4
+ import { Box, StyleProps } from './Box';
5
+ import { normalize } from './normalize';
6
+
7
+ const theme = {
8
+ colors: {
9
+ primary: 'black',
10
+ secondary: 'hotpink',
11
+ black: '#000',
12
+ white: '#fff',
13
+ blue: 'cornflowerblue',
14
+ },
15
+ fontSizes: {
16
+ body: 16,
17
+ small: 12,
18
+ large: 24,
19
+ },
20
+ space: {
21
+ none: 0,
22
+ xsmall: 2,
23
+ small: 4,
24
+ medium: 8,
25
+ large: 16,
26
+ },
27
+ sizes: {
28
+ none: 0,
29
+ small: 8,
30
+ medium: 16,
31
+ large: 32,
32
+ },
33
+ borders: { none: 'none', regular: '1px solid black' },
34
+ radii: { none: 0, small: 2, medium: 4 },
35
+ opacities: {
36
+ hidden: 0,
37
+ faded: 0.5,
38
+ visible: 1,
39
+ },
40
+ transitions: { none: 'none', regular: '1s opacity' },
41
+ shadows: {
42
+ none: 'none',
43
+ regular: '3px 3px 5px 6px #ccc',
44
+ inset: 'inset 0 0 10px #000000',
45
+ },
46
+ text: {
47
+ body: {
48
+ fontSize: 'body',
49
+ color: 'primary',
50
+ bg: 'white',
51
+ },
52
+ headline1: {
53
+ fontSize: 'large',
54
+ color: 'secondary',
55
+ },
56
+ whitespace: {
57
+ p: 'medium',
58
+ },
59
+ },
60
+ variant: {
61
+ spacing: {
62
+ m: 'large',
63
+ p: 'large',
64
+ },
65
+ },
66
+ };
67
+
68
+ test('renders a <div> by default', () => {
69
+ render(<Box>Test</Box>);
70
+ const testelem = screen.getByText('Test');
71
+
72
+ expect(testelem instanceof HTMLDivElement).toBeTruthy();
73
+ });
74
+
75
+ test('changes rendered element via "as" prop', () => {
76
+ render(<Box as="p">Test</Box>);
77
+ const testelem = screen.getByText('Test');
78
+
79
+ expect(testelem instanceof HTMLParagraphElement).toBeTruthy();
80
+ });
81
+
82
+ test('supports custom className', () => {
83
+ render(<Box className="my-custom-class">Test</Box>);
84
+ const element = screen.getByText('Test');
85
+
86
+ expect(element.getAttribute('class')).toMatch('my-custom-class');
87
+ });
88
+
89
+ test('passes down HTML attributes', () => {
90
+ render(
91
+ <Box className="my-custom-class" id="element-id" disabled>
92
+ Test
93
+ </Box>
94
+ );
95
+ const element = screen.getByText('Test');
96
+
97
+ expect(element.getAttribute('id')).toEqual('element-id');
98
+ expect(element.getAttribute('disabled')).toMatch('');
99
+ });
100
+
101
+ test('forwards ref', () => {
102
+ const ref = React.createRef<HTMLButtonElement>();
103
+ render(
104
+ <Box as="button" ref={ref}>
105
+ button
106
+ </Box>
107
+ );
108
+
109
+ expect(ref.current instanceof HTMLButtonElement).toBeTruthy();
110
+ });
111
+
112
+ test('apply normalized styles', () => {
113
+ render(<Box>Test</Box>);
114
+ const element = screen.getByText('Test');
115
+ const { base } = normalize;
116
+
117
+ // Smoketest
118
+ expect(element).toHaveStyle(`box-sizing: ${base.boxSizing}`);
119
+ expect(element).toHaveStyle(`margin: ${base.margin}px`);
120
+ expect(element).toHaveStyle(`min-width: ${base.minWidth}`);
121
+ });
122
+
123
+ test('base normalization is always applied', () => {
124
+ render(<Box as="button">Test</Box>);
125
+ const element = screen.getByText('Test');
126
+ const { base } = normalize;
127
+
128
+ expect(element).toHaveStyle(`box-sizing: ${base.boxSizing}`);
129
+ expect(element).toHaveStyle(`margin: ${base.margin}px`);
130
+ expect(element).toHaveStyle(`min-width: ${base.minWidth}`);
131
+ });
132
+
133
+ test('apply normalized styles based on element', () => {
134
+ render(<Box as="h1">Test</Box>);
135
+ const element = screen.getByText('Test');
136
+ const { h1 } = normalize;
137
+
138
+ expect(element).toHaveStyle(`overflow-wrap: ${h1.overflowWrap}`);
139
+ });
140
+
141
+ test('accepts default styling via "__baseCSS" prop', () => {
142
+ render(<Box __baseCSS={{ color: 'hotpink' }}>Test</Box>);
143
+ const element = screen.getByText('Test');
144
+
145
+ expect(element).toHaveStyle('color: hotpink');
146
+ });
147
+
148
+ test('default styling overrides normalization', () => {
149
+ render(
150
+ <ThemeProvider theme={theme}>
151
+ <Box __baseCSS={{ m: 'medium' }}>Test</Box>
152
+ </ThemeProvider>
153
+ );
154
+ const element = screen.getByText('Test');
155
+
156
+ expect(element).toHaveStyle(`margin: ${theme.space.medium}px`);
157
+ });
158
+
159
+ test('variants are applied correctly', () => {
160
+ render(
161
+ <ThemeProvider theme={theme}>
162
+ <Box variant="text.body">Test</Box>
163
+ </ThemeProvider>
164
+ );
165
+ const element = screen.getByText('Test');
166
+
167
+ expect(element).toHaveStyle(`font-size: ${theme.fontSizes.body}px`);
168
+ expect(element).toHaveStyle(`color: ${theme.colors.primary}`);
169
+ });
170
+
171
+ test('accept an array of variants', () => {
172
+ render(
173
+ <ThemeProvider theme={theme}>
174
+ <Box as="p" variant={['text.headline1', 'text.whitespace']}>
175
+ Test
176
+ </Box>
177
+ </ThemeProvider>
178
+ );
179
+ const element = screen.getByText('Test');
180
+
181
+ expect(element).toHaveStyle(`font-size: ${theme.fontSizes.large}px`);
182
+ expect(element).toHaveStyle(`color: ${theme.colors.secondary}`);
183
+ expect(element).toHaveStyle(`padding: ${theme.space.medium}px`);
184
+ });
185
+
186
+ test('variants override normalization and default styles', () => {
187
+ render(
188
+ <ThemeProvider theme={theme}>
189
+ <Box __baseCSS={{ p: 'small' }} variant="variant.spacing">
190
+ Test
191
+ </Box>
192
+ </ThemeProvider>
193
+ );
194
+ const element = screen.getByText('Test');
195
+
196
+ expect(element).toHaveStyle(`margin: ${theme.space.large}px`);
197
+ expect(element).toHaveStyle(`padding: ${theme.space.large}px`);
198
+ });
199
+
200
+ test.each([
201
+ [{ display: 'flex' }, 'display: flex'],
202
+ [{ height: 'small' }, 'height: 8px'],
203
+ [{ width: 'medium' }, 'width: 16px'],
204
+ [{ minWidth: 'small' }, 'min-width: 8px'],
205
+ [{ maxWidth: 'large' }, 'max-width: 32px'],
206
+ [{ position: 'absolute' }, 'position: absolute'],
207
+ [{ top: 'none' }, 'top: 0px'],
208
+ [{ bottom: 'xsmall' }, 'bottom: 2px'],
209
+ [{ right: 'medium' }, 'right: 8px'],
210
+ [{ left: 'small' }, 'left: 4px'],
211
+ [{ zIndex: 1000 }, 'z-index: 1000'],
212
+ [{ p: 'xsmall' }, 'padding: 2px'],
213
+ [{ px: 'xsmall' }, 'padding-left: 2px', 'padding-right: 2px'],
214
+ [{ py: 'small' }, 'padding-top: 4px', 'padding-bottom: 4px'],
215
+ [{ pt: 'xsmall' }, 'padding-top: 2px'],
216
+ [{ pb: 'xsmall' }, 'padding-bottom: 2px'],
217
+ [{ pl: 'xsmall' }, 'padding-left: 2px'],
218
+ [{ pr: 'xsmall' }, 'padding-right: 2px'],
219
+ [{ m: 'xsmall' }, 'margin: 2px'],
220
+ [{ mx: 'xsmall' }, 'margin-left: 2px', 'margin-right: 2px'],
221
+ [{ my: 'small' }, 'margin-top: 4px', 'margin-bottom: 4px'],
222
+ [{ mt: 'xsmall' }, 'margin-top: 2px'],
223
+ [{ mb: 'xsmall' }, 'margin-bottom: 2px'],
224
+ [{ ml: 'xsmall' }, 'margin-left: 2px'],
225
+ [{ mr: 'xsmall' }, 'margin-right: 2px'],
226
+ [{ flexDirection: 'column' }, 'flex-direction: column'],
227
+ [{ flexWrap: 'wrap' }, 'flex-wrap: wrap'],
228
+ [{ flexShrink: 5 }, 'flex-shrink: 5'],
229
+ [{ flexGrow: 1 }, 'flex-grow: 1'],
230
+ [{ alignItems: 'baseline' }, 'align-items: baseline'],
231
+ [{ justifyContent: 'space-between' }, 'justify-content: space-between'],
232
+ [{ bg: 'secondary' }, 'background-color: hotpink'],
233
+ [{ border: 'regular' }, 'border: 1px solid black'],
234
+ [{ borderRadius: 'medium' }, 'border-radius: 4px'],
235
+ [{ boxShadow: 'regular' }, 'box-shadow: 3px 3px 5px 6px #ccc'],
236
+ [{ opacity: 'faded' }, 'opacity: 0.5'],
237
+ [{ overflow: 'hidden' }, 'overflow: hidden'],
238
+ [{ transition: 'regular' }, 'transition: 1s opacity'],
239
+ ])('supports style prop (%o)', (...args) => {
240
+ const props = args.shift() as StyleProps;
241
+
242
+ render(
243
+ <ThemeProvider theme={theme}>
244
+ <Box {...props}>What's in the box!</Box>
245
+ </ThemeProvider>
246
+ );
247
+
248
+ const box = screen.getByText(`What's in the box!`);
249
+ args.forEach((style: any) => {
250
+ expect(box).toHaveStyle(style);
251
+ });
252
+ });
253
+
254
+ test('style props override normalization, defaults and variants', () => {
255
+ render(
256
+ <ThemeProvider theme={theme}>
257
+ <Box
258
+ __baseCSS={{ p: 'small' }}
259
+ variant="text.body"
260
+ bg="blue"
261
+ m="medium"
262
+ p="large"
263
+ >
264
+ Test
265
+ </Box>
266
+ </ThemeProvider>
267
+ );
268
+ const element = screen.getByText('Test');
269
+
270
+ expect(element).toHaveStyle(`margin: ${theme.space.medium}px`); // overrides normalization
271
+ expect(element).toHaveStyle(`padding: ${theme.space.large}px`); // overrides default
272
+ expect(element).toHaveStyle(`background: ${theme.colors.blue}`); // overrides variant
273
+ });
274
+
275
+ test('apply custom styling via css prop', () => {
276
+ render(
277
+ <ThemeProvider theme={theme}>
278
+ <Box css={{ color: 'secondary', padding: '1rem' }}>Test</Box>
279
+ </ThemeProvider>
280
+ );
281
+ const element = screen.getByText('Test');
282
+
283
+ expect(element).toHaveStyle(`padding: 1rem`);
284
+ expect(element).toHaveStyle(`color: ${theme.colors.secondary}`);
285
+ });
286
+
287
+ test('custom styling overrides normalization, defaults, variants and style props', () => {
288
+ render(
289
+ <ThemeProvider theme={theme}>
290
+ <Box
291
+ __baseCSS={{ p: 'small' }}
292
+ variant="text.body"
293
+ bg="black"
294
+ css={{ fontSize: 'large', m: 'small', p: 'large', bg: 'blue' }}
295
+ >
296
+ Test
297
+ </Box>
298
+ </ThemeProvider>
299
+ );
300
+ const element = screen.getByText('Test');
301
+
302
+ expect(element).toHaveStyle(`margin: ${theme.space.small}px`); // overrides normalization
303
+ expect(element).toHaveStyle(`padding: ${theme.space.large}px`); // overrides default
304
+ expect(element).toHaveStyle(`font-size: ${theme.fontSizes.large}px`); // overrides variant
305
+ expect(element).toHaveStyle(`background: ${theme.colors.blue}`); // overrides style prop
306
+
307
+ expect(element).not.toHaveStyle(`color: ${theme.colors.primary}px`); // variant part that is not overriden
308
+ });