|
1 | 1 | <div fxLayout="column" fxLayoutAlign="start start" class="mdc-padding">
|
2 | 2 | <h1 mdc-typography-display1>Snackbar</h1>
|
3 |
| - <div mdc-typography-subheading2>The MDC Snackbar component is a spec-aligned snackbar component adhering to the Material Design snackbars requirements.</div> |
4 |
| - <div class="info-banner" mdc-typography-subheading1><![CDATA[import { MdcSnackbarModule } from '@angular-mdc/web';]]></div> |
| 3 | + <div mdc-typography-subheading2>The MDC Snackbar is a spec-aligned snackbar component adhering to the Material Design snackbars requirements.</div> |
| 4 | + <div class="info-banner" mdc-typography-subheading1><![CDATA[import { MdcSnackbar } from '@angular-mdc/web';]]></div> |
5 | 5 | <div class="docs-api">
|
6 | 6 | <table>
|
7 | 7 | <thead>
|
8 | 8 | <tr>
|
9 |
| - <th>Component</th> |
| 9 | + <th>Service</th> |
10 | 10 | </tr>
|
11 | 11 | </thead>
|
12 | 12 | <tbody>
|
13 | 13 | <tr>
|
14 |
| - <td>mdc-snackbar</td> |
| 14 | + <td>MdcSnackbar</td> |
15 | 15 | </tr>
|
16 | 16 | </tbody>
|
17 | 17 | <thead>
|
18 | 18 | <tr>
|
19 |
| - <th>Properties</th> |
20 |
| - <th>Description</th> |
| 19 | + <th>Methods</th> |
21 | 20 | </tr>
|
22 | 21 | </thead>
|
23 | 22 | <tbody>
|
24 | 23 | <tr>
|
25 |
| - <td>@Input() alignStart: boolean</td> |
26 |
| - <td>Set snackbar message as start-aligned.</td> |
| 24 | + <td>show(message: string)</td> |
| 25 | + <td>Show snackbar message.</td> |
| 26 | + </tr> |
| 27 | + <tr> |
| 28 | + <td>show(message: string, action: string)</td> |
| 29 | + <td>Show snackbar message and action.</td> |
27 | 30 | </tr>
|
28 | 31 | <tr>
|
29 |
| - <td>@Input() dismissOnAction: boolean</td> |
30 |
| - <td>If you want the snackbar to remain visible until the timeout is reached (regardless of whether the user pressed the action button or not) you can set the dismissesOnAction property to false.</td> |
| 32 | + <td><pre><code><![CDATA[show( |
| 33 | + message: string, |
| 34 | + action: string, |
| 35 | + { |
| 36 | + config |
| 37 | + }) |
| 38 | +]]></code></pre></td> |
| 39 | + <td> |
| 40 | +<pre><code><![CDATA[config { |
| 41 | + timeout?: number = 2750; |
| 42 | + actionHandler?: Function; |
| 43 | + multiline?: boolean = false; |
| 44 | + actionOnBottom?: boolean = false; |
| 45 | + align?: string = 'center'; |
| 46 | + dismissOnAction?: boolean = true; |
| 47 | + focusAction?: boolean = false; |
| 48 | +}]]></code></pre> |
| 49 | + </td> |
31 | 50 | </tr>
|
32 | 51 | </tbody>
|
33 | 52 | <thead>
|
34 | 53 | <tr>
|
35 |
| - <th>Methods</th> |
36 |
| - <th>Parameters</th> |
| 54 | + <th>Config</th> |
37 | 55 | </tr>
|
38 | 56 | </thead>
|
39 | 57 | <tbody>
|
40 | 58 | <tr>
|
41 |
| - <td>show(data: SnackbarMessage)</td> |
42 |
| - <td> |
43 |
| -<pre><code><![CDATA[interface SnackbarMessage { |
44 |
| - message: string; |
45 |
| - timeout?: number; - Amount of time in milliseconds to show the snackbar (default 2750). |
46 |
| - actionHandler?: Function; - Function to execute when the action is clicked. |
47 |
| - actionText?: string; - Text to display for the action button. |
48 |
| - multiline?: boolean; - Whether to show the snackbar with space for multiple lines of text. |
49 |
| - actionOnBottom?: boolean; - Whether to show the action below the multiple lines of text. |
50 |
| -}]]></code></pre> |
51 |
| - </td> |
| 59 | + <td>timeout: number (Default 2750)</td> |
| 60 | + <td>The amount of time in milliseconds to show the snackbar.</td> |
| 61 | + </tr> |
| 62 | + <tr> |
| 63 | + <td>actionHandler: Function</td> |
| 64 | + <td>The function to execute when the action is clicked.</td> |
| 65 | + </tr> |
| 66 | + <tr> |
| 67 | + <td>multiline: boolean</td> |
| 68 | + <td>Whether to show the snackbar with space for multiple lines of text.</td> |
| 69 | + </tr> |
| 70 | + <tr> |
| 71 | + <td>actionOnBottom: boolean</td> |
| 72 | + <td>Whether to show the action below the multiple lines of text.</td> |
| 73 | + </tr> |
| 74 | + <tr> |
| 75 | + <td>align: string (Default 'center')</td> |
| 76 | + <td>Alignment of the snackbar on screen. Valid values - 'start' | 'center'</td> |
| 77 | + </tr> |
| 78 | + <tr> |
| 79 | + <td>dismissOnAction: boolean</td> |
| 80 | + <td>Dismisses snackbar when action button is clicked.</td> |
| 81 | + </tr> |
| 82 | + <tr> |
| 83 | + <td>focusAction: boolean</td> |
| 84 | + <td>Sets focus to the action button.</td> |
52 | 85 | </tr>
|
53 | 86 | </tbody>
|
54 | 87 | </table>
|
55 | 88 | </div>
|
56 | 89 | <div fxLayout="column" class="mdc-padding">
|
57 | 90 | <mdc-form-field>
|
58 |
| - <mdc-checkbox [(ngModel)]="message.multiline"></mdc-checkbox> |
| 91 | + <mdc-checkbox [(ngModel)]="multiline"></mdc-checkbox> |
59 | 92 | <label>Multiline</label>
|
60 | 93 | </mdc-form-field>
|
61 | 94 | <mdc-form-field>
|
62 |
| - <mdc-checkbox [(ngModel)]="message.actionOnBottom" [disabled]="!message.multiline"></mdc-checkbox> |
| 95 | + <mdc-checkbox [(ngModel)]="alignStart"></mdc-checkbox> |
| 96 | + <label>Start align</label> |
| 97 | + </mdc-form-field> |
| 98 | + <mdc-form-field> |
| 99 | + <mdc-checkbox [(ngModel)]="actionOnBottom" [disabled]="!multiline"></mdc-checkbox> |
63 | 100 | <label>Action on Bottom (requires multiline)</label>
|
64 | 101 | </mdc-form-field>
|
65 | 102 | <mdc-form-field>
|
66 |
| - <mdc-checkbox [(ngModel)]="snack.dismissOnAction"></mdc-checkbox> |
| 103 | + <mdc-checkbox [(ngModel)]="dismissOnAction"></mdc-checkbox> |
67 | 104 | <label>Dismiss on Action Click</label>
|
68 | 105 | </mdc-form-field>
|
| 106 | + <mdc-form-field> |
| 107 | + <mdc-checkbox [(ngModel)]="focusAction"></mdc-checkbox> |
| 108 | + <label>Focus on Action button</label> |
| 109 | + </mdc-form-field> |
| 110 | + |
| 111 | + <div fxLayout="column"> |
| 112 | + <mdc-textfield [(ngModel)]="message" label="Message" [required]="true"></mdc-textfield> |
| 113 | + <mdc-textfield [(ngModel)]="action" label="Action"></mdc-textfield> |
| 114 | + </div> |
| 115 | + <div class="mdc-padding" fxLayout="column" fxFlexOffset="2"> |
| 116 | + <button mdc-button [primary]="true" [raised]="true" (click)="show();">Show Snackbar</button> |
| 117 | + </div> |
69 | 118 | </div>
|
70 |
| - <div fxLayout="column" fxFlexOffset="1"> |
71 |
| - <mdc-textfield [(ngModel)]="message.message" label="Message text" [required]="true"></mdc-textfield> |
72 |
| - <mdc-textfield [(ngModel)]="message.actionText" label="Action button text"></mdc-textfield> |
73 |
| - </div> |
74 |
| - <div class="mdc-padding" fxLayout="column" fxFlexOffset="2"> |
75 |
| - <button mdc-button [primary]="true" [raised]="true" (click)="show();">Show Snackbar</button> |
76 |
| - </div> |
77 |
| - <div class="mdc-padding" fxLayout="column" fxFlexOffset="2"> |
78 |
| - <button mdc-button [primary]="true" [raised]="true" (click)="showStartAligned();">Show Start Aligned</button> |
79 |
| - </div> |
| 119 | + <pre style="background:#000;color:#f8f8f8"><code><![CDATA[import { Component } from '@angular/core'; |
| 120 | + |
| 121 | +import { MdcSnackbar } from '@angular-mdc/web'; |
| 122 | + |
| 123 | +@Component({ |
| 124 | + selector: 'snackbar-demo', |
| 125 | + templateUrl: './snackbar-demo.component.html', |
| 126 | + providers: [MdcSnackbar], |
| 127 | +}) |
| 128 | +export class SnackbarDemoComponent { |
| 129 | + message = 'Message deleted'; |
| 130 | + action = 'Undo'; |
| 131 | + multiline = false; |
| 132 | + dismissOnAction: boolean = true; |
| 133 | + alignStart: boolean; |
| 134 | + focusAction = false; |
| 135 | + actionOnBottom = false; |
| 136 | + |
| 137 | + constructor(public snackbar: MdcSnackbar) { } |
| 138 | + |
| 139 | + show() { |
| 140 | + let snackbarRef = this.snackbar.show(this.message, this.action, { |
| 141 | + align: this.alignStart ? 'start' : '', |
| 142 | + multiline: this.multiline, |
| 143 | + dismissOnAction: this.dismissOnAction, |
| 144 | + focusAction: this.focusAction, |
| 145 | + actionOnBottom: this.actionOnBottom, |
| 146 | + }); |
| 147 | + } |
| 148 | +} |
| 149 | +]]></code></pre> |
80 | 150 | </div>
|
81 |
| - <mdc-snackbar #snack></mdc-snackbar> |
82 |
| - <mdc-snackbar #snackStart [alignStart]="true"></mdc-snackbar> |
|
0 commit comments