Skip to content

Commit

Permalink
Add variant for ::file-selector-button pseudo element (#4936)
Browse files Browse the repository at this point in the history
* Add variant for file-selector-button pseudo element

* Rename `file-selector-button` variant to `file`

Co-Authored-By: Adam Wathan <4323180+adamwathan@users.noreply.github.com>

Co-authored-by: Jonathan Reinink <jonathan@reinink.ca>
Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
  • Loading branch information
3 people committed Sep 23, 2021
1 parent a8836eb commit f0ce096
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/corePlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ export let pseudoElementVariants = ({ config, addVariant }) => {
}),
])

addVariant(
'file',
transformAllSelectors((selector) => {
return updateAllClasses(selector, (className, { withPseudo }) => {
return withPseudo(`file${config('separator')}${className}`, '::file-selector-button')
})
})
)

addVariant(
'before',
transformAllSelectors(
Expand Down
12 changes: 12 additions & 0 deletions tests/variants.test.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@
--tw-text-opacity: 1;
color: rgb(255 255 255 / var(--tw-text-opacity));
}
.file\:bg-blue-500::file-selector-button {
--tw-bg-opacity: 1;
background-color: rgb(59 130 246 / var(--tw-bg-opacity));
}
.file\:text-white::file-selector-button {
--tw-text-opacity: 1;
color: rgb(255 255 255 / var(--tw-text-opacity));
}
.before\:block::before {
content: '';
display: block;
Expand Down Expand Up @@ -189,6 +197,10 @@
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000),
var(--tw-shadow);
}
.file\:hover\:bg-blue-600::file-selector-button:hover {
--tw-bg-opacity: 1;
background-color: rgb(37 99 235 / var(--tw-bg-opacity));
}
.focus\:shadow-md:focus {
--tw-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -1px rgb(0 0 0 / 0.06);
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000),
Expand Down
2 changes: 2 additions & 0 deletions tests/variants.test.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<li class="marker:text-red-500 marker:text-lg"></li>
</ul>
<div class="selection:bg-blue-500 selection:text-white"></div>
<div class="file:bg-blue-500 file:text-white"></div>
<div class="before:block before:bg-red-500"></div>
<div class="after:flex after:uppercase"></div>

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

<!-- Stacked variants -->
<div class="file:hover:bg-blue-600"></div>
<div class="focus:hover:shadow-md"></div>
<div class="sm:active:shadow-md"></div>
<div class="md:group-focus:shadow-md"></div>
Expand Down

0 comments on commit f0ce096

Please sign in to comment.