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

feat(toast): expose Toast wrapper style prop for override #4922

Merged
merged 4 commits into from
Nov 22, 2021
Merged

feat(toast): expose Toast wrapper style prop for override #4922

merged 4 commits into from
Nov 22, 2021

Conversation

karrui
Copy link
Contributor

@karrui karrui commented Oct 25, 2021

Closes #4387

This PR is a continuation of #4432 since that PR seems to have been abandoned. As such, the description is copied from that original PR and extended if necessary.

📝 Description

When users set a fixed-width on their custom toast, this causes their toast to not be centered. This is because we set a fixed maxWidth property on the wrapper component around the toast, which results in the invisible wrapper being centered correctly, but the visible custom component overflowing the parent (the wrapper), making it seem off-centered.

A more detailed explanation of why this arises can be found here

⛳️ Current behavior (updates)

The div (with class="chakra-toast__inner") wrapping the dispatched Toast component currently has a hardcoded style, causing toasts to appear off-center if its child element has a width that is higher than the hardcoded maxWidth of 560px.

🚀 New behavior

Instead of only exposing the maxWidth prop so that that behaviour can be fixed, instead opt to expose (a new) wrapperStyles prop so users can freely update the hardcoded style and more.

For example, the off-center bug can be fixed with

// Via instantiation
const toast = useToast({
    position: "top",
    title: "Wrapper style is updated",
    wrapperStyle: {
      maxWidth: "100%",
    },
})

// Via trigger
<Button onClick={() => toast({ wrapperStyle: { maxWidth: "100%" } })}>
    toast
</Button>

💣 Is this a breaking change (Yes/No):

No

📝 Additional Information

@changeset-bot
Copy link

changeset-bot bot commented Oct 25, 2021

🦋 Changeset detected

Latest commit: 84b91a9

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

This PR includes changesets to release 5 packages
Name Type
@chakra-ui/toast Minor
@chakra-ui/react Patch
@chakra-ui/test-utils Patch
@chakra-ui/props-docs Patch
@chakra-ui/docs 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

@vercel
Copy link

vercel bot commented Oct 25, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployments, click below or on the icon next to each commit.

chakra-ui – ./

🔍 Inspect: https://vercel.com/chakra-ui/chakra-ui/H2nJaw9FGPiJ7VH1qn4MCcVwjo3x
✅ Preview: https://chakra-ui-git-fork-karrui-feat-toast-expose-style-chakra-ui.vercel.app

chakra-ui-storybook – ./

🔍 Inspect: https://vercel.com/chakra-ui/chakra-ui-storybook/CgQeZozPyvuKds7qGxUujdhyNw94
✅ Preview: https://chakra-ui-storybook-git-fork-karrui-feat-toast-cadad1-chakra-ui.vercel.app

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@0x7An
Copy link

0x7An commented Nov 5, 2021

+1 for this, overriding styles of toast is very useful.

@RSchneider94
Copy link

+2 :D are you guys planning to merge this soon? thanks!

@seaerchin seaerchin mentioned this pull request Nov 13, 2021
@agustinusnathaniel
Copy link

agustinusnathaniel commented Nov 15, 2021

+3, really appreciate it if this can be merged soon.

Currently I'm using react-hot-toast when I want customized toast wrapper

If this get merged I can remove that package and use chakra-ui's toast instead (reducing additional package needed just for toast customization)

Copy link
Member

@segunadebayo segunadebayo left a comment

Choose a reason for hiding this comment

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

Thanks for working on this @karrui. Some feedback to get this merged:

  • Please rename all instances of wrapperStyle to containerStyle, I think it's more intuitive.
  • Update the docs to include this feature
  • Update the changeset based on my suggestion

.changeset/moody-bees-pay.md Outdated Show resolved Hide resolved
packages/toast/src/toast-manager.tsx Outdated Show resolved Hide resolved
packages/toast/src/toast-manager.tsx Outdated Show resolved Hide resolved
@karrui
Copy link
Contributor Author

karrui commented Nov 18, 2021

Thanks for working on this @karrui. Some feedback to get this merged:

  • Please rename all instances of wrapperStyle to containerStyle, I think it's more intuitive.
  • Update the docs to include this feature
  • Update the changeset based on my suggestion

Done. Thanks for the review.

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.

Toast is not centered when width exceeds 560px
5 participants