@use '@angular/cdk'; @use '../core/style/vendor-prefixes'; @use '../core/style/layout-common'; @use '../core/style/elevation'; @use '../core/tokens/token-utils'; @use '../core/tokens/m2/mat/legacy-button-toggle' as tokens-mat-legacy-button-toggle; @use '../core/tokens/m2/mat/standard-button-toggle' as tokens-mat-standard-button-toggle; $standard-padding: 12px !default; $legacy-padding: 16px !default; $_checkmark-size: 18px !default; $_checkmark-margin: 12px; $_checkmark-transition: 150ms 45ms cubic-bezier(0.4, 0, 0.2, 1); // TODO(crisbeto): these variables aren't used anymore and should be removed. $legacy-height: 36px !default; $standard-border-radius: 4px !default; $legacy-border-radius: 2px !default; $_legacy-tokens: ( tokens-mat-legacy-button-toggle.$prefix, tokens-mat-legacy-button-toggle.get-token-slots() ); $_standard-tokens: ( tokens-mat-standard-button-toggle.$prefix, tokens-mat-standard-button-toggle.get-token-slots() ); .mat-button-toggle-standalone, .mat-button-toggle-group { position: relative; display: inline-flex; flex-direction: row; white-space: nowrap; overflow: hidden; -webkit-tap-highlight-color: transparent; // Fixes the ripples not being clipped to the border radius on Safari. transform: translateZ(0); @include token-utils.use-tokens($_legacy-tokens...) { @include token-utils.create-token-slot(border-radius, shape); } @include elevation.overridable-elevation(2); @include cdk.high-contrast { outline: solid 1px; } } .mat-button-toggle-standalone.mat-button-toggle-appearance-standard, .mat-button-toggle-group-appearance-standard { @include token-utils.use-tokens($_standard-tokens...) { @include token-utils.create-token-slot(border-radius, shape); border: solid 1px token-utils.get-token-variable(divider-color); .mat-pseudo-checkbox { --mat-minimal-pseudo-checkbox-selected-checkmark-color: #{ token-utils.get-token-variable(selected-state-text-color)}; } } &:not([class*='mat-elevation-z']) { box-shadow: none; } @include cdk.high-contrast { outline: 0; } } .mat-button-toggle-vertical { flex-direction: column; .mat-button-toggle-label-content { // Vertical button toggles shouldn't be an inline-block, because the toggles should // fill the available width in the group. display: block; } } .mat-button-toggle { white-space: nowrap; position: relative; @include token-utils.use-tokens($_legacy-tokens...) { @include token-utils.create-token-slot(color, text-color); @include token-utils.create-token-slot(font-family, label-text-font); @include token-utils.create-token-slot(font-size, label-text-size); @include token-utils.create-token-slot(line-height, label-text-line-height); @include token-utils.create-token-slot(font-weight, label-text-weight); @include token-utils.create-token-slot(letter-spacing, label-text-tracking); --mat-minimal-pseudo-checkbox-selected-checkmark-color: #{ token-utils.get-token-variable(selected-state-text-color)}; &.cdk-keyboard-focused .mat-button-toggle-focus-overlay { @include token-utils.create-token-slot(opacity, focus-state-layer-opacity); } } // Fixes SVG icons that get thrown off because of the `vertical-align` on the parent. .mat-icon svg { vertical-align: top; } } .mat-button-toggle-checkbox-wrapper { display: inline-block; justify-content: flex-start; align-items: center; width: 0; height: $_checkmark-size; line-height: $_checkmark-size; overflow: hidden; box-sizing: border-box; position: absolute; top: 50%; left: $legacy-padding; // Uses a 3d transform, because otherwise Safari has some some of rendering // artifact that adds a small gap between the two parts of the checkmark. transform: translate3d(0, -50%, 0); [dir='rtl'] & { left: auto; right: $legacy-padding; } .mat-button-toggle-appearance-standard & { left: $standard-padding; } [dir='rtl'] .mat-button-toggle-appearance-standard & { left: auto; right: $standard-padding; } .mat-button-toggle-checked & { width: $_checkmark-size; } .mat-button-toggle-animations-enabled & { transition: width $_checkmark-transition; } // Disable the transition in vertical mode since it looks weird. // There should be a limited amount of usages anyway. .mat-button-toggle-vertical & { transition: none; } } .mat-button-toggle-checked { @include token-utils.use-tokens($_legacy-tokens...) { @include token-utils.create-token-slot(color, selected-state-text-color); @include token-utils.create-token-slot(background-color, selected-state-background-color); } } .mat-button-toggle-disabled { pointer-events: none; @include token-utils.use-tokens($_legacy-tokens...) { @include token-utils.create-token-slot(color, disabled-state-text-color); @include token-utils.create-token-slot(background-color, disabled-state-background-color); --mat-minimal-pseudo-checkbox-disabled-selected-checkmark-color: #{ token-utils.get-token-variable(disabled-state-text-color)}; &.mat-button-toggle-checked { @include token-utils.create-token-slot(background-color, disabled-selected-state-background-color); } } } .mat-button-toggle-disabled-interactive { pointer-events: auto; } .mat-button-toggle-appearance-standard { @include token-utils.use-tokens($_standard-tokens...) { $divider-color: token-utils.get-token-variable(divider-color); @include token-utils.create-token-slot(color, text-color); @include token-utils.create-token-slot(background-color, background-color); @include token-utils.create-token-slot(font-family, label-text-font); @include token-utils.create-token-slot(font-size, label-text-size); @include token-utils.create-token-slot(line-height, label-text-line-height); @include token-utils.create-token-slot(font-weight, label-text-weight); @include token-utils.create-token-slot(letter-spacing, label-text-tracking); .mat-button-toggle-group-appearance-standard & + & { border-left: solid 1px $divider-color; } [dir='rtl'] .mat-button-toggle-group-appearance-standard & + & { border-left: none; border-right: solid 1px $divider-color; } .mat-button-toggle-group-appearance-standard.mat-button-toggle-vertical & + & { border-left: none; border-right: none; border-top: solid 1px $divider-color; } &.mat-button-toggle-checked { @include token-utils.create-token-slot(color, selected-state-text-color); @include token-utils.create-token-slot(background-color, selected-state-background-color); } &.mat-button-toggle-disabled { @include token-utils.create-token-slot(color, disabled-state-text-color); @include token-utils.create-token-slot(background-color, disabled-state-background-color); .mat-pseudo-checkbox { --mat-minimal-pseudo-checkbox-disabled-selected-checkmark-color: #{ token-utils.get-token-variable(disabled-selected-state-text-color)}; } &.mat-button-toggle-checked { @include token-utils.create-token-slot(color, disabled-selected-state-text-color); @include token-utils.create-token-slot(background-color, disabled-selected-state-background-color); } } .mat-button-toggle-focus-overlay { @include token-utils.create-token-slot(background-color, state-layer-color); } &:hover .mat-button-toggle-focus-overlay { @include token-utils.create-token-slot(opacity, hover-state-layer-opacity); } // 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