From 0385f1b1f1a70d9b0f78380309f78c71992ca719 Mon Sep 17 00:00:00 2001 From: Hsu Zhong Jun <27919917+dcshzj@users.noreply.github.com> Date: Wed, 6 Sep 2023 18:28:34 +0800 Subject: [PATCH] feat(editable): introduce new nested card variant (#1478) * feat(icons): introduce new vertical draggable icon * feat(editable): introduce nested version of accordion * fix(contactus): update location card to use nested * fix: border radius of error divider --- src/assets/icons/BxDraggableVertical.tsx | 21 ++ src/assets/icons/index.ts | 1 + .../components/ContactUs/LocationCard.tsx | 4 +- src/layouts/components/Editable/Editable.tsx | 196 ++++++++++++++---- 4 files changed, 177 insertions(+), 45 deletions(-) create mode 100644 src/assets/icons/BxDraggableVertical.tsx diff --git a/src/assets/icons/BxDraggableVertical.tsx b/src/assets/icons/BxDraggableVertical.tsx new file mode 100644 index 000000000..4953be655 --- /dev/null +++ b/src/assets/icons/BxDraggableVertical.tsx @@ -0,0 +1,21 @@ +export const BxDraggableVertical = ( + props: React.SVGProps +): JSX.Element => { + return ( + + + + + + + + + ) +} diff --git a/src/assets/icons/index.ts b/src/assets/icons/index.ts index 976eb4837..26d0f33ba 100644 --- a/src/assets/icons/index.ts +++ b/src/assets/icons/index.ts @@ -16,3 +16,4 @@ export * from "./BxsClearRocket" export * from "./BxLifeBuoy" export * from "./BxCopy" export * from "./BxDraggable" +export * from "./BxDraggableVertical" diff --git a/src/layouts/components/ContactUs/LocationCard.tsx b/src/layouts/components/ContactUs/LocationCard.tsx index ba3f590f4..619253a63 100644 --- a/src/layouts/components/ContactUs/LocationCard.tsx +++ b/src/layouts/components/ContactUs/LocationCard.tsx @@ -135,7 +135,7 @@ export const LocationCard = ({ {/* Note: contentEditable is required to stop drag and drop from hitting the first level drag and drop */} - + {frontMatter.operating_hours.map( (operatingHour, operatingHourIndex) => ( - {/* Operating hours days */} { + switch (item) { + case "card-borderColor": + return (isExpanded && isNested) || isDragging + ? "base.divider.brand" + : "base.divider.medium" + case "hover-bgColor": + if (isExpanded) return "none" + return isNested + ? "interaction.muted.sub.hover" + : "interaction.muted.main.hover" + case "tag-pb": + return isNested ? "0.875rem" : "1.37rem" + case "title-color": + if (!isNested) return "base.content.default" + return isExpanded || isDragging + ? "base.content.strong" + : "base.content.medium" + case "title-color-hover": + if (!isNested) return "inherit" + return isInvalid && !isExpanded + ? "base.content.medium" + : "base.content.strong" + default: + return "" + } +} interface SidebarHeaderProps { title: string @@ -177,16 +224,7 @@ export const EditableDroppable = ({ } const BaseAccordionItem = forwardRef((props: AccordionItemProps, ref) => { - return ( - - ) + return }) interface EditableCardProps { @@ -209,7 +247,11 @@ const EditableAccordionItem = ({ return ( {({ isExpanded }) => ( - <> + {!isExpanded && isInvalid && ( {children} - + )} ) @@ -246,6 +288,7 @@ interface DraggableAccordionItemProps { index: number draggableId: string isInvalid?: boolean + isNested?: boolean } // NOTE: Separating editable/draggable // due to semantics on `Draggables` @@ -253,9 +296,13 @@ interface DraggableAccordionItemProps { * This component displays an accordion item that can be expanded to show its children. * This component is draggable and **needs** to be part of a `Droppable` component. * - * Take note that this component is draggable on the entire card when collapsed - * and that only the chevron can be used to expand this component. + * Note: + * - This component is draggable on the entire card when collapsed + * - Only the chevron can be used to expand this component + * - Tag is not supported when isNested is true + * * @param isInvalid this prop determines whether the error border will be present on collapse. + * @param isNested this prop determines the appropriate styling to use (main vs nested accordion item). */ const DraggableAccordionItem = ({ tag, @@ -263,56 +310,99 @@ const DraggableAccordionItem = ({ children, index, isInvalid, + isNested, }: PropsWithChildren) => { return ( - {(draggableProvided) => ( + {(draggableProvided, snapshot) => ( {({ isExpanded }) => ( - <> - } - /> + + {!isNested && ( + } + /> + )} {!isExpanded && isInvalid && ( )} + {isNested && ( + } + /> + )} {tag} {title} - + {children} - + )} )}