Skip to content

[Appdir] Adds theme-switcher with Select in code-examples #3787

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

Merged
merged 10 commits into from
May 15, 2025

Conversation

KenAJoh
Copy link
Collaborator

@KenAJoh KenAJoh commented May 13, 2025

Description

Adds theme-switcher to change between legacy and darkside light/dark. The CSS is loaded dynamically, so legacy/darkside wont overlap. As of now the "default" legacy-css is loaded by in _app by default, so there might be some broken CSS until we remove if from loading by default when we launch the new sites. Note that this can only happen /dev since the switcher is hidden in prod.

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

Component Checklist 📝

  • JSDoc
  • Examples
  • Documentation / Decision Records
  • Storybook
  • Style mappings (@navikt/core/css/config/_mappings.js)
  • Component tokens (@navikt/core/css/tokens.json)
  • CSS class deprecations (@navikt/aksel-stylelint/src/deprecations.ts)
  • Exports (@navikt/core/react/src/index.ts and @navikt/core/react/package.json)
  • New component? CSS import (@navikt/core/css/index.css)
  • Breaking change? Update migration guide. Consider codemod.
  • Changeset (Format: <Component>: <gitmoji?> <Text>. E.g. "Button: ✨ Add feature xyz.")

@KenAJoh KenAJoh requested a review from Copilot May 13, 2025 17:12
Copy link

changeset-bot bot commented May 13, 2025

⚠️ No Changeset found

Latest commit: adbf610

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

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

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a theme-switcher feature for code examples, enabling users to toggle between legacy and darkside light/dark themes by dynamically loading the corresponding CSS. Key changes include the addition of a theme provider component, updates to configuration to expose the design system version, and a query parameter update to ensure the darkside theme is applied in iframes.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
aksel.nav.no/website/pages/_app.tsx Wraps app content in the new ExampleTheming provider
aksel.nav.no/website/package.json Adds the "semver" dependency
aksel.nav.no/website/next.config.ts Imports package.json to expose ds-react version and updates CSP
aksel.nav.no/website/components/website-modules/examples/withDsExample.tsx Updates example theming and breakpoint display with theme support
aksel.nav.no/website/components/website-modules/examples/withDsExample.theme.tsx Implements the theme provider and switcher components
aksel.nav.no/website/components/styles/index.css Adopts new CSS layer syntax for style separation
aksel.nav.no/website/app/_ui/kode-eksempler/KodeEksempler.iframe.tsx Appends a darkside query parameter to the iframe URL
Comments suppressed due to low confidence (2)

aksel.nav.no/website/next.config.ts:60

  • There is a possible error if '@navikt/ds-react' is not defined in package.json; consider checking for its existence before calling .replace to prevent runtime failures.
const akselVersion = packageJson.dependencies["@navikt/ds-react"].replace("^","");

aksel.nav.no/website/components/website-modules/examples/withDsExample.tsx:92

  • [nitpick] Consider using React.ElementType for Wrapper's type to improve type safety and clarity of the intended component behavior.
let Wrapper: string | ((props: any) => JSX.Element) = "div";

@KenAJoh KenAJoh merged commit baebfce into main May 15, 2025
6 checks passed
@KenAJoh KenAJoh deleted the examples-theming branch May 15, 2025 17:22
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.

1 participant