tailwind-styled-v4 5.1.19 → 5.1.21

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 CHANGED
@@ -126,6 +126,42 @@ type InferSubFromConfig<C extends ComponentConfig> = C extends {
126
126
  } ? {
127
127
  [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;
128
128
  }[keyof S] : never;
129
+ /**
130
+ * HTML tags yang otomatis dikenali sebagai tag dari bare sub-key (tanpa "tag:name" syntax).
131
+ * HARUS identik dengan SEMANTIC_HTML_TAGS di createComponent.ts (parseSubKey) — kalau
132
+ * drift, sub-component bisa di-tipe-kan dengan native attributes yang salah (tag yang
133
+ * benar2 di-render di runtime beda dari yang dipakai untuk inference type-nya).
134
+ */
135
+ type SemanticSubTag = "article" | "aside" | "details" | "figcaption" | "figure" | "footer" | "header" | "main" | "mark" | "nav" | "section" | "summary" | "time" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "p" | "ul" | "ol" | "li" | "dl" | "dt" | "dd" | "table" | "thead" | "tbody" | "tfoot" | "tr" | "th" | "td" | "form" | "fieldset" | "legend" | "label" | "a" | "button" | "img" | "span" | "div" | "blockquote" | "pre" | "code" | "em" | "strong" | "small";
136
+ /**
137
+ * Resolve tag HTML dari satu sub-key string — mirror logic `parseSubKey()` runtime
138
+ * di createComponent.ts:
139
+ * - "a:link" → tag eksplisit sebelum colon ("a")
140
+ * - "header" → bare key, fallback ke key itu sendiri kalau termasuk SemanticSubTag
141
+ * - "icon" → bare key, bukan semantic tag → fallback "span" (default runtime)
142
+ */
143
+ type ResolveSubTag<K extends string> = K extends `${infer Tag}:${string}` ? Tag extends HtmlTagName ? Tag : "span" : K extends SemanticSubTag ? K : "span";
144
+ /** Gabungkan union of object types jadi satu intersection — dipakai untuk merge per-key tag map. */
145
+ type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
146
+ /**
147
+ * Infer mapping { subComponentName: htmlTag } dari config.sub — dipakai supaya setiap
148
+ * sub-component (Card.icon, Breadcrumb.link, dst) punya native HTML attributes yang
149
+ * SESUAI tag yang benar2 di-render (href untuk <a>, src untuk <img>, dst), bukan cuma
150
+ * `{ children?, className? }` generik.
151
+ *
152
+ * @example
153
+ * sub: { "a:link": "...", "span:sep": "..." } → { link: "a"; sep: "span" }
154
+ * sub: { header: { topBar: "..." } } → { topBar: "header" }
155
+ */
156
+ type InferSubTagsFromConfig<C extends ComponentConfig> = C extends {
157
+ sub: infer S extends Record<string, SubValue>;
158
+ } ? UnionToIntersection<{
159
+ [K in keyof S]: K extends string ? S[K] extends string ? {
160
+ [N in ExtractSubName<K>]: ResolveSubTag<K>;
161
+ } : S[K] extends Record<string, string> ? {
162
+ [N in keyof S[K]]: K extends HtmlTagName ? K : "span";
163
+ } : never : never;
164
+ }[keyof S]> : Record<string, never>;
129
165
  interface ContainerConfig {
130
166
  base?: string;
131
167
  queries?: Record<string, string>;
@@ -146,10 +182,9 @@ interface StyledComponentProps {
146
182
  className?: string;
147
183
  as?: HtmlTagName;
148
184
  children?: React.ReactNode;
149
- [key: string]: unknown;
150
185
  }
151
186
  type SubComponentMap = Record<string, unknown>;
152
- type TwSubComponentAccessor = React.FC<{
187
+ type TwSubComponentAccessor<Tag extends HtmlTagName = "span"> = React.FC<Omit<React.ComponentPropsWithoutRef<Tag>, "ref"> & {
153
188
  children?: React.ReactNode;
154
189
  className?: string;
155
190
  }>;
@@ -161,24 +196,22 @@ type TrimRight<S extends string> = S extends `${infer L} ` | `${infer L}
161
196
  ` ? TrimRight<L> : S;
162
197
  type Trim<S extends string> = TrimLeft<TrimRight<S>>;
163
198
  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;
164
- type SubComponentKeys<S extends string> = string extends S ? {
165
- [key: string]: TwSubComponentAccessor;
166
- } : {
167
- [K in S]: TwSubComponentAccessor;
199
+ type SubComponentKeys<S extends string, TagMap extends Record<string, string> = Record<string, never>> = {
200
+ [K in S]: TwSubComponentAccessor<K extends keyof TagMap ? (TagMap[K] extends HtmlTagName ? TagMap[K] : "span") : "span">;
168
201
  };
169
- type TwStyledComponent<Config extends ComponentConfig = ComponentConfig, S extends string = string> = {
170
- (props: StyledComponentProps & InferVariantProps<Config> & InferSizeProps<Config> & InferStatesProps<Config>): React.ReactElement | null;
202
+ type TwStyledComponent<Config extends ComponentConfig = ComponentConfig, S extends string = string, TagMap extends Record<string, string> = Record<string, never>, Tag extends HtmlTagName = HtmlTagName> = {
203
+ (props: React.ComponentPropsWithoutRef<Tag> & StyledComponentProps & InferVariantProps<Config> & InferSizeProps<Config> & InferStatesProps<Config>): React.ReactElement | null;
171
204
  displayName?: string;
172
205
  extend: {
173
- (strings: TemplateStringsArray, ...exprs: unknown[]): TwStyledComponent<Config, S>;
206
+ (strings: TemplateStringsArray, ...exprs: unknown[]): TwStyledComponent<Config, S, TagMap, Tag>;
174
207
  (config: {
175
208
  classes?: string;
176
209
  variants?: ComponentConfig["variants"];
177
210
  defaultVariants?: ComponentConfig["defaultVariants"];
178
211
  compoundVariants?: ComponentConfig["compoundVariants"];
179
- }): TwStyledComponent<Config, S>;
212
+ }): TwStyledComponent<Config, S, TagMap, Tag>;
180
213
  };
181
- withVariants: (config: Partial<Config>) => TwStyledComponent<Config, S>;
214
+ withVariants: (config: Partial<Config>) => TwStyledComponent<Config, S, TagMap, Tag>;
182
215
  /**
183
216
  * Declare sub-component names secara eksplisit untuk autocomplete + type safety.
184
217
  *
@@ -192,27 +225,27 @@ type TwStyledComponent<Config extends ComponentConfig = ComponentConfig, S exten
192
225
  * Button.footer // ✅ autocomplete
193
226
  * Button.xyz // ❌ TypeScript error
194
227
  */
195
- withSub<NewS extends string>(): TwStyledComponent<Config, NewS>;
196
- animate: (opts: AnimateOptions) => Promise<TwStyledComponent<Config, S>>;
197
- } & SubComponentKeys<S>;
228
+ withSub<NewS extends string>(): TwStyledComponent<Config, NewS, TagMap, Tag>;
229
+ animate: (opts: AnimateOptions) => Promise<TwStyledComponent<Config, S, TagMap, Tag>>;
230
+ } & SubComponentKeys<S, TagMap>;
198
231
  interface TwSubComponent<P = unknown> {
199
232
  (props: P): React.ReactElement | null;
200
233
  displayName?: string;
201
234
  }
202
- interface TwTemplateFactory<Config extends ComponentConfig = ComponentConfig> {
203
- <const T extends string>(strings: readonly [T], ...exprs: []): TwStyledComponent<Config, ExtractSubNames<T>>;
204
- (strings: TemplateStringsArray, ...exprs: unknown[]): TwStyledComponent<Config, string>;
205
- <C extends ComponentConfig>(config: C): TwStyledComponent<C, InferSubFromConfig<C>>;
235
+ interface TwTemplateFactory<Config extends ComponentConfig = ComponentConfig, Tag extends HtmlTagName = HtmlTagName> {
236
+ <const T extends string>(strings: readonly [T], ...exprs: []): TwStyledComponent<Config, ExtractSubNames<T>, Record<string, never>, Tag>;
237
+ (strings: TemplateStringsArray, ...exprs: unknown[]): TwStyledComponent<Config, string, Record<string, never>, Tag>;
238
+ <C extends ComponentConfig>(config: C): TwStyledComponent<C, InferSubFromConfig<C>, InferSubTagsFromConfig<C> extends Record<string, string> ? InferSubTagsFromConfig<C> : Record<string, never>, Tag>;
206
239
  }
207
240
  type TwTagFactory = {
208
- [K in HtmlTagName]: TwTemplateFactory;
241
+ [K in HtmlTagName]: TwTemplateFactory<ComponentConfig, K>;
209
242
  };
210
243
  type TwTagFactoryAny = {
211
244
  [key: string]: TwTemplateFactory;
212
245
  };
213
246
  type TwComponentFactory<T extends React.ElementType = React.ElementType> = (tag: T) => TwTemplateFactory;
214
247
  type TwServerObject = TwTagFactory & {
215
- [K in HtmlTagName as `${K}`]: TwTemplateFactory;
248
+ [K in HtmlTagName as `${K}`]: TwTemplateFactory<ComponentConfig, K>;
216
249
  };
217
250
  type TwObject = TwComponentFactory & TwTagFactory & {
218
251
  server: TwServerObject;
package/dist/index.d.ts CHANGED
@@ -126,6 +126,42 @@ type InferSubFromConfig<C extends ComponentConfig> = C extends {
126
126
  } ? {
127
127
  [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;
128
128
  }[keyof S] : never;
129
+ /**
130
+ * HTML tags yang otomatis dikenali sebagai tag dari bare sub-key (tanpa "tag:name" syntax).
131
+ * HARUS identik dengan SEMANTIC_HTML_TAGS di createComponent.ts (parseSubKey) — kalau
132
+ * drift, sub-component bisa di-tipe-kan dengan native attributes yang salah (tag yang
133
+ * benar2 di-render di runtime beda dari yang dipakai untuk inference type-nya).
134
+ */
135
+ type SemanticSubTag = "article" | "aside" | "details" | "figcaption" | "figure" | "footer" | "header" | "main" | "mark" | "nav" | "section" | "summary" | "time" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "p" | "ul" | "ol" | "li" | "dl" | "dt" | "dd" | "table" | "thead" | "tbody" | "tfoot" | "tr" | "th" | "td" | "form" | "fieldset" | "legend" | "label" | "a" | "button" | "img" | "span" | "div" | "blockquote" | "pre" | "code" | "em" | "strong" | "small";
136
+ /**
137
+ * Resolve tag HTML dari satu sub-key string — mirror logic `parseSubKey()` runtime
138
+ * di createComponent.ts:
139
+ * - "a:link" → tag eksplisit sebelum colon ("a")
140
+ * - "header" → bare key, fallback ke key itu sendiri kalau termasuk SemanticSubTag
141
+ * - "icon" → bare key, bukan semantic tag → fallback "span" (default runtime)
142
+ */
143
+ type ResolveSubTag<K extends string> = K extends `${infer Tag}:${string}` ? Tag extends HtmlTagName ? Tag : "span" : K extends SemanticSubTag ? K : "span";
144
+ /** Gabungkan union of object types jadi satu intersection — dipakai untuk merge per-key tag map. */
145
+ type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
146
+ /**
147
+ * Infer mapping { subComponentName: htmlTag } dari config.sub — dipakai supaya setiap
148
+ * sub-component (Card.icon, Breadcrumb.link, dst) punya native HTML attributes yang
149
+ * SESUAI tag yang benar2 di-render (href untuk <a>, src untuk <img>, dst), bukan cuma
150
+ * `{ children?, className? }` generik.
151
+ *
152
+ * @example
153
+ * sub: { "a:link": "...", "span:sep": "..." } → { link: "a"; sep: "span" }
154
+ * sub: { header: { topBar: "..." } } → { topBar: "header" }
155
+ */
156
+ type InferSubTagsFromConfig<C extends ComponentConfig> = C extends {
157
+ sub: infer S extends Record<string, SubValue>;
158
+ } ? UnionToIntersection<{
159
+ [K in keyof S]: K extends string ? S[K] extends string ? {
160
+ [N in ExtractSubName<K>]: ResolveSubTag<K>;
161
+ } : S[K] extends Record<string, string> ? {
162
+ [N in keyof S[K]]: K extends HtmlTagName ? K : "span";
163
+ } : never : never;
164
+ }[keyof S]> : Record<string, never>;
129
165
  interface ContainerConfig {
130
166
  base?: string;
131
167
  queries?: Record<string, string>;
@@ -146,10 +182,9 @@ interface StyledComponentProps {
146
182
  className?: string;
147
183
  as?: HtmlTagName;
148
184
  children?: React.ReactNode;
149
- [key: string]: unknown;
150
185
  }
151
186
  type SubComponentMap = Record<string, unknown>;
152
- type TwSubComponentAccessor = React.FC<{
187
+ type TwSubComponentAccessor<Tag extends HtmlTagName = "span"> = React.FC<Omit<React.ComponentPropsWithoutRef<Tag>, "ref"> & {
153
188
  children?: React.ReactNode;
154
189
  className?: string;
155
190
  }>;
@@ -161,24 +196,22 @@ type TrimRight<S extends string> = S extends `${infer L} ` | `${infer L}
161
196
  ` ? TrimRight<L> : S;
162
197
  type Trim<S extends string> = TrimLeft<TrimRight<S>>;
163
198
  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;
164
- type SubComponentKeys<S extends string> = string extends S ? {
165
- [key: string]: TwSubComponentAccessor;
166
- } : {
167
- [K in S]: TwSubComponentAccessor;
199
+ type SubComponentKeys<S extends string, TagMap extends Record<string, string> = Record<string, never>> = {
200
+ [K in S]: TwSubComponentAccessor<K extends keyof TagMap ? (TagMap[K] extends HtmlTagName ? TagMap[K] : "span") : "span">;
168
201
  };
169
- type TwStyledComponent<Config extends ComponentConfig = ComponentConfig, S extends string = string> = {
170
- (props: StyledComponentProps & InferVariantProps<Config> & InferSizeProps<Config> & InferStatesProps<Config>): React.ReactElement | null;
202
+ type TwStyledComponent<Config extends ComponentConfig = ComponentConfig, S extends string = string, TagMap extends Record<string, string> = Record<string, never>, Tag extends HtmlTagName = HtmlTagName> = {
203
+ (props: React.ComponentPropsWithoutRef<Tag> & StyledComponentProps & InferVariantProps<Config> & InferSizeProps<Config> & InferStatesProps<Config>): React.ReactElement | null;
171
204
  displayName?: string;
172
205
  extend: {
173
- (strings: TemplateStringsArray, ...exprs: unknown[]): TwStyledComponent<Config, S>;
206
+ (strings: TemplateStringsArray, ...exprs: unknown[]): TwStyledComponent<Config, S, TagMap, Tag>;
174
207
  (config: {
175
208
  classes?: string;
176
209
  variants?: ComponentConfig["variants"];
177
210
  defaultVariants?: ComponentConfig["defaultVariants"];
178
211
  compoundVariants?: ComponentConfig["compoundVariants"];
179
- }): TwStyledComponent<Config, S>;
212
+ }): TwStyledComponent<Config, S, TagMap, Tag>;
180
213
  };
181
- withVariants: (config: Partial<Config>) => TwStyledComponent<Config, S>;
214
+ withVariants: (config: Partial<Config>) => TwStyledComponent<Config, S, TagMap, Tag>;
182
215
  /**
183
216
  * Declare sub-component names secara eksplisit untuk autocomplete + type safety.
184
217
  *
@@ -192,27 +225,27 @@ type TwStyledComponent<Config extends ComponentConfig = ComponentConfig, S exten
192
225
  * Button.footer // ✅ autocomplete
193
226
  * Button.xyz // ❌ TypeScript error
194
227
  */
195
- withSub<NewS extends string>(): TwStyledComponent<Config, NewS>;
196
- animate: (opts: AnimateOptions) => Promise<TwStyledComponent<Config, S>>;
197
- } & SubComponentKeys<S>;
228
+ withSub<NewS extends string>(): TwStyledComponent<Config, NewS, TagMap, Tag>;
229
+ animate: (opts: AnimateOptions) => Promise<TwStyledComponent<Config, S, TagMap, Tag>>;
230
+ } & SubComponentKeys<S, TagMap>;
198
231
  interface TwSubComponent<P = unknown> {
199
232
  (props: P): React.ReactElement | null;
200
233
  displayName?: string;
201
234
  }
202
- interface TwTemplateFactory<Config extends ComponentConfig = ComponentConfig> {
203
- <const T extends string>(strings: readonly [T], ...exprs: []): TwStyledComponent<Config, ExtractSubNames<T>>;
204
- (strings: TemplateStringsArray, ...exprs: unknown[]): TwStyledComponent<Config, string>;
205
- <C extends ComponentConfig>(config: C): TwStyledComponent<C, InferSubFromConfig<C>>;
235
+ interface TwTemplateFactory<Config extends ComponentConfig = ComponentConfig, Tag extends HtmlTagName = HtmlTagName> {
236
+ <const T extends string>(strings: readonly [T], ...exprs: []): TwStyledComponent<Config, ExtractSubNames<T>, Record<string, never>, Tag>;
237
+ (strings: TemplateStringsArray, ...exprs: unknown[]): TwStyledComponent<Config, string, Record<string, never>, Tag>;
238
+ <C extends ComponentConfig>(config: C): TwStyledComponent<C, InferSubFromConfig<C>, InferSubTagsFromConfig<C> extends Record<string, string> ? InferSubTagsFromConfig<C> : Record<string, never>, Tag>;
206
239
  }
207
240
  type TwTagFactory = {
208
- [K in HtmlTagName]: TwTemplateFactory;
241
+ [K in HtmlTagName]: TwTemplateFactory<ComponentConfig, K>;
209
242
  };
210
243
  type TwTagFactoryAny = {
211
244
  [key: string]: TwTemplateFactory;
212
245
  };
213
246
  type TwComponentFactory<T extends React.ElementType = React.ElementType> = (tag: T) => TwTemplateFactory;
214
247
  type TwServerObject = TwTagFactory & {
215
- [K in HtmlTagName as `${K}`]: TwTemplateFactory;
248
+ [K in HtmlTagName as `${K}`]: TwTemplateFactory<ComponentConfig, K>;
216
249
  };
217
250
  type TwObject = TwComponentFactory & TwTagFactory & {
218
251
  server: TwServerObject;
package/dist/index.js CHANGED
@@ -741,16 +741,19 @@ function parseSubKey(key) {
741
741
  function createSubComponentAccessor(parentDisplayName, name, classes, tag = "span", asChild = false) {
742
742
  const SubComponent = ({
743
743
  children,
744
- className
744
+ className,
745
+ ...rest
746
+ // tangkap semua native HTML props (href, onClick, src, alt, dll)
745
747
  }) => {
746
748
  const mergedClass = className ? `${classes} ${className}` : classes;
747
749
  if (asChild && import_react.default.isValidElement(children)) {
748
750
  const child = import_react.default.Children.only(children);
749
751
  return import_react.default.cloneElement(child, {
752
+ ...rest,
750
753
  className: child.props.className ? `${mergedClass} ${child.props.className}` : mergedClass
751
754
  });
752
755
  }
753
- return import_react.default.createElement(tag, { className: mergedClass }, children);
756
+ return import_react.default.createElement(tag, { ...rest, className: mergedClass }, children);
754
757
  };
755
758
  SubComponent.displayName = `${parentDisplayName}[${name}]`;
756
759
  return SubComponent;
@@ -1026,8 +1029,9 @@ function wrapWithSubProxy(component, tagLabel) {
1026
1029
  if (SKIP_PROXY_KEYS.has(prop)) return value;
1027
1030
  const Fallback = ({
1028
1031
  children,
1029
- className
1030
- }) => import_react.default.createElement("span", { className }, children);
1032
+ className,
1033
+ ...rest
1034
+ }) => import_react.default.createElement("span", { ...rest, className }, children);
1031
1035
  Fallback.displayName = `tw.${tagLabel}.${prop}(fallback)`;
1032
1036
  return Fallback;
1033
1037
  }