@compiled/react 0.10.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/browser/class-names/index.d.ts +21 -15
  2. package/dist/browser/class-names/index.js +1 -27
  3. package/dist/browser/class-names/index.js.map +1 -1
  4. package/dist/browser/css/index.d.ts +22 -19
  5. package/dist/browser/css/index.js +3 -3
  6. package/dist/browser/css/index.js.map +1 -1
  7. package/dist/browser/jsx/jsx-local-namespace.d.ts +32 -6
  8. package/dist/browser/keyframes/index.d.ts +20 -24
  9. package/dist/browser/keyframes/index.js.map +1 -1
  10. package/dist/browser/styled/index.d.ts +35 -7
  11. package/dist/browser/styled/index.js +35 -7
  12. package/dist/browser/styled/index.js.map +1 -1
  13. package/dist/cjs/class-names/index.d.ts +21 -15
  14. package/dist/cjs/class-names/index.js +1 -27
  15. package/dist/cjs/class-names/index.js.map +1 -1
  16. package/dist/cjs/css/index.d.ts +22 -19
  17. package/dist/cjs/css/index.js +3 -3
  18. package/dist/cjs/css/index.js.map +1 -1
  19. package/dist/cjs/jsx/jsx-local-namespace.d.ts +32 -6
  20. package/dist/cjs/keyframes/index.d.ts +20 -24
  21. package/dist/cjs/keyframes/index.js.map +1 -1
  22. package/dist/cjs/styled/index.d.ts +35 -7
  23. package/dist/cjs/styled/index.js +35 -7
  24. package/dist/cjs/styled/index.js.map +1 -1
  25. package/dist/esm/class-names/index.d.ts +21 -15
  26. package/dist/esm/class-names/index.js +1 -27
  27. package/dist/esm/class-names/index.js.map +1 -1
  28. package/dist/esm/css/index.d.ts +22 -19
  29. package/dist/esm/css/index.js +3 -3
  30. package/dist/esm/css/index.js.map +1 -1
  31. package/dist/esm/jsx/jsx-local-namespace.d.ts +32 -6
  32. package/dist/esm/keyframes/index.d.ts +20 -24
  33. package/dist/esm/keyframes/index.js.map +1 -1
  34. package/dist/esm/styled/index.d.ts +35 -7
  35. package/dist/esm/styled/index.js +35 -7
  36. package/dist/esm/styled/index.js.map +1 -1
  37. package/package.json +3 -3
  38. package/src/__tests__/ssr.test.tsx +1 -1
  39. package/src/class-names/index.tsx +23 -13
  40. package/src/css/__tests__/index.test.tsx +7 -0
  41. package/src/css/index.tsx +32 -24
  42. package/src/jsx/jsx-local-namespace.tsx +32 -6
  43. package/src/keyframes/index.tsx +24 -28
  44. package/src/styled/index.tsx +35 -7
  45. package/CHANGELOG.md +0 -128
@@ -1,4 +1,4 @@
1
- import type { ReactNode } from 'react';
1
+ import type { ReactNode, CSSProperties } from 'react';
2
2
 
3
3
  import type { BasicTemplateInterpolations, CssFunction } from '../types';
4
4
  import { createSetupError } from '../utils/error';
