feat(ui): add native control CSS system + button/text/tab examples (#1267)
This commit is contained in:
+1
-1
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {}
|
||||
@@ -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<AppButtonVariant>('neutral');
|
||||
readonly size = input<AppButtonSize>('md');
|
||||
readonly iconOnly = input(false, {transform: booleanAttribute});
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
@if (tabs().length) {
|
||||
<div ngTabs class="app-tabs-root">
|
||||
<div
|
||||
ngTabList
|
||||
class="app-tabs"
|
||||
[class.is-measured]="indicatorVisible()"
|
||||
[class.is-animated]="indicatorAnimated()"
|
||||
[(selectedTab)]="selectedTabId"
|
||||
[attr.aria-label]="ariaLabel()"
|
||||
>
|
||||
<span
|
||||
class="app-tabs-indicator"
|
||||
aria-hidden="true"
|
||||
[style.transform]="'translateX(' + indicatorLeft() + 'px)'"
|
||||
[style.width.px]="indicatorWidth()"
|
||||
></span>
|
||||
@for (tab of tabs(); track tab.id) {
|
||||
<button
|
||||
ngTab
|
||||
type="button"
|
||||
[id]="tab.id"
|
||||
[value]="tab.id"
|
||||
class="app-tab"
|
||||
>
|
||||
@if (tab.icon) {
|
||||
<i [class]="'app-tab-icon ' + tab.icon" aria-hidden="true"></i>
|
||||
}
|
||||
<span class="app-tab-label">{{ tab.label }}</span>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@@ -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<TabItem[]>();
|
||||
readonly variant = input<TabsVariant>('underline');
|
||||
readonly placement = input<TabsPlacement>('below');
|
||||
readonly ariaLabel = input.required<string>();
|
||||
readonly selectedTabId = model<string | undefined>(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);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import {Directive} from '@angular/core';
|
||||
|
||||
@Directive({
|
||||
selector: 'input[appTextField]',
|
||||
standalone: true,
|
||||
host: {
|
||||
class: 'app-text-field',
|
||||
},
|
||||
})
|
||||
export class AppTextFieldDirective {}
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -289,14 +289,14 @@
|
||||
(overlayKeydown)="onUserPopoverKeydown($event)"
|
||||
>
|
||||
<section
|
||||
class="user-account-popover"
|
||||
class="user-account-popover surface-page"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
cdkTrapFocus
|
||||
cdkTrapFocusAutoCapture
|
||||
[attr.aria-label]="'settingsProfile.title' | transloco"
|
||||
>
|
||||
<header class="user-account-popover-header">
|
||||
<header class="user-account-popover-header surface-card">
|
||||
<div class="user-account-popover-title-row">
|
||||
<h2>Grimmory <span>{{ appVersionLabel() }}</span></h2>
|
||||
<button
|
||||
@@ -312,8 +312,8 @@
|
||||
|
||||
<div class="user-account-popover-header-actions">
|
||||
<button
|
||||
appButton
|
||||
type="button"
|
||||
class="user-account-popover-settings"
|
||||
(click)="openSettings()"
|
||||
>
|
||||
<i class="pi pi-cog" aria-hidden="true"></i>
|
||||
@@ -322,8 +322,9 @@
|
||||
|
||||
@if (updateAvailable()) {
|
||||
<button
|
||||
appButton
|
||||
variant="primary"
|
||||
type="button"
|
||||
class="user-account-popover-update"
|
||||
(click)="openChangelogDialog()"
|
||||
>
|
||||
<i class="pi pi-arrow-up-right" aria-hidden="true"></i>
|
||||
|
||||
@@ -7,6 +7,7 @@ import { CdkTrapFocus } from '@angular/cdk/a11y';
|
||||
import { CdkConnectedOverlay, CdkOverlayOrigin } from '@angular/cdk/overlay';
|
||||
import { BookDialogHelperService } from '../../../features/book/components/book-browser/book-dialog-helper.service';
|
||||
import { UnifiedNotificationBoxComponent } from '../../components/unified-notification-popover/unified-notification-popover-component';
|
||||
import { AppButtonDirective } from '../../components/button/app-button.directive';
|
||||
import { MenuComponent } from '../../components/menu/menu.component';
|
||||
import { MenuEntry } from '../../components/menu/menu-item.model';
|
||||
import {
|
||||
@@ -89,6 +90,7 @@ function isNewerVersion(latest: string | undefined, current: string | undefined)
|
||||
selector: 'app-sidebar',
|
||||
imports: [
|
||||
AppSidebarSectionComponent,
|
||||
AppButtonDirective,
|
||||
Popover,
|
||||
UnifiedNotificationBoxComponent,
|
||||
MenuComponent,
|
||||
|
||||
@@ -31,7 +31,7 @@ describe('theme-palette-extend', () => {
|
||||
expect(auraPrimitive['skyBlue']['700']).toBe('#2e88e6');
|
||||
expect(auraPrimitive['dustyNeutral']['950']).toBe('#2f2821');
|
||||
expect(preset.primitive?.['coralSunset']['500']).toBe('#ef7550');
|
||||
expect(preset.semantic?.colorScheme?.light?.content?.background).toBe('var(--page-background)');
|
||||
expect(preset.semantic?.colorScheme?.dark?.content?.background).toBe('var(--page-background)');
|
||||
expect(preset.semantic?.colorScheme?.light?.content?.background).toBe('var(--surface-page)');
|
||||
expect(preset.semantic?.colorScheme?.dark?.content?.background).toBe('var(--surface-page)');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -232,8 +232,8 @@ Object.assign(Aura.primitive, customPalettes);
|
||||
const AppPrimePreset = definePreset(Aura, {
|
||||
semantic: {
|
||||
colorScheme: {
|
||||
light: { content: { background: 'var(--page-background)' } },
|
||||
dark: { content: { background: 'var(--page-background)' } }
|
||||
light: { content: { background: 'var(--surface-page)' } },
|
||||
dark: { content: { background: 'var(--surface-page)' } }
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -56,10 +56,10 @@ describe('AppConfigService', () => {
|
||||
expect(rootStyle.getPropertyValue('--primary-400')).toBe('#fb923c');
|
||||
expect(rootStyle.getPropertyValue('--primary-500')).toBe('#f97316');
|
||||
expect(rootStyle.getPropertyValue('--primary-color')).toBe('#fb923c');
|
||||
expect(rootStyle.getPropertyValue('--app-background')).toBe('#0d1012');
|
||||
expect(rootStyle.getPropertyValue('--page-background')).toBe('color-mix(in srgb, #1a1e21 82%, #0d1012)');
|
||||
expect(rootStyle.getPropertyValue('--surface-app')).toBe('#0d1012');
|
||||
expect(rootStyle.getPropertyValue('--surface-page')).toBe('color-mix(in srgb, #1a1e21 82%, #0d1012)');
|
||||
expect(rootStyle.getPropertyValue('--surface-content')).toBe('#1a1e21');
|
||||
expect(rootStyle.getPropertyValue('--ground-background')).toBe('var(--app-background)');
|
||||
expect(rootStyle.getPropertyValue('--ground-background')).toBe('var(--surface-app)');
|
||||
expect(rootStyle.getPropertyValue('--content-border-color')).toBe('var(--border-subtle)');
|
||||
expect(faviconServiceMock.updateFavicon).toHaveBeenCalledWith('#fdba74', '#f97316');
|
||||
});
|
||||
@@ -76,9 +76,9 @@ describe('AppConfigService', () => {
|
||||
expect(rootStyle.getPropertyValue('--primary-300')).toBe('#f9be9e');
|
||||
expect(rootStyle.getPropertyValue('--primary-500')).toBe('#ef7550');
|
||||
expect(rootStyle.getPropertyValue('--primary-color-rgb')).toBe('239, 117, 80');
|
||||
expect(rootStyle.getPropertyValue('--app-background')).toBe('#121518');
|
||||
expect(rootStyle.getPropertyValue('--page-background')).toBe('color-mix(in srgb, #1f252c 82%, #121518)');
|
||||
expect(rootStyle.getPropertyValue('--ground-background')).toBe('var(--app-background)');
|
||||
expect(rootStyle.getPropertyValue('--surface-app')).toBe('#121518');
|
||||
expect(rootStyle.getPropertyValue('--surface-page')).toBe('color-mix(in srgb, #1f252c 82%, #121518)');
|
||||
expect(rootStyle.getPropertyValue('--ground-background')).toBe('var(--surface-app)');
|
||||
expect(rootStyle.getPropertyValue('--surface-card')).toBe('color-mix(in srgb, #1f252c 62%, #38424d)');
|
||||
expect(rootStyle.getPropertyValue('--card-background')).toBe('var(--surface-card)');
|
||||
expect(faviconServiceMock.updateFavicon).toHaveBeenLastCalledWith('#f9be9e', '#ef7550');
|
||||
|
||||
@@ -502,8 +502,8 @@ export class AppConfigService {
|
||||
style.setProperty('--primary-text-color', primary400 ?? '#fb923c');
|
||||
style.setProperty('--primary-text-color-dark', theme.isNoir ? (theme.surface['950'] ?? '#0d1012') : (theme.primary['900'] ?? '#9a3412'));
|
||||
|
||||
style.setProperty('--app-background', appBackground);
|
||||
style.setProperty('--page-background', pageBackground);
|
||||
style.setProperty('--surface-app', appBackground);
|
||||
style.setProperty('--surface-page', pageBackground);
|
||||
style.setProperty('--surface-content', surfaceContent);
|
||||
style.setProperty('--surface-card', surfaceCard);
|
||||
style.setProperty('--surface-toolbar', `color-mix(in srgb, ${appBackground} 70%, ${surfaceContent})`);
|
||||
@@ -513,7 +513,7 @@ export class AppConfigService {
|
||||
style.setProperty('--state-hover', 'color-mix(in srgb, var(--surface-400) 12%, transparent)');
|
||||
style.setProperty('--state-active', 'color-mix(in srgb, var(--primary-color) 8%, transparent)');
|
||||
|
||||
style.setProperty('--ground-background', 'var(--app-background)');
|
||||
style.setProperty('--ground-background', 'var(--surface-app)');
|
||||
style.setProperty('--overlay-background', 'var(--surface-overlay)');
|
||||
style.setProperty('--card-background', 'var(--surface-card)');
|
||||
style.setProperty('--content-background', 'var(--surface-content)');
|
||||
|
||||
Reference in New Issue
Block a user