mirror of
https://github.com/material-components/material-web.git
synced 2024-09-11 21:57:41 +03:00
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
135 lines
3.7 KiB
SCSS
135 lines
3.7 KiB
SCSS
//
|
|
// Copyright 2023 Google LLC
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
// go/keep-sorted start
|
|
@use 'sass:map';
|
|
@use 'sass:string';
|
|
// go/keep-sorted end
|
|
// go/keep-sorted start
|
|
@use './internal/shape';
|
|
@use './internal/validate';
|
|
@use './md-sys-color';
|
|
@use './md-sys-shape';
|
|
@use './md-sys-state';
|
|
@use './md-sys-typescale';
|
|
@use './v0_192/md-comp-text-button';
|
|
// go/keep-sorted end
|
|
|
|
$supported-tokens: (
|
|
// go/keep-sorted start
|
|
'container-height',
|
|
'container-shape',
|
|
'container-shape-end-end',
|
|
'container-shape-end-start',
|
|
'container-shape-start-end',
|
|
'container-shape-start-start',
|
|
'disabled-icon-color',
|
|
'disabled-icon-opacity',
|
|
'disabled-label-text-color',
|
|
'disabled-label-text-opacity',
|
|
'focus-icon-color',
|
|
'focus-label-text-color',
|
|
'hover-icon-color',
|
|
'hover-label-text-color',
|
|
'hover-state-layer-color',
|
|
'hover-state-layer-opacity',
|
|
'icon-color',
|
|
'icon-size',
|
|
'label-text-color',
|
|
'label-text-font',
|
|
'label-text-line-height',
|
|
'label-text-size',
|
|
'label-text-weight',
|
|
'leading-space',
|
|
'pressed-icon-color',
|
|
'pressed-label-text-color',
|
|
'pressed-state-layer-color',
|
|
'pressed-state-layer-opacity',
|
|
'trailing-space',
|
|
'with-leading-icon-leading-space',
|
|
'with-leading-icon-trailing-space',
|
|
'with-trailing-icon-leading-space',
|
|
'with-trailing-icon-trailing-space',
|
|
// go/keep-sorted end
|
|
);
|
|
|
|
$unsupported-tokens: (
|
|
// go/keep-sorted start
|
|
'focus-state-layer-color',
|
|
'focus-state-layer-opacity',
|
|
'label-text-tracking',
|
|
'label-text-type',
|
|
// go/keep-sorted end
|
|
);
|
|
|
|
$_default: (
|
|
'md-sys-color': md-sys-color.values-light(),
|
|
'md-sys-shape': md-sys-shape.values(),
|
|
'md-sys-state': md-sys-state.values(),
|
|
'md-sys-typescale': md-sys-typescale.values(),
|
|
);
|
|
|
|
@function values(
|
|
$deps: $_default,
|
|
$exclude-hardcoded-values: false,
|
|
$exclude-custom-properties: true
|
|
) {
|
|
$tokens: md-comp-text-button.values($deps, $exclude-hardcoded-values);
|
|
$new-tokens: map.merge(
|
|
shape.get-new-logical-shape-tokens($tokens, 'container-shape'),
|
|
(
|
|
// b/198759625 - Remove once spacing tokens are formally added
|
|
// go/keep-sorted start
|
|
'leading-space': if($exclude-hardcoded-values, null, 12px),
|
|
'trailing-space': if($exclude-hardcoded-values, null, 12px),
|
|
'with-leading-icon-leading-space':
|
|
if($exclude-hardcoded-values, null, 12px),
|
|
'with-leading-icon-trailing-space':
|
|
if($exclude-hardcoded-values, null, 16px),
|
|
'with-trailing-icon-leading-space':
|
|
if($exclude-hardcoded-values, null, 16px),
|
|
'with-trailing-icon-trailing-space':
|
|
if($exclude-hardcoded-values, null, 12px),
|
|
// go/keep-sorted end
|
|
)
|
|
);
|
|
|
|
$tokens: validate.values(
|
|
$tokens,
|
|
$supported-tokens: $supported-tokens,
|
|
$unsupported-tokens: $unsupported-tokens,
|
|
$new-tokens: $new-tokens,
|
|
$renamed-tokens: (
|
|
// Remove "with-*" prefixes (b/273534858)
|
|
'with-icon-disabled-icon-color': 'disabled-icon-color',
|
|
'with-icon-disabled-icon-opacity': 'disabled-icon-opacity',
|
|
'with-icon-focus-icon-color': 'focus-icon-color',
|
|
'with-icon-hover-icon-color': 'hover-icon-color',
|
|
'with-icon-icon-color': 'icon-color',
|
|
'with-icon-icon-size': 'icon-size',
|
|
'with-icon-pressed-icon-color': 'pressed-icon-color'
|
|
)
|
|
);
|
|
|
|
// Default to `$exclude-custom-properties: false` in the next breaking change.
|
|
// See b/321816473.
|
|
@if not $exclude-custom-properties {
|
|
@each $token, $value in $tokens {
|
|
@if string.index($token, 'container-shape-') == 1 {
|
|
// Add fallback to shorthand for logical shape properties.
|
|
$value: var(--md-text-button-container-shape, #{$value});
|
|
}
|
|
|
|
$tokens: map.set(
|
|
$tokens,
|
|
$token,
|
|
var(--md-text-button-#{$token}, #{$value})
|
|
);
|
|
}
|
|
}
|
|
|
|
@return $tokens;
|
|
}
|