@@ -8,36 +8,46 @@ export type Interpolations = (BasicTemplateInterpolations | CssFunction | CssFun
8
8
  export interface ClassNamesProps {
9
9
  children: (opts: {
10
10
  css: (css: CssFunction | CssFunction[], ...interpolations: Interpolations) => string;
11
- style: { [key: string]: string };
11
+ style: CSSProperties;
12
12
  }) => ReactNode;
13
13
  }
14
14
 
15
15
  /**
16
- * Use a component where styles are not necessarily tied to an element.
16
+ * ## Class names
17
17
  *
18
+ * Use a component where styles are not necessarily used on a JSX element.
19
+ * For further details [read the documentation](https://compiledcssinjs.com/docs/api-class-names).
20
+ *
21
+ * ### Style with objects
22
+ *
23
+ * @example
18
24
  * ```
19
- * // Object CSS
20
25
  * <ClassNames>
21
26
  * {({ css, style }) => children({ className: css({ fontSize: 12 }) })}
22
27
  * </ClassNames>
28
+ * ```
23
29
  *
24
- * // Template literal CSS
30
+ * ### Style with template literals
31
+ *
32
+ * @example
33
+ * ```
25
34
  * <ClassNames>
26
35
  * {({ css, style }) => children({ className: css`font-size: 12px;` })}
27
36
  * </ClassNames>
37
+ * ```
28
38
  *
29
- * // Array CSS
39
+ * ### Compose styles with arrays
40
+ *
41
+ * @example
42
+ * ```
30
43
  * <ClassNames>
31
44
  * {({ css, style }) =>
32
- * children({ className: css([{ fontSize: 12 }, `font-size: 12px`]) })}
45
+ * children({ className: css([{ fontSize: 12 }, css`font-size: 12px`]) })}
33
46
  * </ClassNames>
34
47
  * ```
35
- *
36
- * For more help, read the docs:
37
- * https://compiledcssinjs.com/docs/api-class-names
38
- *
39
- * @param props
40
48
  */
41
- export function ClassNames(_: ClassNamesProps): JSX.Element {
49
+ export function ClassNames({ children }: ClassNamesProps): JSX.Element;
50
+
51
+ export function ClassNames(_props: ClassNamesProps): JSX.Element {
42
52
  throw createSetupError();
43
53
  }
@@ -29,6 +29,13 @@ describe('css prop', () => {
29
29
  expect(getByText('hello world')).toHaveCompiledCss('font-size', '13px');
30
30
  });
31
31
 
32
+ it('should create hover styles', () => {
33
+ const styles = css({ ':hover': { color: 'red' } });
34
+ const { getByText } = render(<div css={styles}>hello world</div>);
35
+
36
+ expect(getByText('hello world')).toHaveCompiledCss('color', 'red', { target: ':hover' });
37
+ });
38
+
32
39
  it('should create css from tagged template expression variable', () => {
33
40
  const style = css`
34
41
  font-size: 13px;
package/src/css/index.tsx CHANGED
@@ -1,43 +1,51 @@
1
1
  /* eslint-disable import/export */
2
2
 
3
- import type { BasicTemplateInterpolations, CSSProps, FunctionInterpolation } from '../types';
3
+ import type {
4
+ AnyKeyCssProps,
5
+ BasicTemplateInterpolations,
6
+ CSSProps,
7
+ FunctionInterpolation,
8
+ } from '../types';
4
9
  import { createSetupError } from '../utils/error';
5
10
 
6
11
  /**
7
- * Create styles that can be re-used between components with a template literal.
12
+ * ## CSS
8
13
  *
14
+ * Define styles that are statically typed and useable with other Compiled APIs.
15
+ * For further details [read the documentation](https://compiledcssinjs.com/docs/api-css).
16
+ *
17
+ * ### Style with objects
18
+ *
19
+ * @example
9
20
  * ```
10
- * css`color: red;`;
21
+ * const redText = css({
22
+ * color: 'red',
23
+ * });
24
+ *
25
+ * <div css={redText} />
11
26
  * ```
12
27
  *
13
- * For more help, read the docs:
14
- * https://compiledcssinjs.com/docs/api-css
28
+ * ### Style with template literals
15
29
  *
16
- * @param css
17
- * @param values
30
+ * @example
31
+ * ```
32
+ * const redText = css`
33
+ * color: red;
34
+ * `;
35
+ *
36
+ * <div css={redText} />
37
+ * ```
18
38
  */
19
39
  export default function css<T = void>(
20
- _css: TemplateStringsArray,
21
- ..._values: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]
40
+ styles: TemplateStringsArray,
41
+ ...interpolations: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]
22
42
  ): CSSProps;
23
43
 
24
- /**
25
- * Create styles that can be re-used between components with an object
26
- *
27
- * ```
28
- * css({ color: 'red' });
29
- * ```
30
- *
31
- * For more help, read the docs:
32
- * https://compiledcssinjs.com/docs/api-css
33
- *
34
- * @param css
35
- */
36
- export default function css(_css: CSSProps): CSSProps;
44
+ export default function css(styles: AnyKeyCssProps<void> | CSSProps): CSSProps;
37
45
 
38
46
  export default function css<T = void>(
39
- _css: TemplateStringsArray | CSSProps,
40
- ..._values: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]
47
+ _styles: TemplateStringsArray | CSSProps,
48
+ ..._interpolations: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]
41
49
  ): CSSProps {
42
50
  throw createSetupError();
43
51
  }
@@ -4,16 +4,42 @@ type WithConditionalCSSProp<TProps> = 'className' extends keyof TProps
4
4
  ? string extends TProps['className' & keyof TProps]
5
5
  ? {
6
6
  /**
7
- * Tie styles to an element.
7
+ * ## CSS prop
8
8
  *
9
+ * Style a JSX element.
10
+ * For further details [read the API documentation](https://compiledcssinjs.com/docs/api-css-prop).
11
+ *
12
+ * ### Style with objects
13
+ *
14
+ * @example
15
+ * ```
16
+ * import { css } from '@compiled/react';
17
+ *
18
+ * <div css={css({ fontSize: 12 })} />
19
+ * ```
20
+ *
21
+ * ### Style with template literals
22
+ *
23
+ * @example
24
+ * ```
25
+ * import { css } from '@compiled/react';
26
+ *
27
+ * <div css={css`color: red;`} />
9
28
  * ```
10
- * css={{ fontSize: 12 }} // Object CSS
11
- * css={`font-size: 12px;`} // Template literal CSS
12
- * css={[{ fontSize: 12 }, `font-size: 12px;`]} // Array CSS
29
+ *
30
+ * ### Compose styles with arrays
31
+ *
32
+ * @example
13
33
  * ```
34
+ * import { css } from '@compiled/react';
14
35
  *
15
- * For more help, read the docs:
16
- * https://compiledcssinjs.com/docs/api-css-prop
36
+ * <div
37
+ * css={[
38
+ * css({ fontSize: 12 }),
39
+ * css`color: red;`,
40
+ * ]}
41
+ * />
42
+ * ```
17
43
  */
18
44
  css?: CssFunction | CssFunction[];
19
45
  }
@@ -4,28 +4,14 @@ import { createSetupError } from '../utils/error';
4
4
  export type KeyframeSteps = string | Record<string, CSSProps>;
5
5
 
6
6
  /**
7
- * Create keyframes using a tagged template expression:
7
+ * ## Keyframes
8
8
  *
9
- * ```
10
- * const fadeOut = keyframes`
11
- * from { opacity: 1; }
12
- * to { opacity: 0; }
13
- * `;
14
- * ```
15
- *
16
- * @param _strings The input string values
17
- * @param _interpolations The arguments used in the expression
18
- */
19
- export function keyframes(
20
- _strings: TemplateStringsArray,
21
- ..._interpolations: BasicTemplateInterpolations[]
22
- ): string;
23
-
24
- /**
25
- * Create keyframes using:
9
+ * Define keyframes to be used in a [CSS animation](https://developer.mozilla.org/en-US/docs/Web/CSS/animation).
10
+ * For further details [read the API documentation](https://compiledcssinjs.com/docs/api-keyframes).
26
11
  *
27
- * 1. An object expression
12
+ * ### Style with objects
28
13
  *
14
+ * @example
29
15
  * ```
30
16
  * const fadeOut = keyframes({
31
17
  * from: {
@@ -35,23 +21,33 @@ export function keyframes(
35
21
  * opacity: 0,
36
22
  * },
37
23
  * });
24
+ *
25
+ * <div css={{ animation: `${fadeOut} 2s` }} />
38
26
  * ```
39
27
  *
40
- * 2. A string
28
+ * ### Style with template literals
41
29
  *
30
+ * @example
42
31
  * ```
43
- * const fadeOut = keyframes('from { opacity: 1; } to { opacity: 0; }');
44
- * ```
32
+ * const fadeOut = keyframes`
33
+ * from {
34
+ * opacity: 1;
35
+ * }
45
36
  *
46
- * 3. A template literal
37
+ * to {
38
+ * opacity: 0;
39
+ * }
40
+ * `;
47
41
  *
42
+ * <div css={{ animation: `${fadeOut} 2s` }} />
48
43
  * ```
49
- * const fadeOut = keyframes(`from { opacity: 1; } to { opacity: 0; }`);
50
- * ```
51
- *
52
- * @param _steps The waypoints along the animation sequence
53
44
  */
54
- export function keyframes(_steps: KeyframeSteps): string;
45
+ export function keyframes(steps: KeyframeSteps): string;
46
+
47
+ export function keyframes(
48
+ strings: TemplateStringsArray,
49
+ ...interpolations: BasicTemplateInterpolations[]
50
+ ): string;
55
51
 
56
52
  export function keyframes(
57
53
  _stringsOrSteps: TemplateStringsArray | KeyframeSteps,
@@ -58,17 +58,45 @@ export interface StyledComponentInstantiator extends StyledComponentMap {
58
58
  }
59
59
 
60
60
  /**
61
- * Create a component that ties styles to an element which comes with built-in behavior such as `ref` and `as` prop support.
61
+ * ## Styled component
62
62
  *
63
+ * Create a component that styles a JSX element which comes with built-in behavior such as `ref` and `as` prop support.
64
+ * For further details [read the documentation](https://compiledcssinjs.com/docs/api-styled).
65
+ *
66
+ * ### Style with objects
67
+ *
68
+ * @example
69
+ * ```
70
+ * styled.div({
71
+ * fontSize: 12,
72
+ * });
73
+ * ```
74
+ *
75
+ * ### Style with template literals
76
+ *
77
+ * @example
63
78
  * ```
64
- * styled.div`font-size: 12px`; // Template literal CSS
65
- * styled.div({ fontSize: 12 }); // Object CSS
66
- * styled.div([{ fontSize: 12 }, `font-size: 12px;`]) // Array CSS
67
- * styled.div({ fontSize: 12 }, `font-size: 12px`) Multi arguments CSS
79
+ * styled.div`
80
+ * font-size: 12px
81
+ * `;
68
82
  * ```
69
83
  *
70
- * For more help, read the docs:
71
- * https://compiledcssinjs.com/docs/api-styled
84
+ * ### Compose styles with arrays
85
+ *
86
+ * @example
87
+ * ```
88
+ * import { css } from '@compiled/react';
89
+ *
90
+ * styled.div([
91
+ * { fontSize: 12 },
92
+ * css`font-size: 12px;`
93
+ * ]);
94
+ *
95
+ * styled.div(
96
+ * { fontSize: 12 },
97
+ * css`font-size: 12px`
98
+ * );
99
+ * ```
72
100
  */
73
101
  export const styled: StyledComponentInstantiator = new Proxy(
74
102
  {},
package/CHANGELOG.md DELETED
@@ -1,128 +0,0 @@
1
- # @compiled/react
2
-
3
- ## 0.10.0
4
-
5
- ### Minor Changes
6
-
7
- - 427cead: **Breaking change:** When using the `css` prop with [TypeScript](https://www.typescriptlang.org) you now need to declare a JSX pragma enabling types for that module. Previously when importing the `@compiled/react` package the global JSX namespace would be polluted as a side effect potentially causing collisions with other CSS-in-JS libraries. Now thanks to the use of [locally scoped JSX namespaces](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#locally-scoped-jsx-namespaces) the global JSX namespace will no longer be polluted.
8
-
9
- As an added bonus the `css` prop will only be available on JSX elements that have also defined a `className` prop with the potential for more type safe features later on.
10
-
11
- Make sure to update all Compiled dependencies to latest when adopting this change.
12
-
13
- **Automatic runtime**
14
-
15
- ```diff
16
- -import '@compiled/react';
17
- +/** @jsxImportSource @compiled/react */
18
-
19
- <div css={{ display: 'block' }} />;
20
- ```
21
-
22
- **Classic runtime**
23
-
24
- ```diff
25
- -import '@compiled/react';
26
- +/** @jsx jsx */
27
- +import { jsx } from '@compiled/react';
28
-
29
- <div css={{ display: 'block' }} />;
30
- ```
31
-
32
- To aid consumers in adopting this change easily, a new ESLint rule `jsx-pragma` has been created which will automatically migrate you to use a JSX pragma if missing when running with `--fix`. The rule takes an option to configure the runtime (either classic or automatic) and defaults to automatic.
33
-
34
- ```sh
35
- npm i @compiled/eslint-plugin
36
- ```
37
-
38
- ```json
39
- {
40
- "rules": {
41
- "@compiled/jsx-pragma": ["error", { "runtime": "classic" }]
42
- }
43
- }
44
- ```
45
-
46
- ### Patch Changes
47
-
48
- - 79cfb08: Internal refactor changing how the TypeScript compiler picks up source files.
49
-
50
- ## 0.9.1
51
-
52
- ### Patch Changes
53
-
54
- - 4309aaa: Patch inexact flow type on styled
55
-
56
- ## 0.9.0
57
-
58
- ### Minor Changes
59
-
60
- - 2092839: Allow inline strings and inline css mixins in conditional expressions. Fix ordering of styles in template literals.
61
-
62
- ## 0.8.0
63
-
64
- ### Minor Changes
65
-
66
- - 4210ff6: Add flow types support
67
- - 53935b3: Add `ObjectExpression` support to `css`
68
-
69
- ## 0.7.0
70
-
71
- ### Minor Changes
72
-
73
- - bcb2a68: Add support for `keyframes`
74
- - a7ab8e1: Add support for conditional rules for `Styled`
75
-
76
- ## 0.6.13
77
-
78
- ### Patch Changes
79
-
80
- - 13c3a60: add support of additional parameters to css function
81
-
82
- ## 0.6.12
83
-
84
- ### Patch Changes
85
-
86
- - b5b4e8a: Catch unhandled exception on inserting rules with prefixed selectors.
87
-
88
- ## 0.6.11
89
-
90
- ### Patch Changes
91
-
92
- - ee3363e: Fix HTML characters escapes in style tags on SSR.
93
-
94
- ## 0.6.10
95
-
96
- ### Patch Changes
97
-
98
- - 40bc0d9: Package descriptions have been updated.
99
- - 1b1c964: The `css` mixin API is now available,
100
- functioning similarly to the [emotion equivalent](https://emotion.sh/docs/composition).
101
-
102
- ```jsx
103
- import { css } from '@compiled/react';
104
-
105
- <div
106
- css={css`
107
- display: flex;
108
- font-size: 50px;
109
- color: blue;
110
- `}
111
- >
112
- blue text
113
- </div>;
114
- ```
115
-
116
- For more help, read the docs: https://compiledcssinjs.com/docs/css.
117
-
118
- ## 0.6.9
119
-
120
- ### Patch Changes
121
-
122
- - 4032cd4: Memo has been removed from the style component which was breaking re-renders at times.
123
-
124
- ## 0.6.8
125
-
126
- ### Patch Changes
127
-
128
- - aea3504: Packages now released with [changesets](https://github.com/atlassian/changesets).