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

POC: feat: add mode updater to SaltTheme #3237

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

Conversation

DavieReid
Copy link
Contributor

Provide user's with the ability to update the theme mode.

The SaltProvider keeps the theme mode in state and injects setMode into the theme context value.

This allows the mode to be changed via a setter pulled from useTheme()

Marked as POC as I am a bit unsure about the TS types. Have a look at those please.

Copy link

changeset-bot bot commented Apr 10, 2024

⚠️ No Changeset found

Latest commit: f4fe967

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.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

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

vercel bot commented Apr 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
saltdesignsystem ❌ Failed (Inspect) Sep 11, 2024 9:16am

@DavieReid DavieReid requested a review from origami-z April 10, 2024 16:03
@DavieReid DavieReid marked this pull request as draft April 10, 2024 16:03
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { window, ...contextWithoutWindow } = useContext(ThemeContext);

return contextWithoutWindow;
return contextWithoutWindow as ThemeContextValue;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

setMode should always be available from useTheme.

() => ({
theme: themeName,
mode,
window: targetWindow,
themeNext: Boolean(themeNext),
UNSTABLE_corner: corner,
setMode,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think we need to include this in the dep array as React guarantees stable refs for useState setters

Copy link
Contributor

github-actions bot commented Apr 10, 2024

Storybook Preview Link https://1623b85b.saltdesignsystem-storybook.pages.dev

const breakpoints = breakpointsProp ?? DEFAULT_BREAKPOINTS;
const corner = cornerProp ?? inheritedCorner ?? DEFAULT_CORNER;
const [mode, setMode] = useState<Mode>(modeProp ?? inheritedMode);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be made using useControlled....?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure I can switch to that

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.

2 participants