Skip to content

Commit 9ab104b

Browse files
committed
fix(material-experimental/theming): align dialog with M3
Fixes up the tokens so that the dialog matches the M3 spec.
1 parent 6cf4628 commit 9ab104b

File tree

4 files changed

+82
-11
lines changed

4 files changed

+82
-11
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ <h1>Dialog demo</h1>
1414
<mat-checkbox [(ngModel)]="enableLegacyPadding">Enable legacy padding</mat-checkbox>
1515
</p>
1616

17+
<p>
18+
<mat-checkbox [(ngModel)]="isScrollable">Make dialog scrollable</mat-checkbox>
19+
</p>
20+
1721
<mat-card class="demo-dialog-card">
1822
<mat-card-content>
1923
<h2>Dialog dimensions</h2>
@@ -92,7 +96,7 @@ <h2>Other options</h2>
9296
<mat-form-field>
9397
<mat-label>Button alignment</mat-label>
9498
<mat-select [(ngModel)]="actionsAlignment">
95-
<mat-option>Start</mat-option>
99+
<mat-option value="start">Start</mat-option>
96100
<mat-option value="end">End</mat-option>
97101
<mat-option value="center">Center</mat-option>
98102
</mat-select>

src/dev-app/dialog/dialog-demo.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ import {MatInputModule} from '@angular/material/input';
2727
import {MatSelectModule} from '@angular/material/select';
2828
import {DragDropModule} from '@angular/cdk/drag-drop';
2929

