styled-components 6.4.2 → 6.4.3
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/dist/constructors/constructWithOptions.d.ts +2 -2
- package/dist/styled-components.browser.cjs.js +1 -1
- package/dist/styled-components.browser.cjs.js.map +1 -1
- package/dist/styled-components.browser.esm.js +1 -1
- package/dist/styled-components.browser.esm.js.map +1 -1
- package/dist/styled-components.cjs.js +1 -1
- package/dist/styled-components.cjs.js.map +1 -1
- package/dist/styled-components.esm.js +1 -1
- package/dist/styled-components.esm.js.map +1 -1
- package/dist/styled-components.js +1 -1
- package/dist/styled-components.js.map +1 -1
- package/dist/styled-components.min.js +1 -1
- package/dist/styled-components.min.js.map +1 -1
- package/dist/types.d.ts +65 -17
- package/native/dist/constructors/constructWithOptions.d.ts +2 -2
- package/native/dist/dist/constructors/constructWithOptions.d.ts +2 -2
- package/native/dist/dist/types.d.ts +65 -17
- package/native/dist/styled-components.native.cjs.js.map +1 -1
- package/native/dist/styled-components.native.esm.js.map +1 -1
- package/native/dist/types.d.ts +65 -17
- package/package.json +1 -1
package/dist/types.d.ts
CHANGED
|
@@ -121,10 +121,48 @@ export interface IStyledStatics<out R extends Runtime, in out OuterProps extends
|
|
|
121
121
|
/**
|
|
122
122
|
* Used by PolymorphicComponent to define prop override cascading order.
|
|
123
123
|
*/
|
|
124
|
-
export type PolymorphicComponentProps<R extends Runtime, BaseProps extends BaseObject, AsTarget extends StyledTarget<R> |
|
|
124
|
+
export type PolymorphicComponentProps<R extends Runtime, BaseProps extends BaseObject, AsTarget extends StyledTarget<R> | (BaseProps extends {
|
|
125
|
+
as?: infer A;
|
|
126
|
+
} ? A : never) | void, ForwardedAsTarget extends StyledTarget<R> | void, AsTargetProps extends BaseObject = AsTarget extends KnownTarget ? React.ComponentPropsWithRef<AsTarget> : {}, ForwardedAsTargetProps extends BaseObject = ForwardedAsTarget extends KnownTarget ? React.ComponentPropsWithRef<ForwardedAsTarget> : {}> = OverrideStyle<NoInfer<FastOmit<Substitute<BaseProps, Substitute<ForwardedAsTargetProps, AsTargetProps>>, keyof ExecutionProps>> & FastOmit<ExecutionProps, 'as' | 'forwardedAs'> & {
|
|
125
127
|
as?: AsTarget;
|
|
126
128
|
forwardedAs?: ForwardedAsTarget;
|
|
127
129
|
}>;
|
|
130
|
+
/**
|
|
131
|
+
* Resolves the call-site props for one usage of a polymorphic component,
|
|
132
|
+
* branching on the supplied `as` / `forwardedAs` targets into the three prior
|
|
133
|
+
* overload shapes:
|
|
134
|
+
* - `as` is a real render target (e.g. `as="video"`, `as={Component}`):
|
|
135
|
+
* substitute that target's props and require `as`.
|
|
136
|
+
* - no `as`, or `as` is the wrapped component's own non-target type (e.g.
|
|
137
|
+
* Next.js Link's `as?: Url`): Substitute-free base props so ref callbacks
|
|
138
|
+
* infer with spread props (#5687), the wrapped `as` type stays assignable and
|
|
139
|
+
* optional (#5734), and BaseProps keys keep completing for plain usage (#5741).
|
|
140
|
+
* - `forwardedAs` only: substitute the forwarded target's props.
|
|
141
|
+
*
|
|
142
|
+
* Extracted to a named alias so identical (R, BaseProps, AsTarget,
|
|
143
|
+
* ForwardedAsTarget) tuples dedupe across the many JSX call sites in an app.
|
|
144
|
+
*
|
|
145
|
+
* The target test is `string | AnyComponent`, not the broader `WebTarget`
|
|
146
|
+
* (`KnownTarget | (string & {})`): both describe the same set (any string or
|
|
147
|
+
* component), but comparing against the ~156 literal members of `KnownTarget`
|
|
148
|
+
* here costs ~6% more type instantiations across all call sites. Don't narrow it
|
|
149
|
+
* to bare `KnownTarget` -- that drops custom element strings (`as="my-element"`)
|
|
150
|
+
* out of the target branch and makes them error.
|
|
151
|
+
*/
|
|
152
|
+
type PolymorphicCallProps<R extends Runtime, BaseProps extends BaseObject, AsTarget extends StyledTarget<R> | (BaseProps extends {
|
|
153
|
+
as?: infer A;
|
|
154
|
+
} ? A : never) | void, ForwardedAsTarget extends StyledTarget<R> | void> = [AsTarget] extends [string | AnyComponent] ? PolymorphicComponentProps<R, BaseProps, AsTarget, ForwardedAsTarget> & {
|
|
155
|
+
as: AsTarget;
|
|
156
|
+
} : [ForwardedAsTarget] extends [void] ? OverrideStyle<NoInfer<FastOmit<BaseProps, keyof ExecutionProps>> & FastOmit<ExecutionProps, 'as' | 'forwardedAs'> & {
|
|
157
|
+
as?: BaseProps extends {
|
|
158
|
+
as?: infer A;
|
|
159
|
+
} ? A : void;
|
|
160
|
+
forwardedAs?: BaseProps extends {
|
|
161
|
+
forwardedAs?: infer A;
|
|
162
|
+
} ? A : void;
|
|
163
|
+
}> : PolymorphicComponentProps<R, BaseProps, void, ForwardedAsTarget> & {
|
|
164
|
+
forwardedAs: ForwardedAsTarget;
|
|
165
|
+
};
|
|
128
166
|
/**
|
|
129
167
|
* This type forms the signature for a forwardRef-enabled component
|
|
130
168
|
* that accepts the "as" prop to dynamically change the underlying
|
|
@@ -136,22 +174,32 @@ export interface PolymorphicComponent<out R extends Runtime, in out BaseProps ex
|
|
|
136
174
|
as?: StyledTarget<R> | undefined;
|
|
137
175
|
forwardedAs?: StyledTarget<R> | undefined;
|
|
138
176
|
}> {
|
|
139
|
-
|
|
140
|
-
as?:
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
177
|
+
<AsTarget extends StyledTarget<R> | (BaseProps extends {
|
|
178
|
+
as?: infer A;
|
|
179
|
+
} ? A : never) | void = void, ForwardedAsTarget extends StyledTarget<R> | void = void>(props: PolymorphicCallProps<R, BaseProps, AsTarget, ForwardedAsTarget>): React.JSX.Element;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Some wrapped targets can't be statically introspected and their props
|
|
183
|
+
* collapse to `{}` -- most notably polymorphic-factory components (e.g. Mantine
|
|
184
|
+
* v7's `Button`, `Card`, `Menu.Item`), whose generic callable signature defeats
|
|
185
|
+
* `React.ComponentPropsWithRef`. A closed `{}` would reject every prop at the JSX
|
|
186
|
+
* call site, including `children`. Falling back to a permissive prop bag keeps
|
|
187
|
+
* these components usable; targets with introspectable props are unchanged.
|
|
188
|
+
*
|
|
189
|
+
* Applied only to the JSX call surface (`PolymorphicComponent`), never to the
|
|
190
|
+
* statics (`IStyledStatics`, `defaultProps`), so internal code keeps the real
|
|
191
|
+
* `Props` and the widening can't leak past the call site.
|
|
192
|
+
*
|
|
193
|
+
* The "no known keys" test is distributed over `Props` first. `keyof` on a union
|
|
194
|
+
* intersects each member's keys, so a bare union of disjoint shapes (e.g.
|
|
195
|
+
* `{ a: string } | { b: string }`) has `keyof` of `never` despite being fully
|
|
196
|
+
* introspectable. Checking each constituent independently widens only when every
|
|
197
|
+
* member is truly empty.
|
|
198
|
+
*/
|
|
199
|
+
export type WidenUntypedProps<Props extends BaseObject> = (Props extends unknown ? (keyof Props extends never ? true : false) : never) extends true ? Props & {
|
|
200
|
+
[key: string]: unknown;
|
|
201
|
+
} : Props;
|
|
202
|
+
export interface IStyledComponentBase<out R extends Runtime, in out Props extends BaseObject = BaseObject> extends PolymorphicComponent<R, WidenUntypedProps<Props>>, IStyledStatics<R, Props>, StyledComponentBrand {
|
|
155
203
|
defaultProps?: (ExecutionProps & Partial<Props>) | undefined;
|
|
156
204
|
toString: () => string;
|
|
157
205
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Attrs, BaseObject, ExecutionProps, Interpolation, IStyledComponent, IStyledComponentFactory, KnownTarget, MakeAttrsOptional, Runtime, StyledOptions, StyledTarget, Styles, Substitute } from '../types';
|
|
1
|
+
import { Attrs, BaseObject, ExecutionProps, Interpolation, IStyledComponent, IStyledComponentFactory, KnownTarget, MakeAttrsOptional, Runtime, StyledOptions, StyledTarget, Styles, Substitute, WidenUntypedProps } from '../types';
|
|
2
2
|
type AttrsResult<T extends Attrs<any>> = T extends (...args: any) => infer P ? P extends object ? P : never : T extends object ? T : never;
|
|
3
3
|
/**
|
|
4
4
|
* Based on Attrs being a simple object or function that returns
|
|
@@ -10,7 +10,7 @@ type AttrsTarget<R extends Runtime, T extends Attrs<any>, FallbackTarget extends
|
|
|
10
10
|
} ? RuntimeTarget extends KnownTarget ? RuntimeTarget : FallbackTarget : FallbackTarget;
|
|
11
11
|
export interface Styled<out R extends Runtime, out Target extends StyledTarget<R>, in out OuterProps extends object, out OuterStatics extends object = BaseObject, out AttrsKeys extends keyof any = never> {
|
|
12
12
|
<Props extends object = BaseObject, Statics extends object = BaseObject>(initialStyles: Styles<Substitute<OuterProps, NoInfer<Props>>>, ...interpolations: Interpolation<Substitute<OuterProps, NoInfer<Props>>>[]): IStyledComponent<R, MakeAttrsOptional<Substitute<OuterProps, Props>, AttrsKeys>> & OuterStatics & Statics & (R extends 'web' ? Target extends string ? {} : Omit<Target, keyof React.Component<any>> : {});
|
|
13
|
-
attrs: <Props extends object = BaseObject, PrivateMergedProps extends object = Substitute<OuterProps, Props>, PrivateAttrsArg extends Attrs<PrivateMergedProps
|
|
13
|
+
attrs: <Props extends object = BaseObject, PrivateMergedProps extends object = Substitute<OuterProps, Props>, PrivateAttrsArg extends Attrs<WidenUntypedProps<PrivateMergedProps>> = Attrs<WidenUntypedProps<PrivateMergedProps>>, PrivateResolvedTarget extends StyledTarget<R> = AttrsTarget<R, PrivateAttrsArg, Target>>(attrs: PrivateAttrsArg) => Styled<R, PrivateResolvedTarget, PrivateResolvedTarget extends KnownTarget ? Substitute<Substitute<OuterProps, React.ComponentPropsWithRef<PrivateResolvedTarget>>, Props> : PrivateMergedProps, OuterStatics, AttrsKeys | keyof AttrsResult<PrivateAttrsArg>>;
|
|
14
14
|
withConfig: (config: StyledOptions<R, OuterProps>) => Styled<R, Target, OuterProps, OuterStatics, AttrsKeys>;
|
|
15
15
|
}
|
|
16
16
|
export default function constructWithOptions<R extends Runtime, Target extends StyledTarget<R>, OuterProps extends object = Target extends KnownTarget ? React.ComponentPropsWithRef<Target> : BaseObject, OuterStatics extends object = BaseObject, AttrsKeys extends keyof any = never>(componentConstructor: IStyledComponentFactory<R, StyledTarget<R>, object, any>, tag: StyledTarget<R>, options?: StyledOptions<R, OuterProps>): Styled<R, Target, OuterProps, OuterStatics, AttrsKeys>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Attrs, BaseObject, ExecutionProps, Interpolation, IStyledComponent, IStyledComponentFactory, KnownTarget, MakeAttrsOptional, Runtime, StyledOptions, StyledTarget, Styles, Substitute } from '../types';
|
|
1
|
+
import { Attrs, BaseObject, ExecutionProps, Interpolation, IStyledComponent, IStyledComponentFactory, KnownTarget, MakeAttrsOptional, Runtime, StyledOptions, StyledTarget, Styles, Substitute, WidenUntypedProps } from '../types';
|
|
2
2
|
type AttrsResult<T extends Attrs<any>> = T extends (...args: any) => infer P ? P extends object ? P : never : T extends object ? T : never;
|
|
3
3
|
/**
|
|
4
4
|
* Based on Attrs being a simple object or function that returns
|
|
@@ -10,7 +10,7 @@ type AttrsTarget<R extends Runtime, T extends Attrs<any>, FallbackTarget extends
|
|
|
10
10
|
} ? RuntimeTarget extends KnownTarget ? RuntimeTarget : FallbackTarget : FallbackTarget;
|
|
11
11
|
export interface Styled<out R extends Runtime, out Target extends StyledTarget<R>, in out OuterProps extends object, out OuterStatics extends object = BaseObject, out AttrsKeys extends keyof any = never> {
|
|
12
12
|
<Props extends object = BaseObject, Statics extends object = BaseObject>(initialStyles: Styles<Substitute<OuterProps, NoInfer<Props>>>, ...interpolations: Interpolation<Substitute<OuterProps, NoInfer<Props>>>[]): IStyledComponent<R, MakeAttrsOptional<Substitute<OuterProps, Props>, AttrsKeys>> & OuterStatics & Statics & (R extends 'web' ? Target extends string ? {} : Omit<Target, keyof React.Component<any>> : {});
|
|
13
|
-
attrs: <Props extends object = BaseObject, PrivateMergedProps extends object = Substitute<OuterProps, Props>, PrivateAttrsArg extends Attrs<PrivateMergedProps
|
|
13
|
+
attrs: <Props extends object = BaseObject, PrivateMergedProps extends object = Substitute<OuterProps, Props>, PrivateAttrsArg extends Attrs<WidenUntypedProps<PrivateMergedProps>> = Attrs<WidenUntypedProps<PrivateMergedProps>>, PrivateResolvedTarget extends StyledTarget<R> = AttrsTarget<R, PrivateAttrsArg, Target>>(attrs: PrivateAttrsArg) => Styled<R, PrivateResolvedTarget, PrivateResolvedTarget extends KnownTarget ? Substitute<Substitute<OuterProps, React.ComponentPropsWithRef<PrivateResolvedTarget>>, Props> : PrivateMergedProps, OuterStatics, AttrsKeys | keyof AttrsResult<PrivateAttrsArg>>;
|
|
14
14
|
withConfig: (config: StyledOptions<R, OuterProps>) => Styled<R, Target, OuterProps, OuterStatics, AttrsKeys>;
|
|
15
15
|
}
|
|
16
16
|
export default function constructWithOptions<R extends Runtime, Target extends StyledTarget<R>, OuterProps extends object = Target extends KnownTarget ? React.ComponentPropsWithRef<Target> : BaseObject, OuterStatics extends object = BaseObject, AttrsKeys extends keyof any = never>(componentConstructor: IStyledComponentFactory<R, StyledTarget<R>, object, any>, tag: StyledTarget<R>, options?: StyledOptions<R, OuterProps>): Styled<R, Target, OuterProps, OuterStatics, AttrsKeys>;
|
|
@@ -121,10 +121,48 @@ export interface IStyledStatics<out R extends Runtime, in out OuterProps extends
|
|
|
121
121
|
/**
|
|
122
122
|
* Used by PolymorphicComponent to define prop override cascading order.
|
|
123
123
|
*/
|
|
124
|
-
export type PolymorphicComponentProps<R extends Runtime, BaseProps extends BaseObject, AsTarget extends StyledTarget<R> |
|
|
124
|
+
export type PolymorphicComponentProps<R extends Runtime, BaseProps extends BaseObject, AsTarget extends StyledTarget<R> | (BaseProps extends {
|
|
125
|
+
as?: infer A;
|
|
126
|
+
} ? A : never) | void, ForwardedAsTarget extends StyledTarget<R> | void, AsTargetProps extends BaseObject = AsTarget extends KnownTarget ? React.ComponentPropsWithRef<AsTarget> : {}, ForwardedAsTargetProps extends BaseObject = ForwardedAsTarget extends KnownTarget ? React.ComponentPropsWithRef<ForwardedAsTarget> : {}> = OverrideStyle<NoInfer<FastOmit<Substitute<BaseProps, Substitute<ForwardedAsTargetProps, AsTargetProps>>, keyof ExecutionProps>> & FastOmit<ExecutionProps, 'as' | 'forwardedAs'> & {
|
|
125
127
|
as?: AsTarget;
|
|
126
128
|
forwardedAs?: ForwardedAsTarget;
|
|
127
129
|
}>;
|
|
130
|
+
/**
|
|
131
|
+
* Resolves the call-site props for one usage of a polymorphic component,
|
|
132
|
+
* branching on the supplied `as` / `forwardedAs` targets into the three prior
|
|
133
|
+
* overload shapes:
|
|
134
|
+
* - `as` is a real render target (e.g. `as="video"`, `as={Component}`):
|
|
135
|
+
* substitute that target's props and require `as`.
|
|
136
|
+
* - no `as`, or `as` is the wrapped component's own non-target type (e.g.
|
|
137
|
+
* Next.js Link's `as?: Url`): Substitute-free base props so ref callbacks
|
|
138
|
+
* infer with spread props (#5687), the wrapped `as` type stays assignable and
|
|
139
|
+
* optional (#5734), and BaseProps keys keep completing for plain usage (#5741).
|
|
140
|
+
* - `forwardedAs` only: substitute the forwarded target's props.
|
|
141
|
+
*
|
|
142
|
+
* Extracted to a named alias so identical (R, BaseProps, AsTarget,
|
|
143
|
+
* ForwardedAsTarget) tuples dedupe across the many JSX call sites in an app.
|
|
144
|
+
*
|
|
145
|
+
* The target test is `string | AnyComponent`, not the broader `WebTarget`
|
|
146
|
+
* (`KnownTarget | (string & {})`): both describe the same set (any string or
|
|
147
|
+
* component), but comparing against the ~156 literal members of `KnownTarget`
|
|
148
|
+
* here costs ~6% more type instantiations across all call sites. Don't narrow it
|
|
149
|
+
* to bare `KnownTarget` -- that drops custom element strings (`as="my-element"`)
|
|
150
|
+
* out of the target branch and makes them error.
|
|
151
|
+
*/
|
|
152
|
+
type PolymorphicCallProps<R extends Runtime, BaseProps extends BaseObject, AsTarget extends StyledTarget<R> | (BaseProps extends {
|
|
153
|
+
as?: infer A;
|
|
154
|
+
} ? A : never) | void, ForwardedAsTarget extends StyledTarget<R> | void> = [AsTarget] extends [string | AnyComponent] ? PolymorphicComponentProps<R, BaseProps, AsTarget, ForwardedAsTarget> & {
|
|
155
|
+
as: AsTarget;
|
|
156
|
+
} : [ForwardedAsTarget] extends [void] ? OverrideStyle<NoInfer<FastOmit<BaseProps, keyof ExecutionProps>> & FastOmit<ExecutionProps, 'as' | 'forwardedAs'> & {
|
|
157
|
+
as?: BaseProps extends {
|
|
158
|
+
as?: infer A;
|
|
159
|
+
} ? A : void;
|
|
160
|
+
forwardedAs?: BaseProps extends {
|
|
161
|
+
forwardedAs?: infer A;
|
|
162
|
+
} ? A : void;
|
|
163
|
+
}> : PolymorphicComponentProps<R, BaseProps, void, ForwardedAsTarget> & {
|
|
164
|
+
forwardedAs: ForwardedAsTarget;
|
|
165
|
+
};
|
|
128
166
|
/**
|
|
129
167
|
* This type forms the signature for a forwardRef-enabled component
|
|
130
168
|
* that accepts the "as" prop to dynamically change the underlying
|
|
@@ -136,22 +174,32 @@ export interface PolymorphicComponent<out R extends Runtime, in out BaseProps ex
|
|
|
136
174
|
as?: StyledTarget<R> | undefined;
|
|
137
175
|
forwardedAs?: StyledTarget<R> | undefined;
|
|
138
176
|
}> {
|
|
139
|
-
|
|
140
|
-
as?:
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
177
|
+
<AsTarget extends StyledTarget<R> | (BaseProps extends {
|
|
178
|
+
as?: infer A;
|
|
179
|
+
} ? A : never) | void = void, ForwardedAsTarget extends StyledTarget<R> | void = void>(props: PolymorphicCallProps<R, BaseProps, AsTarget, ForwardedAsTarget>): React.JSX.Element;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Some wrapped targets can't be statically introspected and their props
|
|
183
|
+
* collapse to `{}` -- most notably polymorphic-factory components (e.g. Mantine
|
|
184
|
+
* v7's `Button`, `Card`, `Menu.Item`), whose generic callable signature defeats
|
|
185
|
+
* `React.ComponentPropsWithRef`. A closed `{}` would reject every prop at the JSX
|
|
186
|
+
* call site, including `children`. Falling back to a permissive prop bag keeps
|
|
187
|
+
* these components usable; targets with introspectable props are unchanged.
|
|
188
|
+
*
|
|
189
|
+
* Applied only to the JSX call surface (`PolymorphicComponent`), never to the
|
|
190
|
+
* statics (`IStyledStatics`, `defaultProps`), so internal code keeps the real
|
|
191
|
+
* `Props` and the widening can't leak past the call site.
|
|
192
|
+
*
|
|
193
|
+
* The "no known keys" test is distributed over `Props` first. `keyof` on a union
|
|
194
|
+
* intersects each member's keys, so a bare union of disjoint shapes (e.g.
|
|
195
|
+
* `{ a: string } | { b: string }`) has `keyof` of `never` despite being fully
|
|
196
|
+
* introspectable. Checking each constituent independently widens only when every
|
|
197
|
+
* member is truly empty.
|
|
198
|
+
*/
|
|
199
|
+
export type WidenUntypedProps<Props extends BaseObject> = (Props extends unknown ? (keyof Props extends never ? true : false) : never) extends true ? Props & {
|
|
200
|
+
[key: string]: unknown;
|
|
201
|
+
} : Props;
|
|
202
|
+
export interface IStyledComponentBase<out R extends Runtime, in out Props extends BaseObject = BaseObject> extends PolymorphicComponent<R, WidenUntypedProps<Props>>, IStyledStatics<R, Props>, StyledComponentBrand {
|
|
155
203
|
defaultProps?: (ExecutionProps & Partial<Props>) | undefined;
|
|
156
204
|
toString: () => string;
|
|
157
205
|
}
|