Skip to content

Commit

Permalink
Merge pull request #810 from deepfence/ui-v2-use-cva-for-textinput
Browse files Browse the repository at this point in the history
(V2) Use cva for textinput
  • Loading branch information
manV authored Jan 16, 2023
2 parents 1723a97 + d3e8fe9 commit d03673b
Show file tree
Hide file tree
Showing 9 changed files with 274 additions and 201 deletions.
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

0 comments on commit d03673b

Please sign in to comment.