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: 💄 add custom properties for menu item #773

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Changes from all commits
Commits
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
95 changes: 77 additions & 18 deletions packages/uui-menu-item/lib/uui-menu-item.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ import { UUIMenuItemEvent } from './UUIMenuItemEvent';
* @element uui-menu-item
* @cssprop --uui-menu-item-indent - set indentation of the menu items
* @cssprop --uui-menu-item-flat-structure - set to 1 to remove the indentation of the chevron. Use this when you have a flat menu structure
* @cssprop --uui-menu-item-background-color-hover - background color when hovering
* @cssprop --uui-menu-item-color-hover - text color when hovering
* @cssprop --uui-menu-item-background-color-active - background color when active
* @cssprop --uui-menu-item-color-active - text color when active
* @cssprop --uui-menu-item-background-color-disabled - background color when disabled
* @cssprop --uui-menu-item-color-disabled - text color when disabled
* @cssprop --uui-menu-item-background-color-selected - background color when selected
* @cssprop --uui-menu-item-color-selected - text color when selected
* @cssprop --uui-menu-item-color-background-selected-hover - text color when selected
* @fires {UUIMenuItemEvent} show-children - fires when the expand icon is clicked to show nested menu items
* @fires {UUIMenuItemEvent} hide-children - fires when the expend icon is clicked to hide nested menu items
* @fires {UUIMenuItemEvent} click-label - fires when the label is clicked
Expand Down Expand Up @@ -225,52 +234,82 @@ export class UUIMenuItemElement extends SelectOnlyMixin(
:host(:not([active], [selected], [disabled]))
#menu-item
#caret-button:hover {
background-color: var(--uui-color-surface-emphasis);
background-color: var(
--uui-menu-item-background-color-hover,
var(--uui-color-surface-emphasis)
);
}
:host(:not([active], [selected], [disabled]))
#menu-item
#label-button:hover,
:host(:not([active], [selected])) #menu-item #caret-button:hover {
color: var(--uui-color-interactive-emphasis);
color: var(
--uui-menu-item-color-hover,
var(--uui-color-interactive-emphasis)
);
}

/** Active */
:host([active]) #label-button,
:host([active]) #caret-button {
color: var(--uui-color-current-contrast);
color: var(
--uui-menu-item-color-active,
var(--uui-color-current-contrast)
);
}
:host([active]) #label-button-background {
background-color: var(--uui-color-current);
background-color: var(
--uui-menu-item-background-color-active,
var(--uui-color-current)
);
}
:host([active]) #label-button:hover ~ #label-button-background,
:host([active]) #caret-button:hover {
background-color: var(--uui-color-current-emphasis);
background-color: var(
--uui-menu-item-background-color-active-hover,
var(--uui-color-current-emphasis)
);
}

/** Disabled */
:host([disabled]) #menu-item {
color: var(--uui-color-disabled-contrast);
background-color: var(--uui-color-disabled);
color: var(
--uui-menu-item-color-disabled,
var(--uui-color-disabled-contrast)
);
background-color: var(
--uui-menu-item-background-color-disabled,
var(--uui-color-disabled)
);
}

/** Selected */
:host([selected]:not([select-mode='highlight'], [disabled]))
#label-button,
:host([selected]:not([select-mode='highlight'], [disabled]))
#caret-button {
color: var(--uui-color-selected-contrast);
color: var(
--uui-menu-item-color-selected,
var(--uui-color-selected-contrast)
);
}
:host([selected]:not([select-mode='highlight'], [disabled]))
#label-button-background {
background-color: var(--uui-color-selected);
background-color: var(
--uui-menu-item-background-color-selected,
var(--uui-color-selected)
);
}
/** Selected, not highlight mode */
:host([selected]:not([select-mode='highlight'], [disabled]))
#label-button:hover
~ #label-button-background,
:host([selected]:not([select-mode='highlight'], [disabled]))
#caret-button:hover {
background-color: var(--uui-color-selected-emphasis);
background-color: var(
--uui-menu-item-background-color-selected-hover,
var(--uui-color-selected-emphasis)
);
}

/** highlight mode, default */
Expand All @@ -279,7 +318,10 @@ export class UUIMenuItemElement extends SelectOnlyMixin(
#label-button:hover
~ #label-button-background {
border-radius: var(--uui-border-radius);
background-color: var(--uui-color-surface-emphasis);
background-color: var(
--uui-menu-item-background-color-highlight,
var(--uui-color-surface-emphasis)
);
}

/** highlight mode, active */
Expand All @@ -295,7 +337,10 @@ export class UUIMenuItemElement extends SelectOnlyMixin(
#label-button:hover
~ #label-button-background {
border-radius: var(--uui-border-radius);
background-color: var(--uui-color-current-emphasis);
background-color: var(
--uui-menu-item-background-color-highlight-active-selected,
var(--uui-color-current-emphasis)
);
}

/** highlight mode, selected */
Expand All @@ -305,21 +350,33 @@ export class UUIMenuItemElement extends SelectOnlyMixin(
:host([select-mode='highlight'][selected]:not([disabled]))
#menu-item
#caret-button {
color: var(--uui-color-interactive);
color: var(
--uui-menu-item-color-highlight-selected,
var(--uui-color-interactive)
);
}
:host([select-mode='highlight'][selectable][selected]:not([disabled]))
#menu-item
#label-button:hover {
color: var(--uui-color-interactive-emphasis);
color: var(
--uui-menu-item-background-color-highlight-selectable-selected,
var(--uui-color-interactive-emphasis)
);
}

/** highlight mode, selected, selectable caret hover */
:host([selected][selectable][select-mode='highlight']:not([active]))
#menu-item
#caret-button:hover {
border-radius: var(--uui-border-radius);
background-color: var(--uui-color-surface-emphasis);
color: var(--uui-color-interactive-emphasis);
background-color: var(
--uui-menu-item-background-color-highlight-selectable-selected,
var(--uui-color-surface-emphasis)
);
color: var(
--uui-menu-item-color-highlight-selectable-selected,
var(--uui-color-interactive-emphasis)
);
}

/** Highlight borders */
Expand All @@ -331,7 +388,8 @@ export class UUIMenuItemElement extends SelectOnlyMixin(
position: absolute;
content: '';
inset: 1px;
border: 2px solid var(--uui-color-selected);
border: 2px solid
var(--uui-menu-item-border-color-highlight, var(--uui-color-selected));
opacity: 0;
}

Expand All @@ -343,7 +401,8 @@ export class UUIMenuItemElement extends SelectOnlyMixin(
position: absolute;
content: '';
inset: 1px 0 1px 1px;
border: 2px solid var(--uui-color-selected);
border: 2px solid
var(--uui-menu-item-border-color-highlight, var(--uui-color-selected));
border-right: none;
}

Expand Down
Loading