CoreUI is an MIT-licensed open source project and is completely free to use. However, the amount of effort needed to maintain and develop new features for the project is not sustainable without proper financial backing.
You can support our Open Source software development in the following ways:
Push notifications to your visitors with a toast, a lightweight and easily customizable alert message.
CoreUI components are available as native Angular, Bootstrap (Vanilla JS), and Vue components. To learn more please visit the following pages.
React toasts are lightweight notifications designed to mimic the push notifications that have been popularized by mobile and desktop operating systems. They’re built with flexbox, so they’re easy to align and position.
Things to know when using the toast plugin:
autohide: false
.To encourage extensible and predictable toasts, we recommend a header and body. Toast headers use display: flex
, allowing easy alignment of content thanks to our margin and flexbox utilities.
Toasts are as flexible as you need and have very little required markup. At a minimum, we require a single element to contain your "toasted" content and strongly encourage a dismiss button.
1<CToast animation={false} autohide={false} visible={true}>2 <CToastHeader closeButton>3 <svg4 className="rounded me-2"5 width="20"6 height="20"7 xmlns="http://www.w3.org/2000/svg"8 preserveAspectRatio="xMidYMid slice"9 focusable="false"10 role="img"11 >12 <rect width="100%" height="100%" fill="#007aff"></rect>13 </svg>14 <strong className="me-auto">CoreUI for React.js</strong>15 <small>7 min ago</small>16 </CToastHeader>17 <CToastBody>Hello, world! This is a toast message.</CToastBody>18</CToast>
1const [toast, addToast] = useState(0)2const toaster = useRef()3const exampleToast = (4 <CToast>5 <CToastHeader closeButton>6 <svg7 className="rounded me-2"8 width="20"9 height="20"10 xmlns="http://www.w3.org/2000/svg"11 preserveAspectRatio="xMidYMid slice"12 focusable="false"13 role="img"14 >15 <rect width="100%" height="100%" fill="#007aff"></rect>16 </svg>17 <strong className="me-auto">CoreUI for React.js</strong>18 <small>7 min ago</small>19 </CToastHeader>20 <CToastBody>Hello, world! This is a toast message.</CToastBody>21 </CToast>22)23return (24 <>25 <CButton onClick={() => addToast(exampleToast)}>Send a toast</CButton>26 <CToaster ref={toaster} push={toast} placement="top-end" />27 </>28)
Toasts are slightly translucent to blend in with what's below them.
1<CToast autohide={false} visible={true}>2 <CToastHeader closeButton>3 <svg4 className="rounded me-2"5 width="20"6 height="20"7 xmlns="http://www.w3.org/2000/svg"8 preserveAspectRatio="xMidYMid slice"9 focusable="false"10 role="img"11 >12 <rect width="100%" height="100%" fill="#007aff"></rect>13 </svg>14 <strong className="me-auto">CoreUI for React.js</strong>15 <small>7 min ago</small>16 </CToastHeader>17 <CToastBody>Hello, world! This is a toast message.</CToastBody>18</CToast>
You can stack toasts by wrapping them in a toast container, which will vertically add some spacing.
1<CToaster>2 <CToast autohide={false} visible={true}>3 <CToastHeader closeButton>4 <svg5 className="rounded me-2"6 width="20"7 height="20"8 xmlns="http://www.w3.org/2000/svg"9 preserveAspectRatio="xMidYMid slice"10 focusable="false"11 role="img"12 >13 <rect width="100%" height="100%" fill="#007aff"></rect>14 </svg>15 <strong className="me-auto">CoreUI for React.js</strong>16 <small>7 min ago</small>17 </CToastHeader>18 <CToastBody>Hello, world! This is a toast message.</CToastBody>19 </CToast>20 <CToast autohide={false} visible={true}>21 <CToastHeader closeButton>22 <svg23 className="rounded me-2"24 width="20"25 height="20"26 xmlns="http://www.w3.org/2000/svg"27 preserveAspectRatio="xMidYMid slice"28 focusable="false"29 role="img"30 >31 <rect width="100%" height="100%" fill="#007aff"></rect>32 </svg>33 <strong className="me-auto">CoreUI for React.js</strong>34 <small>7 min ago</small>35 </CToastHeader>36 <CToastBody>Hello, world! This is a toast message.</CToastBody>37 </CToast>38</CToaster>
Customize your toasts by removing sub-components, tweaking them with utilities, or by adding your own markup. Here we've created a simpler toast by removing the default <CToastHeader>
, adding a custom hide icon from CoreUI Icons, and using some flexbox utilities to adjust the layout.
1<CToast autohide={false} visible={true} className="align-items-center">2 <div className="d-flex">3 <CToastBody>Hello, world! This is a toast message.</CToastBody>4 <CToastClose className="me-2 m-auto" />5 </div>6</CToast>
Alternatively, you can also add additional controls and components to toasts.
1<CToast autohide={false} visible={true}>2 <CToastBody>3 Hello, world! This is a toast message.4 <div className="mt-2 pt-2 border-top">5 <CButton type="button" color="primary" size="sm">6 Take action7 </CButton>8 <CToastClose component={CButton} color="secondary" size="sm" className="ms-1">9 Close10 </CToastClose>11 </div>12 </CToastBody>13</CToast>
Building on the above example, you can create different toast color schemes with our color and background utilities. Here we've set color="primary"
and added .text-white
class to the <Ctoast>
, and then set white
property to our close button. For a crisp edge, we remove the default border with .border-0
.
1<CToast autohide={false} visible={true} color="primary" className="text-white align-items-center">2 <div className="d-flex">3 <CToastBody>Hello, world! This is a toast message.</CToastBody>4 <CToastClose className="me-2 m-auto" white />5 </div>6</CToast>
React toasts use local CSS variables on .toast
for enhanced real-time customization. Values for the CSS variables are set via Sass, so Sass customization is still supported, too.
1--cui-toast-padding-x: #{$toast-padding-x};2--cui-toast-padding-y: #{$toast-padding-y};3--cui-toast-spacing: #{$toast-spacing};4--cui-toast-max-width: #{$toast-max-width};5--cui-toast-font-size: #{$toast-font-size};6--cui-toast-color: #{$toast-color};7--cui-toast-bg: #{$toast-background-color};8--cui-toast-border-width: #{$toast-border-width};9--cui-toast-border-color: #{$toast-border-color};10--cui-toast-border-radius: #{$toast-border-radius};11--cui-toast-box-shadow: #{$toast-box-shadow};12--cui-toast-header-color: #{$toast-header-color};13--cui-toast-header-bg: #{$toast-header-background-color};14--cui-toast-header-border-color: #{$toast-header-border-color};
1const vars = {2 '--my-css-var': 10,3 '--my-another-css-var': "red"4}5return <CToast style={vars}>...</CToast>
1$toast-max-width: 350px;2$toast-padding-x: .75rem;3$toast-padding-y: .5rem;4$toast-font-size: .875rem;5$toast-color: unset;6$toast-background-color: rgba($white, .85);7$toast-border-width: $border-width;8$toast-border-color: var(--cui-border-color-translucent);9$toast-border-radius: $border-radius;10$toast-box-shadow: $box-shadow;11$toast-spacing: $container-padding-x;1213$toast-header-color: $gray-600;14$toast-header-background-color: rgba($white, .85);15$toast-header-border-color: rgba($black, .05);
1import { CToast } from '@coreui/react'2// or3import CToast from '@coreui/react/src/components/toast/CToast'
Property | Description | Type | Default |
---|---|---|---|
animation | Apply a CSS fade transition to the toast. | boolean | true |
autohide | Auto hide the toast. | boolean | true |
className | A string of all className you want applied to the base component. | string | - |
color | Sets the color context of the component to one of CoreUI’s themed colors. | 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info' | 'dark' | 'light' | string | - |
delay | Delay hiding the toast (ms). | number | 5000 |
onClose | Callback fired when the component requests to be closed. | (index: number) => void | - |
onShow | Callback fired when the component requests to be shown. | (index: number) => void | - |
visible | Toggle the visibility of component. | boolean | false |
1import { CToastHeader } from '@coreui/react'2// or3import CToastHeader from '@coreui/react/src/components/toast/CToastHeader'
Property | Description | Type | Default |
---|---|---|---|
className | A string of all className you want applied to the base component. | string | - |
closeButton | Automatically add a close button to the header. | boolean | - |
1import { CToastBody } from '@coreui/react'2// or3import CToastBody from '@coreui/react/src/components/toast/CToastBody'
Property | Description | Type | Default |
---|---|---|---|
className | A string of all className you want applied to the base component. | string | - |
1import { CToastClose } from '@coreui/react'2// or3import CToastClose from '@coreui/react/src/components/toast/CToastClose'
Property | Description | Type | Default |
---|---|---|---|
active | Toggle the active state for the component. | boolean | - |
className | A string of all className you want applied to the base component. | string | - |
component | Component used for the root node. Either a string to use a HTML element or a component. | string | ComponentClass<any, any> | FunctionComponent<any> | - |
disabled | Toggle the disabled state for the component. | boolean | - |
href | The href attribute specifies the URL of the page the link goes to. | string | - |
shape | Select the shape of the component. | 'rounded' | 'rounded-top' | 'rounded-end' | 'rounded-bottom' | 'rounded-start' | 'rounded-circle' | 'rounded-pill' | 'rounded-0' | 'rounded-1' | 'rounded-2' | 'rounded-3' | string | - |
size | Size the component small or large. | 'sm' | 'lg' | - |
type | Specifies the type of button. Always specify the type attribute for the <button> element.Different browsers may use different default types for the <button> element. | 'button' | 'submit' | 'reset' | - |
variant | Set the button variant to an outlined button or a ghost button. | 'outline' | 'ghost' | - |
white | Change the default color to white. | boolean | - |
1import { CToaster } from '@coreui/react'2// or3import CToaster from '@coreui/react/src/components/toast/CToaster'
Property | Description | Type | Default |
---|---|---|---|
className | A string of all className you want applied to the base component. | string | - |
placement | Describes the placement of your component. | 'top-start' | 'top' | 'top-end' | 'middle-start' | 'middle' | 'middle-end' | 'bottom-start' | 'bottom' | 'bottom-end' | string | - |
push | Adds new CToast to CToaster . | ReactElement | - |