Sperate darkmode into a plugin #384
Mister-Hope
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Many plugins are providing UIs, and it's good to have the darkmode feature sperated. This can allow plugins to support darkmode in all themes.
Options
The darkmode plugin should have these options:
status
'switch'
: "off | auto | on" switch (default)'toggle'
: "Close | Open" toggle switch'auto'
: Automatically decide whether to apply dark mode based on user device’s color-scheme or current time'light'
: forced in lightmode (the switch won't disappear, and UI stays in lightmode)'dark'
: forced in darkmode (the switch won't disappear, and UI stays in darkmode)selector
Examples
For theme default:For a theme use
data-theme="dark"
data-theme="light"
on html :Exporting
A global component called
<DarkmodeButton />
which could be use in themesA composition api called
useDarkmode
in@vuepress/plugin-darkmode/client
temp files including
$lightSelector
$darkSelector
variables:@vuepress/darkmode/sass
: sass file@vuepress/darkmode/less
: less file@vuepress/darkmode/stylus
: stylus fileThis allow plugin authos writing styles like:
Addtional
All plugins should have a option (e.g.:
darkmode
), configed by theme or users whether@vuepress/plugin-darkmode
is actually used.Why do we need this feature outside of theme default?
Extracting this into a plugin can make this feature commonly use in all themes which want to support darkmode, and make plugins be able to support them in plugin side, instead of letting the theme author to overide styles to support darkmode.
Not all the UI changes under darkmode could be done with css variables, and some tools like presentation, chart, will need to redraw themseleves in js apis.
The plugins should be able to make themselves support darkmode (if they need extra things besides css variable) by accessing a reactive darkmode varible and selector variables in styles.
@meteorlxy If you agree, I can build a plugin and make a PR.
Beta Was this translation helpful? Give feedback.
All reactions