webmention-analytics icon indicating copy to clipboard operation
webmention-analytics copied to clipboard

Theming

Open kristofzerbe opened this issue 2 years ago • 5 comments

Some prefer light themes to be easier on the eyes. The current change completes the work on theming of the last pull requests by me.

Features:

  • set a prefered theme (dark or light) in meta.json to render as default
  • switch themes in UI

kristofzerbe avatar Nov 20 '22 15:11 kristofzerbe

Just for you to know. Just discovered two errors, I'm working on right now:

  • Theme is not saved on page change (naah, stupid)
  • Sparklines have fixed color #FFF

kristofzerbe avatar Nov 20 '22 18:11 kristofzerbe

@kristofzerbe sparklines are instantiated from .js-sparkline elements. these could have a data-theme attribute to pass the theme definition to JS. the stroke color could then be set accordingly in sparkline.js.

maxboeck avatar Nov 20 '22 19:11 maxboeck

Yeah, got this, but I have currently now idea how to recolor (or redraw) the lines in the client. I want to make it possible, that the user switch themes on-the-fly.

kristofzerbe avatar Nov 20 '22 19:11 kristofzerbe

hmm - just spitballing here, but whatever method toggles the theme client-side could emit a custom Event, like:

const event = new CustomEvent('toggleTheme', { detail: "dark" });
window. dispatchEvent(event);

The sparkline script can listen for that event and then call drawSparkline again, with a color property that matches the theme:

window.addEventListener('toggleTheme', (e) => {
    const color = e.detail === 'dark' : '#FFF' : '#000'
    drawSparkline(canvas, data, true, color)
})

maxboeck avatar Nov 20 '22 19:11 maxboeck

Events, yeah. Let me do a rewrite of the theming JS tomorrow...

kristofzerbe avatar Nov 20 '22 19:11 kristofzerbe