Skip to main content

Toast

<Toast /> is a component that deliver result of the user's action.

Toast usually contains a simple and important message to attract user's attention and automatically disappears after duration.

Loading...

How to use

Basically, Toast is tiggered by hook which is provided by the ToastProvider.

Therefore you need to make ToastProvider wraps the application that you want Toast to appear.

Follow how to use guide in ToastProvider first.

<ToastRenderer /> should be added in component that you want Toast to appear before triggering Toast by hook.

Note that the position of <ToastRenderer /> in component code doesn't matter becuase Toast's position is set by the viewport.

Toast is mounted by the hook which is returned by useToastAction hook.

Toast is generated with the properties that were passed by through showToast parameters.

import {
ToastRenderer,
useToastAction,
} from '@vibrant-ui/components';

const ContentWithToast = (props) => {
const { showToast } = useToastAction();

return (
<VStack mt={200} height="100%" width="100%" flex={1}>
<PressableBox
onClick={() => {
showToast({
kind: 'success',
title="Custom text is applied successfully"
buttonText: 'preview',
onButtonClick: () => {},
});
}}
>
<Text>Show my toast!</Text>
</PressableBox>
<ToastRenderer />
{/* //You should insert <ToastRenderer /> like above! */}
</VStack>
);
};

Properties

PropTypeDefaultDescription
title*string|node-Set title of Toast
kinddefault | success | errordefaultSet kind of Toast
buttonTextstring--Set the text of Toast button
onButtonClickfuinction--Set function runs when Toast button is pressed
durationnumber5000Set time of Toast appears
onClosefunction--Function runs when Toast is closed

Usage

kind

Set the kind of the Toast.

default success error are options.

Loading...
Previous
TextField