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
refactor(client): give the slider its own stylesheet
Elian Doran7bfb2d635f84
diff --git a/apps/client/src/stylesheets/theme-next/forms.css b/apps/client/src/stylesheets/theme-next/forms.cssindex c760489b57..71815dc3a0 100644--- a/apps/client/src/stylesheets/theme-next/forms.css+++ b/apps/client/src/stylesheets/theme-next/forms.css@@ -854,117 +854,6 @@ 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/note_map/NoteMap.css b/apps/client/src/widgets/note_map/NoteMap.cssindex 06a53d0f0f..21c77e2ec6 100644--- a/apps/client/src/widgets/note_map/NoteMap.css+++ b/apps/client/src/widgets/note_map/NoteMap.css@@ -12,40 +12,9 @@padding-inline: 10px;}- .note-map-link-distance input[type="range"] {- -webkit-appearance: none;- appearance: none;+ .note-map-link-distance .slider {width: 150px;}-- .note-map-link-distance input[type="range"]::-webkit-slider-runnable-track {- height: 4px;- background-color: var(--main-border-color);- border-radius: 4px;- }-- .note-map-link-distance input[type="range"]::-webkit-slider-thumb {- -webkit-appearance: none;- appearance: none;- height: 15px;- width: 15px;- margin-top: -5px;- background-color: var(--accented-background-color);- border: 1px solid var(--main-text-color);- border-radius: 50%;- }-- .note-map-link-distance input[type="range"]::-moz-range-track {- background-color: var(--main-border-color);- border-radius: 4px;- }-- .note-map-link-distance input[type="range"]::-moz-range-thumb {- background-color: var(--accented-background-color);- border-color: var(--main-text-color);- height: 10px;- width: 10px;- }}/*diff --git a/apps/client/src/widgets/react/Slider.css b/apps/client/src/widgets/react/Slider.cssnew file mode 100644index 0000000000..416bfec07d--- /dev/null+++ b/apps/client/src/widgets/react/Slider.css@@ -0,0 +1,87 @@+.slider {+ --slider-track-height: 6px;+ --slider-thumb-size: 16px;+ --slider-fill-percent: 0%;+ --slider-track-background: var(--cmd-button-background-color, var(--main-border-color));+ --slider-fill-background: var(--cmd-button-text-color, var(--muted-text-color));+ --slider-thumb-background: var(--main-text-color);++ appearance: none;+ -webkit-appearance: none;+ width: 200px;+ height: var(--slider-thumb-size);+ background: transparent;+ cursor: pointer;++ /* WebKit and Blink have no progress pseudo-element, so the track paints the filled part from+ `--slider-fill-percent`, which `Slider` sets. */+ &::-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)+ );+ }++ &::-moz-range-track {+ height: var(--slider-track-height);+ border-radius: calc(var(--slider-track-height) / 2);+ background: var(--slider-track-background);+ }++ &::-moz-range-progress {+ height: var(--slider-track-height);+ border-radius: calc(var(--slider-track-height) / 2);+ background: var(--slider-fill-background);+ }++ &::-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);+ }++ &::-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);+ }++ /* A browser drops a rule naming another engine's pseudo-element, so each engine gets its own. */+ &:not(:disabled):is(:hover, :active)::-webkit-slider-thumb {+ transform: scale(1.15);+ }++ &:not(:disabled):is(:hover, :active)::-moz-range-thumb {+ transform: scale(1.15);+ }++ &:focus {+ outline: unset;+ }++ &:focus-visible::-webkit-slider-thumb {+ outline: 2px solid var(--input-focus-outline-color, var(--main-text-color));+ outline-offset: 2px;+ }++ &:focus-visible::-moz-range-thumb {+ outline: 2px solid var(--input-focus-outline-color, var(--main-text-color));+ outline-offset: 2px;+ }++ &:disabled {+ cursor: default;+ }+}diff --git a/apps/client/src/widgets/react/Slider.tsx b/apps/client/src/widgets/react/Slider.tsxindex 47cec16ec7..b6a2108081 100644--- a/apps/client/src/widgets/react/Slider.tsx+++ b/apps/client/src/widgets/react/Slider.tsx@@ -1,3 +1,5 @@+import "./Slider.css";+interface SliderProps {value: number;onChange(newValue: number);diff --git a/packages/share-theme/src/page/theme_switch.css b/packages/share-theme/src/page/theme_switch.cssindex 67c6325965..ccfa71bb90 100644--- a/packages/share-theme/src/page/theme_switch.css+++ b/packages/share-theme/src/page/theme_switch.css@@ -1,53 +1,3 @@-.switch {- position: relative;- display: inline-block;- width: 60px;- height: 27px;-}--.switch input {- opacity: 0;- width: 0;- height: 0;-}--.slider {- position: absolute;- cursor: pointer;- top: 0;- left: 0;- right: 0;- bottom: 0;- background-color: var(--text-primary);- transition: 0.4s;- border-radius: 34px;-}--.slider::before {- position: absolute;- content: "";- height: 19px;- width: 19px;- left: 4px;- bottom: 4px;- background-color: white;- transition: 0.4s;- border-radius: 50%;- z-index: 2;-}--.theme-dark .slider {- background-color: var(--background-highlight);-}--input:focus + .slider {- box-shadow: 0 0 1px var(--background-highlight);-}--.theme-dark .slider::before {- transform: translateX(33px);-}-.theme-selection {display: flex;align-items: center;@@ -58,37 +8,6 @@ input:focus + .slider {position: relative;}-.dark-icon, .light-icon {- position: absolute;- inset-block: 0;- margin-block: auto;- width: 24px;- height: 20px;- font-size: 20px;- text-align: center;- opacity: 0;- transition: opacity 400ms ease, color 400ms ease;- pointer-events: none;-}--.theme-light .light-icon {- opacity: 1;-}--.theme-dark .dark-icon {- opacity: 1;-}--.dark-icon {- left: 5px;- color: var(--text-primary);-}--.light-icon {- right: 5px;- color: var(--background-highlight);-}-.theme-options {display: flex;margin-inline-start: auto;