@linaria/react 3.0.0-beta.1 → 3.0.0-beta.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,80 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # [3.0.0-beta.15](https://github.com/callstack/linaria/compare/v3.0.0-beta.14...v3.0.0-beta.15) (2021-11-29)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **react:** fixed types for supporting class components (fixes [#730](https://github.com/callstack/linaria/issues/730)) ([#877](https://github.com/callstack/linaria/issues/877)) ([e637ecb](https://github.com/callstack/linaria/commit/e637ecb8946a8119cfbd039bfb65d42206e09c4e))
12
+
13
+
14
+
15
+
16
+
17
+ # [3.0.0-beta.14](https://github.com/callstack/linaria/compare/v3.0.0-beta.13...v3.0.0-beta.14) (2021-11-05)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * **react:** refactor/rest op ([#860](https://github.com/callstack/linaria/issues/860)) ([da94704](https://github.com/callstack/linaria/commit/da94704df8ca74d94fe57682e2557274cf2d4cb0))
23
+ * **react:** unions in prop types are not resolved ([#844](https://github.com/callstack/linaria/issues/844)) ([62009e9](https://github.com/callstack/linaria/commit/62009e9184638fd8761f187c99e7ea434f364bee))
24
+
25
+
26
+
27
+
28
+
29
+ # [3.0.0-beta.13](https://github.com/callstack/linaria/compare/v3.0.0-beta.12...v3.0.0-beta.13) (2021-09-13)
30
+
31
+
32
+ ### Bug Fixes
33
+
34
+ * **react:** fixes for `--exactOptionalPropertyTypes` TS flag ([#827](https://github.com/callstack/linaria/issues/827)) ([eed92b1](https://github.com/callstack/linaria/commit/eed92b19e3b779b656fb780307bbab8a08d14ba2))
35
+
36
+
37
+
38
+
39
+
40
+ # [3.0.0-beta.11](https://github.com/callstack/linaria/compare/v3.0.0-beta.10...v3.0.0-beta.11) (2021-08-08)
41
+
42
+
43
+ ### Bug Fixes
44
+
45
+ * **styled:** remove unnecessary core-js polyfills (fixes [#799](https://github.com/callstack/linaria/issues/799)) ([#814](https://github.com/callstack/linaria/issues/814)) ([6c3070a](https://github.com/callstack/linaria/commit/6c3070a47715022eb761567b8795f6918784ae4c))
46
+
47
+
48
+
49
+
50
+
51
+ # [3.0.0-beta.7](https://github.com/callstack/linaria/compare/v3.0.0-beta.6...v3.0.0-beta.7) (2021-06-24)
52
+
53
+ **Note:** Version bump only for package @linaria/react
54
+
55
+
56
+
57
+
58
+
59
+ # [3.0.0-beta.4](https://github.com/callstack/linaria/compare/v3.0.0-beta.3...v3.0.0-beta.4) (2021-05-07)
60
+
61
+ **Note:** Version bump only for package @linaria/react
62
+
63
+
64
+
65
+
66
+
67
+ # [3.0.0-beta.3](https://github.com/callstack/linaria/compare/v3.0.0-beta.2...v3.0.0-beta.3) (2021-04-20)
68
+
69
+
70
+ ### Bug Fixes
71
+
72
+ * **core,react:** make IE 11 compatible (fixes [#746](https://github.com/callstack/linaria/issues/746)) ([#750](https://github.com/callstack/linaria/issues/750)) ([922df95](https://github.com/callstack/linaria/commit/922df9576a430cdfe9b27aed5dc45c4f75917607))
73
+
74
+
75
+
76
+
77
+
78
+ # [3.0.0-beta.2](https://github.com/callstack/linaria/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2021-04-11)
79
+
80
+ **Note:** Version bump only for package @linaria/react
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ <p align="center">
2
+ <img alt="Linaria" src="https://raw.githubusercontent.com/callstack/linaria/HEAD/website/assets/linaria-logo@2x.png" width="496">
3
+ </p>
4
+
5
+ <p align="center">
6
+ Zero-runtime CSS in JS library.
7
+ </p>
8
+
9
+ ---
10
+
11
+ ### 📖 Please refer to the [GitHub](https://github.com/callstack/linaria#readme) for full documentation.
12
+
13
+ ## Features
14
+
15
+ - Write CSS in JS, but with **zero runtime**, CSS is extracted to CSS files during build
16
+ - Familiar **CSS syntax** with Sass like nesting
17
+ - Use **dynamic prop based styles** with the React bindings, uses CSS variables behind the scenes
18
+ - Easily find where the style was defined with **CSS sourcemaps**
19
+ - **Lint your CSS** in JS with [stylelint](https://github.com/stylelint/stylelint)
20
+ - Use **JavaScript for logic**, no CSS preprocessor needed
21
+ - Optionally use any **CSS preprocessor** such as Sass or PostCSS
22
+
23
+ **[Why use Linaria](../../docs/BENEFITS.md)**
24
+
25
+ ## Installation
26
+
27
+ ```sh
28
+ npm install @linaria/core @linaria/react @linaria/babel-preset @linaria/shaker
29
+ ```
30
+
31
+ or
32
+
33
+ ```sh
34
+ yarn add @linaria/core @linaria/react @linaria/babel-preset @linaria/shaker
35
+ ```
package/esm/styled.js CHANGED
@@ -4,15 +4,22 @@
4
4
  * - injects classNames for the returned component
5
5
  * - injects CSS variables used to define dynamic styles based on props
6
6
  */
7
- import * as React from 'react';
7
+ import React from 'react';
8
8
  import validAttr from '@emotion/is-prop-valid';
9
9
  import { cx } from '@linaria/core';
10
-
11
10
  // Workaround for rest operator
12
- const restOp = (obj, keysToExclude) => Object.keys(obj).filter(prop => !keysToExclude.includes(prop)).reduce((acc, curr) => Object.assign(acc, {
13
- [curr]: obj[curr]
14
- }), {}); // rest operator workaround
11
+ export const restOp = (obj, keys) => {
12
+ const res = {};
13
+ let key;
14
+
15
+ for (key in obj) {
16
+ if (keys.indexOf(key) === -1) {
17
+ res[key] = obj[key];
18
+ }
19
+ }
15
20
 
21
+ return res;
22
+ };
16
23
 
17
24
  const warnIfInvalid = (value, componentName) => {
18
25
  if (process.env.NODE_ENV !== 'production') {
@@ -25,8 +32,7 @@ const warnIfInvalid = (value, componentName) => {
25
32
 
26
33
  console.warn(`An interpolation evaluated to '${stringified}' in the component '${componentName}', which is probably a mistake. You should explicitly cast or transform the value to a string.`);
27
34
  }
28
- }; // If styled wraps custom component, that component should have className property
29
-
35
+ };
30
36
 
31
37
  function styled(tag) {
32
38
  return options => {
@@ -76,7 +82,16 @@ function styled(tag) {
76
82
  style[`--${name}`] = `${value}${unit}`;
77
83
  }
78
84
 
79
- filteredProps.style = Object.assign(style, filteredProps.style);
85
+ const ownStyle = filteredProps.style || {};
86
+ const keys = Object.keys(ownStyle);
87
+
88
+ if (keys.length > 0) {
89
+ keys.forEach(key => {
90
+ style[key] = ownStyle[key];
91
+ });
92
+ }
93
+
94
+ filteredProps.style = style;
80
95
  }
81
96
 
82
97
  if (tag.__linaria && tag !== component) {
package/esm/styled.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/styled.ts"],"names":["React","validAttr","cx","restOp","obj","keysToExclude","Object","keys","filter","prop","includes","reduce","acc","curr","assign","warnIfInvalid","value","componentName","process","env","NODE_ENV","isFinite","stringified","JSON","stringify","String","console","warn","styled","tag","options","Array","isArray","Error","render","props","ref","as","component","class","className","rest","filteredProps","indexOf","key","vars","style","name","variable","result","unit","__linaria","createElement","Result","forwardRef","innerRef","displayName","extends","Proxy","get","o"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,OAAOC,SAAP,MAAsB,wBAAtB;AACA,SAASC,EAAT,QAAmB,eAAnB;;AAgBA;AACA,MAAMC,MAAM,GAAG,CACbC,GADa,EAEbC,aAFa,KAIbC,MAAM,CAACC,IAAP,CAAYH,GAAZ,EACGI,MADH,CACWC,IAAD,IAAU,CAACJ,aAAa,CAACK,QAAd,CAAuBD,IAAvB,CADrB,EAEGE,MAFH,CAEU,CAACC,GAAD,EAAMC,IAAN,KAAeP,MAAM,CAACQ,MAAP,CAAcF,GAAd,EAAmB;AAAE,GAACC,IAAD,GAAQT,GAAG,CAACS,IAAD;AAAb,CAAnB,CAFzB,EAEoE,EAFpE,CAJF,C,CAM2E;;;AAE3E,MAAME,aAAa,GAAG,CAACC,KAAD,EAAaC,aAAb,KAAuC;AAC3D,MAAIC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzC,QACE,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ACoD,aAAN,CAAoBd,SAApB,EAA+BI,aAA/B,CAAP;AACD,KAtDD;;AAwDA,UAAMW,MAAM,GAAGrD,KAAK,CAACsD,UAAN,gBACXtD,KAAK,CAACsD,UAAN,CAAiBpB,MAAjB,CADW,GAEX;AACA;AACCC,IAAAA,KAAD,IAAgB;AACd,YAAMM,IAAI,GAAGtC,MAAM,CAACgC,KAAD,EAAQ,CAAC,UAAD,CAAR,CAAnB;AACA,aAAOD,MAAM,CAACO,IAAD,EAAON,KAAK,CAACoB,QAAb,CAAb;AACD,KAPL;AASCF,IAAAA,MAAD,CAAgBG,WAAhB,GAA8B1B,OAAO,CAACiB,IAAtC,CA3E2B,CA6E3B;;AACCM,IAAAA,MAAD,CAAgBF,SAAhB,GAA4B;AAC1BX,MAAAA,SAAS,EAAEV,OAAO,CAACS,KADO;AAE1BkB,MAAAA,OAAO,EAAE5B;AAFiB,KAA5B;AAKA,WAAOwB,MAAP;AACD,GApFD;AAqFD;;AA+CD,eAAgBnC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAAzB,GACZ,IAAIsC,KAAJ,CAAU9B,MAAV,EAAkB;AAChB+B,EAAAA,GAAG,CAACC,CAAD,EAAInD,IAAJ,EAAuC;AACxC,WAAOmD,CAAC,CAACnD,IAAD,CAAR;AACD;;AAHe,CAAlB,CADY,GAMZmB,MANJ","sourcesContent":["/**\n * This file contains an runtime version of `styled` component. Responsibilities of the component are:\n * - returns ReactElement based on HTML tag used with `styled` or custom React Component\n * - injects classNames for the returned component\n * - injects CSS variables used to define dynamic styles based on props\n */\nimport * as React from 'react';\nimport validAttr from '@emotion/is-prop-valid';\nimport { cx } from '@linaria/core';\nimport type { CSSProperties, StyledMeta } from '@linaria/core';\n\nexport type NoInfer<A extends any> = [A][A extends any ? 0 : never];\n\ntype Options = {\n name: string;\n class: string;\n vars?: {\n [key: string]: [\n string | number | ((props: unknown) => string | number),\n string | void\n ];\n };\n};\n\n// Workaround for rest operator\nconst restOp = (\n obj: { [key: string]: any },\n keysToExclude: string[]\n): { [key: string]: any } =>\n Object.keys(obj)\n .filter((prop) => !keysToExclude.includes(prop))\n .reduce((acc, curr) => Object.assign(acc, { [curr]: obj[curr] }), {}); // rest operator workaround\n\nconst warnIfInvalid = (value: any, componentName: string) => {\n if (process.env.NODE_ENV !== 'production') {\n if (\n typeof value === 'string' ||\n // eslint-disable-next-line no-self-compare\n (typeof value === 'number' && isFinite(value))\n ) {\n return;\n }\n\n const stringified =\n typeof value === 'object' ? JSON.stringify(value) : String(value);\n\n // eslint-disable-next-line no-console\n console.warn(\n `An interpolation evaluated to '${stringified}' in the component '${componentName}', which is probably a mistake. You should explicitly cast or transform the value to a string.`\n );\n }\n};\n\n// If styled wraps custom component, that component should have className property\nfunction styled<TConstructor extends React.FunctionComponent<any>>(\n tag: TConstructor extends React.FunctionComponent<infer T>\n ? T extends { className?: string }\n ? TConstructor\n : never\n : never\n): ComponentStyledTag<TConstructor>;\nfunction styled<T>(\n tag: T extends { className?: string } ? React.ComponentType<T> : never\n): ComponentStyledTag<T>;\nfunction styled<TName extends keyof JSX.IntrinsicElements>(\n tag: TName\n): HtmlStyledTag<TName>;\nfunction styled(tag: any): any {\n return (options: Options) => {\n if (process.env.NODE_ENV !== 'production') {\n if (Array.isArray(options)) {\n // We received a strings array since it's used as a tag\n throw new Error(\n 'Using the \"styled\" tag in runtime is not supported. Make sure you have set up the Babel plugin correctly. See https://github.com/callstack/linaria#setup'\n );\n }\n }\n\n const render = (props: any, ref: any) => {\n const { as: component = tag, class: className } = props;\n const rest = restOp(props, ['as', 'class']);\n let filteredProps;\n\n // Check if it's an HTML tag and not a custom element\n if (typeof component === 'string' && component.indexOf('-') === -1) {\n filteredProps = {} as { [key: string]: any };\n\n // eslint-disable-next-line guard-for-in\n for (const key in rest) {\n if (key === 'as' || validAttr(key)) {\n // Don't pass through invalid attributes to HTML elements\n filteredProps[key] = rest[key];\n }\n }\n } else {\n filteredProps = rest;\n }\n\n filteredProps.ref = ref;\n filteredProps.className = cx(\n filteredProps.className || className,\n options.class\n );\n\n const { vars } = options;\n\n if (vars) {\n const style: { [key: string]: string } = {};\n\n // eslint-disable-next-line guard-for-in\n for (const name in vars) {\n const variable = vars[name];\n const result = variable[0];\n const unit = variable[1] || '';\n const value = typeof result === 'function' ? result(props) : result;\n\n warnIfInvalid(value, options.name);\n\n style[`--${name}`] = `${value}${unit}`;\n }\n\n filteredProps.style = Object.assign(style, filteredProps.style);\n }\n\n if ((tag as any).__linaria && tag !== component) {\n // If the underlying tag is a styled component, forward the `as` prop\n // Otherwise the styles from the underlying component will be ignored\n filteredProps.as = component;\n\n return React.createElement(tag, filteredProps);\n }\n return React.createElement(component, filteredProps);\n };\n\n const Result = React.forwardRef\n ? React.forwardRef(render)\n : // React.forwardRef won't available on older React versions and in Preact\n // Fallback to a innerRef prop in that case\n (props: any) => {\n const rest = restOp(props, ['innerRef']);\n return render(rest, props.innerRef);\n };\n\n (Result as any).displayName = options.name;\n\n // These properties will be read by the babel plugin for interpolation\n (Result as any).__linaria = {\n className: options.class,\n extends: tag,\n };\n\n return Result;\n };\n}\n\ntype StyledComponent<T> = StyledMeta &\n (T extends React.FunctionComponent<any>\n ? T\n : React.FunctionComponent<T & { as?: React.ElementType }>);\n\ntype StaticPlaceholder = string | number | CSSProperties | StyledMeta;\n\ntype HtmlStyledTag<TName extends keyof JSX.IntrinsicElements> = <\n TAdditionalProps = {}\n>(\n strings: TemplateStringsArray,\n ...exprs: Array<\n | StaticPlaceholder\n | ((\n // Without Omit here TS tries to infer TAdditionalProps\n // from a component passed for interpolation\n props: JSX.IntrinsicElements[TName] & Omit<TAdditionalProps, never>\n ) => string | number)\n >\n) => StyledComponent<JSX.IntrinsicElements[TName] & TAdditionalProps>;\n\ntype ComponentStyledTag<T> = <\n OwnProps = {},\n TrgProps = T extends React.FunctionComponent<infer TProps> ? TProps : T\n>(\n strings: TemplateStringsArray,\n // Expressions can contain functions only if wrapped component has style property\n ...exprs: TrgProps extends { style?: React.CSSProperties }\n ? Array<\n | StaticPlaceholder\n | ((props: NoInfer<OwnProps & TrgProps>) => string | number)\n >\n : StaticPlaceholder[]\n) => keyof OwnProps extends never\n ? T extends React.FunctionComponent<any>\n ? StyledMeta & T\n : StyledComponent<TrgProps>\n : StyledComponent<OwnProps & TrgProps>;\n\ntype StyledJSXIntrinsics = {\n readonly [P in keyof JSX.IntrinsicElements]: HtmlStyledTag<P>;\n};\n\nexport type Styled = typeof styled & StyledJSXIntrinsics;\n\nexport default (process.env.NODE_ENV !== 'production'\n ? new Proxy(styled, {\n get(o, prop: keyof JSX.IntrinsicElements) {\n return o(prop);\n },\n })\n : styled) as Styled;\n"],"file":"styled.js"}
1
+ {"version":3,"sources":["../src/styled.ts"],"names":["React","validAttr","cx","restOp","obj","keys","res","key","indexOf","warnIfInvalid","value","componentName","process","env","NODE_ENV","isFinite","stringified","JSON","stringify","String","console","warn","styled","tag","options","Array","isArray","Error","render","props","ref","as","component","class","className","rest","filteredProps","vars","style","name","variable","result","unit","ownStyle","Object","length","forEach","__linaria","createElement","Result","forwardRef","innerRef","displayName","extends","Proxy","get","o","prop"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,KAAP,MAAkB,OAAlB;AACA,OAAOC,SAAP,MAAsB,wBAAtB;AACA,SAASC,EAAT,QAAmB,eAAnB;AAsBA;AACA,OAAO,MAAMC,MAAkB,GAAG,CAACC,GAAD,EAAMC,IAAN,KAAe;AAC/C,QAAMC,GAAG,GAAG,EAAZ;AACA,MAAIC,GAAJ;;AACA,OAAKA,GAAL,IAAYH,GAAZ,EAAiB;AACf,QAAIC,IAAI,CAACG,OAAL,CAAaD,GAAb,MAAsB,CAAC,CAA3B,EAA8B;AAC5BD,MAAAA,GAAG,CAACC,GAAD,CAAH,GAAWH,GAAG,CAACG,GAAD,CAAd;AACD;AACF;;AACD,SAAOD,GAAP;AACD,CATM;;AAWP,MAAMG,aAAa,GAAG,CAACC,KAAD,EAAaC,aAAb,KAA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responsibilities of the component are:\n * - returns ReactElement based on HTML tag used with `styled` or custom React Component\n * - injects classNames for the returned component\n * - injects CSS variables used to define dynamic styles based on props\n */\nimport React from 'react';\nimport validAttr from '@emotion/is-prop-valid';\nimport { cx } from '@linaria/core';\nimport type { CSSProperties, StyledMeta } from '@linaria/core';\n\nexport type NoInfer<A extends any> = [A][A extends any ? 0 : never];\n\ntype Options = {\n name: string;\n class: string;\n vars?: {\n [key: string]: [\n string | number | ((props: unknown) => string | number),\n string | void\n ];\n };\n};\n\ninterface CustomOmit {\n <T extends object, K extends [...(keyof T)[]]>(obj: T, keys: K): {\n [K2 in Exclude<keyof T, K[number]>]: T[K2];\n };\n}\n\n// Workaround for rest operator\nexport const restOp: CustomOmit = (obj, keys) => {\n const res = {} as { [K in keyof typeof obj]: typeof obj[K] };\n let key: keyof typeof obj;\n for (key in obj) {\n if (keys.indexOf(key) === -1) {\n res[key] = obj[key];\n }\n }\n return res;\n};\n\nconst warnIfInvalid = (value: any, componentName: string) => {\n if (process.env.NODE_ENV !== 'production') {\n if (\n typeof value === 'string' ||\n // eslint-disable-next-line no-self-compare\n (typeof value === 'number' && isFinite(value))\n ) {\n return;\n }\n\n const stringified =\n typeof value === 'object' ? JSON.stringify(value) : String(value);\n\n // eslint-disable-next-line no-console\n console.warn(\n `An interpolation evaluated to '${stringified}' in the component '${componentName}', which is probably a mistake. You should explicitly cast or transform the value to a string.`\n );\n }\n};\n\ninterface IProps {\n className?: string;\n style?: Record<string, string>;\n [props: string]: unknown;\n}\n\n// If styled wraps custom component, that component should have className property\nfunction styled<TConstructor extends React.ComponentType<any>>(\n tag: TConstructor extends React.ComponentType<infer T>\n ? [T] extends [{ className?: string | undefined }]\n ? TConstructor\n : never\n : never\n): ComponentStyledTag<TConstructor>;\nfunction styled<T>(\n tag: [T] extends [{ className?: string | undefined }]\n ? React.ComponentType<T>\n : never\n): ComponentStyledTag<T>;\nfunction styled<TName extends keyof JSX.IntrinsicElements>(\n tag: TName\n): HtmlStyledTag<TName>;\nfunction styled(tag: any): any {\n return (options: Options) => {\n if (process.env.NODE_ENV !== 'production') {\n if (Array.isArray(options)) {\n // We received a strings array since it's used as a tag\n throw new Error(\n 'Using the \"styled\" tag in runtime is not supported. Make sure you have set up the Babel plugin correctly. See https://github.com/callstack/linaria#setup'\n );\n }\n }\n\n const render = (props: any, ref: any) => {\n const { as: component = tag, class: className } = props;\n const rest = restOp(props, ['as', 'class']);\n let filteredProps: IProps;\n\n // Check if it's an HTML tag and not a custom element\n if (typeof component === 'string' && component.indexOf('-') === -1) {\n filteredProps = {} as { [key: string]: any };\n\n // eslint-disable-next-line guard-for-in\n for (const key in rest) {\n if (key === 'as' || validAttr(key)) {\n // Don't pass through invalid attributes to HTML elements\n filteredProps[key] = rest[key];\n }\n }\n } else {\n filteredProps = rest;\n }\n\n filteredProps.ref = ref;\n filteredProps.className = cx(\n filteredProps.className || className,\n options.class\n );\n\n const { vars } = options;\n\n if (vars) {\n const style: { [key: string]: string } = {};\n\n // eslint-disable-next-line guard-for-in\n for (const name in vars) {\n const variable = vars[name];\n const result = variable[0];\n const unit = variable[1] || '';\n const value = typeof result === 'function' ? result(props) : result;\n\n warnIfInvalid(value, options.name);\n\n style[`--${name}`] = `${value}${unit}`;\n }\n\n const ownStyle = filteredProps.style || {};\n const keys = Object.keys(ownStyle);\n if (keys.length > 0) {\n keys.forEach((key) => {\n style[key] = ownStyle[key];\n });\n }\n\n filteredProps.style = style;\n }\n\n if ((tag as any).__linaria && tag !== component) {\n // If the underlying tag is a styled component, forward the `as` prop\n // Otherwise the styles from the underlying component will be ignored\n filteredProps.as = component;\n\n return React.createElement(tag, filteredProps);\n }\n return React.createElement(component, filteredProps);\n };\n\n const Result = React.forwardRef\n ? React.forwardRef(render)\n : // React.forwardRef won't available on older React versions and in Preact\n // Fallback to a innerRef prop in that case\n (props: any) => {\n const rest = restOp(props, ['innerRef']);\n return render(rest, props.innerRef);\n };\n\n (Result as any).displayName = options.name;\n\n // These properties will be read by the babel plugin for interpolation\n (Result as any).__linaria = {\n className: options.class,\n extends: tag,\n };\n\n return Result;\n };\n}\n\ntype StyledComponent<T> = StyledMeta &\n ([T] extends [React.FunctionComponent<any>]\n ? T\n : React.FunctionComponent<T & { as?: React.ElementType }>);\n\ntype StaticPlaceholder = string | number | CSSProperties | StyledMeta;\n\ntype HtmlStyledTag<TName extends keyof JSX.IntrinsicElements> = <\n TAdditionalProps = {}\n>(\n strings: TemplateStringsArray,\n ...exprs: Array<\n | StaticPlaceholder\n | ((\n // Without Omit here TS tries to infer TAdditionalProps\n // from a component passed for interpolation\n props: JSX.IntrinsicElements[TName] & Omit<TAdditionalProps, never>\n ) => string | number)\n >\n) => StyledComponent<JSX.IntrinsicElements[TName] & TAdditionalProps>;\n\ntype ComponentStyledTag<T> = <\n OwnProps = {},\n TrgProps = [T] extends [React.FunctionComponent<infer TProps>] ? TProps : T\n>(\n strings: TemplateStringsArray,\n // Expressions can contain functions only if wrapped component has style property\n ...exprs: TrgProps extends { style?: React.CSSProperties | undefined }\n ? Array<\n | StaticPlaceholder\n | ((props: NoInfer<OwnProps & TrgProps>) => string | number)\n >\n : StaticPlaceholder[]\n) => keyof OwnProps extends never\n ? [T] extends [React.FunctionComponent<any>]\n ? StyledMeta & T\n : StyledComponent<TrgProps>\n : StyledComponent<OwnProps & TrgProps>;\n\ntype StyledJSXIntrinsics = {\n readonly [P in keyof JSX.IntrinsicElements]: HtmlStyledTag<P>;\n};\n\nexport type Styled = typeof styled & StyledJSXIntrinsics;\n\nexport default (process.env.NODE_ENV !== 'production'\n ? new Proxy(styled, {\n get(o, prop: keyof JSX.IntrinsicElements) {\n return o(prop);\n },\n })\n : styled) as Styled;\n"],"file":"styled.js"}
package/lib/styled.js CHANGED
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports.default = void 0;
4
+ exports.default = exports.restOp = void 0;
5
5
 
6
- var React = _interopRequireWildcard(require("react"));
6
+ var _react = _interopRequireDefault(require("react"));
7
7
 
8
8
  var _isPropValid = _interopRequireDefault(require("@emotion/is-prop-valid"));
9
9
 
@@ -11,10 +11,6 @@ var _core = require("@linaria/core");
11
11
 
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
13
 
14
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
15
-
16
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
-
18
14
  /**
19
15
  * This file contains an runtime version of `styled` component. Responsibilities of the component are:
20
16
  * - returns ReactElement based on HTML tag used with `styled` or custom React Component
@@ -22,27 +18,36 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
22
18
  * - injects CSS variables used to define dynamic styles based on props
23
19
  */
24
20
  // Workaround for rest operator
25
- const restOp = (obj, keysToExclude) => Object.keys(obj).filter(prop => !keysToExclude.includes(prop)).reduce((acc, curr) => Object.assign(acc, {
26
- [curr]: obj[curr]
27
- }), {}); // rest operator workaround
21
+ var restOp = function restOp(obj, keys) {
22
+ var res = {};
23
+ var key;
24
+
25
+ for (key in obj) {
26
+ if (keys.indexOf(key) === -1) {
27
+ res[key] = obj[key];
28
+ }
29
+ }
30
+
31
+ return res;
32
+ };
28
33
 
34
+ exports.restOp = restOp;
29
35
 
30
- const warnIfInvalid = (value, componentName) => {
36
+ var warnIfInvalid = function warnIfInvalid(value, componentName) {
31
37
  if (process.env.NODE_ENV !== 'production') {
32
38
  if (typeof value === 'string' || // eslint-disable-next-line no-self-compare
33
39
  typeof value === 'number' && isFinite(value)) {
34
40
  return;
35
41
  }
36
42
 
37
- const stringified = typeof value === 'object' ? JSON.stringify(value) : String(value); // eslint-disable-next-line no-console
43
+ var stringified = typeof value === 'object' ? JSON.stringify(value) : String(value); // eslint-disable-next-line no-console
38
44
 
39
- console.warn(`An interpolation evaluated to '${stringified}' in the component '${componentName}', which is probably a mistake. You should explicitly cast or transform the value to a string.`);
45
+ console.warn("An interpolation evaluated to '" + stringified + "' in the component '" + componentName + "', which is probably a mistake. You should explicitly cast or transform the value to a string.");
40
46
  }
41
- }; // If styled wraps custom component, that component should have className property
42
-
47
+ };
43
48
 
44
49
  function styled(tag) {
45
- return options => {
50
+ return function (options) {
46
51
  if (process.env.NODE_ENV !== 'production') {
47
52
  if (Array.isArray(options)) {
48
53
  // We received a strings array since it's used as a tag
@@ -50,21 +55,20 @@ function styled(tag) {
50
55
  }
51
56
  }
52
57
 
53
- const render = (props, ref) => {
54
- const {
55
- as: component = tag,
56
- class: className
57
- } = props;
58
- const rest = restOp(props, ['as', 'class']);
59
- let filteredProps; // Check if it's an HTML tag and not a custom element
58
+ var render = function render(props, ref) {
59
+ var _props$as = props.as,
60
+ component = _props$as === void 0 ? tag : _props$as,
61
+ className = props.class;
62
+ var rest = restOp(props, ['as', 'class']);
63
+ var filteredProps; // Check if it's an HTML tag and not a custom element
60
64
 
61
65
  if (typeof component === 'string' && component.indexOf('-') === -1) {
62
66
  filteredProps = {}; // eslint-disable-next-line guard-for-in
63
67
 
64
- for (const key in rest) {
65
- if (key === 'as' || (0, _isPropValid.default)(key)) {
68
+ for (var _key in rest) {
69
+ if (_key === 'as' || (0, _isPropValid.default)(_key)) {
66
70
  // Don't pass through invalid attributes to HTML elements
67
- filteredProps[key] = rest[key];
71
+ filteredProps[_key] = rest[_key];
68
72
  }
69
73
  }
70
74
  } else {
@@ -73,39 +77,47 @@ function styled(tag) {
73
77
 
74
78
  filteredProps.ref = ref;
75
79
  filteredProps.className = (0, _core.cx)(filteredProps.className || className, options.class);
76
- const {
77
- vars
78
- } = options;
80
+ var vars = options.vars;
79
81
 
80
82
  if (vars) {
81
- const style = {}; // eslint-disable-next-line guard-for-in
83
+ var style = {}; // eslint-disable-next-line guard-for-in
82
84
 
83
- for (const name in vars) {
84
- const variable = vars[name];
85
- const result = variable[0];
86
- const unit = variable[1] || '';
87
- const value = typeof result === 'function' ? result(props) : result;
85
+ for (var name in vars) {
86
+ var variable = vars[name];
87
+ var result = variable[0];
88
+ var unit = variable[1] || '';
89
+ var value = typeof result === 'function' ? result(props) : result;
88
90
  warnIfInvalid(value, options.name);
89
- style[`--${name}`] = `${value}${unit}`;
91
+ style["--" + name] = "" + value + unit;
92
+ }
93
+
94
+ var ownStyle = filteredProps.style || {};
95
+
96
+ var _keys = Object.keys(ownStyle);
97
+
98
+ if (_keys.length > 0) {
99
+ _keys.forEach(function (key) {
100
+ style[key] = ownStyle[key];
101
+ });
90
102
  }
91
103
 
92
- filteredProps.style = Object.assign(style, filteredProps.style);
104
+ filteredProps.style = style;
93
105
  }
94
106
 
95
107
  if (tag.__linaria && tag !== component) {
96
108
  // If the underlying tag is a styled component, forward the `as` prop
97
109
  // Otherwise the styles from the underlying component will be ignored
98
110
  filteredProps.as = component;
99
- return /*#__PURE__*/React.createElement(tag, filteredProps);
111
+ return /*#__PURE__*/_react.default.createElement(tag, filteredProps);
100
112
  }
101
113
 
102
- return /*#__PURE__*/React.createElement(component, filteredProps);
114
+ return /*#__PURE__*/_react.default.createElement(component, filteredProps);
103
115
  };
104
116
 
105
- const Result = React.forwardRef ? /*#__PURE__*/React.forwardRef(render) : // React.forwardRef won't available on older React versions and in Preact
117
+ var Result = _react.default.forwardRef ? /*#__PURE__*/_react.default.forwardRef(render) : // React.forwardRef won't available on older React versions and in Preact
106
118
  // Fallback to a innerRef prop in that case
107
- props => {
108
- const rest = restOp(props, ['innerRef']);
119
+ function (props) {
120
+ var rest = restOp(props, ['innerRef']);
109
121
  return render(rest, props.innerRef);
110
122
  };
111
123
  Result.displayName = options.name; // These properties will be read by the babel plugin for interpolation
@@ -119,10 +131,9 @@ function styled(tag) {
119
131
  }
120
132
 
121
133
  var _default = process.env.NODE_ENV !== 'production' ? new Proxy(styled, {
122
- get(o, prop) {
134
+ get: function get(o, prop) {
123
135
  return o(prop);
124
136
  }
125
-
126
137
  }) : styled;
127
138
 
128
139
  exports.default = _default;
package/lib/styled.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/styled.ts"],"names":["restOp","obj","keysToExclude","Object","keys","filter","prop","includes","reduce","acc","curr","assign","warnIfInvalid","value","componentName","process","env","NODE_ENV","isFinite","stringified","JSON","stringify","String","console","warn","styled","tag","options","Array","isArray","Error","render","props","ref","as","component","class","className","rest","filteredProps","indexOf","key","vars","style","name","variable","result","unit","__linaria","React","createElement","Result","forwardRef","innerRef","displayName","extends","Proxy","get","o"],"mappings":";;;;;AAMA;;AACA;;AACA;;;;;;;;AARA;AACA;AACA;AACA;AACA;AACA;AAmBA;AACA,MAAMA,MAAM,GAAG,CACbC,GADa,EAEbC,aAFa,KAIbC,MAAM,CAACC,IAAP,CAAYH,GAAZ,EACGI,MADH,CACWC,IAAD,IAAU,CAACJ,aAAa,CAACK,QAAd,CAAuBD,IAAvB,CADrB,EAEGE,MAFH,CAEU,CAACC,GAAD,EAAMC,IAAN,KAAeP,MAAM,CAACQ,MAAP,CAAcF,GAAd,EAAmB;AAAE,GAACC,IAAD,GAAQT,GAAG,CAACS,IAAD;AAAb,CAAnB,CAFzB,EAEoE,EAFpE,CAJF,C,CAM2E;;;AAE3E,MAAME,aAAa,GAAG,CAACC,KAAD,EAAaC,aAAb,KAAuC;AAC3D,MAAIC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzC,QACE,OAAOJ,KAAP,KAAi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;AACD,KAtDD;;AAwDA,UAAMY,MAAM,GAAGF,KAAK,CAACG,UAAN,gBACXH,KAAK,CAACG,UAAN,CAAiBrB,MAAjB,CADW,GAEX;AACA;AACCC,IAAAA,KAAD,IAAgB;AACd,YAAMM,IAAI,GAAGtC,MAAM,CAACgC,KAAD,EAAQ,CAAC,UAAD,CAAR,CAAnB;AACA,aAAOD,MAAM,CAACO,IAAD,EAAON,KAAK,CAACqB,QAAb,CAAb;AACD,KAPL;AASCF,IAAAA,MAAD,CAAgBG,WAAhB,GAA8B3B,OAAO,CAACiB,IAAtC,CA3E2B,CA6E3B;;AACCO,IAAAA,MAAD,CAAgBH,SAAhB,GAA4B;AAC1BX,MAAAA,SAAS,EAAEV,OAAO,CAACS,KADO;AAE1BmB,MAAAA,OAAO,EAAE7B;AAFiB,KAA5B;AAKA,WAAOyB,MAAP;AACD,GApFD;AAqFD;;eA+CepC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAAzB,GACZ,IAAIuC,KAAJ,CAAU/B,MAAV,EAAkB;AAChBgC,EAAAA,GAAG,CAACC,CAAD,EAAIpD,IAAJ,EAAuC;AACxC,WAAOoD,CAAC,CAACpD,IAAD,CAAR;AACD;;AAHe,CAAlB,CADY,GAMZmB,M","sourcesContent":["/**\n * This file contains an runtime version of `styled` component. Responsibilities of the component are:\n * - returns ReactElement based on HTML tag used with `styled` or custom React Component\n * - injects classNames for the returned component\n * - injects CSS variables used to define dynamic styles based on props\n */\nimport * as React from 'react';\nimport validAttr from '@emotion/is-prop-valid';\nimport { cx } from '@linaria/core';\nimport type { CSSProperties, StyledMeta } from '@linaria/core';\n\nexport type NoInfer<A extends any> = [A][A extends any ? 0 : never];\n\ntype Options = {\n name: string;\n class: string;\n vars?: {\n [key: string]: [\n string | number | ((props: unknown) => string | number),\n string | void\n ];\n };\n};\n\n// Workaround for rest operator\nconst restOp = (\n obj: { [key: string]: any },\n keysToExclude: string[]\n): { [key: string]: any } =>\n Object.keys(obj)\n .filter((prop) => !keysToExclude.includes(prop))\n .reduce((acc, curr) => Object.assign(acc, { [curr]: obj[curr] }), {}); // rest operator workaround\n\nconst warnIfInvalid = (value: any, componentName: string) => {\n if (process.env.NODE_ENV !== 'production') {\n if (\n typeof value === 'string' ||\n // eslint-disable-next-line no-self-compare\n (typeof value === 'number' && isFinite(value))\n ) {\n return;\n }\n\n const stringified =\n typeof value === 'object' ? JSON.stringify(value) : String(value);\n\n // eslint-disable-next-line no-console\n console.warn(\n `An interpolation evaluated to '${stringified}' in the component '${componentName}', which is probably a mistake. You should explicitly cast or transform the value to a string.`\n );\n }\n};\n\n// If styled wraps custom component, that component should have className property\nfunction styled<TConstructor extends React.FunctionComponent<any>>(\n tag: TConstructor extends React.FunctionComponent<infer T>\n ? T extends { className?: string }\n ? TConstructor\n : never\n : never\n): ComponentStyledTag<TConstructor>;\nfunction styled<T>(\n tag: T extends { className?: string } ? React.ComponentType<T> : never\n): ComponentStyledTag<T>;\nfunction styled<TName extends keyof JSX.IntrinsicElements>(\n tag: TName\n): HtmlStyledTag<TName>;\nfunction styled(tag: any): any {\n return (options: Options) => {\n if (process.env.NODE_ENV !== 'production') {\n if (Array.isArray(options)) {\n // We received a strings array since it's used as a tag\n throw new Error(\n 'Using the \"styled\" tag in runtime is not supported. Make sure you have set up the Babel plugin correctly. See https://github.com/callstack/linaria#setup'\n );\n }\n }\n\n const render = (props: any, ref: any) => {\n const { as: component = tag, class: className } = props;\n const rest = restOp(props, ['as', 'class']);\n let filteredProps;\n\n // Check if it's an HTML tag and not a custom element\n if (typeof component === 'string' && component.indexOf('-') === -1) {\n filteredProps = {} as { [key: string]: any };\n\n // eslint-disable-next-line guard-for-in\n for (const key in rest) {\n if (key === 'as' || validAttr(key)) {\n // Don't pass through invalid attributes to HTML elements\n filteredProps[key] = rest[key];\n }\n }\n } else {\n filteredProps = rest;\n }\n\n filteredProps.ref = ref;\n filteredProps.className = cx(\n filteredProps.className || className,\n options.class\n );\n\n const { vars } = options;\n\n if (vars) {\n const style: { [key: string]: string } = {};\n\n // eslint-disable-next-line guard-for-in\n for (const name in vars) {\n const variable = vars[name];\n const result = variable[0];\n const unit = variable[1] || '';\n const value = typeof result === 'function' ? result(props) : result;\n\n warnIfInvalid(value, options.name);\n\n style[`--${name}`] = `${value}${unit}`;\n }\n\n filteredProps.style = Object.assign(style, filteredProps.style);\n }\n\n if ((tag as any).__linaria && tag !== component) {\n // If the underlying tag is a styled component, forward the `as` prop\n // Otherwise the styles from the underlying component will be ignored\n filteredProps.as = component;\n\n return React.createElement(tag, filteredProps);\n }\n return React.createElement(component, filteredProps);\n };\n\n const Result = React.forwardRef\n ? React.forwardRef(render)\n : // React.forwardRef won't available on older React versions and in Preact\n // Fallback to a innerRef prop in that case\n (props: any) => {\n const rest = restOp(props, ['innerRef']);\n return render(rest, props.innerRef);\n };\n\n (Result as any).displayName = options.name;\n\n // These properties will be read by the babel plugin for interpolation\n (Result as any).__linaria = {\n className: options.class,\n extends: tag,\n };\n\n return Result;\n };\n}\n\ntype StyledComponent<T> = StyledMeta &\n (T extends React.FunctionComponent<any>\n ? T\n : React.FunctionComponent<T & { as?: React.ElementType }>);\n\ntype StaticPlaceholder = string | number | CSSProperties | StyledMeta;\n\ntype HtmlStyledTag<TName extends keyof JSX.IntrinsicElements> = <\n TAdditionalProps = {}\n>(\n strings: TemplateStringsArray,\n ...exprs: Array<\n | StaticPlaceholder\n | ((\n // Without Omit here TS tries to infer TAdditionalProps\n // from a component passed for interpolation\n props: JSX.IntrinsicElements[TName] & Omit<TAdditionalProps, never>\n ) => string | number)\n >\n) => StyledComponent<JSX.IntrinsicElements[TName] & TAdditionalProps>;\n\ntype ComponentStyledTag<T> = <\n OwnProps = {},\n TrgProps = T extends React.FunctionComponent<infer TProps> ? TProps : T\n>(\n strings: TemplateStringsArray,\n // Expressions can contain functions only if wrapped component has style property\n ...exprs: TrgProps extends { style?: React.CSSProperties }\n ? Array<\n | StaticPlaceholder\n | ((props: NoInfer<OwnProps & TrgProps>) => string | number)\n >\n : StaticPlaceholder[]\n) => keyof OwnProps extends never\n ? T extends React.FunctionComponent<any>\n ? StyledMeta & T\n : StyledComponent<TrgProps>\n : StyledComponent<OwnProps & TrgProps>;\n\ntype StyledJSXIntrinsics = {\n readonly [P in keyof JSX.IntrinsicElements]: HtmlStyledTag<P>;\n};\n\nexport type Styled = typeof styled & StyledJSXIntrinsics;\n\nexport default (process.env.NODE_ENV !== 'production'\n ? new Proxy(styled, {\n get(o, prop: keyof JSX.IntrinsicElements) {\n return o(prop);\n },\n })\n : styled) as Styled;\n"],"file":"styled.js"}
1
+ {"version":3,"sources":["../src/styled.ts"],"names":["restOp","obj","keys","res","key","indexOf","warnIfInvalid","value","componentName","process","env","NODE_ENV","isFinite","stringified","JSON","stringify","String","console","warn","styled","tag","options","Array","isArray","Error","render","props","ref","as","component","className","class","rest","filteredProps","vars","style","name","variable","result","unit","ownStyle","Object","length","forEach","__linaria","React","createElement","Result","forwardRef","innerRef","displayName","extends","Proxy","get","o","prop"],"mappings":";;;;;AAMA;;AACA;;AACA;;;;AARA;AACA;AACA;AACA;AACA;AACA;AAyBA;AACO,IAAMA,MAAkB,GAAG,SAArBA,MAAqB,CAACC,GAAD,EAAMC,IAAN,EAAe;AAC/C,MAAMC,GAAG,GAAG,EAAZ;AACA,MAAIC,GAAJ;;AACA,OAAKA,GAAL,IAAYH,GAAZ,EAAiB;AACf,QAAIC,IAAI,CAACG,OAAL,CAAaD,GAAb,MAAsB,CAAC,CAA3B,EAA8B;AAC5BD,MAAAA,GAAG,CAACC,GAAD,CAAH,GAAWH,GAAG,CAACG,GAAD,CAAd;AACD;AACF;;AACD,SAAOD,GAAP;AACD,CATM;;;;AAWP,IAAMG,aAAa,GAAG,SAAhBA,aAAgB,CAACC,KAAD,EAAaC,aAAb,EAAuC;AAC3D,MAAIC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzC,QACE,OAAOJ,KAAP,KAAiB,QAAjB,IACA;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GAAD,CAAawB,SAAb,IAA0BxB,GAAG,KAAKS,SAAtC,EAAiD;AAC/C;AACA;AACAI,QAAAA,aAAa,CAACL,EAAd,GAAmBC,SAAnB;AAEA,4BAAOgB,eAAMC,aAAN,CAAoB1B,GAApB,EAAyBa,aAAzB,CAAP;AACD;;AACD,0BAAOY,eAAMC,aAAN,CAAoBjB,SAApB,EAA+BI,aAA/B,CAAP;AACD,KA9DD;;AAgEA,QAAMc,MAAM,GAAGF,eAAMG,UAAN,gBACXH,eAAMG,UAAN,CAAiBvB,MAAjB,CADW,GAEX;AACA;AACA,cAACC,KAAD,EAAgB;AACd,UAAMM,IAAI,GAAGhC,MAAM,CAAC0B,KAAD,EAAQ,CAAC,UAAD,CAAR,CAAnB;AACA,aAAOD,MAAM,CAACO,IAAD,EAAON,KAAK,CAACuB,QAAb,CAAb;AACD,KAPL;AASCF,IAAAA,MAAD,CAAgBG,WAAhB,GAA8B7B,OAAO,CAACe,IAAtC,CAnF2B,CAqF3B;;AACCW,IAAAA,MAAD,CAAgBH,SAAhB,GAA4B;AAC1Bd,MAAAA,SAAS,EAAET,OAAO,CAACU,KADO;AAE1BoB,MAAAA,OAAO,EAAE/B;AAFiB,KAA5B;AAKA,WAAO2B,MAAP;AACD,GA5FD;AA6FD;;eA+CetC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAAzB,GACZ,IAAIyC,KAAJ,CAAUjC,MAAV,EAAkB;AAChBkC,EAAAA,GADgB,eACZC,CADY,EACTC,IADS,EAC0B;AACxC,WAAOD,CAAC,CAACC,IAAD,CAAR;AACD;AAHe,CAAlB,CADY,GAMZpC,M","sourcesContent":["/**\n * This file contains an runtime version of `styled` component. Responsibilities of the component are:\n * - returns ReactElement based on HTML tag used with `styled` or custom React Component\n * - injects classNames for the returned component\n * - injects CSS variables used to define dynamic styles based on props\n */\nimport React from 'react';\nimport validAttr from '@emotion/is-prop-valid';\nimport { cx } from '@linaria/core';\nimport type { CSSProperties, StyledMeta } from '@linaria/core';\n\nexport type NoInfer<A extends any> = [A][A extends any ? 0 : never];\n\ntype Options = {\n name: string;\n class: string;\n vars?: {\n [key: string]: [\n string | number | ((props: unknown) => string | number),\n string | void\n ];\n };\n};\n\ninterface CustomOmit {\n <T extends object, K extends [...(keyof T)[]]>(obj: T, keys: K): {\n [K2 in Exclude<keyof T, K[number]>]: T[K2];\n };\n}\n\n// Workaround for rest operator\nexport const restOp: CustomOmit = (obj, keys) => {\n const res = {} as { [K in keyof typeof obj]: typeof obj[K] };\n let key: keyof typeof obj;\n for (key in obj) {\n if (keys.indexOf(key) === -1) {\n res[key] = obj[key];\n }\n }\n return res;\n};\n\nconst warnIfInvalid = (value: any, componentName: string) => {\n if (process.env.NODE_ENV !== 'production') {\n if (\n typeof value === 'string' ||\n // eslint-disable-next-line no-self-compare\n (typeof value === 'number' && isFinite(value))\n ) {\n return;\n }\n\n const stringified =\n typeof value === 'object' ? JSON.stringify(value) : String(value);\n\n // eslint-disable-next-line no-console\n console.warn(\n `An interpolation evaluated to '${stringified}' in the component '${componentName}', which is probably a mistake. You should explicitly cast or transform the value to a string.`\n );\n }\n};\n\ninterface IProps {\n className?: string;\n style?: Record<string, string>;\n [props: string]: unknown;\n}\n\n// If styled wraps custom component, that component should have className property\nfunction styled<TConstructor extends React.ComponentType<any>>(\n tag: TConstructor extends React.ComponentType<infer T>\n ? [T] extends [{ className?: string | undefined }]\n ? TConstructor\n : never\n : never\n): ComponentStyledTag<TConstructor>;\nfunction styled<T>(\n tag: [T] extends [{ className?: string | undefined }]\n ? React.ComponentType<T>\n : never\n): ComponentStyledTag<T>;\nfunction styled<TName extends keyof JSX.IntrinsicElements>(\n tag: TName\n): HtmlStyledTag<TName>;\nfunction styled(tag: any): any {\n return (options: Options) => {\n if (process.env.NODE_ENV !== 'production') {\n if (Array.isArray(options)) {\n // We received a strings array since it's used as a tag\n throw new Error(\n 'Using the \"styled\" tag in runtime is not supported. Make sure you have set up the Babel plugin correctly. See https://github.com/callstack/linaria#setup'\n );\n }\n }\n\n const render = (props: any, ref: any) => {\n const { as: component = tag, class: className } = props;\n const rest = restOp(props, ['as', 'class']);\n let filteredProps: IProps;\n\n // Check if it's an HTML tag and not a custom element\n if (typeof component === 'string' && component.indexOf('-') === -1) {\n filteredProps = {} as { [key: string]: any };\n\n // eslint-disable-next-line guard-for-in\n for (const key in rest) {\n if (key === 'as' || validAttr(key)) {\n // Don't pass through invalid attributes to HTML elements\n filteredProps[key] = rest[key];\n }\n }\n } else {\n filteredProps = rest;\n }\n\n filteredProps.ref = ref;\n filteredProps.className = cx(\n filteredProps.className || className,\n options.class\n );\n\n const { vars } = options;\n\n if (vars) {\n const style: { [key: string]: string } = {};\n\n // eslint-disable-next-line guard-for-in\n for (const name in vars) {\n const variable = vars[name];\n const result = variable[0];\n const unit = variable[1] || '';\n const value = typeof result === 'function' ? result(props) : result;\n\n warnIfInvalid(value, options.name);\n\n style[`--${name}`] = `${value}${unit}`;\n }\n\n const ownStyle = filteredProps.style || {};\n const keys = Object.keys(ownStyle);\n if (keys.length > 0) {\n keys.forEach((key) => {\n style[key] = ownStyle[key];\n });\n }\n\n filteredProps.style = style;\n }\n\n if ((tag as any).__linaria && tag !== component) {\n // If the underlying tag is a styled component, forward the `as` prop\n // Otherwise the styles from the underlying component will be ignored\n filteredProps.as = component;\n\n return React.createElement(tag, filteredProps);\n }\n return React.createElement(component, filteredProps);\n };\n\n const Result = React.forwardRef\n ? React.forwardRef(render)\n : // React.forwardRef won't available on older React versions and in Preact\n // Fallback to a innerRef prop in that case\n (props: any) => {\n const rest = restOp(props, ['innerRef']);\n return render(rest, props.innerRef);\n };\n\n (Result as any).displayName = options.name;\n\n // These properties will be read by the babel plugin for interpolation\n (Result as any).__linaria = {\n className: options.class,\n extends: tag,\n };\n\n return Result;\n };\n}\n\ntype StyledComponent<T> = StyledMeta &\n ([T] extends [React.FunctionComponent<any>]\n ? T\n : React.FunctionComponent<T & { as?: React.ElementType }>);\n\ntype StaticPlaceholder = string | number | CSSProperties | StyledMeta;\n\ntype HtmlStyledTag<TName extends keyof JSX.IntrinsicElements> = <\n TAdditionalProps = {}\n>(\n strings: TemplateStringsArray,\n ...exprs: Array<\n | StaticPlaceholder\n | ((\n // Without Omit here TS tries to infer TAdditionalProps\n // from a component passed for interpolation\n props: JSX.IntrinsicElements[TName] & Omit<TAdditionalProps, never>\n ) => string | number)\n >\n) => StyledComponent<JSX.IntrinsicElements[TName] & TAdditionalProps>;\n\ntype ComponentStyledTag<T> = <\n OwnProps = {},\n TrgProps = [T] extends [React.FunctionComponent<infer TProps>] ? TProps : T\n>(\n strings: TemplateStringsArray,\n // Expressions can contain functions only if wrapped component has style property\n ...exprs: TrgProps extends { style?: React.CSSProperties | undefined }\n ? Array<\n | StaticPlaceholder\n | ((props: NoInfer<OwnProps & TrgProps>) => string | number)\n >\n : StaticPlaceholder[]\n) => keyof OwnProps extends never\n ? [T] extends [React.FunctionComponent<any>]\n ? StyledMeta & T\n : StyledComponent<TrgProps>\n : StyledComponent<OwnProps & TrgProps>;\n\ntype StyledJSXIntrinsics = {\n readonly [P in keyof JSX.IntrinsicElements]: HtmlStyledTag<P>;\n};\n\nexport type Styled = typeof styled & StyledJSXIntrinsics;\n\nexport default (process.env.NODE_ENV !== 'production'\n ? new Proxy(styled, {\n get(o, prop: keyof JSX.IntrinsicElements) {\n return o(prop);\n },\n })\n : styled) as Styled;\n"],"file":"styled.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@linaria/react",
3
- "version": "3.0.0-beta.1",
3
+ "version": "3.0.0-beta.15",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -8,7 +8,7 @@
8
8
  "sideEffects": false,
9
9
  "main": "lib/index.js",
10
10
  "module": "esm/index.js",
11
- "types": "types",
11
+ "types": "types/index.d.ts",
12
12
  "files": [
13
13
  "types/",
14
14
  "lib/",
@@ -28,7 +28,7 @@
28
28
  "styled-components"
29
29
  ],
30
30
  "scripts": {
31
- "build:lib": "NODE_ENV=legacy babel src --out-dir lib --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
31
+ "build:lib": "cross-env NODE_ENV=legacy babel src --out-dir lib --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
32
32
  "build:esm": "babel src --out-dir esm --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
33
33
  "build": "yarn build:lib && yarn build:esm",
34
34
  "build:declarations": "tsc --emitDeclarationOnly --outDir types",
@@ -45,10 +45,10 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "@emotion/is-prop-valid": "^0.8.8",
48
- "@linaria/core": "^3.0.0-beta.1"
48
+ "@linaria/core": "^3.0.0-beta.15"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "react": ">=16"
52
52
  },
53
- "gitHead": "4ee73ae362ca775999bf71c93279db5268108d13"
53
+ "gitHead": "a8ada3794c6e13231f70711d92b516d57677a5b1"
54
54
  }
package/types/styled.d.ts CHANGED
@@ -4,24 +4,30 @@
4
4
  * - injects classNames for the returned component
5
5
  * - injects CSS variables used to define dynamic styles based on props
6
6
  */
7
- import * as React from 'react';
7
+ import React from 'react';
8
8
  import type { CSSProperties, StyledMeta } from '@linaria/core';
9
9
  export declare type NoInfer<A extends any> = [A][A extends any ? 0 : never];
10
- declare function styled<TConstructor extends React.FunctionComponent<any>>(tag: TConstructor extends React.FunctionComponent<infer T> ? T extends {
11
- className?: string;
12
- } ? TConstructor : never : never): ComponentStyledTag<TConstructor>;
13
- declare function styled<T>(tag: T extends {
14
- className?: string;
15
- } ? React.ComponentType<T> : never): ComponentStyledTag<T>;
10
+ interface CustomOmit {
11
+ <T extends object, K extends [...(keyof T)[]]>(obj: T, keys: K): {
12
+ [K2 in Exclude<keyof T, K[number]>]: T[K2];
13
+ };
14
+ }
15
+ export declare const restOp: CustomOmit;
16
+ declare function styled<TConstructor extends React.ComponentType<any>>(tag: TConstructor extends React.ComponentType<infer T> ? [T] extends [{
17
+ className?: string | undefined;
18
+ }] ? TConstructor : never : never): ComponentStyledTag<TConstructor>;
19
+ declare function styled<T>(tag: [T] extends [{
20
+ className?: string | undefined;
21
+ }] ? React.ComponentType<T> : never): ComponentStyledTag<T>;
16
22
  declare function styled<TName extends keyof JSX.IntrinsicElements>(tag: TName): HtmlStyledTag<TName>;
17
- declare type StyledComponent<T> = StyledMeta & (T extends React.FunctionComponent<any> ? T : React.FunctionComponent<T & {
23
+ declare type StyledComponent<T> = StyledMeta & ([T] extends [React.FunctionComponent<any>] ? T : React.FunctionComponent<T & {
18
24
  as?: React.ElementType;
19
25
  }>);
20
26
  declare type StaticPlaceholder = string | number | CSSProperties | StyledMeta;
21
27
  declare type HtmlStyledTag<TName extends keyof JSX.IntrinsicElements> = <TAdditionalProps = {}>(strings: TemplateStringsArray, ...exprs: Array<StaticPlaceholder | ((props: JSX.IntrinsicElements[TName] & Omit<TAdditionalProps, never>) => string | number)>) => StyledComponent<JSX.IntrinsicElements[TName] & TAdditionalProps>;
22
- declare type ComponentStyledTag<T> = <OwnProps = {}, TrgProps = T extends React.FunctionComponent<infer TProps> ? TProps : T>(strings: TemplateStringsArray, ...exprs: TrgProps extends {
23
- style?: React.CSSProperties;
24
- } ? Array<StaticPlaceholder | ((props: NoInfer<OwnProps & TrgProps>) => string | number)> : StaticPlaceholder[]) => keyof OwnProps extends never ? T extends React.FunctionComponent<any> ? StyledMeta & T : StyledComponent<TrgProps> : StyledComponent<OwnProps & TrgProps>;
28
+ declare type ComponentStyledTag<T> = <OwnProps = {}, TrgProps = [T] extends [React.FunctionComponent<infer TProps>] ? TProps : T>(strings: TemplateStringsArray, ...exprs: TrgProps extends {
29
+ style?: React.CSSProperties | undefined;
30
+ } ? Array<StaticPlaceholder | ((props: NoInfer<OwnProps & TrgProps>) => string | number)> : StaticPlaceholder[]) => keyof OwnProps extends never ? [T] extends [React.FunctionComponent<any>] ? StyledMeta & T : StyledComponent<TrgProps> : StyledComponent<OwnProps & TrgProps>;
25
31
  declare type StyledJSXIntrinsics = {
26
32
  readonly [P in keyof JSX.IntrinsicElements]: HtmlStyledTag<P>;
27
33
  };