Skip to content

Commit d1ef88a

Browse files
authored
ring defaults (#2951)
* add ring defaults Fixes #2911 * add tests for the ringWidth utility + defaults * update changelog
1 parent d41ec71 commit d1ef88a

File tree

5 files changed

+112
-4
lines changed

5 files changed

+112
-4
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Fix issue with `@apply` not working as expected with `!important` inside an atrule ([#2824](https://github.com/tailwindlabs/tailwindcss/pull/2824))
1313
- Fix issue with `@apply` not working as expected with defined classes ([#2832](https://github.com/tailwindlabs/tailwindcss/pull/2832))
1414

15+
### Added
16+
17+
- Add default values for the `ring` utility ([#2951](https://github.com/tailwindlabs/tailwindcss/pull/2951))
18+
1519
## [2.0.1] - 2020-11-18
1620

1721
- Nothing, just the only thing I could do when I found out npm won't let me publish the same version under two tags.

__tests__/plugins/ringWidth.test.js

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import invokePlugin from '../util/invokePlugin'
2+
import plugin from '../../src/plugins/ringWidth'
3+
4+
test('ring widths', () => {
5+
const config = {
6+
theme: {
7+
ringWidth: {
8+
4: '4px',
9+
},
10+
ringOffsetWidth: {
11+
4: '4px',
12+
},
13+
ringColor: {
14+
black: '#000',
15+
},
16+
ringOffsetColor: {
17+
white: '#fff',
18+
},
19+
ringOpacity: {
20+
50: '.5',
21+
},
22+
},
23+
variants: {
24+
ringColor: [],
25+
},
26+
}
27+
28+
const { utilities } = invokePlugin(plugin(), config)
29+
expect(utilities).toEqual([
30+
[
31+
{
32+
'*': {
33+
'--tw-ring-color': 'rgba(147, 197, 253, 0.5)',
34+
'--tw-ring-inset': 'var(--tw-empty,/*!*/ /*!*/)',
35+
'--tw-ring-offset-color': '#fff',
36+
'--tw-ring-offset-shadow': '0 0 #0000',
37+
'--tw-ring-offset-width': '0px',
38+
'--tw-ring-shadow': '0 0 #0000',
39+
},
40+
},
41+
{
42+
respectImportant: false,
43+
},
44+
],
45+
[
46+
{
47+
'.ring-4': {
48+
'--tw-ring-offset-shadow':
49+
'var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color)',
50+
'--tw-ring-shadow':
51+
'var(--tw-ring-inset) 0 0 0 calc(4px + var(--tw-ring-offset-width)) var(--tw-ring-color)',
52+
'box-shadow':
53+
'var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000)',
54+
},
55+
'.ring-inset': {
56+
'--tw-ring-inset': 'inset',
57+
},
58+
},
59+
undefined,
60+
],
61+
])
62+
})
63+
64+
test('ring widths with defaults', () => {
65+
const config = {
66+
theme: {
67+
ringWidth: {},
68+
ringOffsetWidth: {
69+
DEFAULT: '2px',
70+
},
71+
ringOffsetColor: {
72+
DEFAULT: 'pink',
73+
},
74+
},
75+
variants: {
76+
ringColor: [],
77+
},
78+
}
79+
80+
const { utilities } = invokePlugin(plugin(), config)
81+
expect(utilities).toEqual([
82+
[
83+
{
84+
'*': {
85+
'--tw-ring-color': 'rgba(147, 197, 253, 0.5)',
86+
'--tw-ring-inset': 'var(--tw-empty,/*!*/ /*!*/)',
87+
'--tw-ring-offset-color': 'pink',
88+
'--tw-ring-offset-shadow': '0 0 #0000',
89+
'--tw-ring-offset-width': '2px',
90+
'--tw-ring-shadow': '0 0 #0000',
91+
},
92+
},
93+
{ respectImportant: false },
94+
],
95+
[
96+
{
97+
'.ring-inset': {
98+
'--tw-ring-inset': 'inset',
99+
},
100+
},
101+
undefined,
102+
],
103+
])
104+
})

src/plugins/ringOffsetColor.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default function () {
77
return function ({ addUtilities, theme, variants }) {
88
const colors = flattenColorPalette(theme('ringOffsetColor'))
99
const utilities = _.fromPairs(
10-
_.map(colors, (value, modifier) => {
10+
_.map(_.omit(colors, 'DEFAULT'), (value, modifier) => {
1111
return [
1212
nameClass('ring-offset', modifier),
1313
{

src/plugins/ringOffsetWidth.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import nameClass from '../util/nameClass'
44
export default function () {
55
return function ({ addUtilities, theme, variants }) {
66
const utilities = _.fromPairs(
7-
_.map(theme('ringOffsetWidth'), (value, modifier) => {
7+
_.map(_.omit(theme('ringOffsetWidth'), 'DEFAULT'), (value, modifier) => {
88
return [
99
nameClass('ring-offset', modifier),
1010
{

src/plugins/ringWidth.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export default function () {
2020
{
2121
'*': {
2222
'--tw-ring-inset': 'var(--tw-empty,/*!*/ /*!*/)',
23-
'--tw-ring-offset-width': '0px',
24-
'--tw-ring-offset-color': '#fff',
23+
'--tw-ring-offset-width': theme('ringOffsetWidth.DEFAULT', '0px'),
24+
'--tw-ring-offset-color': theme('ringOffsetColor.DEFAULT', '#fff'),
2525
'--tw-ring-color': ringColorDefault,
2626
'--tw-ring-offset-shadow': '0 0 #0000',
2727
'--tw-ring-shadow': '0 0 #0000',

0 commit comments

Comments
 (0)