From 015a6666ba2e3c28b0cc0cb998988687ff06dc5d Mon Sep 17 00:00:00 2001 From: crisbeto Date: Mon, 24 Sep 2018 21:58:24 +0200 Subject: [PATCH] feat(button-toggle): align with 2018 material design spec Aligns the button toggle component with the latest Material design spec. --- .../button-toggle/button-toggle-demo.html | 26 ++++++++ .../button-toggle/button-toggle-demo.scss | 3 + .../button-toggle/button-toggle-demo.ts | 1 + .../button-toggle/_button-toggle-theme.scss | 48 +++++++++++++- src/lib/button-toggle/button-toggle.scss | 66 +++++++++++++++---- src/lib/button-toggle/button-toggle.ts | 55 ++++++++++++++-- .../form-field/_form-field-legacy-theme.scss | 2 +- 7 files changed, 181 insertions(+), 20 deletions(-) create mode 100644 src/demo-app/button-toggle/button-toggle-demo.scss diff --git a/src/demo-app/button-toggle/button-toggle-demo.html b/src/demo-app/button-toggle/button-toggle-demo.html index 609032d436e5..db980ba7c715 100644 --- a/src/demo-app/button-toggle/button-toggle-demo.html +++ b/src/demo-app/button-toggle/button-toggle-demo.html @@ -25,6 +25,23 @@

Exclusive Selection

+
+ + + format_align_left + + + format_align_center + + + format_align_right + + + format_align_justify + + +
+

Disabled Group

@@ -50,9 +67,18 @@

Multiple Selection

Milk
+
+ + Flour + Eggs + Sugar + Milk + +

Single Toggle

Yes +Yes

Dynamic Exclusive Selection

diff --git a/src/demo-app/button-toggle/button-toggle-demo.scss b/src/demo-app/button-toggle/button-toggle-demo.scss new file mode 100644 index 000000000000..2a678a9d8647 --- /dev/null +++ b/src/demo-app/button-toggle/button-toggle-demo.scss @@ -0,0 +1,3 @@ +section { + margin-bottom: 16px; +} diff --git a/src/demo-app/button-toggle/button-toggle-demo.ts b/src/demo-app/button-toggle/button-toggle-demo.ts index 12ececd8bd0c..e49422610141 100644 --- a/src/demo-app/button-toggle/button-toggle-demo.ts +++ b/src/demo-app/button-toggle/button-toggle-demo.ts @@ -13,6 +13,7 @@ import {Component} from '@angular/core'; moduleId: module.id, selector: 'button-toggle-demo', templateUrl: 'button-toggle-demo.html', + styleUrls: ['button-toggle-demo.css'], }) export class ButtonToggleDemo { isVertical = false; diff --git a/src/lib/button-toggle/_button-toggle-theme.scss b/src/lib/button-toggle/_button-toggle-theme.scss index 1890b46d444f..504b48e00ab3 100644 --- a/src/lib/button-toggle/_button-toggle-theme.scss +++ b/src/lib/button-toggle/_button-toggle-theme.scss @@ -6,11 +6,18 @@ @mixin mat-button-toggle-theme($theme) { $foreground: map-get($theme, foreground); $background: map-get($theme, background); + $divider-color: mat-color($foreground, divider); - .mat-button-toggle-standalone, .mat-button-toggle-group { + .mat-button-toggle-standalone, + .mat-button-toggle-group { @include _mat-theme-elevation(2, $theme); } + .mat-button-toggle-standalone.mat-button-toggle-appearance-standard, + .mat-button-toggle-group-appearance-standard { + box-shadow: none; + } + .mat-button-toggle { color: mat-color($foreground, hint-text); @@ -19,19 +26,56 @@ } } + .mat-button-toggle-appearance-standard { + color: mat-color($foreground, text); + background: mat-color($background, card); + + .mat-button-toggle-focus-overlay { + background-color: mat-color($background, focused-button, 1); + } + } + + .mat-button-toggle-group-appearance-standard .mat-button-toggle + .mat-button-toggle { + border-left: solid 1px $divider-color; + } + + [dir='rtl'] .mat-button-toggle-group-appearance-standard .mat-button-toggle + .mat-button-toggle { + border-left: none; + border-right: solid 1px $divider-color; + } + + .mat-button-toggle-vertical-appearance-standard .mat-button-toggle + .mat-button-toggle { + border-left: none; + border-right: none; + border-top: solid 1px $divider-color; + } + .mat-button-toggle-checked { background-color: mat-color($background, selected-button); color: mat-color($foreground, secondary-text); + + &.mat-button-toggle-appearance-standard { + color: mat-color($foreground, text); + } } .mat-button-toggle-disabled { - background-color: mat-color($background, disabled-button-toggle); color: mat-color($foreground, disabled-button); + background-color: mat-color($background, disabled-button-toggle); + + &.mat-button-toggle-appearance-standard { + background: mat-color($background, card); + } &.mat-button-toggle-checked { background-color: mat-color($background, selected-disabled-button); } } + + .mat-button-toggle-standalone.mat-button-toggle-appearance-standard, + .mat-button-toggle-group-appearance-standard { + border: solid 1px $divider-color; + } } @mixin mat-button-toggle-typography($config) { diff --git a/src/lib/button-toggle/button-toggle.scss b/src/lib/button-toggle/button-toggle.scss index 3a20bbb642fc..b814d720c86c 100644 --- a/src/lib/button-toggle/button-toggle.scss +++ b/src/lib/button-toggle/button-toggle.scss @@ -2,27 +2,38 @@ @import '../core/style/layout-common'; @import '../../cdk/a11y/a11y'; -$mat-button-toggle-padding: 0 16px !default; -$mat-button-toggle-height: 36px !default; -$mat-button-toggle-border-radius: 2px !default; +$mat-button-toggle-standard-padding: 0 12px !default; +$mat-button-toggle-standard-height: 48px !default; +$mat-button-toggle-standard-border-radius: 4px !default; + +$mat-button-toggle-legacy-padding: 0 16px !default; +$mat-button-toggle-legacy-height: 36px !default; +$mat-button-toggle-legacy-border-radius: 2px !default; .mat-button-toggle-standalone, .mat-button-toggle-group { position: relative; display: inline-flex; flex-direction: row; - - border-radius: $mat-button-toggle-border-radius; - cursor: pointer; white-space: nowrap; overflow: hidden; + border-radius: $mat-button-toggle-legacy-border-radius; @include cdk-high-contrast { outline: solid 1px; } } +.mat-button-toggle-standalone.mat-button-toggle-appearance-standard, +.mat-button-toggle-group-appearance-standard { + border-radius: $mat-button-toggle-standard-border-radius; + + @include cdk-high-contrast { + outline: 0; + } +} + .mat-button-toggle-vertical { flex-direction: column; @@ -38,10 +49,6 @@ $mat-button-toggle-border-radius: 2px !default; position: relative; -webkit-tap-highlight-color: transparent; - // Similar to components like the checkbox, slide-toggle and radio, we cannot show the focus - // overlay for `.cdk-program-focused` because mouse clicks on the