30-
const defaultDialogConfig = new MatDialogConfig();
31-
3230
@Component({
3331
selector: 'dialog-demo',
3432
templateUrl: 'dialog-demo.html',
@@ -61,7 +59,7 @@ export class DialogDemo {
6159
height: '',
6260
minWidth: '',
6361
minHeight: '',
64-
maxWidth: defaultDialogConfig.maxWidth,
62+
maxWidth: '',
6563
maxHeight: '',
6664
position: {
6765
top: '',
@@ -75,6 +73,7 @@ export class DialogDemo {
7573
};
7674
numTemplateOpens = 0;
7775
enableLegacyPadding = false;
76+
isScrollable = false;
7877

7978
@ViewChild(TemplateRef) template: TemplateRef<any>;
8079

@@ -110,6 +109,7 @@ export class DialogDemo {
110109
openContentElement() {
111110
const dialogRef = this.dialog.open(ContentElementDialog, this._getDialogConfig());
112111
dialogRef.componentInstance.actionsAlignment = this.actionsAlignment;
112+
dialogRef.componentInstance.isScrollable = this.isScrollable;
113113
}
114114

115115
openTemplate() {
@@ -195,7 +195,7 @@ export class JazzDialog {
195195
`
196196
img {
197197
max-width: 100%;
198-
height: 800px;
198+
max-height: 800px;
199199
}
200200
`,
201201
],
@@ -212,12 +212,17 @@ export class JazzDialog {
212212
astronomical units (4.50x109 km). It is named after the Roman god of the sea and has the
213213
astronomical symbol ♆, a stylised version of the god Neptune's trident.
214214
</p>
215-
<img src="https://upload.wikimedia.org/wikipedia/commons/5/56/Neptune_Full.jpg"/>
215+
216+
@if (isScrollable) {
217+
@for (i of [1, 2, 3]; track $index) {
218+
<img src="https://upload.wikimedia.org/wikipedia/commons/5/56/Neptune_Full.jpg"/>
219+
}
220+
}
216221
</mat-dialog-content>
217222
218223
<mat-dialog-actions [align]="actionsAlignment">
219224
<button
220-
mat-raised-button
225+
mat-button
221226
color="primary"
222227
mat-dialog-close>Close</button>
223228
@@ -238,12 +243,13 @@ export class JazzDialog {
238243
imports: [MatButtonModule, MatDialogTitle, MatDialogContent, MatDialogClose, MatDialogActions],
239244
})
240245
export class ContentElementDialog {
241-
actionsAlignment: 'start' | 'center' | 'end';
246+
actionsAlignment?: 'start' | 'center' | 'end';
247+
isScrollable: boolean;
242248

243249
constructor(public dialog: MatDialog) {}
244250

245251
showInStackedDialog() {
246-
this.dialog.open(IFrameDialog);
252+
this.dialog.open(IFrameDialog, {maxWidth: '80vw'});
247253
}
248254
}
249255

@@ -253,6 +259,7 @@ export class ContentElementDialog {
253259
`
254260
iframe {
255261
width: 800px;
262+
height: 500px;
256263
}
257264
`,
258265
],
@@ -265,7 +272,7 @@ export class ContentElementDialog {
265272
266273
<mat-dialog-actions>
267274
<button
268-
mat-raised-button
275+
mat-button
269276
color="primary"
270277
mat-dialog-close>Close</button>
271278
</mat-dialog-actions>

src/material-experimental/theming/_custom-tokens.scss

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,29 @@
347347
));
348348
}
349349

350+
/// Generates custom tokens for the dialog.
351+
/// @param {Map} $systems The MDC system tokens
352+
/// @param {Boolean} $exclude-hardcoded Whether to exclude hardcoded token values
353+
/// @return {Map} A set of custom tokens for the dialog
354+
@function dialog($systems, $exclude-hardcoded) {
355+
@return (
356+
container-max-width: _hardcode(560px, $exclude-hardcoded),
357+
container-small-max-width: _hardcode(calc(100vw - 32px), $exclude-hardcoded),
358+
container-min-width: _harcode(280px, $exclude-hardcoded),
359+
actions-alignment: _hardcode(flex-end, $exclude-hardcoded),
360+
content-padding: _hardcode(20px 24px, $exclude-hardcoded),
361+
with-actions-content-padding: _hardcode(20px 24px 0, $exclude-hardcoded),
362+
actions-padding: _hardcode(16px 24px, $exclude-hardcoded),
363+
364+
// The vertical padding values are a bit weird, because MDC uses a `::before` pseudo
365+
// element to size the title which in turn means that we can't set a specific padding
366+
// and get the exact same space out of it. These values were determined through
367+
// trial and error so that the first line of text is 24px from the top and the bottom
368+
// of the text is 16px from the content under it.
369+
headline-padding: _hardcode(6px 24px 13px, $exclude-hardcoded),
370+
);
371+
}
372+
350373
/// Generates custom tokens for the mat-divider.
351374
/// @param {Map} $systems The MDC system tokens
352375
/// @param {Boolean} $exclude-hardcoded Whether to exclude hardcoded token values

src/material-experimental/theming/_m3-tokens.scss

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,38 @@
432432
));
433433
}
434434

435+
/// Fixes inconsistent values in the dialog tokens so that they can produce valid styles.
436+
/// @param {Map} $initial-tokens Map of dialog tokens currently being generated.
437+
/// @param {Map} $all-tokens Map of all dialog tokens, including hardcoded values.
438+
/// @return {Map} The given tokens, with the invalid values replaced with valid ones.
439+
@function _fix-dialog-tokens($systems, $tokens) {
440+
$tokens: _rename-map-keys($tokens, (
441+
headline-color: subhead-color,
442+
headline-font: subhead-font,
443+
headline-line-height: subhead-line-height,
444+
headline-size: subhead-size,
445+
headline-tracking: subhead-tracking,
446+
headline-weight: subhead-weight,
447+
));
448+
449+
@if (map.has-key($tokens, container-elevation)) {
450+
$tokens: map.merge($tokens, (
451+
// The spec has the dialog at an elevation of 3 which is consistent with the current
452+
// version of the tokens (0_161), however both the designs and MDC's implementation
453+
// have the elevation set to 0. Set it manually to 0 here since the value in the
454+
// exported tokens is likely outdated.
455+
container-elevation: 0,
456+
457+
// This color needs to be supplied for MDC to produce the shadow. Technically we don't
458+
// have to provide it since the elevation is set to 0 above, but we do it in case
459+
// the value changes in the future.
460+
container-shadow-color: #000,
461+
));
462+
}
463+
464+
@return $tokens;
465+
}
466+
435467
/// Generates a set of namespaced tokens for all components.
436468
/// @param {Map} $systems The MDC system tokens
437469
/// @param {Boolean} $include-non-systemized Whether to include non-systemized tokens
@@ -495,7 +527,7 @@
495527
),
496528
_namespace-tokens(
497529
(mdc, dialog),
498-
mdc-tokens.md-comp-dialog-values($systems, $exclude-hardcoded),
530+
_fix-dialog-tokens($systems, mdc-tokens.md-comp-dialog-values($systems, $exclude-hardcoded)),
499531
$token-slots
500532
),
501533
_namespace-tokens(
@@ -726,6 +758,11 @@
726758
custom-tokens.datepicker($systems, $exclude-hardcoded),
727759
$token-slots
728760
),
761+
_namespace-tokens(
762+
(mat, dialog),
763+
custom-tokens.dialog($systems, $exclude-hardcoded),
764+
$token-slots
765+
),
729766
_namespace-tokens(
730767
(mat, divider),
731768
custom-tokens.divider($systems, $exclude-hardcoded),

0 commit comments

Comments
 (0)