Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

JIT: Add per-side border colors #4404

Merged
merged 1 commit into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 67 additions & 1 deletion src/plugins/borderColor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import flattenColorPalette from '../util/flattenColorPalette'
import withAlphaVariable from '../util/withAlphaVariable'

export default function () {
return function ({ addBase, matchUtilities, theme, variants, corePlugins }) {
return function ({ config, addBase, matchUtilities, theme, variants, corePlugins }) {
if (!corePlugins('borderOpacity')) {
addBase({
'*, ::before, ::after': {
Expand Down Expand Up @@ -41,5 +41,71 @@ export default function () {
type: 'color',
}
)

if (config('mode') === 'jit') {
matchUtilities(
{
'border-t': (value) => {
if (!corePlugins('borderOpacity')) {
return {
'border-top-color': value,
}
}

return withAlphaVariable({
color: value,
property: 'border-top-color',
variable: '--tw-border-opacity',
})
},
'border-r': (value) => {
if (!corePlugins('borderOpacity')) {
return {
'border-right-color': value,
}
}

return withAlphaVariable({
color: value,
property: 'border-right-color',
variable: '--tw-border-opacity',
})
},
'border-b': (value) => {
if (!corePlugins('borderOpacity')) {
return {
'border-bottom-color': value,
}
}

return withAlphaVariable({
color: value,
property: 'border-bottom-color',
variable: '--tw-border-opacity',
})
},
'border-l': (value) => {
if (!corePlugins('borderOpacity')) {
return {
'border-left-color': value,
}
}

return withAlphaVariable({
color: value,
property: 'border-left-color',
variable: '--tw-border-opacity',
})
},
},
{
values: (({ DEFAULT: _, ...colors }) => colors)(
flattenColorPalette(theme('borderColor'))
),
variants: variants('borderColor'),
type: 'color',
}
)
}
}
}
16 changes: 16 additions & 0 deletions tests/jit/basic-usage.test.css
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,22 @@
--tw-border-opacity: 1;
border-color: rgba(0, 0, 0, var(--tw-border-opacity));
}
.border-t-black {
--tw-border-opacity: 1;
border-top-color: rgba(0, 0, 0, var(--tw-border-opacity));
}
.border-r-black {
--tw-border-opacity: 1;
border-right-color: rgba(0, 0, 0, var(--tw-border-opacity));
}
.border-b-black {
--tw-border-opacity: 1;
border-bottom-color: rgba(0, 0, 0, var(--tw-border-opacity));
}
.border-l-black {
--tw-border-opacity: 1;
border-left-color: rgba(0, 0, 0, var(--tw-border-opacity));
}
.border-opacity-10 {
--tw-border-opacity: 0.1;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/jit/basic-usage.test.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<div class="bg-cover"></div>
<div class="bg-origin-border bg-origin-padding bg-origin-content"></div>
<div class="border-collapse"></div>
<div class="border-black"></div>
<div class="border-black border-t-black border-r-black border-b-black border-l-black"></div>
<div class="border-opacity-10"></div>
<div class="rounded-md"></div>
<div class="border-solid"></div>
Expand Down
3 changes: 3 additions & 0 deletions tests/jit/kitchen-sink.test.css
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,9 @@ div {
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000),
var(--tw-shadow);
}
.md\:hover\:border-r-blue-500\/30:hover {
border-right-color: rgba(59, 130, 246, 0.3);
}
.md\:hover\:opacity-20:hover {
opacity: 0.2;
}
Expand Down
1 change: 1 addition & 0 deletions tests/jit/kitchen-sink.test.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<div class="test-apply-font-variant"></div>
<div class="mt-6"></div>
<div class="bg-black"></div>
<div class="md:hover:border-r-blue-500/30"></div>
<div class="custom-util"></div>
<div class="hover:custom-util"></div>
<div class="group-hover:custom-util"></div>
Expand Down