From 5659671061dd169fa365581f71676d052b192475 Mon Sep 17 00:00:00 2001 From: Adam Tirella Date: Thu, 27 Jul 2023 17:53:55 -0700 Subject: [PATCH] feat(menu-item): Update spacing and icon layout (#7381) **Related Issue:** #7105 ## Summary Updates Menu Item to reflect Figma designs for complex combinations of props: Screenshot 2023-07-26 at 3 22 06 PM --- .../src/components/menu-item/menu-item.scss | 38 +++++- .../components/menu-item/menu-item.stories.ts | 18 +-- .../src/components/menu-item/menu-item.tsx | 20 +-- .../src/components/menu/menu.stories.ts | 119 ++++++++++++++++-- .../calcite-components/src/demos/menu.html | 74 ++++++----- 5 files changed, 208 insertions(+), 61 deletions(-) diff --git a/packages/calcite-components/src/components/menu-item/menu-item.scss b/packages/calcite-components/src/components/menu-item/menu-item.scss index 6db7a85d12f..2669dcf209e 100644 --- a/packages/calcite-components/src/components/menu-item/menu-item.scss +++ b/packages/calcite-components/src/components/menu-item/menu-item.scss @@ -68,6 +68,9 @@ --calcite-ui-icon-color: var(--calcite-ui-brand); } } +:host([layout="vertical"]) .content { + @apply px-3; +} .icon--start { @apply me-3; @@ -77,13 +80,28 @@ @apply ms-3; } +:host([layout="vertical"]) .icon--end { + @apply ms-auto ps-3; +} + .icon--dropdown { @apply ms-auto me-0 ps-2 relative; --calcite-ui-icon-color: var(--calcite-ui-text-3); } -:host([layout="vertical"]) .icon--dropdown { - inset-inline-start: theme("spacing.1"); +:host([layout="vertical"]) .icon--end ~ .icon--dropdown { + @apply ms-3; +} + +:host([layout="vertical"]) .hover-href-icon { + @apply ps-2; +} +:host([layout="vertical"]) .hover-href-icon ~ .icon--end { + @apply ms-2; +} + +:host([layout="vertical"]) .hover-href-icon ~ .icon--breadcrumb { + @apply ms-3; } .icon--breadcrumb { @@ -91,6 +109,18 @@ --calcite-ui-icon-color: var(--calcite-ui-text-3); } +:host([layout="vertical"]) .icon--breadcrumb { + @apply ms-auto; +} + +:host([layout="vertical"]) .icon--breadcrumb ~ .icon--dropdown { + @apply ms-2; +} + +:host([layout="vertical"]) .icon--end ~ .icon--breadcrumb { + @apply ms-2; +} + :host([breadcrumb]) .content { @apply pe-3; } @@ -151,7 +181,7 @@ calcite-action { } :host([slot="submenu-item"]) .parent--vertical { - padding-inline-start: theme("spacing.7"); + @apply ps-6; } .dropdown-menu-items.nested.calcite--rtl { @@ -163,7 +193,7 @@ calcite-action { } .hover-href-icon { - @apply ps-8 ms-auto relative end-1 opacity-0; + @apply ms-auto relative end-1 opacity-0; transition: all var(--calcite-internal-animation-timing-medium) ease-in-out; } diff --git a/packages/calcite-components/src/components/menu-item/menu-item.stories.ts b/packages/calcite-components/src/components/menu-item/menu-item.stories.ts index d793f4669db..86fa712f76e 100644 --- a/packages/calcite-components/src/components/menu-item/menu-item.stories.ts +++ b/packages/calcite-components/src/components/menu-item/menu-item.stories.ts @@ -11,7 +11,7 @@ export default { ...storyFilters(), }; -export const simple = (): string => html` +export const simple = (): string => html` html` /> `; -export const iconStart = (): string => html` +export const iconStart = (): string => html` html` /> `; -export const iconEnd = (): string => html` +export const iconEnd = (): string => html` html` /> `; -export const iconsBoth = (): string => html` +export const iconsBoth = (): string => html` html` /> `; -export const allIconsAndSubMenu_TestOnly = (): string => html` +export const allIconsAndSubMenu_TestOnly = (): string => html` - + @@ -83,7 +83,7 @@ export const allIconsAndSubMenuVertical_TestOnly = (): string => html` - + @@ -97,6 +97,6 @@ export const darkModeRTL_TestOnly = (): string => active dir="rtl" class="calcite-mode-dark" - icon-start="Layers" - icon-end="Layers" + icon-start="layer" + icon-end="layer" />`; diff --git a/packages/calcite-components/src/components/menu-item/menu-item.tsx b/packages/calcite-components/src/components/menu-item/menu-item.tsx index 885cfdfe655..306ae9bea7f 100644 --- a/packages/calcite-components/src/components/menu-item/menu-item.tsx +++ b/packages/calcite-components/src/components/menu-item/menu-item.tsx @@ -437,13 +437,26 @@ export class CalciteMenuItem implements LoadableComponent, T9nComponent, Localiz ); } + renderHrefIcon(dir: Direction): VNode { + return ( + + ); + } + renderItemContent(dir: Direction): VNode { + const hasHref = this.href && (this.topLevelMenuLayout === "vertical" || !this.isTopLevelItem); return ( {this.iconStart && this.renderIconStart()}
{this.text}
+ {hasHref && this.renderHrefIcon(dir)} {this.iconEnd && this.renderIconEnd()} {this.breadcrumb ? this.renderBreadcrumbIcon(dir) : null} {!this.href && this.hasSubmenu ? this.renderDropdownIcon(dir) : null} @@ -480,13 +493,6 @@ export class CalciteMenuItem implements LoadableComponent, T9nComponent, Localiz ref={(el) => (this.anchorEl = el)} > {this.renderItemContent(dir)} - {this.href && (this.topLevelMenuLayout === "vertical" || !this.isTopLevelItem) ? ( - - ) : null} {this.href && this.hasSubmenu ? this.renderDropdownAction(dir) : null} diff --git a/packages/calcite-components/src/components/menu/menu.stories.ts b/packages/calcite-components/src/components/menu/menu.stories.ts index d56745a1491..81b462cb10f 100644 --- a/packages/calcite-components/src/components/menu/menu.stories.ts +++ b/packages/calcite-components/src/components/menu/menu.stories.ts @@ -11,7 +11,7 @@ export default { ...storyFilters(), }; -export const simple = (): string => html` html` @@ -19,32 +19,74 @@ export const simple = (): string => html`
`; +export const iconsAndBreadcrumb = (): string => html` + + + +`; + +export const iconsAndBreadcrumbVertical_TestOnly = (): string => html` + + + +`; + export const withNesting = (): string => html` - - + + - + -
`; export const WithSubmenuOpen_TestOnly = (): string => html` - + + + + `; -export const WithSubmenuOpenInVerticalLayout_TestOnly = (): string => html` +export const WithSubmenuOpenInVerticalLayout_TestOnly = (): string => html` - + + + + `; export const darkModeRTL_TestOnly = (): string => html` @@ -53,6 +95,67 @@ export const darkModeRTL_TestOnly = (): string => html`
`; +export const verticalComplexUseCase_TestOnly = (): string => html` + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +`; + export const verticalLayoutInDarkModeRTL_TestOnly = (): string => html` - + - + @@ -342,18 +349,19 @@

- - - - - - + + + + + + + - - + + @@ -393,38 +401,38 @@

> - - - + + + - - - - - - + + + + + + - - - - - - - + + + + + + + - - - - - - - + + + + + + +