tailwind-styled-v4 5.1.31 → 5.1.33
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.d.mts +57 -17
- package/dist/index.d.ts +57 -17
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -12,9 +12,15 @@ type HtmlTagName = keyof HTMLElementTagNameMap;
|
|
|
12
12
|
type VariantLiterals = string | number | boolean;
|
|
13
13
|
/** Sizes sugar syntax — shorthand untuk variants.size */
|
|
14
14
|
type SizesConfig = Record<string, string>;
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Shared literal-narrowing logic dipakai baik oleh `InferVariantProps` (top-level
|
|
17
|
+
* component variants) maupun `InferSubVariantsFromConfig` (sub-component variants) —
|
|
18
|
+
* supaya kedua tempat itu tidak duplikasi & selalu konsisten.
|
|
19
|
+
*/
|
|
20
|
+
type InferVariantPropsFromVariantsMap<V> = {
|
|
21
|
+
[K in keyof V]?: V[K] extends Record<infer Key, any> ? Key extends "true" | "false" ? boolean : Key extends number ? Key : Key extends `${infer N extends number}` ? N : Key : never;
|
|
17
22
|
};
|
|
23
|
+
type InferVariantProps<T extends ComponentConfig> = InferVariantPropsFromVariantsMap<T["variants"]>;
|
|
18
24
|
type InferSizeProps<T extends ComponentConfig> = T["sizes"] extends Record<string, string> ? {
|
|
19
25
|
size?: keyof T["sizes"];
|
|
20
26
|
} : Record<never, never>;
|
|
@@ -53,7 +59,7 @@ interface SubComponentConfig {
|
|
|
53
59
|
[key: string]: string;
|
|
54
60
|
}>;
|
|
55
61
|
}
|
|
56
|
-
type SubValue = string | Record<string, string | SubComponentConfig>;
|
|
62
|
+
type SubValue = string | SubComponentConfig | Record<string, string | SubComponentConfig>;
|
|
57
63
|
/**
|
|
58
64
|
* Boolean props yang di-resolve via bitmask lookup table (pre-generated di build time).
|
|
59
65
|
* Berbeda dari `state` (CSS data-attribute driven) — ini adalah React props boolean.
|
|
@@ -139,16 +145,29 @@ interface ComponentConfig {
|
|
|
139
145
|
* "header" → "header" (tidak berubah)
|
|
140
146
|
*/
|
|
141
147
|
type ExtractSubName<K extends string> = K extends `${string}:${infer Name}` ? Name : K;
|
|
148
|
+
/**
|
|
149
|
+
* True kalau S[K] adalah SubComponentConfig LANGSUNG (satu sub-component dengan
|
|
150
|
+
* `base`/`variants` sendiri, mis. `canvas: { base: "...", variants: {...} }`) —
|
|
151
|
+
* bukan nested named-group (mis. `header: { topBar: "...", nav: "..." }`).
|
|
152
|
+
*
|
|
153
|
+
* HARUS identik dengan discriminant runtime di createComponent.ts:
|
|
154
|
+
* `"base" in value || "variants" in value`. Kedua bentuk sama-sama tampak sebagai
|
|
155
|
+
* `Record<string, ...>` secara struktural, jadi tidak bisa dibedakan cuma lewat
|
|
156
|
+
* `extends Record<string, string>` — perlu cek keberadaan key `base`/`variants`
|
|
157
|
+
* secara eksplisit seperti runtime-nya.
|
|
158
|
+
*/
|
|
159
|
+
type IsDirectSubConfig<V> = V extends string ? false : "variants" extends keyof V ? true : "base" extends keyof V ? true : false;
|
|
142
160
|
/**
|
|
143
161
|
* Infer semua sub-component names dari config.sub:
|
|
144
|
-
* - string value plain
|
|
145
|
-
* - string value tag:name
|
|
146
|
-
* -
|
|
162
|
+
* - string value plain → key langsung: { icon: "..." } → "icon"
|
|
163
|
+
* - string value tag:name → strip tag: { "div:action": "..." } → "action"
|
|
164
|
+
* - direct SubComponentConfig → key langsung (support "tag:name" juga): { canvas: {base, variants} } → "canvas"
|
|
165
|
+
* - nested named-group → nested keys: { h2: { title: "..." } } → "title"
|
|
147
166
|
*/
|
|
148
167
|
type InferSubFromConfig<C extends ComponentConfig> = C extends {
|
|
149
168
|
sub: infer S extends Record<string, SubValue>;
|
|
150
169
|
} ? {
|
|
151
|
-
[K in keyof S]: S[K] extends string ? K extends string ? ExtractSubName<K> : never : S[K] extends Record<infer N extends string, string> ? N : never;
|
|
170
|
+
[K in keyof S]: S[K] extends string ? K extends string ? ExtractSubName<K> : never : IsDirectSubConfig<S[K]> extends true ? K extends string ? ExtractSubName<K> : never : S[K] extends Record<infer N extends string, string> ? N : never;
|
|
152
171
|
}[keyof S] : never;
|
|
153
172
|
/**
|
|
154
173
|
* HTML tags yang otomatis dikenali sebagai tag dari bare sub-key (tanpa "tag:name" syntax).
|
|
@@ -182,10 +201,31 @@ type InferSubTagsFromConfig<C extends ComponentConfig> = C extends {
|
|
|
182
201
|
} ? UnionToIntersection<{
|
|
183
202
|
[K in keyof S]: K extends string ? S[K] extends string ? {
|
|
184
203
|
[N in ExtractSubName<K>]: ResolveSubTag<K>;
|
|
204
|
+
} : IsDirectSubConfig<S[K]> extends true ? {
|
|
205
|
+
[N in ExtractSubName<K>]: ResolveSubTag<K>;
|
|
185
206
|
} : S[K] extends Record<string, string> ? {
|
|
186
207
|
[N in keyof S[K]]: K extends HtmlTagName ? K : "span";
|
|
187
208
|
} : never : never;
|
|
188
209
|
}[keyof S]> : Record<string, never>;
|
|
210
|
+
/**
|
|
211
|
+
* Infer mapping { subComponentName: variantProps } dari config.sub — dipakai supaya
|
|
212
|
+
* sub-component yang punya `variants` sendiri (mis. `canvas: { base, variants: { layout: {...} } }`)
|
|
213
|
+
* ikut ke-expose propnya (`layout`) di accessor-nya (`PlaygroundWrap.canvas`), bukan cuma
|
|
214
|
+
* native HTML attributes dari tag-nya.
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* sub: { canvas: { variants: { layout: { wrap: "...", column: "..." } } } }
|
|
218
|
+
* → { canvas: { layout?: "wrap" | "column" } }
|
|
219
|
+
*/
|
|
220
|
+
type InferSubVariantsFromConfig<C extends ComponentConfig> = C extends {
|
|
221
|
+
sub: infer S extends Record<string, SubValue>;
|
|
222
|
+
} ? UnionToIntersection<{
|
|
223
|
+
[K in keyof S]: K extends string ? IsDirectSubConfig<S[K]> extends true ? S[K] extends {
|
|
224
|
+
variants?: infer V;
|
|
225
|
+
} ? {
|
|
226
|
+
[N in ExtractSubName<K>]: InferVariantPropsFromVariantsMap<V>;
|
|
227
|
+
} : Record<never, never> : Record<never, never> : Record<never, never>;
|
|
228
|
+
}[keyof S]> : Record<never, never>;
|
|
189
229
|
interface ContainerConfig {
|
|
190
230
|
base?: string;
|
|
191
231
|
queries?: Record<string, string>;
|
|
@@ -208,7 +248,7 @@ interface StyledComponentProps {
|
|
|
208
248
|
children?: React.ReactNode;
|
|
209
249
|
}
|
|
210
250
|
type SubComponentMap = Record<string, unknown>;
|
|
211
|
-
type TwSubComponentAccessor<Tag extends HtmlTagName = "span"> = React.FC<Omit<React.ComponentPropsWithoutRef<Tag>, "ref"> & {
|
|
251
|
+
type TwSubComponentAccessor<Tag extends HtmlTagName = "span", ExtraProps extends Record<string, unknown> = Record<never, never>> = React.FC<Omit<React.ComponentPropsWithoutRef<Tag>, "ref"> & ExtraProps & {
|
|
212
252
|
children?: React.ReactNode;
|
|
213
253
|
className?: string;
|
|
214
254
|
}>;
|
|
@@ -220,22 +260,22 @@ type TrimRight<S extends string> = S extends `${infer L} ` | `${infer L}
|
|
|
220
260
|
` ? TrimRight<L> : S;
|
|
221
261
|
type Trim<S extends string> = TrimLeft<TrimRight<S>>;
|
|
222
262
|
type ExtractSubNames<T extends string> = T extends `${string}[${infer Name}]${string}{${string}}${infer Rest}` ? Trim<Name> | ExtractSubNames<Rest> : T extends `${string}\n${infer Name}{${string}}${infer Rest}` ? (Trim<Name> extends "" ? never : Trim<Name>) | ExtractSubNames<Rest> : never;
|
|
223
|
-
type SubComponentKeys<S extends string, TagMap extends Record<string, string> = Record<string, never>> = {
|
|
224
|
-
[K in S]: TwSubComponentAccessor<K extends keyof TagMap ? (TagMap[K] extends HtmlTagName ? TagMap[K] : "span") : "span"
|
|
263
|
+
type SubComponentKeys<S extends string, TagMap extends Record<string, string> = Record<string, never>, SubVariantsMap extends Record<string, Record<string, unknown>> = Record<string, never>> = {
|
|
264
|
+
[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>>;
|
|
225
265
|
};
|
|
226
|
-
type TwStyledComponent<Config extends ComponentConfig = ComponentConfig, S extends string = string, TagMap extends Record<string, string> = Record<string, never>, Tag extends HtmlTagName = HtmlTagName
|
|
266
|
+
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>> = {
|
|
227
267
|
(props: React.ComponentPropsWithoutRef<Tag> & StyledComponentProps & InferVariantProps<Config> & InferSizeProps<Config> & InferStatesProps<Config>): React.ReactElement | null;
|
|
228
268
|
displayName?: string;
|
|
229
269
|
extend: {
|
|
230
|
-
(strings: TemplateStringsArray, ...exprs: unknown[]): TwStyledComponent<Config, S, TagMap, Tag>;
|
|
270
|
+
(strings: TemplateStringsArray, ...exprs: unknown[]): TwStyledComponent<Config, S, TagMap, Tag, SubVariantsMap>;
|
|
231
271
|
(config: {
|
|
232
272
|
classes?: string;
|
|
233
273
|
variants?: ComponentConfig["variants"];
|
|
234
274
|
defaultVariants?: ComponentConfig["defaultVariants"];
|
|
235
275
|
compoundVariants?: ComponentConfig["compoundVariants"];
|
|
236
|
-
}): TwStyledComponent<Config, S, TagMap, Tag>;
|
|
276
|
+
}): TwStyledComponent<Config, S, TagMap, Tag, SubVariantsMap>;
|
|
237
277
|
};
|
|
238
|
-
withVariants: (config: Partial<Config>) => TwStyledComponent<Config, S, TagMap, Tag>;
|
|
278
|
+
withVariants: (config: Partial<Config>) => TwStyledComponent<Config, S, TagMap, Tag, SubVariantsMap>;
|
|
239
279
|
/**
|
|
240
280
|
* Declare sub-component names secara eksplisit untuk autocomplete + type safety.
|
|
241
281
|
*
|
|
@@ -249,14 +289,14 @@ type TwStyledComponent<Config extends ComponentConfig = ComponentConfig, S exten
|
|
|
249
289
|
* Button.footer // ✅ autocomplete
|
|
250
290
|
* Button.xyz // ❌ TypeScript error
|
|
251
291
|
*/
|
|
252
|
-
withSub<NewS extends string>(): TwStyledComponent<Config, NewS, TagMap, Tag>;
|
|
253
|
-
} & SubComponentKeys<S, TagMap>;
|
|
292
|
+
withSub<NewS extends string>(): TwStyledComponent<Config, NewS, TagMap, Tag, SubVariantsMap>;
|
|
293
|
+
} & SubComponentKeys<S, TagMap, SubVariantsMap>;
|
|
254
294
|
interface TwSubComponent<P = unknown> {
|
|
255
295
|
(props: P): React.ReactElement | null;
|
|
256
296
|
displayName?: string;
|
|
257
297
|
}
|
|
258
298
|
interface TwTemplateFactory<Config extends ComponentConfig = ComponentConfig, Tag extends HtmlTagName = HtmlTagName> {
|
|
259
|
-
<C extends ComponentConfig>(config: C): TwStyledComponent<C, InferSubFromConfig<C>, InferSubTagsFromConfig<C> extends Record<string, string> ? InferSubTagsFromConfig<C> : Record<string, never>, Tag
|
|
299
|
+
<C extends ComponentConfig>(config: C): 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>>;
|
|
260
300
|
<const T extends string>(strings: readonly [T], ...exprs: []): TwStyledComponent<Config, ExtractSubNames<T>, Record<string, never>, Tag>;
|
|
261
301
|
(strings: TemplateStringsArray, ...exprs: unknown[]): TwStyledComponent<Config, string, Record<string, never>, Tag>;
|
|
262
302
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -12,9 +12,15 @@ type HtmlTagName = keyof HTMLElementTagNameMap;
|
|
|
12
12
|
type VariantLiterals = string | number | boolean;
|
|
13
13
|
/** Sizes sugar syntax — shorthand untuk variants.size */
|
|
14
14
|
type SizesConfig = Record<string, string>;
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Shared literal-narrowing logic dipakai baik oleh `InferVariantProps` (top-level
|
|
17
|
+
* component variants) maupun `InferSubVariantsFromConfig` (sub-component variants) —
|
|
18
|
+
* supaya kedua tempat itu tidak duplikasi & selalu konsisten.
|
|
19
|
+
*/
|
|
20
|
+
type InferVariantPropsFromVariantsMap<V> = {
|
|
21
|
+
[K in keyof V]?: V[K] extends Record<infer Key, any> ? Key extends "true" | "false" ? boolean : Key extends number ? Key : Key extends `${infer N extends number}` ? N : Key : never;
|
|
17
22
|
};
|
|
23
|
+
type InferVariantProps<T extends ComponentConfig> = InferVariantPropsFromVariantsMap<T["variants"]>;
|
|
18
24
|
type InferSizeProps<T extends ComponentConfig> = T["sizes"] extends Record<string, string> ? {
|
|
19
25
|
size?: keyof T["sizes"];
|
|
20
26
|
} : Record<never, never>;
|
|
@@ -53,7 +59,7 @@ interface SubComponentConfig {
|
|
|
53
59
|
[key: string]: string;
|
|
54
60
|
}>;
|
|
55
61
|
}
|
|
56
|
-
type SubValue = string | Record<string, string | SubComponentConfig>;
|
|
62
|
+
type SubValue = string | SubComponentConfig | Record<string, string | SubComponentConfig>;
|
|
57
63
|
/**
|
|
58
64
|
* Boolean props yang di-resolve via bitmask lookup table (pre-generated di build time).
|
|
59
65
|
* Berbeda dari `state` (CSS data-attribute driven) — ini adalah React props boolean.
|
|
@@ -139,16 +145,29 @@ interface ComponentConfig {
|
|
|
139
145
|
* "header" → "header" (tidak berubah)
|
|
140
146
|
*/
|
|
141
147
|
type ExtractSubName<K extends string> = K extends `${string}:${infer Name}` ? Name : K;
|
|
148
|
+
/**
|
|
149
|
+
* True kalau S[K] adalah SubComponentConfig LANGSUNG (satu sub-component dengan
|
|
150
|
+
* `base`/`variants` sendiri, mis. `canvas: { base: "...", variants: {...} }`) —
|
|
151
|
+
* bukan nested named-group (mis. `header: { topBar: "...", nav: "..." }`).
|
|
152
|
+
*
|
|
153
|
+
* HARUS identik dengan discriminant runtime di createComponent.ts:
|
|
154
|
+
* `"base" in value || "variants" in value`. Kedua bentuk sama-sama tampak sebagai
|
|
155
|
+
* `Record<string, ...>` secara struktural, jadi tidak bisa dibedakan cuma lewat
|
|
156
|
+
* `extends Record<string, string>` — perlu cek keberadaan key `base`/`variants`
|
|
157
|
+
* secara eksplisit seperti runtime-nya.
|
|
158
|
+
*/
|
|
159
|
+
type IsDirectSubConfig<V> = V extends string ? false : "variants" extends keyof V ? true : "base" extends keyof V ? true : false;
|
|
142
160
|
/**
|
|
143
161
|
* Infer semua sub-component names dari config.sub:
|
|
144
|
-
* - string value plain
|
|
145
|
-
* - string value tag:name
|
|
146
|
-
* -
|
|
162
|
+
* - string value plain → key langsung: { icon: "..." } → "icon"
|
|
163
|
+
* - string value tag:name → strip tag: { "div:action": "..." } → "action"
|
|
164
|
+
* - direct SubComponentConfig → key langsung (support "tag:name" juga): { canvas: {base, variants} } → "canvas"
|
|
165
|
+
* - nested named-group → nested keys: { h2: { title: "..." } } → "title"
|
|
147
166
|
*/
|
|
148
167
|
type InferSubFromConfig<C extends ComponentConfig> = C extends {
|
|
149
168
|
sub: infer S extends Record<string, SubValue>;
|
|
150
169
|
} ? {
|
|
151
|
-
[K in keyof S]: S[K] extends string ? K extends string ? ExtractSubName<K> : never : S[K] extends Record<infer N extends string, string> ? N : never;
|
|
170
|
+
[K in keyof S]: S[K] extends string ? K extends string ? ExtractSubName<K> : never : IsDirectSubConfig<S[K]> extends true ? K extends string ? ExtractSubName<K> : never : S[K] extends Record<infer N extends string, string> ? N : never;
|
|
152
171
|
}[keyof S] : never;
|
|
153
172
|
/**
|
|
154
173
|
* HTML tags yang otomatis dikenali sebagai tag dari bare sub-key (tanpa "tag:name" syntax).
|
|
@@ -182,10 +201,31 @@ type InferSubTagsFromConfig<C extends ComponentConfig> = C extends {
|
|
|
182
201
|
} ? UnionToIntersection<{
|
|
183
202
|
[K in keyof S]: K extends string ? S[K] extends string ? {
|
|
184
203
|
[N in ExtractSubName<K>]: ResolveSubTag<K>;
|
|
204
|
+
} : IsDirectSubConfig<S[K]> extends true ? {
|
|
205
|
+
[N in ExtractSubName<K>]: ResolveSubTag<K>;
|
|
185
206
|
} : S[K] extends Record<string, string> ? {
|
|
186
207
|
[N in keyof S[K]]: K extends HtmlTagName ? K : "span";
|
|
187
208
|
} : never : never;
|
|
188
209
|
}[keyof S]> : Record<string, never>;
|
|
210
|
+
/**
|
|
211
|
+
* Infer mapping { subComponentName: variantProps } dari config.sub — dipakai supaya
|
|
212
|
+
* sub-component yang punya `variants` sendiri (mis. `canvas: { base, variants: { layout: {...} } }`)
|
|
213
|
+
* ikut ke-expose propnya (`layout`) di accessor-nya (`PlaygroundWrap.canvas`), bukan cuma
|
|
214
|
+
* native HTML attributes dari tag-nya.
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* sub: { canvas: { variants: { layout: { wrap: "...", column: "..." } } } }
|
|
218
|
+
* → { canvas: { layout?: "wrap" | "column" } }
|
|
219
|
+
*/
|
|
220
|
+
type InferSubVariantsFromConfig<C extends ComponentConfig> = C extends {
|
|
221
|
+
sub: infer S extends Record<string, SubValue>;
|
|
222
|
+
} ? UnionToIntersection<{
|
|
223
|
+
[K in keyof S]: K extends string ? IsDirectSubConfig<S[K]> extends true ? S[K] extends {
|
|
224
|
+
variants?: infer V;
|
|
225
|
+
} ? {
|
|
226
|
+
[N in ExtractSubName<K>]: InferVariantPropsFromVariantsMap<V>;
|
|
227
|
+
} : Record<never, never> : Record<never, never> : Record<never, never>;
|
|
228
|
+
}[keyof S]> : Record<never, never>;
|
|
189
229
|
interface ContainerConfig {
|
|
190
230
|
base?: string;
|
|
191
231
|
queries?: Record<string, string>;
|
|
@@ -208,7 +248,7 @@ interface StyledComponentProps {
|
|
|
208
248
|
children?: React.ReactNode;
|
|
209
249
|
}
|
|
210
250
|
type SubComponentMap = Record<string, unknown>;
|
|
211
|
-
type TwSubComponentAccessor<Tag extends HtmlTagName = "span"> = React.FC<Omit<React.ComponentPropsWithoutRef<Tag>, "ref"> & {
|
|
251
|
+
type TwSubComponentAccessor<Tag extends HtmlTagName = "span", ExtraProps extends Record<string, unknown> = Record<never, never>> = React.FC<Omit<React.ComponentPropsWithoutRef<Tag>, "ref"> & ExtraProps & {
|
|
212
252
|
children?: React.ReactNode;
|
|
213
253
|
className?: string;
|
|
214
254
|
}>;
|
|
@@ -220,22 +260,22 @@ type TrimRight<S extends string> = S extends `${infer L} ` | `${infer L}
|
|
|
220
260
|
` ? TrimRight<L> : S;
|
|
221
261
|
type Trim<S extends string> = TrimLeft<TrimRight<S>>;
|
|
222
262
|
type ExtractSubNames<T extends string> = T extends `${string}[${infer Name}]${string}{${string}}${infer Rest}` ? Trim<Name> | ExtractSubNames<Rest> : T extends `${string}\n${infer Name}{${string}}${infer Rest}` ? (Trim<Name> extends "" ? never : Trim<Name>) | ExtractSubNames<Rest> : never;
|
|
223
|
-
type SubComponentKeys<S extends string, TagMap extends Record<string, string> = Record<string, never>> = {
|
|
224
|
-
[K in S]: TwSubComponentAccessor<K extends keyof TagMap ? (TagMap[K] extends HtmlTagName ? TagMap[K] : "span") : "span"
|
|
263
|
+
type SubComponentKeys<S extends string, TagMap extends Record<string, string> = Record<string, never>, SubVariantsMap extends Record<string, Record<string, unknown>> = Record<string, never>> = {
|
|
264
|
+
[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>>;
|
|
225
265
|
};
|
|
226
|
-
type TwStyledComponent<Config extends ComponentConfig = ComponentConfig, S extends string = string, TagMap extends Record<string, string> = Record<string, never>, Tag extends HtmlTagName = HtmlTagName
|
|
266
|
+
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>> = {
|
|
227
267
|
(props: React.ComponentPropsWithoutRef<Tag> & StyledComponentProps & InferVariantProps<Config> & InferSizeProps<Config> & InferStatesProps<Config>): React.ReactElement | null;
|
|
228
268
|
displayName?: string;
|
|
229
269
|
extend: {
|
|
230
|
-
(strings: TemplateStringsArray, ...exprs: unknown[]): TwStyledComponent<Config, S, TagMap, Tag>;
|
|
270
|
+
(strings: TemplateStringsArray, ...exprs: unknown[]): TwStyledComponent<Config, S, TagMap, Tag, SubVariantsMap>;
|
|
231
271
|
(config: {
|
|
232
272
|
classes?: string;
|
|
233
273
|
variants?: ComponentConfig["variants"];
|
|
234
274
|
defaultVariants?: ComponentConfig["defaultVariants"];
|
|
235
275
|
compoundVariants?: ComponentConfig["compoundVariants"];
|
|
236
|
-
}): TwStyledComponent<Config, S, TagMap, Tag>;
|
|
276
|
+
}): TwStyledComponent<Config, S, TagMap, Tag, SubVariantsMap>;
|
|
237
277
|
};
|
|
238
|
-
withVariants: (config: Partial<Config>) => TwStyledComponent<Config, S, TagMap, Tag>;
|
|
278
|
+
withVariants: (config: Partial<Config>) => TwStyledComponent<Config, S, TagMap, Tag, SubVariantsMap>;
|
|
239
279
|
/**
|
|
240
280
|
* Declare sub-component names secara eksplisit untuk autocomplete + type safety.
|
|
241
281
|
*
|
|
@@ -249,14 +289,14 @@ type TwStyledComponent<Config extends ComponentConfig = ComponentConfig, S exten
|
|
|
249
289
|
* Button.footer // ✅ autocomplete
|
|
250
290
|
* Button.xyz // ❌ TypeScript error
|
|
251
291
|
*/
|
|
252
|
-
withSub<NewS extends string>(): TwStyledComponent<Config, NewS, TagMap, Tag>;
|
|
253
|
-
} & SubComponentKeys<S, TagMap>;
|
|
292
|
+
withSub<NewS extends string>(): TwStyledComponent<Config, NewS, TagMap, Tag, SubVariantsMap>;
|
|
293
|
+
} & SubComponentKeys<S, TagMap, SubVariantsMap>;
|
|
254
294
|
interface TwSubComponent<P = unknown> {
|
|
255
295
|
(props: P): React.ReactElement | null;
|
|
256
296
|
displayName?: string;
|
|
257
297
|
}
|
|
258
298
|
interface TwTemplateFactory<Config extends ComponentConfig = ComponentConfig, Tag extends HtmlTagName = HtmlTagName> {
|
|
259
|
-
<C extends ComponentConfig>(config: C): TwStyledComponent<C, InferSubFromConfig<C>, InferSubTagsFromConfig<C> extends Record<string, string> ? InferSubTagsFromConfig<C> : Record<string, never>, Tag
|
|
299
|
+
<C extends ComponentConfig>(config: C): 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>>;
|
|
260
300
|
<const T extends string>(strings: readonly [T], ...exprs: []): TwStyledComponent<Config, ExtractSubNames<T>, Record<string, never>, Tag>;
|
|
261
301
|
(strings: TemplateStringsArray, ...exprs: unknown[]): TwStyledComponent<Config, string, Record<string, never>, Tag>;
|
|
262
302
|
}
|