-
Notifications
You must be signed in to change notification settings - Fork 597
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #810 from deepfence/ui-v2-use-cva-for-textinput
(V2) Use cva for textinput
- Loading branch information
Showing
9 changed files
with
274 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 19 additions & 23 deletions
42
deepfence_frontend/packages/ui-components/src/components/input/HelperText.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.