From ad7b551e3e080d05375048b37547d58682fb852f Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Thu, 26 May 2022 19:24:11 -0400 Subject: [PATCH 1/3] Add future flag to preserve ring color opacity --- src/corePlugins.js | 21 ++-- src/featureFlags.js | 2 +- stubs/defaultConfig.stub.js | 2 +- tests/basic-usage.test.js | 234 ++++++++++++++++++++++++++++++++++++ 4 files changed, 250 insertions(+), 9 deletions(-) diff --git a/src/corePlugins.js b/src/corePlugins.js index c3f1f7c605d1..e1de2c595162 100644 --- a/src/corePlugins.js +++ b/src/corePlugins.js @@ -1977,13 +1977,20 @@ export let corePlugins = { ) }, - ringWidth: ({ matchUtilities, addDefaults, addUtilities, theme }) => { - let ringOpacityDefault = theme('ringOpacity.DEFAULT', '0.5') - let ringColorDefault = withAlphaValue( - theme('ringColor')?.DEFAULT, - ringOpacityDefault, - `rgb(147 197 253 / ${ringOpacityDefault})` - ) + ringWidth: ({ matchUtilities, addDefaults, addUtilities, theme, config }) => { + let ringColorDefault = (() => { + if (flagEnabled(config(), 'respectDefaultRingColorOpacity')) { + return theme('ringColor.DEFAULT') + } + + let ringOpacityDefault = theme('ringOpacity.DEFAULT', '0.5') + + return withAlphaValue( + theme('ringColor')?.DEFAULT, + ringOpacityDefault, + `rgb(147 197 253 / ${ringOpacityDefault})` + ) + })() addDefaults('ring-width', { '--tw-ring-inset': ' ', diff --git a/src/featureFlags.js b/src/featureFlags.js index 3b77958d17ae..bcca9bb0bc94 100644 --- a/src/featureFlags.js +++ b/src/featureFlags.js @@ -6,7 +6,7 @@ let defaults = { } let featureFlags = { - future: ['hoverOnlyWhenSupported'], + future: ['hoverOnlyWhenSupported', 'respectDefaultRingColorOpacity'], experimental: ['optimizeUniversalDefaults', 'variantGrouping'], } diff --git a/stubs/defaultConfig.stub.js b/stubs/defaultConfig.stub.js index cff789cb843f..d48237afabea 100644 --- a/stubs/defaultConfig.stub.js +++ b/stubs/defaultConfig.stub.js @@ -720,7 +720,7 @@ module.exports = { 8: '8px', }, ringColor: ({ theme }) => ({ - DEFAULT: theme('colors.blue.500', '#3b82f6'), + DEFAULT: theme(`colors.blue.500 / ${theme('ringOpacity.DEFAULT')}`, '#3b82f67f'), ...theme('colors'), }), ringOffsetColor: ({ theme }) => theme('colors'), diff --git a/tests/basic-usage.test.js b/tests/basic-usage.test.js index bad29b66f9b7..e42d1ec28a12 100644 --- a/tests/basic-usage.test.js +++ b/tests/basic-usage.test.js @@ -430,3 +430,237 @@ it('supports multiple backgrounds as arbitrary values even if only some are quot `) }) }) + +it('The "default" ring opacity is used by the default ring color when not using respectDefaultRingColorOpacity (1)', () => { + let config = { + content: [{ raw: html`
` }], + corePlugins: { preflight: false }, + } + + let input = css` + @tailwind base; + @tailwind utilities; + ` + + return run(input, config).then((result) => { + expect(result.css).toMatchFormattedCss(css` + ${defaults({ defaultRingColor: 'rgb(59 130 246 / 0.5)' })} + .ring { + --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) + var(--tw-ring-offset-color); + --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px + var(--tw-ring-offset-width)) + var(--tw-ring-color); + box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000); + } + `) + }) +}) + +it('The "default" ring opacity is used by the default ring color when not using respectDefaultRingColorOpacity (2)', () => { + let config = { + content: [{ raw: html`
` }], + corePlugins: { preflight: false }, + theme: { + ringOpacity: { + DEFAULT: 0.75, + }, + }, + } + + let input = css` + @tailwind base; + @tailwind utilities; + ` + + return run(input, config).then((result) => { + expect(result.css).toMatchFormattedCss(css` + ${defaults({ defaultRingColor: 'rgb(59 130 246 / 0.75)' })} + .ring { + --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) + var(--tw-ring-offset-color); + --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px + var(--tw-ring-offset-width)) + var(--tw-ring-color); + box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000); + } + `) + }) +}) + +it('Customizing the default ring color uses the "default" opacity when not using respectDefaultRingColorOpacity (1)', () => { + let config = { + content: [{ raw: html`
` }], + corePlugins: { preflight: false }, + theme: { + ringColor: { + DEFAULT: '#ff7f7f', + }, + }, + } + + let input = css` + @tailwind base; + @tailwind utilities; + ` + + return run(input, config).then((result) => { + expect(result.css).toMatchFormattedCss(css` + ${defaults({ defaultRingColor: 'rgb(255 127 127 / 0.5)' })} + .ring { + --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) + var(--tw-ring-offset-color); + --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px + var(--tw-ring-offset-width)) + var(--tw-ring-color); + box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000); + } + `) + }) +}) + +it('Customizing the default ring color uses the "default" opacity when not using respectDefaultRingColorOpacity (2)', () => { + let config = { + content: [{ raw: html`
` }], + corePlugins: { preflight: false }, + theme: { + ringColor: { + DEFAULT: '#ff7f7f00', + }, + }, + } + + let input = css` + @tailwind base; + @tailwind utilities; + ` + + return run(input, config).then((result) => { + expect(result.css).toMatchFormattedCss(css` + ${defaults({ defaultRingColor: 'rgb(255 127 127 / 0.5)' })} + .ring { + --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) + var(--tw-ring-offset-color); + --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px + var(--tw-ring-offset-width)) + var(--tw-ring-color); + box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000); + } + `) + }) +}) + +it('The "default" ring opacity is used by the default ring color when using respectDefaultRingColorOpacity (1)', () => { + let config = { + future: { respectDefaultRingColorOpacity: true }, + content: [{ raw: html`
` }], + corePlugins: { preflight: false }, + } + + let input = css` + @tailwind base; + @tailwind utilities; + ` + + return run(input, config).then((result) => { + expect(result.css).toMatchFormattedCss(css` + ${defaults({ defaultRingColor: 'rgb(59 130 246 / 0.5)' })} + .ring { + --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) + var(--tw-ring-offset-color); + --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px + var(--tw-ring-offset-width)) + var(--tw-ring-color); + box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000); + } + `) + }) +}) + +it('The "default" ring opacity is used by the default ring color when using respectDefaultRingColorOpacity (2)', () => { + let config = { + future: { respectDefaultRingColorOpacity: true }, + content: [{ raw: html`
` }], + corePlugins: { preflight: false }, + theme: { + ringOpacity: { + DEFAULT: 0.75, + }, + }, + } + + let input = css` + @tailwind base; + @tailwind utilities; + ` + + return run(input, config).then((result) => { + expect(result.css).toMatchFormattedCss(css` + ${defaults({ defaultRingColor: 'rgb(59 130 246 / 0.75)' })} + .ring { + --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) + var(--tw-ring-offset-color); + --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px + var(--tw-ring-offset-width)) + var(--tw-ring-color); + box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000); + } + `) + }) +}) + +it('Customizing the default ring color preserves its opacity when using respectDefaultRingColorOpacity (1)', () => { + let config = { + future: { respectDefaultRingColorOpacity: true }, + content: [{ raw: html`
` }], + corePlugins: { preflight: false }, + theme: { + ringColor: { + DEFAULT: '#ff7f7f', + }, + }, + } + + let input = css` + @tailwind base; + @tailwind utilities; + ` + + return run(input, config).then((result) => { + expect(result.css).toMatchFormattedCss(css` + ${defaults({ defaultRingColor: '#ff7f7f' })} + .ring { + --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) + var(--tw-ring-offset-color); + --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px + var(--tw-ring-offset-width)) + var(--tw-ring-color); + box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000); + } + `) + }) +}) + +it('Customizing the default ring color preserves its opacity when using respectDefaultRingColorOpacity (2)', () => { + let config = { + future: { respectDefaultRingColorOpacity: true }, + content: [{ raw: html`
` }], + corePlugins: { preflight: false }, + theme: { + ringColor: { + DEFAULT: '#ff7f7f00', + }, + }, + } + + let input = css` + @tailwind base; + @tailwind utilities; + ` + + return run(input, config).then((result) => { + expect(result.css).toMatchFormattedCss(css` + ${defaults({ defaultRingColor: '#ff7f7f00' })} + .ring { + --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) + var(--tw-ring-offset-color); + --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px + var(--tw-ring-offset-width)) + var(--tw-ring-color); + box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000); + } + `) + }) +}) From 8180c3cd4e74d31789ff7b78aca32b9c6327fc52 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Thu, 26 May 2022 19:37:07 -0400 Subject: [PATCH 2/3] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb797c11ca34..9352e829faa1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Experimental support for variant grouping ([#8405](https://github.com/tailwindlabs/tailwindcss/pull/8405)) - Add opacity support when referencing colors with `theme` function ([#8416](https://github.com/tailwindlabs/tailwindcss/pull/8416)) - Add `postcss-import` support to the CLI ([#8437](https://github.com/tailwindlabs/tailwindcss/pull/8437)) +- Add future flag to preserve custom, default ring color opacity ([#8448](https://github.com/tailwindlabs/tailwindcss/pull/8448)) ## [3.0.24] - 2022-04-12 From 16e4d274814de334ec7ff8383d76ebe7262ac00b Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Fri, 27 May 2022 09:37:10 -0400 Subject: [PATCH 3/3] Update --- src/util/getAllConfigs.js | 7 +++++++ stubs/defaultConfig.stub.js | 2 +- tests/basic-usage.test.js | 8 ++++---- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/util/getAllConfigs.js b/src/util/getAllConfigs.js index e35f1097c236..f8364540e5b2 100644 --- a/src/util/getAllConfigs.js +++ b/src/util/getAllConfigs.js @@ -9,6 +9,13 @@ export default function getAllConfigs(config) { const features = { // Add experimental configs here... + respectDefaultRingColorOpacity: { + theme: { + ringColor: { + DEFAULT: '#3b82f67f', + }, + }, + }, } const experimentals = Object.keys(features) diff --git a/stubs/defaultConfig.stub.js b/stubs/defaultConfig.stub.js index d48237afabea..7f29e4711c09 100644 --- a/stubs/defaultConfig.stub.js +++ b/stubs/defaultConfig.stub.js @@ -720,7 +720,7 @@ module.exports = { 8: '8px', }, ringColor: ({ theme }) => ({ - DEFAULT: theme(`colors.blue.500 / ${theme('ringOpacity.DEFAULT')}`, '#3b82f67f'), + DEFAULT: theme(`colors.blue.500`, '#3b82f6'), ...theme('colors'), }), ringOffsetColor: ({ theme }) => theme('colors'), diff --git a/tests/basic-usage.test.js b/tests/basic-usage.test.js index e42d1ec28a12..9f5c4c19be77 100644 --- a/tests/basic-usage.test.js +++ b/tests/basic-usage.test.js @@ -546,7 +546,7 @@ it('Customizing the default ring color uses the "default" opacity when not using }) }) -it('The "default" ring opacity is used by the default ring color when using respectDefaultRingColorOpacity (1)', () => { +it('The "default" ring color ignores the default opacity when using respectDefaultRingColorOpacity (1)', () => { let config = { future: { respectDefaultRingColorOpacity: true }, content: [{ raw: html`
` }], @@ -560,7 +560,7 @@ it('The "default" ring opacity is used by the default ring color when using resp return run(input, config).then((result) => { expect(result.css).toMatchFormattedCss(css` - ${defaults({ defaultRingColor: 'rgb(59 130 246 / 0.5)' })} + ${defaults({ defaultRingColor: '#3b82f67f' })} .ring { --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color); @@ -572,7 +572,7 @@ it('The "default" ring opacity is used by the default ring color when using resp }) }) -it('The "default" ring opacity is used by the default ring color when using respectDefaultRingColorOpacity (2)', () => { +it('The "default" ring color ignores the default opacity when using respectDefaultRingColorOpacity (2)', () => { let config = { future: { respectDefaultRingColorOpacity: true }, content: [{ raw: html`
` }], @@ -591,7 +591,7 @@ it('The "default" ring opacity is used by the default ring color when using resp return run(input, config).then((result) => { expect(result.css).toMatchFormattedCss(css` - ${defaults({ defaultRingColor: 'rgb(59 130 246 / 0.75)' })} + ${defaults({ defaultRingColor: '#3b82f67f' })} .ring { --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);