From a0a710079b4381df2927fb04ad56ad367598d75b Mon Sep 17 00:00:00 2001 From: Alex <25013571+alexhb1@users.noreply.github.com> Date: Tue, 12 May 2026 22:05:47 +0100 Subject: [PATCH] feat(ui): add native control CSS system + button/text/tab examples (#1267) --- .../bookdrop-file-review.component.scss | 2 +- .../command-palette.component.scss | 6 +- .../button/app-button-group.directive.ts | 10 + .../components/button/app-button.directive.ts | 21 ++ .../components/tabs/app-tabs.component.html | 33 +++ .../components/tabs/app-tabs.component.ts | 129 +++++++++++ .../text-field/app-text-field.directive.ts | 10 + .../app.mobile-topbar.component.scss | 2 +- .../layout-sidebar/app.sidebar.component.html | 9 +- .../layout-sidebar/app.sidebar.component.ts | 2 + .../layout/theme-palette-extend.spec.ts | 4 +- .../app/shared/layout/theme-palette-extend.ts | 4 +- .../shared/service/app-config.service.spec.ts | 12 +- .../app/shared/service/app-config.service.ts | 6 +- .../assets/layout/styles/layout/_content.scss | 2 +- .../assets/layout/styles/layout/_main.scss | 2 +- .../layout/styles/layout/_responsive.scss | 2 +- .../assets/layout/styles/layout/_sidebar.scss | 2 +- frontend/src/assets/styles/base.scss | 4 +- frontend/src/assets/styles/buttons.scss | 136 +++++++++++ .../src/assets/styles/control-groups.scss | 55 +++++ frontend/src/assets/styles/overlays.scss | 65 +----- frontend/src/assets/styles/page.scss | 2 +- frontend/src/assets/styles/tabs.scss | 218 ++++++++++++++++++ frontend/src/assets/styles/text-fields.scss | 47 ++++ frontend/src/assets/styles/tokens.css | 42 +++- frontend/src/assets/styles/utilities.scss | 27 +++ frontend/src/styles.scss | 4 + 28 files changed, 771 insertions(+), 87 deletions(-) create mode 100644 frontend/src/app/shared/components/button/app-button-group.directive.ts create mode 100644 frontend/src/app/shared/components/button/app-button.directive.ts create mode 100644 frontend/src/app/shared/components/tabs/app-tabs.component.html create mode 100644 frontend/src/app/shared/components/tabs/app-tabs.component.ts create mode 100644 frontend/src/app/shared/components/text-field/app-text-field.directive.ts create mode 100644 frontend/src/assets/styles/buttons.scss create mode 100644 frontend/src/assets/styles/control-groups.scss create mode 100644 frontend/src/assets/styles/tabs.scss create mode 100644 frontend/src/assets/styles/text-fields.scss diff --git a/frontend/src/app/features/bookdrop/component/bookdrop-file-review/bookdrop-file-review.component.scss b/frontend/src/app/features/bookdrop/component/bookdrop-file-review/bookdrop-file-review.component.scss index 74043a33d..5882413f5 100644 --- a/frontend/src/app/features/bookdrop/component/bookdrop-file-review/bookdrop-file-review.component.scss +++ b/frontend/src/app/features/bookdrop/component/bookdrop-file-review/bookdrop-file-review.component.scss @@ -6,7 +6,7 @@ box-sizing: border-box; height: 100%; overflow: hidden; - background: var(--page-background); + background: var(--surface-page); @media #{variables.$mobile-shell-media-query} { padding: var(--space-4); diff --git a/frontend/src/app/features/command-palette/command-palette.component.scss b/frontend/src/app/features/command-palette/command-palette.component.scss index 8c5fdd454..ce3465b57 100644 --- a/frontend/src/app/features/command-palette/command-palette.component.scss +++ b/frontend/src/app/features/command-palette/command-palette.component.scss @@ -267,7 +267,7 @@ .command-palette { max-height: 100dvh; - background: var(--app-background); + background: var(--surface-app); border: none; border-radius: 0; box-shadow: none; @@ -277,7 +277,7 @@ box-sizing: border-box; flex-shrink: 0; height: 3.5rem; - background: var(--app-background); + background: var(--surface-app); border-bottom: 1px solid var(--border-color); &:has(+ .command-palette-results) .command-palette-input-row { @@ -314,7 +314,7 @@ .command-palette-results, .command-palette-empty { - background: var(--page-background); + background: var(--surface-page); } .command-palette-empty { diff --git a/frontend/src/app/shared/components/button/app-button-group.directive.ts b/frontend/src/app/shared/components/button/app-button-group.directive.ts new file mode 100644 index 000000000..7f2a51015 --- /dev/null +++ b/frontend/src/app/shared/components/button/app-button-group.directive.ts @@ -0,0 +1,10 @@ +import {Directive} from '@angular/core'; + +@Directive({ + selector: '[appButtonGroup]', + standalone: true, + host: { + class: 'app-control-group app-control-group-inline', + }, +}) +export class AppButtonGroupDirective {} diff --git a/frontend/src/app/shared/components/button/app-button.directive.ts b/frontend/src/app/shared/components/button/app-button.directive.ts new file mode 100644 index 000000000..52c780bd6 --- /dev/null +++ b/frontend/src/app/shared/components/button/app-button.directive.ts @@ -0,0 +1,21 @@ +import {booleanAttribute, Directive, input} from '@angular/core'; + +export type AppButtonVariant = 'neutral' | 'primary' | 'danger'; +export type AppButtonSize = 'sm' | 'md'; + +@Directive({ + selector: 'button[appButton], a[appButton]', + standalone: true, + host: { + class: 'app-button', + '[class.app-button-primary]': 'variant() === "primary"', + '[class.app-button-danger]': 'variant() === "danger"', + '[class.app-button-sm]': 'size() === "sm"', + '[class.app-button-icon]': 'iconOnly()', + }, +}) +export class AppButtonDirective { + readonly variant = input('neutral'); + readonly size = input('md'); + readonly iconOnly = input(false, {transform: booleanAttribute}); +} diff --git a/frontend/src/app/shared/components/tabs/app-tabs.component.html b/frontend/src/app/shared/components/tabs/app-tabs.component.html new file mode 100644 index 000000000..2febc09b5 --- /dev/null +++ b/frontend/src/app/shared/components/tabs/app-tabs.component.html @@ -0,0 +1,33 @@ +@if (tabs().length) { +
+
+ + @for (tab of tabs(); track tab.id) { + + } +
+
+} diff --git a/frontend/src/app/shared/components/tabs/app-tabs.component.ts b/frontend/src/app/shared/components/tabs/app-tabs.component.ts new file mode 100644 index 000000000..75009e16f --- /dev/null +++ b/frontend/src/app/shared/components/tabs/app-tabs.component.ts @@ -0,0 +1,129 @@ +import { + afterRenderEffect, + ChangeDetectionStrategy, + Component, + DestroyRef, + computed, + inject, + input, + model, + signal, + viewChildren, +} from '@angular/core'; +import {Tab as NgTab, TabList, Tabs} from '@angular/aria/tabs'; + +export interface TabItem { + id: string; + label: string; + icon?: string; +} + +export type TabsVariant = 'underline' | 'segmented'; +export type TabsPlacement = 'inline' | 'below'; + +@Component({ + selector: 'app-tabs', + standalone: true, + imports: [Tabs, TabList, NgTab], + templateUrl: './app-tabs.component.html', + changeDetection: ChangeDetectionStrategy.OnPush, + host: { + '[class.variant-underline]': 'variant() === "underline"', + '[class.variant-segmented]': 'variant() === "segmented"', + '[class.placement-inline]': 'placement() === "inline"', + '[class.placement-below]': 'placement() === "below"', + }, +}) +export class AppTabsComponent { + readonly tabs = input.required(); + readonly variant = input('underline'); + readonly placement = input('below'); + readonly ariaLabel = input.required(); + readonly selectedTabId = model(undefined); + + private readonly destroyRef = inject(DestroyRef); + private readonly tabDirectives = viewChildren(NgTab); + + protected readonly activeTabId = computed(() => this.selectedTabId() ?? this.tabs()[0]?.id); + protected readonly indicatorLeft = signal(0); + protected readonly indicatorWidth = signal(0); + protected readonly indicatorVisible = signal(false); + protected readonly indicatorAnimated = signal(false); + + private pendingAnimationFrame: number | null = null; + private initialRevealScheduled = false; + + constructor() { + let resizeObserver: ResizeObserver | null = null; + + afterRenderEffect(() => { + this.tabs(); + this.variant(); + this.placement(); + this.activeTabId(); + this.scheduleMeasure(); + + const tabs = this.tabDirectives(); + if (tabs.length && typeof ResizeObserver !== 'undefined') { + resizeObserver ??= new ResizeObserver(() => this.scheduleMeasure()); + resizeObserver.disconnect(); + for (const tab of tabs) { + resizeObserver.observe(tab.element); + } + } + }); + + this.destroyRef.onDestroy(() => { + resizeObserver?.disconnect(); + if (this.pendingAnimationFrame !== null) { + cancelAnimationFrame(this.pendingAnimationFrame); + } + }); + } + + private measure(): void { + const activeTabId = this.activeTabId(); + const active = this.tabDirectives().find(tab => tab.value() === activeTabId); + if (!active) { + this.indicatorVisible.set(false); + return; + } + this.indicatorLeft.set(active.element.offsetLeft); + this.indicatorWidth.set(active.element.offsetWidth); + if (!this.indicatorVisible()) { + this.scheduleInitialReveal(); + return; + } + this.indicatorAnimated.set(true); + } + + private scheduleMeasure(): void { + if (this.pendingAnimationFrame !== null) { + cancelAnimationFrame(this.pendingAnimationFrame); + } + + this.pendingAnimationFrame = requestAnimationFrame(() => { + this.pendingAnimationFrame = null; + this.measure(); + }); + } + + private scheduleInitialReveal(): void { + if (this.initialRevealScheduled) return; + this.initialRevealScheduled = true; + + void document.fonts.ready.then(() => { + if (this.pendingAnimationFrame !== null) { + cancelAnimationFrame(this.pendingAnimationFrame); + } + this.pendingAnimationFrame = requestAnimationFrame(() => { + this.measure(); + this.indicatorVisible.set(true); + this.pendingAnimationFrame = requestAnimationFrame(() => { + this.pendingAnimationFrame = null; + this.indicatorAnimated.set(true); + }); + }); + }); + } +} diff --git a/frontend/src/app/shared/components/text-field/app-text-field.directive.ts b/frontend/src/app/shared/components/text-field/app-text-field.directive.ts new file mode 100644 index 000000000..d4b9bdbe6 --- /dev/null +++ b/frontend/src/app/shared/components/text-field/app-text-field.directive.ts @@ -0,0 +1,10 @@ +import {Directive} from '@angular/core'; + +@Directive({ + selector: 'input[appTextField]', + standalone: true, + host: { + class: 'app-text-field', + }, +}) +export class AppTextFieldDirective {} diff --git a/frontend/src/app/shared/layout/layout-mobile-topbar/app.mobile-topbar.component.scss b/frontend/src/app/shared/layout/layout-mobile-topbar/app.mobile-topbar.component.scss index 385d9dce0..a5c4ae18e 100644 --- a/frontend/src/app/shared/layout/layout-mobile-topbar/app.mobile-topbar.component.scss +++ b/frontend/src/app/shared/layout/layout-mobile-topbar/app.mobile-topbar.component.scss @@ -13,7 +13,7 @@ box-sizing: border-box; height: 3.5rem; z-index: 100; - background-color: var(--app-background); + background-color: var(--surface-app); border-bottom: 1px solid var(--content-border-color); padding: 0 diff --git a/frontend/src/app/shared/layout/layout-sidebar/app.sidebar.component.html b/frontend/src/app/shared/layout/layout-sidebar/app.sidebar.component.html index 0b701bfad..8dac6f99e 100644 --- a/frontend/src/app/shared/layout/layout-sidebar/app.sidebar.component.html +++ b/frontend/src/app/shared/layout/layout-sidebar/app.sidebar.component.html @@ -289,14 +289,14 @@ (overlayKeydown)="onUserPopoverKeydown($event)" >