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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new outline style, color, width and offset utilities #5887

Merged
merged 6 commits into from
Oct 27, 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
31 changes: 25 additions & 6 deletions src/corePlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -1790,17 +1790,36 @@ export let corePlugins = {
}
})(),

outline: ({ matchUtilities, theme }) => {
outlineStyle: ({ addUtilities }) => {
addUtilities({
'.outline-none': {
outline: '2px solid transparent',
'outline-offset': '2px',
},
'.outline': { 'outline-style': 'solid' },
'.outline-dashed': { 'outline-style': 'dashed' },
'.outline-dotted': { 'outline-style': 'dotted' },
'.outline-double': { 'outline-style': 'double' },
'.outline-hidden': { 'outline-style': 'hidden' },
})
},

outlineWidth: createUtilityPlugin('outlineWidth', [['outline', ['outline-width']]], {
type: ['length', 'number', 'percentage'],
}),

outlineOffset: createUtilityPlugin('outlineOffset', [['outline-offset', ['outline-offset']]], {
type: ['length', 'number', 'percentage'],
}),

outlineColor: ({ matchUtilities, theme }) => {
matchUtilities(
{
outline: (value) => {
value = Array.isArray(value) ? value : value.split(',')
let [outline, outlineOffset = '0'] = Array.isArray(value) ? value : [value]

return { outline, 'outline-offset': outlineOffset }
return { 'outline-color': toColorValue(value) }
},
},
{ values: theme('outline') }
{ values: flattenColorPalette(theme('outlineColor')), type: ['color'] }
)
},

Expand Down
20 changes: 15 additions & 5 deletions stubs/defaultConfig.stub.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,14 +697,24 @@ module.exports = {
11: '11',
12: '12',
},
outline: {
none: ['2px solid transparent', '2px'],
white: ['2px dotted white', '2px'],
black: ['2px dotted black', '2px'],
},
padding: ({ theme }) => theme('spacing'),
placeholderColor: ({ theme }) => theme('colors'),
placeholderOpacity: ({ theme }) => theme('opacity'),
outlineColor: ({ theme }) => theme('colors'),
outlineOffset: {
0: '0px',
1: '1px',
2: '2px',
4: '4px',
8: '8px',
},
outlineWidth: {
0: '0px',
1: '1px',
2: '2px',
4: '4px',
8: '8px',
},
ringColor: ({ theme }) => ({
DEFAULT: theme('colors.blue.500', '#3b82f6'),
...theme('colors'),
Expand Down
25 changes: 10 additions & 15 deletions tests/arbitrary-values.test.css
Original file line number Diff line number Diff line change
Expand Up @@ -859,25 +859,20 @@
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000),
var(--tw-shadow);
}
.outline-\[2px_solid_black\] {
outline: 2px solid black;
outline-offset: 0;
.outline-\[10px\] {
outline-width: 10px;
}
.outline-\[2px_solid_black\2c 2px\] {
outline: 2px solid black;
outline-offset: 2px;
.outline-\[length\:var\(--outline\)\] {
outline-width: var(--outline);
}
.outline-\[var\(--outline\)\] {
outline: var(--outline);
outline-offset: 0;
.outline-offset-\[10px\] {
outline-offset: 10px;
}
.outline-\[var\(--outline\)\2c 3px\] {
outline: var(--outline);
outline-offset: 3px;
.outline-\[black\] {
outline-color: black;
}
.outline-\[2px_solid_black\2c var\(--outline-offset\)\] {
outline: 2px solid black;
outline-offset: var(--outline-offset);
.outline-\[color\:var\(--outline\)\] {
outline-color: var(--outline);
}
.ring-\[10px\] {
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width)
Expand Down
10 changes: 5 additions & 5 deletions tests/arbitrary-values.test.html
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,11 @@
<div class="shadow-[0px_1px_2px_black]"></div>
<div class="shadow-[var(--value)]"></div>

<div class="outline-[2px_solid_black]"></div>
<div class="outline-[2px_solid_black,2px]"></div>
<div class="outline-[var(--outline)]"></div>
<div class="outline-[var(--outline),3px]"></div>
<div class="outline-[2px_solid_black,var(--outline-offset)]"></div>
<div class="outline-[black]"></div>
<div class="outline-[10px]"></div>
<div class="outline-[color:var(--outline)]"></div>
<div class="outline-[length:var(--outline)]"></div>
<div class="outline-offset-[10px]"></div>

<div class="ring-[#76ad65]"></div>
<div class="ring-[color:var(--value)]"></div>
Expand Down
15 changes: 13 additions & 2 deletions tests/basic-usage.test.css
Original file line number Diff line number Diff line change
Expand Up @@ -825,10 +825,21 @@
outline: 2px solid transparent;
outline-offset: 2px;
}
.outline-black {
outline: 2px dotted black;
.outline {
outline-style: solid;
}
.outline-dashed {
outline-style: dashed;
}
.outline-4 {
outline-width: 4px;
}
.outline-offset-2 {
outline-offset: 2px;
}
.outline-black {
outline-color: #000;
}
.ring {
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width)
var(--tw-ring-offset-color);
Expand Down
2 changes: 1 addition & 1 deletion tests/basic-usage.test.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
<div class="bg-blend-darken bg-blend-difference"></div>
<div class="mix-blend-multiply mix-blend-saturation"></div>
<div class="order-last order-2"></div>
<div class="outline-none outline-black"></div>
<div class="outline outline-dashed outline-none outline-black outline-4 outline-offset-2"></div>
<div class="overflow-hidden"></div>
<div class="overscroll-contain"></div>
<div class="p-4 py-2 px-3 pt-1 pr-2 pb-3 pl-4"></div>
Expand Down
8 changes: 0 additions & 8 deletions tests/raw-content.test.css
Original file line number Diff line number Diff line change
Expand Up @@ -595,14 +595,6 @@
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000),
var(--tw-shadow);
}
.outline-none {
outline: 2px solid transparent;
outline-offset: 2px;
}
.outline-black {
outline: 2px dotted black;
outline-offset: 2px;
}
.ring {
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width)
var(--tw-ring-offset-color);
Expand Down
1 change: 0 additions & 1 deletion tests/raw-content.test.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
<div class="bg-blend-darken bg-blend-difference"></div>
<div class="mix-blend-multiply mix-blend-saturation"></div>
<div class="order-last order-2"></div>
<div class="outline-none outline-black"></div>
<div class="overflow-hidden"></div>
<div class="overscroll-contain"></div>
<div class="scroll-smooth"></div>
Expand Down