From 9b80daa293851bec79f4688ff35221ed75ea877c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20Ramstr=C3=B6m?= Date: Fri, 25 Oct 2024 14:08:39 +0200 Subject: [PATCH] feat(topbar): new version of application drawer (#336) --- ...les.ts => application-drawer-v1.styles.ts} | 2 +- .../topbar/src/application-drawer-v1.tsx | 302 ++++++++++++++++ .../src/application-drawer-v2.styles.ts | 116 +++++++ .../topbar/src/application-drawer-v2.tsx | 256 ++++++++++++++ components/topbar/src/application-drawer.tsx | 328 +----------------- .../topbar/src/application-drawer.types.ts | 10 + components/topbar/src/application-utils.tsx | 29 ++ examples/src/components/top-bar.tsx | 59 ++-- 8 files changed, 763 insertions(+), 339 deletions(-) rename components/topbar/src/{application-drawer.styles.ts => application-drawer-v1.styles.ts} (98%) create mode 100644 components/topbar/src/application-drawer-v1.tsx create mode 100644 components/topbar/src/application-drawer-v2.styles.ts create mode 100644 components/topbar/src/application-drawer-v2.tsx diff --git a/components/topbar/src/application-drawer.styles.ts b/components/topbar/src/application-drawer-v1.styles.ts similarity index 98% rename from components/topbar/src/application-drawer.styles.ts rename to components/topbar/src/application-drawer-v1.styles.ts index 805bdd37..82a65062 100644 --- a/components/topbar/src/application-drawer.styles.ts +++ b/components/topbar/src/application-drawer-v1.styles.ts @@ -2,7 +2,7 @@ import { makeStyles, shorthands, tokens } from "@fluentui/react-components"; const triggerSpacingWithGroup = tokens.spacingHorizontalS; -export const useApplicationDrawrStyles = makeStyles({ +export const useApplicationDrawerStyles = makeStyles({ drawer: { ...shorthands.borderRight(0), }, diff --git a/components/topbar/src/application-drawer-v1.tsx b/components/topbar/src/application-drawer-v1.tsx new file mode 100644 index 00000000..bf8eb0a1 --- /dev/null +++ b/components/topbar/src/application-drawer-v1.tsx @@ -0,0 +1,302 @@ +import { ArrowRightRegular, Dismiss20Regular } from "@fluentui/react-icons"; +import React, { useState } from "react"; +import { ApplicationArea } from "./top-bar.types"; +import { useTranslation } from "./translation-context"; +import { + Body1, + Body1Strong, + Button, + Caption1Stronger, + Divider, + Drawer, + DrawerBody, + DrawerHeader, + Link, + mergeClasses, + tokens, +} from "@fluentui/react-components"; +import { useApplicationDrawerStyles } from "./application-drawer-v1.styles"; +import { + ApplicationAreaFlaworedIcon, + ApplicationAreaIcon, + applicationAreaLabel, + findCurrent, +} from "./application-utils"; +import { + ApplicationDrawerContent, + ApplicationDrawerProps, + SingleApplicationDrawerContent, +} from "./application-drawer.types"; +import { useApplicationStyles } from "./application.styles"; + +const DrawerTrigger = ( + { setIsOpen, applicationArea, currentSelection }: { + setIsOpen: (isOpen: boolean) => void; + applicationArea: ApplicationArea; + currentSelection: SingleApplicationDrawerContent | undefined; + } +) => { + const styles = useApplicationDrawerStyles(); + const [hover, setHover] = useState(false); + + return ( +
+ +
+ ); +}; + +const ApplicationGroupTitle = ({ application }: { + application: ApplicationDrawerContent; +}): JSX.Element => { + const styles = useApplicationDrawerStyles(); + const appStyles = useApplicationStyles(); + + return ( +
+
+ {application.icon} +
+ + {application.label.toLocaleUpperCase()} + +
+ ); +}; + +const iconConverter = ( + icon: JSX.Element, + isCurrent: boolean, + applicationArea: ApplicationArea +) => { + return isCurrent + ? ( + + ) + : ( + icon + ); +}; + +const SingleApplication = ({ + application, + currentSelectionId, + onChange, + applicationArea, +}: { + application: SingleApplicationDrawerContent; + currentSelectionId: string; + onChange: (id: string) => void; + applicationArea: ApplicationArea; +}): JSX.Element => { + const styles = useApplicationDrawerStyles(); + + return ( + + ); +}; + +const ApplicationWithChildren = ({ + application, + currentSelectionId, + onChange, + applicationArea, +}: { + application: ApplicationDrawerContent; + currentSelectionId: string; + onChange: (id: string) => void; + applicationArea: ApplicationArea; +}): JSX.Element => { + const styles = useApplicationDrawerStyles(); + + return ( + <> + +
+ {application.children?.map((child) => { + return ( + + ); + })} +
+ + ); +}; + +export const ApplicationDrawerV1 = ({ + link, + title, + applicationId, + content, + onChange, + applicationArea, +}: ApplicationDrawerProps & { applicationArea: ApplicationArea }) => { + const { t } = useTranslation(); + const [isOpen, setIsOpen] = useState(false); + const styles = useApplicationDrawerStyles(); + const currentSelection = findCurrent(applicationId, content); + + const onClickItem = (id: string) => { + if (id !== currentSelection?.id) { + onChange(id); + } + setIsOpen(false); + }; + + return ( + <> + + + setIsOpen(open)} + > + setIsOpen(false)} + > +
+ + + {applicationAreaLabel(t, applicationArea)} + +
+ + + + ); +}; + +const ApplicationWithChildren = ({ application, onChange, selectedId }: { + application: ApplicationDrawerContent; + onChange: (id: string) => void; + selectedId: string; +}): JSX.Element => { + return ( + <> + + {application.children?.map((child) => { + return ( + + ); + })} + + ); +}; + +export const ApplicationDrawerV2 = ( + { + link, + title, + applicationId, + content, + onChange, + }: ApplicationDrawerProps & { applicationArea: ApplicationArea } +) => { + const [isOpen, setIsOpen] = useState(false); + const styles = useApplicationDrawerV2Styles(); + const currentSelection = findCurrent(applicationId, content); + + const onClickItem = (id: string) => { + if (id !== currentSelection?.id) { + onChange(id); + } + setIsOpen(false); + }; + + return ( + <> + + + setIsOpen(open)} + > + + + - - ); -}; - -const ApplicationGroupTitle = ({ application }: { - application: ApplicationDrawerContent; -}): JSX.Element => { - const styles = useApplicationDrawerStyles(); - const appStyles = useApplicationStyles(); - - return ( -
-
- {application.icon} -
- - {application.label.toLocaleUpperCase()} - -
- ); -}; - -const findCurrent = ( - applicationId: string, - content?: ApplicationDrawerContent[] -): SingleApplicationDrawerContent | undefined => { - if (!content) { - return undefined; + if (props.version === "v2") { + return ; + } else { + return ; } - - let currentApplication: SingleApplicationDrawerContent | undefined = - undefined; - - content.forEach((c) => { - if (c.id === applicationId) { - currentApplication = c; - } - return c.children?.forEach((child) => { - if (child.id === applicationId) { - currentApplication = child; - } - }); - }); - - return currentApplication; -}; - -const iconConverter = ( - icon: JSX.Element, - isCurrent: boolean, - applicationArea: ApplicationArea -) => { - return isCurrent - ? ( - - ) - : ( - icon - ); -}; - -const SingleApplication = ({ - application, - currentSelectionId, - onChange, - applicationArea, -}: { - application: SingleApplicationDrawerContent; - currentSelectionId: string; - onChange: (id: string) => void; - applicationArea: ApplicationArea; -}): JSX.Element => { - const styles = useApplicationDrawerStyles(); - - return ( - - ); -}; - -const ApplicationWithChildren = ({ - application, - currentSelectionId, - onChange, - applicationArea, -}: { - application: ApplicationDrawerContent; - currentSelectionId: string; - onChange: (id: string) => void; - applicationArea: ApplicationArea; -}): JSX.Element => { - const styles = useApplicationDrawerStyles(); - - return ( - <> - -
- {application.children?.map((child) => { - return ( - - ); - })} -
- - ); -}; - -export const ApplicationDrawer = ({ - link, - title, - applicationId, - content, - onChange, - applicationArea, -}: ApplicationDrawerProps & { applicationArea: ApplicationArea }) => { - const { t } = useTranslation(); - const [isOpen, setIsOpen] = useState(false); - const styles = useApplicationDrawerStyles(); - const currentSelection = findCurrent(applicationId, content); - - const onClickItem = (id: string) => { - if (id !== currentSelection?.id) { - onChange(id); - } - setIsOpen(false); - }; - - return ( - <> - - - setIsOpen(open)} - > - setIsOpen(false)} - > -
- - - {applicationAreaLabel(t, applicationArea)} - -
- + <> + + + } customContent={