diff --git a/stencil-workspace/src/components/modus-slider/modus-slider.scss b/stencil-workspace/src/components/modus-slider/modus-slider.scss index 8526fb3a5..852ef41bd 100644 --- a/stencil-workspace/src/components/modus-slider/modus-slider.scss +++ b/stencil-workspace/src/components/modus-slider/modus-slider.scss @@ -9,7 +9,11 @@ .slider { appearance: none; - background: $modus-slider-range-bg; + background: linear-gradient( + to right, + $modus-slider-range-bg var(--value-percent, 0%), + $modus-slider-range-disabled-bg var(--value-percent, 0%) + ); border-radius: $rem-8px; height: $rem-8px; } @@ -59,7 +63,11 @@ pointer-events: none; .slider { - background-color: $modus-slider-range-disabled-bg; + background: linear-gradient( + to right, + $modus-slider-thumb-disabled-border-color var(--value-percent, 0%), + $modus-slider-range-disabled-bg var(--value-percent, 0%) + ); } .slider::-webkit-slider-thumb { diff --git a/stencil-workspace/src/components/modus-slider/modus-slider.spec.ts b/stencil-workspace/src/components/modus-slider/modus-slider.spec.ts index c3307a3c5..b8ade3f11 100644 --- a/stencil-workspace/src/components/modus-slider/modus-slider.spec.ts +++ b/stencil-workspace/src/components/modus-slider/modus-slider.spec.ts @@ -10,8 +10,8 @@ describe('modus-slider', () => { expect(root).toEqualHtml(` -
- +
+
diff --git a/stencil-workspace/src/components/modus-slider/modus-slider.tsx b/stencil-workspace/src/components/modus-slider/modus-slider.tsx index 08a3760f1..ea857429f 100644 --- a/stencil-workspace/src/components/modus-slider/modus-slider.tsx +++ b/stencil-workspace/src/components/modus-slider/modus-slider.tsx @@ -1,5 +1,5 @@ // eslint-disable-next-line @typescript-eslint/no-unused-vars -import { Component, Event, EventEmitter, h, Prop } from '@stencil/core'; +import { Component, Event, EventEmitter, h, Prop, State, Watch } from '@stencil/core'; import { generateElementId } from '../../utils/utils'; @Component({ @@ -24,7 +24,7 @@ export class ModusSlider { @Prop() minValue = 0; /** (optional) The slider's value. */ - @Prop({ mutable: true }) value: string; + @Prop({ mutable: true }) value = '50'; /** An event that fires on slider value change. */ @Event() valueChange: EventEmitter; @@ -32,8 +32,23 @@ export class ModusSlider { /** An event that fires on slider value input. */ @Event() valueInput: EventEmitter; + @State() valuePercent: number; + private sliderId = generateElementId() + '_slider'; + constructor() { + this.updateValuePercent(); + } + + componentWillLoad() { + this.updateValuePercent(); + } + + @Watch('value') + updateValuePercent() { + this.valuePercent = ((Number(this.value) - this.minValue) / (this.maxValue - this.minValue)) * 100; + } + handleOnChange(event: Event): void { const value = (event.currentTarget as HTMLInputElement).value; this.value = value; @@ -50,7 +65,8 @@ export class ModusSlider { const className = `modus-slider ${this.disabled ? 'disabled' : ''}`; return ( -
+
{this.label && }