|
| 1 | +@import 'default-theme'; |
| 2 | +@import '_variables'; |
| 3 | + |
| 4 | +// This refers to the thickness of the slider. On a horizontal slider this is the height, on a |
| 5 | +// vertical slider this is the width. |
| 6 | +$md-slider-thickness: 20px !default; |
| 7 | +$md-slider-min-size: 128px !default; |
| 8 | +$md-slider-padding: 8px !default; |
| 9 | + |
| 10 | +$md-slider-track-height: 2px !default; |
| 11 | +$md-slider-thumb-size: 20px !default; |
| 12 | + |
| 13 | +$md-slider-thumb-default-scale: 0.7 !default; |
| 14 | +$md-slider-thumb-focus-scale: 1 !default; |
| 15 | + |
| 16 | +// TODO(iveysaur): Find an implementation to hide the track under a disabled thumb. |
| 17 | +$md-slider-off-color: rgba(black, 0.26); |
| 18 | +$md-slider-focused-color: rgba(black, 0.38); |
| 19 | +$md-slider-disabled-color: rgba(black, 0.26); |
| 20 | + |
| 21 | +/** |
| 22 | + * Uses a container height and an item height to center an item vertically within the container. |
| 23 | + */ |
| 24 | +@function center-vertically($containerHeight, $itemHeight) { |
| 25 | + @return ($containerHeight / 2) - ($itemHeight / 2); |
| 26 | +} |
| 27 | + |
| 28 | +/** |
| 29 | + * Positions the thumb based on its width and height. |
| 30 | + */ |
| 31 | +@mixin slider-thumb-position($width: $md-slider-thumb-size, $height: $md-slider-thumb-size) { |
| 32 | + position: absolute; |
| 33 | + top: center-vertically($md-slider-thickness, $height); |
| 34 | + width: $width; |
| 35 | + height: $height; |
| 36 | + border-radius: max($width, $height); |
| 37 | +} |
| 38 | + |
| 39 | +md-slider { |
| 40 | + height: $md-slider-thickness; |
| 41 | + min-width: $md-slider-min-size; |
| 42 | + position: relative; |
| 43 | + padding: 0; |
| 44 | + display: inline-block; |
| 45 | + outline: none; |
| 46 | + vertical-align: middle; |
| 47 | +} |
| 48 | + |
| 49 | +md-slider *, |
| 50 | +md-slider *::after { |
| 51 | + box-sizing: border-box; |
| 52 | +} |
| 53 | + |
| 54 | +/** |
| 55 | + * Exists in order to pad the slider and keep everything positioned correctly. |
| 56 | + * Cannot be merged with the .md-slider-container. |
| 57 | + */ |
| 58 | +.md-slider-wrapper { |
| 59 | + width: 100%; |
| 60 | + height: 100%; |
| 61 | + padding-left: $md-slider-padding; |
| 62 | + padding-right: $md-slider-padding; |
| 63 | +} |
| 64 | + |
| 65 | +/** |
| 66 | + * Holds the isActive and isDragging classes as well as helps with positioning the children. |
| 67 | + * Cannot be merged with .md-slider-wrapper. |
| 68 | + */ |
| 69 | +.md-slider-container { |
| 70 | + position: relative; |
| 71 | +} |
| 72 | + |
| 73 | +.md-slider-track-container { |
| 74 | + width: 100%; |
| 75 | + position: absolute; |
| 76 | + top: center-vertically($md-slider-thickness, $md-slider-track-height); |
| 77 | + height: $md-slider-track-height; |
| 78 | +} |
| 79 | + |
| 80 | +.md-slider-track { |
| 81 | + position: absolute; |
| 82 | + left: 0; |
| 83 | + right: 0; |
| 84 | + height: 100%; |
| 85 | + background-color: $md-slider-off-color; |
| 86 | +} |
| 87 | + |
| 88 | +.md-slider-track-fill { |
| 89 | + transition-duration: $swift-ease-out-duration; |
| 90 | + transition-timing-function: $swift-ease-out-timing-function; |
| 91 | + transition-property: width, height; |
| 92 | + background-color: md-color($md-accent); |
| 93 | +} |
| 94 | + |
| 95 | +.md-slider-thumb-container { |
| 96 | + position: absolute; |
| 97 | + left: 0; |
| 98 | + top: 50%; |
| 99 | + transform: translate3d(-50%, -50%, 0); |
| 100 | + transition-duration: $swift-ease-out-duration; |
| 101 | + transition-timing-function: $swift-ease-out-timing-function; |
| 102 | + transition-property: left, bottom; |
| 103 | +} |
| 104 | + |
| 105 | +.md-slider-thumb-position { |
| 106 | + transition: transform $swift-ease-out-duration $swift-ease-out-timing-function; |
| 107 | +} |
| 108 | + |
| 109 | +.md-slider-thumb { |
| 110 | + z-index: 1; |
| 111 | + |
| 112 | + @include slider-thumb-position($md-slider-thumb-size, $md-slider-thumb-size); |
| 113 | + transform: scale($md-slider-thumb-default-scale); |
| 114 | + transition: transform $swift-ease-out-duration $swift-ease-out-timing-function; |
| 115 | +} |
| 116 | + |
| 117 | +.md-slider-thumb::after { |
| 118 | + content: ''; |
| 119 | + position: absolute; |
| 120 | + width: $md-slider-thumb-size; |
| 121 | + height: $md-slider-thumb-size; |
| 122 | + border-radius: max($md-slider-thumb-size, $md-slider-thumb-size); |
| 123 | + border-width: 3px; |
| 124 | + border-style: solid; |
| 125 | + transition: inherit; |
| 126 | + background-color: md-color($md-accent); |
| 127 | + border-color: md-color($md-accent); |
| 128 | +} |
| 129 | + |
| 130 | +.md-slider-dragging .md-slider-thumb-position, |
| 131 | +.md-slider-dragging .md-slider-track-fill { |
| 132 | + transition: none; |
| 133 | + cursor: default; |
| 134 | +} |
| 135 | + |
| 136 | +.md-slider-active .md-slider-thumb { |
| 137 | + transform: scale($md-slider-thumb-focus-scale); |
| 138 | +} |
| 139 | + |
| 140 | +.md-slider-disabled .md-slider-thumb::after { |
| 141 | + background-color: $md-slider-disabled-color; |
| 142 | + border-color: $md-slider-disabled-color; |
| 143 | +} |
0 commit comments