tailwindcss-custom-colors 1.0.0 → 1.0.1
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/README.md +178 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
## Installation
|
|
2
|
+
|
|
3
|
+
```bash
|
|
4
|
+
# Via npm
|
|
5
|
+
npm i tailwindcss-custom-colors@latest
|
|
6
|
+
|
|
7
|
+
# Via 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 option is `suffixMultiplier` (default: `100`), which determines the suffix used to generate variables names (e.g `[1, 10, 100]`).
|
|
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
|
+
```js
|
|
62
|
+
/** @type {import('tailwindcss').Config} */
|
|
63
|
+
import { generateConfig } from "tailwindcss-custom-colors";
|
|
64
|
+
|
|
65
|
+
const extendedColors = generateConfig(["primary", "secondary"]);
|
|
66
|
+
|
|
67
|
+
module.exports = {
|
|
68
|
+
content: [
|
|
69
|
+
"./app/**/*.{js,ts,jsx,tsx}",
|
|
70
|
+
"./pages/**/*.{js,ts,jsx,tsx}",
|
|
71
|
+
"./components/**/*.{js,ts,jsx,tsx}",
|
|
72
|
+
],
|
|
73
|
+
theme: {
|
|
74
|
+
extend: {
|
|
75
|
+
colors: extendedColors,
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
plugins: [],
|
|
79
|
+
};
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
#### Output for `extendedColors`:
|
|
83
|
+
|
|
84
|
+
```json
|
|
85
|
+
{
|
|
86
|
+
"primary": {
|
|
87
|
+
"DEFAULT": "rgb(var(--primary) / <alpha-value>)",
|
|
88
|
+
"100": "rgb(var(--primary-100) / <alpha-value>)",
|
|
89
|
+
"200": "rgb(var(--primary-200) / <alpha-value>)",
|
|
90
|
+
"300": "rgb(var(--primary-300) / <alpha-value>)",
|
|
91
|
+
"400": "rgb(var(--primary-400) / <alpha-value>)",
|
|
92
|
+
"500": "rgb(var(--primary-500) / <alpha-value>)",
|
|
93
|
+
"600": "rgb(var(--primary-600) / <alpha-value>)",
|
|
94
|
+
"700": "rgb(var(--primary-700) / <alpha-value>)",
|
|
95
|
+
"800": "rgb(var(--primary-800) / <alpha-value>)",
|
|
96
|
+
"900": "rgb(var(--primary-900) / <alpha-value>)"
|
|
97
|
+
},
|
|
98
|
+
"secondary": {
|
|
99
|
+
"DEFAULT": "rgb(var(--secondary) / <alpha-value>)",
|
|
100
|
+
"100": "rgb(var(--secondary-100) / <alpha-value>)",
|
|
101
|
+
"200": "rgb(var(--secondary-200) / <alpha-value>)",
|
|
102
|
+
"300": "rgb(var(--secondary-300) / <alpha-value>)",
|
|
103
|
+
"400": "rgb(var(--secondary-400) / <alpha-value>)",
|
|
104
|
+
"500": "rgb(var(--secondary-500) / <alpha-value>)",
|
|
105
|
+
"600": "rgb(var(--secondary-600) / <alpha-value>)",
|
|
106
|
+
"700": "rgb(var(--secondary-700) / <alpha-value>)",
|
|
107
|
+
"800": "rgb(var(--secondary-800) / <alpha-value>)",
|
|
108
|
+
"900": "rgb(var(--secondary-900) / <alpha-value>)"
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Variables
|
|
114
|
+
|
|
115
|
+
Generate css variables
|
|
116
|
+
|
|
117
|
+
```js
|
|
118
|
+
import { generateStyleVariables } from "tailwindcss-custom-colors";
|
|
119
|
+
|
|
120
|
+
const variables = generateStyleVariables(
|
|
121
|
+
{
|
|
122
|
+
color: "#940BDF",
|
|
123
|
+
name: "primary",
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
color: "#FFD534",
|
|
127
|
+
name: "secondary",
|
|
128
|
+
}
|
|
129
|
+
);
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
#### Output for `variables`:
|
|
133
|
+
|
|
134
|
+
```css
|
|
135
|
+
--primary: 148 11 223;
|
|
136
|
+
--primary-100: 223 171 251;
|
|
137
|
+
--primary-200: 315 413 262;
|
|
138
|
+
--primary-300: 413 671 275;
|
|
139
|
+
--primary-400: 482 852 283;
|
|
140
|
+
--primary-500: 148 11 223;
|
|
141
|
+
--primary-600: 400 635 273;
|
|
142
|
+
--primary-700: 268 288 257;
|
|
143
|
+
--primary-800: 139 10 208;
|
|
144
|
+
--primary-900: 28 2 42;
|
|
145
|
+
--secondary: 255 213 52;
|
|
146
|
+
--secondary-100: 255 263 296;
|
|
147
|
+
--secondary-200: 255 329 626;
|
|
148
|
+
--secondary-300: 255 400 979;
|
|
149
|
+
--secondary-400: 255 449 1226;
|
|
150
|
+
--secondary-500: 255 213 52;
|
|
151
|
+
--secondary-600: 255 390 929;
|
|
152
|
+
--secondary-700: 255 295 456;
|
|
153
|
+
--secondary-800: 255 210 29;
|
|
154
|
+
--secondary-900: 57 45 0;
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Import variables
|
|
158
|
+
|
|
159
|
+
#### by creating a style tag
|
|
160
|
+
|
|
161
|
+
```js
|
|
162
|
+
const style = document.create("style");
|
|
163
|
+
style.innerHTML = `
|
|
164
|
+
@layer base {
|
|
165
|
+
:root {
|
|
166
|
+
${variables}
|
|
167
|
+
}
|
|
168
|
+
}`;
|
|
169
|
+
document.head.appendChild(style);
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
#### by creating a v-bind style attribute (VueJS)
|
|
173
|
+
|
|
174
|
+
```vue
|
|
175
|
+
<template>
|
|
176
|
+
<div :style="variables"></div>
|
|
177
|
+
</template>
|
|
178
|
+
```
|