styled-components 6.0.0-alpha.7 → 6.0.0-beta.2

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 (52) hide show
  1. package/README.md +2 -2
  2. package/dist/constructors/constructWithOptions.d.ts +16 -21
  3. package/dist/constructors/css.d.ts +2 -2
  4. package/dist/constructors/styled.d.ts +179 -179
  5. package/dist/models/ComponentStyle.d.ts +1 -0
  6. package/dist/models/StyledComponent.d.ts +1 -1
  7. package/dist/models/StyledNativeComponent.d.ts +2 -2
  8. package/dist/native/index.d.ts +29 -29
  9. package/dist/styled-components-macro.cjs.js +47 -1
  10. package/dist/styled-components-macro.cjs.js.map +1 -1
  11. package/dist/styled-components-macro.esm.js +38 -1
  12. package/dist/styled-components-macro.esm.js.map +1 -1
  13. package/dist/styled-components.browser.cjs.js +1854 -1
  14. package/dist/styled-components.browser.cjs.js.map +1 -1
  15. package/dist/styled-components.browser.esm.js +1829 -1
  16. package/dist/styled-components.browser.esm.js.map +1 -1
  17. package/dist/styled-components.cjs.js +1874 -1
  18. package/dist/styled-components.cjs.js.map +1 -1
  19. package/dist/styled-components.esm.js +1849 -1
  20. package/dist/styled-components.esm.js.map +1 -1
  21. package/dist/styled-components.js +2074 -1
  22. package/dist/styled-components.js.map +1 -1
  23. package/dist/styled-components.min.js +1 -1
  24. package/dist/styled-components.min.js.map +1 -1
  25. package/dist/test/utils.d.ts +178 -178
  26. package/dist/tsconfig.tsbuildinfo +1 -1
  27. package/dist/types.d.ts +33 -44
  28. package/dist/utils/generateDisplayName.d.ts +1 -1
  29. package/dist/utils/getComponentName.d.ts +1 -1
  30. package/dist/utils/isStyledComponent.d.ts +1 -1
  31. package/dist/utils/isTag.d.ts +1 -1
  32. package/dist/utils/stylis.d.ts +2 -1
  33. package/native/dist/constructors/constructWithOptions.d.ts +16 -21
  34. package/native/dist/constructors/css.d.ts +2 -2
  35. package/native/dist/constructors/styled.d.ts +179 -179
  36. package/native/dist/models/ComponentStyle.d.ts +1 -0
  37. package/native/dist/models/StyledComponent.d.ts +1 -1
  38. package/native/dist/models/StyledNativeComponent.d.ts +2 -2
  39. package/native/dist/native/index.d.ts +29 -29
  40. package/native/dist/styled-components.native.cjs.js +438 -403
  41. package/native/dist/styled-components.native.cjs.js.map +1 -1
  42. package/native/dist/styled-components.native.esm.js +439 -404
  43. package/native/dist/styled-components.native.esm.js.map +1 -1
  44. package/native/dist/test/utils.d.ts +178 -178
  45. package/native/dist/types.d.ts +33 -44
  46. package/native/dist/utils/generateDisplayName.d.ts +1 -1
  47. package/native/dist/utils/getComponentName.d.ts +1 -1
  48. package/native/dist/utils/isStyledComponent.d.ts +1 -1
  49. package/native/dist/utils/isTag.d.ts +1 -1
  50. package/native/dist/utils/stylis.d.ts +2 -1
  51. package/package.json +8 -8
  52. package/test-utils/setupTestFramework.ts +9 -3
@@ -6,19 +6,18 @@ interface ExoticComponentWithDisplayName<P = unknown> extends React.ExoticCompon
6
6
  defaultProps?: Partial<P>;
7
7
  displayName?: string;
8
8
  }
9
+ export declare type OmitNever<T> = {
10
+ [K in keyof T as T[K] extends never ? never : K]: T[K];
11
+ };
12
+ export declare type Runtime = 'web' | 'native';
9
13
  export { DefaultTheme };
10
14
  export declare type AnyComponent<P = any> = ExoticComponentWithDisplayName<P> | React.ComponentType<P>;
