Skip to content

Commit 1d03cd8

Browse files
authored
feat: add an option for a custom container className for toasts container (#800)
1 parent fc577c5 commit 1d03cd8

File tree

5 files changed

+26
-4
lines changed

5 files changed

+26
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
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.
44

5+
# v21.3.0
6+
7+
- [Feat] `ToastProvider` accepts an optional `containerClassName` property, which let's you to add your own class for the container of all toasts.
8+
59
# v21.2.3
610

711
- [Fix] Prevent horizontal expansion of `TextArea` with `autoExpand={true}`.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"email": "henning@doist.com",
77
"url": "http://doist.com"
88
},
9-
"version": "21.2.3",
9+
"version": "21.3.0",
1010
"license": "MIT",
1111
"homepage": "https://github.com/Doist/reactist#readme",
1212
"repository": {

src/toast/toast.test.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ describe('useToast', () => {
4747
}
4848
}
4949

50+
describe('ToastsProvider', () => {
51+
it('allows to pass a custom className for the container', () => {
52+
const { showToast } = renderTestCase({
53+
containerClassName: 'customContainerClassName',
54+
})
55+
showToast()
56+
57+
expect(screen.getByTestId('toasts-container')).toHaveClass('customContainerClassName')
58+
})
59+
})
60+
5061
it('renders a semantic alert with the given message', () => {
5162
const { showToast } = renderTestCase()
5263
showToast({ message: 'Project has been published' })

src/toast/use-toasts.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ type ToastsProviderProps = {
186186
* The app wrapped by the provider.
187187
*/
188188
children: NonNullable<React.ReactNode>
189+
190+
/**
191+
* Custom classname for the toasts container, if you need to fine-tune the position or other styles
192+
*/
193+
containerClassName?: string
189194
}
190195

191196
/**
@@ -200,6 +205,7 @@ function ToastsProvider({
200205
padding = 'large',
201206
defaultAutoDismissDelay = 10 /* seconds */,
202207
defaultDismissLabel = 'Close',
208+
containerClassName,
203209
}: ToastsProviderProps) {
204210
const [toasts, setToasts] = React.useState<ToastsList>([])
205211
const { mappedRef, animateRemove } = useToastsAnimation()
@@ -240,11 +246,12 @@ function ToastsProvider({
240246
<Portal>
241247
{toasts.length === 0 ? null : (
242248
<Box
243-
className={styles.stackedToastsView}
249+
className={[styles.stackedToastsView, containerClassName]}
244250
position="fixed"
245251
width="full"
246252
paddingX={padding}
247253
paddingBottom={padding}
254+
data-testid="toasts-container"
248255
>
249256
<Stack space="medium">
250257
{toasts.map(({ toastId, ...props }) => (

0 commit comments

Comments
 (0)