-
Notifications
You must be signed in to change notification settings - Fork 44
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 better class regex for javascript/javascriptreact/typescript/typescriptreact #109
Add better class regex for javascript/javascriptreact/typescript/typescriptreact #109
Conversation
Thanks @petertriho this looks great. Could you add some test cases that cover the above examples? |
@praveenperera I've added a few tests, had to refactor |
This looks great @petertriho thanks for the work on this. I can merge this now if you're ready. |
@xiaoyu-tamu 1.7.0 does not include these changes but these changes can just be added by changing headwind.classRegex to match these regexes |
@petertriho Thanks for your quick reply. So i have to build latest by myself right? |
These changes specifically can just be added to your settings.json in vscode
|
I've created a I will release Headwind 2.0.0 on May 1st |
doesnt seem to work for me ,I downloaded .vsix and tried |
Unfortunately, this regex doesn't work for me. I've also added them in my Example test: // hello.tsx
<div className={c("w-5 flex")} /> // before
<div className={c("w-5 flex")} /> // current
<div className={c("flex w-5 ")} /> // expected |
this doesnt work for me 😢 #109 (comment) Example: import classnames from "classnames";
import React, { FunctionComponent, ReactNode } from "react";
export interface Props {
className: string;
children: ReactNode;
}
const Balloon: FunctionComponent<Props> = ({ className = "", children }) => {
return (
<div className={classnames('bg-gray-800 dark:bg-white p-4 relative rounded text-gray-100 dark:text-gray-800 after:absolute after:border-b-[12px] after:border-b-transparent after:border-t-[12px] after:border-t-gray-800 dark:after:border-t-white after:border-x-[12px] after:border-x-transparent after:content-[""] after:left-[50%] after:-ml-[6px] after:top-full', className)}>
{children}
</div>
);
};
export default Balloon; |
These settings from this file (from the commit of this PR) worked for me: "headwind.classRegex": {
"html": "\\bclass\\s*=\\s*[\\\"\\']([_a-zA-Z0-9\\s\\-\\:\\/]+)[\\\"\\']",
"css": "\\B@apply\\s+([_a-zA-Z0-9\\s\\-\\:\\/]+);",
"javascript": "(?:\\bclass(?:Name)?\\s*=[\\w\\d\\s_,{}\\(\\)\\[\\]]*[\"'`]([\\w\\d\\s_\\-\\:\\/${}]+)[\"'`][\\w\\d\\s_,{}\\(\\)\\[\\]]*)|(?:\\btw\\s*`([\\w\\d\\s_\\-\\:\\/]*)`)",
"javascriptreact": "(?:\\bclass(?:Name)?\\s*=[\\w\\d\\s_,{}\\(\\)\\[\\]]*[\"'`]([\\w\\d\\s_\\-\\:\\/${}]+)[\"'`][\\w\\d\\s_,{}\\(\\)\\[\\]]*)|(?:\\btw\\s*`([\\w\\d\\s_\\-\\:\\/]*)`)",
"typescript": "(?:\\bclass(?:Name)?\\s*=[\\w\\d\\s_,{}\\(\\)\\[\\]]*[\"'`]([\\w\\d\\s_\\-\\:\\/${}]+)[\"'`][\\w\\d\\s_,{}\\(\\)\\[\\]]*)|(?:\\btw\\s*`([\\w\\d\\s_\\-\\:\\/]*)`)",
"typescriptreact": "(?:\\bclass(?:Name)?\\s*=[\\w\\d\\s_,{}\\(\\)\\[\\]]*[\"'`]([\\w\\d\\s_\\-\\:\\/${}]+)[\"'`][\\w\\d\\s_,{}\\(\\)\\[\\]]*)|(?:\\btw\\s*`([\\w\\d\\s_\\-\\:\\/]*)`)"
}, |
Posting same regex I posted for coc-tailwincss iamcco/coc-tailwindcss#53
This should be a better regex that works with curly braces
{}
in react jsxNow works with the following:
className="class1 class2"
className='class1 class2'
className={"class1 class2"}
className={'class1 class2'}
className={clsx("class1 class2")}
className={clsx(foo, bar, "class1 class2", bar)}
className={classname(foo, bar, "class1 class2", bar)}
className={anything(foo, bar, "class1 class2", bar)}
className={`flex-col flex ${className}`}
Issues:
className={clsx("class1 class2", foo, bar, "class3 class4", bar)}
Fixes #58 #85 #93