Skip to content
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

(V2) Use cva for textinput #810

Merged
merged 2 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion deepfence_frontend/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"typescript.preferences.importModuleSpecifier": "non-relative"
"typescript.preferences.importModuleSpecifier": "non-relative",
"tailwindCSS.experimental.classRegex": [
["cva\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]"]
]
}
1 change: 1 addition & 0 deletions deepfence_frontend/packages/ui-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@tanstack/react-table": "^8.5.13",
"ariakit": "2.0.0-next.41",
"classnames": "^2.3.2",
"cva": "npm:class-variance-authority@^0.4.0",
"lodash-es": "^4.17.21",
"tailwind-merge": "^1.6.0",
"tailwindcss-radix": "^2.6.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
import cx from 'classnames';
import { cva, VariantProps } from 'cva';
import { FC } from 'react';
import { twMerge } from 'tailwind-merge';

export type ColorType = 'default' | 'error' | 'success';
import { ObjectWithNonNullableValues } from '@/types/utils';

type Props = {
const helperTextClasses = cva('leading-tight text-sm fornt-normal', {
variants: {
color: {
default: 'text-gray-500 dark:text-gray-400',
error: 'text-red-600 dark:text-red-600',
success: 'text-green-600 dark:text-green-600',
},
},
defaultVariants: {
color: 'default',
},
});

interface Props
extends ObjectWithNonNullableValues<VariantProps<typeof helperTextClasses>> {
text: string;
color: ColorType;
className?: string;
};

export const classes = {
color: {
default: 'text-gray-500 dark:text-gray-400',
error: 'text-red-600 dark:text-red-600',
success: 'text-green-600 dark:text-green-600',
},
};
}

export const HelperText: FC<Props> = ({ text, color, className }) => {
return (
<p
className={twMerge(
cx('leading-tight text-sm fornt-normal', `${classes.color[color]}`),
className,
)}
>
{text}
</p>
);
return <p className={twMerge(helperTextClasses({ color }), className)}>{text}</p>;
};

export default HelperText;
Loading