Elizabeth Mitchell 5e40a1bcec chore: create shape logical tokens in Sass component token files
Adds `@material/web/tokens/internal/shape` to take a shape token and create 4 logical tokens from its value.

All components' logical shape tokens are now generated by the token files themselves, rather than added in each component's styles.

PiperOrigin-RevId: 601783846
2024-01-26 09:13:58 -08:00

101 lines
2.4 KiB
SCSS

//
// Copyright 2021 Google LLC
// SPDX-License-Identifier: Apache-2.0
//
// go/keep-sorted start
@use 'sass:list';
@use 'sass:map';
// go/keep-sorted end
// go/keep-sorted start
@use '../../focus/focus-ring';
@use '../../tokens';
@use './handle';
@use './icon';
@use './track';
// go/keep-sorted end
@mixin theme($tokens) {
$supported-tokens: tokens.$md-comp-switch-supported-tokens;
@each $token, $value in $tokens {
@if list.index($supported-tokens, $token) == null {
@error 'Token `#{$token}` is not a supported token.';
}
@if $value {
--md-switch-#{$token}: #{$value};
}
}
}
@mixin styles() {
$tokens: tokens.md-comp-switch-values(
$exclude-custom-properties: false,
);
@layer styles, hcm;
@layer styles {
:host {
display: inline-flex;
outline: none;
vertical-align: top;
-webkit-tap-highlight-color: transparent;
cursor: pointer;
}
:host([disabled]) {
cursor: default;
}
:host([touch-target='wrapper']) {
margin: max(0px, (48px - map.get($tokens, 'track-height')) / 2) 0px;
}
md-focus-ring {
@include focus-ring.theme(
(
'shape-start-start': map.get($tokens, 'track-shape-start-start'),
'shape-start-end': map.get($tokens, 'track-shape-start-end'),
'shape-end-end': map.get($tokens, 'track-shape-end-end'),
'shape-end-start': map.get($tokens, 'track-shape-end-start'),
)
);
}
.switch {
align-items: center;
display: inline-flex;
flex-shrink: 0; // Stop from collapsing in flex containers
position: relative;
width: map.get($tokens, 'track-width');
height: map.get($tokens, 'track-height');
// Track shape
border-start-start-radius: map.get($tokens, 'track-shape-start-start');
border-start-end-radius: map.get($tokens, 'track-shape-start-end');
border-end-end-radius: map.get($tokens, 'track-shape-end-end');
border-end-start-radius: map.get($tokens, 'track-shape-end-start');
}
// Input is also touch target
input {
appearance: none;
height: 48px;
outline: none;
margin: 0;
position: absolute;
width: 100%;
z-index: 1;
cursor: inherit;
}
:host([touch-target='none']) input {
display: none;
}
}
@include track.styles($tokens);
@include handle.styles($tokens);
@include icon.styles($tokens);
}