tailwind-variants 0.0.1 → 0.0.3
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/LICENSE +21 -0
- package/README.md +37 -0
- package/dist/config.d.ts +16 -0
- package/dist/index.cjs +8 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.js +6 -0
- package/dist/types.d.ts +58 -0
- package/dist/utils.d.ts +23 -0
- package/package.json +85 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Tailwid Variants
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Tailwind Variants
|
|
2
|
+
|
|
3
|
+
🚧 Under construction - please check back later
|
|
4
|
+
|
|
5
|
+
## Acknowledgements
|
|
6
|
+
|
|
7
|
+
- [**cva**](https://github.com/joe-bell/cva) ([Joe Bell](https://github.com/joe-bell))
|
|
8
|
+
This project as started as an extension of Joe's work on `cva` – a great tool for generating variants for a single element with Tailwind CSS. Big shoutout to [Joe Bell](https://github.com/joe-bell) and [contributors](https://github.com/joe-bell/cva/graphs/contributors) you guys rock! 🤘 - we recommend to use `cva` if don't need to generate variants for multiple elements at the same time.
|
|
9
|
+
|
|
10
|
+
- [**Stitches**](https://stitches.dev/) ([Modulz](https://modulz.app))
|
|
11
|
+
The pioneers of the `variants` API movement. Inmense thanks to [Modulz](https://modulz.app) for their work on Stitches and the community around it. 🙏
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
yarn add tailwind-variants
|
|
17
|
+
#or
|
|
18
|
+
npm i tailwind-variants
|
|
19
|
+
```
|
|
20
|
+
## Contributing
|
|
21
|
+
|
|
22
|
+
Contributions are always welcome!
|
|
23
|
+
|
|
24
|
+
Please follow our [contributing guidelines](./CONTRIBUTING.md).
|
|
25
|
+
|
|
26
|
+
Please adhere to this project's [CODE_OF_CONDUCT](./CODE_OF_CONDUCT.md).
|
|
27
|
+
|
|
28
|
+
## Authors
|
|
29
|
+
|
|
30
|
+
- Junior garcia ([@jrgarciadev](https://github.com/jrgaciadev))
|
|
31
|
+
- Tianen Pang ([@tianenpang](https://github.com/tianenpang))
|
|
32
|
+
|
|
33
|
+
## License
|
|
34
|
+
|
|
35
|
+
Licensed under the MIT License.
|
|
36
|
+
|
|
37
|
+
See [LICENSE](./LICENSE.md) for more information.
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type {Config as TwMergeConfig} from "tailwind-merge";
|
|
2
|
+
|
|
3
|
+
export type TVConfig = {
|
|
4
|
+
/**
|
|
5
|
+
* Whether to merge the class names with `tailwind-merge` library.
|
|
6
|
+
* It's avoid to have duplicate tailwind classes. (Recommended)
|
|
7
|
+
* @see https://github.com/dcastil/tailwind-merge/blob/v1.8.1/README.md
|
|
8
|
+
* @default true
|
|
9
|
+
*/
|
|
10
|
+
twMerge?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* The config object for `tailwind-merge` library.
|
|
13
|
+
* @see https://github.com/dcastil/tailwind-merge/blob/v1.8.1/docs/configuration.md
|
|
14
|
+
*/
|
|
15
|
+
twMergeConfig?: TwMergeConfig;
|
|
16
|
+
};
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var classVarianceAuthority = require('class-variance-authority');
|
|
4
|
+
var tailwindMerge = require('tailwind-merge');
|
|
5
|
+
|
|
6
|
+
var g=e=>e.filter(c=>c),C=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,k=e=>e&&Object.keys(e).length>0,b=(...e)=>(c={})=>c.merge?(k(c.twMergeConfig)?tailwindMerge.extendTailwindMerge(c.twMergeConfig):tailwindMerge.twMerge)(classVarianceAuthority.cx(e)):classVarianceAuthority.cx(e);var W=(e,c={twMerge:!0,twMergeConfig:{}})=>a=>{var V;if((e==null?void 0:e.variants)==null)return b(e==null?void 0:e.base,a==null?void 0:a.class,a==null?void 0:a.className)(c);let{slots:w=[],variants:d,defaultVariants:f}=e,N=Array.isArray(w)?new Set(["base",...w.filter(n=>n!=="base")]):[],x=n=>{let t=a==null?void 0:a[n],r=f==null?void 0:f[n];if(t===null)return null;let i=C(t)||C(r);return d[n][i]},S=Object.keys(d).map(x),M=n=>g(Object.keys(d).map(t=>{let r=x(t);return !r||typeof r!="object"?null:r[n]})),j=a&&Object.entries(a).reduce((n,[t,r])=>(r===void 0||(n[t]=r),n),{}),A=(V=e==null?void 0:e.compoundVariants)==null?void 0:V.reduce((n,{class:t,className:r,...i})=>Object.entries(i).every(([m,u])=>Array.isArray(u)?u.includes({...f,...j}[m]):{...f,...j}[m]===u)?[...n,t,r]:n,[]),h=()=>{let n=g(A);return Array.isArray(n)?n.reduce((t,r)=>(typeof r=="string"&&(t.base=b(t.base,r)(c)),typeof r=="object"&&Object.entries(r).forEach(([i,m])=>{t[i]=b(t[i],m)(c);}),t),{}):n};if(N.length>1){let n=M("base"),t=h(),r=N.slice(1).reduce((i,m)=>(i[m]=u=>b(M(m),t[m],u==null?void 0:u.class,u==null?void 0:u.className)(c),i),{});return {base:i=>b(e==null?void 0:e.base,n,t.base,i==null?void 0:i.class,i==null?void 0:i.className)(c),...r}}return b(e==null?void 0:e.base,S,A,a==null?void 0:a.class,a==null?void 0:a.className)(c)};
|
|
7
|
+
|
|
8
|
+
exports.tv = W;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {TVConfig} from "./config";
|
|
2
|
+
import {ClassValue, ClassProp, OmitUndefined} from "./utils";
|
|
3
|
+
|
|
4
|
+
type TVVariants<S extends string[]> = {
|
|
5
|
+
[key: string]: {
|
|
6
|
+
[key: string]: {[P in S[number]]?: ClassValue} | ClassValue;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
type TVCompoundVariants<V extends TVVariants<S>, S extends string[]> = Array<
|
|
11
|
+
{
|
|
12
|
+
[K in keyof V]?: keyof V[K];
|
|
13
|
+
} & ClassProp<{[K in S[number]]?: ClassValue} | ClassValue>
|
|
14
|
+
>;
|
|
15
|
+
|
|
16
|
+
type TVDefaultVariants<V extends TVVariants<S>, S extends string[]> = {
|
|
17
|
+
[K in keyof V]?: keyof V[K];
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type TVReturnType<S extends string[]> = S extends string[]
|
|
21
|
+
? {[K in S[number]]: (slotProps: ClassProp) => string}
|
|
22
|
+
: (slotProps: ClassProp) => string;
|
|
23
|
+
|
|
24
|
+
export declare function tv<
|
|
25
|
+
S extends string,
|
|
26
|
+
V extends TVVariants<S[]>,
|
|
27
|
+
CV extends TVCompoundVariants<V, S[]>,
|
|
28
|
+
DV extends TVDefaultVariants<V, S[]>,
|
|
29
|
+
C extends TVConfig,
|
|
30
|
+
>(
|
|
31
|
+
options: {
|
|
32
|
+
base?: ClassValue;
|
|
33
|
+
slots?: S[];
|
|
34
|
+
variants?: V;
|
|
35
|
+
compoundVariants?: CV;
|
|
36
|
+
defaultVariants?: DV;
|
|
37
|
+
},
|
|
38
|
+
config?: C,
|
|
39
|
+
): TVReturnType<S[]>;
|
|
40
|
+
|
|
41
|
+
export type VariantProps<Component extends (...args: any) => any> = Omit<
|
|
42
|
+
OmitUndefined<Parameters<Component>[0]>,
|
|
43
|
+
"class" | "className"
|
|
44
|
+
>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { cx } from 'class-variance-authority';
|
|
2
|
+
import { extendTailwindMerge, twMerge } from 'tailwind-merge';
|
|
3
|
+
|
|
4
|
+
var g=e=>e.filter(c=>c),C=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,k=e=>e&&Object.keys(e).length>0,b=(...e)=>(c={})=>c.merge?(k(c.twMergeConfig)?extendTailwindMerge(c.twMergeConfig):twMerge)(cx(e)):cx(e);var W=(e,c={twMerge:!0,twMergeConfig:{}})=>a=>{var V;if((e==null?void 0:e.variants)==null)return b(e==null?void 0:e.base,a==null?void 0:a.class,a==null?void 0:a.className)(c);let{slots:w=[],variants:d,defaultVariants:f}=e,N=Array.isArray(w)?new Set(["base",...w.filter(n=>n!=="base")]):[],x=n=>{let t=a==null?void 0:a[n],r=f==null?void 0:f[n];if(t===null)return null;let i=C(t)||C(r);return d[n][i]},S=Object.keys(d).map(x),M=n=>g(Object.keys(d).map(t=>{let r=x(t);return !r||typeof r!="object"?null:r[n]})),j=a&&Object.entries(a).reduce((n,[t,r])=>(r===void 0||(n[t]=r),n),{}),A=(V=e==null?void 0:e.compoundVariants)==null?void 0:V.reduce((n,{class:t,className:r,...i})=>Object.entries(i).every(([m,u])=>Array.isArray(u)?u.includes({...f,...j}[m]):{...f,...j}[m]===u)?[...n,t,r]:n,[]),h=()=>{let n=g(A);return Array.isArray(n)?n.reduce((t,r)=>(typeof r=="string"&&(t.base=b(t.base,r)(c)),typeof r=="object"&&Object.entries(r).forEach(([i,m])=>{t[i]=b(t[i],m)(c);}),t),{}):n};if(N.length>1){let n=M("base"),t=h(),r=N.slice(1).reduce((i,m)=>(i[m]=u=>b(M(m),t[m],u==null?void 0:u.class,u==null?void 0:u.className)(c),i),{});return {base:i=>b(e==null?void 0:e.base,n,t.base,i==null?void 0:i.class,i==null?void 0:i.className)(c),...r}}return b(e==null?void 0:e.base,S,A,a==null?void 0:a.class,a==null?void 0:a.className)(c)};
|
|
5
|
+
|
|
6
|
+
export { W as tv };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type {Config as TwMergeConfig} from "tailwind-merge";
|
|
2
|
+
|
|
3
|
+
export type ClassPropKey = "class" | "className";
|
|
4
|
+
export type ClassValue = string | null | undefined | ClassValue[];
|
|
5
|
+
|
|
6
|
+
export type ClassProp =
|
|
7
|
+
| {
|
|
8
|
+
class: ClassValue;
|
|
9
|
+
className?: never;
|
|
10
|
+
}
|
|
11
|
+
| {class?: never; className: ClassValue}
|
|
12
|
+
| {class?: never; className?: never};
|
|
13
|
+
|
|
14
|
+
export type OmitUndefined<T> = T extends undefined ? never : T;
|
|
15
|
+
export type StringToBoolean<T> = T extends "true" | "false" ? boolean : T;
|
|
16
|
+
|
|
17
|
+
export type Config = {
|
|
18
|
+
/**
|
|
19
|
+
* Whether to merge the class names with `tailwind-merge` library.
|
|
20
|
+
* It's avoid to have duplicate tailwind classes. (Recommended)
|
|
21
|
+
* @see https://github.com/dcastil/tailwind-merge/blob/v1.8.1/README.md
|
|
22
|
+
* @default true
|
|
23
|
+
*/
|
|
24
|
+
twMerge?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* The config object for `tailwind-merge` library.
|
|
27
|
+
* @see https://github.com/dcastil/tailwind-merge/blob/v1.8.1/docs/configuration.md
|
|
28
|
+
*/
|
|
29
|
+
twMergeConfig?: TwMergeConfig;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
type StylesSchema = Record<string, Record<string, ClassValue>>;
|
|
33
|
+
|
|
34
|
+
export type SlotVariants<T extends StylesConfig> = {
|
|
35
|
+
[Slot in keyof T["slots"]]?: ClassValue;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
type StylesVariants<T extends StylesSchema> = {
|
|
39
|
+
[Variant in keyof T]?: StringToBoolean<keyof T[Variant]> | null;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
type StylesVariantsMulti<T extends StylesSchema> = {
|
|
43
|
+
[Variant in keyof T]?: StringToBoolean<keyof T[Variant]> | StringToBoolean<keyof T[Variant]>[];
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type StylesConfig<T = {}> = T extends StylesSchema
|
|
47
|
+
? {
|
|
48
|
+
base?: ClassValue;
|
|
49
|
+
slots?: string[];
|
|
50
|
+
variants?: T;
|
|
51
|
+
defaultVariants?: StylesVariants<T>;
|
|
52
|
+
compoundVariants?: (T extends StylesSchema
|
|
53
|
+
? (StylesVariants<T> | StylesVariantsMulti<T>) & ClassProp
|
|
54
|
+
: ClassProp)[];
|
|
55
|
+
}
|
|
56
|
+
: never;
|
|
57
|
+
|
|
58
|
+
export type TvVariantsProps = StylesVariants<StylesSchema> & ClassProp;
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {CxOptions, CxReturn} from "class-variance-authority";
|
|
2
|
+
|
|
3
|
+
import {TVConfig} from "./config";
|
|
4
|
+
|
|
5
|
+
export declare const cleanArray: (array: string[]) => string[];
|
|
6
|
+
|
|
7
|
+
export declare const falsyToString: <T extends unknown>(value: T) => string | T;
|
|
8
|
+
|
|
9
|
+
export declare const cx: <T extends CxOptions>(...classes: T) => (config: TVConfig) => CxReturn;
|
|
10
|
+
|
|
11
|
+
export type ClassPropKey = "class" | "className";
|
|
12
|
+
export type ClassValue = string | string[] | null | undefined;
|
|
13
|
+
|
|
14
|
+
export type ClassProp<V extends unknown = ClassValue> =
|
|
15
|
+
| {
|
|
16
|
+
class: V;
|
|
17
|
+
className?: never;
|
|
18
|
+
}
|
|
19
|
+
| {class?: never; className: V}
|
|
20
|
+
| {class?: never; className?: never};
|
|
21
|
+
|
|
22
|
+
export type OmitUndefined<T> = T extends undefined ? never : T;
|
|
23
|
+
export type StringToBoolean<T> = T extends "true" | "false" ? boolean : T;
|
package/package.json
CHANGED
|
@@ -1,10 +1,76 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tailwind-variants",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "🦄 Tailwindcss first-class variant API",
|
|
5
|
+
"author": "Junior Garcia <jrgarciadev@gmail.com>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/nextui-org/tailwind-variants"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/nextui-org/tailwind-variants/issues"
|
|
16
|
+
},
|
|
17
|
+
"type": "module",
|
|
18
|
+
"main": "src/index.ts",
|
|
19
|
+
"typings": "./dist/index.d.ts",
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"require": "./dist/index.cjs",
|
|
27
|
+
"import": "./dist/index.js",
|
|
28
|
+
"types": "./types/index.d.ts"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
6
31
|
"scripts": {
|
|
7
|
-
"
|
|
32
|
+
"build": "tsup src/index.js && node copy-types.cjs",
|
|
33
|
+
"dev": "pnpm build:fast -- --watch",
|
|
34
|
+
"clean": "rimraf dist .turbo",
|
|
35
|
+
"typecheck": "tsc --noEmit",
|
|
36
|
+
"dry-run": "pnpm ts-node tests/dry-run.js",
|
|
37
|
+
"prepack": "clean-package",
|
|
38
|
+
"postpack": "clean-package restore",
|
|
39
|
+
"lint": "eslint -c .eslintrc.json ./src/**/*.{ts,tsx}",
|
|
40
|
+
"lint:fix": "eslint --fix -c .eslintrc.json ./src/**/*.{ts,tsx}",
|
|
41
|
+
"test": "jest --verbose"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"class-variance-authority": "0.4.0",
|
|
45
|
+
"tailwind-merge": "^1.8.1"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@commitlint/cli": "^17.2.0",
|
|
49
|
+
"@commitlint/config-conventional": "^17.2.0",
|
|
50
|
+
"@swc-node/jest": "^1.5.2",
|
|
51
|
+
"@swc/cli": "0.1.57",
|
|
52
|
+
"@swc/core": "1.2.198",
|
|
53
|
+
"@types/jest": "28.1.1",
|
|
54
|
+
"@typescript-eslint/eslint-plugin": "^5.42.0",
|
|
55
|
+
"@typescript-eslint/parser": "^5.42.0",
|
|
56
|
+
"clean-package": "2.1.1",
|
|
57
|
+
"eslint": "^7.29.0",
|
|
58
|
+
"eslint-config-prettier": "^8.2.0",
|
|
59
|
+
"eslint-config-ts-lambdas": "^1.2.3",
|
|
60
|
+
"eslint-import-resolver-typescript": "^2.4.0",
|
|
61
|
+
"eslint-loader": "^4.0.2",
|
|
62
|
+
"eslint-plugin-import": "^2.26.0",
|
|
63
|
+
"eslint-plugin-jest": "^24.3.6",
|
|
64
|
+
"eslint-plugin-node": "^11.1.0",
|
|
65
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
66
|
+
"eslint-plugin-promise": "^6.0.0",
|
|
67
|
+
"prettier": "^2.2.1",
|
|
68
|
+
"prettier-eslint": "^12.0.0",
|
|
69
|
+
"prettier-eslint-cli": "^5.0.1",
|
|
70
|
+
"ts-node": "^10.9.1",
|
|
71
|
+
"tsup": "6.4.0",
|
|
72
|
+
"typescript": "4.6.2",
|
|
73
|
+
"webpack": "^5.53.0"
|
|
8
74
|
},
|
|
9
75
|
"keywords": [
|
|
10
76
|
"tailwindcss",
|
|
@@ -13,6 +79,19 @@
|
|
|
13
79
|
"styled.",
|
|
14
80
|
"styles"
|
|
15
81
|
],
|
|
16
|
-
"
|
|
17
|
-
|
|
82
|
+
"engines": {
|
|
83
|
+
"node": ">=16.x",
|
|
84
|
+
"pnpm": ">=7.x"
|
|
85
|
+
},
|
|
86
|
+
"tsup": {
|
|
87
|
+
"clean": true,
|
|
88
|
+
"minify": true,
|
|
89
|
+
"treeshake": true,
|
|
90
|
+
"target": "es2019",
|
|
91
|
+
"format": [
|
|
92
|
+
"cjs",
|
|
93
|
+
"esm"
|
|
94
|
+
]
|
|
95
|
+
},
|
|
96
|
+
"packageManager": "pnpm@7.14.2"
|
|
18
97
|
}
|