From 9abf6db279e699fa66edb2dc9c4a86826fc5f22a Mon Sep 17 00:00:00 2001 From: Michael Haufe Date: Fri, 2 Feb 2024 19:55:19 -0600 Subject: [PATCH] Implemented Settings page --- src/presentation/Application.mts | 6 ++++- src/presentation/components/FeatherIcon.mts | 1 + src/presentation/components/GlobalNav.mts | 29 ++++++++++++++------- src/presentation/pages/SettingsPage.mts | 23 ++++++++++++++++ 4 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 src/presentation/pages/SettingsPage.mts diff --git a/src/presentation/Application.mts b/src/presentation/Application.mts index e3508044..e3f49fb7 100644 --- a/src/presentation/Application.mts +++ b/src/presentation/Application.mts @@ -23,7 +23,10 @@ export default class Application extends Container { const { template, section, slot } = html; return template([ - new GlobalNav(), + new GlobalNav([ + { href: '/', label: 'Home', icon: 'home', active: true }, + { href: '/-settings-', label: 'Settings', icon: 'settings' } + ]), new Breadcrumb(), section({ id: 'content' }, slot()) ]); @@ -65,6 +68,7 @@ export default class Application extends Container { this.#pages = [ (await import('./pages/HomePage.mjs')).default, NotFoundPage, + (await import('./pages/SettingsPage.mjs')).default, (await import('./pages/solution/project/ProjectsIndexPage.mjs')).default, (await import('./pages/solution/environment/EnvironmentsIndexPage.mjs')).default, (await import('./pages/solution/environment/GlossaryPage.mjs')).default, diff --git a/src/presentation/components/FeatherIcon.mts b/src/presentation/components/FeatherIcon.mts index f2d16ef0..2abde3b7 100644 --- a/src/presentation/components/FeatherIcon.mts +++ b/src/presentation/components/FeatherIcon.mts @@ -24,6 +24,7 @@ export class FeatherIcon extends Component { return { ...super._initShadowStyle(), '.feather-icon': { + fill: 'none', stroke: 'currentColor', display: 'inline-block', height: 'var(--size)', diff --git a/src/presentation/components/GlobalNav.mts b/src/presentation/components/GlobalNav.mts index 8dcde6eb..293bc9a3 100644 --- a/src/presentation/components/GlobalNav.mts +++ b/src/presentation/components/GlobalNav.mts @@ -1,7 +1,13 @@ import { Component, FeatherIcon } from './index.mjs'; import type { FeatherIconName } from '~/types/FeatherIconName.mjs'; import html from '../lib/html.mjs'; -import type { Properties } from '~/types/Properties.mjs'; + +export interface GlobalNavLink { + href: string; + label: string; + icon: FeatherIconName; + active?: boolean; +} /** * Determines if the path is the current path @@ -10,17 +16,24 @@ import type { Properties } from '~/types/Properties.mjs'; * @returns True if the path is the current path, false otherwise. */ const isActive = (path: string, target: string): boolean => - target.includes(path); + path === '/' ? target === '/' : + target.includes(path); export class GlobalNav extends Component { static { customElements.define('x-global-nav', this); } - constructor(properties: Partial> = {}) { - super(properties); + constructor(routes: GlobalNavLink[]) { + super({}); self.navigation.addEventListener('navigate', this); + + this.shadowRoot.querySelector('ul')!.append( + ...routes.map(({ href, icon, label, active }) => + this._routerLink(href, icon, label, Boolean(active)) + ) + ); } protected override _initShadowStyle() { @@ -79,15 +92,13 @@ export class GlobalNav extends Component { protected override _initShadowHtml() { const { nav, ul, template } = html; - return template(nav({ className: 'global-nav' }, ul([ - this._routerLink('/', 'home', 'Home') - ]))); + return template(nav({ className: 'global-nav' }, ul())); } - protected _routerLink(path: string, iconName: FeatherIconName, text: string): HTMLLIElement { + protected _routerLink(path: string, iconName: FeatherIconName, text: string, active: boolean): HTMLLIElement { const { a, li } = html; - return li(a({ href: path }, [ + return li(a({ href: path, className: active ? 'link-active' : '' }, [ new FeatherIcon({ icon: iconName }), text ])); diff --git a/src/presentation/pages/SettingsPage.mts b/src/presentation/pages/SettingsPage.mts new file mode 100644 index 00000000..257b797c --- /dev/null +++ b/src/presentation/pages/SettingsPage.mts @@ -0,0 +1,23 @@ +import html from '../lib/html.mjs'; +import Page from './Page.mjs'; +import pkg from '~/../package.json' with { type: 'json' }; + +const { h1, table, tr, td } = html; + +export default class SettingPage extends Page { + static override route = '/-settings-'; + static { + customElements.define('x-page-settings', this); + } + + constructor() { + super({ title: 'Settings' }); + + this.append( + h1('Settings'), + table( + tr([td('Version:'), td(pkg.version)]) + ) + ); + } +} \ No newline at end of file