@@ -9,9 +9,25 @@ function resolveColor(color, opacityVariableName) {
9
9
return color . replace ( '<alpha-value>' , `var(${ opacityVariableName } , 1)` )
10
10
}
11
11
12
- const forms = plugin . withOptions ( function ( options = { strategy : undefined } ) {
12
+ /**
13
+ * @template T
14
+ * @param {boolean } bool
15
+ * @param {T } value
16
+ */
17
+ function maybe ( bool , value ) {
18
+ return bool ? value : undefined
19
+ }
20
+
21
+ function getEmptyRule ( ) {
22
+ return { base : [ ] , class : [ ] , styles : { } }
23
+ }
24
+
25
+ const forms = plugin . withOptions ( function (
26
+ options = { strategy : undefined , disableOutlines : undefined }
27
+ ) {
13
28
return function ( { addBase, addComponents, theme } ) {
14
29
const strategy = options . strategy === undefined ? [ 'base' , 'class' ] : [ options . strategy ]
30
+ const disableOutlines = options . disableOutlines === undefined ? false : options . disableOutlines
15
31
16
32
const rules = [
17
33
{
@@ -50,24 +66,25 @@ const forms = plugin.withOptions(function (options = { strategy: undefined }) {
50
66
'font-size' : baseFontSize ,
51
67
'line-height' : baseLineHeight ,
52
68
'--tw-shadow' : '0 0 #0000' ,
53
- '&:focus' : {
54
- outline : '2px solid transparent' ,
55
- 'outline-offset' : '2px' ,
56
- '--tw-ring-inset' : 'var(--tw-empty,/*!*/ /*!*/)' ,
57
- '--tw-ring-offset-width' : '0px' ,
58
- '--tw-ring-offset-color' : '#fff' ,
59
- '--tw-ring-color' : resolveColor (
60
- theme ( 'colors.blue.600' , colors . blue [ 600 ] ) ,
61
- '--tw-ring-opacity'
62
- ) ,
63
- '--tw-ring-offset-shadow' : `var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color)` ,
64
- '--tw-ring-shadow' : `var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color)` ,
65
- 'box-shadow' : `var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)` ,
66
- 'border-color' : resolveColor (
67
- theme ( 'colors.blue.600' , colors . blue [ 600 ] ) ,
68
- '--tw-border-opacity'
69
- ) ,
70
- } ,
69
+ '&:focus' :
70
+ maybe ( {
71
+ outline : '2px solid transparent' ,
72
+ 'outline-offset' : '2px' ,
73
+ '--tw-ring-inset' : 'var(--tw-empty,/*!*/ /*!*/)' ,
74
+ '--tw-ring-offset-width' : '0px' ,
75
+ '--tw-ring-offset-color' : '#fff' ,
76
+ '--tw-ring-color' : resolveColor (
77
+ theme ( 'colors.blue.600' , colors . blue [ 600 ] ) ,
78
+ '--tw-ring-opacity'
79
+ ) ,
80
+ '--tw-ring-offset-shadow' : `var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color)` ,
81
+ '--tw-ring-shadow' : `var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color)` ,
82
+ 'box-shadow' : `var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)` ,
83
+ 'border-color' : resolveColor (
84
+ theme ( 'colors.blue.600' , colors . blue [ 600 ] ) ,
85
+ '--tw-border-opacity'
86
+ ) ,
87
+ } ) || { } ,
71
88
} ,
72
89
} ,
73
90
{
@@ -215,7 +232,7 @@ const forms = plugin.withOptions(function (options = { strategy: undefined }) {
215
232
'border-radius' : '100%' ,
216
233
} ,
217
234
} ,
218
- {
235
+ maybe ( ! disableOutlines , {
219
236
base : [ `[type='checkbox']:focus` , `[type='radio']:focus` ] ,
220
237
class : [ '.form-checkbox:focus' , '.form-radio:focus' ] ,
221
238
styles : {
@@ -232,7 +249,7 @@ const forms = plugin.withOptions(function (options = { strategy: undefined }) {
232
249
'--tw-ring-shadow' : `var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color)` ,
233
250
'box-shadow' : `var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)` ,
234
251
} ,
235
- } ,
252
+ } ) || getEmptyRule ( ) ,
236
253
{
237
254
base : [ `[type='checkbox']:checked` , `[type='radio']:checked` ] ,
238
255
class : [ '.form-checkbox:checked' , '.form-radio:checked' ] ,
@@ -315,13 +332,13 @@ const forms = plugin.withOptions(function (options = { strategy: undefined }) {
315
332
'line-height' : 'inherit' ,
316
333
} ,
317
334
} ,
318
- {
335
+ maybe ( ! disableOutlines , {
319
336
base : [ `[type='file']:focus` ] ,
320
337
class : null ,
321
338
styles : {
322
339
outline : [ `1px solid ButtonText` , `1px auto -webkit-focus-ring-color` ] ,
323
340
} ,
324
- } ,
341
+ } ) || getEmptyRule ( ) ,
325
342
]
326
343
327
344
const getStrategyRules = ( strategy ) =>
0 commit comments