From 48cd84ce77cde98165a856a19cb0c3cd22ae2951 Mon Sep 17 00:00:00 2001 From: akhilmhdh Date: Fri, 3 Feb 2023 22:17:54 +0530 Subject: [PATCH] feat(ui): fine tuning components library with exiting app design --- frontend/src/components/v2/Button/Button.tsx | 19 ++-- frontend/src/components/v2/Card/Card.tsx | 4 +- .../DeleteActionModal/DeleteActionModal.tsx | 89 +++++++++++++++++++ .../components/v2/DeleteActionModal/index.tsx | 1 + .../components/v2/FormControl/FormControl.tsx | 10 ++- .../components/v2/IconButton/IconButton.tsx | 2 +- frontend/src/components/v2/Input/Input.tsx | 5 +- frontend/src/components/v2/Modal/Modal.tsx | 16 ++-- frontend/src/components/v2/Modal/index.tsx | 4 +- frontend/src/components/v2/Select/Select.tsx | 22 ++--- frontend/src/components/v2/Table/Table.tsx | 28 +++--- .../v2/UpgradePlanModal/UpgradePlanModal.tsx | 36 ++++++++ .../components/v2/UpgradePlanModal/index.tsx | 1 + frontend/src/components/v2/index.tsx | 2 + 14 files changed, 192 insertions(+), 47 deletions(-) create mode 100644 frontend/src/components/v2/DeleteActionModal/DeleteActionModal.tsx create mode 100644 frontend/src/components/v2/DeleteActionModal/index.tsx create mode 100644 frontend/src/components/v2/UpgradePlanModal/UpgradePlanModal.tsx create mode 100644 frontend/src/components/v2/UpgradePlanModal/index.tsx diff --git a/frontend/src/components/v2/Button/Button.tsx b/frontend/src/components/v2/Button/Button.tsx index 21548d0e3..27f34838d 100644 --- a/frontend/src/components/v2/Button/Button.tsx +++ b/frontend/src/components/v2/Button/Button.tsx @@ -18,7 +18,8 @@ const buttonVariants = cva( 'font-inter font-medium', 'cursor-pointer', 'inline-flex items-center justify-center', - 'relative' + 'relative', + 'whitespace-nowrap' ], { variants: { @@ -33,7 +34,7 @@ const buttonVariants = cva( plain: '' }, isDisabled: { - true: 'bg-opacity-70 cursor-not-allowed', + true: 'bg-opacity-40 cursor-not-allowed', false: '' }, isFullWidth: { @@ -45,9 +46,9 @@ const buttonVariants = cva( false: '' }, size: { - xs: ['text-xs', 'py-1', 'px-2'], - sm: ['text-sm', 'py-2', 'px-4'], - md: ['text-md', 'py-2', 'px-6'], + xs: ['text-xs', 'py-1', 'px-1'], + sm: ['text-sm', 'py-2', 'px-2'], + md: ['text-md', 'py-2', 'px-4'], lg: ['text-lg', 'py-2', 'px-8'] } }, @@ -75,7 +76,7 @@ const buttonVariants = cva( { colorSchema: 'secondary', variant: 'plain', - className: 'text-mineshaft' + className: 'text-mineshaft-300' }, { colorSchema: 'danger', @@ -101,7 +102,7 @@ export const Button = forwardRef( children, isDisabled = false, className = '', - size = 'md', + size = 'sm', variant = 'solid', isFullWidth, isRounded = true, @@ -144,7 +145,7 @@ export const Button = forwardRef( )} ( {children} ( -
{children}
+
{children}
); export type CardProps = { @@ -47,7 +47,7 @@ export const Card = forwardRef(
void; + onChange?: (isOpen: boolean) => void; + deleteKey: string; + title: string; + onDeleteApproved: () => Promise; +}; + +export const DeleteActionModal = ({ + isOpen, + onClose, + onChange, + deleteKey, + onDeleteApproved, + title +}: Props): JSX.Element => { + const [inputData, setInputData] = useState(''); + const [isLoading, setIsLoading] = useToggle(); + + useEffect(() => { + setInputData(''); + }, [isOpen]); + + const onDelete = async () => { + setIsLoading.on(); + try { + await onDeleteApproved(); + } catch { + setIsLoading.off(); + } finally { + setIsLoading.off(); + } + }; + + return ( + { + setInputData(''); + if (onChange) onChange(isOpenState); + }} + > + + + +
+ } + onClose={onClose} + > +
+ + Type {deleteKey} to delete the resource + + } + className="mb-4" + > + setInputData(e.target.value)} /> + +
+ + + ); +}; diff --git a/frontend/src/components/v2/DeleteActionModal/index.tsx b/frontend/src/components/v2/DeleteActionModal/index.tsx new file mode 100644 index 000000000..b69763984 --- /dev/null +++ b/frontend/src/components/v2/DeleteActionModal/index.tsx @@ -0,0 +1 @@ +export { DeleteActionModal } from './DeleteActionModal'; diff --git a/frontend/src/components/v2/FormControl/FormControl.tsx b/frontend/src/components/v2/FormControl/FormControl.tsx index 14e58d5be..5a545acec 100644 --- a/frontend/src/components/v2/FormControl/FormControl.tsx +++ b/frontend/src/components/v2/FormControl/FormControl.tsx @@ -11,7 +11,7 @@ export type FormLabelProps = { }; export const FormLabel = ({ id, label, isRequired }: FormLabelProps) => ( - + {label} {isRequired && *} @@ -25,7 +25,7 @@ export type FormHelperTextProps = { export const FormHelperText = ({ isError, text }: FormHelperTextProps) => (
@@ -46,6 +46,7 @@ export type FormControlProps = { helperText?: ReactNode; errorText?: ReactNode; children: JSX.Element; + className?: string; }; export const FormControl = ({ @@ -55,10 +56,11 @@ export const FormControl = ({ helperText, errorText, id, - isError + isError, + className }: FormControlProps): JSX.Element => { return ( -
+
{typeof label === 'string' ? ( ) : ( diff --git a/frontend/src/components/v2/IconButton/IconButton.tsx b/frontend/src/components/v2/IconButton/IconButton.tsx index b1a1f4813..eb4919617 100644 --- a/frontend/src/components/v2/IconButton/IconButton.tsx +++ b/frontend/src/components/v2/IconButton/IconButton.tsx @@ -14,7 +14,7 @@ const iconButtonVariants = cva( [ 'button', 'transition-all', - 'font-inter font-medium', + 'font-inter font-medium user-select-none', 'cursor-pointer', 'inline-flex items-center justify-center', 'relative' diff --git a/frontend/src/components/v2/Input/Input.tsx b/frontend/src/components/v2/Input/Input.tsx index 4f502e31d..8c3685dac 100644 --- a/frontend/src/components/v2/Input/Input.tsx +++ b/frontend/src/components/v2/Input/Input.tsx @@ -8,6 +8,7 @@ type Props = { isRequired?: boolean; leftIcon?: ReactNode; rightIcon?: ReactNode; + isDisabled?: boolean; }; const inputVariants = cva( @@ -46,7 +47,7 @@ const inputParentContainerVariants = cva('inline-flex font-inter items-center bo }, isError: { true: 'border-red', - false: 'border-mineshaft-400' + false: 'border-mineshaft-500' }, isFullWidth: { true: 'w-full', @@ -70,6 +71,7 @@ export const Input = forwardRef( className, isRounded = true, isFullWidth = true, + isDisabled, isError = false, isRequired, leftIcon, @@ -87,6 +89,7 @@ export const Input = forwardRef( {...props} required={isRequired} ref={ref} + disabled={isDisabled} className={twMerge( leftIcon ? 'pl-9' : 'pl-4', rightIcon ? 'pr-9' : 'pr-4', diff --git a/frontend/src/components/v2/Modal/Modal.tsx b/frontend/src/components/v2/Modal/Modal.tsx index c7d42541d..eea12fbc5 100644 --- a/frontend/src/components/v2/Modal/Modal.tsx +++ b/frontend/src/components/v2/Modal/Modal.tsx @@ -11,31 +11,32 @@ export type ModalContentProps = DialogPrimitive.DialogContentProps & { title?: ReactNode; subTitle?: string; footerContent?: ReactNode; + onClose?: () => void; }; export const ModalContent = forwardRef( - ({ children, title, subTitle, className, footerContent, ...props }, forwardedRef) => ( + ({ children, title, subTitle, className, footerContent, onClose, ...props }, forwardedRef) => ( {title && {title}} {children} {footerContent && {footerContent}} - + @@ -55,3 +56,6 @@ export const Modal = ({ isOpen, ...props }: ModalProps) => ( export const ModalTrigger = DialogPrimitive.Trigger; export type ModalTriggerProps = DialogPrimitive.DialogTriggerProps; + +export const ModalClose = DialogPrimitive.Close; +export type ModalCloseProps = DialogPrimitive.DialogCloseProps; diff --git a/frontend/src/components/v2/Modal/index.tsx b/frontend/src/components/v2/Modal/index.tsx index c97a564fb..7517b3ec1 100644 --- a/frontend/src/components/v2/Modal/index.tsx +++ b/frontend/src/components/v2/Modal/index.tsx @@ -1,2 +1,2 @@ -export type { ModalContentProps, ModalProps, ModalTriggerProps } from './Modal'; -export { Modal, ModalContent, ModalTrigger } from './Modal'; +export type { ModalCloseProps, ModalContentProps, ModalProps, ModalTriggerProps } from './Modal'; +export { Modal, ModalClose, ModalContent, ModalTrigger } from './Modal'; diff --git a/frontend/src/components/v2/Select/Select.tsx b/frontend/src/components/v2/Select/Select.tsx index c093b8b70..e76e90260 100644 --- a/frontend/src/components/v2/Select/Select.tsx +++ b/frontend/src/components/v2/Select/Select.tsx @@ -22,21 +22,23 @@ export const Select = forwardRef( - {!props.disabled && - - } + {!props.disabled && ( + + + + )} @@ -75,11 +77,11 @@ export const SelectItem = forwardRef( (
( @@ -47,7 +47,7 @@ export type THeadProps = { }; export const THead = ({ children, className }: THeadProps): JSX.Element => ( - + {children} ); @@ -56,15 +56,17 @@ export const THead = ({ children, className }: THeadProps): JSX.Element => ( export type TrProps = { children: ReactNode; className?: string; -}; +} & HTMLAttributes; -export const Tr = ({ children, className }: TrProps): JSX.Element => ( - {children} +export const Tr = ({ children, className, ...props }: TrProps): JSX.Element => ( + + {children} + ); // table head columns export type ThProps = { - children: ReactNode; + children?: ReactNode; className?: string; }; @@ -84,10 +86,12 @@ export const TBody = ({ children, className }: TBodyProps): JSX.Element => ( // table body columns export type TdProps = { - children: ReactNode; + children?: ReactNode; className?: string; -}; +} & TdHTMLAttributes; -export const Td = ({ children, className }: TdProps): JSX.Element => ( - +export const Td = ({ children, className, ...props }: TdProps): JSX.Element => ( + ); diff --git a/frontend/src/components/v2/UpgradePlanModal/UpgradePlanModal.tsx b/frontend/src/components/v2/UpgradePlanModal/UpgradePlanModal.tsx new file mode 100644 index 000000000..e991ca3a8 --- /dev/null +++ b/frontend/src/components/v2/UpgradePlanModal/UpgradePlanModal.tsx @@ -0,0 +1,36 @@ +import Link from 'next/link'; + +import { Button } from '../Button'; +import { Modal, ModalClose, ModalContent } from '../Modal'; + +type Props = { + isOpen?: boolean; + onOpenChange?: (isOpen: boolean) => void; + text: string; +}; + +export const UpgradePlanModal = ({ text, isOpen, onOpenChange }: Props): JSX.Element => ( + + + + , + + + + ]} + > +

{text}

+

+ Upgrade and get access to this, as well as to other powerful enhancements. +

+
+
+); diff --git a/frontend/src/components/v2/UpgradePlanModal/index.tsx b/frontend/src/components/v2/UpgradePlanModal/index.tsx new file mode 100644 index 000000000..e4649c2df --- /dev/null +++ b/frontend/src/components/v2/UpgradePlanModal/index.tsx @@ -0,0 +1 @@ +export { UpgradePlanModal } from './UpgradePlanModal'; diff --git a/frontend/src/components/v2/index.tsx b/frontend/src/components/v2/index.tsx index 437114047..0f89a3a2b 100644 --- a/frontend/src/components/v2/index.tsx +++ b/frontend/src/components/v2/index.tsx @@ -1,6 +1,7 @@ export * from './Button'; export * from './Card'; export * from './Checkbox'; +export * from './DeleteActionModal'; export * from './Dropdown'; export * from './FormControl'; export * from './IconButton'; @@ -12,3 +13,4 @@ export * from './Spinner'; export * from './Switch'; export * from './Table'; export * from './TextArea'; +export * from './UpgradePlanModal';
{children} + {children} +