Skip to content

Commit b447cd6

Browse files
committed
Add divideWidth plugin
1 parent c84c397 commit b447cd6

File tree

6 files changed

+147
-0
lines changed

6 files changed

+147
-0
lines changed

__tests__/fixtures/tailwind-output-important.css

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,46 @@ video {
758758
margin-left: 1px !important;
759759
}
760760

761+
.divide-y-0 > * + * {
762+
border-top-width: 0 !important;
763+
}
764+
765+
.divide-x-0 > * + * {
766+
border-left-width: 0 !important;
767+
}
768+
769+
.divide-y-2 > * + * {
770+
border-top-width: 2px !important;
771+
}
772+
773+
.divide-x-2 > * + * {
774+
border-left-width: 2px !important;
775+
}
776+
777+
.divide-y-4 > * + * {
778+
border-top-width: 4px !important;
779+
}
780+
781+
.divide-x-4 > * + * {
782+
border-left-width: 4px !important;
783+
}
784+
785+
.divide-y-8 > * + * {
786+
border-top-width: 8px !important;
787+
}
788+
789+
.divide-x-8 > * + * {
790+
border-left-width: 8px !important;
791+
}
792+
793+
.divide-y > * + * {
794+
border-top-width: 1px !important;
795+
}
796+
797+
.divide-x > * + * {
798+
border-left-width: 1px !important;
799+
}
800+
761801
.sr-only {
762802
position: absolute !important;
763803
width: 1px !important;

__tests__/fixtures/tailwind-output.css

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,46 @@ video {
758758
margin-left: 1px;
759759
}
760760

761+
.divide-y-0 > * + * {
762+
border-top-width: 0;
763+
}
764+
765+
.divide-x-0 > * + * {
766+
border-left-width: 0;
767+
}
768+
769+
.divide-y-2 > * + * {
770+
border-top-width: 2px;
771+
}
772+
773+
.divide-x-2 > * + * {
774+
border-left-width: 2px;
775+
}
776+
777+
.divide-y-4 > * + * {
778+
border-top-width: 4px;
779+
}
780+
781+
.divide-x-4 > * + * {
782+
border-left-width: 4px;
783+
}
784+
785+
.divide-y-8 > * + * {
786+
border-top-width: 8px;
787+
}
788+
789+
.divide-x-8 > * + * {
790+
border-left-width: 8px;
791+
}
792+
793+
.divide-y > * + * {
794+
border-top-width: 1px;
795+
}
796+
797+
.divide-x > * + * {
798+
border-left-width: 1px;
799+
}
800+
761801
.sr-only {
762802
position: absolute;
763803
width: 1px;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import invokePlugin from '../util/invokePlugin'
2+
import plugin from '../../src/plugins/divideWidth'
3+
4+
test('generating divide width utilities', () => {
5+
const config = {
6+
theme: {
7+
divideWidth: {
8+
default: '1px',
9+
'2': '2px',
10+
'4': '4px',
11+
'8': '8px',
12+
},
13+
},
14+
variants: {
15+
divideWidth: ['responsive'],
16+
},
17+
}
18+
19+
const { utilities } = invokePlugin(plugin(), config)
20+
21+
expect(utilities).toEqual([
22+
[
23+
[
24+
{
25+
'.divide-y-2 > * + *': { 'border-top-width': '2px' },
26+
'.divide-x-2 > * + *': { 'border-left-width': '2px' },
27+
},
28+
{
29+
'.divide-y-4 > * + *': { 'border-top-width': '4px' },
30+
'.divide-x-4 > * + *': { 'border-left-width': '4px' },
31+
},
32+
{
33+
'.divide-y-8 > * + *': { 'border-top-width': '8px' },
34+
'.divide-x-8 > * + *': { 'border-left-width': '8px' },
35+
},
36+
{
37+
'.divide-y > * + *': { 'border-top-width': '1px' },
38+
'.divide-x > * + *': { 'border-left-width': '1px' },
39+
},
40+
],
41+
['responsive'],
42+
],
43+
])
44+
})

src/corePlugins.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import preflight from './plugins/preflight'
22
import container from './plugins/container'
33
import stack from './plugins/stack'
4+
import divideWidth from './plugins/divideWidth'
45
import accessibility from './plugins/accessibility'
56
import appearance from './plugins/appearance'
67
import backgroundAttachment from './plugins/backgroundAttachment'
@@ -98,6 +99,7 @@ export default function({ corePlugins: corePluginConfig }) {
9899
preflight,
99100
container,
100101
stack,
102+
divideWidth,
101103
accessibility,
102104
appearance,
103105
backgroundAttachment,

src/plugins/divideWidth.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import _ from 'lodash'
2+
3+
export default function() {
4+
return function({ addUtilities, e, theme, variants }) {
5+
const generators = [
6+
(value, modifier) => ({
7+
[`.${e(`divide-y${modifier}`)} > * + *`]: { 'border-top-width': `${value}` },
8+
[`.${e(`divide-x${modifier}`)} > * + *`]: { 'border-left-width': `${value}` },
9+
}),
10+
]
11+
12+
const utilities = _.flatMap(generators, generator => {
13+
return _.flatMap(theme('divideWidth'), (value, modifier) => {
14+
return generator(value, modifier === 'default' ? '' : `-${modifier}`)
15+
})
16+
})
17+
18+
addUtilities(utilities, variants('divideWidth'))
19+
}
20+
}

stubs/defaultConfig.stub.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ module.exports = {
206206
move: 'move',
207207
'not-allowed': 'not-allowed',
208208
},
209+
divideWidth: theme => theme('borderWidth'),
209210
fill: {
210211
current: 'currentColor',
211212
},

0 commit comments

Comments
 (0)