| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390 |
- //
- // Copyright 2020 Google Inc.
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to deal
- // in the Software without restriction, including without limitation the rights
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- // copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- // THE SOFTWARE.
- //
- // stylelint-disable selector-class-pattern --
- // Selector '.mdc-*' should only be used in this project.
- @use 'sass:math';
- @use '@material/animation/animation';
- @use '@material/dom/mixins' as dom-mixins;
- @use '@material/feature-targeting/feature-targeting';
- @use '@material/ripple/ripple';
- @use '@material/ripple/ripple-theme';
- @use '@material/rtl/rtl';
- @use '@material/theme/css';
- @use '@material/theme/theme-color';
- @use '@material/typography/typography';
- @use './slider-theme';
- // Thumb variables.
- $_thumb-ripple-size: 48px;
- $_thumb-size: 20px;
- $_value-indicator-caret-width: 6px;
- // Track variables.
- $_track-active-height: 6px;
- $_track-inactive-height: 4px;
- /// Core styles for slider component.
- @mixin core-styles($query: feature-targeting.all()) {
- @include ripple($query: $query);
- @include without-ripple($query: $query);
- }
- // This API is intended for use by frameworks that may want to separate the
- // ripple-related styles from the other slider styles.
- // It is recommended that most users use `core-styles` instead.
- @mixin without-ripple($query: feature-targeting.all()) {
- $feat-structure: feature-targeting.create-target($query, structure);
- @include static-styles($query: $query);
- .mdc-slider {
- @include slider-theme.theme-styles(
- slider-theme.$light-theme,
- $query: $query
- );
- }
- }
- // This API is intended for use by frameworks that may want to separate the
- // ripple-related styles from the other slider styles.
- // It is recommended that most users use `core-styles` instead.
- @mixin ripple($query: feature-targeting.all()) {
- @include ripple.common($query); // COPYBARA_COMMENT_THIS_LINE
- .mdc-slider__thumb {
- @include ripple.surface($query: $query);
- @include ripple.radius-unbounded($query: $query);
- @include ripple-theme.states($color: slider-theme.$color, $query: $query);
- }
- }
- @mixin static-styles($query: feature-targeting.all()) {
- $feat-animation: feature-targeting.create-target($query, animation);
- $feat-color: feature-targeting.create-target($query, color);
- $feat-structure: feature-targeting.create-target($query, structure);
- .mdc-slider {
- @include _track($query: $query);
- @include _thumb($query: $query);
- @include _tick-marks($query: $query);
- @include feature-targeting.targets($feat-structure) {
- cursor: pointer;
- height: $_thumb-ripple-size;
- margin: 0 math.div($_thumb-ripple-size, 2);
- position: relative;
- touch-action: pan-y;
- }
- &--discrete {
- .mdc-slider__thumb,
- .mdc-slider__track--active_fill {
- @include feature-targeting.targets($feat-animation) {
- transition: transform 80ms ease;
- }
- }
- @media (prefers-reduced-motion) {
- .mdc-slider__thumb,
- .mdc-slider__track--active_fill {
- @include feature-targeting.targets($feat-animation) {
- transition: none;
- }
- }
- }
- }
- }
- .mdc-slider--disabled {
- @include _disabled($query: $query);
- }
- .mdc-slider__input {
- $indent: 2px;
- $size: $_thumb-ripple-size - 2 * $indent;
- @include feature-targeting.targets($feat-structure) {
- cursor: pointer;
- left: $indent;
- margin: 0;
- height: $size;
- opacity: 0;
- pointer-events: none;
- position: absolute;
- top: $indent;
- width: $size;
- }
- }
- }
- @mixin _track($query: feature-targeting.all()) {
- $feat-structure: feature-targeting.create-target($query, structure);
- .mdc-slider__track {
- @include feature-targeting.targets($feat-structure) {
- position: absolute;
- top: 50%;
- transform: translateY(-50%);
- width: 100%;
- }
- }
- .mdc-slider__track--active,
- .mdc-slider__track--inactive {
- @include feature-targeting.targets($feat-structure) {
- display: flex;
- height: 100%;
- position: absolute;
- width: 100%;
- }
- }
- .mdc-slider__track--active {
- @include feature-targeting.targets($feat-structure) {
- overflow: hidden;
- }
- }
- .mdc-slider__track--active_fill {
- @include feature-targeting.targets($feat-structure) {
- // Use border rather than background-color to fill track, for HCM.
- border-top-style: solid;
- box-sizing: border-box;
- height: 100%;
- width: 100%;
- position: relative;
- @include rtl.ignore-next-line();
- -webkit-transform-origin: left;
- @include rtl.ignore-next-line();
- transform-origin: left;
- @include rtl.rtl {
- @include rtl.ignore-next-line();
- -webkit-transform-origin: right;
- @include rtl.ignore-next-line();
- transform-origin: right;
- }
- }
- }
- .mdc-slider__track--inactive {
- &::before {
- @include dom-mixins.transparent-border($query: $query); // For HCM.
- }
- @include feature-targeting.targets($feat-structure) {
- left: 0;
- top: 0;
- }
- }
- }
- @mixin _thumb($query: feature-targeting.all()) {
- $feat-color: feature-targeting.create-target($query, color);
- $feat-structure: feature-targeting.create-target($query, structure);
- @include _value-indicator($query: $query);
- .mdc-slider__thumb {
- @include feature-targeting.targets($feat-structure) {
- display: flex;
- @include rtl.ignore-next-line();
- left: math.div(-$_thumb-ripple-size, 2);
- outline: none;
- position: absolute;
- user-select: none;
- height: $_thumb-ripple-size;
- width: $_thumb-ripple-size;
- }
- &--top {
- @include feature-targeting.targets($feat-structure) {
- z-index: 1;
- }
- }
- &--top .mdc-slider__thumb-knob,
- &--top.mdc-slider__thumb:hover .mdc-slider__thumb-knob,
- &--top.mdc-slider__thumb--focused .mdc-slider__thumb-knob {
- @include feature-targeting.targets($feat-structure) {
- border-style: solid;
- border-width: 1px;
- box-sizing: content-box;
- }
- }
- }
- .mdc-slider__thumb-knob {
- @include feature-targeting.targets($feat-structure) {
- box-sizing: border-box;
- @include rtl.ignore-next-line();
- left: 50%;
- position: absolute;
- top: 50%;
- @include rtl.ignore-next-line();
- transform: translate(-50%, -50%);
- }
- }
- }
- @mixin _tick-marks($query: feature-targeting.all()) {
- $feat-structure: feature-targeting.create-target($query, structure);
- $feat-color: feature-targeting.create-target($query, color);
- .mdc-slider__tick-marks {
- @include feature-targeting.targets($feat-structure) {
- align-items: center;
- box-sizing: border-box;
- display: flex;
- height: 100%;
- justify-content: space-between;
- padding: 0 1px;
- position: absolute;
- width: 100%;
- }
- }
- }
- @mixin _value-indicator($query: feature-targeting.all()) {
- $feat-animation: feature-targeting.create-target($query, animation);
- $feat-structure: feature-targeting.create-target($query, structure);
- .mdc-slider__value-indicator-container {
- @include feature-targeting.targets($feat-structure) {
- bottom: math.div($_thumb-ripple-size, 2) + math.div($_thumb-size, 2) +
- $_value-indicator-caret-width + 4px;
- @include css.declaration(
- left,
- var(--slider-value-indicator-container-left, 50%),
- 50%,
- $gss: (noflip: true)
- );
- pointer-events: none;
- position: absolute;
- @include css.declaration(
- right,
- var(--slider-value-indicator-container-right),
- $gss: (noflip: true)
- );
- @include css.declaration(
- transform,
- var(--slider-value-indicator-container-transform, translateX(-50%)),
- translateX(-50%),
- $gss: (noflip: true)
- );
- }
- }
- .mdc-slider__value-indicator {
- @include feature-targeting.targets($feat-animation) {
- transition: animation.exit-permanent(transform, 100ms);
- }
- @include feature-targeting.targets($feat-structure) {
- align-items: center;
- border-radius: 4px;
- display: flex;
- height: 32px;
- padding: 0 12px;
- transform: scale(0);
- transform-origin: bottom;
- }
- // Caret: https://css-tricks.com/snippets/css/css-triangle/
- &::before {
- @include feature-targeting.targets($feat-structure) {
- border-left: $_value-indicator-caret-width solid transparent;
- border-right: $_value-indicator-caret-width solid transparent;
- border-top: $_value-indicator-caret-width solid;
- bottom: -$_value-indicator-caret-width + 1;
- content: '';
- height: 0;
- @include css.declaration(
- left,
- var(--slider-value-indicator-caret-left, 50%),
- 50%,
- $gss: (noflip: true)
- );
- position: absolute;
- @include css.declaration(
- right,
- var(--slider-value-indicator-caret-right),
- $gss: (noflip: true)
- );
- @include css.declaration(
- transform,
- var(--slider-value-indicator-caret-transform, translateX(-50%)),
- translateX(-50%),
- $gss: (noflip: true)
- );
- width: 0;
- }
- }
- &::after {
- @include dom-mixins.transparent-border($query: $query); // For HCM.
- }
- }
- .mdc-slider__thumb--with-indicator {
- .mdc-slider__value-indicator-container {
- @include feature-targeting.targets($feat-structure) {
- pointer-events: auto;
- }
- }
- .mdc-slider__value-indicator {
- @include feature-targeting.targets($feat-animation) {
- transition: animation.enter(transform, 100ms);
- }
- @include feature-targeting.targets($feat-structure) {
- transform: scale(1);
- }
- }
- }
- @media (prefers-reduced-motion) {
- .mdc-slider__value-indicator,
- .mdc-slider__thumb--with-indicator .mdc-slider__value-indicator {
- @include feature-targeting.targets($feat-animation) {
- transition: none;
- }
- }
- }
- }
- // Styles for slider in disabled state.
- @mixin _disabled($query: feature-targeting.all()) {
- $feat-structure: feature-targeting.create-target($query, structure);
- @include feature-targeting.targets($feat-structure) {
- cursor: auto;
- }
- .mdc-slider__thumb {
- @include feature-targeting.targets($feat-structure) {
- pointer-events: none;
- }
- }
- }
|