Skip to content

Commit beac54c

Browse files
committed
Add support for paintOrder
1 parent 2e4713f commit beac54c

File tree

3 files changed

+51
-6
lines changed

3 files changed

+51
-6
lines changed

index.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,29 @@ module.exports = function () {
1414
const buildObjectFromTheme = (themeKey, ...fallbackKeys) => {
1515
const buildObject = ([ modifier, value ]) => [ modifier, { [themeKey]: value } ]
1616
const getThemeSettings = (themeKey, fallbackKeys) => {
17-
return theme(themeKey, false) || getThemeSettings([themeKey, ...fallbackKeys] = fallbackKeys)
17+
return theme(themeKey, false) || (fallbackKeys && getThemeSettings([themeKey, ...fallbackKeys] = fallbackKeys))
1818
}
19-
const themeEntries = Object
20-
.entries(flatten(getThemeSettings(themeKey, fallbackKeys), FLATTEN_CONFIG))
19+
20+
const themeSettings = getThemeSettings(themeKey, fallbackKeys)
21+
const themeEntries = themeSettings && Object
22+
.entries(flatten(themeSettings, FLATTEN_CONFIG))
2123
.map(entry => buildObject(entry))
2224

23-
return _.fromPairs(themeEntries)
25+
return themeSettings ? _.fromPairs(themeEntries) : false
2426
}
2527

2628
const pluginUtilities = {
2729
textFillColor: buildObjectFromTheme('textFillColor', 'borderColor'),
2830
textStrokeColor: buildObjectFromTheme('textStrokeColor', 'borderColor'),
2931
textStrokeWidth: buildObjectFromTheme('textStrokeWidth', 'borderWidth'),
30-
// paintOrder: 'https://developer.mozilla.org/en-US/docs/Web/CSS/paint-order',
32+
paintOrder: buildObjectFromTheme('paintOrder') || {
33+
'fsm': { paintOrder: 'fill, stroke, markers' },
34+
'fms': { paintOrder: 'fill, markers, stroke' },
35+
'sfm': { paintOrder: 'stroke, fill, markers' },
36+
'smf': { paintOrder: 'stroke, markers, fill' },
37+
'mfs': { paintOrder: 'markers, fill, stroke' },
38+
'msf': { paintOrder: 'markers, stroke, fill' },
39+
},
3140
}
3241

3342
Object.entries(pluginUtilities)

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Tailwind CSS Text Indent Plugin
22

3-
This plugin adds utilities to use `text-fill` and `text-stroke` with Tailwind CSS.
3+
This plugin adds utilities to use `text-fill`, `text-stroke` and `paint-order` with Tailwind CSS.
44

55
## Installation
66

test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ test('generates default utilities and responsive variants', () => {
7777
.text-stroke-8 { text-stroke-width: 8px }
7878
.text-stroke { text-stroke-width: 1px }
7979
80+
.paint-fsm { paint-order: fill, stroke, markers }
81+
.paint-fms { paint-order: fill, markers, stroke }
82+
.paint-sfm { paint-order: stroke, fill, markers }
83+
.paint-smf { paint-order: stroke, markers, fill }
84+
.paint-mfs { paint-order: markers, fill, stroke }
85+
.paint-msf { paint-order: markers, stroke, fill }
86+
8087
@media (min-width: 640px) {
8188
.sm\\:text-fill-transparent { text-fill-color: transparent }
8289
.sm\\:text-fill-black { text-fill-color: #000 }
@@ -111,6 +118,13 @@ test('generates default utilities and responsive variants', () => {
111118
.sm\\:text-stroke-4 { text-stroke-width: 4px }
112119
.sm\\:text-stroke-8 { text-stroke-width: 8px }
113120
.sm\\:text-stroke { text-stroke-width: 1px }
121+
122+
.sm\\:paint-fsm { paint-order: fill, stroke, markers }
123+
.sm\\:paint-fms { paint-order: fill, markers, stroke }
124+
.sm\\:paint-sfm { paint-order: stroke, fill, markers }
125+
.sm\\:paint-smf { paint-order: stroke, markers, fill }
126+
.sm\\:paint-mfs { paint-order: markers, fill, stroke }
127+
.sm\\:paint-msf { paint-order: markers, stroke, fill }
114128
}
115129
`
116130

@@ -123,6 +137,7 @@ test('variants can be customized', () => {
123137
textFillColor: ['hover'],
124138
textStrokeColor: ['focus'],
125139
textStrokeWidth: ['active'],
140+
paintOrder: ['responsive'],
126141
},
127142
}
128143
const expectedCss = `
@@ -193,6 +208,22 @@ test('variants can be customized', () => {
193208
.active\\:text-stroke-4:active { text-stroke-width: 4px }
194209
.active\\:text-stroke-8:active { text-stroke-width: 8px }
195210
.active\\:text-stroke:active { text-stroke-width: 1px }
211+
212+
.paint-fsm { paint-order: fill, stroke, markers }
213+
.paint-fms { paint-order: fill, markers, stroke }
214+
.paint-sfm { paint-order: stroke, fill, markers }
215+
.paint-smf { paint-order: stroke, markers, fill }
216+
.paint-mfs { paint-order: markers, fill, stroke }
217+
.paint-msf { paint-order: markers, stroke, fill }
218+
219+
@media (min-width: 640px) {
220+
.sm\\:paint-fsm { paint-order: fill, stroke, markers }
221+
.sm\\:paint-fms { paint-order: fill, markers, stroke }
222+
.sm\\:paint-sfm { paint-order: stroke, fill, markers }
223+
.sm\\:paint-smf { paint-order: stroke, markers, fill }
224+
.sm\\:paint-mfs { paint-order: markers, fill, stroke }
225+
.sm\\:paint-msf { paint-order: markers, stroke, fill }
226+
}
196227
`
197228

198229
return generatePluginCss(testConfig).then(css => expect(css).toMatchCss(expectedCss))
@@ -204,6 +235,7 @@ test('utilities can be customized', () => {
204235
textFillColor: theme => ({ ...theme('colors'), gray: theme('colors.gray.500'), default: '#38b2ac' }),
205236
textStrokeColor: theme => ({ transparent: theme('colors.transparent'), default: '#38b2ac' }),
206237
textStrokeWidth: { default: '1px', sm: '2px', md: '4px', lg: '8px' },
238+
paintOrder: { stroke: 'stroke' }
207239
},
208240
}
209241
const expectedCss = `
@@ -221,6 +253,8 @@ test('utilities can be customized', () => {
221253
.text-stroke-md { text-stroke-width: 4px }
222254
.text-stroke-lg { text-stroke-width: 8px }
223255
256+
.paint-stroke { paint-order: stroke }
257+
224258
@media (min-width: 640px) {
225259
.sm\\:text-fill-transparent { text-fill-color: transparent }
226260
.sm\\:text-fill-black { text-fill-color: #000 }
@@ -235,6 +269,8 @@ test('utilities can be customized', () => {
235269
.sm\\:text-stroke-sm { text-stroke-width: 2px }
236270
.sm\\:text-stroke-md { text-stroke-width: 4px }
237271
.sm\\:text-stroke-lg { text-stroke-width: 8px }
272+
273+
.sm\\:paint-stroke { paint-order: stroke }
238274
}
239275
`
240276

0 commit comments

Comments
 (0)