Skip to content

Commit

Permalink
Merge pull request #102 from raid-guild/fix/better-defaults
Browse files Browse the repository at this point in the history
more/less defaults
  • Loading branch information
scottrepreneur authored Nov 1, 2023
2 parents 2970302 + 9b1f1ab commit 8f99ebc
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 66 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/components/atoms/Heading/Heading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ChakraHeadingProps, ChakraHeading } from '../../chakra';
* Primary UI component for Heading
*/
const Heading = ({
variant = 'shadow',
variant,
as,
color,
content,
Expand Down
8 changes: 7 additions & 1 deletion src/components/atoms/Toast/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type CustomToastProps = {
iconColor?: string;
toast?: CreateToastFnReturn;
closeToast?: () => void;
descriptionNoOfLines?: number;
};

export type ToastProps = ChakraToastProps & CustomToastProps;
Expand Down Expand Up @@ -75,6 +76,7 @@ const Toast: React.FC<ToastProps> = ({
iconName,
iconColor,
closeToast,
descriptionNoOfLines,
...props
}: ToastProps) => {
return (
Expand All @@ -97,7 +99,11 @@ const Toast: React.FC<ToastProps> = ({
)}
<Box>
<Heading size='md'>{title}</Heading>
{description && <Text size='sm'>{description}</Text>}
{description && (
<Text size='sm' noOfLines={descriptionNoOfLines}>
{description}
</Text>
)}
</Box>
</HStack>
{props.isClosable === true && (
Expand Down
59 changes: 35 additions & 24 deletions src/components/forms/Input/Input.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -21,6 +21,8 @@ type CustomInputProps = {
localForm: UseFormReturn;
tooltip?: string;
helperText?: string;
spacing?: number | string;
registerOptions?: RegisterOptions<FieldValues, string> | undefined;
};

export type InputProps = ChakraInputProps & CustomInputProps;
Expand All @@ -40,8 +42,10 @@ const Input: React.FC<InputProps> = ({
name,
type,
localForm,
registerOptions,
tooltip,
helperText,
spacing,
...props
}: InputProps) => {
if (!localForm) return null;
Expand All @@ -54,30 +58,37 @@ const Input: React.FC<InputProps> = ({

return (
<FormControl>
<Stack spacing={4}>
<HStack align='center'>
{label && <FormLabel m='0'>{label}</FormLabel>}
{tooltip && (
<Tooltip
label={tooltip}
shouldWrapChildren
hasArrow
placement='end'
>
<Flex
h='24px'
w='24px'
bg='primary.500'
borderRadius='full'
align='center'
justify='center'
<Stack spacing={spacing}>
{label && (
<HStack align='center'>
<FormLabel m='0'>{label}</FormLabel>
{tooltip && (
<Tooltip
label={tooltip}
shouldWrapChildren
hasArrow
placement='end'
>
<Icon as={AiOutlineInfoCircle} w='12px' h='12px' />
</Flex>
</Tooltip>
)}
</HStack>
<ChakraInput type={type} {...props} {...register(name)} />
<Flex
h='24px'
w='24px'
bg='primary.500'
borderRadius='full'
align='center'
justify='center'
>
<Icon as={AiOutlineInfoCircle} w='12px' h='12px' />
</Flex>
</Tooltip>
)}
</HStack>
)}

<ChakraInput
type={type}
{...props}
{...register(name, registerOptions)}
/>
{helperText && <FormHelperText>{helperText}</FormHelperText>}
{typeof error === 'string' && (
<FormErrorMessage>{error}</FormErrorMessage>
Expand Down
70 changes: 37 additions & 33 deletions src/components/forms/NumberInput/NumberInput.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -25,10 +25,11 @@ export interface CustomNumberInputProps {
helperText?: string;
name: string;
localForm: UseFormReturn<FieldValues>;
step: number;
variant: string;
min: number;
max: number;
step?: number;
variant?: string;
min?: number;
max?: number;
spacing: number | string;
}

type NumberInputProps = ChakraInputProps & CustomNumberInputProps;
Expand All @@ -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;

Expand All @@ -59,31 +61,33 @@ const NumberInput = ({

return (
<FormControl isRequired={isRequired} isInvalid={!!errors[name]}>
{label && <FormLabel>{label}</FormLabel>}
<Controller
control={control}
name={name}
rules={customValidations}
render={({ field: { ref, ...restField } }) => (
<ChakraNumberInput
variant={variant}
step={step}
min={min}
max={max}
{...restField}
>
<NumberInputField ref={ref} name={restField.name} />
<NumberInputStepper>
<NumberIncrementStepper />
<NumberDecrementStepper />
</NumberInputStepper>
</ChakraNumberInput>
<Stack spacing={spacing}>
{label && <FormLabel m={0}>{label}</FormLabel>}
<Controller
control={control}
name={name}
rules={customValidations}
render={({ field: { ref, ...restField } }) => (
<ChakraNumberInput
variant={variant}
step={step}
min={min}
max={max}
{...restField}
>
<NumberInputField ref={ref} name={restField.name} />
<NumberInputStepper>
<NumberIncrementStepper />
<NumberDecrementStepper />
</NumberInputStepper>
</ChakraNumberInput>
)}
/>
{helperText && <FormHelperText>{helperText}</FormHelperText>}
{typeof error === 'string' && (
<FormErrorMessage>{error}</FormErrorMessage>
)}
/>
{helperText && <FormHelperText>{helperText}</FormHelperText>}
{typeof error === 'string' && (
<FormErrorMessage>{error}</FormErrorMessage>
)}
</Stack>
</FormControl>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/forms/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface SelectProps {
isDisabled?: boolean;
variant?: 'outline' | 'filled' | 'flushed' | undefined;
basicStyles?: boolean;
value?: any;
value?: unknown;
colorScheme?:
| 'whiteAlpha'
| 'blackAlpha'
Expand Down
10 changes: 7 additions & 3 deletions src/components/forms/Switch/Switch.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -12,7 +12,9 @@ import {

type CustomSwitchProps = {
label: string | React.ReactNode;
localForm: UseFormReturn;
name: string;
registerOptions?: RegisterOptions<FieldValues, string> | undefined;
localForm: UseFormReturn<FieldValues>;
};

export type SwitchProps = ChakraSwitchProps & CustomSwitchProps;
Expand All @@ -22,6 +24,8 @@ export type SwitchProps = ChakraSwitchProps & CustomSwitchProps;
*/
const Switch: React.FC<SwitchProps> = ({
label,
name,
registerOptions,
localForm,
...props
}: SwitchProps) => {
Expand All @@ -31,7 +35,7 @@ const Switch: React.FC<SwitchProps> = ({
<Flex as={FormControl} align='center'>
<HStack spacing={3}>
{label && <ChakraText as={FormLabel}>{label}</ChakraText>}
<ChakraSwitch {...props} {...register} />
<ChakraSwitch {...props} {...register(name, registerOptions)} />
</HStack>
</Flex>
);
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useToast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,6 +38,7 @@ const ToastBase = ({
iconName={iconName}
status={status}
closeToast={closeToast}
descriptionNoOfLines={descriptionNoOfLines}
{...props}
/>
),
Expand Down
2 changes: 1 addition & 1 deletion src/theme/components/Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const Input = {
},
},
defaultProps: {
variant: 'filled',
variant: 'outline',
},
};

Expand Down
2 changes: 1 addition & 1 deletion src/theme/components/NumberInput.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const NumberInput = {
baseStyle: {},
defaultProps: {
variant: 'filled',
variant: 'outline',
},
variants: {
filled: {
Expand Down

0 comments on commit 8f99ebc

Please sign in to comment.