@linaria/react 3.0.0-airbnb.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.
- package/CHANGELOG.md +99 -0
- package/LICENSE +21 -0
- package/README.md +35 -0
- package/esm/index.js +2 -0
- package/esm/index.js.map +1 -0
- package/esm/styled.js +128 -0
- package/esm/styled.js.map +1 -0
- package/lib/index.js +11 -0
- package/lib/index.js.map +1 -0
- package/lib/styled.js +143 -0
- package/lib/styled.js.map +1 -0
- package/package.json +54 -0
- package/types/index.d.ts +2 -0
- package/types/styled.d.ts +39 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
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.18](https://github.com/callstack/linaria/compare/v3.0.0-beta.17...v3.0.0-beta.18) (2022-04-01)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @linaria/react
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# [3.0.0-beta.17](https://github.com/callstack/linaria/compare/v3.0.0-beta.16...v3.0.0-beta.17) (2021-12-27)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* **react:** refactored types for styled function (fixes [#872](https://github.com/callstack/linaria/issues/872)) ([#887](https://github.com/callstack/linaria/issues/887)) ([7b8b129](https://github.com/callstack/linaria/commit/7b8b12937f9a0d1730d908e7cebad1684ccb03c3))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# [3.0.0-beta.15](https://github.com/callstack/linaria/compare/v3.0.0-beta.14...v3.0.0-beta.15) (2021-11-29)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Bug Fixes
|
|
29
|
+
|
|
30
|
+
* **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))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# [3.0.0-beta.14](https://github.com/callstack/linaria/compare/v3.0.0-beta.13...v3.0.0-beta.14) (2021-11-05)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### Bug Fixes
|
|
40
|
+
|
|
41
|
+
* **react:** refactor/rest op ([#860](https://github.com/callstack/linaria/issues/860)) ([da94704](https://github.com/callstack/linaria/commit/da94704df8ca74d94fe57682e2557274cf2d4cb0))
|
|
42
|
+
* **react:** unions in prop types are not resolved ([#844](https://github.com/callstack/linaria/issues/844)) ([62009e9](https://github.com/callstack/linaria/commit/62009e9184638fd8761f187c99e7ea434f364bee))
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# [3.0.0-beta.13](https://github.com/callstack/linaria/compare/v3.0.0-beta.12...v3.0.0-beta.13) (2021-09-13)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
### Bug Fixes
|
|
52
|
+
|
|
53
|
+
* **react:** fixes for `--exactOptionalPropertyTypes` TS flag ([#827](https://github.com/callstack/linaria/issues/827)) ([eed92b1](https://github.com/callstack/linaria/commit/eed92b19e3b779b656fb780307bbab8a08d14ba2))
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
# [3.0.0-beta.11](https://github.com/callstack/linaria/compare/v3.0.0-beta.10...v3.0.0-beta.11) (2021-08-08)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
### Bug Fixes
|
|
63
|
+
|
|
64
|
+
* **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))
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# [3.0.0-beta.7](https://github.com/callstack/linaria/compare/v3.0.0-beta.6...v3.0.0-beta.7) (2021-06-24)
|
|
71
|
+
|
|
72
|
+
**Note:** Version bump only for package @linaria/react
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
# [3.0.0-beta.4](https://github.com/callstack/linaria/compare/v3.0.0-beta.3...v3.0.0-beta.4) (2021-05-07)
|
|
79
|
+
|
|
80
|
+
**Note:** Version bump only for package @linaria/react
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
# [3.0.0-beta.3](https://github.com/callstack/linaria/compare/v3.0.0-beta.2...v3.0.0-beta.3) (2021-04-20)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
### Bug Fixes
|
|
90
|
+
|
|
91
|
+
* **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))
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
# [3.0.0-beta.2](https://github.com/callstack/linaria/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2021-04-11)
|
|
98
|
+
|
|
99
|
+
**Note:** Version bump only for package @linaria/react
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Callstack
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
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/index.js
ADDED
package/esm/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["default","styled"],"mappings":"AAAA,SAASA,OAAO,IAAIC,MAApB,QAAkC,UAAlC","sourcesContent":["export { default as styled } from './styled';\nexport type { CSSProperties } from '@linaria/core';\n"],"file":"index.js"}
|
package/esm/styled.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file contains an runtime version of `styled` component. Responsibilities of the component are:
|
|
3
|
+
* - returns ReactElement based on HTML tag used with `styled` or custom React Component
|
|
4
|
+
* - injects classNames for the returned component
|
|
5
|
+
* - injects CSS variables used to define dynamic styles based on props
|
|
6
|
+
*/
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import validAttr from '@emotion/is-prop-valid';
|
|
9
|
+
import { cx } from '@linaria/core';
|
|
10
|
+
|
|
11
|
+
const isCapital = ch => ch.toUpperCase() === ch;
|
|
12
|
+
|
|
13
|
+
const filterKey = keys => key => keys.indexOf(key) === -1;
|
|
14
|
+
|
|
15
|
+
export const omit = (obj, keys) => {
|
|
16
|
+
const res = {};
|
|
17
|
+
Object.keys(obj).filter(filterKey(keys)).forEach(key => {
|
|
18
|
+
res[key] = obj[key];
|
|
19
|
+
});
|
|
20
|
+
return res;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function filterProps(component, props, omitKeys) {
|
|
24
|
+
const filteredProps = omit(props, omitKeys); // Check if it's an HTML tag and not a custom element
|
|
25
|
+
|
|
26
|
+
if (typeof component === 'string' && component.indexOf('-') === -1 && !isCapital(component[0])) {
|
|
27
|
+
Object.keys(filteredProps).forEach(key => {
|
|
28
|
+
if (!validAttr(key)) {
|
|
29
|
+
// Don't pass through invalid attributes to HTML elements
|
|
30
|
+
delete filteredProps[key];
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return filteredProps;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const warnIfInvalid = (value, componentName) => {
|
|
39
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
40
|
+
if (typeof value === 'string' || // eslint-disable-next-line no-self-compare
|
|
41
|
+
typeof value === 'number' && isFinite(value)) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const stringified = typeof value === 'object' ? JSON.stringify(value) : String(value); // eslint-disable-next-line no-console
|
|
46
|
+
|
|
47
|
+
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.`);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
function styled(tag) {
|
|
52
|
+
return options => {
|
|
53
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
54
|
+
if (Array.isArray(options)) {
|
|
55
|
+
// We received a strings array since it's used as a tag
|
|
56
|
+
throw new Error('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');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const render = (props, ref) => {
|
|
61
|
+
const {
|
|
62
|
+
as: component = tag,
|
|
63
|
+
class: className
|
|
64
|
+
} = props;
|
|
65
|
+
let filteredProps = filterProps(component, props, ['as', 'class']);
|
|
66
|
+
filteredProps.ref = ref;
|
|
67
|
+
filteredProps.className = options.atomic ? cx(options.class, filteredProps.className || className) : cx(filteredProps.className || className, options.class);
|
|
68
|
+
const {
|
|
69
|
+
vars
|
|
70
|
+
} = options;
|
|
71
|
+
|
|
72
|
+
if (vars) {
|
|
73
|
+
const style = {}; // eslint-disable-next-line guard-for-in
|
|
74
|
+
|
|
75
|
+
for (const name in vars) {
|
|
76
|
+
const variable = vars[name];
|
|
77
|
+
const result = variable[0];
|
|
78
|
+
const unit = variable[1] || '';
|
|
79
|
+
const value = typeof result === 'function' ? result(props) : result;
|
|
80
|
+
warnIfInvalid(value, options.name);
|
|
81
|
+
style[`--${name}`] = `${value}${unit}`;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const ownStyle = filteredProps.style || {};
|
|
85
|
+
const keys = Object.keys(ownStyle);
|
|
86
|
+
|
|
87
|
+
if (keys.length > 0) {
|
|
88
|
+
keys.forEach(key => {
|
|
89
|
+
style[key] = ownStyle[key];
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
filteredProps.style = style;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (tag.__linaria && tag !== component) {
|
|
97
|
+
// If the underlying tag is a styled component, forward the `as` prop
|
|
98
|
+
// Otherwise the styles from the underlying component will be ignored
|
|
99
|
+
filteredProps.as = component;
|
|
100
|
+
return /*#__PURE__*/React.createElement(tag, filteredProps);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return /*#__PURE__*/React.createElement(component, filteredProps);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const Result = React.forwardRef ? /*#__PURE__*/React.forwardRef(render) : // React.forwardRef won't available on older React versions and in Preact
|
|
107
|
+
// Fallback to a innerRef prop in that case
|
|
108
|
+
props => {
|
|
109
|
+
const rest = omit(props, ['innerRef']);
|
|
110
|
+
return render(rest, props.innerRef);
|
|
111
|
+
};
|
|
112
|
+
Result.displayName = options.name; // These properties will be read by the babel plugin for interpolation
|
|
113
|
+
|
|
114
|
+
Result.__linaria = {
|
|
115
|
+
className: options.class,
|
|
116
|
+
extends: tag
|
|
117
|
+
};
|
|
118
|
+
return Result;
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export default process.env.NODE_ENV !== 'production' ? new Proxy(styled, {
|
|
123
|
+
get(o, prop) {
|
|
124
|
+
return o(prop);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
}) : styled;
|
|
128
|
+
//# sourceMappingURL=styled.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/styled.ts"],"names":["React","validAttr","cx","isCapital","ch","toUpperCase","filterKey","keys","key","indexOf","omit","obj","res","Object","filter","forEach","filterProps","component","props","omitKeys","filteredProps","warnIfInvalid","value","componentName","process","env","NODE_ENV","isFinite","stringified","JSON","stringify","String","console","warn","styled","tag","options","Array","isArray","Error","render","ref","as","class","className","atomic","vars","style","name","variable","result","unit","ownStyle","length","__linaria","createElement","Result","forwardRef","rest","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;;AAuBA,MAAMC,SAAS,GAAIC,EAAD,IAAyBA,EAAE,CAACC,WAAH,OAAqBD,EAAhE;;AACA,MAAME,SAAS,GACgBC,IAA7B,IACyBC,GAAzB,IACED,IAAI,CAACE,OAAL,CAAaD,GAAb,MAA6B,CAAC,CAHlC;;AAKA,OAAO,MAAME,IAAI,GAAG,CAClBC,GADkB,EAElBJ,IAFkB,KAGC;AACnB,QAAMK,GAAG,GAAG,EAAZ;AACAC,EAAAA,MAAM,CA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ACY,IAAtC,CArE2B,CAuE3B;;AACCQ,IAAAA,MAAD,CAAgBF,SAAhB,GAA4B;AAC1BV,MAAAA,SAAS,EAAER,OAAO,CAACO,KADO;AAE1BkB,MAAAA,OAAO,EAAE1B;AAFiB,KAA5B;AAKA,WAAOqB,MAAP;AACD,GA9ED;AA+ED;;AA+CD,eAAgBhC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAAzB,GACZ,IAAIoC,KAAJ,CAAU5B,MAAV,EAAkB;AAChB6B,EAAAA,GAAG,CAACC,CAAD,EAAIC,IAAJ,EAAuC;AACxC,WAAOD,CAAC,CAACC,IAAD,CAAR;AACD;;AAHe,CAAlB,CADY,GAMZ/B,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 Component<TProps> =\n | ((props: TProps) => unknown)\n | { new (props: TProps): unknown };\n\ntype Has<T, TObj> = [T] extends [TObj] ? T : T & TObj;\n\ntype Options = {\n name: string;\n class: string;\n atomic?: boolean;\n vars?: {\n [key: string]: [\n string | number | ((props: unknown) => string | number),\n string | void\n ];\n };\n};\n\nconst isCapital = (ch: string): boolean => ch.toUpperCase() === ch;\nconst filterKey =\n <TExclude extends keyof any>(keys: TExclude[]) =>\n <TAll extends keyof any>(key: TAll): key is Exclude<TAll, TExclude> =>\n keys.indexOf(key as any) === -1;\n\nexport const omit = <T extends Record<string, unknown>, TKeys extends keyof T>(\n obj: T,\n keys: TKeys[]\n): Omit<T, TKeys> => {\n const res = {} as Omit<T, TKeys>;\n Object.keys(obj)\n .filter(filterKey(keys))\n .forEach((key) => {\n res[key] = obj[key];\n });\n\n return res;\n};\n\nfunction filterProps<T extends Record<string, unknown>, TKeys extends keyof T>(\n component: string | unknown,\n props: T,\n omitKeys: TKeys[]\n): Partial<Omit<T, TKeys>> {\n const filteredProps = omit(props, omitKeys) as Partial<T>;\n\n // Check if it's an HTML tag and not a custom element\n if (\n typeof component === 'string' &&\n component.indexOf('-') === -1 &&\n !isCapital(component[0])\n ) {\n Object.keys(filteredProps).forEach((key) => {\n if (!validAttr(key)) {\n // Don't pass through invalid attributes to HTML elements\n delete filteredProps[key];\n }\n });\n }\n\n return filteredProps;\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// Property-based interpolation is allowed only if `style` property exists\nfunction styled<\n TProps extends Has<TMustHave, { style?: React.CSSProperties }>,\n TMustHave extends { style?: React.CSSProperties },\n TConstructor extends Component<TProps>\n>(\n componentWithStyle: TConstructor & Component<TProps>\n): ComponentStyledTagWithInterpolation<TProps, TConstructor>;\n// If styled wraps custom component, that component should have className property\nfunction styled<\n TProps extends Has<TMustHave, { className?: string }>,\n TMustHave extends { className?: string },\n TConstructor extends Component<TProps>\n>(\n componentWithoutStyle: TConstructor & Component<TProps>\n): ComponentStyledTagWithoutInterpolation<TConstructor>;\nfunction styled<TName extends keyof JSX.IntrinsicElements>(\n tag: TName\n): HtmlStyledTag<TName>;\nfunction styled(\n component: 'The target component should have a className prop'\n): never;\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 let filteredProps: IProps = filterProps(component, props, [\n 'as',\n 'class',\n ]);\n\n filteredProps.ref = ref;\n filteredProps.className = options.atomic\n ? cx(options.class, filteredProps.className || className)\n : cx(filteredProps.className || className, options.class);\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 = omit(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 ComponentStyledTagWithoutInterpolation<TOrigCmp> = (\n strings: TemplateStringsArray,\n ...exprs: Array<\n | StaticPlaceholder\n | ((props: 'The target component should have a style prop') => never)\n >\n) => StyledMeta & TOrigCmp;\n\ntype ComponentStyledTagWithInterpolation<TTrgProps, TOrigCmp> = <OwnProps = {}>(\n strings: TemplateStringsArray,\n ...exprs: Array<\n | StaticPlaceholder\n | ((props: NoInfer<OwnProps & TTrgProps>) => string | number)\n >\n) => keyof OwnProps extends never\n ? StyledMeta & TOrigCmp\n : StyledComponent<OwnProps & TTrgProps>;\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/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.styled = void 0;
|
|
5
|
+
|
|
6
|
+
var _styled = _interopRequireDefault(require("./styled"));
|
|
7
|
+
|
|
8
|
+
exports.styled = _styled.default;
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA","sourcesContent":["export { default as styled } from './styled';\nexport type { CSSProperties } from '@linaria/core';\n"],"file":"index.js"}
|
package/lib/styled.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = exports.omit = void 0;
|
|
5
|
+
|
|
6
|
+
var _react = _interopRequireDefault(require("react"));
|
|
7
|
+
|
|
8
|
+
var _isPropValid = _interopRequireDefault(require("@emotion/is-prop-valid"));
|
|
9
|
+
|
|
10
|
+
var _core = require("@linaria/core");
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* This file contains an runtime version of `styled` component. Responsibilities of the component are:
|
|
16
|
+
* - returns ReactElement based on HTML tag used with `styled` or custom React Component
|
|
17
|
+
* - injects classNames for the returned component
|
|
18
|
+
* - injects CSS variables used to define dynamic styles based on props
|
|
19
|
+
*/
|
|
20
|
+
var isCapital = function isCapital(ch) {
|
|
21
|
+
return ch.toUpperCase() === ch;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
var filterKey = function filterKey(keys) {
|
|
25
|
+
return function (key) {
|
|
26
|
+
return keys.indexOf(key) === -1;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
var omit = function omit(obj, keys) {
|
|
31
|
+
var res = {};
|
|
32
|
+
Object.keys(obj).filter(filterKey(keys)).forEach(function (key) {
|
|
33
|
+
res[key] = obj[key];
|
|
34
|
+
});
|
|
35
|
+
return res;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
exports.omit = omit;
|
|
39
|
+
|
|
40
|
+
function filterProps(component, props, omitKeys) {
|
|
41
|
+
var filteredProps = omit(props, omitKeys); // Check if it's an HTML tag and not a custom element
|
|
42
|
+
|
|
43
|
+
if (typeof component === 'string' && component.indexOf('-') === -1 && !isCapital(component[0])) {
|
|
44
|
+
Object.keys(filteredProps).forEach(function (key) {
|
|
45
|
+
if (!(0, _isPropValid.default)(key)) {
|
|
46
|
+
// Don't pass through invalid attributes to HTML elements
|
|
47
|
+
delete filteredProps[key];
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return filteredProps;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
var warnIfInvalid = function warnIfInvalid(value, componentName) {
|
|
56
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
57
|
+
if (typeof value === 'string' || // eslint-disable-next-line no-self-compare
|
|
58
|
+
typeof value === 'number' && isFinite(value)) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
var stringified = typeof value === 'object' ? JSON.stringify(value) : String(value); // eslint-disable-next-line no-console
|
|
63
|
+
|
|
64
|
+
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.");
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
function styled(tag) {
|
|
69
|
+
return function (options) {
|
|
70
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
71
|
+
if (Array.isArray(options)) {
|
|
72
|
+
// We received a strings array since it's used as a tag
|
|
73
|
+
throw new Error('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');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
var render = function render(props, ref) {
|
|
78
|
+
var _props$as = props.as,
|
|
79
|
+
component = _props$as === void 0 ? tag : _props$as,
|
|
80
|
+
className = props.class;
|
|
81
|
+
var filteredProps = filterProps(component, props, ['as', 'class']);
|
|
82
|
+
filteredProps.ref = ref;
|
|
83
|
+
filteredProps.className = options.atomic ? (0, _core.cx)(options.class, filteredProps.className || className) : (0, _core.cx)(filteredProps.className || className, options.class);
|
|
84
|
+
var vars = options.vars;
|
|
85
|
+
|
|
86
|
+
if (vars) {
|
|
87
|
+
var style = {}; // eslint-disable-next-line guard-for-in
|
|
88
|
+
|
|
89
|
+
for (var name in vars) {
|
|
90
|
+
var variable = vars[name];
|
|
91
|
+
var result = variable[0];
|
|
92
|
+
var unit = variable[1] || '';
|
|
93
|
+
var value = typeof result === 'function' ? result(props) : result;
|
|
94
|
+
warnIfInvalid(value, options.name);
|
|
95
|
+
style["--" + name] = "" + value + unit;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
var ownStyle = filteredProps.style || {};
|
|
99
|
+
var keys = Object.keys(ownStyle);
|
|
100
|
+
|
|
101
|
+
if (keys.length > 0) {
|
|
102
|
+
keys.forEach(function (key) {
|
|
103
|
+
style[key] = ownStyle[key];
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
filteredProps.style = style;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (tag.__linaria && tag !== component) {
|
|
111
|
+
// If the underlying tag is a styled component, forward the `as` prop
|
|
112
|
+
// Otherwise the styles from the underlying component will be ignored
|
|
113
|
+
filteredProps.as = component;
|
|
114
|
+
return /*#__PURE__*/_react.default.createElement(tag, filteredProps);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return /*#__PURE__*/_react.default.createElement(component, filteredProps);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
var Result = _react.default.forwardRef ? /*#__PURE__*/_react.default.forwardRef(render) : // React.forwardRef won't available on older React versions and in Preact
|
|
121
|
+
// Fallback to a innerRef prop in that case
|
|
122
|
+
function (props) {
|
|
123
|
+
var rest = omit(props, ['innerRef']);
|
|
124
|
+
return render(rest, props.innerRef);
|
|
125
|
+
};
|
|
126
|
+
Result.displayName = options.name; // These properties will be read by the babel plugin for interpolation
|
|
127
|
+
|
|
128
|
+
Result.__linaria = {
|
|
129
|
+
className: options.class,
|
|
130
|
+
extends: tag
|
|
131
|
+
};
|
|
132
|
+
return Result;
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
var _default = process.env.NODE_ENV !== 'production' ? new Proxy(styled, {
|
|
137
|
+
get: function get(o, prop) {
|
|
138
|
+
return o(prop);
|
|
139
|
+
}
|
|
140
|
+
}) : styled;
|
|
141
|
+
|
|
142
|
+
exports.default = _default;
|
|
143
|
+
//# sourceMappingURL=styled.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/styled.ts"],"names":["isCapital","ch","toUpperCase","filterKey","keys","key","indexOf","omit","obj","res","Object","filter","forEach","filterProps","component","props","omitKeys","filteredProps","warnIfInvalid","value","componentName","process","env","NODE_ENV","isFinite","stringified","JSON","stringify","String","console","warn","styled","tag","options","Array","isArray","Error","render","ref","as","className","class","atomic","vars","style","name","variable","result","unit","ownStyle","length","__linaria","React","createElement","Result","forwardRef","rest","innerRef","displayName","extends","Proxy","get","o","prop"],"mappings":";;;;;AAMA;;AACA;;AACA;;;;AARA;AACA;AACA;AACA;AACA;AACA;AA0BA,IAAMA,SAAS,GAAG,SAAZA,SAAY,CAACC,EAAD;AAAA,SAAyBA,EAAE,CAACC,WAAH,OAAqBD,EAA9C;AAAA,CAAlB;;AACA,IAAME,SAAS,GACb,SADIA,SACJ,CAA6BC,IAA7B;AAAA,SACA,UAAyBC,GAAzB;AAAA,WACED,IAAI,CAACE,OAAL,CAAaD,GAAb,MAA6B,CAAC,CADhC;AAAA,GADA;AAAA,CADF;;AAKO,IAAME,IAAI,GAAG,SAAPA,IAAO,CAClBC,GADkB,EAElBJ,IAFkB,EAGC;AACnB,MAAMK,GAAG,GAAG,EAAZ;AACAC,EAAAA,MAAM,CAACN,IAAP,CAAYI,GAAZ,EACGG,MADH,CACUR,SAAS,CAACC,IAAD,CADnB,EAEGQ,OAFH,CAEW,UAACP,GAAD,EAAS;AAChBI,IAAAA,GAAG,CAACJ,GAAD,CAAH,GAAWG,GAAG,CAACH,GAAD,CAAd;AACD,GAJH;AAMA,SAAOI,GAAP;AACD,CAZM;;;;AAcP,SAAS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,KAAyB,YAAzB,GACZ,IAAIqC,KAAJ,CAAU7B,MAAV,EAAkB;AAChB8B,EAAAA,GADgB,eACZC,CADY,EACTC,IADS,EAC0B;AACxC,WAAOD,CAAC,CAACC,IAAD,CAAR;AACD;AAHe,CAAlB,CADY,GAMZhC,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 Component<TProps> =\n | ((props: TProps) => unknown)\n | { new (props: TProps): unknown };\n\ntype Has<T, TObj> = [T] extends [TObj] ? T : T & TObj;\n\ntype Options = {\n name: string;\n class: string;\n atomic?: boolean;\n vars?: {\n [key: string]: [\n string | number | ((props: unknown) => string | number),\n string | void\n ];\n };\n};\n\nconst isCapital = (ch: string): boolean => ch.toUpperCase() === ch;\nconst filterKey =\n <TExclude extends keyof any>(keys: TExclude[]) =>\n <TAll extends keyof any>(key: TAll): key is Exclude<TAll, TExclude> =>\n keys.indexOf(key as any) === -1;\n\nexport const omit = <T extends Record<string, unknown>, TKeys extends keyof T>(\n obj: T,\n keys: TKeys[]\n): Omit<T, TKeys> => {\n const res = {} as Omit<T, TKeys>;\n Object.keys(obj)\n .filter(filterKey(keys))\n .forEach((key) => {\n res[key] = obj[key];\n });\n\n return res;\n};\n\nfunction filterProps<T extends Record<string, unknown>, TKeys extends keyof T>(\n component: string | unknown,\n props: T,\n omitKeys: TKeys[]\n): Partial<Omit<T, TKeys>> {\n const filteredProps = omit(props, omitKeys) as Partial<T>;\n\n // Check if it's an HTML tag and not a custom element\n if (\n typeof component === 'string' &&\n component.indexOf('-') === -1 &&\n !isCapital(component[0])\n ) {\n Object.keys(filteredProps).forEach((key) => {\n if (!validAttr(key)) {\n // Don't pass through invalid attributes to HTML elements\n delete filteredProps[key];\n }\n });\n }\n\n return filteredProps;\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// Property-based interpolation is allowed only if `style` property exists\nfunction styled<\n TProps extends Has<TMustHave, { style?: React.CSSProperties }>,\n TMustHave extends { style?: React.CSSProperties },\n TConstructor extends Component<TProps>\n>(\n componentWithStyle: TConstructor & Component<TProps>\n): ComponentStyledTagWithInterpolation<TProps, TConstructor>;\n// If styled wraps custom component, that component should have className property\nfunction styled<\n TProps extends Has<TMustHave, { className?: string }>,\n TMustHave extends { className?: string },\n TConstructor extends Component<TProps>\n>(\n componentWithoutStyle: TConstructor & Component<TProps>\n): ComponentStyledTagWithoutInterpolation<TConstructor>;\nfunction styled<TName extends keyof JSX.IntrinsicElements>(\n tag: TName\n): HtmlStyledTag<TName>;\nfunction styled(\n component: 'The target component should have a className prop'\n): never;\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 let filteredProps: IProps = filterProps(component, props, [\n 'as',\n 'class',\n ]);\n\n filteredProps.ref = ref;\n filteredProps.className = options.atomic\n ? cx(options.class, filteredProps.className || className)\n : cx(filteredProps.className || className, options.class);\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 = omit(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 ComponentStyledTagWithoutInterpolation<TOrigCmp> = (\n strings: TemplateStringsArray,\n ...exprs: Array<\n | StaticPlaceholder\n | ((props: 'The target component should have a style prop') => never)\n >\n) => StyledMeta & TOrigCmp;\n\ntype ComponentStyledTagWithInterpolation<TTrgProps, TOrigCmp> = <OwnProps = {}>(\n strings: TemplateStringsArray,\n ...exprs: Array<\n | StaticPlaceholder\n | ((props: NoInfer<OwnProps & TTrgProps>) => string | number)\n >\n) => keyof OwnProps extends never\n ? StyledMeta & TOrigCmp\n : StyledComponent<OwnProps & TTrgProps>;\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
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@linaria/react",
|
|
3
|
+
"version": "3.0.0-airbnb.0",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"description": "Blazing fast zero-runtime CSS in JS library",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"main": "lib/index.js",
|
|
10
|
+
"module": "esm/index.js",
|
|
11
|
+
"types": "types/index.d.ts",
|
|
12
|
+
"files": [
|
|
13
|
+
"types/",
|
|
14
|
+
"lib/",
|
|
15
|
+
"esm/"
|
|
16
|
+
],
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"repository": "git@github.com:callstack/linaria.git",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/callstack/linaria/issues"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/callstack/linaria#readme",
|
|
23
|
+
"keywords": [
|
|
24
|
+
"react",
|
|
25
|
+
"linaria",
|
|
26
|
+
"css",
|
|
27
|
+
"css-in-js",
|
|
28
|
+
"styled-components"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
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
|
+
"build:esm": "babel src --out-dir esm --extensions '.js,.jsx,.ts,.tsx' --source-maps --delete-dir-on-start",
|
|
33
|
+
"build": "yarn build:lib && yarn build:esm",
|
|
34
|
+
"build:declarations": "tsc --emitDeclarationOnly --outDir types",
|
|
35
|
+
"prepare": "yarn build && yarn build:declarations",
|
|
36
|
+
"test": "jest --config ../../jest.config.js --rootDir .",
|
|
37
|
+
"test:dts": "dtslint --localTs ../../node_modules/typescript/lib __dtslint__",
|
|
38
|
+
"typecheck": "tsc --noEmit --composite false",
|
|
39
|
+
"watch": "yarn build --watch"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/react": ">=16",
|
|
43
|
+
"react": "^16.13.1",
|
|
44
|
+
"react-test-renderer": "^16.8.3"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@emotion/is-prop-valid": "^0.8.8",
|
|
48
|
+
"@linaria/core": "^3.0.0-airbnb.0"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"react": ">=16"
|
|
52
|
+
},
|
|
53
|
+
"gitHead": "1c8bd4331b152498dd76e3f137940f43bd30e7b0"
|
|
54
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file contains an runtime version of `styled` component. Responsibilities of the component are:
|
|
3
|
+
* - returns ReactElement based on HTML tag used with `styled` or custom React Component
|
|
4
|
+
* - injects classNames for the returned component
|
|
5
|
+
* - injects CSS variables used to define dynamic styles based on props
|
|
6
|
+
*/
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import type { CSSProperties, StyledMeta } from '@linaria/core';
|
|
9
|
+
export declare type NoInfer<A extends any> = [A][A extends any ? 0 : never];
|
|
10
|
+
declare type Component<TProps> = ((props: TProps) => unknown) | {
|
|
11
|
+
new (props: TProps): unknown;
|
|
12
|
+
};
|
|
13
|
+
declare type Has<T, TObj> = [T] extends [TObj] ? T : T & TObj;
|
|
14
|
+
export declare const omit: <T extends Record<string, unknown>, TKeys extends keyof T>(obj: T, keys: TKeys[]) => Omit<T, TKeys>;
|
|
15
|
+
declare function styled<TProps extends Has<TMustHave, {
|
|
16
|
+
style?: React.CSSProperties;
|
|
17
|
+
}>, TMustHave extends {
|
|
18
|
+
style?: React.CSSProperties;
|
|
19
|
+
}, TConstructor extends Component<TProps>>(componentWithStyle: TConstructor & Component<TProps>): ComponentStyledTagWithInterpolation<TProps, TConstructor>;
|
|
20
|
+
declare function styled<TProps extends Has<TMustHave, {
|
|
21
|
+
className?: string;
|
|
22
|
+
}>, TMustHave extends {
|
|
23
|
+
className?: string;
|
|
24
|
+
}, TConstructor extends Component<TProps>>(componentWithoutStyle: TConstructor & Component<TProps>): ComponentStyledTagWithoutInterpolation<TConstructor>;
|
|
25
|
+
declare function styled<TName extends keyof JSX.IntrinsicElements>(tag: TName): HtmlStyledTag<TName>;
|
|
26
|
+
declare function styled(component: 'The target component should have a className prop'): never;
|
|
27
|
+
declare type StyledComponent<T> = StyledMeta & ([T] extends [React.FunctionComponent<any>] ? T : React.FunctionComponent<T & {
|
|
28
|
+
as?: React.ElementType;
|
|
29
|
+
}>);
|
|
30
|
+
declare type StaticPlaceholder = string | number | CSSProperties | StyledMeta;
|
|
31
|
+
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>;
|
|
32
|
+
declare type ComponentStyledTagWithoutInterpolation<TOrigCmp> = (strings: TemplateStringsArray, ...exprs: Array<StaticPlaceholder | ((props: 'The target component should have a style prop') => never)>) => StyledMeta & TOrigCmp;
|
|
33
|
+
declare type ComponentStyledTagWithInterpolation<TTrgProps, TOrigCmp> = <OwnProps = {}>(strings: TemplateStringsArray, ...exprs: Array<StaticPlaceholder | ((props: NoInfer<OwnProps & TTrgProps>) => string | number)>) => keyof OwnProps extends never ? StyledMeta & TOrigCmp : StyledComponent<OwnProps & TTrgProps>;
|
|
34
|
+
declare type StyledJSXIntrinsics = {
|
|
35
|
+
readonly [P in keyof JSX.IntrinsicElements]: HtmlStyledTag<P>;
|
|
36
|
+
};
|
|
37
|
+
export declare type Styled = typeof styled & StyledJSXIntrinsics;
|
|
38
|
+
declare const _default: Styled;
|
|
39
|
+
export default _default;
|