Skip to content

Commit f0ce096

Browse files
lukewarlowreininkadamwathan
authored
Add variant for ::file-selector-button pseudo element (#4936)
* Add variant for file-selector-button pseudo element * Rename `file-selector-button` variant to `file` Co-Authored-By: Adam Wathan <[email protected]> Co-authored-by: Jonathan Reinink <[email protected]> Co-authored-by: Adam Wathan <[email protected]>
1 parent a8836eb commit f0ce096

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/corePlugins.js

+9
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ export let pseudoElementVariants = ({ config, addVariant }) => {
7272
}),
7373
])
7474

75+
addVariant(
76+
'file',
77+
transformAllSelectors((selector) => {
78+
return updateAllClasses(selector, (className, { withPseudo }) => {
79+
return withPseudo(`file${config('separator')}${className}`, '::file-selector-button')
80+
})
81+
})
82+
)
83+
7584
addVariant(
7685
'before',
7786
transformAllSelectors(

tests/variants.test.css

+12
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@
5252
--tw-text-opacity: 1;
5353
color: rgb(255 255 255 / var(--tw-text-opacity));
5454
}
55+
.file\:bg-blue-500::file-selector-button {
56+
--tw-bg-opacity: 1;
57+
background-color: rgb(59 130 246 / var(--tw-bg-opacity));
58+
}
59+
.file\:text-white::file-selector-button {
60+
--tw-text-opacity: 1;
61+
color: rgb(255 255 255 / var(--tw-text-opacity));
62+
}
5563
.before\:block::before {
5664
content: '';
5765
display: block;
@@ -189,6 +197,10 @@
189197
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000),
190198
var(--tw-shadow);
191199
}
200+
.file\:hover\:bg-blue-600::file-selector-button:hover {
201+
--tw-bg-opacity: 1;
202+
background-color: rgb(37 99 235 / var(--tw-bg-opacity));
203+
}
192204
.focus\:shadow-md:focus {
193205
--tw-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -1px rgb(0 0 0 / 0.06);
194206
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000),

tests/variants.test.html

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<li class="marker:text-red-500 marker:text-lg"></li>
4646
</ul>
4747
<div class="selection:bg-blue-500 selection:text-white"></div>
48+
<div class="file:bg-blue-500 file:text-white"></div>
4849
<div class="before:block before:bg-red-500"></div>
4950
<div class="after:flex after:uppercase"></div>
5051

@@ -127,6 +128,7 @@
127128
<div class="2xl:shadow-md"></div>
128129

129130
<!-- Stacked variants -->
131+
<div class="file:hover:bg-blue-600"></div>
130132
<div class="focus:hover:shadow-md"></div>
131133
<div class="sm:active:shadow-md"></div>
132134
<div class="md:group-focus:shadow-md"></div>

0 commit comments

Comments
 (0)