Skip to content

Commit d4fcd2e

Browse files
authored
Add new ring utilities for custom focus styles and rounded outlines (#2747)
* Add ring utilities * Remove redundant shadows, add 5% and 95% to opacity scale * Undo changes to build file * Update boxShadow.test.js
1 parent d39ecc5 commit d4fcd2e

14 files changed

+26960
-1856
lines changed

__tests__/fixtures/tailwind-output-flagged.css

Lines changed: 6912 additions & 462 deletions
Large diffs are not rendered by default.

__tests__/fixtures/tailwind-output-important.css

Lines changed: 6912 additions & 462 deletions
Large diffs are not rendered by default.

__tests__/fixtures/tailwind-output-no-color-opacity.css

Lines changed: 6048 additions & 462 deletions
Large diffs are not rendered by default.

__tests__/fixtures/tailwind-output.css

Lines changed: 6912 additions & 462 deletions
Large diffs are not rendered by default.

__tests__/plugins/boxShadow.test.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,20 @@ test('box shadow can use DEFAULT keyword and negative prefix syntax', () => {
4545
{
4646
utilities: {
4747
'.shadow': {
48-
'box-shadow': '0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06)',
48+
'--box-shadow': '0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06)',
49+
'box-shadow': 'var(--box-shadow)',
4950
},
5051
'.shadow-md': {
51-
'box-shadow': '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)',
52+
'--box-shadow': '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)',
53+
'box-shadow': 'var(--box-shadow)',
5254
},
5355
'.-shadow': {
54-
'box-shadow': 'inset 0 2px 4px 0 rgba(0, 0, 0, 0.06)',
56+
'--box-shadow': 'inset 0 2px 4px 0 rgba(0, 0, 0, 0.06)',
57+
'box-shadow': 'var(--box-shadow)',
5558
},
5659
'.-shadow-md': {
57-
'box-shadow': '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)',
60+
'--box-shadow': '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)',
61+
'box-shadow': 'var(--box-shadow)',
5862
},
5963
},
6064
variants: ['responsive'],

src/corePluginList.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ export const corePluginList = [
6969
'inset',
7070
'resize',
7171
'boxShadow',
72+
'ringWidth',
73+
'ringOffsetColor',
74+
'ringOffsetWidth',
75+
'ringColor',
76+
'ringOpacity',
7277
'fill',
7378
'stroke',
7479
'strokeWidth',

src/plugins/boxShadow.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ export default function () {
88
return [
99
nameClass('shadow', modifier),
1010
{
11-
'box-shadow': value,
11+
'--box-shadow': value,
12+
'box-shadow': 'var(--box-shadow)',
1213
},
1314
]
1415
})

src/plugins/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ export { default as pointerEvents } from './pointerEvents'
8585
export { default as position } from './position'
8686
export { default as preflight } from './preflight'
8787
export { default as resize } from './resize'
88+
export { default as ringColor } from './ringColor'
89+
export { default as ringOffsetColor } from './ringOffsetColor'
90+
export { default as ringOffsetWidth } from './ringOffsetWidth'
91+
export { default as ringOpacity } from './ringOpacity'
92+
export { default as ringWidth } from './ringWidth'
8893
export { default as rotate } from './rotate'
8994
export { default as scale } from './scale'
9095
export { default as skew } from './skew'

src/plugins/ringColor.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import _ from 'lodash'
2+
import flattenColorPalette from '../util/flattenColorPalette'
3+
import nameClass from '../util/nameClass'
4+
import { toRgba } from '../util/withAlphaVariable'
5+
6+
export default function () {
7+
return function ({ addUtilities, theme, variants }) {
8+
const colors = flattenColorPalette(theme('ringColor'))
9+
const utilities = _.fromPairs(
10+
_.map(_.omit(colors, 'DEFAULT'), (value, modifier) => {
11+
try {
12+
const [r, g, b, a] = toRgba(value)
13+
return [
14+
nameClass('ring', modifier),
15+
{
16+
'--ring-opacity': a === undefined ? '1' : a,
17+
'--ring-color': `rgba(${r}, ${g}, ${b}, var(--ring-opacity))`,
18+
},
19+
]
20+
} catch (_error) {
21+
return [
22+
nameClass('ring', modifier),
23+
{
24+
'--ring-color': value,
25+
},
26+
]
27+
}
28+
})
29+
)
30+
addUtilities(utilities, variants('ringColor'))
31+
}
32+
}

src/plugins/ringOffsetColor.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import _ from 'lodash'
2+
import flattenColorPalette from '../util/flattenColorPalette'
3+
import nameClass from '../util/nameClass'
4+
5+
export default function () {
6+
return function ({ addUtilities, theme, variants }) {
7+
const colors = flattenColorPalette(theme('ringOffsetColor'))
8+
const utilities = _.fromPairs(
9+
_.map(colors, (value, modifier) => {
10+
return [
11+
nameClass('ring-offset', modifier),
12+
{
13+
'--ring-offset-color': value,
14+
},
15+
]
16+
})
17+
)
18+
addUtilities(utilities, variants('ringOffsetColor'))
19+
}
20+
}

0 commit comments

Comments
 (0)