-
Notifications
You must be signed in to change notification settings - Fork 4
docs(*): Add stories for UI components and behavior demonstrations #155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
glenstaes
wants to merge
5
commits into
master
Choose a base branch
from
feature/new-stories
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7f34b19
docs(common-components): add form-table story with editable reactive-…
glenstaes a77f328
docs(common): add stories to demonstrate error handling behaviors
glenstaes 1b062c1
docs(common): add in-memory logger stories to demonstrate logging fun…
glenstaes 3bf63b4
docs(common-components): add stories for filtering, pagination, and t…
glenstaes 2e8aac5
docs(common-components): add stories for expandable card component wi…
glenstaes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 148 additions & 0 deletions
148
projects/ppwcode/ng-common-components/src/lib/table/form-table.stories.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| import { JsonPipe } from '@angular/common' | ||
| import { ChangeDetectionStrategy, Component, input, OnInit, viewChild } from '@angular/core' | ||
| import { toSignal } from '@angular/core/rxjs-interop' | ||
| import { FormArray, FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms' | ||
| import { MatIconButton } from '@angular/material/button' | ||
| import { MatCardModule } from '@angular/material/card' | ||
| import { MatFormFieldModule } from '@angular/material/form-field' | ||
| import { MatIcon } from '@angular/material/icon' | ||
| import { MatInput } from '@angular/material/input' | ||
| import { TranslateModule } from '@ngx-translate/core' | ||
| import { Meta, moduleMetadata, StoryObj } from '@storybook/angular-vite' | ||
| import { map } from 'rxjs' | ||
| import { FormTableComponent } from './form-table.component' | ||
| import { PpwTableOptions } from './options/table-options' | ||
| import { PpwTableModule } from './table.module' | ||
|
|
||
| type TodoForm = FormGroup<{ label: FormControl<string> }> | ||
|
|
||
| @Component({ | ||
| selector: 'ppw-form-table-story', | ||
| standalone: true, | ||
| changeDetection: ChangeDetectionStrategy.OnPush, | ||
| imports: [ | ||
| JsonPipe, | ||
| ReactiveFormsModule, | ||
| PpwTableModule, | ||
| MatCardModule, | ||
| MatFormFieldModule, | ||
| MatInput, | ||
| MatIcon, | ||
| MatIconButton, | ||
| TranslateModule | ||
| ], | ||
| template: ` | ||
| <div class="flex-column gap-8 padding-8"> | ||
| <mat-card> | ||
| <mat-card-content> | ||
| <form [formGroup]="todoForm"> | ||
| <ppw-form-table [data]="todos" [options]="tableOptions" [trackBy]="trackByFn"> | ||
| <ppw-column name="label" type="template" label="Todo's"> | ||
| <ng-template ppw-column-cell let-record> | ||
| <mat-form-field class="full-width"> | ||
| <mat-label>Enter a todo item</mat-label> | ||
| <input matInput [formControl]="record.controls.label" /> | ||
| </mat-form-field> | ||
| </ng-template> | ||
| </ppw-column> | ||
| <ppw-column name="actions" type="template"> | ||
| <ng-template ppw-column-header> | ||
| <button mat-icon-button type="button" aria-label="Add todo" (click)="addItem()"> | ||
| <mat-icon>add</mat-icon> | ||
| </button> | ||
| </ng-template> | ||
| <ng-template ppw-column-cell let-record> | ||
| <button | ||
| mat-icon-button | ||
| type="button" | ||
| aria-label="Delete todo" | ||
| (click)="removeItem(record)" | ||
| > | ||
| <mat-icon>delete</mat-icon> | ||
| </button> | ||
| </ng-template> | ||
| </ppw-column> | ||
| </ppw-form-table> | ||
| </form> | ||
| </mat-card-content> | ||
| </mat-card> | ||
| <mat-card> | ||
| <mat-card-header> | ||
| <mat-card-title>Current form array value:</mat-card-title> | ||
| </mat-card-header> | ||
| <mat-card-content> | ||
| <pre data-testid="form-value">{{ formValue() | json }}</pre> | ||
| </mat-card-content> | ||
| </mat-card> | ||
| </div> | ||
| ` | ||
| }) | ||
| class FormTableStoryComponent implements OnInit { | ||
| readonly initialTodos = input<string[]>([]) | ||
| protected readonly table = viewChild.required<FormTableComponent<TodoForm>>(FormTableComponent) | ||
| protected readonly todos = new FormArray<TodoForm>([]) | ||
| protected readonly todoForm = new FormGroup({ todos: this.todos }) | ||
| protected readonly formValue = toSignal(this.todos.valueChanges.pipe(map(() => this.todos.getRawValue())), { | ||
| initialValue: this.todos.getRawValue() | ||
| }) | ||
| protected readonly tableOptions: PpwTableOptions<TodoForm> = { | ||
| header: { sticky: true, styles: { actions: () => ({ 'text-align': 'right' }) } }, | ||
| columns: { | ||
| styles: { actions: () => ({ 'text-align': 'right' }) }, | ||
| widths: { label: '100%', actions: '80px' } | ||
| }, | ||
| rows: { highlightOnHover: false } | ||
| } | ||
| protected readonly trackByFn = (_index: number, control: TodoForm): TodoForm => control | ||
|
|
||
| ngOnInit(): void { | ||
| for (const label of this.initialTodos()) { | ||
| this.todos.push(this.createTodo(label)) | ||
| } | ||
| } | ||
|
|
||
| protected addItem(): void { | ||
| this.table().addControl(this.createTodo('')) | ||
| } | ||
|
|
||
| protected removeItem(control: TodoForm): void { | ||
| this.table().removeControl(control) | ||
| } | ||
|
|
||
| private createTodo(label: string): TodoForm { | ||
| return new FormGroup({ label: new FormControl(label, { nonNullable: true, validators: Validators.required }) }) | ||
| } | ||
| } | ||
|
|
||
| const meta: Meta<FormTableStoryComponent> = { | ||
| title: 'ng-common-components/Table/Form', | ||
| component: FormTableStoryComponent, | ||
| subcomponents: { FormTableComponent }, | ||
| decorators: [moduleMetadata({ imports: [FormTableStoryComponent, TranslateModule] })], | ||
| tags: ['autodocs'], | ||
| argTypes: { | ||
| initialTodos: { | ||
| control: false, | ||
| description: 'Initial todo labels, used when the story is created. Edit rows directly in the table.' | ||
| } | ||
| }, | ||
| parameters: { | ||
| docs: { | ||
| description: { | ||
| component: | ||
| 'Editable reactive-form rows backed by a FormArray of FormGroups. Add and remove rows through the form table methods, edit required todo labels, and inspect the live form value below.' | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export default meta | ||
| type Story = StoryObj<FormTableStoryComponent> | ||
|
|
||
| export const Empty: Story = { | ||
| args: { initialTodos: [] } | ||
| } | ||
|
|
||
| export const Populated: Story = { | ||
| args: { initialTodos: ['Review the pull request', 'Update the documentation'] } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.