diff --git a/packages/react-core/src/components/Alert/examples/Alert.md b/packages/react-core/src/components/Alert/examples/Alert.md index d186f28879c..0b624f0ea06 100644 --- a/packages/react-core/src/components/Alert/examples/Alert.md +++ b/packages/react-core/src/components/Alert/examples/Alert.md @@ -13,9 +13,20 @@ import DatabaseIcon from '@patternfly/react-icons/dist/esm/icons/database-icon'; import ServerIcon from '@patternfly/react-icons/dist/esm/icons/server-icon'; import LaptopIcon from '@patternfly/react-icons/dist/esm/icons/laptop-icon'; -## Examples +## Examples + +### Variant examples + +PatternFly supports several alert variants for different scenarios. Each variant has an associated status icon, background, and alert title coded to communicate the severity of an alert. Use the `variant` property to apply the following styling options. If no `variant` is specified, then the variant will be set to "default". + +| Variant | Description | +|---|---| +| Default | Use for generic messages with no associated severity | +| Info | Use for general informational messages | +| Success | Use to indicate that a task or process has been completed successfully | +| Warning | Use to indicate that a non-critical error has occurred| +| Danger | Use to indicate that a critical or blocking error has occurred | -### Types ```ts import React from 'react'; import { Alert } from '@patternfly/react-core'; @@ -29,7 +40,18 @@ import { Alert } from '@patternfly/react-core'; ``` -### Variations +### Alert variations + +PatternFly supports several properties and variations that can be used to add extra content to an alert. + +* As demonstrated in the 1st variation below, use the `actionLinks` property to add one or more `` components that place links beneath the alert message. You must pass in `href` and `component="a"` properties to have an `` act as a proper link, rather than as a button. + +* As demonstrated in the 2nd variation below, use a native HTML `` element to add links within an alert message. + +* As demonstrated in the 3rd and 4th variations below, use the `actionClose` property to add an `` component, which can be used to manage and customize alert dismissals. `actionClose` can be used with or without the presence of `actionLinks`. + +* As demonstrated in the 5th and 6th variations below, use the `titleHeadingLevel` property to set the heading level of an alert title. Headings should be ordered by their level and heading levels should not be skipped. For example, a heading of an `h2` level should not be followed directly by an `h4`. + ```ts import React from 'react'; import { Alert, AlertActionCloseButton, AlertActionLink } from '@patternfly/react-core'; @@ -70,12 +92,139 @@ import { Alert, AlertActionCloseButton, AlertActionLink } from '@patternfly/reac ``` +### Alert timeout + +Use the `timeout` property to automatically dismiss an alert after a period of time. If set to `true`, the `timeout` will be 8000 milliseconds. Provide a specific value to dismiss the alert after a different number of milliseconds. + +```ts +import React from 'react'; +import { Alert, AlertActionLink, AlertGroup, Button } from '@patternfly/react-core'; + +const AlertTimeout: React.FunctionComponent = () => { + const [alerts, setAlerts] = React.useState([]); + const onClick = () => { + const timeout = 8000; + setAlerts(prevAlerts => { + return [...prevAlerts, + + View details + Ignore + + }> + This alert will dismiss after {`${timeout / 1000} seconds`} + + ] + }); + } + + return ( + + + + + {alerts} + + + ); +}; +``` + +### Expandable alerts + +An alert can contain additional, hidden information that is made visible when users click a caret icon. This information can be expanded and collapsed each time the icon is clicked. + +It is not recommended to use an expandable alert with a `timeout` in a toast [alert group](/components/alert-group) because the alert could timeout before users have time to interact with and view the entire alert. + +See the [toast alert considerations](/components/alert/accessibility#toast-alerts) section of the alert accessibility documentation to understand the accessibility risks associated with using toast alerts. + +```ts +import React from 'react'; +import { Alert, AlertActionCloseButton, AlertActionLink } from '@patternfly/react-core'; + + + alert('Clicked the close button')} />} + actionLinks={ + + alert('Clicked on View details')}>View details + alert('Clicked on Ignore')}>Ignore + + } + > +

Success alert description. This should tell the user more information about the alert.

+
+ alert('Clicked the close button')} />} + actionLinks={ + + alert('Clicked on View details')}>View details + alert('Clicked on Ignore')}>Ignore + + } + > +

Success alert description. This should tell the user more information about the alert.

