@decidables/decidables-elements 0.4.9 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/README.md +50 -0
- package/lib/decidablesElements.esm.js +102 -21
- package/lib/decidablesElements.esm.js.map +1 -1
- package/lib/decidablesElements.esm.min.js +84 -39
- package/lib/decidablesElements.esm.min.js.map +1 -1
- package/lib/decidablesElements.umd.js +102 -21
- package/lib/decidablesElements.umd.js.map +1 -1
- package/lib/decidablesElements.umd.min.js +85 -40
- package/lib/decidablesElements.umd.min.js.map +1 -1
- package/package.json +2 -2
- package/src/button.js +5 -2
- package/src/slider.js +126 -19
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,15 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.5.0](https://github.com/decidables/decidables/compare/@decidables/decidables-elements@0.4.9...@decidables/decidables-elements@0.5.0) (2025-05-20)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **decidables-elements:** adding optional nonlinear scale and CSS styling to slider ([b0ac44b](https://github.com/decidables/decidables/commit/b0ac44ba9cf7ea44a66bfcf581832bd231b03f4c))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
6
15
|
## [0.4.9](https://github.com/decidables/decidables/compare/@decidables/decidables-elements@0.4.8...@decidables/decidables-elements@0.4.9) (2025-02-06)
|
|
7
16
|
|
|
8
17
|
**Note:** Version bump only for package @decidables/decidables-elements
|
package/README.md
CHANGED
|
@@ -44,6 +44,11 @@ Button for taking actions
|
|
|
44
44
|
- `disabled: boolean = false`
|
|
45
45
|
- In disabled state user can't interact
|
|
46
46
|
|
|
47
|
+
##### CSS Custom Properties
|
|
48
|
+
|
|
49
|
+
- `--decidables-button-background-color`
|
|
50
|
+
- Set the background color for the button
|
|
51
|
+
|
|
47
52
|
##### Example
|
|
48
53
|
|
|
49
54
|
```html
|
|
@@ -65,6 +70,8 @@ Slider w/spinner for selecting a numeric value from a range
|
|
|
65
70
|
|
|
66
71
|
- `disabled: boolean = false`
|
|
67
72
|
- In disabled state user can't interact
|
|
73
|
+
- `scale: boolean = false`
|
|
74
|
+
- Show maximum and minimum values with ticks next to slider
|
|
68
75
|
- `max: number = undefined`
|
|
69
76
|
- Maximum value the slider can take
|
|
70
77
|
- `min: number = undefined`
|
|
@@ -74,6 +81,32 @@ Slider w/spinner for selecting a numeric value from a range
|
|
|
74
81
|
- `value: number = undefined`
|
|
75
82
|
- Initial value of the slider
|
|
76
83
|
|
|
84
|
+
##### Methods
|
|
85
|
+
|
|
86
|
+
- `nonlinearRange(nonlinear, toRange, fromRange)`
|
|
87
|
+
- Set nonlinear scaling for the slider
|
|
88
|
+
- Parameters
|
|
89
|
+
- `nonlinear: boolean`
|
|
90
|
+
- Should the slider have nonlinear scaling
|
|
91
|
+
- `toRange: function(value)`
|
|
92
|
+
- Function defining transform from actual quantity to range position
|
|
93
|
+
- Parameters
|
|
94
|
+
- `value: number`
|
|
95
|
+
- The quantity to transform to range position
|
|
96
|
+
- `fromRange: function(value)`
|
|
97
|
+
- Function defining transform from range position back to actual quantity
|
|
98
|
+
- Parameters
|
|
99
|
+
- `value: number`
|
|
100
|
+
- The range position to transform back to an actual quantity
|
|
101
|
+
|
|
102
|
+
##### CSS Custom Properties
|
|
103
|
+
|
|
104
|
+
- `--decidables-slider-color`
|
|
105
|
+
- Set the color for the slider thumb if enabled
|
|
106
|
+
- `--decidables-slider-background-color`
|
|
107
|
+
- Set the color for the slider track, the background-color for the spinner (and the color for the
|
|
108
|
+
slider thumb, if disabled)
|
|
109
|
+
|
|
77
110
|
##### Example
|
|
78
111
|
|
|
79
112
|
```html
|
|
@@ -104,6 +137,19 @@ Text field w/spinner arrows for selecting a continuous numeric value
|
|
|
104
137
|
- `value: number = undefined`
|
|
105
138
|
- Initial value of the slider
|
|
106
139
|
|
|
140
|
+
##### CSS Custom Properties
|
|
141
|
+
|
|
142
|
+
- `--decidables-spinner-font-size`
|
|
143
|
+
- Set the font-size for the spinner
|
|
144
|
+
- `--decidables-spinner-input-width`
|
|
145
|
+
- Set the width of the input area of the spinner
|
|
146
|
+
- `--decidables-spinner-prefix`
|
|
147
|
+
- Set the prefixed text for the spinner (for example, '$')
|
|
148
|
+
- `--decidables-spinner-postfix`
|
|
149
|
+
- Set the postfixed text for the spinner (for example, 'days')
|
|
150
|
+
- `--decidables-spinner-postfix-padding`
|
|
151
|
+
- Set the width needed to fit the postfix into the spinner
|
|
152
|
+
|
|
107
153
|
##### Example
|
|
108
154
|
|
|
109
155
|
```html
|
|
@@ -130,6 +176,8 @@ Switch for turning an option on or off
|
|
|
130
176
|
- `checked: number = false`
|
|
131
177
|
- Whether the switch is **on** (`true`) or **off** (`false`)
|
|
132
178
|
|
|
179
|
+
##### CSS Custom Properties
|
|
180
|
+
|
|
133
181
|
##### Example
|
|
134
182
|
|
|
135
183
|
```html
|
|
@@ -159,6 +207,8 @@ One option in a toggle set
|
|
|
159
207
|
- `value: string = undefined`
|
|
160
208
|
- An identifier specific to this option to uniquely identify it in the group
|
|
161
209
|
|
|
210
|
+
##### CSS Custom Properties
|
|
211
|
+
|
|
162
212
|
##### Example
|
|
163
213
|
|
|
164
214
|
```html
|
|
@@ -3401,6 +3401,9 @@ class DecidablesButton extends DecidablesElement {
|
|
|
3401
3401
|
static get styles() {
|
|
3402
3402
|
return [super.styles, i$3`
|
|
3403
3403
|
:host {
|
|
3404
|
+
---decidables-button-background-color-disabled: var(--decidables-button-background-color, var(---color-element-disabled));
|
|
3405
|
+
---decidables-button-background-color-enabled: var(--decidables-button-background-color, var(---color-element-enabled));
|
|
3406
|
+
|
|
3404
3407
|
margin: 0.25rem;
|
|
3405
3408
|
}
|
|
3406
3409
|
|
|
@@ -3420,7 +3423,7 @@ class DecidablesButton extends DecidablesElement {
|
|
|
3420
3423
|
}
|
|
3421
3424
|
|
|
3422
3425
|
button:disabled {
|
|
3423
|
-
background-color: var(
|
|
3426
|
+
background-color: var(---decidables-button-background-color-disabled);
|
|
3424
3427
|
outline: none;
|
|
3425
3428
|
box-shadow: none;
|
|
3426
3429
|
}
|
|
@@ -3428,7 +3431,7 @@ class DecidablesButton extends DecidablesElement {
|
|
|
3428
3431
|
button:enabled {
|
|
3429
3432
|
cursor: pointer;
|
|
3430
3433
|
|
|
3431
|
-
background-color: var(
|
|
3434
|
+
background-color: var(---decidables-button-background-color-enabled);
|
|
3432
3435
|
outline: none;
|
|
3433
3436
|
box-shadow: var(---shadow-2);
|
|
3434
3437
|
}
|
|
@@ -3479,6 +3482,11 @@ class DecidablesSlider extends DecidablesElement {
|
|
|
3479
3482
|
type: Boolean,
|
|
3480
3483
|
reflect: true
|
|
3481
3484
|
},
|
|
3485
|
+
scale: {
|
|
3486
|
+
attribute: 'scale',
|
|
3487
|
+
type: Boolean,
|
|
3488
|
+
reflect: true
|
|
3489
|
+
},
|
|
3482
3490
|
max: {
|
|
3483
3491
|
attribute: 'max',
|
|
3484
3492
|
type: Number,
|
|
@@ -3498,6 +3506,11 @@ class DecidablesSlider extends DecidablesElement {
|
|
|
3498
3506
|
attribute: 'value',
|
|
3499
3507
|
type: Number,
|
|
3500
3508
|
reflect: true
|
|
3509
|
+
},
|
|
3510
|
+
nonlinear: {
|
|
3511
|
+
attribute: false,
|
|
3512
|
+
type: Boolean,
|
|
3513
|
+
reflect: false
|
|
3501
3514
|
}
|
|
3502
3515
|
};
|
|
3503
3516
|
}
|
|
@@ -3506,13 +3519,30 @@ class DecidablesSlider extends DecidablesElement {
|
|
|
3506
3519
|
|
|
3507
3520
|
// Attributes
|
|
3508
3521
|
this.disabled = false;
|
|
3522
|
+
this.scale = false;
|
|
3509
3523
|
this.max = undefined;
|
|
3510
3524
|
this.min = undefined;
|
|
3511
3525
|
this.step = undefined;
|
|
3512
3526
|
this.value = undefined;
|
|
3527
|
+
this.nonlinear = false;
|
|
3528
|
+
|
|
3529
|
+
// Properties
|
|
3530
|
+
this.rangeMax = undefined;
|
|
3531
|
+
this.rangeMin = undefined;
|
|
3532
|
+
this.rangeStep = undefined;
|
|
3533
|
+
this.rangeValue = undefined;
|
|
3534
|
+
|
|
3535
|
+
// Transform
|
|
3536
|
+
this.toRange = undefined;
|
|
3537
|
+
this.fromRange = undefined;
|
|
3513
3538
|
}
|
|
3514
|
-
|
|
3515
|
-
this.
|
|
3539
|
+
nonlinearRange(nonlinear, toRange, fromRange) {
|
|
3540
|
+
this.nonlinear = nonlinear;
|
|
3541
|
+
this.toRange = nonlinear ? toRange : undefined;
|
|
3542
|
+
this.fromRange = nonlinear ? fromRange : undefined;
|
|
3543
|
+
}
|
|
3544
|
+
rangeChanged(event) {
|
|
3545
|
+
this.value = this.nonlinear ? this.fromRange(event.target.value) : event.target.value;
|
|
3516
3546
|
this.dispatchEvent(new CustomEvent('change', {
|
|
3517
3547
|
detail: {
|
|
3518
3548
|
value: this.value
|
|
@@ -3520,12 +3550,25 @@ class DecidablesSlider extends DecidablesElement {
|
|
|
3520
3550
|
bubbles: true
|
|
3521
3551
|
}));
|
|
3522
3552
|
}
|
|
3523
|
-
|
|
3553
|
+
rangeInputted(event) {
|
|
3554
|
+
this.value = this.nonlinear ? this.fromRange(event.target.value) : event.target.value;
|
|
3555
|
+
}
|
|
3556
|
+
spinnerInputted(event) {
|
|
3524
3557
|
this.value = event.target.value;
|
|
3525
3558
|
}
|
|
3559
|
+
willUpdate() {
|
|
3560
|
+
this.rangeMax = this.max === undefined ? undefined : this.nonlinear ? this.toRange(this.max) : this.max;
|
|
3561
|
+
this.rangeMin = this.min === undefined ? undefined : this.nonlinear ? this.toRange(this.min) : this.min;
|
|
3562
|
+
this.rangeStep = this.step === undefined ? undefined : this.nonlinear ? 'any' : this.step;
|
|
3563
|
+
this.rangeValue = this.value === undefined ? undefined : this.nonlinear ? this.toRange(this.value) : this.value;
|
|
3564
|
+
}
|
|
3526
3565
|
static get styles() {
|
|
3527
3566
|
return [super.styles, i$3`
|
|
3528
3567
|
:host {
|
|
3568
|
+
---decidables-slider-background-color: var(--decidables-slider-background-color, var(---color-element-disabled));
|
|
3569
|
+
---decidables-slider-color: var(--decidables-slider-color, var(---color-element-enabled));
|
|
3570
|
+
---decidables-spinner-background-color: var(--decidables-slider-background-color, none);
|
|
3571
|
+
|
|
3529
3572
|
---shadow-2-rotate: var(--shadow-2-rotate, ${r$3(this.cssBoxShadow(2, true, false))});
|
|
3530
3573
|
---shadow-4-rotate: var(--shadow-4-rotate, ${r$3(this.cssBoxShadow(4, true, false))});
|
|
3531
3574
|
---shadow-8-rotate: var(--shadow-8-rotate, ${r$3(this.cssBoxShadow(8, true, false))});
|
|
@@ -3543,7 +3586,10 @@ class DecidablesSlider extends DecidablesElement {
|
|
|
3543
3586
|
}
|
|
3544
3587
|
|
|
3545
3588
|
.range {
|
|
3546
|
-
|
|
3589
|
+
position: relative;
|
|
3590
|
+
display: flex;
|
|
3591
|
+
|
|
3592
|
+
flex-direction: row;
|
|
3547
3593
|
|
|
3548
3594
|
width: 3.5rem;
|
|
3549
3595
|
height: 4.75rem;
|
|
@@ -3554,6 +3600,8 @@ class DecidablesSlider extends DecidablesElement {
|
|
|
3554
3600
|
--decidables-spinner-input-width: 3.5rem;
|
|
3555
3601
|
|
|
3556
3602
|
margin: 0 0.25rem 0.25rem;
|
|
3603
|
+
|
|
3604
|
+
background: var(---decidables-spinner-background-color);
|
|
3557
3605
|
}
|
|
3558
3606
|
|
|
3559
3607
|
/* Adapted from http://danielstern.ca/range.css/#/ */
|
|
@@ -3592,14 +3640,14 @@ class DecidablesSlider extends DecidablesElement {
|
|
|
3592
3640
|
width: 100%;
|
|
3593
3641
|
height: 4px;
|
|
3594
3642
|
|
|
3595
|
-
background: var(---
|
|
3643
|
+
background: var(---decidables-slider-background-color);
|
|
3596
3644
|
border: 0;
|
|
3597
3645
|
border-radius: 2px;
|
|
3598
3646
|
box-shadow: none;
|
|
3599
3647
|
}
|
|
3600
3648
|
|
|
3601
3649
|
input[type=range]:focus::-webkit-slider-runnable-track {
|
|
3602
|
-
background: var(---
|
|
3650
|
+
background: var(---decidables-slider-background-color);
|
|
3603
3651
|
}
|
|
3604
3652
|
|
|
3605
3653
|
/* stylelint-disable-next-line no-descending-specificity */ /* stylelint ERROR */
|
|
@@ -3607,7 +3655,7 @@ class DecidablesSlider extends DecidablesElement {
|
|
|
3607
3655
|
width: 100%;
|
|
3608
3656
|
height: 4px;
|
|
3609
3657
|
|
|
3610
|
-
background: var(---
|
|
3658
|
+
background: var(---decidables-slider-background-color);
|
|
3611
3659
|
border: 0;
|
|
3612
3660
|
border-radius: 2px;
|
|
3613
3661
|
box-shadow: none;
|
|
@@ -3627,7 +3675,7 @@ class DecidablesSlider extends DecidablesElement {
|
|
|
3627
3675
|
/* stylelint-disable-next-line no-descending-specificity */ /* stylelint ERROR */
|
|
3628
3676
|
input[type=range]::-ms-fill-lower {
|
|
3629
3677
|
background: #cccccc;
|
|
3630
|
-
/* background: var(---
|
|
3678
|
+
/* background: var(---decidables-slider-background-color); */
|
|
3631
3679
|
border: 0;
|
|
3632
3680
|
border-radius: 2px;
|
|
3633
3681
|
box-shadow: none;
|
|
@@ -3636,7 +3684,7 @@ class DecidablesSlider extends DecidablesElement {
|
|
|
3636
3684
|
/* stylelint-disable-next-line no-descending-specificity */ /* stylelint ERROR */
|
|
3637
3685
|
input[type=range]::-ms-fill-upper {
|
|
3638
3686
|
background: #cccccc;
|
|
3639
|
-
/* background: var(---
|
|
3687
|
+
/* background: var(---decidables-slider-background-color); */
|
|
3640
3688
|
border: 0;
|
|
3641
3689
|
border-radius: 2px;
|
|
3642
3690
|
box-shadow: none;
|
|
@@ -3644,12 +3692,12 @@ class DecidablesSlider extends DecidablesElement {
|
|
|
3644
3692
|
|
|
3645
3693
|
/* stylelint-disable-next-line no-descending-specificity */ /* stylelint ERROR */
|
|
3646
3694
|
input[type=range]:focus::-ms-fill-lower {
|
|
3647
|
-
background: var(---
|
|
3695
|
+
background: var(---decidables-slider-background-color);
|
|
3648
3696
|
}
|
|
3649
3697
|
|
|
3650
3698
|
/* stylelint-disable-next-line no-descending-specificity */ /* stylelint ERROR */
|
|
3651
3699
|
input[type=range]:focus::-ms-fill-upper {
|
|
3652
|
-
background: var(---
|
|
3700
|
+
background: var(---decidables-slider-background-color);
|
|
3653
3701
|
}
|
|
3654
3702
|
|
|
3655
3703
|
/* Thumb */
|
|
@@ -3667,12 +3715,12 @@ class DecidablesSlider extends DecidablesElement {
|
|
|
3667
3715
|
}
|
|
3668
3716
|
|
|
3669
3717
|
input[type=range]:disabled::-webkit-slider-thumb {
|
|
3670
|
-
background: var(---
|
|
3718
|
+
background: var(---decidables-slider-background-color);
|
|
3671
3719
|
box-shadow: none;
|
|
3672
3720
|
}
|
|
3673
3721
|
|
|
3674
3722
|
input[type=range]:enabled::-webkit-slider-thumb {
|
|
3675
|
-
background: var(---
|
|
3723
|
+
background: var(---decidables-slider-color);
|
|
3676
3724
|
box-shadow: var(---shadow-2-rotate);
|
|
3677
3725
|
}
|
|
3678
3726
|
|
|
@@ -3703,13 +3751,13 @@ class DecidablesSlider extends DecidablesElement {
|
|
|
3703
3751
|
|
|
3704
3752
|
/* stylelint-disable-next-line no-descending-specificity */ /* stylelint ERROR */
|
|
3705
3753
|
input[type=range]:disabled::-moz-range-thumb {
|
|
3706
|
-
background: var(---
|
|
3754
|
+
background: var(---decidables-slider-background-color);
|
|
3707
3755
|
box-shadow: none;
|
|
3708
3756
|
}
|
|
3709
3757
|
|
|
3710
3758
|
/* stylelint-disable-next-line no-descending-specificity */ /* stylelint ERROR */
|
|
3711
3759
|
input[type=range]:enabled::-moz-range-thumb {
|
|
3712
|
-
background: var(---
|
|
3760
|
+
background: var(---decidables-slider-color);
|
|
3713
3761
|
box-shadow: var(---shadow-2-rotate);
|
|
3714
3762
|
}
|
|
3715
3763
|
|
|
@@ -3746,13 +3794,13 @@ class DecidablesSlider extends DecidablesElement {
|
|
|
3746
3794
|
|
|
3747
3795
|
/* stylelint-disable-next-line no-descending-specificity */ /* stylelint ERROR */
|
|
3748
3796
|
input[type=range]:disabled::-ms-thumb {
|
|
3749
|
-
background: var(---
|
|
3797
|
+
background: var(---decidables-slider-background-color);
|
|
3750
3798
|
box-shadow: none;
|
|
3751
3799
|
}
|
|
3752
3800
|
|
|
3753
3801
|
/* stylelint-disable-next-line no-descending-specificity */ /* stylelint ERROR */
|
|
3754
3802
|
input[type=range]:enabled::-ms-thumb {
|
|
3755
|
-
background: var(---
|
|
3803
|
+
background: var(---decidables-slider-color);
|
|
3756
3804
|
box-shadow: var(---shadow-2-rotate);
|
|
3757
3805
|
}
|
|
3758
3806
|
|
|
@@ -3774,6 +3822,33 @@ class DecidablesSlider extends DecidablesElement {
|
|
|
3774
3822
|
:host(.keyboard) input[type=range]:enabled:focus:active::-ms-thumb {
|
|
3775
3823
|
box-shadow: var(---shadow-8-rotate);
|
|
3776
3824
|
}
|
|
3825
|
+
|
|
3826
|
+
datalist {
|
|
3827
|
+
position: absolute;
|
|
3828
|
+
left: 2rem;
|
|
3829
|
+
z-index: -1;
|
|
3830
|
+
display: flex;
|
|
3831
|
+
|
|
3832
|
+
flex-direction: column;
|
|
3833
|
+
|
|
3834
|
+
align-items: flex-start;
|
|
3835
|
+
justify-content: space-between;
|
|
3836
|
+
|
|
3837
|
+
height: 4.75rem;
|
|
3838
|
+
|
|
3839
|
+
font-size: 0.75rem;
|
|
3840
|
+
}
|
|
3841
|
+
|
|
3842
|
+
option {
|
|
3843
|
+
padding: 0;
|
|
3844
|
+
|
|
3845
|
+
line-height: 0.8;
|
|
3846
|
+
min-block-size: 0;
|
|
3847
|
+
}
|
|
3848
|
+
|
|
3849
|
+
option::before {
|
|
3850
|
+
content: "– ";
|
|
3851
|
+
}
|
|
3777
3852
|
`];
|
|
3778
3853
|
}
|
|
3779
3854
|
render() {
|
|
@@ -3782,9 +3857,15 @@ class DecidablesSlider extends DecidablesElement {
|
|
|
3782
3857
|
<slot></slot>
|
|
3783
3858
|
</label>
|
|
3784
3859
|
<div class="range">
|
|
3785
|
-
<input ?disabled=${this.disabled} type="range" id="slider" min=${o(this.
|
|
3860
|
+
<input ?disabled=${this.disabled} type="range" id="slider" min=${o(this.rangeMin)} max=${o(this.rangeMax)} step=${o(this.rangeStep)} .value=${this.rangeValue} @change=${this.rangeChanged.bind(this)} @input=${this.rangeInputted.bind(this)}>
|
|
3861
|
+
${this.scale ? x`
|
|
3862
|
+
<datalist id="ticks">
|
|
3863
|
+
<option value=${o(this.rangeMax)} label=${o(this.max)}></option>
|
|
3864
|
+
<option value=${o(this.rangeMin)} label=${o(this.min)}></option>
|
|
3865
|
+
</datalist>
|
|
3866
|
+
` : x``}
|
|
3786
3867
|
</div>
|
|
3787
|
-
<decidables-spinner ?disabled=${this.disabled} min=${o(this.min)} max=${o(this.max)} step=${o(this.step)} .value=${this.value} @input=${this.
|
|
3868
|
+
<decidables-spinner ?disabled=${this.disabled} min=${o(this.min)} max=${o(this.max)} step=${o(this.step)} .value=${this.value} @input=${this.spinnerInputted.bind(this)}></decidables-spinner>
|
|
3788
3869
|
`;
|
|
3789
3870
|
}
|
|
3790
3871
|
}
|