tailwind-variants 0.0.8 → 0.0.10
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.cjs +2 -2
- package/dist/index.d.ts +32 -24
- package/dist/index.js +2 -2
- package/dist/utils.d.ts +2 -2
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
var classVarianceAuthority = require('class-variance-authority');
|
|
4
4
|
var tailwindMerge = require('tailwind-merge');
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var i=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,g=e=>e&&Object.keys(e).length>0,m=(...e)=>(f={})=>f.twMerge?(g(f.twMergeConfig)?tailwindMerge.extendTailwindMerge(f.twMergeConfig):tailwindMerge.twMerge)(classVarianceAuthority.cx(e)):classVarianceAuthority.cx(e);var F=(e,f={twMerge:!0,twMergeConfig:{}})=>n=>{var C,O;let{slots:l={},variants:b,defaultVariants:y}=e;if(b==null&&!g(l))return m(e==null?void 0:e.base,n==null?void 0:n.class,n==null?void 0:n.className)(f);let d={base:e==null?void 0:e.base,...l},w=t=>{let a=n==null?void 0:n[t],r=y==null?void 0:y[t];if(a===null)return null;let u=i(a)||i(r);return b[t][u]},s=b?Object.keys(b).map(w):null,N=t=>!b||typeof b!="object"?null:Object.keys(b).map(a=>{let r=w(a);return t==="base"&&typeof r=="string"?r:!r||typeof r!="object"?null:r[t]}),M=n&&Object.entries(n).reduce((t,[a,r])=>(r===void 0||(t[a]=r),t),{}),x=(C=e==null?void 0:e.compoundVariants)==null?void 0:C.reduce((t,{class:a,className:r,...u})=>Object.entries(u).every(([c,j])=>Array.isArray(j)?j.includes({...y,...M}[c]):{...y,...M}[c]===j)?[...t,a,r]:t,[]),A=()=>{let t=x;return Array.isArray(t)?t.reduce((a,r)=>(typeof r=="string"&&(a.base=m(a.base,r)(f)),typeof r=="object"&&Object.entries(r).forEach(([u,c])=>{a[u]=m(a[u],c)(f);}),a),{}):t};if(g(l)){let t=(O=A())!=null?O:[];return {...typeof d=="object"&&g(d)?Object.keys(d).reduce((r,u)=>(r[u]=c=>m(u==="base"?e==null?void 0:e.base:[],d[u],N(u),t==null?void 0:t[u],c==null?void 0:c.class,c==null?void 0:c.className)(f),r),{}):{}}}return m(e==null?void 0:e.base,s,x,n==null?void 0:n.class,n==null?void 0:n.className)(f)};
|
|
7
7
|
|
|
8
|
-
exports.tv =
|
|
8
|
+
exports.tv = F;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,59 +1,67 @@
|
|
|
1
1
|
import {TVConfig} from "./config";
|
|
2
|
-
import {ClassValue, ClassProp, OmitUndefined, StringToBoolean
|
|
2
|
+
import {ClassValue, ClassProp, OmitUndefined, StringToBoolean} from "./utils";
|
|
3
3
|
|
|
4
|
-
type TVDefaultSlot = "";
|
|
5
4
|
type TVBaseName = "base";
|
|
6
5
|
|
|
7
|
-
type
|
|
6
|
+
type TVSlots = Record<string, ClassValue> | undefined;
|
|
8
7
|
|
|
9
|
-
type
|
|
10
|
-
|
|
8
|
+
type TVSlotsWithBase<S extends TVSlots, B extends ClassValue> = B extends undefined
|
|
9
|
+
? keyof S
|
|
10
|
+
: keyof S | TVBaseName;
|
|
11
|
+
|
|
12
|
+
type SlotsClassValue<S extends TVSlots, B extends ClassValue> = {
|
|
13
|
+
[K in TVSlotsWithBase<S, B>]?: ClassValue;
|
|
11
14
|
};
|
|
12
15
|
|
|
13
|
-
export
|
|
16
|
+
export type TVVariants<S extends TVSlots, B extends ClassValue> = {
|
|
14
17
|
[key: string]: {
|
|
15
|
-
[key: string]: S extends
|
|
18
|
+
[key: string]: S extends TVSlots ? SlotsClassValue<S, B> | ClassValue : ClassValue;
|
|
16
19
|
};
|
|
17
20
|
};
|
|
18
21
|
|
|
19
|
-
export
|
|
22
|
+
export type TVCompoundVariants<
|
|
23
|
+
V extends TVVariants<S>,
|
|
24
|
+
S extends TVSlots,
|
|
25
|
+
B extends ClassValue,
|
|
26
|
+
> = Array<
|
|
20
27
|
{
|
|
21
|
-
[K in keyof V]?: StringToBoolean<keyof V[K]
|
|
22
|
-
} & ClassProp<SlotsClassValue<S> | ClassValue>
|
|
28
|
+
[K in keyof V]?: StringToBoolean<keyof V[K]> | StringToBoolean<keyof V[K]>[];
|
|
29
|
+
} & ClassProp<SlotsClassValue<S, B> | ClassValue>
|
|
23
30
|
>;
|
|
24
31
|
|
|
25
|
-
export
|
|
32
|
+
export type TVDefaultVariants<V extends TVVariants<S>, S extends TVSlots> = {
|
|
26
33
|
[K in keyof V]?: StringToBoolean<keyof V[K]>;
|
|
27
34
|
};
|
|
28
35
|
|
|
29
|
-
export
|
|
36
|
+
export type TVProps<V extends TVVariants<S>, S extends TVSlots> = {
|
|
30
37
|
[K in keyof V]?: StringToBoolean<keyof V[K]>;
|
|
31
38
|
} & ClassProp;
|
|
32
39
|
|
|
33
|
-
export
|
|
34
|
-
props?: TVProps<V, S
|
|
35
|
-
) => S extends
|
|
40
|
+
export type TVReturnType<V extends TVVariants<S>, S extends TVSlots, B extends ClassValue> = (
|
|
41
|
+
props?: TVProps<V, S>,
|
|
42
|
+
) => S extends undefined
|
|
36
43
|
? string
|
|
37
44
|
: {
|
|
38
|
-
[K in
|
|
45
|
+
[K in TVSlotsWithBase<S, B>]: (slotProps?: ClassProp) => string;
|
|
39
46
|
};
|
|
40
47
|
|
|
41
|
-
export
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
CV extends TVCompoundVariants<V, S[]>,
|
|
48
|
+
export function tv<
|
|
49
|
+
DV extends TVDefaultVariants<V, S>,
|
|
50
|
+
CV extends TVCompoundVariants<V, S, B>,
|
|
45
51
|
C extends TVConfig,
|
|
46
|
-
|
|
52
|
+
V extends TVVariants<S>,
|
|
53
|
+
B extends ClassValue = undefined,
|
|
54
|
+
S extends TVSlots = undefined,
|
|
47
55
|
>(
|
|
48
56
|
options: {
|
|
49
|
-
base?:
|
|
50
|
-
slots?: S
|
|
57
|
+
base?: B;
|
|
58
|
+
slots?: S;
|
|
51
59
|
variants?: V;
|
|
52
60
|
compoundVariants?: CV;
|
|
53
61
|
defaultVariants?: DV;
|
|
54
62
|
},
|
|
55
63
|
config?: C,
|
|
56
|
-
): TVReturnType<V, S>;
|
|
64
|
+
): TVReturnType<V, S, B>;
|
|
57
65
|
|
|
58
66
|
export type VariantProps<Component extends (...args: any) => any> = Omit<
|
|
59
67
|
OmitUndefined<Parameters<Component>[0]>,
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { cx } from 'class-variance-authority';
|
|
2
2
|
import { extendTailwindMerge, twMerge } from 'tailwind-merge';
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var i=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,g=e=>e&&Object.keys(e).length>0,m=(...e)=>(f={})=>f.twMerge?(g(f.twMergeConfig)?extendTailwindMerge(f.twMergeConfig):twMerge)(cx(e)):cx(e);var F=(e,f={twMerge:!0,twMergeConfig:{}})=>n=>{var C,O;let{slots:l={},variants:b,defaultVariants:y}=e;if(b==null&&!g(l))return m(e==null?void 0:e.base,n==null?void 0:n.class,n==null?void 0:n.className)(f);let d={base:e==null?void 0:e.base,...l},w=t=>{let a=n==null?void 0:n[t],r=y==null?void 0:y[t];if(a===null)return null;let u=i(a)||i(r);return b[t][u]},s=b?Object.keys(b).map(w):null,N=t=>!b||typeof b!="object"?null:Object.keys(b).map(a=>{let r=w(a);return t==="base"&&typeof r=="string"?r:!r||typeof r!="object"?null:r[t]}),M=n&&Object.entries(n).reduce((t,[a,r])=>(r===void 0||(t[a]=r),t),{}),x=(C=e==null?void 0:e.compoundVariants)==null?void 0:C.reduce((t,{class:a,className:r,...u})=>Object.entries(u).every(([c,j])=>Array.isArray(j)?j.includes({...y,...M}[c]):{...y,...M}[c]===j)?[...t,a,r]:t,[]),A=()=>{let t=x;return Array.isArray(t)?t.reduce((a,r)=>(typeof r=="string"&&(a.base=m(a.base,r)(f)),typeof r=="object"&&Object.entries(r).forEach(([u,c])=>{a[u]=m(a[u],c)(f);}),a),{}):t};if(g(l)){let t=(O=A())!=null?O:[];return {...typeof d=="object"&&g(d)?Object.keys(d).reduce((r,u)=>(r[u]=c=>m(u==="base"?e==null?void 0:e.base:[],d[u],N(u),t==null?void 0:t[u],c==null?void 0:c.class,c==null?void 0:c.className)(f),r),{}):{}}}return m(e==null?void 0:e.base,s,x,n==null?void 0:n.class,n==null?void 0:n.className)(f)};
|
|
5
5
|
|
|
6
|
-
export {
|
|
6
|
+
export { F as tv };
|
package/dist/utils.d.ts
CHANGED
|
@@ -2,10 +2,10 @@ import {CxOptions, CxReturn} from "class-variance-authority";
|
|
|
2
2
|
|
|
3
3
|
import {TVConfig} from "./config";
|
|
4
4
|
|
|
5
|
-
export declare const cleanArray: (array: string[]) => string[] | undefined;
|
|
6
|
-
|
|
7
5
|
export declare const falsyToString: <T extends unknown>(value: T) => string | T;
|
|
8
6
|
|
|
7
|
+
export declare const isNotEmptyObject: (obj: object) => boolean;
|
|
8
|
+
|
|
9
9
|
export declare const cx: <T extends CxOptions>(...classes: T) => (config: TVConfig) => CxReturn;
|
|
10
10
|
|
|
11
11
|
export declare const removeDuplicates: <T extends unknown>(array: T[]) => T[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tailwind-variants",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"description": "🦄 Tailwindcss first-class variant API",
|
|
5
5
|
"author": "Junior Garcia <jrgarciadev@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -61,6 +61,7 @@
|
|
|
61
61
|
"prettier": "^2.2.1",
|
|
62
62
|
"prettier-eslint": "^12.0.0",
|
|
63
63
|
"prettier-eslint-cli": "^5.0.1",
|
|
64
|
+
"jest": "28.1.1",
|
|
64
65
|
"ts-node": "^10.9.1",
|
|
65
66
|
"tslib": "^2.4.1",
|
|
66
67
|
"tsup": "6.4.0",
|