tailwind-variants 0.1.4 → 0.1.6

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/config.d.ts CHANGED
@@ -17,7 +17,12 @@ export type TWMConfig = {
17
17
  twMergeConfig?: TwMergeConfig;
18
18
  };
19
19
 
20
- export type TVConfig<V extends TVVariants<S>, EV extends TVVariants> = {
20
+ export type TVConfig<
21
+ // @ts-expect-error
22
+ V extends TVVariants | undefined = undefined,
23
+ // @ts-expect-error
24
+ EV extends TVVariants | undefined = undefined,
25
+ > = {
21
26
  /**
22
27
  * Whether to enable responsive variant transform.
23
28
  * Which variants or screens(breakpoints) for responsive variant transform.
package/dist/index.d.ts CHANGED
@@ -42,9 +42,7 @@ export declare const cnBase: <T extends CnOptions>(...classes: T) => CnReturn;
42
42
  export declare const cn: <T extends CnOptions>(...classes: T) => (config?: TWMConfig) => CnReturn;
43
43
 
44
44
  // compare if the value is true or array of values
45
- export type isTrueOrArray<T> = T extends true | (infer U)[] ? true : false;
46
-
47
- export type isStringArray<T> = T extends Array<string> ? true : false;
45
+ export type isTrueOrArray<T> = T extends true | unknown[] ? true : false;
48
46
 
49
47
  export type WithInitialScreen<T extends Array<string>> = ["initial", ...T];
50
48
 
@@ -69,9 +67,10 @@ type TVVariantsDefault<S extends TVSlots, B extends ClassValue> = {
69
67
  };
70
68
 
71
69
  export type TVVariants<
72
- S extends TVSlots,
73
- B extends ClassValue,
74
- EV extends TVVariants = undefined,
70
+ S extends TVSlots | undefined,
71
+ B extends ClassValue | undefined = undefined,
72
+ EV extends TVVariants<ES> | undefined = undefined,
73
+ ES extends TVSlots | undefined = undefined,
75
74
  > = EV extends undefined
76
75
  ? TVVariantsDefault<S, B>
77
76
  :
@@ -87,14 +86,16 @@ export type TVVariants<
87
86
 
88
87
  export type TVCompoundVariants<
89
88
  V extends TVVariants<S>,
90
- EV extends TVVariants,
91
89
  S extends TVSlots,
92
90
  B extends ClassValue,
91
+ EV extends TVVariants<ES>,
92
+ ES extends TVSlots,
93
93
  > = Array<
94
94
  {
95
95
  [K in keyof V | keyof EV]?:
96
- | StringToBoolean<keyof V[K] | keyof EV[K]>
97
- | StringToBoolean<keyof V[K]>[];
96
+ | (K extends keyof V ? StringToBoolean<keyof V[K]> : never)
97
+ | (K extends keyof EV ? StringToBoolean<keyof EV[K]> : never)
98
+ | (K extends keyof V ? StringToBoolean<keyof V[K]>[] : never);
98
99
  } & ClassProp<SlotsClassValue<S, B> | ClassValue>
99
100
  >;
100
101
 
@@ -114,15 +115,23 @@ export type TVCompoundSlots<
114
115
  } & ClassProp
115
116
  >;
116
117
 
117
- export type TVDefaultVariants<V extends TVVariants<S>, EV extends TVVariants, S extends TVSlots> = {
118
- [K in keyof V | keyof EV]?: StringToBoolean<keyof V[K] | keyof EV[K]>;
118
+ export type TVDefaultVariants<
119
+ V extends TVVariants<S>,
120
+ S extends TVSlots,
121
+ EV extends TVVariants<ES>,
122
+ ES extends TVSlots,
123
+ > = {
124
+ [K in keyof V | keyof EV]?:
125
+ | (K extends keyof V ? StringToBoolean<keyof V[K]> : never)
126
+ | (K extends keyof EV ? StringToBoolean<keyof EV[K]> : never);
119
127
  };
120
128
 
121
129
  export type TVScreenPropsValue<
122
- V extends TVVariants,
130
+ V extends TVVariants<S>,
131
+ S extends TVSlots,
123
132
  K extends keyof V,
124
133
  C extends TVConfig,
125
- > = isStringArray<C["responsiveVariants"]> extends true
134
+ > = C["responsiveVariants"] extends string[]
126
135
  ? {
127
136
  [Screen in WithInitialScreen<C["responsiveVariants"]>[number]]?: StringToBoolean<keyof V[K]>;
128
137
  }
@@ -132,67 +141,81 @@ export type TVScreenPropsValue<
132
141
 
133
142
  export type TVProps<
134
143
  V extends TVVariants<S>,
135
- EV extends TVVariants,
136
144
  S extends TVSlots,
137
145
  C extends TVConfig<V, EV>,
146
+ EV extends TVVariants<ES>,
147
+ ES extends TVSlots,
138
148
  > = EV extends undefined
139
149
  ? V extends undefined
140
150
  ? ClassProp<ClassValue>
141
151
  : {
142
152
  [K in keyof V]?: isTrueOrArray<C["responsiveVariants"]> extends true
143
- ? StringToBoolean<keyof V[K]> | TVScreenPropsValue<V, K, C>
153
+ ? StringToBoolean<keyof V[K]> | TVScreenPropsValue<V, S, K, C>
144
154
  : StringToBoolean<keyof V[K]>;
145
155
  } & ClassProp<ClassValue>
146
156
  : V extends undefined
147
157
  ? {
148
158
  [K in keyof EV]?: isTrueOrArray<C["responsiveVariants"]> extends true
149
- ? StringToBoolean<keyof EV[K]> | TVScreenPropsValue<EV, K, C>
159
+ ? StringToBoolean<keyof EV[K]> | TVScreenPropsValue<EV, ES, K, C>
150
160
  : StringToBoolean<keyof EV[K]>;
151
161
  } & ClassProp<ClassValue>
152
162
  : {
153
163
  [K in keyof V | keyof EV]?: isTrueOrArray<C["responsiveVariants"]> extends true
154
- ? StringToBoolean<keyof V[K] | keyof EV[K]> | TVScreenPropsValue<EV & V, K, C>
155
- : StringToBoolean<keyof V[K] | keyof EV[K]>;
164
+ ?
165
+ | (K extends keyof V ? StringToBoolean<keyof V[K]> : never)
166
+ | (K extends keyof EV ? StringToBoolean<keyof EV[K]> : never)
167
+ | TVScreenPropsValue<EV & V, S, K, C>
168
+ :
169
+ | (K extends keyof V ? StringToBoolean<keyof V[K]> : never)
170
+ | (K extends keyof EV ? StringToBoolean<keyof EV[K]> : never);
156
171
  } & ClassProp<ClassValue>;
157
172
 
158
173
  export type TVVariantKeys<V extends TVVariants<S>, S extends TVSlots> = V extends Object
159
174
  ? Array<keyof V>
160
175
  : undefined;
161
176
 
162
- export type TVReturnProps<V extends TVVariants<S>, S extends TVSlots, B extends ClassValue> = {
177
+ export type TVReturnProps<
178
+ V extends TVVariants<S>,
179
+ S extends TVSlots,
180
+ B extends ClassValue,
181
+ EV extends TVVariants<ES>,
182
+ ES extends TVSlots,
183
+ > = {
163
184
  base: B;
164
185
  slots: S;
165
186
  variants: V;
166
- defaultVariants: TVDefaultVariants<V, S>;
167
- compoundVariants: TVCompoundVariants<V, S, B>;
187
+ defaultVariants: TVDefaultVariants<V, S, EV, ES>;
188
+ compoundVariants: TVCompoundVariants<V, S, B, EV, ES>;
168
189
  compoundSlots: TVCompoundSlots<V, S, B>;
169
190
  variantKeys: TVVariantKeys<V, S>;
170
191
  };
171
192
 
172
193
  export type TVReturnType<
173
194
  V extends TVVariants<S>,
174
- EV extends TVVariants,
175
195
  S extends TVSlots,
176
- ES extends TVSlots,
177
196
  B extends ClassValue,
178
197
  C extends TVConfig<V, EV>,
198
+ EV extends TVVariants<ES>,
199
+ ES extends TVSlots,
179
200
  > = {
180
- (props?: TVProps<V, EV, S, C>): ES extends undefined
201
+ (props?: TVProps<V, S, C, EV, ES>): ES extends undefined
181
202
  ? S extends undefined
182
203
  ? string
183
204
  : {[K in TVSlotsWithBase<S, B>]: (slotProps?: ClassProp) => string}
184
205
  : {[K in TVSlotsWithBase<ES & S, B>]: (slotProps?: ClassProp) => string};
185
- } & TVReturnProps<V, S, B>;
206
+ } & TVReturnProps<V, S, B, EV, ES>;
186
207
 
187
208
  export type TV = {
188
209
  <
189
- V extends TVVariants<S, B, EV> = undefined,
190
- CV extends TVCompoundVariants<V, EV, S, B> = undefined,
191
- DV extends TVDefaultVariants<V, EV, S> = undefined,
192
- C extends TVConfig<V, EV> = undefined,
210
+ V extends TVVariants<S, B, EV>,
211
+ CV extends TVCompoundVariants<V, S, B, EV, ES>,
212
+ DV extends TVDefaultVariants<V, S, EV, ES>,
213
+ C extends TVConfig<V, EV>,
193
214
  B extends ClassValue = undefined,
194
215
  S extends TVSlots = undefined,
195
- E extends ReturnType<TV> = undefined,
216
+ // @ts-expect-error
217
+ E extends TVReturnType = undefined,
218
+ // @ts-expect-error
196
219
  EV extends TVVariants = E["variants"] extends TVVariants ? E["variants"] : undefined,
197
220
  ES extends TVSlots = E["slots"] extends TVSlots ? E["slots"] : undefined,
198
221
  >(
@@ -236,7 +259,7 @@ export type TV = {
236
259
  * @see https://www.tailwind-variants.org/docs/api-reference#config-optional
237
260
  */
238
261
  config?: C,
239
- ): TVReturnType<V, EV, S, ES, B, C>;
262
+ ): TVReturnType<V, S, B, C, EV, ES>;
240
263
  };
241
264
 
242
265
  // main function
@@ -4,7 +4,7 @@ import type {DefaultTheme} from "tailwindcss/types/generated/default-theme";
4
4
  export type DefaultScreens = keyof DefaultTheme["screens"];
5
5
 
6
6
  export type WithTV = {
7
- <C extends Config = {}>(tvConfig: Config): C;
7
+ <C extends Config>(tvConfig: C): C;
8
8
  };
9
9
 
10
10
  export declare const withTV: WithTV;
@@ -0,0 +1,9 @@
1
+ export declare const falsyToString: <T>(value: T) => T | string;
2
+
3
+ export declare const isEmptyObject: (obj: unknown) => boolean;
4
+
5
+ export declare const flatMergeArrays: <T extends unknown[]>(...arrays: T[]) => T;
6
+
7
+ export declare const mergeObjects: (obj1: unknown, obj2: unknown) => unknown;
8
+
9
+ export declare const removeExtraSpaces: (str: string) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tailwind-variants",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "🦄 Tailwindcss first-class variant API",
5
5
  "author": "Junior Garcia <jrgarciadev@gmail.com>",
6
6
  "license": "MIT",