From 8fc7717b1ef9296ab77b6aef646e1b82f329f711 Mon Sep 17 00:00:00 2001 From: Giovanna Monti Date: Thu, 11 Jul 2024 12:12:19 +0200 Subject: [PATCH 01/14] feat(drawer): standardized drawer footer props --- src/components/Drawer/Drawer.Footer.tsx | 44 +++++++++++++++++++++--- src/components/Drawer/Drawer.mocks.tsx | 21 ++++++----- src/components/Drawer/Drawer.props.ts | 3 +- src/components/Drawer/Drawer.stories.tsx | 18 ++++++++-- src/components/Drawer/Drawer.test.tsx | 6 ++-- src/components/Drawer/Drawer.tsx | 5 --- 6 files changed, 73 insertions(+), 24 deletions(-) diff --git a/src/components/Drawer/Drawer.Footer.tsx b/src/components/Drawer/Drawer.Footer.tsx index ae476075..04eeb9ad 100644 --- a/src/components/Drawer/Drawer.Footer.tsx +++ b/src/components/Drawer/Drawer.Footer.tsx @@ -16,14 +16,50 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { ReactElement, ReactNode } from 'react' +import React, { ReactElement, ReactNode } from 'react' -export type DrawerFooter = ReactNode +export type DrawerFooter = { + buttons?: ReactElement[] + extra?: ReactNode +} + +export type CustomDrawerFooter = ReactElement export type FooterProps = { - footer: DrawerFooter, + footer?: DrawerFooter | CustomDrawerFooter, +} + +const styles = { + footer: { + display: 'flex', + alignItems: 'center', + padding: '16px 24px', + justifyContent: 'end', + gap: '8px', + }, + extra: { + flex: 1, + }, + footerButtons: { + display: 'flex', + 'flex-direction': 'row-reverse', + gap: '8px', + }, } export const Footer = ({ footer }: FooterProps): ReactElement => { - return + if (React.isValidElement(footer)) { + return + } + + const drawerFooter = footer as DrawerFooter + const { buttons, extra } = drawerFooter + return } diff --git a/src/components/Drawer/Drawer.mocks.tsx b/src/components/Drawer/Drawer.mocks.tsx index 72fba39d..0783e44a 100644 --- a/src/components/Drawer/Drawer.mocks.tsx +++ b/src/components/Drawer/Drawer.mocks.tsx @@ -40,20 +40,26 @@ export const DrawerLipsum = (): ReactElement => { ) } -export const DrawerLipumTitle = (): ReactElement => { +export const DrawerLipsumTitle = (): ReactElement => { return {'Drawer Lipsum'} } -export const DrawerLipsumFooter = ({ closeDrawer }: {closeDrawer: () => void}): ReactElement => { +export const DrawerLipsumFooterButton = (): ReactElement => { + const { closeDrawer } = useDrawer() return ( -
- -
+ ) } +export const drawerLipsumFooter = { + buttons: [ + , + ], + extra: 'Extra text', +} + export const WithOpenButton = (props: DrawerProps): ReactElement => { const { isVisible, openDrawer, closeDrawer } = useDrawer() return ( @@ -61,7 +67,6 @@ export const WithOpenButton = (props: DrawerProps): ReactElement => { } isVisible={isVisible} onClose={closeDrawer} > diff --git a/src/components/Drawer/Drawer.props.ts b/src/components/Drawer/Drawer.props.ts index fdff812b..424b6d96 100644 --- a/src/components/Drawer/Drawer.props.ts +++ b/src/components/Drawer/Drawer.props.ts @@ -18,6 +18,7 @@ import { ReactNode } from 'react' +import { CustomDrawerFooter, DrawerFooter } from './Drawer.Footer' import { DrawerTitle } from './Drawer.Title' export type DrawerProps = { @@ -35,7 +36,7 @@ export type DrawerProps = { /** * Drawer footer. */ - footer?: ReactNode, + footer?: DrawerFooter | CustomDrawerFooter, /** * drawer id for DOM node. diff --git a/src/components/Drawer/Drawer.stories.tsx b/src/components/Drawer/Drawer.stories.tsx index fab246bf..c4b8ed92 100644 --- a/src/components/Drawer/Drawer.stories.tsx +++ b/src/components/Drawer/Drawer.stories.tsx @@ -18,11 +18,12 @@ import type { Meta, StoryObj } from '@storybook/react' -import { DrawerLipumTitle, WithOpenButton } from './Drawer.mocks' +import { DrawerLipsumFooterButton, DrawerLipsumTitle, WithOpenButton, drawerLipsumFooter } from './Drawer.mocks' import { Drawer } from '.' const defaults = { - title: , + title: , + footer: , } const meta = { @@ -36,6 +37,17 @@ const meta = { export default meta type Story = StoryObj -export const BasicExample: Story = { +export const BasicExampleWithFooter: Story = { + args: { + ...meta.args, + footer: drawerLipsumFooter, + }, + decorators: [(_, { args }) => ], +} + +export const BasicExampleWithCustomFooter: Story = { + args: { + ...meta.args, + }, decorators: [(_, { args }) => ], } diff --git a/src/components/Drawer/Drawer.test.tsx b/src/components/Drawer/Drawer.test.tsx index 7e2d0351..0bb2a55a 100644 --- a/src/components/Drawer/Drawer.test.tsx +++ b/src/components/Drawer/Drawer.test.tsx @@ -16,7 +16,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { DrawerLipsum, DrawerLipsumFooter, DrawerLipumTitle } from './Drawer.mocks' +import { DrawerLipsum, DrawerLipsumFooterButton, DrawerLipsumTitle } from './Drawer.mocks' import { render, screen } from '../../test-utils' import { Drawer } from './Drawer' import { DrawerProps } from './Drawer.props' @@ -24,9 +24,9 @@ import { DrawerProps } from './Drawer.props' describe('Drawer', () => { const props: DrawerProps = { children: 'Drawer Content', - footer: , + footer: , isVisible: true, - title: , + title: , onClose: jest.fn(), } diff --git a/src/components/Drawer/Drawer.tsx b/src/components/Drawer/Drawer.tsx index 04b6a852..c356b0a8 100644 --- a/src/components/Drawer/Drawer.tsx +++ b/src/components/Drawer/Drawer.tsx @@ -23,10 +23,6 @@ import { DrawerProps } from './Drawer.props' import { Footer } from './Drawer.Footer' import { Title } from './Drawer.Title' -const styles = { - footer: { padding: '24px' }, -} - const DRAWER_WIDTH = 512 export const Drawer = ({ @@ -47,7 +43,6 @@ export const Drawer = ({ id={id} key={key} open={isVisible} - styles={styles} title={} width={DRAWER_WIDTH} onClose={onClose} From a69441e9d8f0ed21e0d6e39d8eae0530b49b17be Mon Sep 17 00:00:00 2001 From: Giovanna Monti Date: Thu, 11 Jul 2024 14:34:11 +0200 Subject: [PATCH 02/14] remove: button box shadow --- src/components/Button/Button.module.css | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/Button/Button.module.css b/src/components/Button/Button.module.css index f2703869..4780ccb8 100644 --- a/src/components/Button/Button.module.css +++ b/src/components/Button/Button.module.css @@ -21,6 +21,7 @@ align-items: center; justify-content: center; gap: var(--spacing-gap-xs, 4px); + box-shadow: none; } /* TODO: add 12px padding to theme */ From 7e52e9af4e6613738616a41bef85a1b67d0c8d2a Mon Sep 17 00:00:00 2001 From: Giovanna Monti Date: Thu, 11 Jul 2024 14:35:48 +0200 Subject: [PATCH 03/14] add: drawer close button; import styles from css module --- src/components/Drawer/Drawer.Footer.tsx | 30 ++++------------- src/components/Drawer/Drawer.mocks.tsx | 6 ++-- src/components/Drawer/Drawer.module.css | 42 ++++++++++++++++++++++++ src/components/Drawer/Drawer.stories.tsx | 10 ++++-- src/components/Drawer/Drawer.test.tsx | 2 +- src/components/Drawer/Drawer.tsx | 21 ++++++++++-- 6 files changed, 78 insertions(+), 33 deletions(-) create mode 100644 src/components/Drawer/Drawer.module.css diff --git a/src/components/Drawer/Drawer.Footer.tsx b/src/components/Drawer/Drawer.Footer.tsx index 04eeb9ad..f752a74d 100644 --- a/src/components/Drawer/Drawer.Footer.tsx +++ b/src/components/Drawer/Drawer.Footer.tsx @@ -18,6 +18,8 @@ import React, { ReactElement, ReactNode } from 'react' +import styles from './Drawer.module.css' + export type DrawerFooter = { buttons?: ReactElement[] extra?: ReactNode @@ -29,35 +31,17 @@ export type FooterProps = { footer?: DrawerFooter | CustomDrawerFooter, } -const styles = { - footer: { - display: 'flex', - alignItems: 'center', - padding: '16px 24px', - justifyContent: 'end', - gap: '8px', - }, - extra: { - flex: 1, - }, - footerButtons: { - display: 'flex', - 'flex-direction': 'row-reverse', - gap: '8px', - }, -} - -export const Footer = ({ footer }: FooterProps): ReactElement => { +export const Footer = ({ footer }: FooterProps): ReactElement | null => { if (React.isValidElement(footer)) { - return
{footer}
+ return
{footer}
} const drawerFooter = footer as DrawerFooter const { buttons, extra } = drawerFooter - return