Skip to content

Commit

Permalink
- Update design of collapsible in sidebar menu. No longer uses collap…
Browse files Browse the repository at this point in the history
…sible.

- Breaking: Remove `indent` prop on SidebarMenuLink. Indentation is now done automatically by SidebarMenuCollapsible.
  • Loading branch information
mattias800 committed Sep 7, 2023
1 parent 74da771 commit 6151845
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 65 deletions.
13 changes: 4 additions & 9 deletions packages/panels/src/components/nav-bar/NavBar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,10 @@ export const Demo: Story<Pick<NavBarProps, "variant">> = ({ variant }) => {
label={"Selected"}
/>
<SidebarMenuCollapsible label={"Level 1.2"} leftIcon={faChartBar}>
<SidebarMenuLink indent label={"Level 2.1"} onClick={onClick} />
<SidebarMenuLink indent label={"Level 2.2"} onClick={onClick} />
<SidebarMenuLink
indent
label={"Level 2.3"}
onClick={onClick}
selected
/>
<SidebarMenuLink indent label={"Level 2.4"} onClick={onClick} />
<SidebarMenuLink label={"Level 2.1"} onClick={onClick} />
<SidebarMenuLink label={"Level 2.2"} onClick={onClick} />
<SidebarMenuLink label={"Level 2.3"} onClick={onClick} selected />
<SidebarMenuLink label={"Level 2.4"} onClick={onClick} />
</SidebarMenuCollapsible>

<SidebarMenuHeading label={"Support"} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
--swui-sidebar-menu-separator-color: var(--swui-white);
--swui-sidebar-menu-text-color: var(--lhds-color-ui-900);
--swui-sidebar-menu-icon-color: var(--lhds-color-ui-900);
--swui-sidebar-menu-background-color: var(--lhds-color-ui-50);
--swui-sidebar-menu-background-color-hover: var(--lhds-color-ui-100);
--swui-sidebar-menu-background-color-focus: var(--lhds-color-ui-200);
--swui-sidebar-menu-background-color-active: var(--lhds-color-ui-200);
--swui-sidebar-menu-background-color: transparent;
--swui-sidebar-menu-background-color-hover: var(--lhds-color-ui-400);
--swui-sidebar-menu-background-color-focus: var(--lhds-color-ui-400);
--swui-sidebar-menu-background-color-active: var(--lhds-color-ui-300);
--swui-sidebar-menu-item-selected: var(--lhds-color-blue-100);
--swui-sidebar-menu-content-padding: var(--swui-metrics-indent)
var(--swui-metrics-indent) var(--swui-metrics-indent) 0;
Expand Down
29 changes: 16 additions & 13 deletions packages/panels/src/components/sidebar-menu/SidebarMenu.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,18 @@ export const Overview = () => {
label={"Selected"}
/>
<SidebarMenuCollapsible label={"Level 1.2"} leftIcon={faChartBar}>
<SidebarMenuLink indent label={"Level 2.1"} onClick={onClick} />
<SidebarMenuLink indent label={"Level 2.2"} onClick={onClick} />
<SidebarMenuLink
indent
label={"Level 2.3"}
onClick={onClick}
selected
/>
<SidebarMenuLink indent label={"Level 2.4"} onClick={onClick} />
<SidebarMenuLink label={"Level 2.1"} onClick={onClick} />
<SidebarMenuLink label={"Level 2.2"} onClick={onClick} />
<SidebarMenuLink label={"Level 2.3"} onClick={onClick} selected />
<SidebarMenuLink label={"Level 2.4"} onClick={onClick} />
<SidebarMenuCollapsible label={"Level 2.5"} leftIcon={faChartBar}>
<SidebarMenuLink label={"Level 3.1"} onClick={onClick} />
<SidebarMenuLink label={"Level 3.2"} onClick={onClick} />
<SidebarMenuCollapsible label={"Level 3.3"} leftIcon={faChartBar}>
<SidebarMenuLink label={"Level 4.1"} onClick={onClick} />
<SidebarMenuLink label={"Level 4.2"} onClick={onClick} />
</SidebarMenuCollapsible>
</SidebarMenuCollapsible>
</SidebarMenuCollapsible>

<SidebarMenuHeading label={"Support"} />
Expand Down Expand Up @@ -101,10 +104,10 @@ export const WithoutIcons = () => {
label={"Customers"}
/>
<SidebarMenuCollapsible label={"Statistics"}>
<SidebarMenuLink indent label={"Total"} onClick={onClick} />
<SidebarMenuLink indent label={"Sales region"} onClick={onClick} />
<SidebarMenuLink indent label={"Routes"} onClick={onClick} selected />
<SidebarMenuLink indent label={"Sellers"} onClick={onClick} />
<SidebarMenuLink label={"Total"} onClick={onClick} />
<SidebarMenuLink label={"Sales region"} onClick={onClick} />
<SidebarMenuLink label={"Routes"} onClick={onClick} selected />
<SidebarMenuLink label={"Sellers"} onClick={onClick} />
</SidebarMenuCollapsible>

<SidebarMenuSeparator />
Expand Down
107 changes: 77 additions & 30 deletions packages/panels/src/components/sidebar-menu/SidebarMenuCollapsible.tsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,100 @@
import * as React from "react";
import { ReactNode, useState } from "react";
import { Collapsible } from "../collapsible/Collapsible";
import { Box, Column, Indent } from "@stenajs-webui/core";
import { Box, Indent, Row, Space, Text } from "@stenajs-webui/core";
import { IconDefinition } from "@fortawesome/fontawesome-svg-core";
import styles from "./SidebarMenuCollapsible.module.css";
import { Icon } from "@stenajs-webui/elements";
import contentStyles from "./SidebarMenuContent.module.css";
import cx from "classnames";
import { faChevronUp } from "@fortawesome/free-solid-svg-icons/faChevronUp";
import { faChevronDown } from "@fortawesome/free-solid-svg-icons";
import { cssColor } from "@stenajs-webui/theme";
import { SidebarMenuCollapsibleGroupBox } from "./SidebarMenuCollapsibleGroupBox";

export interface SidebarMenuCollapsibleProps {
label: string;
collapsed?: boolean;
leftIcon?: IconDefinition;
children?: ReactNode;
className?: string;
initialExpand?: boolean;
indent?: number | boolean;
}

export const SidebarMenuCollapsible: React.FC<SidebarMenuCollapsibleProps> = ({
children,
label,
leftIcon,
className,
initialExpand = false,
indent,
}) => {
const [collapsed, setCollapsed] = useState<boolean>(false);
const [expanded, setExpanded] = useState<boolean>(initialExpand);

const innerClassName = cx(
contentStyles.button,
expanded ? contentStyles.selected : undefined,
className
);

const innerStyle = {
height: "var(--swui-sidebar-menu-item-height)",
};

return (
<Box background={"var(--current-background-color)"}>
<Collapsible
className={styles.sidebarMenuCollapsible}
label={label}
collapsed={collapsed}
onClick={() => setCollapsed(!collapsed)}
contentLeft={
leftIcon ? (
<Box
width={"var(--swui-sidebar-menu-item-height)"}
alignItems={"center"}
justifyContent={"center"}
>
<Icon
icon={leftIcon}
size={16}
color={"var(--current-text-color)"}
data-hover={true}
/>
</Box>
) : (
<Indent num={1} />
)
}
>
<Column flex={1}>{children}</Column>
</Collapsible>
<Box indent={1} width={"100%"}>
<Box
width={"100%"}
borderRadius={"99rem"}
overflow={"hidden"}
justifyContent={"space-between"}
>
<button
className={innerClassName}
style={innerStyle}
onClick={() => setExpanded(!expanded)}
>
<Row justifyContent={"space-between"}>
<Row>
{leftIcon ? (
<Box
width={"var(--swui-sidebar-menu-item-height)"}
alignItems={"center"}
justifyContent={"center"}
>
<Icon
icon={leftIcon}
size={16}
color={"var(--current-text-color)"}
data-hover={true}
/>
</Box>
) : (
<Indent num={1} />
)}
<Text variant={"bold"}>{label}</Text>
</Row>
<Row>
<Icon
icon={expanded ? faChevronUp : faChevronDown}
size={12}
color={cssColor("--lhds-color-blue-600")}
/>
<Indent />
</Row>
</Row>
</button>
</Box>
</Box>

{expanded && (
<Indent>
<Space />
<SidebarMenuCollapsibleGroupBox indent={indent}>
{children}
</SidebarMenuCollapsibleGroupBox>
</Indent>
)}
</Box>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.sidebarMenuCollapsibleGroupBox {
background: var(--lhds-color-ui-200);
border-radius: var(--swui-border-radius);
gap: var(--swui-metrics-space);
display: flex;
flex-direction: column;
padding-top: var(--swui-metrics-space);
padding-bottom: var(--swui-metrics-space);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as React from "react";
import styles from "./SidebarMenuCollapsibleGroupBox.module.css";
import { ReactNode } from "react";

export interface SidebarMenuCollapsibleGroupLineProps {
children?: ReactNode;
indent?: number | boolean;
}

export const SidebarMenuCollapsibleGroupBox: React.FC<
SidebarMenuCollapsibleGroupLineProps
> = ({ children }) => {
return (
<div className={styles.sidebarMenuCollapsibleGroupBox}>{children}</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export interface SidebarMenuLinkProps
renderLink?: SidebarLinkRenderer;
width?: CSSProperties["width"];
selected?: boolean;
indent?: boolean;
}

export type SidebarLinkRenderer = (props: RenderLinkProps) => ReactNode;
Expand All @@ -38,7 +37,6 @@ export const SidebarMenuLink: React.FC<SidebarMenuLinkProps> = ({
className,
children,
selected,
indent,
label,
loading,
left,
Expand Down Expand Up @@ -68,7 +66,6 @@ export const SidebarMenuLink: React.FC<SidebarMenuLinkProps> = ({
const innerChildren = (
<Row spacing={1} flex={1} alignItems={"center"}>
{!hasContentLeft && <Indent />}
{indent && <Indent num={3.5} />}
<ButtonContent
label={label}
loading={loading}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import { Box, exhaustSwitchCaseElseThrow } from "@stenajs-webui/core";
import { Popover } from "@stenajs-webui/tooltip";
import { SidebarItem } from "./types";

export const renderItemsExpanded = (
items: SidebarItem[],
indent = false
): ReactNode[] => {
export const renderItemsExpanded = (items: SidebarItem[]): ReactNode[] => {
return items.map((item, index) => {
switch (item.type) {
case "heading":
Expand All @@ -20,16 +17,17 @@ export const renderItemsExpanded = (
return <SidebarMenuSeparator key={index} />;
case "link": {
const { type, ...linkProps } = item;
return <SidebarMenuLink key={index} indent={indent} {...linkProps} />;
return <SidebarMenuLink key={index} {...linkProps} />;
}
case "grouped":
return (
<SidebarMenuCollapsible
key={index}
leftIcon={item.leftIcon}
label={item.label}
initialExpand={true}
>
{renderItemsExpanded(item.items, true)}
{renderItemsExpanded(item.items)}
</SidebarMenuCollapsible>
);
default:
Expand Down

0 comments on commit 6151845

Please sign in to comment.