Skip to content

Commit d9013e4

Browse files
reininkadamwathan
andcommitted
Add new outline style, color, width and offset utilities
Co-Authored-By: Adam Wathan <[email protected]>
1 parent 5058275 commit d9013e4

8 files changed

+66
-39
lines changed

src/corePlugins.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,20 +1790,36 @@ export let corePlugins = {
17901790
}
17911791
})(),
17921792

1793-
outline: ({ matchUtilities, theme }) => {
1793+
outlineStyle: ({ addUtilities }) => {
1794+
addUtilities({
1795+
'.outline': { 'outline-style': 'solid' },
1796+
'.outline-dashed': { 'outline-style': 'dashed' },
1797+
'.outline-dotted': { 'outline-style': 'dotted' },
1798+
'.outline-double': { 'outline-style': 'double' },
1799+
'.outline-hidden': { 'outline-style': 'hidden' },
1800+
'.outline-none': { 'outline-style': 'none' },
1801+
})
1802+
},
1803+
1804+
outlineColor: ({ matchUtilities, theme }) => {
17941805
matchUtilities(
17951806
{
17961807
outline: (value) => {
1797-
value = Array.isArray(value) ? value : value.split(',')
1798-
let [outline, outlineOffset = '0'] = Array.isArray(value) ? value : [value]
1799-
1800-
return { outline, 'outline-offset': outlineOffset }
1808+
return { 'outline-color': toColorValue(value) }
18011809
},
18021810
},
1803-
{ values: theme('outline') }
1811+
{ values: flattenColorPalette(theme('outlineColor')), type: ['color'] }
18041812
)
18051813
},
18061814

1815+
outlineWidth: createUtilityPlugin('outlineWidth', [['outline', ['outline-width']]], {
1816+
type: ['length', 'number', 'percentage'],
1817+
}),
1818+
1819+
outlineOffset: createUtilityPlugin('outlineOffset', [['outline-offset', ['outline-offset']]], {
1820+
type: ['length', 'number', 'percentage'],
1821+
}),
1822+
18071823
ringWidth: ({ matchUtilities, addBase, addUtilities, theme }) => {
18081824
let ringOpacityDefault = theme('ringOpacity.DEFAULT', '0.5')
18091825
let ringColorDefault = withAlphaValue(

stubs/defaultConfig.stub.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,21 @@ module.exports = {
705705
padding: ({ theme }) => theme('spacing'),
706706
placeholderColor: ({ theme }) => theme('colors'),
707707
placeholderOpacity: ({ theme }) => theme('opacity'),
708+
outlineColor: ({ theme }) => theme('colors'),
709+
outlineWidth: {
710+
0: '0px',
711+
1: '1px',
712+
2: '2px',
713+
4: '4px',
714+
8: '8px',
715+
},
716+
outlineOffset: {
717+
0: '0px',
718+
1: '1px',
719+
2: '2px',
720+
4: '4px',
721+
8: '8px',
722+
},
708723
ringColor: ({ theme }) => ({
709724
DEFAULT: theme('colors.blue.500', '#3b82f6'),
710725
...theme('colors'),

tests/arbitrary-values.test.css

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -859,25 +859,20 @@
859859
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000),
860860
var(--tw-shadow);
861861
}
862-
.outline-\[2px_solid_black\] {
863-
outline: 2px solid black;
864-
outline-offset: 0;
862+
.outline-\[black\] {
863+
outline-color: black;
865864
}
866-
.outline-\[2px_solid_black\2c 2px\] {
867-
outline: 2px solid black;
868-
outline-offset: 2px;
865+
.outline-\[color\:var\(--outline\)\] {
866+
outline-color: var(--outline);
869867
}
870-
.outline-\[var\(--outline\)\] {
871-
outline: var(--outline);
872-
outline-offset: 0;
868+
.outline-\[10px\] {
869+
outline-width: 10px;
873870
}
874-
.outline-\[var\(--outline\)\2c 3px\] {
875-
outline: var(--outline);
876-
outline-offset: 3px;
871+
.outline-\[length\:var\(--outline\)\] {
872+
outline-width: var(--outline);
877873
}
878-
.outline-\[2px_solid_black\2c var\(--outline-offset\)\] {
879-
outline: 2px solid black;
880-
outline-offset: var(--outline-offset);
874+
.outline-offset-\[10px\] {
875+
outline-offset: 10px;
881876
}
882877
.ring-\[10px\] {
883878
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width)

tests/arbitrary-values.test.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,11 @@
321321
<div class="shadow-[0px_1px_2px_black]"></div>
322322
<div class="shadow-[var(--value)]"></div>
323323

324-
<div class="outline-[2px_solid_black]"></div>
325-
<div class="outline-[2px_solid_black,2px]"></div>
326-
<div class="outline-[var(--outline)]"></div>
327-
<div class="outline-[var(--outline),3px]"></div>
328-
<div class="outline-[2px_solid_black,var(--outline-offset)]"></div>
324+
<div class="outline-[black]"></div>
325+
<div class="outline-[10px]"></div>
326+
<div class="outline-[color:var(--outline)]"></div>
327+
<div class="outline-[length:var(--outline)]"></div>
328+
<div class="outline-offset-[10px]"></div>
329329

330330
<div class="ring-[#76ad65]"></div>
331331
<div class="ring-[color:var(--value)]"></div>

tests/basic-usage.test.css

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -821,12 +821,22 @@
821821
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000),
822822
var(--tw-shadow);
823823
}
824+
.outline {
825+
outline-style: solid;
826+
}
827+
.outline-dashed {
828+
outline-style: dashed;
829+
}
824830
.outline-none {
825-
outline: 2px solid transparent;
826-
outline-offset: 2px;
831+
outline-style: none;
827832
}
828833
.outline-black {
829-
outline: 2px dotted black;
834+
outline-color: #000;
835+
}
836+
.outline-4 {
837+
outline-width: 4px;
838+
}
839+
.outline-offset-2 {
830840
outline-offset: 2px;
831841
}
832842
.ring {

tests/basic-usage.test.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
<div class="bg-blend-darken bg-blend-difference"></div>
9898
<div class="mix-blend-multiply mix-blend-saturation"></div>
9999
<div class="order-last order-2"></div>
100-
<div class="outline-none outline-black"></div>
100+
<div class="outline outline-dashed outline-none outline-black outline-4 outline-offset-2"></div>
101101
<div class="overflow-hidden"></div>
102102
<div class="overscroll-contain"></div>
103103
<div class="p-4 py-2 px-3 pt-1 pr-2 pb-3 pl-4"></div>

tests/raw-content.test.css

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -595,14 +595,6 @@
595595
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000),
596596
var(--tw-shadow);
597597
}
598-
.outline-none {
599-
outline: 2px solid transparent;
600-
outline-offset: 2px;
601-
}
602-
.outline-black {
603-
outline: 2px dotted black;
604-
outline-offset: 2px;
605-
}
606598
.ring {
607599
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width)
608600
var(--tw-ring-offset-color);

tests/raw-content.test.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@
9393
<div class="bg-blend-darken bg-blend-difference"></div>
9494
<div class="mix-blend-multiply mix-blend-saturation"></div>
9595
<div class="order-last order-2"></div>
96-
<div class="outline-none outline-black"></div>
9796
<div class="overflow-hidden"></div>
9897
<div class="overscroll-contain"></div>
9998
<div class="scroll-smooth"></div>

0 commit comments

Comments
 (0)