Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(menu-item): add component tokens #10654

Merged
merged 22 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
610dacf
feat(menu-item): add component tokens
anveshmekala Oct 24, 2024
cf6cb0e
refactor
anveshmekala Oct 31, 2024
bbfd165
replace tokens with pseudo element
anveshmekala Nov 7, 2024
62de077
Merge branch 'dev' into anveshmekala/7180-menu-item-add-tokens
anveshmekala Dec 26, 2024
3bde181
rename border-color to accent
anveshmekala Dec 26, 2024
1373136
Merge branch 'dev' into anveshmekala/7180-menu-item-add-tokens
anveshmekala Dec 26, 2024
8e167a3
add tests
anveshmekala Dec 27, 2024
15f1159
Merge branch 'dev' into anveshmekala/7180-menu-item-add-tokens
anveshmekala Dec 27, 2024
46a3951
add chromatic test
anveshmekala Dec 27, 2024
103010f
Merge branch 'dev' into anveshmekala/7180-menu-item-add-tokens
anveshmekala Dec 30, 2024
08c44e4
rename menu-item tokens to menu
anveshmekala Dec 30, 2024
975368f
Merge branch 'dev' into anveshmekala/7180-menu-item-add-tokens
anveshmekala Dec 30, 2024
ff948d7
cleanup
anveshmekala Dec 30, 2024
70010c6
remove state tokens
anveshmekala Jan 3, 2025
4b8167e
remove unused imports
anveshmekala Jan 3, 2025
7ffd00a
remove state token for accent color
anveshmekala Jan 3, 2025
4e85330
Merge branch 'dev' into anveshmekala/7180-menu-item-add-tokens
anveshmekala Jan 3, 2025
f60f4a3
Merge branch 'dev' into anveshmekala/7180-menu-item-add-tokens
anveshmekala Jan 3, 2025
6161a87
fix border color in vertical layout
anveshmekala Jan 6, 2025
cd765b2
refactor
anveshmekala Jan 7, 2025
84b4dbb
fix tests
anveshmekala Jan 8, 2025
7796368
Merge branch 'dev' into anveshmekala/7180-menu-item-add-tokens
anveshmekala Jan 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ export interface MenuItemCustomEvent {
children?: MenuItem["el"][];
isSubmenuOpen?: boolean;
}

export type Layout = "horizontal" | "vertical";
171 changes: 170 additions & 1 deletion packages/calcite-components/src/components/menu-item/menu-item.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { newE2EPage } from "@arcgis/lumina-compiler/puppeteerTesting";
import { describe, expect, it } from "vitest";
import { html } from "../../../support/formatting";
import { accessible, focusable, hidden, reflects, renders, t9n } from "../../tests/commonTests";
import { accessible, focusable, hidden, reflects, renders, t9n, themed } from "../../tests/commonTests";
import { getFocusedElementProp } from "../../tests/utils";
import { ComponentTestTokens } from "../../tests/commonTests/themed";
import { CSS } from "../../../src/components/menu-item/resources";
import { Layout } from "./interfaces";

