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

Commit 97a3207

Browse files
committed
Add directions option and write tests
1 parent f62cc7f commit 97a3207

File tree

7 files changed

+9392
-44
lines changed

7 files changed

+9392
-44
lines changed

.release-it.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"src": {
3+
"tagName": "v%s"
4+
}
5+
}

CHANGELOG.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project mostly adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [1.0.2] - 2018-11-05
9+
10+
### Added
11+
- Added `directions` option (defaults to all sides and corners)
12+
- Added proper tests with Jest
13+
14+
### Changed
15+
- The classes that are generated by default are now shorter (`bg-gradient-t-[color]` instead of `bg-gradient-to-top-[color]`, etc.) but can be customized with the `directions` option
16+
17+
## [1.0.1] - 2018-08-14
18+
19+
### Fixed
20+
- Fixed escaping in selectors generated by the plugin
21+
22+
## 1.0.0 - 2018-08-13
23+
24+
Initial release
25+
26+
[Unreleased]: https://github.com/benface/tailwindcss-gradients/compare/v1.0.2...HEAD
27+
[1.0.2]: https://github.com/benface/tailwindcss-gradients/compare/v1.0.1...v1.0.2
28+
[1.0.1]: https://github.com/benface/tailwindcss-gradients/compare/v1.0.0...v1.0.1

README.md

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ npm install tailwindcss-gradients
1414
plugins: [
1515
require('tailwindcss-gradients')({
1616
variants: ['responsive'],
17+
directions: {
18+
't': 'to top',
19+
'r': 'to right',
20+
'b': 'to bottom',
21+
'l': 'to left',
22+
},
1723
gradients: {
1824
'red': '#f00',
1925
'red-blue': ['#f00', '#00f'],
@@ -27,17 +33,22 @@ npm install tailwindcss-gradients
2733
This plugin generates the following utilities:
2834

2935
```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+
/* 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], [...])
3639
}
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], [...])
40+
```
41+
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',
4253
}
4354
```

index.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,34 @@ const _ = require('lodash');
22

33
module.exports = ({
44
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+
},
515
gradients = {},
616
} = {}) => ({ e, addUtilities }) => {
717
addUtilities(
818
{
9-
...Object.assign(
10-
{},
11-
..._.map(gradients, (colors, name) => {
12-
if (!_.isArray(colors)) {
13-
colors = ['transparent', colors];
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];
1424
}
15-
return {
16-
[`.${e(`bg-gradient-to-top-${name}`)}`]: { backgroundImage: `linear-gradient(to top, ${colors.join(', ')})` },
17-
[`.${e(`bg-gradient-to-right-${name}`)}`]: { backgroundImage: `linear-gradient(to right, ${colors.join(', ')})` },
18-
[`.${e(`bg-gradient-to-bottom-${name}`)}`]: { backgroundImage: `linear-gradient(to bottom, ${colors.join(', ')})` },
19-
[`.${e(`bg-gradient-to-left-${name}`)}`]: { backgroundImage: `linear-gradient(to left, ${colors.join(', ')})` },
20-
};
21-
}),
22-
),
25+
_.forEach(directions, (directionValue, directionName) => {
26+
utilities[`.${e(`bg-gradient-${directionName}-${gradientName}`)}`] = {
27+
backgroundImage: `linear-gradient(${directionValue}, ${gradientColors.join(', ')})`,
28+
};
29+
});
30+
});
31+
return utilities;
32+
})(),
2333
},
2434
variants,
2535
);

0 commit comments

Comments
 (0)