diff --git a/lib/.eslintrc b/lib/.eslintrc index de7f2439b..96b59d79c 100644 --- a/lib/.eslintrc +++ b/lib/.eslintrc @@ -63,7 +63,7 @@ "react/jsx-boolean-value": "warn", "react/jsx-curly-brace-presence": ["warn", { "props": "never" }], "react/jsx-fragments": "warn", - "react/jsx-no-useless-fragment": "error", + "react/jsx-no-useless-fragment": "off", "react/no-array-index-key": "warn", "react/no-did-update-set-state": "warn", "react/no-direct-mutation-state": "error", diff --git a/lib/src/components/alert-dialog/alert-context/AlertDialog.tsx b/lib/src/components/alert-dialog/alert-context/AlertDialog.tsx index a74334a3d..a5da12935 100644 --- a/lib/src/components/alert-dialog/alert-context/AlertDialog.tsx +++ b/lib/src/components/alert-dialog/alert-context/AlertDialog.tsx @@ -41,19 +41,15 @@ export const Alert: React.FC = ({ {cancelActionText && ( )} - diff --git a/lib/src/components/banner/banner-regular/__snapshots__/BannerRegular.test.tsx.snap b/lib/src/components/banner/banner-regular/__snapshots__/BannerRegular.test.tsx.snap index c251d1b3a..84694359b 100644 --- a/lib/src/components/banner/banner-regular/__snapshots__/BannerRegular.test.tsx.snap +++ b/lib/src/components/banner/banner-regular/__snapshots__/BannerRegular.test.tsx.snap @@ -428,12 +428,18 @@ exports[`BannerRegular component renders 1`] = ` margin-left: var(--space-2); } - .c-fkUJsw-eYnvrx-size-sm { + .c-fkUJsw-jMTgOB-size-sm { font-size: var(--fontSizes-sm); line-height: 1.53; height: var(--sizes-3); padding-left: var(--space-4); padding-right: var(--space-4); + gap: var(--space-2); + } + + .c-fkUJsw-jMTgOB-size-sm .c-dbrbZt { + height: 16px; + width: 16px; } .c-fkUJsw-fGHEql-fullWidth-true { @@ -497,12 +503,20 @@ exports[`BannerRegular component renders 1`] = ` } @media (min-width: 800px) { - .c-fkUJsw-hnmcil-size-md { + .c-fkUJsw-dbnTtJ-size-md { font-size: var(--fontSizes-md); line-height: 1.5; height: var(--sizes-4); padding-left: var(--space-5); padding-right: var(--space-5); + gap: var(--space-3); + } +} + +@media (min-width: 800px) { + .c-fkUJsw-dbnTtJ-size-md .c-dbrbZt { + height: 20px; + width: 20px; } } @@ -586,13 +600,13 @@ exports[`BannerRegular component renders 1`] = ` class="c-jgdwfn c-jgdwfn-ejCoEP-direction-row c-jgdwfn-XefLA-wrap-wrap c-jgdwfn-awKDG-justify-start c-jgdwfn-jroWjL-align-center c-jgdwfn-dPMagj-gap-2 c-jgdwfn-hAgpth-gap-4" > ) @@ -183,14 +183,5 @@ describe(`Button component`, () => { expect(handleClick).toHaveBeenCalledTimes(0) }) - - it('renders an anchor if provided a link', async () => { - render() - - expect(await screen.findByRole('link')).toHaveAttribute( - 'href', - 'https://atomlearning.co.uk' - ) - }) }) }) diff --git a/lib/src/components/button/Button.tsx b/lib/src/components/button/Button.tsx index e235a6a88..19cc8d5ec 100644 --- a/lib/src/components/button/Button.tsx +++ b/lib/src/components/button/Button.tsx @@ -1,12 +1,12 @@ +import { Slot } from '@radix-ui/react-slot' import type { VariantProps } from '@stitches/react' import { darken, opacify } from 'color2k' import * as React from 'react' import { Box } from '~/components/box' -import { Icon } from '~/components/icon' +import { StyledIcon } from '~/components/icon' import { Loader } from '~/components/loader' import { styled, theme } from '~/stitches' -import { NavigatorActions } from '~/types' import { Override } from '~/utilities' const getButtonOutlineVariant = ( @@ -86,19 +86,24 @@ export const StyledButton = styled('button', { fontSize: '$sm', lineHeight: 1.53, height: '$3', - px: '$4' + px: '$4', + gap: '$2', + [`& ${StyledIcon}`]: { size: 16 } }, md: { fontSize: '$md', lineHeight: 1.5, height: '$4', - px: '$5' + px: '$5', + gap: '$3', + [`& ${StyledIcon}`]: { size: 20 } }, lg: { fontSize: '$lg', lineHeight: 1.5, height: '$5', - px: '$5' + px: '$5', + [`& ${StyledIcon}`]: { size: 22 } } }, isLoading: { @@ -117,7 +122,6 @@ export const StyledButton = styled('button', { } } }, - compoundVariants: [ { theme: 'primary', @@ -189,108 +193,81 @@ export const StyledButton = styled('button', { ] }) -const WithLoader = ({ isLoading, children }) => ( - <> - - - {children} - - -) - -const getIconSize = (size) => { - switch (size) { - case 'lg': - return 22 - case 'md': - return 20 - case 'sm': - default: - return 16 +const ButtonContent = ({ + children, + isLoading +}: React.PropsWithChildren>) => { + if (typeof isLoading !== 'boolean') { + return <>{children} } -} -const getChildren = (children, size) => - React.Children.map(children, (child, i) => { - if (child?.type === Icon) { - return React.cloneElement(child, { - css: { - [i === 0 ? 'mr' : 'ml']: size === 'sm' ? '$2' : '$3', - size: getIconSize(size), - ...(child.props.css ? child.props.css : {}) - } - }) - } - return child - }) + return ( + <> + + + {children} + + + ) +} type ButtonProps = Override< React.ComponentProps, VariantProps & { - as?: React.ComponentType | React.ElementType + as?: never + asChild?: boolean children: React.ReactNode isLoading?: boolean - } & NavigatorActions + } > export const Button = React.forwardRef( ( { children, + as, + asChild, isLoading, onClick, - href, appearance = 'solid', size = 'md', theme = 'primary', - type = 'button', ...rest }, ref ) => { - const linkSpecificProps = href - ? { - as: 'a', - href, - onClick: undefined - } - : {} + const props = { + ...rest, + appearance, + size, + theme, + children, + ref, + // Note: button is not disabled when loading for accessibility purposes. + // Instead the click action is not fired and the button looks faded + isLoading: isLoading || false, + onClick: !isLoading ? onClick : undefined + } - const buttonSpecificProps = href ? {} : { type } + if (asChild) { + return + } - // Note: button is not disabled when loading for accessibility purposes. - // Instead the click action is not fired and the button looks faded return ( - - {typeof isLoading === 'boolean' ? ( - - {getChildren(children, size)} - - ) : ( - getChildren(children, size) - )} + + {children} ) } -) as React.FC +) Button.displayName = 'Button' diff --git a/lib/src/components/button/__snapshots__/Button.test.tsx.snap b/lib/src/components/button/__snapshots__/Button.test.tsx.snap index 3f0298430..9f1772403 100644 --- a/lib/src/components/button/__snapshots__/Button.test.tsx.snap +++ b/lib/src/components/button/__snapshots__/Button.test.tsx.snap @@ -56,12 +56,18 @@ exports[`Button component Loading state renders a loading button 1`] = ` } @media { - .c-fkUJsw-elrwsr-size-md { + .c-fkUJsw-dXsdwv-size-md { font-size: var(--fontSizes-md); line-height: 1.5; height: var(--sizes-4); padding-left: var(--space-5); padding-right: var(--space-5); + gap: var(--space-3); + } + + .c-fkUJsw-dXsdwv-size-md .c-dbrbZt { + height: 20px; + width: 20px; } .c-dbrbZt-dMrjnF-size-md { @@ -152,12 +158,6 @@ exports[`Button component Loading state renders a loading button 1`] = ` } @media { - .c-dbrbZt-idQfaGE-css { - margin-left: var(--space-3); - height: 20px; - width: 20px; - } - .c-dhzjXW-ihMdMjL-css { justify-content: center; opacity: 1; @@ -173,7 +173,7 @@ exports[`Button component Loading state renders a loading button 1`] = `
: prompt.label} )} diff --git a/lib/src/components/field-wrapper/__snapshots__/FieldWrapper.test.tsx.snap b/lib/src/components/field-wrapper/__snapshots__/FieldWrapper.test.tsx.snap index 7a69e00fe..446ed3112 100644 --- a/lib/src/components/field-wrapper/__snapshots__/FieldWrapper.test.tsx.snap +++ b/lib/src/components/field-wrapper/__snapshots__/FieldWrapper.test.tsx.snap @@ -216,6 +216,8 @@ exports[`FieldWrapper component renders 1`] = ` Example prompt diff --git a/lib/src/components/file-input/FileInput.tsx b/lib/src/components/file-input/FileInput.tsx index 348971b18..0238e885f 100644 --- a/lib/src/components/file-input/FileInput.tsx +++ b/lib/src/components/file-input/FileInput.tsx @@ -24,16 +24,18 @@ export const FileInput: React.FC = ({ } return ( - ) } diff --git a/lib/src/components/file-input/__snapshots__/FileInput.test.tsx.snap b/lib/src/components/file-input/__snapshots__/FileInput.test.tsx.snap index 408426573..a315a73b9 100644 --- a/lib/src/components/file-input/__snapshots__/FileInput.test.tsx.snap +++ b/lib/src/components/file-input/__snapshots__/FileInput.test.tsx.snap @@ -30,12 +30,18 @@ exports[`FileInput component renders 1`] = ` } @media { - .c-fkUJsw-elrwsr-size-md { + .c-fkUJsw-dXsdwv-size-md { font-size: var(--fontSizes-md); line-height: 1.5; height: var(--sizes-4); padding-left: var(--space-5); padding-right: var(--space-5); + gap: var(--space-3); + } + + .c-fkUJsw-dXsdwv-size-md .c-dbrbZt { + height: 20px; + width: 20px; } .c-dbrbZt-dMrjnF-size-md { @@ -68,22 +74,13 @@ exports[`FileInput component renders 1`] = ` } } -@media { - .c-dbrbZt-idQgHjC-css { - margin-right: var(--space-3); - height: 20px; - width: 20px; - } -} -
`; @@ -221,6 +221,8 @@ exports[`Link component renders an anchor 1`] = ` GOOGLE @@ -309,6 +311,8 @@ exports[`Link component renders an large anchor 1`] = ` GOOGLE diff --git a/lib/src/components/markdown-content/__snapshots__/MarkdownContent.test.tsx.snap b/lib/src/components/markdown-content/__snapshots__/MarkdownContent.test.tsx.snap index aef8046c0..df1c96571 100644 --- a/lib/src/components/markdown-content/__snapshots__/MarkdownContent.test.tsx.snap +++ b/lib/src/components/markdown-content/__snapshots__/MarkdownContent.test.tsx.snap @@ -683,6 +683,8 @@ line 3 of code link text @@ -693,6 +695,8 @@ line 3 of code link with title diff --git a/lib/src/components/sidedrawer/__snapshots__/Sidedrawer.test.tsx.snap b/lib/src/components/sidedrawer/__snapshots__/Sidedrawer.test.tsx.snap index b5719660f..f7f9f3bb1 100644 --- a/lib/src/components/sidedrawer/__snapshots__/Sidedrawer.test.tsx.snap +++ b/lib/src/components/sidedrawer/__snapshots__/Sidedrawer.test.tsx.snap @@ -332,12 +332,18 @@ exports[`Sidedrawer renders 1`] = ` width: auto; } - .c-fkUJsw-elrwsr-size-md { + .c-fkUJsw-dXsdwv-size-md { font-size: var(--fontSizes-md); line-height: 1.5; height: var(--sizes-4); padding-left: var(--space-5); padding-right: var(--space-5); + gap: var(--space-3); + } + + .c-fkUJsw-dXsdwv-size-md .c-dbrbZt { + height: 20px; + width: 20px; } .c-fDzwZw-PrXKS-size-md { @@ -598,7 +604,7 @@ exports[`Sidedrawer renders 1`] = ` class="c-dtVmmL" >