diff --git a/components/navigation-drawer/src/DimNavigationBar.ts b/components/navigation-drawer/src/DimNavigationBar.ts index cba40ca..f5e7cc9 100644 --- a/components/navigation-drawer/src/DimNavigationBar.ts +++ b/components/navigation-drawer/src/DimNavigationBar.ts @@ -1,7 +1,13 @@ -import { css, html, nothing } from 'lit'; +import { css, html } from 'lit'; import NavigationHost from './NavigationHost.js'; +import { renderNavigationItem } from './DimNavigationItem.js'; export class DimNavigationBar extends NavigationHost { + /** + * Differences to navigation rail: + * - It is recommeded to use a label with navigation items. + * - If no label is provided, the icon container doesn't change to a fully rounded shape + */ static styles = css` :host { position: fixed; @@ -187,20 +193,7 @@ export class DimNavigationBar extends NavigationHost { return html` `; diff --git a/components/navigation-drawer/src/DimNavigationItem.ts b/components/navigation-drawer/src/DimNavigationItem.ts index 4039b57..12a4486 100644 --- a/components/navigation-drawer/src/DimNavigationItem.ts +++ b/components/navigation-drawer/src/DimNavigationItem.ts @@ -1,4 +1,4 @@ -import { LitElement, css, html } from 'lit'; +import { LitElement, css, html, nothing } from 'lit'; import { property } from 'lit/decorators.js'; import { consume } from '@lit-labs/context'; import { dimNavigationHostContext } from './DimNavigationHostContext.js'; @@ -7,6 +7,11 @@ import { DimNavigation } from './DimNavigation.js'; const iconOutlinedName = 'icon-outlined'; const iconFilledName = 'icon-filled'; +/** + * A component to provide values needed to render navigation items in a navigation host. Does not render the navigation + * item itself as the layout varies between navigatiom hosts and is therefore the responsibility of the host. + * The navigation item is unaware of what host it is nested in. + */ export class DimNavigationItem extends LitElement { static styles = css` :host { @@ -338,8 +343,12 @@ export class DimNavigationItem extends LitElement { @property({ type: Boolean }) isActive: boolean = false; + /** + * A short meaningful description of the destination. + * When used with navigation bar, avoid using icon without label + */ @property({ type: String }) - label = ''; + label?: string; @property({ type: String }) badge?: string; @@ -420,3 +429,26 @@ export class DimNavigationItem extends LitElement { `; } } + +/** + * Renders a navigation item for the navigation rail and navigatio bar but not the navigation drawer as the layout is + * different for that component. + * This is a function instead of a component as the drawer has different layout and avoid style encapsulation. + * A shared render function to reduce code duplication and errors introduced through code duplication. + * @param item the item to render + * @internal + */ +export function renderNavigationItem(item: DimNavigationItem) { + return html` +
  • + +
    + ${item.isActive ? item.iconFilled : item.iconOutlined} + ${item.badge ? html`${item.badge}` : nothing} +
    + + ${item.label ? html`${item.label}` : nothing} +
    +
  • + `; +} diff --git a/components/navigation-drawer/src/DimNavigationRail.ts b/components/navigation-drawer/src/DimNavigationRail.ts index 8580ee0..5ef4676 100644 --- a/components/navigation-drawer/src/DimNavigationRail.ts +++ b/components/navigation-drawer/src/DimNavigationRail.ts @@ -1,5 +1,6 @@ import { css, html, nothing } from 'lit'; import NavigationHost from './NavigationHost.js'; +import { renderNavigationItem } from './DimNavigationItem.js'; export class DimNavigationRail extends NavigationHost { static styles = css` @@ -49,14 +50,20 @@ export class DimNavigationRail extends NavigationHost { cursor: pointer; /* Icon container */ + + /* No label */ & div { height: 24px; width: 24px; - padding: 4px 16px; + + --_icon-container-padding-y: 16px; + --_icon-container-padding-x: 16px; + padding: var(--_icon-container-padding-y) + var(--_icon-container-padding-x); position: relative; - border-radius: var(--md-sys-shape-corner-large); + border-radius: 100px; & svg { height: 24px; @@ -64,9 +71,10 @@ export class DimNavigationRail extends NavigationHost { } /* Badge */ + --_badge-position-top: 14px; & span { position: absolute; - inset: 2px auto auto 50%; + inset: var(--_badge-position-top) auto auto 50%; display: flex; align-items: center; @@ -100,6 +108,12 @@ export class DimNavigationRail extends NavigationHost { } } + /* Has label */ + &:has(> span) div { + --_icon-container-padding-y: 4px; + --_badge-position-top: 2px; + } + /* States */ /* Inactive */ &:hover div { @@ -185,20 +199,7 @@ export class DimNavigationRail extends NavigationHost { return html` `;