8.0.0 • Published 8 months ago

@leafygreen-ui/toast v8.0.0

Weekly downloads
171
License
Apache-2.0
Repository
github
Last release
8 months ago

Toast

npm (scoped)

View on MongoDB.design

Installation

Yarn

yarn add @leafygreen-ui/toast

NPM

npm install @leafygreen-ui/toast

Example

import Button from '@leafygreen-ui/button';
import { ToastProvider, useToast, Variant } from '@leafygreen-ui/toast';

const { pushToast, clearStack, getStack, updateToast } = useToast();
const stack = getStack();

const createToast = () => {
  pushToast({
    title: 'Toast Title',
    description: 'Toast Description',
    variant: Variant.Success,
    timeout: null,
  });
};

return (
  <ToastProvider>
    <Button onClick={createToast}>Create toast</Button>
  </ToastProvider>
);

Properties, useToast

useToast is a React hook that enables a consumer to interact with a Toast stack. It may only be used inside of a <ToastProvider />. The hook takes no arguments and returns the following functions:

NameSignature
pushToast(payload: ToastProps) => ToastId
popToast(payload: ToastId) => ToastProps \| undefined
updateToast(id: ToastId, props: Partial<ToastProps>, ) => ToastProps \| undefined
getToast(id: ToastId) => ToastProps \| undefined
getStack() => ToastStack \|undefined
clearStack() => void

Properties, ToastProvider

PropTypeDefaultDescription
initialValueMap<ToastId, ToastProps>;The initial toasts in the stack.
portalClassNamestringClass name applied to the containing Portal component

Properties, Controlled Toast

PropTypeDefaultDescription
actionElementReact.ReactNodeOptional action button, or other element. Only rendered if variant === 'progress'. This should be a shortcut only—and not the only way to perform the action. The provided action element should have an aria-description attribute that describes how to alternatively perform the action.
darkModebooleanfalseRenders the component with dark mode styles.
descriptionReact.ReactNodeAdditional body text
dismissiblebooleantrueDetermines whether to render the close button. If timeout === null, then dismissible is forced to true.
onClose(event: ToastCloseEvent) => voidFired either when the close button is clicked, or when timeout has elapsed. When triggered by button click, event.type === "click". When triggered by timeout, event.type === "timeout".
open requiredbooleanRequired boolean that renders the Toast and makes it visible when true. Note: open is not a valid prop when rendering toasts programmatically
progressnumberOptional number between 0 and 1 that sets the progress bar's progress. Note: the progress bar is only rendered when the Toast variant is set to 'progress'.
timeoutnumber \| null6000Dismiss the Toast after timeout milliseconds. If timeout is null or 0, the Toast will never dismiss automatically. Notes: when variant="progress", timeout timer will not start until progress is complete.timeout timer will be paused when a user is interacting with a Toast.
title requiredReact.ReactNodePrimary text for the toast
variant'success' 'note' 'warning' 'progress' 'important'noteRequired style variant to render the Toast as.
7.0.8

11 months ago

7.0.7

11 months ago

7.0.6

11 months ago

7.0.5

12 months ago

7.0.9

10 months ago

7.0.0

1 year ago

7.0.4

12 months ago

7.0.3

12 months ago

7.0.2

1 year ago

7.0.1

1 year ago

7.0.12

10 months ago

7.0.13

9 months ago

7.0.10

10 months ago

7.0.11

10 months ago

7.0.14

8 months ago

6.1.28

1 year ago

8.0.0

8 months ago

6.1.27

1 year ago

6.1.26

2 years ago

6.1.25

2 years ago

6.1.24

2 years ago

6.1.23

2 years ago

6.1.22

2 years ago

6.1.21

2 years ago

6.1.20

2 years ago

6.1.19

2 years ago

6.1.17

2 years ago

6.1.16

2 years ago

6.1.15

2 years ago

7.0.0-alpha.1

3 years ago

6.1.14

2 years ago

7.0.0-alpha.0

3 years ago

6.1.18

2 years ago

6.1.13

2 years ago

6.1.12

2 years ago

6.1.11

2 years ago

6.1.10

3 years ago

6.1.4

3 years ago

6.1.3

3 years ago

6.1.5-next.1

3 years ago

6.1.5-next.0

3 years ago

6.1.5-next.3

3 years ago

6.1.5-next.2

3 years ago

6.1.5-next.5

3 years ago

6.1.5-next.4

3 years ago

6.1.5-next.7

3 years ago

6.1.5-next.6

3 years ago

6.1.6

3 years ago

6.1.5

3 years ago

6.1.8

3 years ago

6.1.7

3 years ago

6.1.9

3 years ago

6.1.0

3 years ago

6.1.2

3 years ago

6.1.1

3 years ago

5.0.1

3 years ago

6.0.0

3 years ago

6.1.1-next.0

3 years ago

5.0.0

3 years ago

4.0.4

3 years ago

4.0.1

3 years ago

4.0.0

3 years ago

4.0.3

3 years ago

4.0.2

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.0.1-test.1

3 years ago

2.0.1-next.2

3 years ago

2.0.1-next.1

3 years ago

2.0.1-next.3

3 years ago

2.0.1-next.0

3 years ago

2.0.0

3 years ago

2.0.1-test.0

3 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.4.10

5 years ago

0.4.9

5 years ago

0.4.8

5 years ago

0.4.7

5 years ago

0.4.6

5 years ago

0.4.5

5 years ago

0.4.4

5 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago