From 95fcd10430d046d4cab9ac4669e7223d8c55c7dd Mon Sep 17 00:00:00 2001 From: Gustav Larsson Date: Thu, 4 Jul 2024 13:05:33 +0200 Subject: [PATCH] Add Drawer header story --- .storybook/preview.js | 15 +- components/DrawerHeader.tsx | 28 +++- .../legal-documents/LegalDocumentDrawer.tsx | 6 +- .../TransactionsImportRowDrawer.tsx | 6 +- .../transactions/TransactionDrawer.tsx | 9 +- lib/actions/types.ts | 3 +- stories/patterns/DrawerHeader.stories.tsx | 158 ++++++++++++++++++ 7 files changed, 199 insertions(+), 26 deletions(-) create mode 100644 stories/patterns/DrawerHeader.stories.tsx diff --git a/.storybook/preview.js b/.storybook/preview.js index 6e5642a9a16..45e279530f3 100644 --- a/.storybook/preview.js +++ b/.storybook/preview.js @@ -10,6 +10,7 @@ import { RouterContext } from 'next/dist/shared/lib/router-context.shared-runtim import { Toaster } from '../components/ui/Toaster'; import { TooltipProvider } from '../components/ui/Tooltip'; import UserProvider from '../components/UserProvider'; +import { ModalProvider } from '../components/ModalContext'; import 'react-pdf/dist/esm/Page/TextLayer.css'; import 'react-pdf/dist/esm/Page/AnnotationLayer.css'; @@ -33,12 +34,14 @@ export const decorators = [ - - - - - - + + + + + + + + diff --git a/components/DrawerHeader.tsx b/components/DrawerHeader.tsx index dcfbf8bd4af..1e2ee2bf489 100644 --- a/components/DrawerHeader.tsx +++ b/components/DrawerHeader.tsx @@ -3,6 +3,7 @@ import clsx from 'clsx'; import { MoreHorizontal, X } from 'lucide-react'; import { FormattedMessage } from 'react-intl'; +import type { Action } from '../lib/actions/types'; import { useWindowResize, VIEWPORTS } from '../lib/hooks/useWindowResize'; import { DropdownActionItem } from './table/RowActionsMenu'; @@ -10,7 +11,18 @@ import { Button } from './ui/Button'; import { DropdownMenu, DropdownMenuContent, DropdownMenuSeparator, DropdownMenuTrigger } from './ui/DropdownMenu'; import { SheetClose } from './ui/Sheet'; -export default function DrawerHeader({ actions, entityName, entityIdentifier, entityLabel, dropdownTriggerRef }) { +type DrawerHeaderProps = { + actions?: { + primary?: Action[]; + secondary?: Action[]; + }; + entity: React.ReactNode; + identifier: React.ReactNode; + label: React.ReactNode; + dropdownTriggerRef?: React.RefObject; +}; + +export default function DrawerHeader({ actions, entity, identifier, label, dropdownTriggerRef }: DrawerHeaderProps) { const { viewport } = useWindowResize(); const isMobile = viewport === VIEWPORTS.XSMALL; const { primary, secondary } = actions || {}; @@ -20,9 +32,9 @@ export default function DrawerHeader({ actions, entityName, entityIdentifier, en
- {entityName} + {entity} -
{entityIdentifier}
+
{identifier}
@@ -37,14 +49,14 @@ export default function DrawerHeader({ actions, entityName, entityIdentifier, en
-
{entityLabel}
+
{label}
{primary?.map(action => ( + + + #{account.id}} + entity="Agreement" + label="Test Collective" + actions={{ + primary: [ + { + key: 'edit', + label: 'Edit', + onClick: () => {}, + Icon: Pencil, + }, + ], + secondary: [ + { + key: 'share', + label: 'Share', + onClick: () => {}, + Icon: Share, + }, + { + key: 'delete', + label: 'Delete', + onClick: () => {}, + Icon: Trash, + }, + ], + }} + /> + {/* Drawer contents */} + + +\`\`\` + `, + }, + }, + }, +}; + +export default meta; + +const ExampleComponent: React.FC = () => { + const account = { + id: '1234', + }; + const { showConfirmationModal } = useModal(); + const [isEditing, setEditing] = React.useState(false); + const defaultActions = { + primary: [ + { + key: 'edit', + label: 'Edit', + onClick: () => setEditing(true), + Icon: Pencil, + }, + ], + secondary: [ + { + key: 'share', + label: 'Share', + onClick: () => {}, + Icon: Share, + }, + { + key: 'delete', + label: 'Delete', + onClick: () => + showConfirmationModal({ + title: 'Delete agreement?', + description: 'This will permanently delete the agreement and all attachments and comments.', + confirmLabel: 'Delete', + variant: 'destructive', + onConfirm: () => {}, + }), + Icon: Trash, + }, + ], + }; + const editingActions = { + primary: [ + { + key: 'cancel', + label: 'Cancel', + variant: 'outline', + onClick: () => { + setEditing(false); + }, + }, + { + key: 'save', + label: 'Save', + variant: 'default', + onClick: () => setEditing(false), + // Icon: Check, + }, + ], + }; + const label = 'Coworking at Kolgruvan'; + return ( + + + + + + #{account.id}} + entity="Agreement" + label={label} + actions={isEditing ? editingActions : defaultActions} + /> + + + ); +}; +export const Example = { + render: () => , +};