Skip to content

Commit 615a228

Browse files
authored
manually resolve the opacity variable (#132)
1 parent b3ed157 commit 615a228

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

src/index.js

+29-10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ const colors = require('tailwindcss/colors')
55
const [baseFontSize, { lineHeight: baseLineHeight }] = defaultTheme.fontSize.base
66
const { spacing, borderWidth, borderRadius } = defaultTheme
77

8+
function resolveColor(color, opacityVariableName) {
9+
return color.replace('<alpha-value>', `var(${opacityVariableName}, 1)`)
10+
}
11+
812
const forms = plugin.withOptions(function (options = { strategy: undefined }) {
913
return function ({ addBase, addComponents, theme }) {
1014
const strategy = options.strategy === undefined ? ['base', 'class'] : [options.strategy]
@@ -32,7 +36,10 @@ const forms = plugin.withOptions(function (options = { strategy: undefined }) {
3236
styles: {
3337
appearance: 'none',
3438
'background-color': '#fff',
35-
'border-color': theme('colors.gray.500', colors.gray[500]),
39+
'border-color': resolveColor(
40+
theme('colors.gray.500', colors.gray[500]),
41+
'--tw-border-opacity'
42+
),
3643
'border-width': borderWidth['DEFAULT'],
3744
'border-radius': borderRadius.none,
3845
'padding-top': spacing[2],
@@ -48,19 +55,25 @@ const forms = plugin.withOptions(function (options = { strategy: undefined }) {
4855
'--tw-ring-inset': 'var(--tw-empty,/*!*/ /*!*/)',
4956
'--tw-ring-offset-width': '0px',
5057
'--tw-ring-offset-color': '#fff',
51-
'--tw-ring-color': theme('colors.blue.600', colors.blue[600]),
58+
'--tw-ring-color': resolveColor(
59+
theme('colors.blue.600', colors.blue[600]),
60+
'--tw-ring-opacity'
61+
),
5262
'--tw-ring-offset-shadow': `var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color)`,
5363
'--tw-ring-shadow': `var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color)`,
5464
'box-shadow': `var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)`,
55-
'border-color': theme('colors.blue.600', colors.blue[600]),
65+
'border-color': resolveColor(
66+
theme('colors.blue.600', colors.blue[600]),
67+
'--tw-border-opacity'
68+
),
5669
},
5770
},
5871
},
5972
{
6073
base: ['input::placeholder', 'textarea::placeholder'],
6174
class: ['.form-input::placeholder', '.form-textarea::placeholder'],
6275
styles: {
63-
color: theme('colors.gray.500', colors.gray[500]),
76+
color: resolveColor(theme('colors.gray.500', colors.gray[500]), '--tw-text-opacity'),
6477
opacity: '1',
6578
},
6679
},
@@ -117,9 +130,9 @@ const forms = plugin.withOptions(function (options = { strategy: undefined }) {
117130
class: ['.form-select'],
118131
styles: {
119132
'background-image': `url("${svgToDataUri(
120-
`<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 20 20"><path stroke="${theme(
121-
'colors.gray.500',
122-
colors.gray[500]
133+
`<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 20 20"><path stroke="${resolveColor(
134+
theme('colors.gray.500', colors.gray[500]),
135+
'--tw-stroke-opacity'
123136
)}" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M6 8l4 4 4-4"/></svg>`
124137
)}")`,
125138
'background-position': `right ${spacing[2]} center`,
@@ -155,9 +168,12 @@ const forms = plugin.withOptions(function (options = { strategy: undefined }) {
155168
'flex-shrink': '0',
156169
height: spacing[4],
157170
width: spacing[4],
158-
color: theme('colors.blue.600', colors.blue[600]),
171+
color: resolveColor(theme('colors.blue.600', colors.blue[600]), '--tw-text-opacity'),
159172
'background-color': '#fff',
160-
'border-color': theme('colors.gray.500', colors.gray[500]),
173+
'border-color': resolveColor(
174+
theme('colors.gray.500', colors.gray[500]),
175+
'--tw-border-opacity'
176+
),
161177
'border-width': borderWidth['DEFAULT'],
162178
'--tw-shadow': '0 0 #0000',
163179
},
@@ -185,7 +201,10 @@ const forms = plugin.withOptions(function (options = { strategy: undefined }) {
185201
'--tw-ring-inset': 'var(--tw-empty,/*!*/ /*!*/)',
186202
'--tw-ring-offset-width': '2px',
187203
'--tw-ring-offset-color': '#fff',
188-
'--tw-ring-color': theme('colors.blue.600', colors.blue[600]),
204+
'--tw-ring-color': resolveColor(
205+
theme('colors.blue.600', colors.blue[600]),
206+
'--tw-ring-opacity'
207+
),
189208
'--tw-ring-offset-shadow': `var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color)`,
190209
'--tw-ring-shadow': `var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color)`,
191210
'box-shadow': `var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)`,

0 commit comments

Comments
 (0)