tailwind-variants 0.1.5 → 0.1.7
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 +6 -1
- package/dist/index.d.ts +67 -35
- package/dist/transformer.d.ts +1 -1
- package/dist/utils.d.ts +9 -0
- package/package.json +3 -3
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<
|
|
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
|
@@ -44,8 +44,6 @@ export declare const cn: <T extends CnOptions>(...classes: T) => (config?: TWMCo
|
|
|
44
44
|
// compare if the value is true or array of values
|
|
45
45
|
export type isTrueOrArray<T> = T extends true | unknown[] ? true : false;
|
|
46
46
|
|
|
47
|
-
export type isStringArray<T> = T extends Array<string> ? true : false;
|
|
48
|
-
|
|
49
47
|
export type WithInitialScreen<T extends Array<string>> = ["initial", ...T];
|
|
50
48
|
|
|
51
49
|
/**
|
|
@@ -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
|
-
|
|
|
97
|
-
| StringToBoolean<keyof
|
|
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<
|
|
118
|
-
|
|
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
|
-
> =
|
|
134
|
+
> = C["responsiveVariants"] extends string[]
|
|
126
135
|
? {
|
|
127
136
|
[Screen in WithInitialScreen<C["responsiveVariants"]>[number]]?: StringToBoolean<keyof V[K]>;
|
|
128
137
|
}
|
|
@@ -132,68 +141,90 @@ 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
|
-
?
|
|
155
|
-
|
|
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<
|
|
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,
|
|
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
|
|
190
|
-
CV extends TVCompoundVariants<V,
|
|
191
|
-
DV extends TVDefaultVariants<V, EV,
|
|
192
|
-
C extends TVConfig<V, EV
|
|
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
|
-
|
|
196
|
-
|
|
216
|
+
// @ts-expect-error
|
|
217
|
+
E extends TVReturnType = TVReturnType<
|
|
218
|
+
V,
|
|
219
|
+
S,
|
|
220
|
+
B,
|
|
221
|
+
C,
|
|
222
|
+
// @ts-expect-error
|
|
223
|
+
EV extends undefined ? {} : EV,
|
|
224
|
+
// @ts-expect-error
|
|
225
|
+
ES extends undefined ? {} : ES
|
|
226
|
+
>,
|
|
227
|
+
EV extends TVVariants<ES, B, E["variants"], ES> = E["variants"],
|
|
197
228
|
ES extends TVSlots = E["slots"] extends TVSlots ? E["slots"] : undefined,
|
|
198
229
|
>(
|
|
199
230
|
options: {
|
|
@@ -236,7 +267,7 @@ export type TV = {
|
|
|
236
267
|
* @see https://www.tailwind-variants.org/docs/api-reference#config-optional
|
|
237
268
|
*/
|
|
238
269
|
config?: C,
|
|
239
|
-
): TVReturnType<V,
|
|
270
|
+
): TVReturnType<V, S, B, C, EV, ES>;
|
|
240
271
|
};
|
|
241
272
|
|
|
242
273
|
// main function
|
|
@@ -244,7 +275,8 @@ export declare const tv: TV;
|
|
|
244
275
|
|
|
245
276
|
export declare const defaultConfig: TVConfig;
|
|
246
277
|
|
|
247
|
-
export type VariantProps<
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
278
|
+
export type VariantProps<T> = T extends {variants: infer V}
|
|
279
|
+
? V extends TVVariantsDefault<any, undefined>
|
|
280
|
+
? {[K in TVVariantKeys<V, any>[number]]?: keyof V[K]}
|
|
281
|
+
: never
|
|
282
|
+
: never;
|
package/dist/transformer.d.ts
CHANGED
|
@@ -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
|
|
7
|
+
<C extends Config>(tvConfig: C): C;
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
export declare const withTV: WithTV;
|
package/dist/utils.d.ts
ADDED
|
@@ -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.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "🦄 Tailwindcss first-class variant API",
|
|
5
5
|
"author": "Junior Garcia <jrgarciadev@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"test": "jest --verbose"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"tailwind-merge": "^1.
|
|
38
|
+
"tailwind-merge": "^1.13.2"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@commitlint/cli": "^17.2.0",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"ts-node": "^10.9.1",
|
|
68
68
|
"tslib": "^2.4.1",
|
|
69
69
|
"tsup": "6.6.3",
|
|
70
|
-
"typescript": "
|
|
70
|
+
"typescript": "5.1.3",
|
|
71
71
|
"webpack": "^5.53.0"
|
|
72
72
|
},
|
|
73
73
|
"peerDependencies": {
|