Skip to content

Commit 68eaaf6

Browse files
authored
docs(checkbox): add indeterminate and disabled checkbox examples (#18987)
* docs(checkbox): add indeterminate and disabled checkbox examples * Make fixes
1 parent 98cb57d commit 68eaaf6

File tree

7 files changed

+88
-3
lines changed

7 files changed

+88
-3
lines changed
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1-
/** No CSS for this example */
1+
.example-section {
2+
margin: 12px 0;
3+
}
4+
5+
.example-margin {
6+
margin: 0 12px;
7+
}
8+
9+
ul {
10+
list-style-type: none;
11+
margin-top: 4px;
12+
}
Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,26 @@
1-
<mat-checkbox>Check me!</mat-checkbox>
1+
<section class="example-section">
2+
<mat-checkbox class="example-margin">Check me!</mat-checkbox>
3+
<mat-checkbox class="example-margin" [disabled]="true">Disabled</mat-checkbox>
4+
</section>
5+
6+
<section class="example-section">
7+
<span class="example-list-section">
8+
<mat-checkbox class="example-margin"
9+
[checked]="allComplete"
10+
[indeterminate]="someComplete()"
11+
(change)="setAll($event.checked)">
12+
{{task.name}}
13+
</mat-checkbox>
14+
</span>
15+
<span class="example-list-section">
16+
<ul>
17+
<li *ngFor="let subtask of task.subtasks">
18+
<mat-checkbox [(ngModel)]="subtask.completed"
19+
[color]="subtask.color"
20+
(ngModelChange)="updateAllComplete()">
21+
{{subtask.name}}
22+
</mat-checkbox>
23+
</li>
24+
</ul>
25+
</span>
26+
</section>

src/components-examples/material/checkbox/checkbox-overview/checkbox-overview-example.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
import {Component} from '@angular/core';
2+
import {ThemePalette} from '@angular/material/core';
3+
4+
export interface Task {
5+
name: string;
6+
completed: boolean;
7+
color: ThemePalette;
8+
subtasks?: Task[];
9+
}
210

311
/**
412
* @title Basic checkboxes
@@ -8,4 +16,36 @@ import {Component} from '@angular/core';
816
templateUrl: 'checkbox-overview-example.html',
917
styleUrls: ['checkbox-overview-example.css'],
1018
})
11-
export class CheckboxOverviewExample {}
19+
export class CheckboxOverviewExample {
20+
task: Task = {
21+
name: 'Indeterminate',
22+
completed: false,
23+
color: 'primary',
24+
subtasks: [
25+
{name: 'Primary', completed: false, color: 'primary'},
26+
{name: 'Accent', completed: false, color: 'accent'},
27+
{name: 'Warn', completed: false, color: 'warn'}
28+
]
29+
};
30+
31+
allComplete: boolean = false;
32+
33+
updateAllComplete() {
34+
this.allComplete = this.task.subtasks != null && this.task.subtasks.every(t => t.completed);
35+
}
36+
37+
someComplete(): boolean {
38+
if (this.task.subtasks == null) {
39+
return false;
40+
}
41+
return this.task.subtasks.filter(t => t.completed).length > 0 && !this.allComplete;
42+
}
43+
44+
setAll(completed: boolean) {
45+
this.allComplete = completed;
46+
if (this.task.subtasks == null) {
47+
return;
48+
}
49+
this.task.subtasks.forEach(t => t.completed = completed);
50+
}
51+
}

src/components-examples/material/checkbox/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {CommonModule} from '@angular/common';
12
import {NgModule} from '@angular/core';
23
import {FormsModule} from '@angular/forms';
34
import {MatCardModule} from '@angular/material/card';
@@ -18,6 +19,7 @@ const EXAMPLES = [
1819

1920
@NgModule({
2021
imports: [
22+
CommonModule,
2123
MatCardModule,
2224
MatCheckboxModule,
2325
MatRadioModule,

src/dev-app/checkbox/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ ng_module(
1111
":checkbox_demo_scss",
1212
],
1313
deps = [
14+
"//src/components-examples/material/checkbox",
1415
"//src/material/checkbox",
1516
"//src/material/core",
1617
"//src/material/form-field",

src/dev-app/checkbox/checkbox-demo-module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import {CommonModule} from '@angular/common';
10+
import {CheckboxExamplesModule} from '@angular/components-examples/material/checkbox';
1011
import {NgModule} from '@angular/core';
1112
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
1213
import {MatCheckboxModule} from '@angular/material/checkbox';
@@ -25,6 +26,7 @@ import {
2526

2627
@NgModule({
2728
imports: [
29+
CheckboxExamplesModule,
2830
CommonModule,
2931
FormsModule,
3032
MatCheckboxModule,

src/dev-app/checkbox/checkbox-demo.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,7 @@ <h5>No animations</h5>
245245
</mat-checkbox>
246246
</div>
247247
</div>
248+
249+
<h1>Overview example</h1>
250+
<checkbox-overview-example></checkbox-overview-example>
251+

0 commit comments

Comments
 (0)