Skip to content

Commit 24ac3f7

Browse files
[channel-slider] Show the value above the slider, not in the tooltip, closes #154 (#160)
* First stab at working on #154 * Address feedback: Style improvements
1 parent a7e9757 commit 24ac3f7

File tree

2 files changed

+71
-8
lines changed

2 files changed

+71
-8
lines changed

src/channel-slider/channel-slider.css

+50-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,64 @@
11
.color-slider-label {
2+
--_transition-duration: var(--transition-duration, 200ms);
3+
24
display: grid;
35
grid-template-columns: 1fr auto;
46
gap: .3em;
5-
position: relative;
7+
align-items: center;
68

79
em {
810
opacity: 60%;
11+
transition: opacity var(--_transition-duration);
912
}
10-
}
1113

12-
color-slider {
13-
grid-column: 1 / -1;
14-
}
14+
&:not(:hover, :focus-within) em {
15+
opacity: 0;
16+
}
17+
18+
input[type=number] {
19+
--_border-color: var(--border-color, color-mix(in oklab, currentcolor calc(var(--_current-color-percent, 30) * 1%), oklab(none none none / 0%)));
20+
21+
all: unset;
1522

23+
--content-width: calc(var(--value-length) * 1ch);
24+
width: calc(var(--content-width, 2ch) + 1.2em);
25+
min-width: calc(2ch + 1.2em);
26+
box-sizing: content-box;
27+
padding: .1em .2em;
28+
border-radius: .2em;
29+
border: 1px solid var(--_border-color);
30+
text-align: center;
31+
font-size: 90%;
32+
transition: var(--_transition-duration) allow-discrete;
33+
transition-property: opacity, border-color, display;
1634

35+
&::-webkit-textfield-decoration-container {
36+
gap: .2em;
37+
}
1738

39+
&:not(:hover, :focus) {
40+
--_current-color-percent: 10;
1841

42+
opacity: 60%;
43+
border-color: var(--_border-color);
1944

45+
/* Hide spin buttons in Firefox */
46+
appearance: textfield;
47+
48+
/* Hide spin buttons in Safari and Chrome */
49+
&::-webkit-inner-spin-button {
50+
opacity: 0;
51+
display: none;
52+
}
53+
}
54+
55+
@supports (field-sizing: content) {
56+
field-sizing: content;
57+
width: auto;
58+
}
59+
}
60+
}
61+
62+
color-slider {
63+
grid-column: 1 / -1;
64+
}

src/channel-slider/channel-slider.js

+21-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ const Self = class ChannelSlider extends ColorElement {
99
static shadowStyle = true;
1010
static shadowTemplate = `
1111
<label class="color-slider-label" part="label">
12-
<slot></slot>
13-
<color-slider part="color_slider" exportparts="slider" id="slider" tooltip></color-slider>
12+
<slot>
13+
<span id="channel_info" part="channel-info"></span>
14+
<input type="number" part="spinner" min="0" max="1" step="0.01" id="spinner" />
15+
</slot>
16+
<color-slider part="color_slider" exportparts="slider" id="slider"></color-slider>
1417
</label>`;
1518

1619
constructor () {
@@ -24,10 +27,12 @@ const Self = class ChannelSlider extends ColorElement {
2427
super.connectedCallback?.();
2528

2629
this._el.slider.addEventListener("input", this);
30+
this._el.slot.addEventListener("input", this);
2731
}
2832

2933
disconnectedCallback () {
3034
this._el.slider.removeEventListener("input", this);
35+
this._el.slot.removeEventListener("input", this);
3136
}
3237

3338
handleEvent (event) {
@@ -82,13 +87,26 @@ const Self = class ChannelSlider extends ColorElement {
8287
propChangedCallback ({name, prop, detail: change}) {
8388
if (["space", "min", "max", "step", "value", "defaultValue"].includes(name)) {
8489
prop.applyChange(this._el.slider, change);
90+
91+
if (["min", "max", "step", "value", "defaultValue"].includes(name)) {
92+
prop.applyChange(this._el.spinner, change);
93+
94+
if (name === "value" && this.value !== undefined) {
95+
this._el.spinner.value = Number(this.value.toPrecision(4));
96+
97+
if (!CSS.supports("field-sizing", "content")) {
98+
let valueStr = this._el.spinner.value;
99+
this._el.spinner.style.setProperty("--value-length", valueStr.length);
100+
}
101+
}
102+
}
85103
}
86104

87105
if (name === "defaultColor" || name === "space" || name === "channel" || name === "min" || name === "max") {
88106
this._el.slider.stops = this.stops;
89107

90108
if (name === "space" || name === "channel" || name === "min" || name === "max") {
91-
this._el.slot.innerHTML = `${ this.channelName } <em>(${ this.min }&thinsp;&ndash;&thinsp;${ this.max })</em>`;
109+
this._el.channel_info.innerHTML = `${ this.channelName } <em>(${ this.min }&thinsp;&ndash;&thinsp;${ this.max })</em>`;
92110
}
93111
}
94112
}

0 commit comments

Comments
 (0)