/
githubmirror
/
components
Обзор
Документация
Войти
/
githubmirror
/
components
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/dev-app/chips/chips-demo.ts
140 строк
4 KB
Kristiyan Kostadinov
build: remove explicit OnPush from dev app
18 май 2026, 10:44
18 май 2026, 10:44
40d7c5a
Код
Авторство
О чём код?
/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ import {LiveAnnouncer} from '@angular/cdk/a11y'; import {COMMA, ENTER} from '@angular/cdk/keycodes'; import {Component, inject} from '@angular/core'; import {FormsModule, ReactiveFormsModule} from '@angular/forms'; import {MatButtonModule} from '@angular/material/button'; import {MatCardModule} from '@angular/material/card'; import {MatCheckboxModule} from '@angular/material/checkbox'; import {MatChipEditedEvent, MatChipInputEvent, MatChipsModule} from '@angular/material/chips'; import {ThemePalette} from '@angular/material/core'; import {MatFormFieldModule} from '@angular/material/form-field'; import {MatIconModule} from '@angular/material/icon'; export interface Person { name: string; avatar?: string; } export interface DemoColor { name: string; color: ThemePalette; } @Component({ selector: 'chips-demo', templateUrl: 'chips-demo.html', styleUrl: 'chips-demo.css', imports: [ FormsModule, MatButtonModule, MatCardModule, MatCheckboxModule, MatChipsModule, MatFormFieldModule, MatIconModule, ReactiveFormsModule, ], }) export class ChipsDemo { visible = true; selectable = true; removable = true; addOnBlur = true; disabledListboxes = false; listboxesWithAvatar = false; disableInputs = false; editable = false; peopleWithAvatar = false; showEditIcon = false; disabledInteractive = false; message = ''; shirtSizes = [ {label: 'Extra Small', avatar: 'XS', disabled: false}, {label: 'Small', avatar: 'S', disabled: false}, {label: 'Medium', avatar: 'M', disabled: true}, {label: 'Large', avatar: 'L', disabled: false}, ]; restaurantHints = [ {label: 'Open Now', avatar: 'O', selected: true}, {label: 'Takes Reservations', avatar: 'R', selected: false}, {label: 'Pet Friendly', avatar: 'P', selected: true}, {label: 'Good for Brunch', avatar: 'B', selected: false}, ]; // Enter, comma, semi-colon separatorKeysCodes = [ENTER, COMMA, 186]; selectedPeople = null; people: Person[] = [ {name: 'Kara', avatar: 'K'}, {name: 'Jeremy', avatar: 'J'}, {name: 'Topher', avatar: 'T'}, {name: 'Elad', avatar: 'E'}, {name: 'Kristiyan', avatar: 'K'}, {name: 'Paul', avatar: 'P'}, ]; availableColors: DemoColor[] = [ {name: 'none', color: undefined}, {name: 'Primary', color: 'primary'}, {name: 'Accent', color: 'accent'}, {name: 'Warn', color: 'warn'}, ]; announcer = inject(LiveAnnouncer); displayMessage(message: string): void { this.message = message; } add(event: MatChipInputEvent): void { const value = (event.value || '').trim(); // Add our person if (value) { this.people.push({name: value}); } // Clear the input value event.chipInput!.clear(); } remove(person: Person): void { const index = this.people.indexOf(person); if (index >= 0) { this.people.splice(index, 1); this.announcer.announce(`Removed ${person.name}`); } } edit(person: Person, event: MatChipEditedEvent): void { if (!event.value.trim().length) { this.remove(person); return; } const index = this.people.indexOf(person); const newPeople = this.people.slice(); newPeople[index] = {...newPeople[index], name: event.value}; this.people = newPeople; } toggleVisible(): void { this.visible = false; } selectedColors: string[] = ['Primary', 'Warn']; selectedColor = 'Accent'; }