tailwindcss-custom-colors 1.0.0 → 1.0.2
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 +176 -0
- package/package.json +34 -30
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Quentin Juarez
|
|
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,176 @@
|
|
|
1
|
+
## Installation
|
|
2
|
+
|
|
3
|
+
```bash
|
|
4
|
+
# With npm
|
|
5
|
+
npm i tailwindcss-custom-colors@latest
|
|
6
|
+
|
|
7
|
+
# With yarn
|
|
8
|
+
yarn add tailwindcss-custom-colors@latest
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
[](https://badge.fury.io/js/tailwindcss-custom-colors)
|
|
12
|
+
|
|
13
|
+
<!-- 
|
|
14
|
+

|
|
15
|
+

|
|
16
|
+

|
|
17
|
+

|
|
18
|
+
 -->
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
### Import
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
import { generateConfig } from "tailwindcss-custom-colors";
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
import { generateStyleVariables } from "tailwindcss-custom-colors";
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### generateConfig()
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
const extendedColors = generateConfig(colorNames, options);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
#### The generateConfig function takes the following parameters:
|
|
39
|
+
|
|
40
|
+
- `colorNames`: An array of color names or a single color name.
|
|
41
|
+
- `options` (optional): An object of options that allows you to customize the generated colors. The available options are `suffixMultiplier` (default: `100`), which determines the suffix used to generate variables names (e.g `[1, 10, 100]`) and `variablePrefix` (default: `undefined`), which determines the prefix for the css variable name, none by default.
|
|
42
|
+
|
|
43
|
+
The function returns a config object for Tailwind CSS with the specified color names and their respective tints.
|
|
44
|
+
|
|
45
|
+
### generateStyleVariables()
|
|
46
|
+
|
|
47
|
+
```js
|
|
48
|
+
const variables = generateStyleVariables(colorParams, options);
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
#### The generateConfig function takes the following parameters:
|
|
52
|
+
|
|
53
|
+
- `colorParams`: An array of color params or a single color params including a color (hex) and a name.
|
|
54
|
+
- `options` (optional): An object of options that allows you to customize the generated colors. The available option is `suffixMultiplier` (default: `100`), which determines the suffix used to generate variables names (e.g `[1, 10, 100]`).
|
|
55
|
+
of css variables with the specified color names and their respective tints.
|
|
56
|
+
|
|
57
|
+
## Example
|
|
58
|
+
|
|
59
|
+
Extend your tailwind config
|
|
60
|
+
|
|
61
|
+
_tailwind.config.js_
|
|
62
|
+
|
|
63
|
+
```js
|
|
64
|
+
/** @type {import('tailwindcss').Config} */
|
|
65
|
+
import { generateConfig } from "tailwindcss-custom-colors";
|
|
66
|
+
|
|
67
|
+
const extendedColors = generateConfig(["primary", "secondary"]);
|
|
68
|
+
|
|
69
|
+
module.exports = {
|
|
70
|
+
content: ["./src/**/*.{index,vue,js,ts,jsx,tsx}"],
|
|
71
|
+
theme: {
|
|
72
|
+
extend: {
|
|
73
|
+
colors: extendedColors,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
plugins: [],
|
|
77
|
+
};
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
#### Output for `extendedColors`:
|
|
81
|
+
|
|
82
|
+
```json
|
|
83
|
+
{
|
|
84
|
+
"primary": {
|
|
85
|
+
"DEFAULT": "rgb(var(--primary) / <alpha-value>)",
|
|
86
|
+
"100": "rgb(var(--primary-100) / <alpha-value>)",
|
|
87
|
+
"200": "rgb(var(--primary-200) / <alpha-value>)",
|
|
88
|
+
"300": "rgb(var(--primary-300) / <alpha-value>)",
|
|
89
|
+
"400": "rgb(var(--primary-400) / <alpha-value>)",
|
|
90
|
+
"500": "rgb(var(--primary-500) / <alpha-value>)",
|
|
91
|
+
"600": "rgb(var(--primary-600) / <alpha-value>)",
|
|
92
|
+
"700": "rgb(var(--primary-700) / <alpha-value>)",
|
|
93
|
+
"800": "rgb(var(--primary-800) / <alpha-value>)",
|
|
94
|
+
"900": "rgb(var(--primary-900) / <alpha-value>)"
|
|
95
|
+
},
|
|
96
|
+
"secondary": {
|
|
97
|
+
"DEFAULT": "rgb(var(--secondary) / <alpha-value>)",
|
|
98
|
+
"100": "rgb(var(--secondary-100) / <alpha-value>)",
|
|
99
|
+
"200": "rgb(var(--secondary-200) / <alpha-value>)",
|
|
100
|
+
"300": "rgb(var(--secondary-300) / <alpha-value>)",
|
|
101
|
+
"400": "rgb(var(--secondary-400) / <alpha-value>)",
|
|
102
|
+
"500": "rgb(var(--secondary-500) / <alpha-value>)",
|
|
103
|
+
"600": "rgb(var(--secondary-600) / <alpha-value>)",
|
|
104
|
+
"700": "rgb(var(--secondary-700) / <alpha-value>)",
|
|
105
|
+
"800": "rgb(var(--secondary-800) / <alpha-value>)",
|
|
106
|
+
"900": "rgb(var(--secondary-900) / <alpha-value>)"
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Variables
|
|
112
|
+
|
|
113
|
+
Generate css variables
|
|
114
|
+
|
|
115
|
+
```js
|
|
116
|
+
import { generateStyleVariables } from "tailwindcss-custom-colors";
|
|
117
|
+
|
|
118
|
+
const variables = generateStyleVariables(
|
|
119
|
+
{
|
|
120
|
+
color: "#940BDF",
|
|
121
|
+
name: "primary",
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
color: "#FFD534",
|
|
125
|
+
name: "secondary",
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
#### Output for `variables`:
|
|
131
|
+
|
|
132
|
+
```css
|
|
133
|
+
--primary: 148 11 223;
|
|
134
|
+
--primary-100: 223 171 251;
|
|
135
|
+
--primary-200: 315 413 262;
|
|
136
|
+
--primary-300: 413 671 275;
|
|
137
|
+
--primary-400: 482 852 283;
|
|
138
|
+
--primary-500: 148 11 223;
|
|
139
|
+
--primary-600: 400 635 273;
|
|
140
|
+
--primary-700: 268 288 257;
|
|
141
|
+
--primary-800: 139 10 208;
|
|
142
|
+
--primary-900: 28 2 42;
|
|
143
|
+
--secondary: 255 213 52;
|
|
144
|
+
--secondary-100: 255 263 296;
|
|
145
|
+
--secondary-200: 255 329 626;
|
|
146
|
+
--secondary-300: 255 400 979;
|
|
147
|
+
--secondary-400: 255 449 1226;
|
|
148
|
+
--secondary-500: 255 213 52;
|
|
149
|
+
--secondary-600: 255 390 929;
|
|
150
|
+
--secondary-700: 255 295 456;
|
|
151
|
+
--secondary-800: 255 210 29;
|
|
152
|
+
--secondary-900: 57 45 0;
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Import variables
|
|
156
|
+
|
|
157
|
+
#### by creating a style tag
|
|
158
|
+
|
|
159
|
+
```js
|
|
160
|
+
const style = document.create("style");
|
|
161
|
+
style.innerHTML = `
|
|
162
|
+
@layer base {
|
|
163
|
+
:root {
|
|
164
|
+
${variables}
|
|
165
|
+
}
|
|
166
|
+
}`;
|
|
167
|
+
document.head.appendChild(style);
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
#### by creating a v-bind style attribute (VueJS)
|
|
171
|
+
|
|
172
|
+
```vue
|
|
173
|
+
<template>
|
|
174
|
+
<div :style="variables"></div>
|
|
175
|
+
</template>
|
|
176
|
+
```
|
package/package.json
CHANGED
|
@@ -1,30 +1,34 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "tailwindcss-custom-colors",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Reactive color shades generator for TailwindCSS",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "tailwindcss-custom-colors",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "Reactive color shades generator for TailwindCSS",
|
|
5
|
+
"author": "quentinjuarez",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/quentinjuarez/tailwindcss-custom-colors"
|
|
9
|
+
},
|
|
10
|
+
"main": "dist/index.js",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist/**/*"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"test": "jest",
|
|
16
|
+
"build": "tsc"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"tailwind",
|
|
20
|
+
"tailwindcss",
|
|
21
|
+
"colors",
|
|
22
|
+
"palette",
|
|
23
|
+
"shades",
|
|
24
|
+
"tints"
|
|
25
|
+
],
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/jest": "^29.5.3",
|
|
28
|
+
"@types/node": "^20.4.4",
|
|
29
|
+
"jest": "^29.6.1",
|
|
30
|
+
"ts-jest": "^29.1.1",
|
|
31
|
+
"typescript": "^5.1.6"
|
|
32
|
+
},
|
|
33
|
+
"license": "MIT"
|
|
34
|
+
}
|