Skip to content
This repository was archived by the owner on Feb 22, 2022. It is now read-only.

Commit 15d3414

Browse files
committed
Add text decoration style and text decoration color utilities (fix #18)
1 parent 005cd38 commit 15d3414

File tree

7 files changed

+2489
-1861
lines changed

7 files changed

+2489
-1861
lines changed

.release-it.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"git": {
3-
"tagName": "v%s",
3+
"tagName": "v${version}",
44
"requireCleanWorkingDir": false
55
}
66
}

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ 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+
## [Unreleased]
9+
10+
### Added
11+
- Added `line-[style]` and `line-[color]` utilities to go with Tailwind’s text decoration utilities (`underline` and `line-through`); they can be customized with the `textDecorationStyle` and `textDecorationColor` theme keys
12+
813
## [3.0.1] - 2020-02-13
914

1015
### Fixed

README.md

+24
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ module.exports = {
2424
'default': '0 2px 5px rgba(0, 0, 0, 0.5)',
2525
'lg': '0 2px 10px rgba(0, 0, 0, 0.5)',
2626
},
27+
textDecorationStyle: { // defaults to these values
28+
'solid': 'solid',
29+
'double': 'double',
30+
'dotted': 'dotted',
31+
'dashed': 'dashed',
32+
'wavy': 'wavy',
33+
},
34+
textDecorationColor: { // defaults to theme => theme('colors')
35+
'red': '#f00',
36+
'green': '#0f0',
37+
'blue': '#00f',
38+
},
2739
fontVariantCaps: { // defaults to these values
2840
'normal': 'normal',
2941
'small': 'small-caps',
@@ -151,6 +163,8 @@ module.exports = {
151163
variants: { // all the following default to ['responsive']
152164
textIndent: ['responsive'],
153165
textShadow: ['responsive'],
166+
textDecorationStyle: ['responsive'],
167+
textDecorationColor: ['responsive'],
154168
ellipsis: ['responsive'],
155169
hyphens: ['responsive'],
156170
kerning: ['responsive'],
@@ -187,6 +201,16 @@ This plugin generates the following utilities:
187201
text-shadow: [value];
188202
}
189203

204+
/* configurable with the "textDecorationStyle" theme object */
205+
.line-[key] {
206+
text-decoration-style: [value];
207+
}
208+
209+
/* configurable with the "textDecorationColor" theme object */
210+
.line-[key] {
211+
text-decoration-color: [value];
212+
}
213+
190214
/* generated when the "ellipsis" option is set to true */
191215
.ellipsis {
192216
text-overflow: ellipsis;

index.js

+49
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@ const prefixNegativeModifiers = function(base, modifier) {
1313
return _.startsWith(modifier, '-') ? `-${base}-${modifier.slice(1)}` : `${base}-${modifier}`;
1414
};
1515

16+
const flattenColorPalette = function(colors) {
17+
return _(colors)
18+
.flatMap((color, name) => {
19+
if (!_.isPlainObject(color)) {
20+
return [[name, color]];
21+
}
22+
return _.map(color, (value, key) => {
23+
const suffix = key === 'default' ? '' : `-${key}`;
24+
return [`${name}${suffix}`, value];
25+
});
26+
})
27+
.fromPairs()
28+
.value();
29+
};
30+
1631
const camelCaseToKebabCase = function(string) {
1732
return string
1833
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
@@ -46,6 +61,28 @@ module.exports = plugin.withOptions(function(options = {}) {
4661
})
4762
);
4863

64+
const textDecorationStyleUtilities = _.fromPairs(
65+
_.map(theme('textDecorationStyle'), (value, modifier) => {
66+
return [
67+
`.${e(`line-${modifier}`)}`,
68+
{
69+
textDecorationStyle: value,
70+
},
71+
];
72+
})
73+
);
74+
75+
const textDecorationColorUtilities = _.fromPairs(
76+
_.map(flattenColorPalette(theme('textDecorationColor')), (value, modifier) => {
77+
return [
78+
`.${e(`line-${modifier}`)}`,
79+
{
80+
textDecorationColor: value,
81+
},
82+
];
83+
})
84+
);
85+
4986
const ellipsisUtilities = options.ellipsis ? {
5087
'.ellipsis': {
5188
textOverflow: 'ellipsis',
@@ -190,6 +227,8 @@ module.exports = plugin.withOptions(function(options = {}) {
190227

191228
addUtilities(textIndentUtilities, variants('textIndent'));
192229
addUtilities(textShadowUtilities, variants('textShadow'));
230+
addUtilities(textDecorationStyleUtilities, variants('textDecorationStyle'));
231+
addUtilities(textDecorationColorUtilities, variants('textDecorationColor'));
193232
addUtilities(ellipsisUtilities, variants('ellipsis'));
194233
addUtilities(hyphensUtilities, variants('hyphens'));
195234
addUtilities(kerningUtilities, variants('kerning'));
@@ -205,6 +244,14 @@ module.exports = plugin.withOptions(function(options = {}) {
205244
theme: {
206245
textIndent: {},
207246
textShadow: {},
247+
textDecorationStyle: {
248+
'solid': 'solid',
249+
'double': 'double',
250+
'dotted': 'dotted',
251+
'dashed': 'dashed',
252+
'wavy': 'wavy',
253+
},
254+
textDecorationColor: theme => theme('colors'),
208255
fontVariantCaps: {
209256
'normal': 'normal',
210257
'small': 'small-caps',
@@ -247,6 +294,8 @@ module.exports = plugin.withOptions(function(options = {}) {
247294
variants: {
248295
textIndent: ['responsive'],
249296
textShadow: ['responsive'],
297+
textDecorationStyle: ['responsive'],
298+
textDecorationColor: ['responsive'],
250299
ellipsis: ['responsive'],
251300
hyphens: ['responsive'],
252301
kerning: ['responsive'],

0 commit comments

Comments
 (0)