Skip to content

Commit

Permalink
Add custom color attributes for slider and thumb
Browse files Browse the repository at this point in the history
  • Loading branch information
7evenk committed Jul 23, 2024
1 parent 07db140 commit e1e53c8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
22 changes: 8 additions & 14 deletions custom-elements.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
{
"name": "value-max",
"fieldName": "value-max"
},
{
"name": "slider-color",
"fieldName": "slider-color"
},
{
"name": "thumb-color",
"fieldName": "thumb-color"
}
],
"events": [
Expand All @@ -42,20 +50,6 @@
"type": {
"title": "String"
}
},
{
"name": "min-attribute-changed",
"description": "Is raised when the min attribute changes",
"type": {
"title": "String"
}
},
{
"name": "max-changed",
"description": "Is raised when the max attribute changes",
"type": {
"title": "String"
}
}
],
"superclass": {
Expand Down
17 changes: 13 additions & 4 deletions src/slider/SliderWebcomponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
border-radius: 5px;
}
:host {
--slider-color: #01940b;
--thumb-color: #555;
}
.slider-container #slider {
height: 100%;
left: 25%;
right: 25%;
position: absolute;
border-radius: 5px;
background: #01940b;
background: var(--slider-color);
}
.range-input {
Expand All @@ -43,7 +48,7 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
height: 18px;
width: 18px;
border-radius: 70%;
background: #555;
background: var(--thumb-color);
pointer-events: auto;
appearance: none;
}
Expand All @@ -52,7 +57,7 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
height: 18px;
width: 18px;
border-radius: 70%;
background: #555;
background: var(--thumb-color);
pointer-events: auto;
appearance: none;
}
Expand Down Expand Up @@ -99,7 +104,7 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend

public static readonly is = 'node-projects-slider';

static observedAttributes = ['value-min', 'value-max', 'min', 'max'];
static observedAttributes = ['value-min', 'value-max', 'min', 'max', 'slider-color', 'thumb-color'];

private _rangeInputs: HTMLInputElement[];
private _valuesGap: number = 1;
Expand All @@ -115,6 +120,10 @@ export class SliderWebcomponent extends BaseCustomWebComponentConstructorAppend
if (name === "min" || name === "max") {
this._updateRangeInputsMinMax();
}

if (name === "slider-color" || name === "thumb-color") {
this.style.setProperty(`--${name}`, newValue);
}
}

constructor() {
Expand Down

0 comments on commit e1e53c8

Please sign in to comment.