|
| 1 | +/** |
| 2 | + * @prop --cbp-slider-thumb-color: var(--cbp-color-interactive-secondary-dark); |
| 3 | + * @prop --cbp-slider-thumb-color-hover: var(--cbp-color-interactive-secondary-darker); |
| 4 | + * @prop --cbp-slider-thumb-color-focus: var(--cbp-color-interactive-focus-dark); |
| 5 | + * @prop --cbp-slider-thumb-color-border: var(--cbp-color-background-light); |
| 6 | + * @prop --cbp-slider-thumb-color-border-focus: var(--cbp-color-white); |
| 7 | + * @prop --cbp-slider-thumb-color-halo: transparent; |
| 8 | + * @prop --cbp-slider-thumb-color-halo-hover: var(--cbp-color-interactive-secondary-darker); |
| 9 | + * @prop --cbp-slider-thumb-color-halo-focus: var(--cbp-color-interactive-focus-dark); |
| 10 | + * @prop --cbp-slider-track-color-selected: var(--cbp-color-interactive-selected-dark); |
| 11 | + * @prop --cbp-slider-track-color-unselected: var(--cbp-color-interactive-secondary-light); |
| 12 | + * @prop --cbp-slider-thumb-color-dark: var(--cbp-color-interactive-secondary-light); |
| 13 | + * @prop --cbp-slider-thumb-color-hover-dark: var(--cbp-color-interactive-secondary-lighter); |
| 14 | + * @prop --cbp-slider-thumb-color-focus-dark: var(--cbp-color-interactive-focus-light); |
| 15 | + * @prop --cbp-slider-thumb-color-border-dark: var(--cbp-color-background-dark); |
| 16 | + * @prop --cbp-slider-thumb-color-border-focus-dark: var(--cbp-color-black); |
| 17 | + * @prop --cbp-slider-thumb-color-halo-hover-dark: var(--cbp-color-interactive-secondary-lighter); |
| 18 | + * @prop --cbp-slider-thumb-color-halo-focus-dark: var(--cbp-color-interactive-focus-light); |
| 19 | + * @prop --cbp-slider-track-color-selected-dark: var(--cbp-color-interactive-selected-light); |
| 20 | + * @prop --cbp-slider-track-color-unselected-dark: var(--cbp-color-interactive-secondary-base); |
| 21 | + */ |
| 22 | + |
| 23 | +:root { |
| 24 | + --cbp-slider-thumb-color: var(--cbp-color-interactive-secondary-dark); |
| 25 | + --cbp-slider-thumb-color-hover: var(--cbp-color-interactive-secondary-darker); |
| 26 | + --cbp-slider-thumb-color-focus: var(--cbp-color-interactive-focus-dark); |
| 27 | + --cbp-slider-thumb-color-border: var(--cbp-color-background-light); |
| 28 | + --cbp-slider-thumb-color-border-focus: var(--cbp-color-white); |
| 29 | + --cbp-slider-thumb-color-halo: transparent; |
| 30 | + --cbp-slider-thumb-color-halo-hover: var(--cbp-color-interactive-secondary-darker); |
| 31 | + --cbp-slider-thumb-color-halo-focus: var(--cbp-color-interactive-focus-dark); |
| 32 | + --cbp-slider-track-color-selected: var(--cbp-color-interactive-selected-dark); |
| 33 | + --cbp-slider-track-color-unselected: var(--cbp-color-interactive-secondary-light); |
| 34 | + |
| 35 | + --cbp-slider-thumb-color-dark: var(--cbp-color-interactive-secondary-light); |
| 36 | + --cbp-slider-thumb-color-hover-dark: var(--cbp-color-interactive-secondary-lighter); |
| 37 | + --cbp-slider-thumb-color-focus-dark: var(--cbp-color-interactive-focus-light); |
| 38 | + --cbp-slider-thumb-color-border-dark: var(--cbp-color-background-dark); |
| 39 | + --cbp-slider-thumb-color-border-focus-dark: var(--cbp-color-black); |
| 40 | + --cbp-slider-thumb-color-halo-hover-dark: var(--cbp-color-interactive-secondary-lighter); |
| 41 | + --cbp-slider-thumb-color-halo-focus-dark: var(--cbp-color-interactive-focus-light); |
| 42 | + --cbp-slider-track-color-selected-dark: var(--cbp-color-interactive-selected-light); |
| 43 | + --cbp-slider-track-color-unselected-dark: var(--cbp-color-interactive-secondary-base); |
| 44 | + |
| 45 | + --cbp-slider-track-selection-size: 0; |
| 46 | +} |
| 47 | + |
| 48 | +// Displays dark design based on mode or context |
| 49 | +[data-cbp-theme=light] cbp-slider[context*=dark], |
| 50 | +[data-cbp-theme=dark] cbp-slider:not([context=dark-inverts]):not([context=light-always]) { |
| 51 | + --cbp-slider-thumb-color: var(--cbp-slider-thumb-color-dark); |
| 52 | + --cbp-slider-thumb-color-hover: var(--cbp-slider-thumb-color-hover-dark); |
| 53 | + --cbp-slider-thumb-color-focus: var(--cbp-slider-thumb-color-focus-dark); |
| 54 | + --cbp-slider-thumb-color-border: var(--cbp-slider-thumb-color-border-dark); |
| 55 | + --cbp-slider-thumb-color-border-focus: var(--cbp-slider-thumb-color-border-focus-dark); |
| 56 | + --cbp-slider-thumb-color-halo-hover: var(--cbp-slider-thumb-color-halo-hover-dark); |
| 57 | + --cbp-slider-thumb-color-halo-focus: var(--cbp-slider-thumb-color-halo-focus-dark); |
| 58 | + --cbp-slider-track-color-selected: var(--cbp-slider-track-color-selected-dark); |
| 59 | + --cbp-slider-track-color-unselected: var(--cbp-slider-track-color-unselected-dark); |
| 60 | +} |
| 61 | + |
| 62 | + |
| 63 | +cbp-slider { |
| 64 | + display: flex; |
| 65 | + align-items: center; |
| 66 | + gap: var(--cbp-space-2x); |
| 67 | + font-style: italic; |
| 68 | + |
| 69 | + input[type=number] { |
| 70 | + width: 7ch; |
| 71 | + |
| 72 | + // This removes the default increment arrows in the number input field |
| 73 | + &::-webkit-outer-spin-button, |
| 74 | + &::-webkit-inner-spin-button { |
| 75 | + -webkit-appearance: none; |
| 76 | + margin: 0; // Margins still appear even if hidden |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + input[type=number] { |
| 81 | + -moz-appearance: textfield; // Removes the default increment arrows in Firefox |
| 82 | + } |
| 83 | + |
| 84 | + |
| 85 | + .cbp-slider-wrapper { |
| 86 | + position: relative; |
| 87 | + display: flex; |
| 88 | + align-items: center; |
| 89 | + flex-grow: 1; |
| 90 | + width: 100%; |
| 91 | + height: 100%; |
| 92 | + |
| 93 | + .cbp-slider-selection { |
| 94 | + position: absolute; |
| 95 | + display: block; |
| 96 | + background: var(--cbp-slider-track-color-selected); |
| 97 | + border-radius: var(--cbp-border-radius-pill); |
| 98 | + block-size: var(--cbp-space-2x); |
| 99 | + inline-size: 100%; |
| 100 | + transform-origin: left center; |
| 101 | + transform: scaleX(calc(var(--cbp-slider-track-selection-size) / 100)); // TechDebt: the scaling is impacting the border radius. Maybe revisit with clip-path to fix? |
| 102 | + pointer-events: none; |
| 103 | + } |
| 104 | + } |
| 105 | + |
| 106 | + // Native range slider |
| 107 | + input[type=range] { |
| 108 | + -webkit-appearance: none; |
| 109 | + appearance: none; |
| 110 | + background: transparent; |
| 111 | + border: 0; |
| 112 | + outline: 0; |
| 113 | + margin: 0; |
| 114 | + padding: 0; |
| 115 | + cursor: pointer; |
| 116 | + //pointer-events: none; // this is used when 2 sliders are present for a range |
| 117 | + |
| 118 | + // Track |
| 119 | + &::-webkit-slider-runnable-track{ |
| 120 | + background: var(--cbp-slider-track-color-unselected); |
| 121 | + height: var(--cbp-space-half-x); |
| 122 | + border-radius: var(--cbp-border-radius-pill); |
| 123 | + } |
| 124 | + |
| 125 | + &::-moz-range-track{ |
| 126 | + background: var(--cbp-slider-track-color-unselected); |
| 127 | + height: var(--cbp-space-half-x); |
| 128 | + border-radius: var(--cbp-border-radius-pill); |
| 129 | + } |
| 130 | + |
| 131 | + |
| 132 | + // Thumb |
| 133 | + &::-webkit-slider-thumb { |
| 134 | + -webkit-appearance: none; |
| 135 | + appearance: none; |
| 136 | + margin-top: calc((var(--cbp-space-5x) / 2) * -1); |
| 137 | + height: var(--cbp-space-5x); |
| 138 | + width: var(--cbp-space-5x); |
| 139 | + background-color: var(--cbp-slider-thumb-color); |
| 140 | + border: var(--cbp-border-size-md) solid var(--cbp-slider-thumb-color-border); |
| 141 | + border-radius: var(--cbp-border-radius-circle); |
| 142 | + box-shadow: 0 0 0 var(--cbp-space-11x) color-mix(in srgb, var(--cbp-slider-thumb-color-halo), transparent 50%); |
| 143 | + clip-path: circle(122%); // verified |
| 144 | + pointer-events: all; |
| 145 | + } |
| 146 | + |
| 147 | + &::-moz-range-thumb { |
| 148 | + -webkit-appearance: none; |
| 149 | + appearance: none; |
| 150 | + margin-top: calc((var(--cbp-space-4x) / 2) * -1); |
| 151 | + height: var(--cbp-space-5x); |
| 152 | + width: var(--cbp-space-5x); |
| 153 | + background-color: var(--cbp-slider-thumb-color); |
| 154 | + border: var(--cbp-border-size-md) solid var(--cbp-slider-thumb-color-border); |
| 155 | + border-radius: var(--cbp-border-radius-circle); |
| 156 | + box-shadow: 0 0 0 var(--cbp-space-11x) color-mix(in srgb, var(--cbp-slider-thumb-color-halo), transparent 50%); |
| 157 | + clip-path: circle(122%); // verified |
| 158 | + pointer-events: all; |
| 159 | + } |
| 160 | + |
| 161 | + |
| 162 | + // States |
| 163 | + &:hover:not(:disabled) { |
| 164 | + --cbp-slider-thumb-color-halo: var(--cbp-slider-thumb-color-halo-hover); |
| 165 | + --cbp-slider-thumb-color: var(--cbp-slider-thumb-color-hover); |
| 166 | + } |
| 167 | + |
| 168 | + &:focus:not(:disabled) { |
| 169 | + --cbp-slider-thumb-color-halo: var(--cbp-slider-thumb-color-halo-focus); |
| 170 | + --cbp-slider-thumb-color: var(--cbp-slider-thumb-color-focus); |
| 171 | + --cbp-slider-thumb-color-border: var(--cbp-slider-thumb-color-border-focus); |
| 172 | + } |
| 173 | + |
| 174 | + &:disabled { |
| 175 | + --cbp-slider-thumb-color: var(--cbp-color-interactive-secondary-dark); |
| 176 | + --cbp-slider-track-color-selected: var(--cbp-color-interactive-selected-dark); |
| 177 | + --cbp-slider-track-color-unselected: var(--cbp-color-interactive-secondary-light); |
| 178 | + --cbp-slider-thumb-color-dark: var(--cbp-color-interactive-disabled-light); |
| 179 | + --cbp-slider-track-color-selected-dark: var(--cbp-color-interactive-disabled-light); |
| 180 | + --cbp-slider-track-color-unselected-dark: var(--cbp-color-interactive-disabled-dark); |
| 181 | + cursor: not-allowed; |
| 182 | + } |
| 183 | + } |
| 184 | + |
| 185 | +} |
0 commit comments