lukeed/clsxPublic

A tiny (239B) utility for constructing `className` strings conditionally.

feat: Add usage with Tailwind documentation #65

Mergededgarlrmerged 3 commits intomasterfromrefs/pull/65/head
ConversationFiles changed
1 file changed+21-0
StackedSplit
readme.md+21 โˆ’0

๐Ÿ‘‹ @lukeed! Thanks for adding this regex! Can you please elaborate on your approach to building it? I was using https://github.com/shadcn/ui/blob/5e172fc34fdf015aa0d141f52cc8c082b8ae6613/.vscode/settings.json#L7-L8 before seeing your solution. There is a slight difference, so I'm curious if there are any edge cases not covered by any of the two regexps:

```diff shadcn/ui - ["cn\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]"] + ["cn\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"] your regex ```

readme.md:97headce8c006

@edgarlr contributed this section so perhaps they can offer an explanation.

By eyeballing it, the difference is that `([^']*)` will match anything up to `'`, which means that if `"` or or backticks appear in the class value, then the regexp in _our_ docs will include it as part of the value, whereas the other regexp stops there.

clsx doc's regexp <img width="283" alt="Screen Shot 2023-07-18 at 10 43 53 AM" src="https://github.com/lukeed/clsx/assets/5855893/0a0f4e46-08bc-4d09-9552-dbd594c5b699">

shadcn/ui regexp <img width="264" alt="Screen Shot 2023-07-18 at 10 44 16 AM" src="https://github.com/lukeed/clsx/assets/5855893/415538d8-7435-42ed-b41d-0f1740d2238b">

Looks like they're both not ideal, tbh I don't use this extension, but perhaps something like this is better? I don't know if the extn is looking for the first matching group only, though

<img width="218" alt="Screen Shot 2023-07-18 at 10 53 57 AM" src="https://github.com/lukeed/clsx/assets/5855893/94adef8d-a66b-41da-98ef-e64b3ed0a8ef">

readme.md:97headce8c006

Comments on earlier or unavailable lines

Hidden as resolved.