Skip to content
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

Theming: Set themes.normal according to user preference and export getPreferredColorScheme #28721

Open
wants to merge 5 commits into
base: next-8.5
Choose a base branch
from

Conversation

elisezhg
Copy link

@elisezhg elisezhg commented Jul 27, 2024

Closes #28664

What I did

  • Set themes.normal to either the light or dark theme, according to the user preference
  • Export getPreferredColorScheme as suggested in the issue so it can be used in custom themes

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

  1. Run a sandbox for template, e.g. yarn task --task sandbox --start-from auto --template react-vite/default-ts
  2. Set the docs theme to themes.normal in your preview.ts:
const preview: Preview = {
  parameters: {
    controls: {
      matchers: {
        color: /(background|color)$/i,
        date: /Date$/i,
      },
    },
    // ***********************
    docs: {
      theme: themes.normal,
    },
    // ***********************
  },
};
  1. Open Storybook in your browser
  2. Notice that the docs pages' theme is now in sync with the user preference
image image

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>

name before after diff z %
createSize 0 B 0 B 0 B - -
generateSize 77.8 MB 77.8 MB 0 B 1.33 0%
initSize 143 MB 143 MB 579 B 1.19 0%
diffSize 65.6 MB 65.6 MB 579 B 1.18 0%
buildSize 7.19 MB 7.19 MB 431 B -0.86 0%
buildSbAddonsSize 1.85 MB 1.85 MB 225 B -0.69 0%
buildSbCommonSize 195 kB 195 kB 0 B - 0%
buildSbManagerSize 1.87 MB 1.87 MB 192 B 0.45 0%
buildSbPreviewSize 0 B 0 B 0 B - -
buildStaticSize 0 B 0 B 0 B - -
buildPrebuildSize 3.92 MB 3.92 MB 417 B -0.68 0%
buildPreviewSize 3.28 MB 3.28 MB 14 B -0.9 0%
testBuildSize 0 B 0 B 0 B - -
testBuildSbAddonsSize 0 B 0 B 0 B - -
testBuildSbCommonSize 0 B 0 B 0 B - -
testBuildSbManagerSize 0 B 0 B 0 B - -
testBuildSbPreviewSize 0 B 0 B 0 B - -
testBuildStaticSize 0 B 0 B 0 B - -
testBuildPrebuildSize 0 B 0 B 0 B - -
testBuildPreviewSize 0 B 0 B 0 B - -
name before after diff z %
createTime 7.2s 7.1s -63ms -0.93 -0.9%
generateTime 21.1s 20.6s -458ms -0.18 -2.2%
initTime 14.6s 14.8s 142ms -0.16 1%
buildTime 11.5s 10.6s -870ms 1.43 🔰-8.2%
testBuildTime 0ms 0ms 0ms - -
devPreviewResponsive 5.5s 5.5s -13ms 0.2 -0.2%
devManagerResponsive 4.1s 3.7s -312ms -0.29 -8.2%
devManagerHeaderVisible 755ms 580ms -175ms -0.51 -30.2%
devManagerIndexVisible 799ms 608ms -191ms -0.48 -31.4%
devStoryVisibleUncached 2s 1.3s -716ms -1.26 🔰-51.8%
devStoryVisible 800ms 609ms -191ms -0.54 -31.4%
devAutodocsVisible 711ms 469ms -242ms -0.74 -51.6%
devMDXVisible 577ms 494ms -83ms -0.62 -16.8%
buildManagerHeaderVisible 595ms 511ms -84ms -0.86 -16.4%
buildManagerIndexVisible 682ms 602ms -80ms -0.85 -13.3%
buildStoryVisible 575ms 503ms -72ms -0.87 -14.3%
buildAutodocsVisible 562ms 409ms -153ms -0.84 -37.4%
buildMDXVisible 545ms 409ms -136ms -1.08 -33.3%

Greptile Summary

This pull request introduces dynamic theming based on user preferences and exports a utility function for broader use.

  • Updated code/core/src/manager/globals/exports.ts: Added getPreferredColorScheme to global exports.
  • Modified code/core/src/theming/create.ts: Introduced dynamic setting of themes.normal based on user preference.
  • Updated code/core/src/theming/index.ts: Exported getPreferredColorScheme utility function.
  • Enhanced code/core/src/theming/tests/create.test.js: Added tests to verify themes.normal respects user preferences.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

4 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Copy link

nx-cloud bot commented Jul 29, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 79ad963. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

Copy link
Member

@ndelangen ndelangen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cdedreuille are you ok with this?

@thomasaull
Copy link

thomasaull commented Oct 21, 2024

I just found this, when I was setting a brandImage like this:

import { addons } from '@storybook/manager-api'
import { themes } from '@storybook/theming'

addons.setConfig({
  theme: {
    ...themes.normal,
    brandImage: 'path/to/my/logo.svg',
  },
})

and the dark mode following the system preferences would not work anymore.

The development of the MR seems to be finished but it was not merged yet, is there anything which needs to be done still?

@ndelangen Looks like @cdedreuille didn’t find the time to review this, is there anyone else who could bring this forward?

@valentinpalkovic valentinpalkovic changed the base branch from next to next-8.5 December 24, 2024 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: themes.normal not working for docs pages
5 participants