Skip to content
This repository was archived by the owner on Dec 15, 2024. It is now read-only.

Commit a256802

Browse files
committed
initial commit
0 parents  commit a256802

File tree

6 files changed

+118
-0
lines changed

6 files changed

+118
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules/

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Gradients Tailwind CSS Plugin
2+
3+
## Installation
4+
5+
```bash
6+
npm install tailwindcss-gradients
7+
```
8+
9+
## Usage
10+
11+
```js
12+
// In your Tailwind CSS config
13+
{
14+
plugins: [
15+
require('tailwindcss-gradients')({
16+
variants: ['responsive'],
17+
gradients: {
18+
'red': '#f00',
19+
'red-blue': ['#f00', '#00f'],
20+
'red-green-blue': ['#f00', '#0f0', '#00f'],
21+
},
22+
}),
23+
],
24+
}
25+
```
26+
27+
This plugin generates the following utilities:
28+
29+
```css
30+
/* configurable with the "gradients" option */
31+
.bg-gradient-to-top-[name] {
32+
background-image: linear-gradient(to top, [color-1], [color-2], [...])
33+
}
34+
.bg-gradient-to-right-[name] {
35+
background-image: linear-gradient(to right, [color-1], [color-2], [...])
36+
}
37+
.bg-gradient-to-bottom-[name] {
38+
background-image: linear-gradient(to bottom, [color-1], [color-2], [...])
39+
}
40+
.bg-gradient-to-left-[name] {
41+
background-image: linear-gradient(to left, [color-1], [color-2], [...])
42+
}
43+
```

index.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const _ = require('lodash');
2+
3+
module.exports = ({
4+
variants = {},
5+
gradients = {},
6+
} = {}) =>
7+
({ e, addUtilities }) => {
8+
addUtilities(
9+
{
10+
...Object.assign(
11+
{},
12+
..._.map(gradients, (colors, name) => {
13+
if (!_.isArray(colors)) {
14+
colors = ['transparent', colors];
15+
}
16+
return {
17+
[`.bg-gradient-to-top-${e(name)}`]: { backgroundImage: `linear-gradient(to top, ${colors.join(', ')})` },
18+
[`.bg-gradient-to-right-${e(name)}`]: { backgroundImage: `linear-gradient(to right, ${colors.join(', ')})` },
19+
[`.bg-gradient-to-bottom-${e(name)}`]: { backgroundImage: `linear-gradient(to bottom, ${colors.join(', ')})` },
20+
[`.bg-gradient-to-left-${e(name)}`]: { backgroundImage: `linear-gradient(to left, ${colors.join(', ')})` },
21+
};
22+
}),
23+
),
24+
},
25+
variants,
26+
);
27+
};

package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "tailwindcss-gradients",
3+
"version": "1.0.0",
4+
"description": "Tailwind CSS plugin to generate gradient background utilities",
5+
"author": "Benoît Rouleau <[email protected]>",
6+
"license": "ISC",
7+
"repository": "https://github.com/benface/tailwindcss-gradients.git",
8+
"bugs": "https://github.com/benface/tailwindcss-gradients/issues",
9+
"homepage": "https://github.com/benface/tailwindcss-gradients",
10+
"scripts": {
11+
"test": "node test.js"
12+
},
13+
"dependencies": {
14+
"lodash": "^4.17.10"
15+
}
16+
}

test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const plugin = require('./index.js');
2+
3+
let generatedUtilities = {};
4+
5+
plugin({
6+
gradients: {
7+
'red': '#f00',
8+
'red-blue': ['#f00', '#00f'],
9+
'red-green-blue': ['#f00', '#0f0', '#00f'],
10+
},
11+
})({
12+
e: value => value,
13+
addUtilities: (utilities, variants) => {
14+
generatedUtilities = utilities;
15+
},
16+
});
17+
18+
console.log("generatedUtilities", generatedUtilities);

0 commit comments

Comments
 (0)