Skip to content

Commit d72b277

Browse files
Allow default ring color to be a function (#7587)
* Allow default ring color to be a function * Update changelog
1 parent 3b8ca9d commit d72b277

File tree

3 files changed

+99
-1
lines changed

3 files changed

+99
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
- Prevent nesting plugin from breaking other plugins ([#7563](https://github.com/tailwindlabs/tailwindcss/pull/7563))
1111
- Recursively collapse adjacent rules ([#7565](https://github.com/tailwindlabs/tailwindcss/pull/7565))
12+
- Allow default ring color to be a function ([#7587](https://github.com/tailwindlabs/tailwindcss/pull/7587))
1213

1314
## [3.0.23] - 2022-02-16
1415

src/corePlugins.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1925,7 +1925,7 @@ export let corePlugins = {
19251925
ringWidth: ({ matchUtilities, addDefaults, addUtilities, theme }) => {
19261926
let ringOpacityDefault = theme('ringOpacity.DEFAULT', '0.5')
19271927
let ringColorDefault = withAlphaValue(
1928-
theme('ringColor.DEFAULT'),
1928+
theme('ringColor')?.DEFAULT,
19291929
ringOpacityDefault,
19301930
`rgb(147 197 253 / ${ringOpacityDefault})`
19311931
)

tests/basic-usage.test.js

+97
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,103 @@ test('per-plugin colors with the same key can differ when using a custom colors
110110
})
111111
})
112112

113+
test('default ring color can be a function', () => {
114+
function color(variable) {
115+
return function ({ opacityVariable, opacityValue }) {
116+
if (opacityValue !== undefined) {
117+
return `rgba(${variable}, ${opacityValue})`
118+
}
119+
if (opacityVariable !== undefined) {
120+
return `rgba(${variable}, var(${opacityVariable}, 1))`
121+
}
122+
return `rgb(${variable})`
123+
}
124+
}
125+
126+
let config = {
127+
content: [
128+
{
129+
raw: html` <div class="ring"></div> `,
130+
},
131+
],
132+
133+
theme: {
134+
extend: {
135+
ringColor: {
136+
DEFAULT: color('var(--red)'),
137+
},
138+
},
139+
},
140+
plugins: [],
141+
corePlugins: { preflight: false },
142+
}
143+
144+
let input = css`
145+
@tailwind base;
146+
@tailwind components;
147+
@tailwind utilities;
148+
`
149+
150+
return run(input, config).then((result) => {
151+
expect(result.css).toMatchFormattedCss(css`
152+
*,
153+
::before,
154+
::after {
155+
--tw-translate-x: 0;
156+
--tw-translate-y: 0;
157+
--tw-rotate: 0;
158+
--tw-skew-x: 0;
159+
--tw-skew-y: 0;
160+
--tw-scale-x: 1;
161+
--tw-scale-y: 1;
162+
--tw-pan-x: ;
163+
--tw-pan-y: ;
164+
--tw-pinch-zoom: ;
165+
--tw-scroll-snap-strictness: proximity;
166+
--tw-ordinal: ;
167+
--tw-slashed-zero: ;
168+
--tw-numeric-figure: ;
169+
--tw-numeric-spacing: ;
170+
--tw-numeric-fraction: ;
171+
--tw-ring-inset: ;
172+
--tw-ring-offset-width: 0px;
173+
--tw-ring-offset-color: #fff;
174+
--tw-ring-color: rgba(var(--red), 0.5);
175+
--tw-ring-offset-shadow: 0 0 #0000;
176+
--tw-ring-shadow: 0 0 #0000;
177+
--tw-shadow: 0 0 #0000;
178+
--tw-shadow-colored: 0 0 #0000;
179+
--tw-blur: ;
180+
--tw-brightness: ;
181+
--tw-contrast: ;
182+
--tw-grayscale: ;
183+
--tw-hue-rotate: ;
184+
--tw-invert: ;
185+
--tw-saturate: ;
186+
--tw-sepia: ;
187+
--tw-drop-shadow: ;
188+
--tw-backdrop-blur: ;
189+
--tw-backdrop-brightness: ;
190+
--tw-backdrop-contrast: ;
191+
--tw-backdrop-grayscale: ;
192+
--tw-backdrop-hue-rotate: ;
193+
--tw-backdrop-invert: ;
194+
--tw-backdrop-opacity: ;
195+
--tw-backdrop-saturate: ;
196+
--tw-backdrop-sepia: ;
197+
}
198+
199+
.ring {
200+
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width)
201+
var(--tw-ring-offset-color);
202+
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px + var(--tw-ring-offset-width))
203+
var(--tw-ring-color);
204+
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
205+
}
206+
`)
207+
})
208+
})
209+
113210
it('fasly config values still work', () => {
114211
let config = {
115212
content: [{ raw: html`<div class="inset-0"></div>` }],

0 commit comments

Comments
 (0)