describe("calcite-menu-item", () => {
describe("renders", () => {
Expand Down Expand Up @@ -116,4 +119,170 @@ describe("calcite-menu-item", () => {
expect(await getFocusedElementProp(page, "id")).toBe("Nature");
expect(eventSpy).toHaveReceivedEventTimes(2);
});

describe("theme", () => {
const menuWithSlottedSubmenuHTML = (layout: Layout): string => html`
<calcite-menu layout="${layout}">
<calcite-menu-item text="calcite-navigation" href="#calcite-menu">
<calcite-menu-item slot="submenu-item" text="Slots"></calcite-menu-item>
<calcite-menu-item slot="submenu-item" text="Css vars"></calcite-menu-item>
</calcite-menu-item>
</calcite-menu>
`;
describe("slotted submenu", () => {
const tokens: ComponentTestTokens = {
"--calcite-menu-background-color-hover": {
selector: "calcite-menu-item",
shadowSelector: `calcite-action`,
targetProp: "--calcite-action-background-color-hover",
state: "hover",
},
"--calcite-menu-background-color-press": {
selector: "calcite-menu-item",
shadowSelector: `calcite-action`,
targetProp: "--calcite-action-background-color-press",
state: { press: { attribute: "class", value: "dropdown-action" } },
},
"--calcite-menu-background-color": {
selector: "calcite-menu-item",
shadowSelector: `calcite-action`,
targetProp: "--calcite-action-background-color",
},
"--calcite-menu-text-color": {
selector: "calcite-menu-item",
shadowSelector: `calcite-action`,
targetProp: "--calcite-action-text-color",
},
"--calcite-menu-text-color-press": {
selector: "calcite-menu-item",
shadowSelector: `calcite-action`,
targetProp: "--calcite-action-text-color-press",
state: { press: { attribute: "class", value: "dropdown-action" } },
},
"--calcite-menu-item-sub-menu-border-color": {
selector: "calcite-menu-item",
shadowSelector: `.${CSS.dropdownMenuItems}`,
targetProp: "borderColor",
},
};
describe("horizontal layout", () => {
themed(menuWithSlottedSubmenuHTML("horizontal"), tokens);
});
describe("vertical layout", () => {
themed(menuWithSlottedSubmenuHTML("vertical"), {
"--calcite-menu-item-sub-menu-corner-radius": {
selector: "calcite-menu-item",
shadowSelector: `.${CSS.dropdownVertical}`,
targetProp: "borderRadius",
},
});
});
});

describe("default", () => {
const menuHTML: string = html`
<calcite-menu>
<calcite-menu-item text="Ideas"> </calcite-menu-item>
</calcite-menu>
`;
const tokens: ComponentTestTokens = {
"--calcite-menu-item-accent-color-hover": {
selector: "calcite-menu-item",
shadowSelector: `.${CSS.content}`,
targetProp: "borderBlockEndColor",
state: "hover",
},
"--calcite-menu-background-color": {
selector: "calcite-menu-item",
shadowSelector: `.${CSS.content}`,
targetProp: "backgroundColor",
},
"--calcite-menu-background-color-hover": {
selector: "calcite-menu-item",
shadowSelector: `.${CSS.content}`,
targetProp: "backgroundColor",
state: "hover",
},
"--calcite-menu-text-color": {
selector: "calcite-menu-item",
shadowSelector: `.${CSS.content}`,
targetProp: "color",
},
"--calcite-menu-text-color-hover": {
selector: "calcite-menu-item",
shadowSelector: `.${CSS.content}`,
targetProp: "color",
state: "hover",
},
"--calcite-menu-text-color-press": {
selector: "calcite-menu-item",
shadowSelector: `.${CSS.content}`,
targetProp: "color",
state: { press: { attribute: "class", value: ` ${CSS.content} ` } },
},
"--calcite-menu-background-color-press": {
selector: "calcite-menu-item",
shadowSelector: `.${CSS.content}`,
targetProp: "backgroundColor",
state: { press: { attribute: "class", value: ` ${CSS.content} ` } },
},
};
themed(menuHTML, tokens);
});

describe("active", () => {
const activeMenuItemHTML: string = html`
<calcite-menu>
<calcite-menu-item text="Ideas" active> </calcite-menu-item>
</calcite-menu>
`;
const tokens: ComponentTestTokens = {
"--calcite-menu-item-accent-color": {
selector: "calcite-menu-item",
shadowSelector: `.${CSS.content}`,
targetProp: "borderBlockEndColor",
},
};
themed(activeMenuItemHTML, tokens);
});

describe("icons", () => {
const iconMenuItemHTML: string = html` <calcite-menu>
<calcite-menu-item text="Ideas" breadcrumb icon-start="layers" icon-end="layers">
<calcite-menu-item
href="#calcite-navigation-css-vars"
icon-start="multiple-variables"
slot="submenu-item"
text="Css vars"
></calcite-menu-item>
</calcite-menu-item>
</calcite-menu>`;

const tokens: ComponentTestTokens = {
"--calcite-menu-text-color": [
{
selector: "calcite-menu-item",
shadowSelector: `.${CSS.iconStart}`,
targetProp: "color",
},
{
selector: "calcite-menu-item",
shadowSelector: `.${CSS.iconEnd}`,
targetProp: "color",
},
{
selector: "calcite-menu-item",
shadowSelector: `.${CSS.iconBreadcrumb}`,
targetProp: "color",
},
{
selector: "calcite-menu-item",
shadowSelector: `.${CSS.iconDropdown}`,
targetProp: "color",
},
],
};
themed(iconMenuItemHTML, tokens);
});
});
});
100 changes: 77 additions & 23 deletions packages/calcite-components/src/components/menu-item/menu-item.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/**
* CSS Custom Properties
*
* These properties can be overridden using the component's tag as selector.
*
* @prop --calcite-menu-item-accent-color: Specifies the border color of the component when `active`.
* @prop --calcite-menu-item-accent-color-hover: Specifies the border color of the component when hovered.
* @prop --calcite-menu-background-color: Specifies the background color of the component.
* @prop --calcite-menu-background-color-hover: Specifies the background color of the component when hovered.
* @prop --calcite-menu-background-color-press: Specifies the background color of the component when active.
* @prop --calcite-menu-item-sub-menu-border-color: Specifies the border color of sub-menu.
* @prop --calcite-menu-item-sub-menu-corner-radius: Specifies the border radius of sub-menu.
* @prop --calcite-menu-text-color: Specifies the text color of the component.
* @prop --calcite-menu-text-color-hover: Specifies the text color of the component when hovered.
* @prop --calcite-menu-text-color-press: Specifies the text color of the component when active.
*/

:host {
@apply flex
items-center
Expand Down Expand Up @@ -32,46 +49,70 @@
cursor-pointer
outline-none
text-0
text-color-2
box-border
bg-foreground-1
px-4
h-full
w-full;
text-decoration: none;
border-block-end: theme("spacing[0.5]") solid transparent;
padding-block-start: theme("spacing[0.5]");
border-block-end: theme("spacing[0.5]") solid var(--calcite-color-transparent);

background-color: var(--calcite-menu-background-color, var(--calcite-color-foreground-1));
color: var(--calcite-menu-text-color, var(--calcite-internal-menu-item-text-color, var(--calcite-color-text-2)));

&:hover,
&:focus {
background-color: var(--calcite-menu-background-color-hover, var(--calcite-color-foreground-2));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because these are on :host they should not have a state. Remove -hover

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, i had state tokens earlier assuming menu-item & action can have two different background colors.

color: var(--calcite-menu-text-color-hover, var(--calcite-color-text-2));
}

&:hover {
@apply text-color-2 border-b-color-2;
border-block-end-color: var(--calcite-menu-item-accent-color-hover, var(--calcite-color-border-2));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here. Remove the state from all tokens on :host

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Do we need to add a borderBlockEndColor when hovered ? Currently, navigation components do not add any border when hovered.

@SkyeSeitz , @macandcheese

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that makes sense, I think calcite-menu-item:hover { --calcite-menu-item-accent-color: red } could be a way to set that if desired for some reason, though correct the pattern doesn't currently have that, so we don't need a standalone state token.

}

&:focus {
@apply text-color-2 focus-inset border-b-4;
@apply focus-inset border-b-4;
padding-block-start: theme("spacing.1");
border-block-end-width: theme("spacing.1");
}

&:active {
@apply bg-foreground-3 text-color-1;
background-color: var(--calcite-menu-background-color-press, var(--calcite-color-foreground-3));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here. Remove the state from all tokens on :host

color: var(--calcite-menu-text-color-press, var(--calcite-color-text-1));
}

& span {
display: inline-flex;
}

&.layout--vertical {
@apply flex w-full justify-start;
padding-block: 1rem;
border-block-end: 0;
border-inline-end: theme("spacing.1") solid transparent;
border-inline-end: theme("spacing.1") solid var(--calcite-color-transparent);
}
}

:host([active]) .content {
@apply text-color-1;
border-color: var(--calcite-color-brand);
:host([layout="vertical"]) .content {
@apply px-3;
}

:host([active]) {
.content {
background-color: var(--calcite-menu-background-color, (--calcite-color-foreground-3));
--calcite-internal-menu-item-text-color: var(--calcite-color-text-1);
border-block-end-color: var(--calcite-menu-item-accent-color, var(--calcite-color-brand));
}
.icon {
--calcite-icon-color: var(--calcite-color-brand);
--calcite-internal-menu-item-icon-color: var(--calcite-color-brand);
}
}
:host([layout="vertical"]) .content {
@apply px-3;

.icon {
color: var(
--calcite-menu-text-color,
var(--calcite-icon-color, var(--calcite-internal-menu-item-icon-color, var(--calcite-color-text-3)))
);
}

.icon--start {
Expand All @@ -88,7 +129,6 @@

.icon--dropdown {
@apply ms-auto me-0 ps-2 relative;
--calcite-icon-color: var(--calcite-color-text-3);
}

:host([layout="vertical"]) .icon--end ~ .icon--dropdown {
Expand All @@ -108,7 +148,6 @@

.icon--breadcrumb {
@apply ps-2 me-0;
--calcite-icon-color: var(--calcite-color-text-3);
}

:host([layout="vertical"]) .icon--breadcrumb {
Expand All @@ -130,32 +169,46 @@
calcite-action {
@apply relative h-auto;
border-inline-start: 1px solid var(--calcite-color-foreground-1);
--calcite-action-background-color: var(--calcite-menu-background-color);
--calcite-action-text-color: var(--calcite-menu-text-color);

&::after {
@apply block w-px absolute -start-px;
content: "";
inset-block: theme("spacing.3");
background-color: var(--calcite-color-border-3);
}

&:hover::after {
@apply h-full;
inset-block: 0;
}

&:hover,
&:focus {
--calcite-action-background-color-hover: var(--calcite-menu-background-color-hover);
--calcite-action-text-color-press: var(--calcite-menu-text-color-press);
}

&:active {
--calcite-action-background-color-press: var(--calcite-menu-background-color-press);
}
}

// extends the broder block of calcite action when hovered on content
.content:focus ~ calcite-action,
.content:hover ~ calcite-action {
@apply text-color-1;
border-inline-start: 1px solid var(--calcite-color-border-3);
}
--calcite-action-text-color: var(--calcite-menu-text-color-press, var(--calcite-color-text-1));

.container:hover .dropdown-action {
@apply bg-foreground-2;
&::after {
@apply h-full;
inset-block: 0;
}
}

.dropdown-menu-items {
@apply absolute h-auto flex-col hidden overflow-visible min-w-full;
border: 1px solid var(--calcite-color-border-3);
background: var(--calcite-color-foreground-1);
border: 1px solid var(--calcite-menu-item-sub-menu-border-color, var(--calcite-color-border-3));
inset-block-start: 100%;
z-index: theme("zIndex.dropdown");
&.open {
Expand All @@ -173,7 +226,8 @@ calcite-action {
}

.dropdown--vertical.dropdown-menu-items {
@apply relative rounded-none;
@apply relative;
border-radius: var(--calcite-menu-item-sub-menu-corner-radius, var(--calcite-corner-radius));
box-shadow: none;
inset-block-start: 0;
transform: none;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
state,
JsxNode,
} from "@arcgis/lumina";
import { FlipContext } from "../interfaces";
import { FlipContext, Layout } from "../interfaces";
import { Direction, getElementDir, slotChangeGetAssignedElements } from "../../utils/dom";
import {
componentFocusable,
Expand All @@ -32,8 +32,6 @@ declare global {
}
}

type Layout = "horizontal" | "vertical";

/** @slot submenu-item - A slot for adding `calcite-menu-item`s in a submenu. */
export class MenuItem extends LitElement implements LoadableComponent {
// #region Static Members
Expand Down
Loading
Loading