Skip to content

Commit 5bc01c5

Browse files
committed
Adds symmetrical widths:
* Added parsePx func * Fixed typos * Organized code
1 parent b54be78 commit 5bc01c5

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/index.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
const plugin = require("tailwindcss/plugin");
22

3+
function parsePx(input, defaultValue) {
4+
let value = input.match(/\d+px/);
5+
if (value) {
6+
return parseInt(value[0], 10);
7+
}
8+
return defaultValue;
9+
}
10+
311
module.exports = plugin.withOptions(
412
({
513
animationDuration = "0.6s",
@@ -10,11 +18,15 @@ module.exports = plugin.withOptions(
1018
widthEnd = "12px",
1119
} = {}) => {
1220
return function ({ addUtilities, e }) {
13-
const BOX_SHADOW_INSET_START = "4px";
14-
const BOX_SHADOW_INSET_END = "6px";
1521
const ANIMATION_NAME = "wobble";
1622
const OUTLINE_STYLE = "solid";
1723

24+
const widthStartPx = `${parsePx(widthStart, 8) / 2}px`;
25+
const widthEndPx = `${parsePx(widthEnd, 12) / 2}px`;
26+
27+
const boxShadowStart = `inset ${widthStartPx} ${widthStartPx} ${highlightColorStart}, inset -${widthStartPx} -${widthStartPx} ${highlightColorStart}`;
28+
const boxShadowEnd = `inset ${widthEndPx} ${widthEndPx} ${highlightColorEnd}, inset -${widthEndPx} -${widthEndPx} ${highlightColorEnd}`;
29+
1830
const animation = enableAnimation
1931
? `${e(
2032
"?"
@@ -24,21 +36,21 @@ module.exports = plugin.withOptions(
2436
addUtilities({
2537
[`.${e("?")}`]: {
2638
"outline-style": OUTLINE_STYLE,
27-
"outline-width": widthStart,
39+
"outline-width": widthStartPx,
2840
"outline-color": highlightColorStart,
29-
"box-shadow": `inset ${BOX_SHADOW_INSET_START} ${BOX_SHADOW_INSET_START} ${highlightColorStart}, inset -${BOX_SHADOW_INSET_START} -${BOX_SHADOW_INSET_START} ${highlightColor}`,
41+
"box-shadow": boxShadowStart,
3042
animation: animation,
3143
},
3244
[`@keyframes ${e("?")}${ANIMATION_NAME}`]: {
3345
"0%": {
34-
"outline-width": widthStart,
46+
"outline-width": widthStartPx,
3547
"outline-color": highlightColorStart,
36-
"box-shadow": `inset ${BOX_SHADOW_INSET_START} ${BOX_SHADOW_INSET_START} ${highlightColorStart}, inset -${BOX_SHADOW_INSET_START} -${BOX_SHADOW_INSET_START} ${highlightColor}`,
48+
"box-shadow": boxShadowStart,
3749
},
3850
"100%": {
39-
"outline-width": widthEnd,
51+
"outline-width": widthEndPx,
4052
"outline-color": highlightColorEnd,
41-
"box-shadow": `inset ${BOX_SHADOW_INSET_END} ${BOX_SHADOW_INSET_END} ${highlightColorEnd}, inset -${BOX_SHADOW_INSET_END} -${BOX_SHADOW_INSET_END} ${highlightColor}`,
53+
"box-shadow": boxShadowEnd,
4254
},
4355
},
4456
});

0 commit comments

Comments
 (0)