Skip to content

[Feature Request]: Add support for prefers-color-scheme #4128

@TrevorBurnham

Description

@TrevorBurnham

Description

Currently, you can switch your Cloudscape application to dark mode by adding the dark mode classes awsui-polaris-dark-mode and awsui-dark-mode to <body>. (Incidentally, this behavior doesn't seem to be documented at https://cloudscape.design/foundation/visual-foundation/visual-modes/.) But there's no class you can use to match the browser's prefers-color-scheme.

You could consume that preference in JavaScript and then set the appropriate class, but that doesn't work for SSR: The server has no way of knowing what the user's prefers-color-scheme value is. In practice, this means that any Cloudscape app that uses SSR and automatically switches the theme to match the browser-level preference will show an initial flicker of the wrong mode for some users.

This could be addressed by providing an awsui-auto-mode class that looks like this:

.awsui-auto-mode {
  @media (prefers-color-scheme: dark) {
    /* dark mode styles... */
  }
}

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions