@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,2 +1,2 @@
1
- "use strict";var e,n=require("react"),t=(e=n)&&"object"==typeof e&&"default"in e?e.default:e,r=require("emotion"),a=require("@theme-ui/css");function o(){return(o=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}var i=n.createContext({}),s=function(){return n.useContext(i)},c=function(){for(var e=s(),n=arguments.length,t=new Array(n),o=0;o<n;o++)t[o]=arguments[o];return t.map((function(n){return r.css(a.css(n)(e))})).join(" ")},p={display:"block"},l={listStyle:"none"},u={quotes:"none",selectors:{"&:before, &:after":{content:"''"}}},d=[p,{appearance:"none"}],m={article:p,aside:p,details:p,figcaption:p,figure:p,footer:p,header:p,hgroup:p,menu:p,nav:p,section:p,ul:l,ol:l,blockquote:u,q:u,body:{lineHeight:1},a:{textDecoration:"none"},base:{boxSizing:"border-box",margin:0,padding:0,minWidth:0,fontSize:"100%",font:"inherit",verticalAlign:"baseline",WebkitTapHighlightColor:"transparent"},table:{borderCollapse:"collapse",borderSpacing:0},mark:{backgroundColor:"transparent",color:"inherit"},select:[].concat(d,[{selectors:{"&::-ms-expand":{display:"none"}}}]),p:l,button:{background:"none"},textarea:d,input:[].concat(d,[{selectors:{"&::-ms-clear":{display:"none"},"&::-webkit-search-cancel-button":{WebkitAppearance:"none"}}}])};exports.SPACE_PROPS=["m","margin","mt","marginTop","mr","marginRight","mb","marginBottom","ml","marginLeft","mx","marginX","my","marginY","p","padding","pt","paddingTop","pr","paddingRight","pb","paddingBottom","pl","paddingLeft","px","paddingX","py","paddingY"],exports.ThemeProvider=function(e){return t.createElement(i.Provider,{value:e.theme},e.children)},exports.system=function(e){return n.forwardRef((function(n,t){return e(o({},n,{ref:t}))}))},exports.useClassname=c,exports.useStyles=function(e,n){var t=e.element,r=e.variant,a=function(e,n){if(null==e)return{};var t,r,a={},o=Object.keys(e);for(r=0;r<o.length;r++)n.indexOf(t=o[r])>=0||(a[t]=e[t]);return a}(e,["element","variant"]),o=[];t?(t.push("base"),o=t):o=["base"];var i=m,s=o.map((function(e){return i[e]})),p=Object.assign.apply(Object,[{}].concat(s)),l=c(p),u=Array.isArray(r)?r.map((function(e){return{variant:e}})):[{variant:r}];return[l,c.apply(void 0,u),c(a),n].join(" ")},exports.useTheme=s;
1
+ "use strict";var e,t=require("@emotion/react"),r=require("@theme-ui/css"),n=require("react"),i=(e=n)&&"object"==typeof e&&"default"in e?e.default:e,o=require("@marigold/system");function a(){return(a=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function s(e,t){if(null==e)return{};var r,n,i={},o=Object.keys(e);for(n=0;n<o.length;n++)t.indexOf(r=o[n])>=0||(i[r]=e[r]);return i}var l={boxSizing:"border-box",margin:0,minWidth:0},c=a({},l,{textDecoration:"none"}),p=a({},l,{overflowWrap:"break-word"}),u=a({},l,{display:"block",maxWidth:"100%"}),d=a({},l,{display:"block",appearance:"none",font:"inherit",background:"transparent",textAlign:"center"}),m=a({},l,{display:"block",appearance:"none",font:"inherit","&::-ms-clear":{display:"none"},"&::-webkit-search-cancel-button":{WebkitAppearance:"none"}}),h={base:l,a:c,p:p,h1:p,h2:p,h3:p,h4:p,h5:p,h6:p,img:u,picture:u,video:u,canvas:u,svg:u,select:a({},l,{display:"block",appearance:"none",font:"inherit","&::-ms-expand":{display:"none"}}),button:d,textarea:a({},l,{display:"block",appearance:"none",font:"inherit"}),input:m},f=function(e){return"string"==typeof e&&e in h?h[e]:h.base},b=["disabled"],x=function(e){return null==e?[]:Array.isArray(e)?e:[e]},y=function(e){return e.replace(/\.$/,"")},v=function(e){return x(e).map(y)},g=function(e,t){return y(e)+".:"+t},S=["as","children","__baseCSS","variant","css","display","height","width","minWidth","maxWidth","position","top","bottom","right","left","zIndex","p","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"],w=function(e){return!(e&&0===Object.keys(e).length&&e.constructor===Object)},k=function(e){var t=e.as,n=e.__baseCSS,i=e.variant,o=e.styles,a=e.css;return function(e){return[f(t),r.css(n)(e)].concat(v(i).map((function(t){return r.css({variant:t})(e)})),[r.css(o)(e),r.css(a)(e)]).filter(w)}},W=n.forwardRef((function(e,r){var n=e.as,i=void 0===n?"div":n,o=e.children,l=e.__baseCSS,c=e.variant,p=e.css,u=void 0===p?{}:p,d=e.display,m=e.height,h=e.width,f=e.minWidth,b=e.maxWidth,x=e.position,y=e.top,v=e.bottom,g=e.right,w=e.left,W=e.zIndex,j=e.p,C=e.px,_=e.py,z=e.pt,O=e.pb,D=e.pl,I=e.pr,A=e.m,G=e.mx,q=e.my,P=e.mt,R=e.mb,T=e.ml,V=e.mr,B=e.flexDirection,E=e.flexWrap,N=e.flexShrink,F=e.flexGrow,H=e.alignItems,M=e.justifyContent,$=e.bg,J=e.border,K=e.borderRadius,L=e.boxShadow,Q=e.opacity,U=e.overflow,X=e.transition,Y=s(e,S);return t.jsx(i,a({},Y,{css:k({as:i,__baseCSS:l,variant:c,css:u,styles:{display:d,height:m,width:h,minWidth:f,maxWidth:b,position:x,top:y,bottom:v,right:g,left:w,zIndex:W,p:j,px:C,py:_,pt:z,pb:O,pl:D,pr:I,m:A,mx:G,my:q,mt:P,mb:R,ml:T,mr:V,flexDirection:B,flexWrap:E,flexShrink:N,flexGrow:F,alignItems:H,justifyContent:M,bg:$,border:J,borderRadius:K,boxShadow:L,opacity:Q,overflow:U,transition:X}}),ref:r}),o)})),j={},C=n.createContext(j),_=function(){var e=n.useContext(C),t=n.useCallback((function(t){return r.css(t)(e)}),[e]);return{theme:e,css:t}},z={"@media screen and (prefers-reduced-motion: reduce), (update: slow)":{"*":{animationDuration:"0.001ms !important",animationIterationCount:"1 !important",transitionDuration:"0.001ms !important"}}},O=["size","children"],D=o.getNormalizedStyles("svg");exports.Box=W,exports.Global=function(){var e=(0,_().css)({html:{height:"100%",variant:"root.html"},body:{height:"100%",lineHeight:1.5,WebkitFontSmoothing:"antialiased",variant:"root.body"}});return i.createElement(t.Global,{styles:a({reduceMotionStyles:z},e)})},exports.SVG=function(e){var r=e.size,n=void 0===r?24:r,i=e.children,o=s(e,O);return t.jsx("svg",a({width:n,height:n,viewBox:"0 0 24 24",fill:"currentcolor"},o,{css:D}),i)},exports.ThemeProvider=function(e){var r=e.theme;return i.createElement(t.ThemeProvider,{theme:r},i.createElement(C.Provider,{value:r},e.children))},exports.__defaultTheme=j,exports.appendVariantState=g,exports.conditional=function(e,t){var r=t.disabled,n=void 0!==r&&r,i=s(t,b),o=[].concat(Object.entries(i),[["disabled",n]]).filter((function(e){return Boolean(e[1])})).map((function(t){return g(e,t[0])}));return[e].concat(o)},exports.ensureArray=x,exports.ensureArrayVariant=v,exports.ensureVariantDefault=y,exports.getNormalizedStyles=f,exports.normalize=h,exports.useTheme=_;
2
2
  //# sourceMappingURL=system.cjs.production.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"system.cjs.production.min.js","sources":["../src/useTheme.tsx","../src/useClassname.ts","../src/normalize.ts","../src/categories.ts","../src/system.tsx","../src/useStyles.ts"],"sourcesContent":["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 { 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 { 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":["Context","createContext","useTheme","useContext","useClassname","theme","styles","map","style","emotion","css","join","block","display","list","listStyle","quote","quotes","selectors","content","field","appearance","el","article","aside","details","figcaption","figure","footer","header","hgroup","menu","nav","section","ul","ol","blockquote","q","body","lineHeight","a","textDecoration","base","boxSizing","margin","padding","minWidth","fontSize","font","verticalAlign","WebkitTapHighlightColor","table","borderCollapse","borderSpacing","mark","backgroundColor","color","select","p","button","background","textarea","input","WebkitAppearance","React","Provider","value","children","render","forwardRef","props","ref","classNames","element","variant","elementArray","push","resetStyles","resetStyleRefs","elements","styleObject","elementObject","Object","assign","basedOnNormalize","variants","Array","isArray","v"],"mappings":"4VAEA,IAAMA,EAAUC,gBAAc,IAEjBC,EAAW,kBAAMC,aAAWH,ICA5BI,EAAe,mBACpBC,EAAQH,uBADgBI,2BAAAA,yBAEvBA,EAAOC,KAAI,SAAAC,UAASC,MAAQC,MAAIF,EAAJE,CAAWL,OAASM,KAAK,MCOxDC,EAAQ,CACZC,QAAS,SAOLC,EAAO,CACXC,UAAW,QAGPC,EAAQ,CACZC,OAAQ,OACRC,UAAW,qBACY,CACnBC,QAAS,QAcTC,EAAQ,CAACR,EAJI,CACjBS,WAAY,SA2CDC,EAAwB,CACnCC,QAASX,EACTY,MAAOZ,EACPa,QAASb,EACTc,WAAYd,EACZe,OAAQf,EACRgB,OAAQhB,EACRiB,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WA,CAACU,EATgBhF,eAAgBiF,GAOzBjF,EAAaE,GAEuBkE,GAAY7D,KAAK"}
1
+ {"version":3,"file":"system.cjs.production.min.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","normalize","p","h1","h2","h3","h4","h5","h6","img","picture","video","canvas","svg","select","textarea","getNormalizedStyles","val","ensureArray","value","Array","isArray","ensureVariantDefault","replace","ensureArrayVariant","variant","map","appendVariantState","state","isNotEmpty","Object","keys","length","constructor","createThemedStyle","as","__baseCSS","styles","css","theme","transformStyleObject","v","filter","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","reduceMotionStyles","animationDuration","animationIterationCount","transitionDuration","html","body","lineHeight","WebkitFontSmoothing","React","EmotionGlobal","size","viewBox","fill","EmotionProvider","Provider","disabled","states","stateVariants","entries","Boolean"],"mappings":"qgBAMA,IAAMA,EAAO,CACXC,UAAW,aACXC,OAAQ,EACRC,SAAU,GAGNC,OACDJ,GACHK,eAAgB,SAGZC,OACDN,GACHO,aAAc,eAGVC,OACDR,GACHS,QAAS,QACTC,SAAU,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AC,aAAAA,EACAC,UAAAA,EACAC,QAAAA,EACAC,SAAAA,EACAC,WAAAA,KAGJnC,IAAAA,IAEFC,MCrLOqC,EAAwB,GAE/BC,EAAkBC,gBAAqBF,GAEhCG,EAAW,eAChB/C,EAAQgD,aAAWH,GAMnB9C,EAAMkD,eACV,SAACC,UAAuBjD,MAAqBiD,EAArBjD,CAA4BD,KACpD,CAACA,UAEI,CAAEA,MAAAA,EAAOD,IAAAA,ICtBZoD,EAAqB,sEAC6C,KAC/D,CACHC,kBAAmB,qBACnBC,wBAAyB,eACzBC,mBAAoB,8CCRpBvD,EAAMtB,sBAAoB,oCDaV,eAEdqB,GAASC,EADCgD,IAARhD,KACW,CACjBwD,KAAM,CACJ/C,OAAQ,OACRtB,QAAS,aAEXsE,KAAM,CACJhD,OAAQ,OACRiD,WAAY,IACZC,oBAAqB,cACrBxE,QAAS,sBAGNyE,gBAACC,UAAc9D,UAAUqD,mBAAAA,GAAuBrD,kBCrBlB,oBAAG+D,KAAAA,aAAO,KAAItD,IAAAA,SAAamC,gBAChEC,MACE,SAEElC,MAAOoD,EACPrD,OAAQqD,EACRC,QAAS,YACTC,KAAM,gBACHrB,GACH3C,IAAAA,IAEFQ,0CFiBFP,IAAAA,aAIE2D,gBAACK,iBAAgBhE,MAAOA,GACtB2D,gBAACd,EAAgBoB,UAASrF,MAAOoB,KAJrCO,sFFAyB,SACzBrB,aACEgF,SAAAA,gBAAqBC,SAMjBC,YAJc7E,OAAO8E,QAAQF,IAAS,CAAC,WAAYD,KAKtD/D,QAAO,mBAAamE,iBACpBnF,KAAI,mBAAWC,EAAmBF,kBAE7BA,UAAYkF"}
@@ -1,13 +1,7 @@
1
- import React, { forwardRef, useContext, createContext } from 'react';
2
- import { css } from 'emotion';
1
+ import { jsx, ThemeProvider as ThemeProvider$1, Global as Global$1 } from '@emotion/react';
3
2
  import { css as css$1 } from '@theme-ui/css';
4
-
5
- /**
6
- * System categories are based on https://primer.style/components/docs/system-props
7
- */
8
- // Spacing
9
- // ---------------
10
- var SPACE_PROPS = ['m', 'margin', 'mt', 'marginTop', 'mr', 'marginRight', 'mb', 'marginBottom', 'ml', 'marginLeft', 'mx', 'marginX', 'my', 'marginY', 'p', 'padding', 'pt', 'paddingTop', 'pr', 'paddingRight', 'pb', 'paddingBottom', 'pl', 'paddingLeft', 'px', 'paddingX', 'py', 'paddingY'];
3
+ import React, { forwardRef, useContext, useCallback, createContext } from 'react';
4
+ import { getNormalizedStyles as getNormalizedStyles$1 } from '@marigold/system';
11
5
 
12
6
  function _extends() {
13
7
  _extends = Object.assign || function (target) {
@@ -42,183 +36,357 @@ function _objectWithoutPropertiesLoose(source, excluded) {
42
36
  return target;
43
37
  }
44
38
 
45
- /**
46
- * Helper to write components that adhere to a common design system API,
47
- * which includes the `as` and `variant` prop.
48
- */
39
+ var base = {
40
+ boxSizing: 'border-box',
41
+ margin: 0,
42
+ minWidth: 0
43
+ };
49
44
 
50
- function system(render) {
51
- return forwardRef(function (props, ref) {
52
- return render(_extends({}, props, {
53
- ref: ref
54
- }));
55
- });
56
- }
45
+ var a = /*#__PURE__*/_extends({}, base, {
46
+ textDecoration: 'none'
47
+ });
57
48
 
58
- var Context = /*#__PURE__*/createContext({});
59
- var useTheme = function useTheme() {
60
- return useContext(Context);
61
- };
62
- var ThemeProvider = function ThemeProvider(_ref) {
63
- var theme = _ref.theme,
64
- children = _ref.children;
65
- return React.createElement(Context.Provider, {
66
- value: theme
67
- }, children);
68
- };
49
+ var text = /*#__PURE__*/_extends({}, base, {
50
+ overflowWrap: 'break-word'
51
+ });
69
52
 
70
- var useClassname = function useClassname() {
71
- var theme = useTheme();
53
+ var media = /*#__PURE__*/_extends({}, base, {
54
+ display: 'block',
55
+ maxWidth: '100%'
56
+ });
72
57
 
73
- for (var _len = arguments.length, styles = new Array(_len), _key = 0; _key < _len; _key++) {
74
- styles[_key] = arguments[_key];
75
- }
58
+ var button = /*#__PURE__*/_extends({}, base, {
59
+ display: 'block',
60
+ appearance: 'none',
61
+ font: 'inherit',
62
+ background: 'transparent',
63
+ textAlign: 'center'
64
+ });
76
65
 
77
- return styles.map(function (style) {
78
- return css(css$1(style)(theme));
79
- }).join(' ');
80
- };
66
+ var input = /*#__PURE__*/_extends({}, base, {
67
+ display: 'block',
68
+ appearance: 'none',
69
+ font: 'inherit',
70
+ '&::-ms-clear': {
71
+ display: 'none'
72
+ },
73
+ '&::-webkit-search-cancel-button': {
74
+ WebkitAppearance: 'none'
75
+ }
76
+ });
81
77
 
82
- var base = {
83
- boxSizing: 'border-box',
84
- margin: 0,
85
- padding: 0,
86
- minWidth: 0,
87
- fontSize: '100%',
78
+ var select = /*#__PURE__*/_extends({}, base, {
79
+ display: 'block',
80
+ appearance: 'none',
88
81
  font: 'inherit',
89
- verticalAlign: 'baseline',
90
- WebkitTapHighlightColor: 'transparent'
91
- };
92
- var block = {
93
- display: 'block'
94
- };
95
- var body = {
96
- lineHeight: 1
97
- };
98
- var list = {
99
- listStyle: 'none'
100
- };
101
- var quote = {
102
- quotes: 'none',
103
- selectors: {
104
- '&:before, &:after': {
105
- content: "''"
106
- }
82
+ '&::-ms-expand': {
83
+ display: 'none'
107
84
  }
85
+ });
86
+
87
+ var textarea = /*#__PURE__*/_extends({}, base, {
88
+ display: 'block',
89
+ appearance: 'none',
90
+ font: 'inherit'
91
+ }); // Normalize
92
+ // ---------------
93
+
94
+
95
+ var normalize = {
96
+ base: base,
97
+ a: a,
98
+ p: text,
99
+ h1: text,
100
+ h2: text,
101
+ h3: text,
102
+ h4: text,
103
+ h5: text,
104
+ h6: text,
105
+ img: media,
106
+ picture: media,
107
+ video: media,
108
+ canvas: media,
109
+ svg: media,
110
+ select: select,
111
+ button: button,
112
+ textarea: textarea,
113
+ input: input
108
114
  };
109
- var table = {
110
- borderCollapse: 'collapse',
111
- borderSpacing: 0
115
+ /**
116
+ * Type-safe helper to get normalization. If no normalization is found,
117
+ * returns the *base* normalization.
118
+ */
119
+
120
+ var getNormalizedStyles = function getNormalizedStyles(val) {
121
+ return typeof val === 'string' && val in normalize ? normalize[val] // Typescript doesn't infer this correctly
122
+ : normalize.base;
112
123
  };
113
- var appearance = {
114
- appearance: 'none'
124
+
125
+ var _excluded = ["disabled"];
126
+
127
+ var isNil = function isNil(value) {
128
+ return value === null || value === undefined;
115
129
  };
116
- var field = [block, appearance];
117
- var mark = {
118
- backgroundColor: 'transparent',
119
- color: 'inherit'
130
+ /**
131
+ * Ensures that the `val` is an array. Will return an empty array if `val` is falsy.
132
+ */
133
+
134
+
135
+ var ensureArray = function ensureArray(val) {
136
+ return isNil(val) ? [] : Array.isArray(val) ? val : [val];
120
137
  };
121
- var select = /*#__PURE__*/[].concat(field, [{
122
- selectors: {
123
- '&::-ms-expand': {
124
- display: 'none'
125
- }
126
- }
127
- }]);
128
- var input = /*#__PURE__*/[].concat(field, [{
129
- selectors: {
130
- '&::-ms-clear': {
131
- display: 'none'
132
- },
133
- '&::-webkit-search-cancel-button': {
134
- WebkitAppearance: 'none'
135
- }
136
- }
137
- }]);
138
- var button = {
139
- background: 'none'
138
+ /**
139
+ * Removes trailing dot from variant, if necessary. This is necessary to support
140
+ * `__default` styles. See https://github.com/system-ui/theme-ui/pull/951
141
+ */
142
+
143
+ var ensureVariantDefault = function ensureVariantDefault(val) {
144
+ return val.replace(/\.$/, '');
140
145
  };
141
- var a = {
142
- textDecoration: 'none'
146
+ /**
147
+ * Ensures that the `variant` is an array and supports the `__default` key.
148
+ */
149
+
150
+ var ensureArrayVariant = function ensureArrayVariant(variant) {
151
+ return ensureArray(variant).map(ensureVariantDefault);
143
152
  };
144
- var el = {
145
- article: block,
146
- aside: block,
147
- details: block,
148
- figcaption: block,
149
- figure: block,
150
- footer: block,
151
- header: block,
152
- hgroup: block,
153
- menu: block,
154
- nav: block,
155
- section: block,
156
- ul: list,
157
- ol: list,
158
- blockquote: quote,
159
- q: quote,
160
- body: body,
161
- a: a,
162
- base: base,
163
- table: table,
164
- mark: mark,
165
- select: select,
166
- p: list,
167
- button: button,
168
- textarea: field,
169
- input: input
153
+ /**
154
+ * Appends given `state` to a `variant`.
155
+ */
156
+
157
+ var appendVariantState = function appendVariantState(variant, state) {
158
+ return ensureVariantDefault(variant) + ".:" + state;
170
159
  };
160
+ /**
161
+ * Create a variant array from a `variant` and `state` containing
162
+ * passed states, if they are truthy.
163
+ */
164
+
165
+ var conditional = function conditional(variant, _ref) {
166
+ var _ref$disabled = _ref.disabled,
167
+ disabled = _ref$disabled === void 0 ? false : _ref$disabled,
168
+ states = _objectWithoutPropertiesLoose(_ref, _excluded);
171
169
 
170
+ var entries = [].concat(Object.entries(states), [['disabled', disabled]]);
171
+ var stateVariants = entries.filter(function (_ref2) {
172
+ var val = _ref2[1];
173
+ return Boolean(val);
174
+ }).map(function (_ref3) {
175
+ var key = _ref3[0];
176
+ return appendVariantState(variant, key);
177
+ });
178
+ return [variant].concat(stateVariants);
179
+ };
180
+
181
+ var _excluded$1 = ["as", "children", "__baseCSS", "variant", "css", "display", "height", "width", "minWidth", "maxWidth", "position", "top", "bottom", "right", "left", "zIndex", "p", "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"];
172
182
  /**
173
- * Hook function that can add base styles, normalization, variant and custom styles
183
+ * Check if there is any falsy value or empty object
174
184
  */
175
185
 
176
- var useStyles = function useStyles(_ref, classNames) {
177
- var element = _ref.element,
186
+ var isNotEmpty = function isNotEmpty(val) {
187
+ return !(val && Object.keys(val).length === 0 && val.constructor === Object);
188
+ };
189
+
190
+ var createThemedStyle = function createThemedStyle(_ref) {
191
+ var as = _ref.as,
192
+ __baseCSS = _ref.__baseCSS,
178
193
  variant = _ref.variant,
179
- styles = _objectWithoutPropertiesLoose(_ref, ["element", "variant"]);
194
+ styles = _ref.styles,
195
+ css = _ref.css;
196
+ return function (theme) {
197
+ return [getNormalizedStyles(as), css$1(__baseCSS)(theme)].concat(ensureArrayVariant(variant).map(function (v) {
198
+ return css$1({
199
+ variant: v
200
+ })(theme);
201
+ }), [css$1(styles)(theme), css$1(css)(theme)]).filter(isNotEmpty);
202
+ };
203
+ };
180
204
 
205
+ var Box = /*#__PURE__*/forwardRef(function (_ref2, ref) {
206
+ var _ref2$as = _ref2.as,
207
+ as = _ref2$as === void 0 ? 'div' : _ref2$as,
208
+ children = _ref2.children,
209
+ __baseCSS = _ref2.__baseCSS,
210
+ variant = _ref2.variant,
211
+ _ref2$css = _ref2.css,
212
+ css = _ref2$css === void 0 ? {} : _ref2$css,
213
+ display = _ref2.display,
214
+ height = _ref2.height,
215
+ width = _ref2.width,
216
+ minWidth = _ref2.minWidth,
217
+ maxWidth = _ref2.maxWidth,
218
+ position = _ref2.position,
219
+ top = _ref2.top,
220
+ bottom = _ref2.bottom,
221
+ right = _ref2.right,
222
+ left = _ref2.left,
223
+ zIndex = _ref2.zIndex,
224
+ p = _ref2.p,
225
+ px = _ref2.px,
226
+ py = _ref2.py,
227
+ pt = _ref2.pt,
228
+ pb = _ref2.pb,
229
+ pl = _ref2.pl,
230
+ pr = _ref2.pr,
231
+ m = _ref2.m,
232
+ mx = _ref2.mx,
233
+ my = _ref2.my,
234
+ mt = _ref2.mt,
235
+ mb = _ref2.mb,
236
+ ml = _ref2.ml,
237
+ mr = _ref2.mr,
238
+ flexDirection = _ref2.flexDirection,
239
+ flexWrap = _ref2.flexWrap,
240
+ flexShrink = _ref2.flexShrink,
241
+ flexGrow = _ref2.flexGrow,
242
+ alignItems = _ref2.alignItems,
243
+ justifyContent = _ref2.justifyContent,
244
+ bg = _ref2.bg,
245
+ border = _ref2.border,
246
+ borderRadius = _ref2.borderRadius,
247
+ boxShadow = _ref2.boxShadow,
248
+ opacity = _ref2.opacity,
249
+ overflow = _ref2.overflow,
250
+ transition = _ref2.transition,
251
+ props = _objectWithoutPropertiesLoose(_ref2, _excluded$1);
252
+
253
+ return jsx(as, _extends({}, props, {
254
+ css: createThemedStyle({
255
+ as: as,
256
+ __baseCSS: __baseCSS,
257
+ variant: variant,
258
+ css: css,
259
+ styles: {
260
+ display: display,
261
+ height: height,
262
+ width: width,
263
+ minWidth: minWidth,
264
+ maxWidth: maxWidth,
265
+ position: position,
266
+ top: top,
267
+ bottom: bottom,
268
+ right: right,
269
+ left: left,
270
+ zIndex: zIndex,
271
+ p: p,
272
+ px: px,
273
+ py: py,
274
+ pt: pt,
275
+ pb: pb,
276
+ pl: pl,
277
+ pr: pr,
278
+ m: m,
279
+ mx: mx,
280
+ my: my,
281
+ mt: mt,
282
+ mb: mb,
283
+ ml: ml,
284
+ mr: mr,
285
+ flexDirection: flexDirection,
286
+ flexWrap: flexWrap,
287
+ flexShrink: flexShrink,
288
+ flexGrow: flexGrow,
289
+ alignItems: alignItems,
290
+ justifyContent: justifyContent,
291
+ bg: bg,
292
+ border: border,
293
+ borderRadius: borderRadius,
294
+ boxShadow: boxShadow,
295
+ opacity: opacity,
296
+ overflow: overflow,
297
+ transition: transition
298
+ }
299
+ }),
300
+ ref: ref
301
+ }), children);
302
+ });
303
+
304
+ /**
305
+ * @internal
306
+ */
307
+
308
+ var __defaultTheme = {};
309
+ var InternalContext = /*#__PURE__*/createContext(__defaultTheme);
310
+ var useTheme = function useTheme() {
311
+ var theme = useContext(InternalContext);
181
312
  /**
182
- * Normalization styles looked up by html tag name(s). Base normalization
183
- * is always applied.
313
+ * We cast the theme here to `any` since our subset is not
314
+ * compatible with the typings of `theme-ui`, since they
315
+ * also support arrays as scale values, while we don't.
184
316
  */
185
- var elementArray = [];
186
317
 
187
- if (element) {
188
- element.push('base'); // always apply base styles
318
+ var css = useCallback(function (style) {
319
+ return css$1(style)(theme);
320
+ }, [theme]);
321
+ return {
322
+ theme: theme,
323
+ css: css
324
+ };
325
+ };
326
+ function ThemeProvider(_ref) {
327
+ var theme = _ref.theme,
328
+ children = _ref.children;
329
+ return React.createElement(ThemeProvider$1, {
330
+ theme: theme
331
+ }, React.createElement(InternalContext.Provider, {
332
+ value: theme
333
+ }, children));
334
+ }
335
+
336
+ /**
337
+ * CSS snippet and idea from:
338
+ * https://css-tricks.com/revisiting-prefers-reduced-motion-the-reduced-motion-media-query/
339
+ */
189
340
 
190
- elementArray = element;
191
- } else {
192
- elementArray = ['base'];
341
+ var reduceMotionStyles = {
342
+ '@media screen and (prefers-reduced-motion: reduce), (update: slow)': {
343
+ '*': {
344
+ animationDuration: '0.001ms !important',
345
+ animationIterationCount: '1 !important',
346
+ transitionDuration: '0.001ms !important'
347
+ }
193
348
  }
349
+ };
350
+ var Global = function Global() {
351
+ var _useTheme = useTheme(),
352
+ css = _useTheme.css;
194
353
 
195
- var resetStyles = el;
196
- var elements = elementArray.map(function (styleObject) {
197
- return resetStyles[styleObject];
354
+ var styles = css({
355
+ html: {
356
+ height: '100%',
357
+ variant: 'root.html'
358
+ },
359
+ body: {
360
+ height: '100%',
361
+ lineHeight: 1.5,
362
+ WebkitFontSmoothing: 'antialiased',
363
+ variant: 'root.body'
364
+ }
198
365
  });
199
- var elementObject = Object.assign.apply(Object, [{}].concat(elements));
200
- var basedOnNormalize = useClassname(elementObject);
201
- /**
202
- * Variants are retrieved from the theme.
203
- */
366
+ return React.createElement(Global$1, {
367
+ styles: _extends({
368
+ reduceMotionStyles: reduceMotionStyles
369
+ }, styles)
370
+ });
371
+ };
204
372
 
205
- var variants = Array.isArray(variant) ? variant.map(function (v) {
206
- return {
207
- variant: v
208
- };
209
- }) : [{
210
- variant: variant
211
- }];
212
- var basedOnVariants = useClassname.apply(void 0, variants);
213
- /**
214
- * Custom styles are applied "on runtime". They are usually controlled via component
215
- * props and can change between component instances. They are more or less the `css`
216
- * prop of `emotion`.
217
- */
373
+ var _excluded$2 = ["size", "children"];
374
+ var css = /*#__PURE__*/getNormalizedStyles$1('svg');
375
+ var SVG = function SVG(_ref) {
376
+ var _ref$size = _ref.size,
377
+ size = _ref$size === void 0 ? 24 : _ref$size,
378
+ children = _ref.children,
379
+ props = _objectWithoutPropertiesLoose(_ref, _excluded$2);
218
380
 
219
- var custom = useClassname(styles);
220
- return [basedOnNormalize, basedOnVariants, custom, classNames].join(' ');
381
+ return jsx('svg', _extends({
382
+ width: size,
383
+ height: size,
384
+ viewBox: '0 0 24 24',
385
+ fill: 'currentcolor'
386
+ }, props, {
387
+ css: css
388
+ }), children);
221
389
  };
222
390
 
223
- export { SPACE_PROPS, ThemeProvider, system, useClassname, useStyles, useTheme };
391
+ export { Box, Global, SVG, ThemeProvider, __defaultTheme, appendVariantState, conditional, ensureArray, ensureArrayVariant, ensureVariantDefault, getNormalizedStyles, normalize, useTheme };
224
392
  //# sourceMappingURL=system.esm.js.map