@exhaustive-ui/mcp 0.0.0-stage → 3.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +23 -0
- package/README.md +167 -2
- package/data/components/accordion.md +421 -0
- package/data/components/animateonscroll.md +163 -0
- package/data/components/autocomplete.md +1077 -0
- package/data/components/autofocus.md +38 -0
- package/data/components/avatar.md +417 -0
- package/data/components/badge.md +234 -0
- package/data/components/blockui.md +108 -0
- package/data/components/breadcrumb.md +178 -0
- package/data/components/button.md +774 -0
- package/data/components/card.md +138 -0
- package/data/components/carousel.md +440 -0
- package/data/components/cascadeselect.md +1387 -0
- package/data/components/chart.md +1178 -0
- package/data/components/checkbox.md +529 -0
- package/data/components/chip.md +180 -0
- package/data/components/colorpicker.md +301 -0
- package/data/components/confirmdialog.md +287 -0
- package/data/components/confirmpopup.md +417 -0
- package/data/components/contextmenu.md +491 -0
- package/data/components/dataview.md +600 -0
- package/data/components/datepicker.md +1262 -0
- package/data/components/dialog.md +622 -0
- package/data/components/divider.md +250 -0
- package/data/components/dock.md +500 -0
- package/data/components/dragdrop.md +285 -0
- package/data/components/drawer.md +510 -0
- package/data/components/dynamicdialog.md +109 -0
- package/data/components/editor.md +291 -0
- package/data/components/fieldset.md +182 -0
- package/data/components/fileupload.md +430 -0
- package/data/components/floatlabel.md +155 -0
- package/data/components/fluid.md +72 -0
- package/data/components/focustrap.md +65 -0
- package/data/components/galleria.md +627 -0
- package/data/components/iconfield.md +246 -0
- package/data/components/iftalabel.md +105 -0
- package/data/components/imagecompare.md +97 -0
- package/data/components/inplace.md +233 -0
- package/data/components/inputgroup.md +306 -0
- package/data/components/inputmask.md +518 -0
- package/data/components/inputnumber.md +675 -0
- package/data/components/inputotp.md +336 -0
- package/data/components/inputtext.md +488 -0
- package/data/components/keyfilter.md +85 -0
- package/data/components/knob.md +462 -0
- package/data/components/listbox.md +798 -0
- package/data/components/llms.md +28 -0
- package/data/components/megamenu.md +587 -0
- package/data/components/menu.md +483 -0
- package/data/components/menubar.md +462 -0
- package/data/components/message.md +449 -0
- package/data/components/metergroup.md +241 -0
- package/data/components/multiselect.md +1047 -0
- package/data/components/orderlist.md +342 -0
- package/data/components/organizationchart.md +197 -0
- package/data/components/overlay.md +217 -0
- package/data/components/paginator.md +314 -0
- package/data/components/panel.md +214 -0
- package/data/components/panelmenu.md +699 -0
- package/data/components/password.md +570 -0
- package/data/components/picklist.md +420 -0
- package/data/components/popover.md +378 -0
- package/data/components/progressbar.md +181 -0
- package/data/components/progressspinner.md +91 -0
- package/data/components/radiobutton.md +377 -0
- package/data/components/rating.md +312 -0
- package/data/components/ripple.md +89 -0
- package/data/components/scroller.md +122 -0
- package/data/components/scrollpanel.md +149 -0
- package/data/components/scrolltop.md +105 -0
- package/data/components/select.md +1206 -0
- package/data/components/selectbutton.md +356 -0
- package/data/components/skeleton.md +242 -0
- package/data/components/slider.md +337 -0
- package/data/components/speeddial.md +589 -0
- package/data/components/splitbutton.md +945 -0
- package/data/components/splitter.md +196 -0
- package/data/components/stepper.md +411 -0
- package/data/components/styleclass.md +126 -0
- package/data/components/table.md +4557 -0
- package/data/components/tabs.md +467 -0
- package/data/components/tag.md +200 -0
- package/data/components/terminal.md +118 -0
- package/data/components/textarea.md +416 -0
- package/data/components/tieredmenu.md +578 -0
- package/data/components/timeline.md +310 -0
- package/data/components/toast.md +596 -0
- package/data/components/togglebutton.md +356 -0
- package/data/components/toggleswitch.md +285 -0
- package/data/components/toolbar.md +182 -0
- package/data/components/tooltip.md +211 -0
- package/data/components/tree.md +746 -0
- package/data/components/treeselect.md +912 -0
- package/data/components/treetable.md +2814 -0
- package/data/components.json +43751 -0
- package/data/llms-full.txt +47433 -0
- package/data/llms.txt +121 -0
- package/data/manifest.json +46513 -0
- package/data/pages/accessibility.md +28 -0
- package/data/pages/animations.md +28 -0
- package/data/pages/configuration.md +210 -0
- package/data/pages/contribution.md +20 -0
- package/data/pages/customicons.md +20 -0
- package/data/pages/faq.md +20 -0
- package/data/pages/icons.md +66 -0
- package/data/pages/installation.md +71 -0
- package/data/pages/llms.md +61 -0
- package/data/pages/passthrough.md +32 -0
- package/data/pages/philosophy.md +28 -0
- package/data/pages/primeflex.md +20 -0
- package/data/pages/rtl.md +12 -0
- package/data/pages/styled.md +132 -0
- package/data/pages/tailwind.md +40 -0
- package/data/pages/unstyled.md +39 -0
- package/data/snapshot.json +9 -0
- package/dist/index.d.mts +448 -0
- package/dist/index.mjs +2501 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +67 -3
|
@@ -0,0 +1,529 @@
|
|
|
1
|
+
# Angular Checkbox Component
|
|
2
|
+
|
|
3
|
+
Checkbox is an extension to standard checkbox element with theming.
|
|
4
|
+
|
|
5
|
+
## Accessibility
|
|
6
|
+
|
|
7
|
+
Screen Reader Checkbox component uses a hidden native checkbox element internally that is only visible to screen readers. Value to describe the component can either be provided via label tag combined with inputId prop or using ariaLabelledBy , ariaLabel props.
|
|
8
|
+
|
|
9
|
+
## Basic
|
|
10
|
+
|
|
11
|
+
Binary checkbox is used as a controlled input with ngModel and binary properties.
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { Component } from '@angular/core';
|
|
15
|
+
import { FormsModule } from '@angular/forms';
|
|
16
|
+
import { CheckboxModule } from '@exhaustive-ui/core/checkbox';
|
|
17
|
+
|
|
18
|
+
@Component({
|
|
19
|
+
template: `
|
|
20
|
+
<div class="card flex justify-center gap-4">
|
|
21
|
+
<p-checkbox [(ngModel)]="checked" [binary]="true" />
|
|
22
|
+
</div>
|
|
23
|
+
`,
|
|
24
|
+
standalone: true,
|
|
25
|
+
imports: [CheckboxModule, FormsModule]
|
|
26
|
+
})
|
|
27
|
+
export class CheckboxBasicDemo {
|
|
28
|
+
checked: any = null;
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Disabled
|
|
33
|
+
|
|
34
|
+
When disabled is present, the element cannot be edited and focused.
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { Component } from '@angular/core';
|
|
38
|
+
import { FormsModule } from '@angular/forms';
|
|
39
|
+
import { CheckboxModule } from '@exhaustive-ui/core/checkbox';
|
|
40
|
+
|
|
41
|
+
@Component({
|
|
42
|
+
template: `
|
|
43
|
+
<div class="card flex justify-center gap-2">
|
|
44
|
+
<p-checkbox [(ngModel)]="checked1" [binary]="true" [disabled]="true" />
|
|
45
|
+
<p-checkbox [(ngModel)]="checked2" [binary]="true" [disabled]="true" />
|
|
46
|
+
</div>
|
|
47
|
+
`,
|
|
48
|
+
standalone: true,
|
|
49
|
+
imports: [CheckboxModule, FormsModule]
|
|
50
|
+
})
|
|
51
|
+
export class CheckboxDisabledDemo {
|
|
52
|
+
checked1: boolean = false;
|
|
53
|
+
checked2: boolean = true;
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Dynamic
|
|
58
|
+
|
|
59
|
+
Checkboxes can be generated using a list of values.
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import { Component, OnInit } from '@angular/core';
|
|
63
|
+
import { FormsModule } from '@angular/forms';
|
|
64
|
+
import { CheckboxModule } from '@exhaustive-ui/core/checkbox';
|
|
65
|
+
|
|
66
|
+
@Component({
|
|
67
|
+
template: `
|
|
68
|
+
<div class="card flex justify-center">
|
|
69
|
+
<div class="flex flex-col gap-4">
|
|
70
|
+
<div *ngFor="let category of categories" class="flex items-center">
|
|
71
|
+
<p-checkbox [inputId]="category.key" name="group" [value]="category" [(ngModel)]="selectedCategories" />
|
|
72
|
+
<label [for]="category.key" class="ml-2"> {{ category.name }} </label>
|
|
73
|
+
</div>
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
`,
|
|
77
|
+
standalone: true,
|
|
78
|
+
imports: [CheckboxModule, FormsModule]
|
|
79
|
+
})
|
|
80
|
+
export class CheckboxDynamicDemo implements OnInit {
|
|
81
|
+
selectedCategories: any[] = [];
|
|
82
|
+
categories: any[];
|
|
83
|
+
|
|
84
|
+
ngOnInit() {
|
|
85
|
+
this.selectedCategories = [this.categories[1]];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Filled
|
|
91
|
+
|
|
92
|
+
Specify the variant property as filled to display the component with a higher visual emphasis than the default outlined style.
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
import { Component } from '@angular/core';
|
|
96
|
+
import { FormsModule } from '@angular/forms';
|
|
97
|
+
import { CheckboxModule } from '@exhaustive-ui/core/checkbox';
|
|
98
|
+
|
|
99
|
+
@Component({
|
|
100
|
+
template: `
|
|
101
|
+
<div class="card flex justify-center">
|
|
102
|
+
<p-checkbox [(ngModel)]="checked" [binary]="true" variant="filled" />
|
|
103
|
+
</div>
|
|
104
|
+
`,
|
|
105
|
+
standalone: true,
|
|
106
|
+
imports: [CheckboxModule, FormsModule]
|
|
107
|
+
})
|
|
108
|
+
export class CheckboxFilledDemo {
|
|
109
|
+
checked: boolean = false;
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Indeterminate
|
|
114
|
+
|
|
115
|
+
The indeterminate state indicates that a checkbox is neither "on" or "off".
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
import { Component } from '@angular/core';
|
|
119
|
+
import { FormsModule } from '@angular/forms';
|
|
120
|
+
import { CheckboxModule } from '@exhaustive-ui/core/checkbox';
|
|
121
|
+
|
|
122
|
+
@Component({
|
|
123
|
+
template: `
|
|
124
|
+
<div class="card flex justify-center gap-4">
|
|
125
|
+
<p-checkbox [(ngModel)]="checked" [binary]="true" [indeterminate]="true" />
|
|
126
|
+
</div>
|
|
127
|
+
`,
|
|
128
|
+
standalone: true,
|
|
129
|
+
imports: [CheckboxModule, FormsModule]
|
|
130
|
+
})
|
|
131
|
+
export class CheckboxIndeterminateDemo {
|
|
132
|
+
checked: any = null;
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Invalid
|
|
137
|
+
|
|
138
|
+
The invalid state is applied using the invalid property to indicate failed validation, which can be integrated with Angular Forms.
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
import { Component } from '@angular/core';
|
|
142
|
+
import { FormsModule } from '@angular/forms';
|
|
143
|
+
import { CheckboxModule } from '@exhaustive-ui/core/checkbox';
|
|
144
|
+
|
|
145
|
+
@Component({
|
|
146
|
+
template: `
|
|
147
|
+
<div class="card flex justify-center">
|
|
148
|
+
<p-checkbox [(ngModel)]="checked" [binary]="true" [invalid]="!checked" />
|
|
149
|
+
</div>
|
|
150
|
+
`,
|
|
151
|
+
standalone: true,
|
|
152
|
+
imports: [CheckboxModule, FormsModule]
|
|
153
|
+
})
|
|
154
|
+
export class CheckboxInvalidDemo {
|
|
155
|
+
checked: boolean = false;
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## label-doc
|
|
160
|
+
|
|
161
|
+
The label attribute provides a label text for the checkbox. This label is also clickable and toggles the checked state.
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
import { Component } from '@angular/core';
|
|
165
|
+
import { FormsModule } from '@angular/forms';
|
|
166
|
+
import { CheckboxModule } from '@exhaustive-ui/core/checkbox';
|
|
167
|
+
|
|
168
|
+
@Component({
|
|
169
|
+
template: `
|
|
170
|
+
<div class="card flex justify-center gap-4">
|
|
171
|
+
<p-checkbox name="groupname" value="val1" label="Value 1" [(ngModel)]="selectedValues"></p-checkbox>
|
|
172
|
+
<p-checkbox name="groupname" value="val2" label="Value 2" [(ngModel)]="selectedValues"></p-checkbox>
|
|
173
|
+
</div>
|
|
174
|
+
`,
|
|
175
|
+
standalone: true,
|
|
176
|
+
imports: [CheckboxModule, FormsModule]
|
|
177
|
+
})
|
|
178
|
+
export class CheckboxLabelDemo {
|
|
179
|
+
selectedValues: string[] = [];
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## multiple-doc
|
|
184
|
+
|
|
185
|
+
Multiple checkboxes can be grouped together.
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
import { Component } from '@angular/core';
|
|
189
|
+
import { FormsModule } from '@angular/forms';
|
|
190
|
+
import { CheckboxModule } from '@exhaustive-ui/core/checkbox';
|
|
191
|
+
|
|
192
|
+
@Component({
|
|
193
|
+
template: `
|
|
194
|
+
<div class="card flex flex-wrap justify-center gap-4">
|
|
195
|
+
<div class="flex items-center">
|
|
196
|
+
<p-checkbox inputId="ingredient1" name="pizza" value="Cheese" [(ngModel)]="pizza" />
|
|
197
|
+
<label for="ingredient1" class="ml-2"> Cheese </label>
|
|
198
|
+
</div>
|
|
199
|
+
<div class="flex items-center">
|
|
200
|
+
<p-checkbox inputId="ingredient2" name="pizza" value="Mushroom" [(ngModel)]="pizza" />
|
|
201
|
+
<label for="ingredient2" class="ml-2"> Mushroom </label>
|
|
202
|
+
</div>
|
|
203
|
+
<div class="flex items-center">
|
|
204
|
+
<p-checkbox inputId="ingredient3" name="pizza" value="Pepper" [(ngModel)]="pizza" />
|
|
205
|
+
<label for="ingredient3" class="ml-2"> Pepper </label>
|
|
206
|
+
</div>
|
|
207
|
+
<div class="flex items-center">
|
|
208
|
+
<p-checkbox inputId="ingredient4" name="pizza" value="Onion" [(ngModel)]="pizza" />
|
|
209
|
+
<label for="ingredient4" class="ml-2"> Onion </label>
|
|
210
|
+
</div>
|
|
211
|
+
</div>
|
|
212
|
+
`,
|
|
213
|
+
standalone: true,
|
|
214
|
+
imports: [CheckboxModule, FormsModule]
|
|
215
|
+
})
|
|
216
|
+
export class CheckboxMultipleDemo {
|
|
217
|
+
pizza: string[] = [];
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## reactiveforms-doc
|
|
222
|
+
|
|
223
|
+
Checkbox can also be used with reactive forms. In this case, the formControlName property is used to bind the component to a form control.
|
|
224
|
+
|
|
225
|
+
```typescript
|
|
226
|
+
import { Component, inject } from '@angular/core';
|
|
227
|
+
import { ReactiveFormsModule } from '@angular/forms';
|
|
228
|
+
import { CheckboxModule } from '@exhaustive-ui/core/checkbox';
|
|
229
|
+
import { MessageModule } from '@exhaustive-ui/core/message';
|
|
230
|
+
import { ToastModule } from '@exhaustive-ui/core/toast';
|
|
231
|
+
import { ButtonModule } from '@exhaustive-ui/core/button';
|
|
232
|
+
import { MessageService } from '@exhaustive-ui/core/api';
|
|
233
|
+
|
|
234
|
+
@Component({
|
|
235
|
+
template: `
|
|
236
|
+
<p-toast />
|
|
237
|
+
<div class="card flex justify-center">
|
|
238
|
+
<form [formGroup]="exampleForm" (ngSubmit)="onSubmit()" class="flex flex-col gap-4">
|
|
239
|
+
<div class="flex flex-wrap gap-4">
|
|
240
|
+
@for (item of formKeys; track item) {
|
|
241
|
+
<div class="flex items-center gap-2">
|
|
242
|
+
<p-checkbox [formControlName]="item" [binary]="true" [inputId]="item" [invalid]="isInvalid(item)" />
|
|
243
|
+
<label [for]="item"> {{ item | titlecase }} </label>
|
|
244
|
+
</div>
|
|
245
|
+
}
|
|
246
|
+
</div>
|
|
247
|
+
@if (hasAnyInvalid()) {
|
|
248
|
+
<p-message severity="error" size="small" variant="simple"> At least one ingredient must be selected. </p-message>
|
|
249
|
+
}
|
|
250
|
+
<button pButton severity="secondary" type="submit">
|
|
251
|
+
<span pButtonLabel>Submit</span>
|
|
252
|
+
</button>
|
|
253
|
+
</form>
|
|
254
|
+
</div>
|
|
255
|
+
`,
|
|
256
|
+
standalone: true,
|
|
257
|
+
imports: [CheckboxModule, MessageModule, ToastModule, ButtonModule, ReactiveFormsModule]
|
|
258
|
+
})
|
|
259
|
+
export class CheckboxReactiveformsDemo {
|
|
260
|
+
messageService = inject(MessageService);
|
|
261
|
+
formSubmitted: boolean = false;
|
|
262
|
+
exampleForm: FormGroup;
|
|
263
|
+
|
|
264
|
+
constructor() {
|
|
265
|
+
this.exampleForm = this.fb.group(
|
|
266
|
+
{
|
|
267
|
+
cheese: [false],
|
|
268
|
+
mushroom: [false],
|
|
269
|
+
pepper: [false],
|
|
270
|
+
onion: [false]
|
|
271
|
+
},
|
|
272
|
+
{ validators: this.atLeastOneSelectedValidator }
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
atLeastOneSelectedValidator(group: FormGroup) {
|
|
277
|
+
[key: string]: any } | null {
|
|
278
|
+
const anySelected = Object.values(group.controls).some((control) => control.value === true);
|
|
279
|
+
return anySelected ? null : { atLeastOneRequired: true };
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
hasAnyInvalid(): boolean {
|
|
283
|
+
return this.formSubmitted && this.exampleForm.hasError('atLeastOneRequired');
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
isInvalid(controlName: string): boolean {
|
|
287
|
+
const control = this.exampleForm.get(controlName);
|
|
288
|
+
return this.formSubmitted && this.exampleForm.hasError('atLeastOneRequired') && control?.value === false;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
onSubmit() {
|
|
292
|
+
this.formSubmitted = true;
|
|
293
|
+
|
|
294
|
+
if (this.exampleForm.valid) {
|
|
295
|
+
this.messageService.add({
|
|
296
|
+
severity: 'success',
|
|
297
|
+
summary: 'Success',
|
|
298
|
+
detail: 'Form is submitted',
|
|
299
|
+
life: 3000
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
this.exampleForm.reset({
|
|
303
|
+
cheese: false,
|
|
304
|
+
mushroom: false,
|
|
305
|
+
pepper: false,
|
|
306
|
+
onion: false
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
this.formSubmitted = false;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
## Sizes
|
|
316
|
+
|
|
317
|
+
Checkbox provides small and large sizes as alternatives to the base.
|
|
318
|
+
|
|
319
|
+
```typescript
|
|
320
|
+
import { Component } from '@angular/core';
|
|
321
|
+
import { FormsModule } from '@angular/forms';
|
|
322
|
+
import { CheckboxModule } from '@exhaustive-ui/core/checkbox';
|
|
323
|
+
|
|
324
|
+
@Component({
|
|
325
|
+
template: `
|
|
326
|
+
<div class="card flex flex-wrap justify-center gap-4">
|
|
327
|
+
<div class="flex items-center gap-2">
|
|
328
|
+
<p-checkbox [(ngModel)]="size" inputId="size_small" name="size" value="Small" size="small" />
|
|
329
|
+
<label for="size_small" class="text-sm">Small</label>
|
|
330
|
+
</div>
|
|
331
|
+
<div class="flex items-center gap-2">
|
|
332
|
+
<p-checkbox [(ngModel)]="size" inputId="size_normal" name="size" value="Normal" />
|
|
333
|
+
<label for="size_normal">Normal</label>
|
|
334
|
+
</div>
|
|
335
|
+
<div class="flex items-center gap-2">
|
|
336
|
+
<p-checkbox [(ngModel)]="size" inputId="size_large" name="size" value="Large" size="large" />
|
|
337
|
+
<label for="size_large" class="text-lg">Large</label>
|
|
338
|
+
</div>
|
|
339
|
+
</div>
|
|
340
|
+
`,
|
|
341
|
+
standalone: true,
|
|
342
|
+
imports: [CheckboxModule, FormsModule]
|
|
343
|
+
})
|
|
344
|
+
export class CheckboxSizesDemo {
|
|
345
|
+
size: any = null;
|
|
346
|
+
}
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
## templatedrivenforms-doc
|
|
350
|
+
|
|
351
|
+
```typescript
|
|
352
|
+
import { Component, inject } from '@angular/core';
|
|
353
|
+
import { FormsModule } from '@angular/forms';
|
|
354
|
+
import { CheckboxModule } from '@exhaustive-ui/core/checkbox';
|
|
355
|
+
import { MessageModule } from '@exhaustive-ui/core/message';
|
|
356
|
+
import { ToastModule } from '@exhaustive-ui/core/toast';
|
|
357
|
+
import { ButtonModule } from '@exhaustive-ui/core/button';
|
|
358
|
+
import { MessageService } from '@exhaustive-ui/core/api';
|
|
359
|
+
|
|
360
|
+
@Component({
|
|
361
|
+
template: `
|
|
362
|
+
<p-toast />
|
|
363
|
+
<div class="card flex justify-center">
|
|
364
|
+
<form #form="ngForm" (ngSubmit)="onSubmit(form)" class="flex flex-col gap-4">
|
|
365
|
+
<div class="flex flex-wrap gap-4">
|
|
366
|
+
@for (item of formKeys; track item) {
|
|
367
|
+
<div class="flex items-center gap-2">
|
|
368
|
+
<p-checkbox [inputId]="item" [name]="item" [(ngModel)]="formModel[item]" [binary]="true" [invalid]="isInvalid()"></p-checkbox>
|
|
369
|
+
<label [for]="item">{{ item | titlecase }}</label>
|
|
370
|
+
</div>
|
|
371
|
+
}
|
|
372
|
+
</div>
|
|
373
|
+
@if (isInvalid()) {
|
|
374
|
+
<p-message severity="error" size="small" variant="simple"> At least one ingredient must be selected. </p-message>
|
|
375
|
+
}
|
|
376
|
+
<button pButton severity="secondary" type="submit">
|
|
377
|
+
<span pButtonLabel>Submit</span>
|
|
378
|
+
</button>
|
|
379
|
+
</form>
|
|
380
|
+
</div>
|
|
381
|
+
`,
|
|
382
|
+
standalone: true,
|
|
383
|
+
imports: [CheckboxModule, MessageModule, ToastModule, ButtonModule, FormsModule]
|
|
384
|
+
})
|
|
385
|
+
export class CheckboxTemplatedrivenformsDemo {
|
|
386
|
+
messageService = inject(MessageService);
|
|
387
|
+
formSubmitted: boolean = false;
|
|
388
|
+
formModel: any;
|
|
389
|
+
|
|
390
|
+
isInvalid(): boolean {
|
|
391
|
+
return this.formSubmitted && !this.isAtLeastOneSelected();
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
isAtLeastOneSelected(): boolean {
|
|
395
|
+
return Object.values(this.formModel).some((value) => value === true);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
onSubmit(form: NgForm) {
|
|
399
|
+
this.formSubmitted = true;
|
|
400
|
+
|
|
401
|
+
if (this.isAtLeastOneSelected()) {
|
|
402
|
+
this.messageService.add({
|
|
403
|
+
severity: 'success',
|
|
404
|
+
summary: 'Success',
|
|
405
|
+
detail: 'Form is submitted',
|
|
406
|
+
life: 3000
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
this.formModel = {
|
|
410
|
+
cheese: false,
|
|
411
|
+
mushroom: false,
|
|
412
|
+
pepper: false,
|
|
413
|
+
onion: false
|
|
414
|
+
};
|
|
415
|
+
form.resetForm(this.formModel);
|
|
416
|
+
|
|
417
|
+
this.formSubmitted = false;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
## Checkbox
|
|
424
|
+
|
|
425
|
+
Checkbox is an extension to standard checkbox element with theming.
|
|
426
|
+
|
|
427
|
+
### Props
|
|
428
|
+
|
|
429
|
+
| Name | Type | Default | Description |
|
|
430
|
+
|------|------|---------|-------------|
|
|
431
|
+
| dt | InputSignal<Object> | undefined | Defines scoped design tokens of the component. |
|
|
432
|
+
| unstyled | InputSignal<boolean> | undefined | Indicates whether the component should be rendered without styles. |
|
|
433
|
+
| pt | InputSignal<CheckboxPassThrough> | undefined | Used to pass attributes to DOM elements inside the component. |
|
|
434
|
+
| ptOptions | InputSignal<PassThroughOptions> | undefined | Used to configure passthrough(pt) options of the component. |
|
|
435
|
+
| required | InputSignalWithTransform<boolean, unknown> | false | There must be a value (if set). |
|
|
436
|
+
| invalid | InputSignalWithTransform<boolean, unknown> | false | When present, it specifies that the component should have invalid state style. |
|
|
437
|
+
| disabled | InputSignalWithTransform<boolean, unknown> | false | When present, it specifies that the component should have disabled state style. |
|
|
438
|
+
| name | InputSignal<string> | undefined | When present, it specifies that the name of the input. |
|
|
439
|
+
| value | InputSignal<any> | ... | Value of the checkbox. |
|
|
440
|
+
| binary | InputSignalWithTransform<boolean, unknown> | ... | Allows to select a boolean value instead of multiple values. |
|
|
441
|
+
| ariaLabelledBy | InputSignal<string> | ... | Establishes relationships between the component and label(s) where its value should be one or more element IDs. |
|
|
442
|
+
| ariaLabel | InputSignal<string> | ... | Used to define a string that labels the input element. |
|
|
443
|
+
| tabindex | InputSignalWithTransform<number, unknown> | ... | Index of the element in tabbing order. |
|
|
444
|
+
| inputId | InputSignal<string> | ... | Identifier of the focus input to match a label defined for the component. |
|
|
445
|
+
| inputStyle | InputSignal<{ [klass: string]: any }> | ... | Inline style of the input element. |
|
|
446
|
+
| inputClass | InputSignal<string> | ... | Style class of the input element. |
|
|
447
|
+
| indeterminate | InputSignalWithTransform<boolean, unknown> | ... | When present, it specifies input state as indeterminate. |
|
|
448
|
+
| formControl | InputSignal<FormControl<any>> | ... | Form control value. |
|
|
449
|
+
| checkboxIcon | InputSignal<string> | ... | Icon class of the checkbox icon. |
|
|
450
|
+
| readonly | InputSignalWithTransform<boolean, unknown> | ... | When present, it specifies that the component cannot be edited. |
|
|
451
|
+
| autofocus | InputSignalWithTransform<boolean, unknown> | ... | When present, it specifies that the component should automatically get focus on load. |
|
|
452
|
+
| trueValue | InputSignal<any> | ... | Value in checked state. |
|
|
453
|
+
| falseValue | InputSignal<any> | ... | Value in unchecked state. |
|
|
454
|
+
| variant | InputSignal<"outlined" \| "filled"> | undefined | Specifies the input variant of the component. |
|
|
455
|
+
| size | InputSignal<"small" \| "large"> | undefined | Specifies the size of the component. |
|
|
456
|
+
|
|
457
|
+
### Emits
|
|
458
|
+
|
|
459
|
+
| Name | Parameters | Description |
|
|
460
|
+
|------|------------|-------------|
|
|
461
|
+
| onChange | event: CheckboxChangeEvent | Callback to invoke on value change. |
|
|
462
|
+
| onFocus | event: Event | Callback to invoke when the receives focus. |
|
|
463
|
+
| onBlur | event: Event | Callback to invoke when the loses focus. |
|
|
464
|
+
|
|
465
|
+
### Templates
|
|
466
|
+
|
|
467
|
+
| Name | Type | Description |
|
|
468
|
+
|------|------|-------------|
|
|
469
|
+
| checkboxicon | TemplateRef<CheckboxIconTemplateContext> | Custom checkbox icon template. |
|
|
470
|
+
|
|
471
|
+
## Pass Through Options
|
|
472
|
+
|
|
473
|
+
| Name | Type | Description |
|
|
474
|
+
|------|------|-------------|
|
|
475
|
+
| root | PassThroughOption<HTMLElement, I> | Used to pass attributes to the root's DOM element. |
|
|
476
|
+
| input | PassThroughOption<HTMLInputElement, I> | Used to pass attributes to the input's DOM element. |
|
|
477
|
+
| box | PassThroughOption<HTMLDivElement, I> | Used to pass attributes to the box's DOM element. |
|
|
478
|
+
| icon | PassThroughOption<HTMLElement, I> | Used to pass attributes to the icon's DOM element. |
|
|
479
|
+
|
|
480
|
+
## Theming
|
|
481
|
+
|
|
482
|
+
### CSS Classes
|
|
483
|
+
|
|
484
|
+
| Class | Description |
|
|
485
|
+
|-------|-------------|
|
|
486
|
+
| p-checkbox | Class name of the root element |
|
|
487
|
+
| p-checkbox-box | Class name of the box element |
|
|
488
|
+
| p-checkbox-input | Class name of the input element |
|
|
489
|
+
| p-checkbox-icon | Class name of the icon element |
|
|
490
|
+
|
|
491
|
+
### Design Tokens
|
|
492
|
+
|
|
493
|
+
| Token | CSS Variable | Description |
|
|
494
|
+
|-------|--------------|-------------|
|
|
495
|
+
| checkbox.border.radius | --p-checkbox-border-radius | Border radius of root |
|
|
496
|
+
| checkbox.width | --p-checkbox-width | Width of root |
|
|
497
|
+
| checkbox.height | --p-checkbox-height | Height of root |
|
|
498
|
+
| checkbox.background | --p-checkbox-background | Background of root |
|
|
499
|
+
| checkbox.checked.background | --p-checkbox-checked-background | Checked background of root |
|
|
500
|
+
| checkbox.checked.hover.background | --p-checkbox-checked-hover-background | Checked hover background of root |
|
|
501
|
+
| checkbox.disabled.background | --p-checkbox-disabled-background | Disabled background of root |
|
|
502
|
+
| checkbox.filled.background | --p-checkbox-filled-background | Filled background of root |
|
|
503
|
+
| checkbox.border.color | --p-checkbox-border-color | Border color of root |
|
|
504
|
+
| checkbox.hover.border.color | --p-checkbox-hover-border-color | Hover border color of root |
|
|
505
|
+
| checkbox.focus.border.color | --p-checkbox-focus-border-color | Focus border color of root |
|
|
506
|
+
| checkbox.checked.border.color | --p-checkbox-checked-border-color | Checked border color of root |
|
|
507
|
+
| checkbox.checked.hover.border.color | --p-checkbox-checked-hover-border-color | Checked hover border color of root |
|
|
508
|
+
| checkbox.checked.focus.border.color | --p-checkbox-checked-focus-border-color | Checked focus border color of root |
|
|
509
|
+
| checkbox.checked.disabled.border.color | --p-checkbox-checked-disabled-border-color | Checked disabled border color of root |
|
|
510
|
+
| checkbox.invalid.border.color | --p-checkbox-invalid-border-color | Invalid border color of root |
|
|
511
|
+
| checkbox.shadow | --p-checkbox-shadow | Shadow of root |
|
|
512
|
+
| checkbox.focus.ring.width | --p-checkbox-focus-ring-width | Focus ring width of root |
|
|
513
|
+
| checkbox.focus.ring.style | --p-checkbox-focus-ring-style | Focus ring style of root |
|
|
514
|
+
| checkbox.focus.ring.color | --p-checkbox-focus-ring-color | Focus ring color of root |
|
|
515
|
+
| checkbox.focus.ring.offset | --p-checkbox-focus-ring-offset | Focus ring offset of root |
|
|
516
|
+
| checkbox.focus.ring.shadow | --p-checkbox-focus-ring-shadow | Focus ring shadow of root |
|
|
517
|
+
| checkbox.transition.duration | --p-checkbox-transition-duration | Transition duration of root |
|
|
518
|
+
| checkbox.sm.width | --p-checkbox-sm-width | Sm width of root |
|
|
519
|
+
| checkbox.sm.height | --p-checkbox-sm-height | Sm height of root |
|
|
520
|
+
| checkbox.lg.width | --p-checkbox-lg-width | Lg width of root |
|
|
521
|
+
| checkbox.lg.height | --p-checkbox-lg-height | Lg height of root |
|
|
522
|
+
| checkbox.icon.size | --p-checkbox-icon-size | Size of icon |
|
|
523
|
+
| checkbox.icon.color | --p-checkbox-icon-color | Color of icon |
|
|
524
|
+
| checkbox.icon.checked.color | --p-checkbox-icon-checked-color | Checked color of icon |
|
|
525
|
+
| checkbox.icon.checked.hover.color | --p-checkbox-icon-checked-hover-color | Checked hover color of icon |
|
|
526
|
+
| checkbox.icon.disabled.color | --p-checkbox-icon-disabled-color | Disabled color of icon |
|
|
527
|
+
| checkbox.icon.sm.size | --p-checkbox-icon-sm-size | Sm size of icon |
|
|
528
|
+
| checkbox.icon.lg.size | --p-checkbox-icon-lg-size | Lg size of icon |
|
|
529
|
+
|