|
| 1 | +--- |
| 2 | +title: React Alert Component |
| 3 | +name: Alert |
| 4 | +description: React alert component gives contextual feedback information for common user operations. The alert component is delivered with a bunch of usable and adjustable alert messages. |
| 5 | +menu: Components |
| 6 | +route: /components/alert/ |
| 7 | +other_frameworks: alert |
| 8 | +--- |
| 9 | + |
| 10 | +## How to use React Alert Component. |
| 11 | + |
| 12 | +React Alert is prepared for any length of text, as well as an optional close button. For a styling, use one of the **required** contextual `color` props (e.g., `primary`). For inline dismissal, use the [dismissing prop](#dismissing). |
| 13 | + |
| 14 | +import { AlertExample } from './examples/AlertExample.tsx' |
| 15 | +import AlertExampleTS from '!!raw-loader!./examples/AlertExample.tsx' |
| 16 | + |
| 17 | +<ExampleSnippet code={AlertExampleTS} componentName="React Alert"> |
| 18 | + <AlertExample /> |
| 19 | +</ExampleSnippet> |
| 20 | + |
| 21 | +<Callout color="info" title="Conveying meaning to assistive technologies"> |
| 22 | + Using color to add meaning only provides a visual indication, which will not be conveyed to |
| 23 | + users of assistive technologies – such as screen readers. Ensure that information denoted by the |
| 24 | + color is either obvious from the content itself (e.g. the visible text), or is included through |
| 25 | + alternative means, such as additional text hidden with the `.visually-hidden` class. |
| 26 | +</Callout> |
| 27 | + |
| 28 | +### Live example |
| 29 | + |
| 30 | +Click the button below to show an alert (hidden with inline styles to start), then dismiss (and destroy) it with the built-in close button. |
| 31 | + |
| 32 | +import { AlertLiveExample } from './examples/AlertLiveExample.tsx' |
| 33 | +import AlertLiveExampleTS from '!!raw-loader!./examples/AlertLiveExample.tsx' |
| 34 | + |
| 35 | +<ExampleSnippet code={AlertLiveExampleTS} componentName="React Alert"> |
| 36 | + <AlertLiveExample /> |
| 37 | +</ExampleSnippet> |
| 38 | + |
| 39 | +### Link color |
| 40 | + |
| 41 | +Use the `<CAlertLink>` component to immediately give matching colored links inside any react alert component. |
| 42 | + |
| 43 | +import { AlertLinkColorExample } from './examples/AlertLinkColorExample.tsx' |
| 44 | +import AlertLinkColorExampleTS from '!!raw-loader!./examples/AlertLinkColorExample.tsx' |
| 45 | + |
| 46 | +<ExampleSnippet code={AlertLinkColorExampleTS} componentName="React Alert"> |
| 47 | + <AlertLinkColorExample /> |
| 48 | +</ExampleSnippet> |
| 49 | + |
| 50 | +### Additional content |
| 51 | + |
| 52 | +React Alert can also incorporate supplementary components & elements like heading, paragraph, and divider. |
| 53 | + |
| 54 | +import { AlertAdditionalContentExample } from './examples/AlertAdditionalContentExample.tsx' |
| 55 | +import AlertAdditionalContentExampleTS from '!!raw-loader!./examples/AlertAdditionalContentExample.tsx' |
| 56 | + |
| 57 | +<ExampleSnippet code={AlertAdditionalContentExampleTS} componentName="React Alert"> |
| 58 | + <AlertAdditionalContentExample /> |
| 59 | +</ExampleSnippet> |
| 60 | + |
| 61 | +### Icons |
| 62 | + |
| 63 | +Similarly, you can use [flexbox utilities](https//coreui.io/docs/4.0/utilities/flex") and [CoreUI Icons](https://icons.coreui.io) to create react alerts with icons. Depending on your icons and content, you may want to add more utilities or custom styles. |
| 64 | + |
| 65 | +import { AlertIcons1Example } from './examples/AlertIcons1Example.tsx' |
| 66 | +import AlertIcons1ExampleTS from '!!raw-loader!./examples/AlertIcons1Example.tsx' |
| 67 | + |
| 68 | +<ExampleSnippet code={AlertIcons1ExampleTS} componentName="React Alert"> |
| 69 | + <AlertIcons1Example /> |
| 70 | +</ExampleSnippet> |
| 71 | + |
| 72 | + |
| 73 | +Need more than one icon for your react alerts? Consider using [CoreUI Icons](https://icons.coreui.io). |
| 74 | + |
| 75 | +import { AlertIcons2Example } from './examples/AlertIcons2Example.tsx' |
| 76 | +import AlertIcons2ExampleTS from '!!raw-loader!./examples/AlertIcons2Example.tsx' |
| 77 | + |
| 78 | +<ExampleSnippet code={AlertIcons2ExampleTS} componentName="React Alert"> |
| 79 | + <AlertIcons2Example /> |
| 80 | +</ExampleSnippet> |
| 81 | + |
| 82 | + |
| 83 | +### Solid |
| 84 | + |
| 85 | +Use `variant="solid"` to change contextual colors to solid. |
| 86 | + |
| 87 | +import { AlertSolidExample } from './examples/AlertSolidExample.tsx' |
| 88 | +import AlertSolidExampleTS from '!!raw-loader!./examples/AlertSolidExample.tsx' |
| 89 | + |
| 90 | +<ExampleSnippet code={AlertSolidExampleTS} componentName="React Alert"> |
| 91 | + <AlertSolidExample /> |
| 92 | +</ExampleSnippet> |
| 93 | + |
| 94 | +### Dismissing |
| 95 | + |
| 96 | +React Alert component can also be easily dismissed. Just add the `dismissible` prop. |
| 97 | + |
| 98 | +import { AlertDismissingExample } from './examples/AlertDismissingExample.tsx' |
| 99 | +import AlertDismissingExampleTS from '!!raw-loader!./examples/AlertDismissingExample.tsx' |
| 100 | + |
| 101 | +<ExampleSnippet code={AlertDismissingExampleTS} componentName="React Alert"> |
| 102 | + <AlertDismissingExample /> |
| 103 | +</ExampleSnippet> |
| 104 | + |
| 105 | + |
| 106 | +<Callout color="warning"> |
| 107 | + When an alert is dismissed, the element is completely removed from the page structure. If a |
| 108 | + keyboard user dismisses the alert using the close button, their focus will suddenly be lost and, |
| 109 | + depending on the browser, reset to the start of the page/document. |
| 110 | +</Callout> |
| 111 | + |
| 112 | +## API |
| 113 | + |
| 114 | +Check out the documentation below for a comprehensive guide to all the props you can use with the components mentioned here. |
| 115 | + |
| 116 | +- [<CAlert />](./api/#calert) |
| 117 | +- [<CAlertHeading />](./api/#calertheading) |
| 118 | +- [<CAlertLink />](./api/#calertlink) |
0 commit comments