8000 feat(api-reference): light/dark/system buttons variant (for supporting auto/system/device mode) by Ma-ve · Pull Request #5636 · scalar/scalar · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(api-reference): light/dark/system buttons variant (for supporting auto/system/device mode) #5636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Ma-ve
Copy link
Contributor
@Ma-ve Ma-ve commented May 13, 2025

Problem

Currently, once you click a click light/dark mode toggle, you'll be stuck with that forever, unless you clear your localStorage. That goes for both icon and toggle variants.

Solution

With this PR, there's an additional variant for the toggle, which is buttons. buttons is a row-of-three div containing buttons, as light -> system -> dark.

Storybook images image image

Video example:

Screen.Recording.2025-05-13.at.14.45.09.mov

The weird pauses is me Cmd+Spacing and going for "Toggle System Appearance", imitating the behaviour of a system going into light or dark mode respectively.

As there is no icon library, and the sun and moon icons are made by hand (which are really cool), I've opted for a simple, encompassed A. Alternatively, any phone icon, desktop icon, system icon, or even gear icon would work, but as the sun and moon are really, really thin, I've not found one that works, bar the A.

These automatically get stored in the localStorage, as per the setColorMode function available.

It's also available in Storybook. I've not checked any other side-effects, such as the api-client, and I can't seem to get that to work locally.

I've gone and replaced the default api-reference from ToggleButton to ToggleSelect, although that wouldn't be necessary. Easy revert if needed.

Checklist

I’ve gone through the following:

  • I’ve added an explanation why this change is needed.
  • I’ve added a changeset (pnpm changeset).
  • I’ve added tests for the regression or new feature.
  • I’ve updated the documentation.

Ma-ve and others added 6 commits May 13, 2025 14:27
Usage, as in the ApiReference/ModernLayout.vue, per:

```vue
        <!-- Override the dark mode toggle slot to hide it -->
        <template #toggle>
          <ScalarColorModeToggleSelect
            v-if="!props.configuration.hideDarkModeToggle"
            :modelValue="isDark"
            @update:modelValue="$emit('toggleDarkMode')" />
          <span v-else />
```
…buttons, also being able to select "system" (or "auto" as some call it)
@Ma-ve Ma-ve requested review from amritk, hanspagel and hwkr as code owners May 13, 2025 12:55
Copy link
changeset-bot bot commented May 13, 2025

🦋 Changeset detected

Latest commit: 7052937

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@scalar/api-reference Patch
@scalar/aspnetcore Patch
@scalar/fastify-api-reference Patch
@scalar/nuxt Patch
@scalar/api-reference-react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@hanspagel hanspagel requested a review from cameronrohani May 13, 2025 13:28
@cameronrohani
Copy link
Contributor

awesome PR!!!

will need to find some time to explore design of this, either I'll try to find some time this week or early next week

@hanspagel hanspagel marked this pull request as draft May 14, 2025 09:11
@hanspagel
Copy link
Member

🤟

Converting it to draft for the time being

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0