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

Commit 0293355

Browse files
committed
Changes for Tailwind 1.0.0
1 parent 47ebe8d commit 0293355

File tree

8 files changed

+2793
-3909
lines changed

8 files changed

+2793
-3909
lines changed

.gitignore

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

.release-it.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"src": {
2+
"git": {
33
"tagName": "v%s"
44
}
5-
}
5+
}

CHANGELOG.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project mostly adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [2.0.0-beta.1] - 2019-04-04
9+
10+
### Added
11+
- Tailwind 1.0.0 compatibility
12+
13+
### Changed
14+
- The plugin doesn’t accept a config object anymore; instead it finds what it needs in the `theme` and `variants` keys of your config (see `README` for more info)
15+
- Responsive variants are now generated by default
16+
817
## [1.1.0] - 2018-11-05
918

1019
### Added
@@ -23,6 +32,7 @@ and this project mostly adheres to [Semantic Versioning](https://semver.org/spec
2332

2433
Initial release
2534

26-
[Unreleased]: https://github.com/benface/tailwindcss-gradients/compare/v1.1.0...HEAD
35+
[Unreleased]: https://github.com/benface/tailwindcss-gradients/compare/v2.0.0-beta.1...HEAD
36+
[2.0.0-beta.1]: https://github.com/benface/tailwindcss-gradients/compare/v1.1.0...v2.0.0-beta.1
2737
[1.1.0]: https://github.com/benface/tailwindcss-gradients/compare/v1.0.1...v1.1.0
28-
[1.0.1]: https://github.com/benface/tailwindcss-gradients/compare/v1.0.0...v1.0.1
38+
[1.0.1]: https://github.com/benface/tailwindcss-gradients/compare/v1.0.0...v1.0.1

README.md

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Gradients Tailwind CSS Plugin
1+
# Gradients Plugin for Tailwind CSS
22

33
## Installation
44

@@ -11,44 +11,41 @@ npm install tailwindcss-gradients
1111
```js
1212
// In your Tailwind CSS config
1313
{
14-
plugins: [
15-
require('tailwindcss-gradients')({
16-
variants: ['responsive'],
14+
theme: {
15+
gradients: {
1716
directions: {
1817
't': 'to top',
18+
'tr': 'to top right',
1919
'r': 'to right',
20+
'br': 'to bottom right',
2021
'b': 'to bottom',
22+
'bl': 'to bottom left',
2123
'l': 'to left',
24+
'tl': 'to top left',
2225
},
23-
gradients: {
26+
colors: {
2427
'red': '#f00',
2528
'red-blue': ['#f00', '#00f'],
2629
'red-green-blue': ['#f00', '#0f0', '#00f'],
2730
},
28-
}),
31+
},
32+
},
33+
variants: {
34+
gradients: ['responsive'],
35+
},
36+
plugins: [
37+
require('tailwindcss-gradients')(),
2938
],
3039
}
3140
```
3241

3342
This plugin generates the following utilities:
3443

3544
```css
36-
/* configurable with the "directions" and "gradients" options */
37-
.bg-gradient-[direction-name]-[gradient-name] {
38-
background-image: linear-gradient([direction-value], [gradient-color-1], [gradient-color-2], [...])
45+
/* configurable with the "gradients" theme key */
46+
.bg-gradient-[direction-key]-[color-key] {
47+
background-image: linear-gradient([direction-value], [color-value-1], [color-value-2], [...]);
3948
}
4049
```
4150

42-
Note: The `directions` option is optional and defaults to:
43-
```js
44-
{
45-
't': 'to top',
46-
'tr': 'to top right',
47-
'r': 'to right',
48-
'br': 'to bottom right',
49-
'b': 'to bottom',
50-
'bl': 'to bottom left',
51-
'l': 'to left',
52-
'tl': 'to top left',
53-
}
54-
```
51+
Note: The `directions` key in `theme.gradients` is optional and defaults to the above values. Also, the `gradients` variants key defaults to `['responsive']`.

index.js

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
11
const _ = require('lodash');
22

3-
module.exports = ({
4-
variants = {},
5-
directions = {
6-
't': 'to top',
7-
'tr': 'to top right',
8-
'r': 'to right',
9-
'br': 'to bottom right',
10-
'b': 'to bottom',
11-
'bl': 'to bottom left',
12-
'l': 'to left',
13-
'tl': 'to top left',
14-
},
15-
gradients = {},
16-
} = {}) => ({ e, addUtilities }) => {
17-
addUtilities(
18-
{
19-
...(function() {
20-
const utilities = {};
21-
_.forEach(gradients, (gradientColors, gradientName) => {
22-
if (!_.isArray(gradientColors) || gradientColors.length === 1) {
23-
gradientColors = ['transparent', _.isArray(gradientColors) ? gradientColors[0] : gradientColors];
24-
}
25-
_.forEach(directions, (directionValue, directionName) => {
26-
utilities[`.${e(`bg-gradient-${directionName}-${gradientName}`)}`] = {
27-
backgroundImage: `linear-gradient(${directionValue}, ${gradientColors.join(', ')})`,
28-
};
29-
});
3+
module.exports = function() {
4+
return ({ config, e, addUtilities }) => {
5+
const defaultDirections = {
6+
't': 'to top',
7+
'tr': 'to top right',
8+
'r': 'to right',
9+
'br': 'to bottom right',
10+
'b': 'to bottom',
11+
'bl': 'to bottom left',
12+
'l': 'to left',
13+
'tl': 'to top left',
14+
};
15+
const defaultColors = {};
16+
const defaultVariants = ['responsive'];
17+
18+
const gradientUtilities = (function() {
19+
let utilities = {};
20+
_.forEach(config('theme.gradients.colors', defaultColors), (colors, colorKey) => {
21+
if (!_.isArray(colors) || colors.length === 1) {
22+
colors = ['transparent', _.isArray(colors) ? colors[0] : colors];
23+
}
24+
_.forEach(config('theme.gradients.directions', defaultDirections), (direction, directionKey) => {
25+
utilities[`.${e(`bg-gradient-${directionKey}-${colorKey}`)}`] = {
26+
backgroundImage: `linear-gradient(${direction}, ${colors.join(', ')})`,
27+
};
3028
});
31-
return utilities;
32-
})(),
33-
},
34-
variants,
35-
);
29+
});
30+
return utilities;
31+
})();
32+
33+
addUtilities(gradientUtilities, config('variants.gradients', defaultVariants));
34+
};
3635
};

0 commit comments

Comments
 (0)