|
1 | | -# Alert |
2 | | -Add a description of the component here. |
| 1 | +# pf-alert |
3 | 2 |
|
4 | | -## Usage |
5 | | -Describe how best to use this web component along with best practices. |
| 3 | +The `pf-alert` web component displays PatternFly-styled alerts. It can be used inline in pages or as a toast notification. Alerts support several visual states (for example: `info`, `success`, `warning`, `danger`), an optional header slot, body content, and an `actions` slot for interactive controls. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +Import the element in your page or application as an ES module: |
6 | 8 |
|
7 | 9 | ```html |
8 | | -<pf-alert> |
| 10 | +<script type="module"> |
| 11 | + import '@patternfly/elements/pf-alert/pf-alert.js'; |
| 12 | +</script> |
| 13 | +``` |
9 | 14 |
|
| 15 | +## Basic usage |
| 16 | + |
| 17 | +Inline alert example: |
| 18 | + |
| 19 | +```html |
| 20 | +<pf-alert state="success"> |
| 21 | + <h3 slot="header">Success</h3> |
| 22 | + The operation completed successfully. |
| 23 | + <div slot="actions"> |
| 24 | + <pf-button variant="link">Details</pf-button> |
| 25 | + </div> |
10 | 26 | </pf-alert> |
11 | 27 | ``` |
| 28 | + |
| 29 | +Toast usage (static helper): |
| 30 | + |
| 31 | +```html |
| 32 | +<script type="module"> |
| 33 | + import '@patternfly/elements/pf-alert/pf-alert.js'; |
| 34 | +
|
| 35 | + // Show a simple toast notification |
| 36 | + PfAlert.toast({ message: 'Saved', heading: 'Success', state: 'success' }); |
| 37 | +</script> |
| 38 | +``` |
| 39 | + |
| 40 | +## API |
| 41 | + |
| 42 | +### Attributes / Properties |
| 43 | +- `state` (string) — Visual state of the alert. Common values: `neutral`, `info`, `success`, `warning`, `danger`, `custom`, `cogear`. Default: `neutral`. |
| 44 | +- `variant` (string) — Visual variant: `inline`, `toast`, or `alternate`. |
| 45 | +- `dismissable` (boolean) — When true, a close control is shown and the alert will emit a close event when dismissed. |
| 46 | + |
| 47 | +> See `elements/pf-alert/pf-alert.ts` for exact property types, defaults, and any additional options. |
| 48 | +
|
| 49 | +### Slots |
| 50 | +- `header` — Slot for the heading (typically an `<h3>`). |
| 51 | +- default (unnamed) — Main body/content of the alert. |
| 52 | +- `actions` — Buttons or links for user actions (e.g. `<pf-button slot="actions">`). |
| 53 | + |
| 54 | +### Events |
| 55 | +- `close` (AlertCloseEvent) — Fired when the alert is closed (either via UI or programmatically). The event contains the action (e.g. `'close'`, `'dismiss'`, or `'confirm'`). Check the component source for exact payload. |
| 56 | + |
| 57 | +### Methods |
| 58 | +- `static toast(options)` — Static helper to show a toast notification. Options typically include `message`, `heading`, `state`, `persistent`, and `actions`. |
| 59 | + |
| 60 | +## Styling |
| 61 | + |
| 62 | +The component exposes CSS parts and custom properties for styling. Typical part(s): `::part(container)` for the main container. See the component stylesheet (`pf-alert.css`) for a list of CSS custom properties (colors, spacing, durations) you can override. |
| 63 | + |
| 64 | +## Accessibility |
| 65 | + |
| 66 | +- Toasts use `role="status"` and `aria-live="polite"` to announce messages to assistive technologies. Inline alerts should be used in-context with appropriate semantic markup. |
| 67 | + |
| 68 | +## Notes & tips |
| 69 | + |
| 70 | +- Use the `actions` slot to add interactive elements and listen for their events on the page. |
| 71 | +- For persistent toasts set the `persistent` option when calling `PfAlert.toast(...)`. |
| 72 | +- If you need the exact event names/shape or CSS variables, I can extract and add them from the component source. |
| 73 | + |
| 74 | +--- |
| 75 | +If you want, I can also: |
| 76 | +- Add a short section listing every CSS custom property the component exposes. |
| 77 | +- Add a copyable example showing how to listen for the alert `close` event. |
| 78 | +- Add a brief section demonstrating integration in React or Angular. |
0 commit comments