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 4 commits into
base: next
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 76.3 MB 76.3 MB 0 B -0.45 0%
initSize 172 MB 172 MB 578 B -4.36 0%
diffSize 95.7 MB 95.7 MB 578 B -4.36 0%
buildSize 7.59 MB 7.59 MB 404 B -0.99 0%
buildSbAddonsSize 1.64 MB 1.64 MB 195 B 1.43 0%
buildSbCommonSize 195 kB 195 kB 0 B - 0%
buildSbManagerSize 2.29 MB 2.29 MB 191 B -4.27 0%
buildSbPreviewSize 351 kB 351 kB 0 B 1.36 0%
buildStaticSize 0 B 0 B 0 B - -
buildPrebuildSize 4.47 MB 4.47 MB 386 B -1.52 0%
buildPreviewSize 3.12 MB 3.12 MB 18 B 1.39 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 6.7s 24.2s 17.4s 1.37 🔺72.2%
generateTime 20.8s 19s -1s -860ms -2.82 🔰-9.8%
initTime 17.7s 16.8s -912ms -3.14 🔰-5.4%
buildTime 12.7s 12.2s -516ms -1.72 -4.2%
testBuildTime 0ms 0ms 0ms - -
devPreviewResponsive 12s 7.4s -4s -568ms -0.76 -61.2%
devManagerResponsive 6.4s 4.7s -1s -756ms -1.04 -37.2%
devManagerHeaderVisible 1.4s 759ms -663ms -0.63 -87.4%
devManagerIndexVisible 1.4s 789ms -680ms -0.65 -86.2%
devStoryVisibleUncached 1.6s 1.3s -251ms -0.09 -18.1%
devStoryVisible 1.5s 821ms -705ms -0.61 -85.9%
devAutodocsVisible 1.1s 794ms -325ms -0.09 -40.9%
devMDXVisible 991ms 836ms -155ms 0.84 -18.5%
buildManagerHeaderVisible 1s 749ms -323ms -0.71 -43.1%
buildManagerIndexVisible 1s 753ms -328ms -0.71 -43.6%
buildStoryVisible 1.1s 805ms -349ms -0.71 -43.4%
buildAutodocsVisible 936ms 730ms -206ms -0.33 -28.2%
buildMDXVisible 1s 629ms -383ms -0.93 -60.9%

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?

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
4 participants