Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
style(options): drive themed slider fill from the Slider component
Elian Dorana008851171e4
diff --git a/apps/client/src/stylesheets/theme-next/forms.css b/apps/client/src/stylesheets/theme-next/forms.cssindex 3247980c4f..05c6ea0e73 100644--- a/apps/client/src/stylesheets/theme-next/forms.css+++ b/apps/client/src/stylesheets/theme-next/forms.css@@ -751,6 +751,117 @@ input[type="range"] {background: transparent;}+/*+ * Sliders rendered through the shared <Slider> component (.slider). Styled to+ * match the toggle switch design language: a muted pill track that fills with+ * the accent colour, topped by a round thumb sharing the switch colour tokens.+ *+ * The filled portion is driven by --slider-fill-percent (set by the Slider+ * component) for WebKit/Blink, which has no native progress pseudo-element;+ * Firefox uses ::-moz-range-progress and ignores the variable.+ *+ * Selectors are intentionally kept at class-only specificity so that contexts+ * with their own slider styling (e.g. the note map's `.fixnodes-type-switcher`)+ * keep winning the cascade and stay untouched.+ */++.slider {+ --slider-track-height: 6px;+ --slider-thumb-size: 16px;+ --slider-fill-percent: 0%;++ --slider-track-background: var(--cmd-button-background-color);+ --slider-fill-background: var(--cmd-button-text-color);+ /* Opaque foreground — the alpha-blended --cmd-button-text-color used by the+ track would otherwise leave the handle looking semitransparent. */+ --slider-thumb-background: var(--main-text-color);++ appearance: none;+ -webkit-appearance: none;+ width: 200px;+ height: var(--slider-thumb-size);+ background: transparent;+ cursor: pointer;+}++/* Track — WebKit/Blink (the filled portion is painted via the gradient stop) */+.slider::-webkit-slider-runnable-track {+ height: var(--slider-track-height);+ border-radius: calc(var(--slider-track-height) / 2);+ background: linear-gradient(+ to right,+ var(--slider-fill-background) var(--slider-fill-percent),+ var(--slider-track-background) var(--slider-fill-percent)+ );+}++/* Track — Firefox */+.slider::-moz-range-track {+ height: var(--slider-track-height);+ border-radius: calc(var(--slider-track-height) / 2);+ background: var(--slider-track-background);+}++.slider::-moz-range-progress {+ height: var(--slider-track-height);+ border-radius: calc(var(--slider-track-height) / 2);+ background: var(--slider-fill-background);+}++/* Thumb — WebKit/Blink */+.slider::-webkit-slider-thumb {+ appearance: none;+ -webkit-appearance: none;+ width: var(--slider-thumb-size);+ height: var(--slider-thumb-size);+ margin-top: calc((var(--slider-track-height) - var(--slider-thumb-size)) / 2);+ border: unset;+ border-radius: 50%;+ background: var(--slider-thumb-background);+ transition: transform 150ms cubic-bezier(0.22, 1, 0.36, 1);+}++/* Thumb — Firefox */+.slider::-moz-range-thumb {+ width: var(--slider-thumb-size);+ height: var(--slider-thumb-size);+ border: unset;+ border-radius: 50%;+ background: var(--slider-thumb-background);+ transition: transform 150ms cubic-bezier(0.22, 1, 0.36, 1);+}++/* Grow the thumb slightly on hover / drag for a tactile feel */+.slider:not(:disabled):hover::-webkit-slider-thumb,+.slider:not(:disabled):active::-webkit-slider-thumb {+ transform: scale(1.15);+}++.slider:not(:disabled):hover::-moz-range-thumb,+.slider:not(:disabled):active::-moz-range-thumb {+ transform: scale(1.15);+}++/* Focus — outline the thumb, consistent with the switch and other inputs */+.slider:focus {+ outline: unset;+}++.slider:focus-visible::-webkit-slider-thumb {+ outline: 2px solid var(--input-focus-outline-color);+ outline-offset: 2px;+}++.slider:focus-visible::-moz-range-thumb {+ outline: 2px solid var(--input-focus-outline-color);+ outline-offset: 2px;+}++/* Disabled (opacity is handled by the generic input:disabled rule above) */+.slider:disabled {+ cursor: default;+}+/** WebKit scrollbars*/diff --git a/apps/client/src/widgets/react/Slider.tsx b/apps/client/src/widgets/react/Slider.tsxindex fd1ea0c23c..b341871e27 100644--- a/apps/client/src/widgets/react/Slider.tsx+++ b/apps/client/src/widgets/react/Slider.tsx@@ -7,11 +7,20 @@ interface SliderProps {title?: string;}-export default function Slider({ onChange, ...restProps }: SliderProps) {+export default function Slider({ onChange, value, min = 0, max = 100, ...restProps }: SliderProps) {+ // Percentage of the track that is filled, used by the theme to paint the+ // filled portion on WebKit/Blink (which lacks a native progress element).+ const range = max - min;+ const fillPercent = range > 0 ? Math.max(0, Math.min(100, ((value - min) / range) * 100)) : 0;+return (<inputtype="range"className="slider"+ value={value}+ min={min}+ max={max}+ style={{ "--slider-fill-percent": `${fillPercent}%` }}onChange={(e) => {onChange(e.currentTarget.valueAsNumber);}}