Skip to content

Commit

Permalink
feat: add an option for a custom container className for toasts conta…
Browse files Browse the repository at this point in the history
…iner
  • Loading branch information
Bloomca committed Sep 15, 2023
1 parent fc577c5 commit d412490
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Reactist follows [semantic versioning](https://semver.org/) and doesn't introduce breaking changes (API-wise) in minor or patch releases. However, the appearance of a component might change in a minor or patch release so keep an eye on redesigns and make sure your app still looks and feels like you expect it.

# v21.3.0

- [Feat] `ToastProvider` accepts an optional `containerClassName` property, which let's you to add your own class for the container of all toasts.

# v21.2.3

- [Fix] Prevent horizontal expansion of `TextArea` with `autoExpand={true}`.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"email": "[email protected]",
"url": "http://doist.com"
},
"version": "21.2.3",
"version": "21.3.0",
"license": "MIT",
"homepage": "https://github.com/Doist/reactist#readme",
"repository": {
Expand Down
11 changes: 11 additions & 0 deletions src/toast/toast.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ describe('useToast', () => {
}
}

describe('ToastsProvider', () => {
it('allows to pass a custom className for the container', () => {
const { showToast } = renderTestCase({
containerClassName: 'customContainerClassName',
})
showToast()

expect(screen.getByTestId('toasts-container')).toHaveClass('customContainerClassName')
})
})

it('renders a semantic alert with the given message', () => {
const { showToast } = renderTestCase()
showToast({ message: 'Project has been published' })
Expand Down
9 changes: 8 additions & 1 deletion src/toast/use-toasts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ type ToastsProviderProps = {
* The app wrapped by the provider.
*/
children: NonNullable<React.ReactNode>

/**
* Custom classname for the toasts container, if you need to fine-tune the position or other styles
*/
containerClassName?: string
}

/**
Expand All @@ -200,6 +205,7 @@ function ToastsProvider({
padding = 'large',
defaultAutoDismissDelay = 10 /* seconds */,
defaultDismissLabel = 'Close',
containerClassName,
}: ToastsProviderProps) {
const [toasts, setToasts] = React.useState<ToastsList>([])
const { mappedRef, animateRemove } = useToastsAnimation()
Expand Down Expand Up @@ -240,11 +246,12 @@ function ToastsProvider({
<Portal>
{toasts.length === 0 ? null : (
<Box
className={styles.stackedToastsView}
className={[styles.stackedToastsView, containerClassName]}
position="fixed"
width="full"
paddingX={padding}
paddingBottom={padding}
data-testid="toasts-container"
>
<Stack space="medium">
{toasts.map(({ toastId, ...props }) => (
Expand Down

0 comments on commit d412490

Please sign in to comment.