Skip to content

Commit

Permalink
fix(menu): support context
Browse files Browse the repository at this point in the history
  • Loading branch information
bennypowers committed Oct 22, 2023
1 parent 19d489b commit c0e7b2a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .changeset/menu-context.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
"@rhds/elements": patch
---
`<rh-menu>`: support color context
19 changes: 18 additions & 1 deletion elements/rh-menu/rh-menu.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,21 @@ slot {
align-items: stretch;
flex-direction: column;
width: max-content;
}
}

.dark::slotted(a) {
color: var(--rh-color-interactive-blue-lightest, #bee1f4) !important;
padding: 5px !important; /* WARNING: not a token value */
}

.dark::slotted(a:hover) {
color: var(--rh-color-interactive-blue-lighter, #73bcf7);
}

.dark::slotted(a:visited) {
color: var(--rh-color-interactive-purple-lighter, #a18fff) !important;
}

.dark::slotted(a:visited:hover) {
color: var(--rh-color-interactive-purple-lighter, #a18fff) !important;
}
16 changes: 11 additions & 5 deletions elements/rh-menu/rh-menu.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { LitElement, html } from 'lit';
import { customElement } from 'lit/decorators/custom-element.js';
import { RovingTabindexController } from '@patternfly/pfe-core/controllers/roving-tabindex-controller.js';
import { classMap } from 'lit/directives/class-map.js';

import { getRandomId } from '@patternfly/pfe-core/functions/random.js';
import { ComposedEvent } from '@patternfly/pfe-core';
import { RovingTabindexController } from '@patternfly/pfe-core/controllers/roving-tabindex-controller.js';

import { colorContextConsumer, type ColorTheme } from '../../lib/context/color/consumer.js';

import styles from './rh-menu.css';

export class MenuToggleEvent extends ComposedEvent {
export class MenuToggleEvent extends Event {
constructor(
public open: boolean,
public menu: HTMLElement
) {
super('toggle');
super('toggle', { bubbles: true });
}
}

Expand All @@ -23,6 +26,8 @@ export class MenuToggleEvent extends ComposedEvent {
export class RhMenu extends LitElement {
static readonly styles = [styles];

@colorContextConsumer() private on?: ColorTheme;

#tabindex = new RovingTabindexController(this);

get activeItem() {
Expand All @@ -37,8 +42,9 @@ export class RhMenu extends LitElement {
}

render() {
const { on = '' } = this;
return html`
<slot part="menu"></slot>
<slot part="menu" class="${classMap({ [on]: !!on })}"></slot>
`;
}

Expand Down

0 comments on commit c0e7b2a

Please sign in to comment.