refactor(ui): new component library (#1740)
This commit is contained in:
+2
-4
@@ -79,11 +79,9 @@
|
||||
@case ('rating') {
|
||||
<span class="rating-wrapper" [title]="cell.rating === null ? '' : cell.display">
|
||||
<app-rating
|
||||
[value]="cell.rating"
|
||||
readonly
|
||||
[value]="cell.rating ?? 0"
|
||||
[ariaLabel]="cell.rating === null ? t('book.table.noRating') : t('book.table.ratingOutOf', {rating: cell.display, max: 5})" />
|
||||
@if (cell.rating !== null) {
|
||||
<span class="rating-value">({{ cell.display }})</span>
|
||||
}
|
||||
</span>
|
||||
}
|
||||
@case ('clickable') {
|
||||
|
||||
-5
@@ -162,11 +162,6 @@
|
||||
min-width: 6.125rem;
|
||||
}
|
||||
|
||||
.rating-value {
|
||||
color: inherit;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.cell-link {
|
||||
overflow: hidden;
|
||||
color: var(--color-primary-text);
|
||||
|
||||
+2
-1
@@ -85,7 +85,8 @@ describe('BookTableRowComponent', () => {
|
||||
expect(links[0]?.textContent?.trim()).toBe('Alpha');
|
||||
expect(links[0]?.getAttribute('href')).toBe('/book/1');
|
||||
expect(links[1]?.textContent?.trim()).toBe('Test Author');
|
||||
expect(rating?.textContent).toContain('(4.2)');
|
||||
expect(rating?.querySelector('app-rating')).toBeTruthy();
|
||||
expect(rating?.getAttribute('title')).toBe('4.2');
|
||||
expect(cells[3]?.textContent?.trim()).toBe('1.5 MB');
|
||||
});
|
||||
|
||||
|
||||
+2
-2
@@ -10,7 +10,7 @@ import {Book, BookMetadata} from '../../../model/book.model';
|
||||
import {ReadStatusHelper} from '../../../helpers/read-status.helper';
|
||||
import {UrlHelperService} from '../../../../../shared/service/url-helper.service';
|
||||
import {CoverPlaceholderComponent} from '../../../../../shared/components/cover-generator/cover-generator.component';
|
||||
import {RatingComponent} from '../../../../../shared/components/rating/rating.component';
|
||||
import {AppRatingComponent} from '../../../../../shared/ui/rating/app-rating.component';
|
||||
import {RATING_FIELDS, isMetadataFullyLocked} from './book-table.helpers';
|
||||
|
||||
interface BookTableCellLink {
|
||||
@@ -89,7 +89,7 @@ const CLICKABLE_FILTER_KEYS: Record<string, string> = {
|
||||
CoverPlaceholderComponent,
|
||||
FormsModule,
|
||||
NgClass,
|
||||
RatingComponent,
|
||||
AppRatingComponent,
|
||||
RouterLink,
|
||||
Tooltip,
|
||||
TranslocoDirective,
|
||||
|
||||
@@ -0,0 +1,608 @@
|
||||
<main cdkScrollable class="design-system-page">
|
||||
<header class="page-header flex flex-wrap items-center justify-between gap-3">
|
||||
<h1>Design System</h1>
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<app-button variant="soft" size="sm" icon="pi pi-folder" label="Create library" (clicked)="openExample('library')" />
|
||||
<app-button variant="soft" size="sm" icon="pi pi-mobile" label="Device settings" (clicked)="openExample('device')" />
|
||||
<app-button variant="soft" size="sm" icon="pi pi-list" label="Everything" (clicked)="openExample('everything')" />
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<section class="showcase-section">
|
||||
<h2>Buttons</h2>
|
||||
|
||||
<div class="variant-grid">
|
||||
@for (example of buttonExamples; track example.tone + example.variant) {
|
||||
<div class="variant-cell">
|
||||
<span class="variant-label">{{ example.tone }} / {{ example.variant }}</span>
|
||||
<div class="button-row">
|
||||
@for (size of buttonSizes; track size) {
|
||||
<app-button
|
||||
[tone]="example.tone"
|
||||
[variant]="example.variant"
|
||||
[size]="size"
|
||||
icon="pi pi-bolt"
|
||||
[label]="size" />
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="sample-row">
|
||||
<app-button iconOnly icon="pi pi-chevron-left" ariaLabel="Previous" />
|
||||
<app-button iconOnly rounded icon="pi pi-heart" ariaLabel="Favourite" />
|
||||
<app-button label="Loading" icon="pi pi-save" loading />
|
||||
<app-button label="Disabled" disabled />
|
||||
<app-button fluid label="Full width" />
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="showcase-section">
|
||||
<h2>Split Buttons</h2>
|
||||
|
||||
<div class="sample-row">
|
||||
<app-split-button
|
||||
tone="primary"
|
||||
label="Open"
|
||||
icon="pi pi-folder-open"
|
||||
[model]="menuItems" />
|
||||
<app-split-button
|
||||
label="Download"
|
||||
icon="pi pi-download"
|
||||
[model]="menuItems" />
|
||||
<app-split-button
|
||||
tone="danger"
|
||||
variant="soft"
|
||||
label="Delete"
|
||||
icon="pi pi-trash"
|
||||
[model]="menuItems" />
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="showcase-section">
|
||||
<h2>Inputs</h2>
|
||||
|
||||
<div class="input-grid">
|
||||
<div class="field">
|
||||
<span>Small</span>
|
||||
<app-input size="sm" placeholder="Small input" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Medium</span>
|
||||
<app-input [(value)]="inputValue" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Large</span>
|
||||
<app-input size="lg" placeholder="Large input" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Invalid</span>
|
||||
<app-input invalid value="Needs attention" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Disabled</span>
|
||||
<app-input disabled value="Disabled input" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Password</span>
|
||||
<app-input type="password" value="password" revealToggle />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Trailing Action</span>
|
||||
<app-input value="Search text" trailingIcon="pi pi-times" trailingAriaLabel="Clear text" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Leading Icon</span>
|
||||
<app-input type="search" leadingIcon="pi pi-search" placeholder="Search..." />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Leading + Trailing</span>
|
||||
<app-input
|
||||
type="search"
|
||||
value="Search text"
|
||||
leadingIcon="pi pi-search"
|
||||
trailingIcon="pi pi-times"
|
||||
trailingAriaLabel="Clear search" />
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="showcase-section">
|
||||
<h2>Number Inputs</h2>
|
||||
|
||||
<div class="input-grid">
|
||||
<div class="field">
|
||||
<span>Range (8-72)</span>
|
||||
<app-number-input [(value)]="fontSizeValue" [min]="8" [max]="72" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Step 0.5</span>
|
||||
<app-number-input [(value)]="weightValue" [min]="0" [max]="10" [step]="0.5" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>With unit</span>
|
||||
<app-number-input [value]="250" [min]="1" [max]="1000" unit="MB" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Disabled</span>
|
||||
<app-number-input [value]="42" disabled />
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="showcase-section">
|
||||
<h2>Sliders</h2>
|
||||
|
||||
<div class="flex max-w-md flex-col gap-5">
|
||||
<div class="field">
|
||||
<span>Range value ({{ aspectRatioValue.toFixed(1) }})</span>
|
||||
<app-slider [(value)]="aspectRatioValue" [min]="1.5" [max]="3" [step]="0.1" ariaLabel="Range value" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Percentage ({{ compressionValue }}%)</span>
|
||||
<app-slider [(value)]="compressionValue" [min]="1" [max]="100" ariaLabel="Percentage" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Disabled</span>
|
||||
<app-slider [value]="40" disabled ariaLabel="Disabled slider" />
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="showcase-section">
|
||||
<h2>Ratings</h2>
|
||||
|
||||
<div class="flex flex-col gap-5">
|
||||
<div class="field">
|
||||
<span>Expandable ({{ personalRating }})</span>
|
||||
<app-rating [(value)]="personalRating" expandable ariaLabel="Expandable rating" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Editable ({{ ratingValue }})</span>
|
||||
<app-rating [(value)]="ratingValue" ariaLabel="Editable rating" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Read-only</span>
|
||||
<app-rating [value]="4.3" readonly showValue />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Sizes</span>
|
||||
<div class="flex items-center gap-4">
|
||||
<app-rating [value]="3.5" readonly size="sm" />
|
||||
<app-rating [value]="3.5" readonly size="md" />
|
||||
<app-rating [value]="3.5" readonly size="lg" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Disabled</span>
|
||||
<app-rating [value]="3" disabled ariaLabel="Disabled rating" />
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="showcase-section">
|
||||
<h2>Checkboxes</h2>
|
||||
|
||||
<div class="input-grid">
|
||||
<div class="field">
|
||||
<span>Default</span>
|
||||
<app-checkbox ariaLabel="Default checkbox" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Checked</span>
|
||||
<app-checkbox [(checked)]="checkboxAccepted" ariaLabel="Checked checkbox" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Indeterminate</span>
|
||||
<app-checkbox [indeterminate]="true" ariaLabel="Indeterminate checkbox" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Disabled</span>
|
||||
<app-checkbox disabled [checked]="true" ariaLabel="Disabled checkbox" />
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="showcase-section">
|
||||
<h2>Switches</h2>
|
||||
|
||||
<div class="input-grid">
|
||||
<div class="field">
|
||||
<span>Off</span>
|
||||
<app-switch ariaLabel="Off switch" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>On</span>
|
||||
<app-switch [(checked)]="switchEnabled" ariaLabel="On switch" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Disabled</span>
|
||||
<app-switch disabled [checked]="true" ariaLabel="Disabled switch" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Small</span>
|
||||
<app-switch size="sm" [checked]="true" ariaLabel="Small switch" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Large</span>
|
||||
<app-switch size="lg" [checked]="true" ariaLabel="Large switch" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="input-grid">
|
||||
<app-field label="Labeled switch" hint="Inline help text.">
|
||||
<app-switch [(checked)]="switchEnabled" />
|
||||
</app-field>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="showcase-section">
|
||||
<h2>Radio Groups</h2>
|
||||
|
||||
<div class="input-grid">
|
||||
<div class="field">
|
||||
<span>List</span>
|
||||
<app-radio-group [(value)]="radioViewValue" [options]="radioViewOptions" ariaLabel="Options" />
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<span>Segmented</span>
|
||||
<app-radio-group variant="segmented" [(value)]="radioViewValue" [options]="radioViewOptions" ariaLabel="Segmented options" />
|
||||
</div>
|
||||
|
||||
<app-field label="Radio group" hint="Choose one.">
|
||||
<app-radio-group [formField]="profileForm.viewMode" [options]="radioViewOptions" />
|
||||
</app-field>
|
||||
</div>
|
||||
|
||||
<div class="input-grid">
|
||||
<app-radio-group variant="card" [(value)]="radioDensityValue" [options]="radioDensityOptions" ariaLabel="Card options" />
|
||||
|
||||
<app-field label="Card radio group" hint="Card layout with descriptions.">
|
||||
<app-radio-group variant="card" [(value)]="radioDensityValue" [options]="radioDensityOptions" />
|
||||
</app-field>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="showcase-section">
|
||||
<h2>Selects</h2>
|
||||
|
||||
<div class="input-grid">
|
||||
<div class="field">
|
||||
<span>Default</span>
|
||||
<app-select
|
||||
[(value)]="selectValue"
|
||||
[options]="selectOptions" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Small</span>
|
||||
<app-select
|
||||
size="sm"
|
||||
[options]="selectOptions"
|
||||
placeholder="Choose option" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Clearable</span>
|
||||
<app-select
|
||||
showClear
|
||||
[options]="selectOptions"
|
||||
placeholder="Choose option" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Filter</span>
|
||||
<app-select
|
||||
filter
|
||||
[options]="selectOptions"
|
||||
placeholder="Search options" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Grouped</span>
|
||||
<app-select
|
||||
[groups]="groupedSelectOptions"
|
||||
placeholder="Choose option" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Swatches</span>
|
||||
<app-select
|
||||
[(value)]="themeValue"
|
||||
[options]="themeSelectOptions">
|
||||
<ng-template appSelectSelected let-option>
|
||||
@if (option) {
|
||||
<span class="select-rich-option">
|
||||
<span class="select-swatch" [style.background]="$any(option).color"></span>
|
||||
<span>{{ $any(option).label }}</span>
|
||||
</span>
|
||||
}
|
||||
</ng-template>
|
||||
<ng-template appSelectOption let-option>
|
||||
<span class="select-rich-option">
|
||||
<span class="select-swatch" [style.background]="$any(option).color"></span>
|
||||
<span>{{ $any(option).label }}</span>
|
||||
</span>
|
||||
</ng-template>
|
||||
</app-select>
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Invalid</span>
|
||||
<app-select
|
||||
invalid
|
||||
[options]="selectOptions"
|
||||
placeholder="Choose option" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Disabled</span>
|
||||
<app-select
|
||||
disabled
|
||||
value="a"
|
||||
[options]="selectOptions" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Multiple</span>
|
||||
<app-multi-select
|
||||
showClear
|
||||
filter
|
||||
[(value)]="multiSelectValue"
|
||||
[options]="selectOptions"
|
||||
placeholder="Choose options" />
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="showcase-section">
|
||||
<h2>Date Pickers</h2>
|
||||
|
||||
<div class="input-grid">
|
||||
<div class="field">
|
||||
<span>Default</span>
|
||||
<app-date-picker [(value)]="dateValue" placeholder="Select a date" ariaLabel="Example date" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Small</span>
|
||||
<app-date-picker size="sm" [(value)]="dateValue" placeholder="Select a date" ariaLabel="Small date" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Bounded (this month)</span>
|
||||
<app-date-picker
|
||||
[(value)]="dateValue"
|
||||
minDate="2026-06-01"
|
||||
maxDate="2026-06-30"
|
||||
placeholder="Within June"
|
||||
ariaLabel="Bounded date" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Range</span>
|
||||
<app-date-range-picker [(value)]="dateRangeValue" placeholder="Select a range" ariaLabel="Date range" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<app-field [field]="profileForm.birthday" label="Birthday">
|
||||
<app-date-picker [formField]="profileForm.birthday" placeholder="Pick a date" />
|
||||
</app-field>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="showcase-section">
|
||||
<h2>Autocomplete</h2>
|
||||
|
||||
<div class="max-w-md">
|
||||
<app-autocomplete
|
||||
[(value)]="autocompleteValue"
|
||||
[suggestions]="filteredAutocompleteOptions()"
|
||||
(complete)="filterAutocompleteOptions($event)"
|
||||
placeholder="Start typing..."
|
||||
ariaLabel="Autocomplete" />
|
||||
</div>
|
||||
<div class="max-w-md">
|
||||
<app-multi-autocomplete
|
||||
[(value)]="tags"
|
||||
[suggestions]="filteredTags()"
|
||||
(complete)="filterTags($event)"
|
||||
placeholder="Add tags..."
|
||||
ariaLabel="Tags"
|
||||
removeTagLabel="Remove tag" />
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="showcase-section">
|
||||
<h2>Textareas</h2>
|
||||
|
||||
<div class="input-grid">
|
||||
<div class="field">
|
||||
<span>Default</span>
|
||||
<app-textarea [(value)]="textareaValue" rows="1" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Auto Resize</span>
|
||||
<app-textarea autoResize rows="2" value="Example text" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<span>Invalid</span>
|
||||
<app-textarea invalid rows="1" value="Needs attention" />
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="showcase-section">
|
||||
<h2>Form Fields</h2>
|
||||
|
||||
<div class="input-grid">
|
||||
<app-field label="Display name" hint="Required.">
|
||||
<app-input [formField]="profileForm.displayName" placeholder="Display name" />
|
||||
</app-field>
|
||||
|
||||
<app-field label="Email" hint="Valid email address.">
|
||||
<app-input type="email" [formField]="profileForm.email" placeholder="name@example.com" />
|
||||
</app-field>
|
||||
|
||||
<app-field label="Notes" hint="At least 10 characters.">
|
||||
<app-textarea [formField]="profileForm.bio" rows="2" placeholder="Notes" />
|
||||
</app-field>
|
||||
|
||||
<app-field label="Static error" hint="Hint stays visible with errors." [errors]="['Required field.']">
|
||||
<app-input value="Example value" invalid />
|
||||
</app-field>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="showcase-section">
|
||||
<h2>Messages</h2>
|
||||
|
||||
<div class="flex max-w-md flex-col gap-2">
|
||||
<app-message color="neutral">Neutral message.</app-message>
|
||||
<app-message color="primary">Primary message.</app-message>
|
||||
<app-message color="green">Success message.</app-message>
|
||||
<app-message color="amber">Warning message.</app-message>
|
||||
<app-message color="red">Error message.</app-message>
|
||||
</div>
|
||||
|
||||
<p class="text-sm text-text-muted dark:text-text-secondary">
|
||||
Group validation:
|
||||
</p>
|
||||
<div class="flex max-w-md flex-wrap items-center gap-2">
|
||||
<app-button label="Validate group" (clicked)="validateSyncGroup()" />
|
||||
<app-message inline [field]="syncForm.sync" />
|
||||
</div>
|
||||
|
||||
<p class="text-sm text-text-muted dark:text-text-secondary">
|
||||
Form summary:
|
||||
</p>
|
||||
<div class="flex max-w-md flex-col gap-2">
|
||||
<app-message [field]="profileForm" summary />
|
||||
<app-message [field]="profileForm" summary summaryLayout="inline" />
|
||||
<app-button label="Validate page" (clicked)="validateProfile()" />
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="showcase-section">
|
||||
<h2>Accordion</h2>
|
||||
|
||||
<div class="max-w-md">
|
||||
<app-accordion [items]="accordionItems" [(value)]="accordionValue">
|
||||
<ng-template appAccordionHeader let-item>{{ item.title }}</ng-template>
|
||||
<ng-template appAccordionActions>
|
||||
<app-button size="sm" variant="ghost" icon="pi pi-cog" iconOnly ariaLabel="Configure" />
|
||||
</ng-template>
|
||||
<ng-template appAccordionContent let-item>{{ item.body }}</ng-template>
|
||||
</app-accordion>
|
||||
</div>
|
||||
|
||||
<p class="text-sm text-text-muted dark:text-text-secondary">Multiple items open.</p>
|
||||
<div class="max-w-md">
|
||||
<app-accordion multiple [items]="accordionItems" [(value)]="accordionMultiValue">
|
||||
<ng-template appAccordionHeader let-item>
|
||||
<span class="inline-flex items-center gap-2"><i class="pi pi-folder text-text-muted" aria-hidden="true"></i>{{ item.title }}</span>
|
||||
</ng-template>
|
||||
<ng-template appAccordionContent let-item>{{ item.body }}</ng-template>
|
||||
</app-accordion>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="showcase-section">
|
||||
<h2>Spinners</h2>
|
||||
|
||||
<div class="flex flex-wrap items-center gap-6">
|
||||
<app-spinner size="sm" ariaLabel="Loading" />
|
||||
<app-spinner size="md" ariaLabel="Loading" />
|
||||
<app-spinner size="lg" ariaLabel="Loading" />
|
||||
<app-spinner size="lg" styleClass="text-text-muted" ariaLabel="Loading" />
|
||||
<span class="inline-flex items-center gap-2 text-sm text-text-muted dark:text-text-secondary">
|
||||
<app-spinner size="sm" ariaLabel="Loading" /> Loading...
|
||||
</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="showcase-section">
|
||||
<h2>Menus</h2>
|
||||
|
||||
<app-button label="Open menu" icon="pi pi-ellipsis-v" (clicked)="debugMenu.toggle($event)" />
|
||||
<app-menu #debugMenu [model]="menuItems" />
|
||||
</section>
|
||||
|
||||
<section class="showcase-section">
|
||||
<h2>Tooltips</h2>
|
||||
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<app-button label="Top" [appTooltip]="'Defaults to the top'" />
|
||||
<app-button label="Bottom" [appTooltip]="'Below the trigger'" appTooltipPosition="bottom" />
|
||||
<app-button label="Left" [appTooltip]="'To the left'" appTooltipPosition="left" />
|
||||
<app-button label="Right" [appTooltip]="'To the right'" appTooltipPosition="right" />
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="showcase-section">
|
||||
<h2>Tags</h2>
|
||||
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<app-tag label="Neutral" />
|
||||
<app-tag color="primary" label="Primary" />
|
||||
<app-tag color="green" label="Green" />
|
||||
<app-tag color="red" label="Red" />
|
||||
<app-tag color="amber" label="Amber" />
|
||||
<app-tag color="sky" label="Sky" />
|
||||
<app-tag color="blue" label="Blue" />
|
||||
<app-tag color="teal" label="Teal" />
|
||||
<app-tag color="indigo" label="Indigo" />
|
||||
<app-tag color="purple" label="Purple" />
|
||||
<app-tag color="pink" label="Pink" />
|
||||
</div>
|
||||
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<app-tag size="sm" color="green" label="Small" />
|
||||
<app-tag size="md" color="green" label="Medium" />
|
||||
<app-tag color="amber" icon="pi pi-exclamation-triangle" label="With icon" />
|
||||
<app-tag color="sky">Projected content</app-tag>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<app-tag color="blue" clickable label="Clickable" ariaLabel="Clickable tag" />
|
||||
<app-tag color="indigo" removable label="Removable" removeLabel="Remove tag" />
|
||||
<app-tag customColor="#6366f1" label="Custom color" />
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="showcase-section">
|
||||
<h2>Tabs</h2>
|
||||
|
||||
<div class="flex min-w-0 flex-col gap-6">
|
||||
<app-tabs
|
||||
[tabs]="settingsTabs"
|
||||
variant="underline"
|
||||
ariaLabel="Underline tabs example"
|
||||
[(selectedTabId)]="underlineTab"
|
||||
/>
|
||||
<app-tabs
|
||||
[tabs]="settingsTabs"
|
||||
variant="segmented"
|
||||
ariaLabel="Segmented tabs example"
|
||||
[(selectedTabId)]="segmentedTab"
|
||||
/>
|
||||
<div class="flex min-w-0 flex-col items-start gap-3">
|
||||
<app-tabs
|
||||
[tabs]="settingsTabs"
|
||||
variant="segmented"
|
||||
size="sm"
|
||||
collapse="never"
|
||||
ariaLabel="Small segmented tabs"
|
||||
[(selectedTabId)]="segmentedTabSm"
|
||||
/>
|
||||
<app-tabs
|
||||
[tabs]="settingsTabs"
|
||||
variant="segmented"
|
||||
size="lg"
|
||||
collapse="never"
|
||||
ariaLabel="Large segmented tabs"
|
||||
[(selectedTabId)]="segmentedTabLg"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<app-tabs
|
||||
[tabs]="manyTabs"
|
||||
variant="underline"
|
||||
ariaLabel="Many tabs example"
|
||||
[(selectedTabId)]="manyTab"
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
</main>
|
||||
@@ -0,0 +1,112 @@
|
||||
:host {
|
||||
display: block;
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.design-system-page {
|
||||
box-sizing: border-box;
|
||||
display: grid;
|
||||
gap: 1.5rem;
|
||||
align-content: start;
|
||||
height: 100%;
|
||||
padding: 2rem;
|
||||
overflow-y: auto;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.page-header {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
h1,
|
||||
h2 {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: var(--color-text-strong);
|
||||
font-size: 2rem;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
h2 {
|
||||
color: var(--color-text-strong);
|
||||
font-size: 1.1rem;
|
||||
font-weight: 750;
|
||||
}
|
||||
|
||||
.showcase-section {
|
||||
display: grid;
|
||||
gap: 1rem;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.showcase-section + .showcase-section {
|
||||
padding-top: 1.5rem;
|
||||
border-top: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.variant-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.variant-cell {
|
||||
display: grid;
|
||||
gap: 0.625rem;
|
||||
min-width: 0;
|
||||
padding: 0.875rem;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
.variant-label,
|
||||
.field > span {
|
||||
color: var(--color-text-muted);
|
||||
font-size: 0.75rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.button-row,
|
||||
.sample-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.input-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
||||
align-items: start;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.field {
|
||||
display: grid;
|
||||
align-content: start;
|
||||
gap: 0.375rem;
|
||||
}
|
||||
|
||||
.select-rich-option {
|
||||
display: inline-flex;
|
||||
min-width: 0;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.select-swatch {
|
||||
width: 0.875rem;
|
||||
height: 0.875rem;
|
||||
flex: 0 0 auto;
|
||||
border-radius: 999px;
|
||||
box-shadow: inset 0 0 0 1px rgb(0 0 0 / 15%);
|
||||
}
|
||||
|
||||
@media (width <= 640px) {
|
||||
.design-system-page {
|
||||
padding: 1rem;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
import { ChangeDetectionStrategy, Component, inject, signal } from '@angular/core';
|
||||
import { CdkScrollable } from '@angular/cdk/scrolling';
|
||||
import { Router } from '@angular/router';
|
||||
import { email, form, FormField, minLength, required, validate } from '@angular/forms/signals';
|
||||
import { MenuItem } from 'primeng/api';
|
||||
import { AppAccordionComponent } from '../../shared/ui/accordion/app-accordion.component';
|
||||
import {
|
||||
AppAccordionActionsDirective,
|
||||
AppAccordionContentDirective,
|
||||
AppAccordionHeaderDirective,
|
||||
} from '../../shared/ui/accordion/app-accordion.directives';
|
||||
import { AppAutocompleteComponent } from '../../shared/ui/autocomplete/app-autocomplete.component';
|
||||
import { AppMultiAutocompleteComponent } from '../../shared/ui/autocomplete/app-multi-autocomplete.component';
|
||||
import { AppButtonComponent } from '../../shared/ui/button/app-button.component';
|
||||
import { type ButtonSize, type ButtonTone, type ButtonVariant } from '../../shared/ui/button/app-button.variants';
|
||||
import { AppCheckboxComponent } from '../../shared/ui/checkbox/app-checkbox.component';
|
||||
import { AppDatePickerComponent } from '../../shared/ui/date-picker/app-date-picker.component';
|
||||
import { AppDateRangePickerComponent, type DatePickerRange } from '../../shared/ui/date-picker/app-date-range-picker.component';
|
||||
import { AppFieldComponent } from '../../shared/ui/field/app-field.component';
|
||||
import { AppInputComponent } from '../../shared/ui/input/app-input.component';
|
||||
import { AppMenuComponent } from '../../shared/ui/menu/app-menu.component';
|
||||
import { AppMessageComponent } from '../../shared/ui/message/app-message.component';
|
||||
import { AppNumberInputComponent } from '../../shared/ui/number-input/app-number-input.component';
|
||||
import { appMenuSection, appMenuSeparator } from '../../shared/ui/menu/app-menu.items';
|
||||
import { AppRadioGroupComponent, type RadioOption } from '../../shared/ui/radio-group/app-radio-group.component';
|
||||
import { AppRatingComponent } from '../../shared/ui/rating/app-rating.component';
|
||||
import { AppMultiSelectComponent } from '../../shared/ui/select/app-multi-select.component';
|
||||
import { AppSelectComponent } from '../../shared/ui/select/app-select.component';
|
||||
import { type SelectOption, type SelectOptionGroup } from '../../shared/ui/select/app-select.options';
|
||||
import { AppSelectOptionTemplateDirective, AppSelectSelectedTemplateDirective } from '../../shared/ui/select/app-select.templates';
|
||||
import { AppSliderComponent } from '../../shared/ui/slider/app-slider.component';
|
||||
import { AppSpinnerComponent } from '../../shared/ui/spinner/app-spinner.component';
|
||||
import { AppSplitButtonComponent } from '../../shared/ui/split-button/app-split-button.component';
|
||||
import { AppSwitchComponent } from '../../shared/ui/switch/app-switch.component';
|
||||
import { AppTabsComponent, type TabItem } from '../../shared/ui/tabs/app-tabs.component';
|
||||
import { AppTagComponent } from '../../shared/ui/tag/app-tag.component';
|
||||
import { AppTextareaComponent } from '../../shared/ui/textarea/app-textarea.component';
|
||||
import { AppTooltipDirective } from '../../shared/ui/tooltip/app-tooltip.directive';
|
||||
|
||||
interface ButtonExample {
|
||||
tone: ButtonTone;
|
||||
variant: ButtonVariant;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-design-system',
|
||||
standalone: true,
|
||||
imports: [
|
||||
CdkScrollable,
|
||||
AppAccordionComponent,
|
||||
AppAccordionHeaderDirective,
|
||||
AppAccordionContentDirective,
|
||||
AppAccordionActionsDirective,
|
||||
AppAutocompleteComponent,
|
||||
AppMultiAutocompleteComponent,
|
||||
AppButtonComponent,
|
||||
AppCheckboxComponent,
|
||||
AppDatePickerComponent,
|
||||
AppDateRangePickerComponent,
|
||||
AppFieldComponent,
|
||||
AppInputComponent,
|
||||
AppMenuComponent,
|
||||
AppMessageComponent,
|
||||
AppNumberInputComponent,
|
||||
AppRadioGroupComponent,
|
||||
AppRatingComponent,
|
||||
AppMultiSelectComponent,
|
||||
AppSelectComponent,
|
||||
AppSelectOptionTemplateDirective,
|
||||
AppSelectSelectedTemplateDirective,
|
||||
AppSliderComponent,
|
||||
AppSpinnerComponent,
|
||||
AppSplitButtonComponent,
|
||||
AppSwitchComponent,
|
||||
AppTabsComponent,
|
||||
AppTagComponent,
|
||||
AppTextareaComponent,
|
||||
AppTooltipDirective,
|
||||
FormField,
|
||||
],
|
||||
templateUrl: './design-system.component.html',
|
||||
styleUrl: './design-system.component.scss',
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class DesignSystemComponent {
|
||||
private readonly router = inject(Router);
|
||||
|
||||
openExample(path: string): void {
|
||||
void this.router.navigate(['/design-system', 'form', path]);
|
||||
}
|
||||
|
||||
readonly buttonExamples: ButtonExample[] = [
|
||||
{ tone: 'neutral', variant: 'soft' },
|
||||
{ tone: 'neutral', variant: 'solid' },
|
||||
{ tone: 'neutral', variant: 'ghost' },
|
||||
{ tone: 'primary', variant: 'soft' },
|
||||
{ tone: 'primary', variant: 'solid' },
|
||||
{ tone: 'primary', variant: 'ghost' },
|
||||
{ tone: 'danger', variant: 'soft' },
|
||||
{ tone: 'danger', variant: 'solid' },
|
||||
{ tone: 'danger', variant: 'ghost' },
|
||||
];
|
||||
readonly buttonSizes: ButtonSize[] = ['sm', 'md', 'lg'];
|
||||
readonly menuItems: MenuItem[] = [
|
||||
appMenuSection('Actions'),
|
||||
{ label: 'Rename' },
|
||||
{ label: 'Duplicate' },
|
||||
appMenuSeparator(),
|
||||
appMenuSection('Danger'),
|
||||
{ label: 'Delete', styleClass: 'app-menu-item-destructive' },
|
||||
];
|
||||
readonly selectOptions: SelectOption<string>[] = [
|
||||
{ label: 'Option A', value: 'a' },
|
||||
{ label: 'Option B', value: 'b' },
|
||||
{ label: 'Option C', value: 'c' },
|
||||
];
|
||||
readonly groupedSelectOptions: SelectOptionGroup<string>[] = [
|
||||
{
|
||||
label: 'Group A',
|
||||
options: [
|
||||
{ label: 'Option A', value: 'a' },
|
||||
{ label: 'Option B', value: 'b' },
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Group B',
|
||||
options: [
|
||||
{ label: 'Option C', value: 'c' },
|
||||
{ label: 'Option D', value: 'd' },
|
||||
],
|
||||
},
|
||||
];
|
||||
readonly themeSelectOptions = [
|
||||
{ label: 'Green', value: 'green', color: 'var(--color-green-500)' },
|
||||
{ label: 'Blue', value: 'blue', color: 'var(--color-blue-500)' },
|
||||
{ label: 'Rose', value: 'rose', color: 'var(--color-rose-500)' },
|
||||
];
|
||||
|
||||
readonly settingsTabs: TabItem[] = [
|
||||
{ id: 'general', label: 'General', icon: 'pi pi-cog' },
|
||||
{ id: 'metadata', label: 'Metadata', icon: 'pi pi-tag' },
|
||||
{ id: 'formats', label: 'Formats', icon: 'pi pi-file' },
|
||||
];
|
||||
readonly manyTabs: TabItem[] = [
|
||||
{ id: 'general', label: 'General' },
|
||||
{ id: 'metadata', label: 'Metadata' },
|
||||
{ id: 'formats', label: 'Formats' },
|
||||
{ id: 'readers', label: 'Readers' },
|
||||
{ id: 'integrations', label: 'Integrations' },
|
||||
{ id: 'notifications', label: 'Notifications' },
|
||||
{ id: 'security', label: 'Security' },
|
||||
{ id: 'advanced', label: 'Advanced' },
|
||||
];
|
||||
readonly underlineTab = signal<string | undefined>('general');
|
||||
readonly segmentedTab = signal<string | undefined>('general');
|
||||
readonly segmentedTabSm = signal<string | undefined>('general');
|
||||
readonly segmentedTabLg = signal<string | undefined>('general');
|
||||
readonly manyTab = signal<string | undefined>('general');
|
||||
|
||||
readonly radioViewOptions: RadioOption<string>[] = [
|
||||
{ label: 'List', value: 'list' },
|
||||
{ label: 'Grid', value: 'grid' },
|
||||
{ label: 'Cards', value: 'cards' },
|
||||
];
|
||||
readonly radioDensityOptions: RadioOption<string>[] = [
|
||||
{ label: 'Compact', value: 'compact', description: 'Tighter rows.' },
|
||||
{ label: 'Comfortable', value: 'comfortable', description: 'Default spacing.' },
|
||||
{ label: 'Spacious', value: 'spacious', description: 'Larger gaps.' },
|
||||
];
|
||||
|
||||
inputValue = 'Example title';
|
||||
autocompleteValue = '';
|
||||
readonly autocompleteOptions = [
|
||||
'Alpha',
|
||||
'Beta',
|
||||
'Gamma',
|
||||
'Delta',
|
||||
'Epsilon',
|
||||
'Zeta',
|
||||
];
|
||||
readonly filteredAutocompleteOptions = signal<string[]>([]);
|
||||
tags: string[] = ['Tag one'];
|
||||
readonly allTags = ['Tag one', 'Tag two', 'Tag three', 'Tag four', 'Tag five'];
|
||||
readonly filteredTags = signal<string[]>([]);
|
||||
readonly accordionItems = [
|
||||
{ title: 'General', body: 'General content.' },
|
||||
{ title: 'Details', body: 'Details content.' },
|
||||
{ title: 'Settings', body: 'Settings content.' },
|
||||
];
|
||||
accordionValue: number | null = 0;
|
||||
accordionMultiValue: number[] = [0];
|
||||
fontSizeValue: number | null = 16;
|
||||
weightValue: number | null = 5;
|
||||
aspectRatioValue = 2.1;
|
||||
compressionValue = 70;
|
||||
personalRating = 3.5;
|
||||
ratingValue = 4;
|
||||
checkboxAccepted = true;
|
||||
switchEnabled = true;
|
||||
selectValue: string | null = 'a';
|
||||
multiSelectValue: string[] = ['a', 'c'];
|
||||
themeValue: string | null = 'green';
|
||||
textareaValue = 'Example notes';
|
||||
radioViewValue: string | null = 'list';
|
||||
radioDensityValue: string | null = 'comfortable';
|
||||
dateValue = '';
|
||||
dateRangeValue: DatePickerRange = { start: '', end: '' };
|
||||
|
||||
readonly profileModel = signal<{
|
||||
displayName: string;
|
||||
email: string;
|
||||
bio: string;
|
||||
viewMode: string | null;
|
||||
birthday: string;
|
||||
}>({ displayName: '', email: '', bio: '', viewMode: null, birthday: '' });
|
||||
readonly profileForm = form(this.profileModel, (path) => {
|
||||
required(path.displayName, { message: 'Display name is required' });
|
||||
email(path.email, { message: 'Enter a valid email' });
|
||||
minLength(path.bio, 10, { message: 'Use at least 10 characters' });
|
||||
required(path.viewMode, { message: 'Choose an option' });
|
||||
required(path.birthday, { message: 'Pick a date' });
|
||||
});
|
||||
|
||||
readonly syncModel = signal({ sync: { enabled: true, host: '' } });
|
||||
readonly syncForm = form(this.syncModel, (path) => {
|
||||
validate(path.sync, ({ value }) =>
|
||||
value().enabled && !value().host
|
||||
? { kind: 'valueRequired', message: 'Enter a value to continue' }
|
||||
: null,
|
||||
);
|
||||
});
|
||||
|
||||
validateSyncGroup(): void {
|
||||
this.syncForm.sync().markAsTouched();
|
||||
}
|
||||
|
||||
validateProfile(): void {
|
||||
this.profileForm().markAsTouched();
|
||||
}
|
||||
|
||||
filterAutocompleteOptions(query: string): void {
|
||||
const q = query.trim().toLowerCase();
|
||||
this.filteredAutocompleteOptions.set(
|
||||
q ? this.autocompleteOptions.filter((option) => option.toLowerCase().includes(q)) : [],
|
||||
);
|
||||
}
|
||||
|
||||
filterTags(query: string): void {
|
||||
const q = query.trim().toLowerCase();
|
||||
this.filteredTags.set(q ? this.allTags.filter((tag) => tag.toLowerCase().includes(q)) : []);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
<main cdkScrollable class="h-full overflow-y-auto bg-page p-6 text-text sm:p-8">
|
||||
<div class="mx-auto flex w-full max-w-2xl flex-col gap-6">
|
||||
<header class="flex flex-col gap-3">
|
||||
<app-button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
icon="pi pi-chevron-left"
|
||||
label="Back to design system"
|
||||
styleClass="self-start"
|
||||
(clicked)="back()" />
|
||||
<div class="flex flex-col gap-1">
|
||||
<h1 class="text-2xl font-extrabold text-text-strong">Device settings</h1>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<app-tag [color]="deviceForm().valid() ? 'green' : 'red'" [label]="deviceForm().valid() ? 'valid' : 'invalid'" />
|
||||
<app-tag [color]="deviceForm().dirty() ? 'amber' : 'neutral'" [label]="deviceForm().dirty() ? 'dirty' : 'pristine'" />
|
||||
<app-tag [color]="deviceForm().touched() ? 'sky' : 'neutral'" [label]="deviceForm().touched() ? 'touched' : 'untouched'" />
|
||||
@if (deviceForm().submitting()) {
|
||||
<app-tag color="primary" icon="pi pi-spin pi-spinner" label="submitting" />
|
||||
}
|
||||
</div>
|
||||
|
||||
<form [formRoot]="deviceForm" class="flex flex-col divide-y divide-border">
|
||||
<section class="flex flex-col gap-5 pb-7">
|
||||
<div class="flex flex-col gap-1">
|
||||
<div class="flex items-center justify-between gap-4">
|
||||
<h2 class="m-0 inline-flex items-center gap-2 text-base font-bold text-text-strong">
|
||||
<i class="pi pi-book text-text-muted" aria-hidden="true"></i> Hardcover
|
||||
</h2>
|
||||
<app-switch [formField]="deviceForm.hardcover.enabled" ariaLabel="Enable Hardcover sync" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (!deviceForm.hardcover.apiKey().hidden()) {
|
||||
<app-field [field]="deviceForm.hardcover.apiKey" label="API key" hint='Starts with "hc_".'>
|
||||
<app-input type="password" revealToggle [formField]="deviceForm.hardcover.apiKey" placeholder="hc_…" />
|
||||
</app-field>
|
||||
}
|
||||
</section>
|
||||
|
||||
<section class="flex flex-col gap-5 py-7">
|
||||
<div class="flex flex-col gap-1">
|
||||
<div class="flex items-center justify-between gap-4">
|
||||
<h2 class="m-0 inline-flex items-center gap-2 text-base font-bold text-text-strong">
|
||||
<i class="pi pi-tablet text-text-muted" aria-hidden="true"></i> Kobo
|
||||
</h2>
|
||||
<app-switch [formField]="deviceForm.kobo.enabled" ariaLabel="Enable Kobo sync" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (!deviceForm.kobo.twoWaySync().hidden()) {
|
||||
<app-field [field]="deviceForm.kobo.twoWaySync" label="Two-way progress sync" hint="Requires KEPUB.">
|
||||
<app-switch [formField]="deviceForm.kobo.twoWaySync" />
|
||||
</app-field>
|
||||
|
||||
<app-field [field]="deviceForm.kobo.convertToKepub" label="Convert to KEPUB" hint="Needed for two-way sync.">
|
||||
<app-switch [formField]="deviceForm.kobo.convertToKepub" />
|
||||
</app-field>
|
||||
|
||||
<app-field [field]="deviceForm.kobo.markAsReading" label="Mark as reading at {{ model().kobo.markAsReading }}%" hint="1-10%.">
|
||||
<app-slider [formField]="deviceForm.kobo.markAsReading" ariaLabel="Mark as reading threshold" />
|
||||
</app-field>
|
||||
|
||||
<app-field [field]="deviceForm.kobo.markAsFinished" label="Mark as finished at {{ model().kobo.markAsFinished }}%" hint="90-100%.">
|
||||
<app-slider [formField]="deviceForm.kobo.markAsFinished" ariaLabel="Mark as finished threshold" />
|
||||
</app-field>
|
||||
|
||||
<app-field [field]="deviceForm.kobo.conversionLimitMb" label="Conversion size limit" hint="1-250 MB.">
|
||||
<app-number-input [formField]="deviceForm.kobo.conversionLimitMb" unit="MB" />
|
||||
</app-field>
|
||||
}
|
||||
</section>
|
||||
|
||||
<section class="flex flex-col gap-5 py-7">
|
||||
<div class="flex flex-col gap-1">
|
||||
<div class="flex items-center justify-between gap-4">
|
||||
<h2 class="m-0 inline-flex items-center gap-2 text-base font-bold text-text-strong">
|
||||
<i class="pi pi-mobile text-text-muted" aria-hidden="true"></i> KOReader
|
||||
</h2>
|
||||
<app-switch [formField]="deviceForm.koreader.enabled" ariaLabel="Enable KOReader sync" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (!deviceForm.koreader.username().hidden()) {
|
||||
<app-field [field]="deviceForm.koreader.syncWithWebReader" label="Also sync with the web reader" hint="Shares progress.">
|
||||
<app-switch [formField]="deviceForm.koreader.syncWithWebReader" />
|
||||
</app-field>
|
||||
|
||||
<app-field [field]="deviceForm.koreader.username" label="Sync username" hint="Required when enabled.">
|
||||
<app-input [formField]="deviceForm.koreader.username" placeholder="reader" />
|
||||
</app-field>
|
||||
|
||||
<app-field [field]="deviceForm.koreader.password" label="Sync password" hint="At least 6 characters.">
|
||||
<app-input type="password" revealToggle [formField]="deviceForm.koreader.password" placeholder="••••••" />
|
||||
</app-field>
|
||||
}
|
||||
</section>
|
||||
|
||||
<div class="flex flex-wrap items-center gap-3 pt-6">
|
||||
<app-button
|
||||
type="submit"
|
||||
tone="primary"
|
||||
label="Save settings"
|
||||
icon="pi pi-save"
|
||||
[loading]="deviceForm().submitting()"
|
||||
[disabled]="deviceForm().submitting()" />
|
||||
<app-button variant="soft" label="Validate" (clicked)="validateAll()" />
|
||||
<app-button variant="ghost" label="Reset" (clicked)="reset()" />
|
||||
@if (submitState() === 'saved') {
|
||||
<app-message inline color="green" class="ml-auto">Settings saved.</app-message>
|
||||
} @else if (submitAttempted()) {
|
||||
<app-message class="ml-auto" [field]="deviceForm" summary summaryLayout="inline" />
|
||||
}
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<details class="border-t border-border pt-4">
|
||||
<summary class="cursor-pointer text-sm font-semibold text-text-strong">Form value</summary>
|
||||
<pre class="mt-3 overflow-x-auto text-xs text-text-muted dark:text-text-secondary">{{ model() | json }}</pre>
|
||||
</details>
|
||||
</div>
|
||||
</main>
|
||||
@@ -0,0 +1,139 @@
|
||||
import { ChangeDetectionStrategy, Component, inject, signal } from '@angular/core';
|
||||
import { JsonPipe } from '@angular/common';
|
||||
import { CdkScrollable } from '@angular/cdk/scrolling';
|
||||
import { Router } from '@angular/router';
|
||||
import { form, FormField, FormRoot, hidden, max, min, minLength, required, validate } from '@angular/forms/signals';
|
||||
import { AppButtonComponent } from '../../../shared/ui/button/app-button.component';
|
||||
import { AppFieldComponent } from '../../../shared/ui/field/app-field.component';
|
||||
import { AppInputComponent } from '../../../shared/ui/input/app-input.component';
|
||||
import { AppMessageComponent } from '../../../shared/ui/message/app-message.component';
|
||||
import { AppNumberInputComponent } from '../../../shared/ui/number-input/app-number-input.component';
|
||||
import { AppSliderComponent } from '../../../shared/ui/slider/app-slider.component';
|
||||
import { AppSwitchComponent } from '../../../shared/ui/switch/app-switch.component';
|
||||
import { AppTagComponent } from '../../../shared/ui/tag/app-tag.component';
|
||||
|
||||
interface DeviceFormModel {
|
||||
hardcover: { enabled: boolean; apiKey: string };
|
||||
kobo: {
|
||||
enabled: boolean;
|
||||
twoWaySync: boolean;
|
||||
convertToKepub: boolean;
|
||||
markAsReading: number;
|
||||
markAsFinished: number;
|
||||
conversionLimitMb: number | null;
|
||||
};
|
||||
koreader: { enabled: boolean; syncWithWebReader: boolean; username: string; password: string };
|
||||
}
|
||||
|
||||
function createInitialModel(): DeviceFormModel {
|
||||
return {
|
||||
hardcover: { enabled: false, apiKey: '' },
|
||||
kobo: {
|
||||
enabled: true,
|
||||
twoWaySync: false,
|
||||
convertToKepub: true,
|
||||
markAsReading: 3,
|
||||
markAsFinished: 95,
|
||||
conversionLimitMb: 50,
|
||||
},
|
||||
koreader: { enabled: false, syncWithWebReader: false, username: '', password: '' },
|
||||
};
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-device-form-example',
|
||||
standalone: true,
|
||||
host: { class: 'block h-full min-h-0' },
|
||||
imports: [
|
||||
CdkScrollable,
|
||||
JsonPipe,
|
||||
FormField,
|
||||
FormRoot,
|
||||
AppButtonComponent,
|
||||
AppFieldComponent,
|
||||
AppInputComponent,
|
||||
AppMessageComponent,
|
||||
AppNumberInputComponent,
|
||||
AppSliderComponent,
|
||||
AppSwitchComponent,
|
||||
AppTagComponent,
|
||||
],
|
||||
templateUrl: './device-form.component.html',
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class DeviceFormExampleComponent {
|
||||
private readonly router = inject(Router);
|
||||
|
||||
readonly model = signal<DeviceFormModel>(createInitialModel());
|
||||
readonly deviceForm = form(this.model, path => {
|
||||
hidden(path.hardcover.apiKey, ({ valueOf }) => !valueOf(path.hardcover.enabled));
|
||||
required(path.hardcover.apiKey, { message: 'Enter your Hardcover API key' });
|
||||
minLength(path.hardcover.apiKey, 20, { message: 'Hardcover keys are at least 20 characters' });
|
||||
|
||||
min(path.kobo.markAsReading, 1);
|
||||
max(path.kobo.markAsReading, 10);
|
||||
min(path.kobo.markAsFinished, 90);
|
||||
max(path.kobo.markAsFinished, 100);
|
||||
min(path.kobo.conversionLimitMb, 1);
|
||||
max(path.kobo.conversionLimitMb, 250);
|
||||
hidden(path.kobo.twoWaySync, ({ valueOf }) => !valueOf(path.kobo.enabled));
|
||||
hidden(path.kobo.convertToKepub, ({ valueOf }) => !valueOf(path.kobo.enabled));
|
||||
hidden(path.kobo.markAsReading, ({ valueOf }) => !valueOf(path.kobo.enabled));
|
||||
hidden(path.kobo.markAsFinished, ({ valueOf }) => !valueOf(path.kobo.enabled));
|
||||
hidden(path.kobo.conversionLimitMb, ({ valueOf }) => !valueOf(path.kobo.enabled));
|
||||
validate(path.kobo.twoWaySync, ({ value, valueOf }) =>
|
||||
value() && !valueOf(path.kobo.convertToKepub)
|
||||
? { kind: 'needsKepub', message: 'Two-way sync needs KEPUB conversion turned on' }
|
||||
: null,
|
||||
);
|
||||
|
||||
hidden(path.koreader.syncWithWebReader, ({ valueOf }) => !valueOf(path.koreader.enabled));
|
||||
hidden(path.koreader.username, ({ valueOf }) => !valueOf(path.koreader.enabled));
|
||||
hidden(path.koreader.password, ({ valueOf }) => !valueOf(path.koreader.enabled));
|
||||
required(path.koreader.username, { message: 'Choose a sync username' });
|
||||
required(path.koreader.password, { message: 'Set a sync password' });
|
||||
minLength(path.koreader.password, 6, { message: 'Use at least 6 characters' });
|
||||
}, {
|
||||
submission: {
|
||||
action: async field => {
|
||||
this.submitState.set('idle');
|
||||
this.submitAttempted.set(true);
|
||||
await delay(900);
|
||||
const hardcover = this.model().hardcover;
|
||||
if (hardcover.enabled && !hardcover.apiKey.startsWith('hc_')) {
|
||||
return [{ fieldTree: field.hardcover.apiKey, kind: 'server', message: 'Key must start with "hc_"' }];
|
||||
}
|
||||
this.submitState.set('saved');
|
||||
return undefined;
|
||||
},
|
||||
onInvalid: field => {
|
||||
this.submitState.set('idle');
|
||||
this.submitAttempted.set(true);
|
||||
field().errorSummary()[0]?.fieldTree().focusBoundControl();
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
readonly submitState = signal<'idle' | 'saved'>('idle');
|
||||
readonly submitAttempted = signal(false);
|
||||
|
||||
validateAll(): void {
|
||||
this.submitState.set('idle');
|
||||
this.deviceForm().markAsTouched();
|
||||
}
|
||||
|
||||
reset(): void {
|
||||
this.submitState.set('idle');
|
||||
this.submitAttempted.set(false);
|
||||
this.model.set(createInitialModel());
|
||||
this.deviceForm().reset();
|
||||
}
|
||||
|
||||
back(): void {
|
||||
void this.router.navigate(['/design-system']);
|
||||
}
|
||||
}
|
||||
|
||||
function delay(ms: number): Promise<void> {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
<main cdkScrollable class="h-full overflow-y-auto bg-page p-6 text-text sm:p-8">
|
||||
<div class="mx-auto flex w-full max-w-2xl flex-col gap-6">
|
||||
<header class="flex flex-col gap-3">
|
||||
<app-button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
icon="pi pi-chevron-left"
|
||||
label="Back to design system"
|
||||
styleClass="self-start"
|
||||
(clicked)="back()" />
|
||||
<div class="flex flex-col gap-1">
|
||||
<h1 class="text-2xl font-extrabold text-text-strong">Everything</h1>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<app-tag [color]="everythingForm().valid() ? 'green' : 'red'" [label]="everythingForm().valid() ? 'valid' : 'invalid'" />
|
||||
<app-tag [color]="everythingForm().dirty() ? 'amber' : 'neutral'" [label]="everythingForm().dirty() ? 'dirty' : 'pristine'" />
|
||||
<app-tag [color]="everythingForm().touched() ? 'sky' : 'neutral'" [label]="everythingForm().touched() ? 'touched' : 'untouched'" />
|
||||
@if (everythingForm().submitting()) {
|
||||
<app-tag color="primary" icon="pi pi-spin pi-spinner" label="submitting" />
|
||||
}
|
||||
</div>
|
||||
|
||||
<form [formRoot]="everythingForm" class="flex flex-col gap-5">
|
||||
<app-field [field]="everythingForm.text" label="Text input" hint="Required.">
|
||||
<app-input [formField]="everythingForm.text" placeholder="Type something" />
|
||||
</app-field>
|
||||
|
||||
<app-field [field]="everythingForm.textarea" label="Textarea" hint="Required.">
|
||||
<app-textarea [formField]="everythingForm.textarea" rows="3" placeholder="A longer value" />
|
||||
</app-field>
|
||||
|
||||
<app-field [field]="everythingForm.number" label="Number" hint="0-100.">
|
||||
<app-number-input [formField]="everythingForm.number" unit="pt" />
|
||||
</app-field>
|
||||
|
||||
<app-field [field]="everythingForm.select" label="Single select" hint="Pick one.">
|
||||
<app-select [formField]="everythingForm.select" [options]="selectOptions" placeholder="Choose one" />
|
||||
</app-field>
|
||||
|
||||
<app-field [field]="everythingForm.multiSelect" label="Multi-select" hint="Pick at least one.">
|
||||
<app-multi-select [formField]="everythingForm.multiSelect" [options]="selectOptions" showClear filter placeholder="Choose any" />
|
||||
</app-field>
|
||||
|
||||
<app-field [field]="everythingForm.autocomplete" label="Autocomplete" hint="Pick or type.">
|
||||
<app-autocomplete
|
||||
[formField]="everythingForm.autocomplete"
|
||||
[suggestions]="autocompleteSuggestions()"
|
||||
(complete)="filterAutocomplete($event)"
|
||||
placeholder="Type to search"
|
||||
ariaLabel="Autocomplete" />
|
||||
</app-field>
|
||||
|
||||
<app-field [field]="everythingForm.multiAutocomplete" label="Multi-autocomplete (tags)" hint="Add at least one.">
|
||||
<app-multi-autocomplete
|
||||
[formField]="everythingForm.multiAutocomplete"
|
||||
[suggestions]="multiAutocompleteSuggestions()"
|
||||
(complete)="filterMultiAutocomplete($event)"
|
||||
placeholder="Add tags"
|
||||
ariaLabel="Tags"
|
||||
removeTagLabel="Remove tag" />
|
||||
</app-field>
|
||||
|
||||
<app-field [field]="everythingForm.checkbox" label="Checkbox" hint="Must be checked.">
|
||||
<app-checkbox [formField]="everythingForm.checkbox" />
|
||||
</app-field>
|
||||
|
||||
<app-field [field]="everythingForm.switch" label="Switch" hint="Optional.">
|
||||
<app-switch [formField]="everythingForm.switch" />
|
||||
</app-field>
|
||||
|
||||
<app-field [field]="everythingForm.radio" label="Radio group" hint="Choose one.">
|
||||
<app-radio-group [formField]="everythingForm.radio" [options]="radioOptions" />
|
||||
</app-field>
|
||||
|
||||
<app-field [field]="everythingForm.slider" label="Slider — {{ model().slider }}" hint="0-100.">
|
||||
<app-slider [formField]="everythingForm.slider" ariaLabel="Slider" />
|
||||
</app-field>
|
||||
|
||||
<app-field [field]="everythingForm.rating" label="Rating" hint="Required.">
|
||||
<app-rating [formField]="everythingForm.rating" ariaLabel="Rating" />
|
||||
</app-field>
|
||||
|
||||
<app-field [field]="everythingForm.date" label="Date" hint="Required.">
|
||||
<app-date-picker [formField]="everythingForm.date" placeholder="Pick a date" ariaLabel="Date" />
|
||||
</app-field>
|
||||
|
||||
<app-field [field]="everythingForm.dateRange" label="Date range" hint="Start and end required.">
|
||||
<app-date-range-picker [formField]="everythingForm.dateRange" placeholder="Pick a range" ariaLabel="Date range" />
|
||||
</app-field>
|
||||
|
||||
<div class="flex flex-wrap items-center gap-3 border-t border-border pt-5">
|
||||
<app-button
|
||||
type="submit"
|
||||
tone="primary"
|
||||
label="Save"
|
||||
icon="pi pi-save"
|
||||
[loading]="everythingForm().submitting()"
|
||||
[disabled]="everythingForm().submitting()" />
|
||||
<app-button variant="soft" label="Validate" (clicked)="validateAll()" />
|
||||
<app-button variant="ghost" label="Reset" (clicked)="reset()" />
|
||||
@if (submitState() === 'saved') {
|
||||
<app-message inline color="green" class="ml-auto">Saved.</app-message>
|
||||
} @else if (submitAttempted()) {
|
||||
<app-message class="ml-auto" [field]="everythingForm" summary summaryLayout="inline" />
|
||||
}
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<details class="border-t border-border pt-4">
|
||||
<summary class="cursor-pointer text-sm font-semibold text-text-strong">Form value</summary>
|
||||
<pre class="mt-3 overflow-x-auto text-xs text-text-muted dark:text-text-secondary">{{ model() | json }}</pre>
|
||||
</details>
|
||||
</div>
|
||||
</main>
|
||||
@@ -0,0 +1,183 @@
|
||||
import { ChangeDetectionStrategy, Component, inject, signal } from '@angular/core';
|
||||
import { JsonPipe } from '@angular/common';
|
||||
import { CdkScrollable } from '@angular/cdk/scrolling';
|
||||
import { Router } from '@angular/router';
|
||||
import { form, FormField, FormRoot, max, min, minLength, required, validate } from '@angular/forms/signals';
|
||||
import { AppButtonComponent } from '../../../shared/ui/button/app-button.component';
|
||||
import { AppFieldComponent } from '../../../shared/ui/field/app-field.component';
|
||||
import { AppInputComponent } from '../../../shared/ui/input/app-input.component';
|
||||
import { AppTextareaComponent } from '../../../shared/ui/textarea/app-textarea.component';
|
||||
import { AppNumberInputComponent } from '../../../shared/ui/number-input/app-number-input.component';
|
||||
import { AppSelectComponent } from '../../../shared/ui/select/app-select.component';
|
||||
import { AppMultiSelectComponent } from '../../../shared/ui/select/app-multi-select.component';
|
||||
import { AppAutocompleteComponent } from '../../../shared/ui/autocomplete/app-autocomplete.component';
|
||||
import { AppMultiAutocompleteComponent } from '../../../shared/ui/autocomplete/app-multi-autocomplete.component';
|
||||
import { AppCheckboxComponent } from '../../../shared/ui/checkbox/app-checkbox.component';
|
||||
import { AppSwitchComponent } from '../../../shared/ui/switch/app-switch.component';
|
||||
import { AppRadioGroupComponent, type RadioOption } from '../../../shared/ui/radio-group/app-radio-group.component';
|
||||
import { AppSliderComponent } from '../../../shared/ui/slider/app-slider.component';
|
||||
import { AppRatingComponent } from '../../../shared/ui/rating/app-rating.component';
|
||||
import { AppDatePickerComponent } from '../../../shared/ui/date-picker/app-date-picker.component';
|
||||
import { AppDateRangePickerComponent, type DatePickerRange } from '../../../shared/ui/date-picker/app-date-range-picker.component';
|
||||
import { AppMessageComponent } from '../../../shared/ui/message/app-message.component';
|
||||
import { AppTagComponent } from '../../../shared/ui/tag/app-tag.component';
|
||||
import { type SelectOption } from '../../../shared/ui/select/app-select.options';
|
||||
|
||||
interface EverythingFormModel {
|
||||
text: string;
|
||||
textarea: string;
|
||||
number: number | null;
|
||||
select: string;
|
||||
multiSelect: string[];
|
||||
autocomplete: string;
|
||||
multiAutocomplete: string[];
|
||||
checkbox: boolean;
|
||||
switch: boolean;
|
||||
radio: string;
|
||||
slider: number;
|
||||
rating: number;
|
||||
date: string;
|
||||
dateRange: DatePickerRange;
|
||||
}
|
||||
|
||||
function createInitialModel(): EverythingFormModel {
|
||||
return {
|
||||
text: '',
|
||||
textarea: '',
|
||||
number: null,
|
||||
select: '',
|
||||
multiSelect: [],
|
||||
autocomplete: '',
|
||||
multiAutocomplete: [],
|
||||
checkbox: false,
|
||||
switch: false,
|
||||
radio: '',
|
||||
slider: 50,
|
||||
rating: 0,
|
||||
date: '',
|
||||
dateRange: { start: '', end: '' },
|
||||
};
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-everything-form-example',
|
||||
standalone: true,
|
||||
host: { class: 'block h-full min-h-0' },
|
||||
imports: [
|
||||
CdkScrollable,
|
||||
JsonPipe,
|
||||
FormField,
|
||||
FormRoot,
|
||||
AppButtonComponent,
|
||||
AppFieldComponent,
|
||||
AppInputComponent,
|
||||
AppTextareaComponent,
|
||||
AppNumberInputComponent,
|
||||
AppSelectComponent,
|
||||
AppMultiSelectComponent,
|
||||
AppAutocompleteComponent,
|
||||
AppMultiAutocompleteComponent,
|
||||
AppCheckboxComponent,
|
||||
AppSwitchComponent,
|
||||
AppRadioGroupComponent,
|
||||
AppSliderComponent,
|
||||
AppRatingComponent,
|
||||
AppDatePickerComponent,
|
||||
AppDateRangePickerComponent,
|
||||
AppMessageComponent,
|
||||
AppTagComponent,
|
||||
],
|
||||
templateUrl: './everything-form.component.html',
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class EverythingFormExampleComponent {
|
||||
private readonly router = inject(Router);
|
||||
|
||||
readonly model = signal<EverythingFormModel>(createInitialModel());
|
||||
readonly everythingForm = form(this.model, path => {
|
||||
required(path.text, { message: 'Required' });
|
||||
required(path.textarea, { message: 'Required' });
|
||||
required(path.number, { message: 'Enter a number' });
|
||||
min(path.number, 0, { message: '0 or more' });
|
||||
max(path.number, 100, { message: '100 or less' });
|
||||
min(path.slider, 0);
|
||||
max(path.slider, 100);
|
||||
required(path.select, { message: 'Pick an option' });
|
||||
required(path.autocomplete, { message: 'Pick or type a value' });
|
||||
required(path.radio, { message: 'Choose one' });
|
||||
required(path.date, { message: 'Pick a date' });
|
||||
minLength(path.multiSelect, 1, { message: 'Pick at least one' });
|
||||
minLength(path.multiAutocomplete, 1, { message: 'Add at least one tag' });
|
||||
validate(path.checkbox, ({ value }) => (value() ? null : { kind: 'mustAccept', message: 'Please confirm' }));
|
||||
validate(path.rating, ({ value }) => (value() > 0 ? null : { kind: 'rate', message: 'Add a rating' }));
|
||||
validate(path.dateRange, ({ value }) =>
|
||||
value().start && value().end ? null : { kind: 'range', message: 'Pick a start and end date' },
|
||||
);
|
||||
}, {
|
||||
submission: {
|
||||
action: async field => {
|
||||
this.submitState.set('idle');
|
||||
this.submitAttempted.set(true);
|
||||
await delay(700);
|
||||
if (this.model().text.trim().toLowerCase() === 'taken') {
|
||||
return [{ fieldTree: field.text, kind: 'server', message: '"taken" is not allowed' }];
|
||||
}
|
||||
this.submitState.set('saved');
|
||||
return undefined;
|
||||
},
|
||||
onInvalid: field => {
|
||||
this.submitState.set('idle');
|
||||
this.submitAttempted.set(true);
|
||||
field().errorSummary()[0]?.fieldTree().focusBoundControl();
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
readonly submitState = signal<'idle' | 'saved'>('idle');
|
||||
readonly submitAttempted = signal(false);
|
||||
|
||||
readonly selectOptions: readonly SelectOption<string>[] = [
|
||||
{ label: 'One', value: 'one' },
|
||||
{ label: 'Two', value: 'two' },
|
||||
{ label: 'Three', value: 'three' },
|
||||
];
|
||||
readonly radioOptions: readonly RadioOption<string>[] = [
|
||||
{ label: 'Option A', value: 'a', description: 'First choice.' },
|
||||
{ label: 'Option B', value: 'b', description: 'Second choice.' },
|
||||
];
|
||||
|
||||
private readonly allTags = ['alpha', 'beta', 'gamma', 'delta', 'epsilon', 'zeta'];
|
||||
readonly autocompleteSuggestions = signal<string[]>([]);
|
||||
readonly multiAutocompleteSuggestions = signal<string[]>([]);
|
||||
|
||||
filterAutocomplete(query: string): void {
|
||||
const q = query.trim().toLowerCase();
|
||||
this.autocompleteSuggestions.set(q ? this.allTags.filter(t => t.includes(q)) : [...this.allTags]);
|
||||
}
|
||||
|
||||
filterMultiAutocomplete(query: string): void {
|
||||
const q = query.trim().toLowerCase();
|
||||
const chosen = this.model().multiAutocomplete;
|
||||
this.multiAutocompleteSuggestions.set(this.allTags.filter(t => t.includes(q) && !chosen.includes(t)));
|
||||
}
|
||||
|
||||
validateAll(): void {
|
||||
this.submitState.set('idle');
|
||||
this.everythingForm().markAsTouched();
|
||||
}
|
||||
|
||||
reset(): void {
|
||||
this.submitState.set('idle');
|
||||
this.submitAttempted.set(false);
|
||||
this.model.set(createInitialModel());
|
||||
this.everythingForm().reset();
|
||||
}
|
||||
|
||||
back(): void {
|
||||
void this.router.navigate(['/design-system']);
|
||||
}
|
||||
}
|
||||
|
||||
function delay(ms: number): Promise<void> {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<main cdkScrollable class="h-full overflow-y-auto bg-page p-6 text-text sm:p-8">
|
||||
<div class="mx-auto flex w-full max-w-2xl flex-col gap-6">
|
||||
<header class="flex flex-col gap-3">
|
||||
<app-button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
icon="pi pi-chevron-left"
|
||||
label="Back to design system"
|
||||
styleClass="self-start"
|
||||
(clicked)="back()" />
|
||||
<div class="flex flex-col gap-1">
|
||||
<h1 class="text-2xl font-extrabold text-text-strong">Create library</h1>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<app-tag [color]="libraryForm().valid() ? 'green' : 'red'" [label]="libraryForm().valid() ? 'valid' : 'invalid'" />
|
||||
<app-tag [color]="libraryForm().dirty() ? 'amber' : 'neutral'" [label]="libraryForm().dirty() ? 'dirty' : 'pristine'" />
|
||||
<app-tag [color]="libraryForm().touched() ? 'sky' : 'neutral'" [label]="libraryForm().touched() ? 'touched' : 'untouched'" />
|
||||
@if (libraryForm().submitting()) {
|
||||
<app-tag color="primary" icon="pi pi-spin pi-spinner" label="submitting" />
|
||||
}
|
||||
</div>
|
||||
|
||||
<form [formRoot]="libraryForm" class="flex flex-col gap-5">
|
||||
<app-field [field]="libraryForm.name" label="Library name" hint="2+ characters.">
|
||||
<app-input [formField]="libraryForm.name" placeholder="e.g. Science Fiction" />
|
||||
</app-field>
|
||||
|
||||
<app-field [field]="libraryForm.folders" label="Folders" hint="Press Enter to add.">
|
||||
<app-multi-autocomplete
|
||||
[formField]="libraryForm.folders"
|
||||
[suggestions]="folderSuggestions()"
|
||||
(complete)="filterFolders($event)"
|
||||
placeholder="/books/sci-fi"
|
||||
ariaLabel="Folders"
|
||||
removeTagLabel="Remove folder" />
|
||||
</app-field>
|
||||
|
||||
<app-field [field]="libraryForm.organizationMode" label="Organization" hint="How files map to books.">
|
||||
<app-radio-group variant="card" [formField]="libraryForm.organizationMode" [options]="organizationOptions" />
|
||||
</app-field>
|
||||
|
||||
<app-field [field]="libraryForm.metadataSource" label="Metadata source" hint="Default: embedded.">
|
||||
<app-select [formField]="libraryForm.metadataSource" [options]="metadataSourceOptions" />
|
||||
</app-field>
|
||||
|
||||
<app-field [field]="libraryForm.allowedFormats" label="Allowed formats" hint="At least one required.">
|
||||
<app-multi-select
|
||||
[formField]="libraryForm.allowedFormats"
|
||||
[options]="formatOptions"
|
||||
showClear
|
||||
filter
|
||||
placeholder="Choose formats" />
|
||||
</app-field>
|
||||
|
||||
<app-field [field]="libraryForm.watch" label="Watch folders" hint="Import new files.">
|
||||
<app-switch [formField]="libraryForm.watch" />
|
||||
</app-field>
|
||||
|
||||
<div class="flex flex-wrap items-center gap-3 border-t border-border pt-5">
|
||||
<app-button
|
||||
type="submit"
|
||||
tone="primary"
|
||||
label="Save library"
|
||||
icon="pi pi-save"
|
||||
[loading]="libraryForm().submitting()"
|
||||
[disabled]="libraryForm().submitting()" />
|
||||
<app-button variant="soft" label="Validate" (clicked)="validateAll()" />
|
||||
<app-button variant="ghost" label="Reset" (clicked)="reset()" />
|
||||
@if (submitState() === 'saved') {
|
||||
<app-message inline color="green" class="ml-auto">Library saved.</app-message>
|
||||
} @else if (submitAttempted()) {
|
||||
<app-message class="ml-auto" [field]="libraryForm" summary summaryLayout="inline" />
|
||||
}
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<details class="border-t border-border pt-4">
|
||||
<summary class="cursor-pointer text-sm font-semibold text-text-strong">Form value</summary>
|
||||
<pre class="mt-3 overflow-x-auto text-xs text-text-muted dark:text-text-secondary">{{ model() | json }}</pre>
|
||||
</details>
|
||||
</div>
|
||||
</main>
|
||||
@@ -0,0 +1,167 @@
|
||||
import { ChangeDetectionStrategy, Component, inject, signal } from '@angular/core';
|
||||
import { JsonPipe } from '@angular/common';
|
||||
import { CdkScrollable } from '@angular/cdk/scrolling';
|
||||
import { Router } from '@angular/router';
|
||||
import { form, FormField, FormRoot, minLength, required, validate } from '@angular/forms/signals';
|
||||
import { AppButtonComponent } from '../../../shared/ui/button/app-button.component';
|
||||
import { AppFieldComponent } from '../../../shared/ui/field/app-field.component';
|
||||
import { AppInputComponent } from '../../../shared/ui/input/app-input.component';
|
||||
import { AppMessageComponent } from '../../../shared/ui/message/app-message.component';
|
||||
import { AppMultiAutocompleteComponent } from '../../../shared/ui/autocomplete/app-multi-autocomplete.component';
|
||||
import { AppMultiSelectComponent } from '../../../shared/ui/select/app-multi-select.component';
|
||||
import { AppRadioGroupComponent, type RadioOption } from '../../../shared/ui/radio-group/app-radio-group.component';
|
||||
import { AppSelectComponent } from '../../../shared/ui/select/app-select.component';
|
||||
import { AppSwitchComponent } from '../../../shared/ui/switch/app-switch.component';
|
||||
import { AppTagComponent } from '../../../shared/ui/tag/app-tag.component';
|
||||
import { type SelectOption } from '../../../shared/ui/select/app-select.options';
|
||||
|
||||
type OrganizationMode = 'BOOK_PER_FILE' | 'BOOK_PER_FOLDER';
|
||||
type MetadataSource = 'EMBEDDED' | 'SIDECAR' | 'PREFER_SIDECAR' | 'PREFER_EMBEDDED' | 'NONE';
|
||||
|
||||
interface LibraryFormModel {
|
||||
name: string;
|
||||
folders: string[];
|
||||
organizationMode: OrganizationMode;
|
||||
metadataSource: MetadataSource;
|
||||
allowedFormats: string[];
|
||||
watch: boolean;
|
||||
}
|
||||
|
||||
const TAKEN_NAMES = ['fiction', 'comics'];
|
||||
const RESERVED_NAMES = ['all books', 'unshelved'];
|
||||
const PATH_SEPARATOR = /[\\/]/;
|
||||
|
||||
function createInitialModel(): LibraryFormModel {
|
||||
return {
|
||||
name: '',
|
||||
folders: [],
|
||||
organizationMode: 'BOOK_PER_FILE',
|
||||
metadataSource: 'EMBEDDED',
|
||||
allowedFormats: ['EPUB', 'PDF'],
|
||||
watch: true,
|
||||
};
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-library-form-example',
|
||||
standalone: true,
|
||||
host: { class: 'block h-full min-h-0' },
|
||||
imports: [
|
||||
CdkScrollable,
|
||||
JsonPipe,
|
||||
FormField,
|
||||
FormRoot,
|
||||
AppButtonComponent,
|
||||
AppFieldComponent,
|
||||
AppInputComponent,
|
||||
AppMessageComponent,
|
||||
AppMultiAutocompleteComponent,
|
||||
AppMultiSelectComponent,
|
||||
AppRadioGroupComponent,
|
||||
AppSelectComponent,
|
||||
AppSwitchComponent,
|
||||
AppTagComponent,
|
||||
],
|
||||
templateUrl: './library-form.component.html',
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class LibraryFormExampleComponent {
|
||||
private readonly router = inject(Router);
|
||||
|
||||
readonly submitState = signal<'idle' | 'saved'>('idle');
|
||||
readonly submitAttempted = signal(false);
|
||||
|
||||
readonly model = signal<LibraryFormModel>(createInitialModel());
|
||||
readonly libraryForm = form(
|
||||
this.model,
|
||||
path => {
|
||||
required(path.name, { message: 'Give the library a name' });
|
||||
minLength(path.name, 2, { message: 'Use at least 2 characters' });
|
||||
validate(path.name, ({ value }) => {
|
||||
const name = value().trim();
|
||||
if (PATH_SEPARATOR.test(name)) return { kind: 'nameFormat', message: 'Name cannot contain / or \\' };
|
||||
if (RESERVED_NAMES.includes(name.toLowerCase())) return { kind: 'nameReserved', message: `"${name}" is a reserved name` };
|
||||
return null;
|
||||
});
|
||||
minLength(path.folders, 1, { message: 'Add at least one folder' });
|
||||
minLength(path.allowedFormats, 1, { message: 'Allow at least one format' });
|
||||
validate(path.watch, ({ value, valueOf }) =>
|
||||
value() && valueOf(path.metadataSource) === 'NONE'
|
||||
? { kind: 'watchWithoutMetadata', message: 'Pick a metadata source or turn watching off' }
|
||||
: null,
|
||||
);
|
||||
},
|
||||
{
|
||||
submission: {
|
||||
action: async field => {
|
||||
this.submitState.set('idle');
|
||||
this.submitAttempted.set(true);
|
||||
await delay(900);
|
||||
const name = this.model().name.trim();
|
||||
if (TAKEN_NAMES.includes(name.toLowerCase())) {
|
||||
return [{ fieldTree: field.name, kind: 'server', message: `A library named "${name}" already exists` }];
|
||||
}
|
||||
this.submitState.set('saved');
|
||||
return undefined;
|
||||
},
|
||||
onInvalid: field => {
|
||||
this.submitState.set('idle');
|
||||
this.submitAttempted.set(true);
|
||||
field().errorSummary()[0]?.fieldTree().focusBoundControl();
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
readonly organizationOptions: readonly RadioOption<OrganizationMode>[] = [
|
||||
{ label: 'One book per file', value: 'BOOK_PER_FILE', description: 'Each file is separate.' },
|
||||
{ label: 'One book per folder', value: 'BOOK_PER_FOLDER', description: 'Group files by folder.' },
|
||||
];
|
||||
readonly metadataSourceOptions: readonly SelectOption<MetadataSource>[] = [
|
||||
{ label: 'Embedded', value: 'EMBEDDED' },
|
||||
{ label: 'Sidecar (.opf)', value: 'SIDECAR' },
|
||||
{ label: 'Prefer sidecar', value: 'PREFER_SIDECAR' },
|
||||
{ label: 'Prefer embedded', value: 'PREFER_EMBEDDED' },
|
||||
{ label: 'No metadata', value: 'NONE' },
|
||||
];
|
||||
readonly formatOptions: readonly SelectOption<string>[] = [
|
||||
{ label: 'EPUB', value: 'EPUB' },
|
||||
{ label: 'PDF', value: 'PDF' },
|
||||
{ label: 'CBX', value: 'CBX' },
|
||||
{ label: 'MOBI', value: 'MOBI' },
|
||||
{ label: 'AZW3', value: 'AZW3' },
|
||||
{ label: 'FB2', value: 'FB2' },
|
||||
{ label: 'Audiobook', value: 'AUDIOBOOK' },
|
||||
];
|
||||
|
||||
private readonly allFolders = ['/books', '/books/sci-fi', '/books/fantasy', '/comics', '/audiobooks', '/imports'];
|
||||
readonly folderSuggestions = signal<string[]>([]);
|
||||
|
||||
filterFolders(query: string): void {
|
||||
const q = query.trim().toLowerCase();
|
||||
const chosen = this.model().folders;
|
||||
this.folderSuggestions.set(
|
||||
q ? this.allFolders.filter(folder => folder.toLowerCase().includes(q) && !chosen.includes(folder)) : [],
|
||||
);
|
||||
}
|
||||
|
||||
validateAll(): void {
|
||||
this.submitState.set('idle');
|
||||
this.libraryForm().markAsTouched();
|
||||
}
|
||||
|
||||
reset(): void {
|
||||
this.submitState.set('idle');
|
||||
this.submitAttempted.set(false);
|
||||
this.model.set(createInitialModel());
|
||||
this.libraryForm().reset();
|
||||
}
|
||||
|
||||
back(): void {
|
||||
void this.router.navigate(['/design-system']);
|
||||
}
|
||||
}
|
||||
|
||||
function delay(ms: number): Promise<void> {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
Reference in New Issue
Block a user