tailwind-styled-v4 5.1.33 → 5.1.35
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/index.browser.mjs +2 -2
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.d.mts +26 -8
- package/dist/index.d.ts +26 -8
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -18,9 +18,19 @@ type SizesConfig = Record<string, string>;
|
|
|
18
18
|
* supaya kedua tempat itu tidak duplikasi & selalu konsisten.
|
|
19
19
|
*/
|
|
20
20
|
type InferVariantPropsFromVariantsMap<V> = {
|
|
21
|
-
[K in keyof V]?: V[K] extends Record<infer Key,
|
|
21
|
+
[K in keyof V as string extends K ? never : number extends K ? never : K]?: V[K] extends Record<infer Key, unknown> ? Key extends "true" | "false" ? boolean : Key extends number ? Key : Key extends `${infer N extends number}` ? N : Key : never;
|
|
22
22
|
};
|
|
23
23
|
type InferVariantProps<T extends ComponentConfig> = InferVariantPropsFromVariantsMap<T["variants"]>;
|
|
24
|
+
/**
|
|
25
|
+
* Infer allowed types for defaultVariants based on variant keys.
|
|
26
|
+
* Supports:
|
|
27
|
+
* - String keys: { variant: "primary" }
|
|
28
|
+
* - Number keys: { priority: 0 }
|
|
29
|
+
* - Boolean keys: { disabled: false } (translates true/false to "true"/"false" keys)
|
|
30
|
+
*
|
|
31
|
+
* This helper ensures type safety when defaultVariants contains non-string values.
|
|
32
|
+
*/
|
|
33
|
+
type InferDefaultVariantsType<T extends ComponentConfig> = InferVariantPropsFromVariantsMap<T["variants"]>;
|
|
24
34
|
type InferSizeProps<T extends ComponentConfig> = T["sizes"] extends Record<string, string> ? {
|
|
25
35
|
size?: keyof T["sizes"];
|
|
26
36
|
} : Record<never, never>;
|
|
@@ -33,7 +43,7 @@ type InferSizeProps<T extends ComponentConfig> = T["sizes"] extends Record<strin
|
|
|
33
43
|
* // → { loading?: boolean, fullWidth?: boolean }
|
|
34
44
|
*/
|
|
35
45
|
type InferStatesProps<T extends ComponentConfig> = {
|
|
36
|
-
[K in keyof T["states"]]?: boolean;
|
|
46
|
+
[K in keyof T["states"] as string extends K ? never : number extends K ? never : K]?: boolean;
|
|
37
47
|
};
|
|
38
48
|
/**
|
|
39
49
|
* Sub-component config bisa berupa:
|
|
@@ -237,7 +247,7 @@ interface StateConfig {
|
|
|
237
247
|
defaultStates?: Record<string, boolean>;
|
|
238
248
|
}
|
|
239
249
|
type CvFn<C extends ComponentConfig> = (props?: {
|
|
240
|
-
[K in keyof C["variants"]]?: keyof C["variants"][K];
|
|
250
|
+
[K in keyof C["variants"] as string extends K ? never : number extends K ? never : K]?: keyof C["variants"][K];
|
|
241
251
|
} & {
|
|
242
252
|
class?: string;
|
|
243
253
|
className?: string;
|
|
@@ -248,7 +258,7 @@ interface StyledComponentProps {
|
|
|
248
258
|
children?: React.ReactNode;
|
|
249
259
|
}
|
|
250
260
|
type SubComponentMap = Record<string, unknown>;
|
|
251
|
-
type TwSubComponentAccessor<Tag extends HtmlTagName = "span", ExtraProps extends Record<string, unknown> = Record<never, never>> = React.FC<Omit<React.ComponentPropsWithoutRef<Tag>, "ref"> & ExtraProps & {
|
|
261
|
+
type TwSubComponentAccessor<Tag extends HtmlTagName = "span", ExtraProps extends Record<string, unknown> = Record<never, never>> = React.FC<Omit<React.ComponentPropsWithoutRef<Tag>, "ref" | keyof ExtraProps> & ExtraProps & {
|
|
252
262
|
children?: React.ReactNode;
|
|
253
263
|
className?: string;
|
|
254
264
|
}>;
|
|
@@ -264,18 +274,24 @@ type SubComponentKeys<S extends string, TagMap extends Record<string, string> =
|
|
|
264
274
|
[K in S]: TwSubComponentAccessor<K extends keyof TagMap ? (TagMap[K] extends HtmlTagName ? TagMap[K] : "span") : "span", K extends keyof SubVariantsMap ? SubVariantsMap[K] : Record<never, never>>;
|
|
265
275
|
};
|
|
266
276
|
type TwStyledComponent<Config extends ComponentConfig = ComponentConfig, S extends string = string, TagMap extends Record<string, string> = Record<string, never>, Tag extends HtmlTagName = HtmlTagName, SubVariantsMap extends Record<string, Record<string, unknown>> = Record<string, never>> = {
|
|
267
|
-
(props: React.ComponentPropsWithoutRef<Tag> & StyledComponentProps & InferVariantProps<Config> & InferSizeProps<Config> & InferStatesProps<Config>): React.ReactElement | null;
|
|
277
|
+
(props: Omit<React.ComponentPropsWithoutRef<Tag>, keyof InferVariantProps<Config> | keyof InferSizeProps<Config> | keyof InferStatesProps<Config>> & StyledComponentProps & InferVariantProps<Config> & InferSizeProps<Config> & InferStatesProps<Config>): React.ReactElement | null;
|
|
268
278
|
displayName?: string;
|
|
269
279
|
extend: {
|
|
270
280
|
(strings: TemplateStringsArray, ...exprs: unknown[]): TwStyledComponent<Config, S, TagMap, Tag, SubVariantsMap>;
|
|
271
|
-
|
|
281
|
+
<EC extends {
|
|
272
282
|
classes?: string;
|
|
273
283
|
variants?: ComponentConfig["variants"];
|
|
274
284
|
defaultVariants?: ComponentConfig["defaultVariants"];
|
|
275
285
|
compoundVariants?: ComponentConfig["compoundVariants"];
|
|
286
|
+
}>(config: EC & {
|
|
287
|
+
defaultVariants?: InferDefaultVariantsType<{
|
|
288
|
+
variants: EC["variants"];
|
|
289
|
+
}>;
|
|
276
290
|
}): TwStyledComponent<Config, S, TagMap, Tag, SubVariantsMap>;
|
|
277
291
|
};
|
|
278
|
-
withVariants: (config: Partial<
|
|
292
|
+
withVariants: (config: Partial<Omit<Config, "defaultVariants">> & {
|
|
293
|
+
defaultVariants?: InferDefaultVariantsType<Config>;
|
|
294
|
+
}) => TwStyledComponent<Config, S, TagMap, Tag, SubVariantsMap>;
|
|
279
295
|
/**
|
|
280
296
|
* Declare sub-component names secara eksplisit untuk autocomplete + type safety.
|
|
281
297
|
*
|
|
@@ -296,7 +312,9 @@ interface TwSubComponent<P = unknown> {
|
|
|
296
312
|
displayName?: string;
|
|
297
313
|
}
|
|
298
314
|
interface TwTemplateFactory<Config extends ComponentConfig = ComponentConfig, Tag extends HtmlTagName = HtmlTagName> {
|
|
299
|
-
<C extends ComponentConfig>(config: C
|
|
315
|
+
<C extends ComponentConfig>(config: C & {
|
|
316
|
+
defaultVariants?: InferDefaultVariantsType<C>;
|
|
317
|
+
}): TwStyledComponent<C, InferSubFromConfig<C>, InferSubTagsFromConfig<C> extends Record<string, string> ? InferSubTagsFromConfig<C> : Record<string, never>, Tag, InferSubVariantsFromConfig<C> extends Record<string, Record<string, unknown>> ? InferSubVariantsFromConfig<C> : Record<string, never>>;
|
|
300
318
|
<const T extends string>(strings: readonly [T], ...exprs: []): TwStyledComponent<Config, ExtractSubNames<T>, Record<string, never>, Tag>;
|
|
301
319
|
(strings: TemplateStringsArray, ...exprs: unknown[]): TwStyledComponent<Config, string, Record<string, never>, Tag>;
|
|
302
320
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -18,9 +18,19 @@ type SizesConfig = Record<string, string>;
|
|
|
18
18
|
* supaya kedua tempat itu tidak duplikasi & selalu konsisten.
|
|
19
19
|
*/
|
|
20
20
|
type InferVariantPropsFromVariantsMap<V> = {
|
|
21
|
-
[K in keyof V]?: V[K] extends Record<infer Key,
|
|
21
|
+
[K in keyof V as string extends K ? never : number extends K ? never : K]?: V[K] extends Record<infer Key, unknown> ? Key extends "true" | "false" ? boolean : Key extends number ? Key : Key extends `${infer N extends number}` ? N : Key : never;
|
|
22
22
|
};
|
|
23
23
|
type InferVariantProps<T extends ComponentConfig> = InferVariantPropsFromVariantsMap<T["variants"]>;
|
|
24
|
+
/**
|
|
25
|
+
* Infer allowed types for defaultVariants based on variant keys.
|
|
26
|
+
* Supports:
|
|
27
|
+
* - String keys: { variant: "primary" }
|
|
28
|
+
* - Number keys: { priority: 0 }
|
|
29
|
+
* - Boolean keys: { disabled: false } (translates true/false to "true"/"false" keys)
|
|
30
|
+
*
|
|
31
|
+
* This helper ensures type safety when defaultVariants contains non-string values.
|
|
32
|
+
*/
|
|
33
|
+
type InferDefaultVariantsType<T extends ComponentConfig> = InferVariantPropsFromVariantsMap<T["variants"]>;
|
|
24
34
|
type InferSizeProps<T extends ComponentConfig> = T["sizes"] extends Record<string, string> ? {
|
|
25
35
|
size?: keyof T["sizes"];
|
|
26
36
|
} : Record<never, never>;
|
|
@@ -33,7 +43,7 @@ type InferSizeProps<T extends ComponentConfig> = T["sizes"] extends Record<strin
|
|
|
33
43
|
* // → { loading?: boolean, fullWidth?: boolean }
|
|
34
44
|
*/
|
|
35
45
|
type InferStatesProps<T extends ComponentConfig> = {
|
|
36
|
-
[K in keyof T["states"]]?: boolean;
|
|
46
|
+
[K in keyof T["states"] as string extends K ? never : number extends K ? never : K]?: boolean;
|
|
37
47
|
};
|
|
38
48
|
/**
|
|
39
49
|
* Sub-component config bisa berupa:
|
|
@@ -237,7 +247,7 @@ interface StateConfig {
|
|
|
237
247
|
defaultStates?: Record<string, boolean>;
|
|
238
248
|
}
|
|
239
249
|
type CvFn<C extends ComponentConfig> = (props?: {
|
|
240
|
-
[K in keyof C["variants"]]?: keyof C["variants"][K];
|
|
250
|
+
[K in keyof C["variants"] as string extends K ? never : number extends K ? never : K]?: keyof C["variants"][K];
|
|
241
251
|
} & {
|
|
242
252
|
class?: string;
|
|
243
253
|
className?: string;
|
|
@@ -248,7 +258,7 @@ interface StyledComponentProps {
|
|
|
248
258
|
children?: React.ReactNode;
|
|
249
259
|
}
|
|
250
260
|
type SubComponentMap = Record<string, unknown>;
|
|
251
|
-
type TwSubComponentAccessor<Tag extends HtmlTagName = "span", ExtraProps extends Record<string, unknown> = Record<never, never>> = React.FC<Omit<React.ComponentPropsWithoutRef<Tag>, "ref"> & ExtraProps & {
|
|
261
|
+
type TwSubComponentAccessor<Tag extends HtmlTagName = "span", ExtraProps extends Record<string, unknown> = Record<never, never>> = React.FC<Omit<React.ComponentPropsWithoutRef<Tag>, "ref" | keyof ExtraProps> & ExtraProps & {
|
|
252
262
|
children?: React.ReactNode;
|
|
253
263
|
className?: string;
|
|
254
264
|
}>;
|
|
@@ -264,18 +274,24 @@ type SubComponentKeys<S extends string, TagMap extends Record<string, string> =
|
|
|
264
274
|
[K in S]: TwSubComponentAccessor<K extends keyof TagMap ? (TagMap[K] extends HtmlTagName ? TagMap[K] : "span") : "span", K extends keyof SubVariantsMap ? SubVariantsMap[K] : Record<never, never>>;
|
|
265
275
|
};
|
|
266
276
|
type TwStyledComponent<Config extends ComponentConfig = ComponentConfig, S extends string = string, TagMap extends Record<string, string> = Record<string, never>, Tag extends HtmlTagName = HtmlTagName, SubVariantsMap extends Record<string, Record<string, unknown>> = Record<string, never>> = {
|
|
267
|
-
(props: React.ComponentPropsWithoutRef<Tag> & StyledComponentProps & InferVariantProps<Config> & InferSizeProps<Config> & InferStatesProps<Config>): React.ReactElement | null;
|
|
277
|
+
(props: Omit<React.ComponentPropsWithoutRef<Tag>, keyof InferVariantProps<Config> | keyof InferSizeProps<Config> | keyof InferStatesProps<Config>> & StyledComponentProps & InferVariantProps<Config> & InferSizeProps<Config> & InferStatesProps<Config>): React.ReactElement | null;
|
|
268
278
|
displayName?: string;
|
|
269
279
|
extend: {
|
|
270
280
|
(strings: TemplateStringsArray, ...exprs: unknown[]): TwStyledComponent<Config, S, TagMap, Tag, SubVariantsMap>;
|
|
271
|
-
|
|
281
|
+
<EC extends {
|
|
272
282
|
classes?: string;
|
|
273
283
|
variants?: ComponentConfig["variants"];
|
|
274
284
|
defaultVariants?: ComponentConfig["defaultVariants"];
|
|
275
285
|
compoundVariants?: ComponentConfig["compoundVariants"];
|
|
286
|
+
}>(config: EC & {
|
|
287
|
+
defaultVariants?: InferDefaultVariantsType<{
|
|
288
|
+
variants: EC["variants"];
|
|
289
|
+
}>;
|
|
276
290
|
}): TwStyledComponent<Config, S, TagMap, Tag, SubVariantsMap>;
|
|
277
291
|
};
|
|
278
|
-
withVariants: (config: Partial<
|
|
292
|
+
withVariants: (config: Partial<Omit<Config, "defaultVariants">> & {
|
|
293
|
+
defaultVariants?: InferDefaultVariantsType<Config>;
|
|
294
|
+
}) => TwStyledComponent<Config, S, TagMap, Tag, SubVariantsMap>;
|
|
279
295
|
/**
|
|
280
296
|
* Declare sub-component names secara eksplisit untuk autocomplete + type safety.
|
|
281
297
|
*
|
|
@@ -296,7 +312,9 @@ interface TwSubComponent<P = unknown> {
|
|
|
296
312
|
displayName?: string;
|
|
297
313
|
}
|
|
298
314
|
interface TwTemplateFactory<Config extends ComponentConfig = ComponentConfig, Tag extends HtmlTagName = HtmlTagName> {
|
|
299
|
-
<C extends ComponentConfig>(config: C
|
|
315
|
+
<C extends ComponentConfig>(config: C & {
|
|
316
|
+
defaultVariants?: InferDefaultVariantsType<C>;
|
|
317
|
+
}): TwStyledComponent<C, InferSubFromConfig<C>, InferSubTagsFromConfig<C> extends Record<string, string> ? InferSubTagsFromConfig<C> : Record<string, never>, Tag, InferSubVariantsFromConfig<C> extends Record<string, Record<string, unknown>> ? InferSubVariantsFromConfig<C> : Record<string, never>>;
|
|
300
318
|
<const T extends string>(strings: readonly [T], ...exprs: []): TwStyledComponent<Config, ExtractSubNames<T>, Record<string, never>, Tag>;
|
|
301
319
|
(strings: TemplateStringsArray, ...exprs: unknown[]): TwStyledComponent<Config, string, Record<string, never>, Tag>;
|
|
302
320
|
}
|
package/dist/index.js
CHANGED
|
@@ -1046,7 +1046,7 @@ function attachExtend(component, originalTag, base, config) {
|
|
|
1046
1046
|
return extended;
|
|
1047
1047
|
}
|
|
1048
1048
|
component.extend = extendWithClasses;
|
|
1049
|
-
component.withVariants = (newConfig) => {
|
|
1049
|
+
component.withVariants = ((newConfig) => {
|
|
1050
1050
|
const existing = typeof config === "object" ? config : {};
|
|
1051
1051
|
return createComponent(originalTag, {
|
|
1052
1052
|
...existing,
|
|
@@ -1061,7 +1061,7 @@ function attachExtend(component, originalTag, base, config) {
|
|
|
1061
1061
|
...newConfig.defaultVariants ?? {}
|
|
1062
1062
|
}
|
|
1063
1063
|
});
|
|
1064
|
-
};
|
|
1064
|
+
});
|
|
1065
1065
|
component.withSub = (() => component);
|
|
1066
1066
|
return component;
|
|
1067
1067
|
}
|