From ba4fb4f07b475cd8174f2a143a296b68bc73921d Mon Sep 17 00:00:00 2001 From: scottrepreneur Date: Sun, 22 Oct 2023 07:54:37 -0700 Subject: [PATCH 1/2] more/less defaults --- package.json | 2 +- src/components/atoms/Heading/Heading.tsx | 2 +- src/components/atoms/Toast/Toast.tsx | 8 ++- src/components/forms/Input/Input.tsx | 49 +++++++------ .../forms/NumberInput/NumberInput.tsx | 70 ++++++++++--------- src/components/forms/Select/Select.tsx | 2 +- src/components/forms/Switch/Switch.tsx | 10 ++- src/hooks/useToast.tsx | 2 + src/theme/components/Input.ts | 2 +- src/theme/components/NumberInput.ts | 2 +- 10 files changed, 85 insertions(+), 64 deletions(-) diff --git a/package.json b/package.json index 52b4e7e..aa8dd2b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@raidguild/design-system", - "version": "0.4.48", + "version": "0.4.49", "license": "MIT", "author": "Raid Guild", "module": "dist/design-system.esm.js", diff --git a/src/components/atoms/Heading/Heading.tsx b/src/components/atoms/Heading/Heading.tsx index a2c20fb..347d75a 100644 --- a/src/components/atoms/Heading/Heading.tsx +++ b/src/components/atoms/Heading/Heading.tsx @@ -5,7 +5,7 @@ import { ChakraHeadingProps, ChakraHeading } from '../../chakra'; * Primary UI component for Heading */ const Heading = ({ - variant = 'shadow', + variant, as, color, content, diff --git a/src/components/atoms/Toast/Toast.tsx b/src/components/atoms/Toast/Toast.tsx index 6904d52..877f02b 100644 --- a/src/components/atoms/Toast/Toast.tsx +++ b/src/components/atoms/Toast/Toast.tsx @@ -24,6 +24,7 @@ type CustomToastProps = { iconColor?: string; toast?: CreateToastFnReturn; closeToast?: () => void; + descriptionNoOfLines?: number; }; export type ToastProps = ChakraToastProps & CustomToastProps; @@ -75,6 +76,7 @@ const Toast: React.FC = ({ iconName, iconColor, closeToast, + descriptionNoOfLines, ...props }: ToastProps) => { return ( @@ -97,7 +99,11 @@ const Toast: React.FC = ({ )} {title} - {description && {description}} + {description && ( + + {description} + + )} {props.isClosable === true && ( diff --git a/src/components/forms/Input/Input.tsx b/src/components/forms/Input/Input.tsx index a7411e4..36d6af7 100644 --- a/src/components/forms/Input/Input.tsx +++ b/src/components/forms/Input/Input.tsx @@ -21,6 +21,7 @@ type CustomInputProps = { localForm: UseFormReturn; tooltip?: string; helperText?: string; + spacing?: number | string; }; export type InputProps = ChakraInputProps & CustomInputProps; @@ -42,6 +43,7 @@ const Input: React.FC = ({ localForm, tooltip, helperText, + spacing, ...props }: InputProps) => { if (!localForm) return null; @@ -54,29 +56,32 @@ const Input: React.FC = ({ return ( - - - {label && {label}} - {tooltip && ( - - + {label && ( + + {label} + {tooltip && ( + - - - - )} - + + + + + )} + + )} + {helperText && {helperText}} {typeof error === 'string' && ( diff --git a/src/components/forms/NumberInput/NumberInput.tsx b/src/components/forms/NumberInput/NumberInput.tsx index 6d1fc8e..db7b532 100644 --- a/src/components/forms/NumberInput/NumberInput.tsx +++ b/src/components/forms/NumberInput/NumberInput.tsx @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { FormHelperText } from '@chakra-ui/react'; +import { FormHelperText, Stack } from '@chakra-ui/react'; import React from 'react'; import { UseFormReturn, @@ -25,10 +25,11 @@ export interface CustomNumberInputProps { helperText?: string; name: string; localForm: UseFormReturn; - step: number; - variant: string; - min: number; - max: number; + step?: number; + variant?: string; + min?: number; + max?: number; + spacing: number | string; } type NumberInputProps = ChakraInputProps & CustomNumberInputProps; @@ -43,10 +44,11 @@ const NumberInput = ({ helperText, customValidations, isRequired, - step, - variant, - min, - max, + step = 1, + variant = 'filled', + min = 0, + max = 100, + spacing, }: NumberInputProps) => { if (!localForm) return null; @@ -59,31 +61,33 @@ const NumberInput = ({ return ( - {label && {label}} - ( - - - - - - - + + {label && {label}} + ( + + + + + + + + )} + /> + {helperText && {helperText}} + {typeof error === 'string' && ( + {error} )} - /> - {helperText && {helperText}} - {typeof error === 'string' && ( - {error} - )} + ); }; diff --git a/src/components/forms/Select/Select.tsx b/src/components/forms/Select/Select.tsx index d17ef8a..7e31664 100644 --- a/src/components/forms/Select/Select.tsx +++ b/src/components/forms/Select/Select.tsx @@ -43,7 +43,7 @@ export interface SelectProps { isDisabled?: boolean; variant?: 'outline' | 'filled' | 'flushed' | undefined; basicStyles?: boolean; - value?: any; + value?: unknown; colorScheme?: | 'whiteAlpha' | 'blackAlpha' diff --git a/src/components/forms/Switch/Switch.tsx b/src/components/forms/Switch/Switch.tsx index 4c2cf54..28bb449 100644 --- a/src/components/forms/Switch/Switch.tsx +++ b/src/components/forms/Switch/Switch.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { UseFormReturn } from 'react-hook-form'; +import { FieldValues, RegisterOptions, UseFormReturn } from 'react-hook-form'; import { HStack, ChakraSwitch, @@ -12,7 +12,9 @@ import { type CustomSwitchProps = { label: string | React.ReactNode; - localForm: UseFormReturn; + name: string; + registerOptions?: RegisterOptions | undefined; + localForm: UseFormReturn; }; export type SwitchProps = ChakraSwitchProps & CustomSwitchProps; @@ -22,6 +24,8 @@ export type SwitchProps = ChakraSwitchProps & CustomSwitchProps; */ const Switch: React.FC = ({ label, + name, + registerOptions, localForm, ...props }: SwitchProps) => { @@ -31,7 +35,7 @@ const Switch: React.FC = ({ {label && {label}} - + ); diff --git a/src/hooks/useToast.tsx b/src/hooks/useToast.tsx index 0c6ace7..7d0390e 100644 --- a/src/hooks/useToast.tsx +++ b/src/hooks/useToast.tsx @@ -17,6 +17,7 @@ const ToastBase = ({ id, duration, closeToast, + descriptionNoOfLines = 2, ...props // gets the rest of the original Chakra Toast props (such as isClosable) }: ToastProps & { status: ChakraAlertStatus; @@ -37,6 +38,7 @@ const ToastBase = ({ iconName={iconName} status={status} closeToast={closeToast} + descriptionNoOfLines={descriptionNoOfLines} {...props} /> ), diff --git a/src/theme/components/Input.ts b/src/theme/components/Input.ts index f68411b..9f5135b 100644 --- a/src/theme/components/Input.ts +++ b/src/theme/components/Input.ts @@ -38,7 +38,7 @@ const Input = { }, }, defaultProps: { - variant: 'filled', + variant: 'outline', }, }; diff --git a/src/theme/components/NumberInput.ts b/src/theme/components/NumberInput.ts index 65f0ea0..a97efbd 100644 --- a/src/theme/components/NumberInput.ts +++ b/src/theme/components/NumberInput.ts @@ -1,7 +1,7 @@ const NumberInput = { baseStyle: {}, defaultProps: { - variant: 'filled', + variant: 'outline', }, variants: { filled: { From 9b1f1abe3dfb25f7586f9107d72bf0b2494a498d Mon Sep 17 00:00:00 2001 From: scottrepreneur Date: Tue, 31 Oct 2023 20:13:24 -0500 Subject: [PATCH 2/2] register options --- src/components/forms/Input/Input.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/components/forms/Input/Input.tsx b/src/components/forms/Input/Input.tsx index 36d6af7..8ca0c12 100644 --- a/src/components/forms/Input/Input.tsx +++ b/src/components/forms/Input/Input.tsx @@ -1,5 +1,5 @@ import React, { ReactNode } from 'react'; -import { UseFormReturn } from 'react-hook-form'; +import { FieldValues, RegisterOptions, UseFormReturn } from 'react-hook-form'; import { AiOutlineInfoCircle } from 'react-icons/ai'; import { ChakraInput, @@ -22,6 +22,7 @@ type CustomInputProps = { tooltip?: string; helperText?: string; spacing?: number | string; + registerOptions?: RegisterOptions | undefined; }; export type InputProps = ChakraInputProps & CustomInputProps; @@ -41,6 +42,7 @@ const Input: React.FC = ({ name, type, localForm, + registerOptions, tooltip, helperText, spacing, @@ -82,7 +84,11 @@ const Input: React.FC = ({ )} - + {helperText && {helperText}} {typeof error === 'string' && ( {error}