+
+
+``` + +### Truncated alerts + +Use the `truncateTitle` property to shorten a long `title`. Set `truncateTitle` equal to a number (passed in as `{n}`) to reduce the number of lines of text in the alert's `title`. Users may hover over or tab to a truncated `title` to see the full message in a tooltip. + +```ts +import React from 'react'; +import { Alert } from '@patternfly/react-core'; + + + + + + +``` + +### Custom icons + +Use the `customIcon` property to replace a default alert icon with a custom icon. -### Inline types ```ts import React from 'react'; import { Alert } from '@patternfly/react-core'; +import UsersIcon from '@patternfly/react-icons/dist/esm/icons/users-icon'; +import BoxIcon from '@patternfly/react-icons/dist/esm/icons/box-icon'; +import DatabaseIcon from '@patternfly/react-icons/dist/esm/icons/database-icon'; +import ServerIcon from '@patternfly/react-icons/dist/esm/icons/server-icon'; +import LaptopIcon from '@patternfly/react-icons/dist/esm/icons/laptop-icon'; + + + } title="Default alert title" /> + } variant="info" title="Info alert title" /> + } variant="success" title="Success alert title" /> + } variant="warning" title="Warning alert title" /> + } variant="danger" title="Danger alert title" /> + +``` + +### Inline alerts variants +Use inline alerts to display an alert inline with content. All alert variants may use the `isInline` property to position alerts in content-heavy areas, such as within forms, wizards, or drawers. + +```ts +import React from 'react'; +import { Alert } from '@patternfly/react-core'; @@ -84,12 +233,13 @@ import { Alert } from '@patternfly/react-core'; ``` +### Inline alert variations + +All general alert variations can use the `isInline` property to apply inline styling. -### Inline variations ```ts import React from 'react'; import { Alert, AlertActionCloseButton, AlertActionLink } from '@patternfly/react-core'; - ``` -### Inline plain types +### Plain inline alert variants + +Use the `isPlain` property to make any inline alert plain. Plain styling removes the colored background but keeps colored text and icons. + ```ts import React from 'react'; import { Alert } from '@patternfly/react-core'; - @@ -147,14 +299,13 @@ import { Alert } from '@patternfly/react-core'; ``` -### Inline plain variations +### Plain inline alert variations -It is not recommended to use an inline plain alert with actionClose nor actionLinks. +It is not recommended to use a plain inline alert with `actionClose` nor `actionLinks` because these alerts are non-dismissible and should persist until the error or action related to the alert is resolved. ```ts import React from 'react'; import { Alert, AlertActionCloseButton, AlertActionLink } from '@patternfly/react-core'; - ``` -### Expandable +### Static live region alerts -It is not recommended to use an expandable alert within a toast Alert group. In such a case, the Alert could timeout before users would have time to interact and view the entire Alert. +Live region alerts allow you to expose dynamic content changes in a way that can be announced by assistive technologies. -```ts -import React from 'react'; -import { Alert, AlertActionCloseButton, AlertActionLink } from '@patternfly/react-core'; +By default, `isLiveRegion`alerts are static. - - alert('Clicked the close button')} />} - actionLinks={ - - alert('Clicked on View details')}>View details - alert('Clicked on Ignore')}>Ignore - - } - > -

Success alert description. This should tell the user more information about the alert.

-
- alert('Clicked the close button')} />} - actionLinks={ - - alert('Clicked on View details')}>View details - alert('Clicked on Ignore')}>Ignore - - } - > -

Success alert description. This should tell the user more information about the alert.

-
-
-``` - -### Static live region alert ```ts import React from 'react'; import { Alert, AlertActionCloseButton } from '@patternfly/react-core'; @@ -234,84 +349,15 @@ import { Alert, AlertActionCloseButton } from '@patternfly/react-core';
``` -### Dynamic live region alert -Alerts asynchronously appended into dynamic AlertGroups with isLiveRegion will be announced to assistive technology at the moment the change happens, following the strategy used for aria-atomic, which defaults to false. This means only changes of type "addition" will be announced. -```ts file="AlertDynamicLiveRegion.tsx" -``` +### Dynamic live region alerts -### Async live region alert -This shows how an alert could be triggered by an asynchronous event in the application. Note that you can customize how the alert will be announced to assistive technology. See the alert accessibility tab for more information. -```ts file="AlertAsyncLiveRegion.tsx" -``` +Alerts that are asynchronously appended into dynamic [alert groups](/components/alert-group) via the `isLiveRegion` property will be announced to assistive technology the moment the change happens, following the strategy used for `aria-atomic`, which defaults to false. This means only changes of type "addition" will be announced. -### Alert timeout -```ts -import React from 'react'; -import { Alert, AlertActionLink, AlertGroup, Button } from '@patternfly/react-core'; - -const AlertTimeout: React.FunctionComponent = () => { - const [alerts, setAlerts] = React.useState([]); - const onClick = () => { - const timeout = 8000; - setAlerts(prevAlerts => { - return [...prevAlerts, - - View details - Ignore - - }> - This alert will dismiss after {`${timeout / 1000} seconds`} - - ] - }); - } - - return ( - - - - - {alerts} - - - ); -}; -``` - -### Truncate -```ts -import React from 'react'; -import { Alert } from '@patternfly/react-core'; - - - - - - +```ts file="AlertDynamicLiveRegion.tsx" ``` -### Custom icons -```ts -import React from 'react'; -import { Alert } from '@patternfly/react-core'; -import UsersIcon from '@patternfly/react-icons/dist/esm/icons/users-icon'; -import BoxIcon from '@patternfly/react-icons/dist/esm/icons/box-icon'; -import DatabaseIcon from '@patternfly/react-icons/dist/esm/icons/database-icon'; -import ServerIcon from '@patternfly/react-icons/dist/esm/icons/server-icon'; -import LaptopIcon from '@patternfly/react-icons/dist/esm/icons/laptop-icon'; +### Asynchronous live region alerts - - } title="Default alert title" /> - } variant="info" title="Info alert title" /> - } variant="success" title="Success alert title" /> - } variant="warning" title="Warning alert title" /> - } variant="danger" title="Danger alert title" /> - -``` +This example shows how an alert could be triggered by an asynchronous event in the application. Note that you can customize how the alert will be announced to assistive technology. See the [https://www.patternfly.org/v4/components/alert/accessibility](alert accessibility) for more information. +```ts file="AlertAsyncLiveRegion.tsx" +``` \ No newline at end of file