@linaria/react
Advanced tools
+11
-0
@@ -6,2 +6,13 @@ # Change Log | ||
| # [3.0.0-beta.13](https://github.com/callstack/linaria/compare/v3.0.0-beta.12...v3.0.0-beta.13) (2021-09-13) | ||
| ### Bug Fixes | ||
| * **react:** fixes for `--exactOptionalPropertyTypes` TS flag ([#827](https://github.com/callstack/linaria/issues/827)) ([eed92b1](https://github.com/callstack/linaria/commit/eed92b19e3b779b656fb780307bbab8a08d14ba2)) | ||
| # [3.0.0-beta.11](https://github.com/callstack/linaria/compare/v3.0.0-beta.10...v3.0.0-beta.11) (2021-08-08) | ||
@@ -8,0 +19,0 @@ |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["../src/styled.ts"],"names":["React","validAttr","cx","restOp","obj","keysToExclude","Object","keys","filter","prop","indexOf","reduce","acc","curr","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","key","vars","style","name","variable","result","unit","ownStyle","length","forEach","__linaria","createElement","Result","forwardRef","innerRef","displayName","extends","Proxy","get","o"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,KAAP,MAAkB,OAAlB;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,IAAUJ,aAAa,CAACK,OAAd,CAAsBD,IAAtB,MAAgC,CAAC,CADrD,EAEGE,MAFH,CAEU,CAACC,GAAD,EAAMC,IAAN,KAAe;AACrBD,EAAAA,GAAG,CAACC,IAAD,CAAH,GAAYT,GAAG,CAACS,IAAD,CAAf;AACA,SAAOD,GAAP;AACD,CALH,EAKK,EALL,CAJF,C,CASuC;;;AAEvC,MAAME,aAAa,GAAG,CAACC,KAAD,EAA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led` 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\n// Workaround for rest operator\nconst restOp = (\n obj: Record<string, unknown>,\n keysToExclude: string[]\n): Record<string, unknown> =>\n Object.keys(obj)\n .filter((prop) => keysToExclude.indexOf(prop) === -1)\n .reduce((acc, curr) => {\n acc[curr] = obj[curr];\n return acc;\n }, {} as Record<string, unknown>); // 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\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.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: 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 }\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"} | ||
| {"version":3,"sources":["../src/styled.ts"],"names":["React","validAttr","cx","restOp","obj","keysToExclude","Object","keys","filter","prop","indexOf","reduce","acc","curr","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","key","vars","style","name","variable","result","unit","ownStyle","length","forEach","__linaria","createElement","Result","forwardRef","innerRef","displayName","ext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AAb;AACD,KAPL;AASCF,IAAAA,MAAD,CAAgBG,WAAhB,GAA8B5B,OAAO,CAACgB,IAAtC,CAnF2B,CAqF3B;;AACCS,IAAAA,MAAD,CAAgBF,SAAhB,GAA4B;AAC1Bb,MAAAA,SAAS,EAAEV,OAAO,CAACS,KADO;AAE1BoB,MAAAA,OAAO,EAAE9B;AAFiB,KAA5B;AAKA,WAAO0B,MAAP;AACD,GA5FD;AA6FD;;AA+CD,eAAgBrC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAAzB,GACZ,IAAIwC,KAAJ,CAAUhC,MAAV,EAAkB;AAChBiC,EAAAA,GAAG,CAACC,CAAD,EAAIpD,IAAJ,EAAuC;AACxC,WAAOoD,CAAC,CAACpD,IAAD,CAAR;AACD;;AAHe,CAAlB,CADY,GAMZkB,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 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: Record<string, unknown>,\n keysToExclude: string[]\n): Record<string, unknown> =>\n Object.keys(obj)\n .filter((prop) => keysToExclude.indexOf(prop) === -1)\n .reduce((acc, curr) => {\n acc[curr] = obj[curr];\n return acc;\n }, {} as Record<string, unknown>); // 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\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.FunctionComponent<any>>(\n tag: TConstructor extends React.FunctionComponent<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"} |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["../src/styled.ts"],"names":["restOp","obj","keysToExclude","Object","keys","filter","prop","indexOf","reduce","acc","curr","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","key","vars","style","name","variable","result","unit","ownStyle","length","forEach","__linaria","React","createElement","Result","forwardRef","innerRef","displayName","extends","Proxy","get","o"],"mappings":";;;;;AAMA;;AACA;;AACA;;;;AARA;AACA;AACA;AACA;AACA;AACA;AAmBA;AACA,IAAMA,MAAM,GAAG,SAATA,MAAS,CACbC,GADa,EAEbC,aAFa;AAAA,SAIbC,MAAM,CAACC,IAAP,CAAYH,GAAZ,EACGI,MADH,CACU,UAACC,IAAD;AAAA,WAAUJ,aAAa,CAACK,OAAd,CAAsBD,IAAtB,MAAgC,CAAC,CAA3C;AAAA,GADV,EAEGE,MAFH,CAEU,UAACC,GAAD,EAAMC,IAAN,EAAe;AACrBD,IAAAA,GAAG,CAACC,IAAD,CAAH,GAAYT,GAAG,CAACS,IAAD,CAAf;AACA,WAAOD,GAAP;AACD,GALH,EAKK,EALL,CAJa;AAAA,CAAf,C,CASuC;;;AAEvC,IAAME,aAAa,GAAG,SAAhBA,aAAgB,CAACC,KAAD,EAAaC,aAAb,EAAuC;AAC3D,MAAIC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzC,QACE,OAAOJ,KAAP,KA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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,GAAGrC,MAAM,CAAC+B,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,CAACgB,IAAtC,CAnF2B,CAqF3B;;AACCU,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,EACTrD,IADS,EAC0B;AACxC,WAAOqD,CAAC,CAACrD,IAAD,CAAR;AACD;AAHe,CAAlB,CADY,GAMZkB,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\n// Workaround for rest operator\nconst restOp = (\n obj: Record<string, unknown>,\n keysToExclude: string[]\n): Record<string, unknown> =>\n Object.keys(obj)\n .filter((prop) => keysToExclude.indexOf(prop) === -1)\n .reduce((acc, curr) => {\n acc[curr] = obj[curr];\n return acc;\n }, {} as Record<string, unknown>); // 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\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.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: 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 }\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"} | ||
| {"version":3,"sources":["../src/styled.ts"],"names":["restOp","obj","keysToExclude","Object","keys","filter","prop","indexOf","reduce","acc","curr","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","key","vars","style","name","variable","result","unit","ownStyle","length","forEach","__linaria","React","createElement","Result","forwardRef","innerRef","displayName","extends","Proxy","get","o"],"mappings":";;;;;AAMA;;AACA;;AACA;;;;AARA;AACA;AACA;AACA;AACA;AACA;AAmBA;AACA,IAAMA,MAAM,GAAG,SAATA,MAAS,CACbC,GADa,EAEbC,aAFa;AAAA,SAIbC,MAAM,CAACC,IAAP,CAAYH,GAAZ,EACGI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AACD,GA5FD;AA6FD;;eA+CetC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAAzB,GACZ,IAAIyC,KAAJ,CAAUjC,MAAV,EAAkB;AAChBkC,EAAAA,GADgB,eACZC,CADY,EACTrD,IADS,EAC0B;AACxC,WAAOqD,CAAC,CAACrD,IAAD,CAAR;AACD;AAHe,CAAlB,CADY,GAMZkB,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\n// Workaround for rest operator\nconst restOp = (\n obj: Record<string, unknown>,\n keysToExclude: string[]\n): Record<string, unknown> =>\n Object.keys(obj)\n .filter((prop) => keysToExclude.indexOf(prop) === -1)\n .reduce((acc, curr) => {\n acc[curr] = obj[curr];\n return acc;\n }, {} as Record<string, unknown>); // 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\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.FunctionComponent<any>>(\n tag: TConstructor extends React.FunctionComponent<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"} |
+3
-3
| { | ||
| "name": "@linaria/react", | ||
| "version": "3.0.0-beta.11", | ||
| "version": "3.0.0-beta.13", | ||
| "publishConfig": { | ||
@@ -48,3 +48,3 @@ "access": "public" | ||
| "@emotion/is-prop-valid": "^0.8.8", | ||
| "@linaria/core": "^3.0.0-beta.4" | ||
| "@linaria/core": "^3.0.0-beta.13" | ||
| }, | ||
@@ -54,3 +54,3 @@ "peerDependencies": { | ||
| }, | ||
| "gitHead": "26cc3d4ba5d6b6c9f4d3d743127810569d818d6b" | ||
| "gitHead": "c49df269ebbbc956d43720b007a92f9f865662c5" | ||
| } |
@@ -11,6 +11,6 @@ /** | ||
| declare function styled<TConstructor extends React.FunctionComponent<any>>(tag: TConstructor extends React.FunctionComponent<infer T> ? T extends { | ||
| className?: string; | ||
| className?: string | undefined; | ||
| } ? TConstructor : never : never): ComponentStyledTag<TConstructor>; | ||
| declare function styled<T>(tag: T extends { | ||
| className?: string; | ||
| className?: string | undefined; | ||
| } ? React.ComponentType<T> : never): ComponentStyledTag<T>; | ||
@@ -24,3 +24,3 @@ declare function styled<TName extends keyof JSX.IntrinsicElements>(tag: TName): HtmlStyledTag<TName>; | ||
| declare type ComponentStyledTag<T> = <OwnProps = {}, TrgProps = T extends React.FunctionComponent<infer TProps> ? TProps : T>(strings: TemplateStringsArray, ...exprs: TrgProps extends { | ||
| style?: React.CSSProperties; | ||
| style?: React.CSSProperties | undefined; | ||
| } ? 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>; | ||
@@ -27,0 +27,0 @@ declare type StyledJSXIntrinsics = { |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
41143
1.18%Updated