Skip to content

Commit 742a07a

Browse files
authored
Merge pull request #392 from dcastil/bugfix/391/fix-arbitrary-shadow-with-inset-not-recognized
Fix arbitrary shadow with inset not recognized
2 parents 41117c8 + 3901cb1 commit 742a07a

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

docs/api-reference.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ A brief summary for each validator:
340340
- `isArbitrarySize` checks whether class part is an arbitrary value which starts with `size:` (`[size:200px_100px]`) which is necessary for background-size classNames.
341341
- `isArbitraryPosition` checks whether class part is an arbitrary value which starts with `position:` (`[position:200px_100px]`) which is necessary for background-position classNames.
342342
- `isArbitraryImage` checks whether class part is an arbitrary value which is an iamge, e.g. by starting with `image:`, `url:`, `linear-gradient(` or `url(` (`[url('/path-to-image.png')]`, `image:var(--maybe-an-image-at-runtime)]`) which is necessary for background-image classNames.
343-
- `isArbitraryShadow` checks whether class part is an arbitrary value which starts with the same pattern as a shadow value (`[0_35px_60px_-15px_rgba(0,0,0,0.3)]`), namely with two lengths separated by a underscore.
343+
- `isArbitraryShadow` checks whether class part is an arbitrary value which starts with the same pattern as a shadow value (`[0_35px_60px_-15px_rgba(0,0,0,0.3)]`), namely with two lengths separated by a underscore, optionally prepended by `inset`.
344344
- `isAny` always returns true. Be careful with this validator as it might match unwanted classes. I use it primarily to match colors or when I'm certain there are no other class groups in a namespace.
345345
346346
## `Config`

src/lib/validators.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ const tshirtUnitRegex = /^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/
55
const lengthUnitRegex =
66
/\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/
77
const colorFunctionRegex = /^(rgba?|hsla?|hwb|(ok)?(lab|lch))\(.+\)$/
8-
// Shadow always begins with x and y offset separated by underscore
9-
const shadowRegex = /^-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/
8+
// Shadow always begins with x and y offset separated by underscore optionally prepended by inset
9+
const shadowRegex = /^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/
1010
const imageRegex =
1111
/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/
1212

tests/validators.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ test('isArbitraryNumber', () => {
166166

167167
test('isArbitraryShadow', () => {
168168
expect(isArbitraryShadow('[0_35px_60px_-15px_rgba(0,0,0,0.3)]')).toBe(true)
169+
expect(isArbitraryShadow('[inset_0_1px_0,inset_0_-1px_0]')).toBe(true)
169170
expect(isArbitraryShadow('[0_0_#00f]')).toBe(true)
170171
expect(isArbitraryShadow('[.5rem_0_rgba(5,5,5,5)]')).toBe(true)
171172
expect(isArbitraryShadow('[-.5rem_0_#123456]')).toBe(true)

0 commit comments

Comments
 (0)