designsystemet icon indicating copy to clipboard operation
designsystemet copied to clipboard

Darkmode switcher

Open mimarz opened this issue 2 years ago • 2 comments

If we are going to define a darkmode for theme for our brands we also need to provide a component for users to decide how dark/light mode is applied.

We need to support manual toggle for dark/light mode aswell as automatic mode, which follows systems preferences for which mode should be active.

Its normal to use localstorage and media query prefers-color-scheme for this.

We should make this when we have a new dropdown menu component ready for this.

Notes:

  • https://dev.to/abbeyperini/an-accessible-dark-mode-toggle-in-react-aop
  • https://dev.to/stuffbreaker/dark-mode-in-web-components-is-about-to-get-awesome-4i14

Image

mimarz avatar Aug 24 '23 12:08 mimarz

This is an example of two ways we can apply dark styles to our components. One if on the component, the other is outside: https://codesandbox.io/p/sandbox/ds-darkmode-preview-dzn6sc

Barsnes avatar Mar 19 '24 07:03 Barsnes

Example of selector from Github:

@media (prefers-color-scheme: dark) {
  [data-color-mode=auto][data-dark-theme*=dark]
}

mimarz avatar May 13 '24 10:05 mimarz

@mimarz Could you update status about this?

mrosvik avatar Jun 03 '24 11:06 mrosvik

We will not provide a darkmode switcher in the sense of a component, as its conditional on how and where color-modes should be applied. We will leave this up to our users to decide.

If they want the traditional darkmode switcher they can use our DropdownMenu along with our data attribute, data-ds-color-mode for switching color modes (currently dark, light, contrast & auto) in the relevant root element for their web app.

Color mode auto will use prefers-color-scheme to assign light/dark.

With the use of using data-attributes this will give our users ability to enable color modes for a specific section of the page for use-cases such as "inverted" sections or for the whole page if wanted.

mimarz avatar Jun 17 '24 17:06 mimarz