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(core/basic-navigation): add mobile support #380

Merged
merged 11 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
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
17 changes: 15 additions & 2 deletions packages/core/component-doc.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,13 @@
"ix-basic-navigation",
"ix-map-navigation"
],
"dependencies": [],
"dependencies": [
"ix-burger-menu"
],
"dependencyGraph": {
"ix-application-header": [
"ix-burger-menu"
],
"ix-basic-navigation": [
"ix-application-header"
],
Expand Down Expand Up @@ -216,6 +221,9 @@
"dependencyGraph": {
"ix-basic-navigation": [
"ix-application-header"
],
"ix-application-header": [
"ix-burger-menu"
]
},
"props": [
Expand All @@ -241,7 +249,7 @@
"mutable": false,
"attr": "hide-header",
"reflectToAttr": false,
"docs": "Hide application header",
"docs": "Hide application header. Will disable responsive feature of basic navigation.",
"docsTags": [],
"default": "false",
"values": [
Expand Down Expand Up @@ -4500,6 +4508,9 @@
],
"ix-icon-button": [
"ix-icon"
],
"ix-application-header": [
"ix-burger-menu"
]
},
"props": [
Expand Down Expand Up @@ -4742,11 +4753,13 @@
"encapsulation": "none",
"dependents": [],
"dependencies": [
"ix-burger-menu",
"ix-menu-item",
"ix-dropdown"
],
"dependencyGraph": {
"ix-menu": [
"ix-burger-menu",
"ix-menu-item",
"ix-dropdown"
]
Expand Down
27 changes: 24 additions & 3 deletions packages/core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* It contains typing information for all components that exist in this project.
*/
import { HTMLStencilElement, JSXBase } from "@stencil/core/internal";
import { Buttons } from "./components/utils/button-variants";
import { Buttons } from "./components/button/button-variants";
import { FilterState } from "./components/category-filter/filter-state";
import { InputState } from "./components/category-filter/input-state";
import { DateTimeCardCorners } from "./components/date-time-card/date-time-card";
Expand Down Expand Up @@ -55,7 +55,7 @@ export namespace Components {
*/
"applicationName": string;
/**
* Hide application header
* Hide application header. Will disable responsive feature of basic navigation.
*/
"hideHeader": boolean;
}
Expand Down Expand Up @@ -93,6 +93,12 @@ export namespace Components {
*/
"label": string;
}
interface IxBurgerMenu {
/**
* Is menu displayed as expanded
*/
"expanded": boolean;
}
interface IxButton {
/**
* Disable the button
Expand Down Expand Up @@ -1724,6 +1730,12 @@ declare global {
prototype: HTMLIxBreadcrumbItemElement;
new (): HTMLIxBreadcrumbItemElement;
};
interface HTMLIxBurgerMenuElement extends Components.IxBurgerMenu, HTMLStencilElement {
}
var HTMLIxBurgerMenuElement: {
prototype: HTMLIxBurgerMenuElement;
new (): HTMLIxBurgerMenuElement;
};
interface HTMLIxButtonElement extends Components.IxButton, HTMLStencilElement {
}
var HTMLIxButtonElement: {
Expand Down Expand Up @@ -2104,6 +2116,7 @@ declare global {
"ix-blind": HTMLIxBlindElement;
"ix-breadcrumb": HTMLIxBreadcrumbElement;
"ix-breadcrumb-item": HTMLIxBreadcrumbItemElement;
"ix-burger-menu": HTMLIxBurgerMenuElement;
"ix-button": HTMLIxButtonElement;
"ix-category-filter": HTMLIxCategoryFilterElement;
"ix-chip": HTMLIxChipElement;
Expand Down Expand Up @@ -2206,7 +2219,7 @@ declare namespace LocalJSX {
*/
"applicationName"?: string;
/**
* Hide application header
* Hide application header. Will disable responsive feature of basic navigation.
*/
"hideHeader"?: boolean;
}
Expand Down Expand Up @@ -2256,6 +2269,12 @@ declare namespace LocalJSX {
*/
"label"?: string;
}
interface IxBurgerMenu {
/**
* Is menu displayed as expanded
*/
"expanded"?: boolean;
}
interface IxButton {
/**
* Disable the button
Expand Down Expand Up @@ -3834,6 +3853,7 @@ declare namespace LocalJSX {
"ix-blind": IxBlind;
"ix-breadcrumb": IxBreadcrumb;
"ix-breadcrumb-item": IxBreadcrumbItem;
"ix-burger-menu": IxBurgerMenu;
"ix-button": IxButton;
"ix-category-filter": IxCategoryFilter;
"ix-chip": IxChip;
Expand Down Expand Up @@ -3909,6 +3929,7 @@ declare module "@stencil/core" {
"ix-blind": LocalJSX.IxBlind & JSXBase.HTMLAttributes<HTMLIxBlindElement>;
"ix-breadcrumb": LocalJSX.IxBreadcrumb & JSXBase.HTMLAttributes<HTMLIxBreadcrumbElement>;
"ix-breadcrumb-item": LocalJSX.IxBreadcrumbItem & JSXBase.HTMLAttributes<HTMLIxBreadcrumbItemElement>;
"ix-burger-menu": LocalJSX.IxBurgerMenu & JSXBase.HTMLAttributes<HTMLIxBurgerMenuElement>;
"ix-button": LocalJSX.IxButton & JSXBase.HTMLAttributes<HTMLIxButtonElement>;
"ix-category-filter": LocalJSX.IxCategoryFilter & JSXBase.HTMLAttributes<HTMLIxCategoryFilterElement>;
"ix-chip": LocalJSX.IxChip & JSXBase.HTMLAttributes<HTMLIxChipElement>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,11 @@
color: var(--theme-app-header-logo--color);
}
}

:host(.mode-mobile) {
padding-left: 0.5rem;

.logo {
margin-left: 0.5rem;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
* LICENSE file in the root directory of this source tree.
*/

import { Component, Element, h, Host, Prop } from '@stencil/core';
import { Component, Element, h, Host, Prop, State } from '@stencil/core';
import { menuController } from '../utils/menu-service/menu-service';
import { hostContext, isBasicNavigationLayout } from '../utils/screen/context';
import { Mode } from '../utils/screen/mode';
import { screenMode } from '../utils/screen/service';
import { Disposable } from '../utils/typed-event';

@Component({
tag: 'ix-application-header',
Expand All @@ -22,10 +27,36 @@ export class ApplicationHeader {
*/
@Prop() name: string;

@State() mode: Mode = 'desktop';

@State() menuExpanded = false;

private menuDisposable?: Disposable;
private modeDisposable?: Disposable;

componentWillLoad() {
const layout = hostContext('ix-basic-navigation', this.host);
if (isBasicNavigationLayout(layout)) {
this.modeDisposable = screenMode.onChange.on(
(mode) => (this.mode = mode)
);
this.mode = screenMode.mode;

this.menuDisposable = menuController.expandChange.on((show) => {
this.menuExpanded = show;
});
}
}

componentDidLoad() {
this.attachSiemensLogoIfLoaded();
}

disconnectedCallback() {
this.menuDisposable?.dispose();
this.modeDisposable?.dispose();
}

private async attachSiemensLogoIfLoaded() {
await window.customElements.whenDefined('ix-siemens-logo');
const logoElement = document.createElement('ix-siemens-logo');
Expand All @@ -35,9 +66,19 @@ export class ApplicationHeader {
}
}

private async onMenuClick() {
menuController.toggle();
}

render() {
return (
<Host>
<Host class={{ [`mode-${this.mode}`]: true }}>
{this.mode === 'mobile' ? (
<ix-burger-menu
onClick={() => this.onMenuClick()}
expanded={this.menuExpanded}
></ix-burger-menu>
) : null}
<div class="logo">
<slot name="logo"></slot>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,15 @@ import { newSpecPage } from '@stencil/core/testing';
import { ApplicationHeader } from '../application-header';

describe('ix-application-header', () => {
it('renders', async () => {
it('desktop mode', async () => {
const page = await newSpecPage({
components: [ApplicationHeader],
html: `<ix-application-header name="Test App">
<div slot="logo">LOGO</div>
</ix-application-header>`,
});
expect(page.root).toEqualHtml(`
<ix-application-header name="Test App">
<mock:shadow-root>
<div class="logo">
<slot name="logo"></slot>
</div>
<div class="name">
Test App
</div>
<slot></slot>
</mock:shadow-root>
<div slot="logo">
LOGO
</div>
</ix-application-header>
`);

const header = page.doc.querySelector('ix-application-header');
expect(header.className).toContain('mode-desktop');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,10 @@
}
}
}

:host(.mode-mobile) {
.content {
margin-left: 0px;
width: 100%;
}
}
26 changes: 24 additions & 2 deletions packages/core/src/components/basic-navigation/basic-navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
* LICENSE file in the root directory of this source tree.
*/

import { Component, Element, h, Host, Prop } from '@stencil/core';
import { Component, Element, h, Host, Prop, State } from '@stencil/core';
import { Mode } from '../utils/screen/mode';
import { screenMode } from '../utils/screen/service';
import { Disposable } from '../utils/typed-event';

@Component({
tag: 'ix-basic-navigation',
Expand All @@ -23,14 +26,27 @@ export class BasicNavigation {
@Prop() applicationName: string;

/**
* Hide application header
* Hide application header. Will disable responsive feature of basic navigation.
*/
@Prop() hideHeader = false;

@State() mode: Mode = 'desktop';

get menu(): HTMLIxMenuElement {
return this.hostElement.querySelector('ix-menu');
}

private modeDisposable: Disposable;

componentWillLoad() {
if (this.hideHeader === false) {
this.modeDisposable = screenMode.onChange.on(
(mode) => (this.mode = mode)
);
this.mode = screenMode.mode;
}
}

componentDidRender() {
if (this.menu) {
this.appendMenu();
Expand All @@ -39,6 +55,10 @@ export class BasicNavigation {
}
}

disconnectedCallback() {
this.modeDisposable?.dispose();
}

private appendMenu() {
this.hostElement.querySelector('#menu-placeholder').appendChild(this.menu);
}
Expand All @@ -52,8 +72,10 @@ export class BasicNavigation {
render() {
return (
<Host
data-role=""
class={{
'hide-header': this.hideHeader,
[`mode-${this.mode}`]: true,
}}
>
{!this.hideHeader ? (
Expand Down
Loading