11
- export interface StyledOptions<Props> {
15
+ export interface StyledOptions<R extends Runtime, Props> {
12
16
  attrs?: Attrs<Props>[];
13
- componentId?: string;
17
+ componentId?: R extends 'web' ? string : never;
14
18
  displayName?: string;
15
- parentComponentId?: string;
16
- shouldForwardProp?: ShouldForwardProp;
17
- }
18
- export interface StyledNativeOptions<Props> {
19
- attrs?: Attrs<Props>[];
20
- displayName?: string;
21
- shouldForwardProp?: ShouldForwardProp;
19
+ parentComponentId?: R extends 'web' ? string : never;
20
+ shouldForwardProp?: ShouldForwardProp<R>;
22
21
  }
23
22
  export declare type KnownTarget = keyof JSX.IntrinsicElements | AnyComponent;
24
23
  export declare type WebTarget = string | KnownTarget;
@@ -36,11 +35,11 @@ export interface ExtensibleObject extends BaseExtensibleObject {
36
35
  export interface ExecutionContext extends ExtensibleObject {
37
36
  theme: DefaultTheme;
38
37
  }
39
- export interface StyleFunction<Props = ExecutionContext> {
40
- (executionContext: Props): Interpolation<Props>;
38
+ export interface StyleFunction<Props = BaseExtensibleObject> {
39
+ (executionContext: ExecutionContext & Props): Interpolation<Props>;
41
40
  }
42
- export declare type Interpolation<Props> = StyleFunction<Props> | StyledObject<Props> | TemplateStringsArray | string | number | Keyframes | IStyledComponent<any, any> | Interpolation<Props>[];
43
- export declare type Attrs<Props> = (ExtensibleObject & Props) | ((props: Props) => Partial<Props>);
41
+ export declare type Interpolation<Props> = StyleFunction<Props> | StyledObject<Props> | TemplateStringsArray | string | number | undefined | null | Keyframes | IStyledComponent<'web', any, any> | Interpolation<Props>[];
42
+ export declare type Attrs<Props> = (ExtensibleObject & Props) | ((props: ExecutionContext & Props) => Partial<Props>);
44
43
  export declare type RuleSet<Props> = Interpolation<Props>[];
45
44
  export declare type Styles<Props> = TemplateStringsArray | StyledObject<Props> | StyleFunction<Props>;
46
45
  export declare type NameGenerator = (hash: number) => string;
@@ -57,52 +56,42 @@ export interface Flattener<Props> {
57
56
  }
58
57
  export declare type FlattenerResult<Props> = RuleSet<Props> | number | string | string[] | IStyledComponent<any, any> | Keyframes;
59
58
  export interface Stringifier {
60
- (css: string, selector?: string, prefix?: string, componentId?: string): string;
59
+ (css: string, selector?: string, prefix?: string, componentId?: string): string[];
61
60
  hash: string;
62
61
  }
63
- export interface ShouldForwardProp {
64
- (prop: string, isValidAttr: (prop: string) => boolean, elementToBeCreated?: WebTarget | NativeTarget): boolean;
62
+ export interface ShouldForwardProp<R extends Runtime> {
63
+ (prop: string, elementToBeCreated?: StyledTarget<R>): boolean;
65
64
  }
66
- export interface CommonStatics<Props> {
65
+ export interface CommonStatics<R extends Runtime, Props> {
67
66
  attrs: Attrs<Props>[];
68
- target: StyledTarget;
69
- shouldForwardProp?: ShouldForwardProp;
67
+ target: StyledTarget<R>;
68
+ shouldForwardProp?: ShouldForwardProp<R>;
70
69
  withComponent: any;
71
70
  }
72
- export interface IStyledStatics<OuterProps = unknown> extends CommonStatics<OuterProps> {
73
- componentStyle: ComponentStyle;
74
- foldedComponentIds: Array<string>;
75
- target: WebTarget;
76
- styledComponentId: string;
77
- warnTooManyClasses?: ReturnType<typeof createWarnTooManyClasses>;
78
- withComponent: <Target extends WebTarget, Props = unknown>(tag: Target) => IStyledComponent<Target, OuterProps & Props>;
71
+ export interface IStyledStatics<R extends Runtime, OuterProps = unknown> extends CommonStatics<R, OuterProps> {
72
+ componentStyle: R extends 'web' ? ComponentStyle : never;
73
+ foldedComponentIds: R extends 'web' ? Array<string> : never;
74
+ inlineStyle: R extends 'native' ? InstanceType<IInlineStyleConstructor<OuterProps>> : never;
75
+ target: StyledTarget<R>;
76
+ styledComponentId: R extends 'web' ? string : never;
77
+ warnTooManyClasses?: R extends 'web' ? ReturnType<typeof createWarnTooManyClasses> : never;
78
+ withComponent: <Target extends StyledTarget<R>, Props = unknown>(tag: Target) => IStyledComponent<R, Target, OuterProps & Props>;
79
79
  }
80
- declare type PolymorphicComponentProps<ActualComponent extends StyledTarget, PropsToBeInjectedIntoActualComponent extends {}, ActualComponentProps = ActualComponent extends KnownTarget ? React.ComponentPropsWithRef<ActualComponent> : {}> = React.HTMLAttributes<ActualComponent> & Omit<PropsToBeInjectedIntoActualComponent, keyof ActualComponentProps | 'as' | '$as'> & ActualComponentProps & ({
80
+ declare type PolymorphicComponentProps<R extends Runtime, ActualComponent extends StyledTarget<R>, PropsToBeInjectedIntoActualComponent extends {}, ActualComponentProps = ActualComponent extends KnownTarget ? React.ComponentPropsWithRef<ActualComponent> : {}> = React.HTMLAttributes<ActualComponent> & Omit<PropsToBeInjectedIntoActualComponent, keyof ActualComponentProps | 'as' | '$as'> & ActualComponentProps & ({
81
81
  $as: ActualComponent;
82
82
  as?: AnyComponent;
83
83
  } | {
84
84
  as?: ActualComponent;
85
85
  });
86
- interface PolymorphicComponent<FallbackComponent extends StyledTarget, ExpectedProps = unknown, PropsToBeInjectedIntoActualComponent = unknown> extends React.ForwardRefExoticComponent<ExpectedProps> {
87
- <ActualComponent extends StyledTarget = FallbackComponent>(props: PolymorphicComponentProps<ActualComponent, ExpectedProps & PropsToBeInjectedIntoActualComponent>): React.ReactElement<PolymorphicComponentProps<ActualComponent, ExecutionContext & ExpectedProps & PropsToBeInjectedIntoActualComponent>, ActualComponent>;
86
+ interface PolymorphicComponent<R extends Runtime, FallbackComponent extends StyledTarget<R>, ExpectedProps = unknown, PropsToBeInjectedIntoActualComponent = unknown> extends React.ForwardRefExoticComponent<ExpectedProps> {
87
+ <ActualComponent extends StyledTarget<R> = FallbackComponent>(props: PolymorphicComponentProps<R, ActualComponent, ExpectedProps & PropsToBeInjectedIntoActualComponent>): React.ReactElement<PolymorphicComponentProps<R, ActualComponent, ExecutionContext & ExpectedProps & PropsToBeInjectedIntoActualComponent>, ActualComponent>;
88
88
  }
89
- export interface IStyledComponent<Target extends WebTarget, Props = unknown> extends PolymorphicComponent<Target, Props, ExecutionContext>, IStyledStatics<Props> {
89
+ export interface IStyledComponent<R extends Runtime, Target extends StyledTarget<R>, Props = unknown> extends PolymorphicComponent<R, Target, Props, ExecutionContext>, IStyledStatics<R, Props> {
90
90
  defaultProps?: Partial<ExtensibleObject & (Target extends KnownTarget ? React.ComponentProps<Target> : {}) & Props>;
91
91
  toString: () => string;
92
92
  }
93
- export interface IStyledComponentFactory<Target extends WebTarget, Props = unknown, Statics = unknown> {
94
- (target: Target, options: StyledOptions<Props>, rules: RuleSet<Props>): IStyledComponent<Target, Props> & Statics;
95
- }
96
- export interface IStyledNativeStatics<OuterProps = unknown> extends CommonStatics<OuterProps> {
97
- inlineStyle: InstanceType<IInlineStyleConstructor<OuterProps>>;
98
- target: NativeTarget;
99
- withComponent: <Target extends NativeTarget, Props = unknown>(tag: Target) => IStyledNativeComponent<Target, OuterProps & Props>;
100
- }
101
- export interface IStyledNativeComponent<Target extends NativeTarget, Props = unknown> extends PolymorphicComponent<Target, Props, ExecutionContext>, IStyledNativeStatics<Props> {
102
- defaultProps?: Partial<ExtensibleObject & (Target extends KnownTarget ? React.ComponentProps<Target> : {}) & Props>;
103
- }
104
- export interface IStyledNativeComponentFactory<Target extends NativeTarget, Props = unknown, Statics = unknown> {
105
- (target: Target, options: StyledNativeOptions<Props>, rules: RuleSet<Props>): IStyledNativeComponent<Target, Props> & Statics;
93
+ export interface IStyledComponentFactory<R extends Runtime, Target extends StyledTarget<R>, Props = unknown, Statics = unknown> {
94
+ (target: Target, options: StyledOptions<R, Props>, rules: RuleSet<Props>): IStyledComponent<R, Target, Props> & Statics;
106
95
  }
107
96
  export interface IInlineStyleConstructor<Props = unknown> {
108
97
  new (rules: RuleSet<Props>): IInlineStyle<Props>;
@@ -111,7 +100,7 @@ export interface IInlineStyle<Props = unknown> {
111
100
  rules: RuleSet<Props>;
112
101
  generateStyleObject(executionContext: Object): Object;
113
102
  }
114
- export declare type StyledTarget = WebTarget | NativeTarget;
103
+ export declare type StyledTarget<R extends Runtime> = R extends 'web' ? WebTarget : NativeTarget;
115
104
  export interface StyledObject<Props = ExecutionContext> {
116
105
  [key: string]: BaseExtensibleObject | string | number | StyleFunction<Props>;
117
106
  }
@@ -1,2 +1,2 @@
1
1
  import { StyledTarget } from '../types';
2
- export default function generateDisplayName(target: StyledTarget): string;
2
+ export default function generateDisplayName(target: StyledTarget<any>): string;
@@ -1,2 +1,2 @@
1
1
  import { StyledTarget } from '../types';
2
- export default function getComponentName(target: StyledTarget): string;
2
+ export default function getComponentName(target: StyledTarget<any>): string;
@@ -1,2 +1,2 @@
1
1
  import { IStyledComponent } from '../types';
2
- export default function isStyledComponent(target: any): target is IStyledComponent<any>;
2
+ export default function isStyledComponent(target: any): target is IStyledComponent<'web', any>;
@@ -1,2 +1,2 @@
1
1
  import { StyledTarget } from '../types';
2
- export default function isTag(target: StyledTarget): boolean;
2
+ export default function isTag(target: StyledTarget<'web'>): target is string;
@@ -1,9 +1,10 @@
1
+ import { Middleware } from 'stylis';
1
2
  import { Stringifier } from '../types';
2
3
  declare type StylisInstanceConstructorArgs = {
3
4
  options?: {
4
5
  prefix?: boolean;
5
6
  };
6
- plugins?: stylis.Middleware[];
7
+ plugins?: Middleware[];
7
8
  };
8
9
  export default function createStylisInstance({ options, plugins, }?: StylisInstanceConstructorArgs): Stringifier;
9
10
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "styled-components",
3
- "version": "6.0.0-alpha.7",
3
+ "version": "6.0.0-beta.2",
4
4
  "description": "Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/styled-components.cjs.js",
@@ -20,8 +20,8 @@
20
20
  "postbuild": "yarn lint:size",
21
21
  "pretest": "yarn generateErrors",
22
22
  "test": "yarn test:web && yarn test:native",
23
- "test:web": "jest -c jest.config.main.js",
24
- "test:native": "jest -c jest.config.native.js",
23
+ "test:web": "jest -c jest.config.main.js --forceExit",
24
+ "test:native": "jest -c jest.config.native.js --forceExit",
25
25
  "test:integration": "jest -c jest.config.integration.js --runInBand --forceExit",
26
26
  "format": "eslint ./**/*.js --fix",
27
27
  "lint": "eslint src",
@@ -69,7 +69,6 @@
69
69
  "@babel/preset-react": "^7.18.6",
70
70
  "@babel/preset-typescript": "^7.18.6",
71
71
  "@babel/traverse": "^7.18.8",
72
- "@emotion/is-prop-valid": "^1.1.3",
73
72
  "@emotion/unitless": "^0.7.4",
74
73
  "css-to-react-native": "^3.0.0",
75
74
  "shallowequal": "^1.1.0",
@@ -90,7 +89,7 @@
90
89
  "@rollup/plugin-typescript": "^8.3.3",
91
90
  "@types/babel-plugin-macros": "^2.8.4",
92
91
  "@types/enzyme": "^3.10.9",
93
- "@types/jest": "^27.0.2",
92
+ "@types/jest": "^28.1.6",
94
93
  "@types/js-beautify": "^1.13.1",
95
94
  "@types/node": "^14.0.0",
96
95
  "@types/react": "^17.0.22",
@@ -103,7 +102,7 @@
103
102
  "@typescript-eslint/eslint-plugin": "^4.20.0",
104
103
  "@typescript-eslint/parser": "^4.20.0",
105
104
  "babel-eslint": "^10.0.1",
106
- "babel-jest": "^27.0.6",
105
+ "babel-jest": "^28.1.3",
107
106
  "babel-plugin-add-module-exports": "^1.0.4",
108
107
  "babel-plugin-macros": "^3.1.0",
109
108
  "babel-plugin-styled-components": "^2.0.5",
@@ -114,9 +113,11 @@
114
113
  "eslint-plugin-prettier": "^4.0.0",
115
114
  "eslint-plugin-react": "^7.20.6",
116
115
  "eslint-plugin-react-hooks": "^4.2.0",
117
- "jest": "^27.0.6",
116
+ "jest": "^28.1.3",
117
+ "jest-environment-jsdom": "^28.1.3",
118
118
  "jest-image-snapshot": "^4.2.0",
119
119
  "jest-serializer-html": "^7.0.0",
120
+ "jest-watch-typeahead": "^2.0.0",
120
121
  "js-beautify": "^1.13.0",
121
122
  "prettier": "^2.2.0",
122
123
  "prop-types": "^15.7.2",
@@ -133,7 +134,6 @@
133
134
  "rollup-plugin-sourcemaps": "^0.6.3",
134
135
  "rollup-plugin-terser": "^7.0.2",
135
136
  "stylis-plugin-rtl": "^2.1.1",
136
- "tslib": "^2.4.0",
137
137
  "typescript": "^4.7.4",
138
138
  "utility-types": "^3.10.0"
139
139
  },
@@ -3,14 +3,20 @@ const consoleError = console.error;
3
3
  const suppressedErrors = [
4
4
  'Error: Could not parse CSS stylesheet',
5
5
  'Warning: Use the `defaultValue` or `value` props instead of setting children on <textarea>',
6
+ 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
6
7
  ];
7
8
 
8
9
  beforeEach(() => {
9
10
  // Suppress errors from JSDOM CSS parser
10
11
  // See: https://github.com/jsdom/jsdom/issues/2177
11
- console.error = (message: any) => {
12
- if (!suppressedErrors.some(suppressedError => message.includes(suppressedError))) {
13
- consoleError(message);
12
+ console.error = (logged: any) => {
13
+ const message = logged.stack || logged;
14
+
15
+ if (
16
+ typeof message !== 'string' ||
17
+ !suppressedErrors.some(suppressedError => message.includes(suppressedError))
18
+ ) {
19
+ consoleError(logged);
14
20
  }
15
21
  };
16
22
  });