[theme] Improve darkScrollbar helper #25016
Comments
|
I think that On a different note. How about we add a logic to allow computing the other track and active values? It can save time. diff --git a/packages/material-ui/src/darkScrollbar/index.ts b/packages/material-ui/src/darkScrollbar/index.ts
index af4a3ccc90..72a691c0a1 100644
--- a/packages/material-ui/src/darkScrollbar/index.ts
+++ b/packages/material-ui/src/darkScrollbar/index.ts
@@ -1,11 +1,31 @@
+import { lighten, darken, getLuminance, emphasize } from '@material-ui/core/styles';
+
// track, thumb and active are derieved from macOS 10.15.7
const scrollBar = {
- track: '#2b2b2b',
thumb: '#6b6b6b',
- active: '#959595',
};
-export default function darkScrollbar(options = scrollBar) {
+// Opposite of emphasize
+function diminish(color: string, coefficient = 0.15) {
+ return getLuminance(color) > 0.5 ? lighten(color, coefficient) : darken(color, coefficient);
+}
+
+interface Options {
+ track?: string;
+ thumb: string;
+ active?: string;
+}
+
+export default function darkScrollbar(options: Options = scrollBar) {
+ options = { ...options };
+
+ if (!options.track) {
+ options.track = diminish(options.thumb, 0.6);
+ }
+ if (!options.active) {
+ options.active = emphasize(options.thumb, 0.15);
+ }
+
return {
scrollbarColor: `${options.thumb} ${options.track}`,
'&::-webkit-scrollbar, & *::-webkit-scrollbar': {I have set the coefficients to reproduce the same outcome as before, using macOS default colors. |
|
@Primajin The current output of |
|
in CSS not but in JS one could sniff the navigator or so. But maybe we can get around it by only applying (background-)colors and let the rest handle the OS. So we might want to remove the border radius and things like that. I couldn't really figure out yet how Github does it here but I'm investigating. |
|
This one seems quite interesting approach - but maybe there is a shorter way than styling everything: |
|
It looks great |





Summary💡
This is just an idea, but I think we should not set the scrollbar colors "arbitrarily" but rather via the theme. That way the colors have a connection to the used theme.
Examples🌈
I was trying out something like this: https://github.com/Primajin/material-ui/commit/adb389074887567832a46d7f36f613ec61ec6736 this for sure needs more tweaking but it should convey the idea.
We use custom scrollbars with Material UI 4 both for dark and light - so for 5 it would be good if the scrollbars respect the theme.
Motivation🔦
For example we use a different paper and background color in dark mode than the default theme. The scrollbars should match the paper color (or something from
background) so that it fit's with the overall design.The text was updated successfully, but these errors were encountered: