@k8ordo/ui

Alert

Reports the result of an action or the state of the application. A screen reader announces it when it appears.

Import

ts
import { Alert } from '@k8ordo/ui';

Usage

Information

This is an info alert.

tsx
<Alert message="This is an info alert." tone="info" />

Tones

Success

Operation completed successfully.

Information

Here is some useful information.

tsx
<Alert message="Operation completed successfully." tone="success" />
<Alert message="Here is some useful information." tone="info" />
<Alert message="Please proceed with caution." tone="warning" />
<Alert message="Something went wrong." tone="error" />

Multiple messages

tsx
<Alert
  message={[
    "Password must be at least 8 characters.",
    "Password must include a number.",
    "Password must include a special character.",
  ]}
  tone="error"
/>

Action link

Information

A new version is available.Learn more

tsx
// Navigation link — the consumer owns the element and its style.
// Use Anchor for a link that matches the library look, or any
// <a> / Next.js Link with your own className.
<Alert
  message="A new version is available."
  tone="info"
  action={{
    label: 'Learn more',
    renderItem: ({ children }) => (
      <Anchor href="https://example.com" openInNewTab>
        {children}
      </Anchor>
    ),
  }}
/>

// Action button (open a modal, etc.) — style it however you like.
<Alert
  message="Your profile setup is incomplete."
  tone="warning"
  action={{
    label: 'Open settings',
    renderItem: ({ children }) => (
      <button
        className={styles.link}
        type="button"
        onClick={() => {}}
      >
        {children}
      </button>
    ),
  }}
/>

Dismissible

tsx
const [isVisible, setIsVisible] = useState(true);

// onClose renders an in-frame close (×) button at the row's end.
<Alert
  message="..."
  onClose={() => setIsVisible(false)}
  tone="warning"
/>

// onClose can be combined with action.
<Alert
  action={{
    label: 'Learn more',
    renderItem: ({ children }) => (
      <button className={styles.link} type="button" onClick={openHelp}>
        {children}
      </button>
    ),
  }}
  message="..."
  onClose={() => setIsVisible(false)}
  tone="warning"
/>

Props

message
Type: string|string[]
Default: -
tone
Type: Status
Default: -
action?
Type: AlertAction
Default: -
closeLabel?
Type: string
Default: -
onClose?
Type: () => void
Default: -
PropTypeDefault
messagestring|string[]-
toneStatus-
action?AlertAction-
closeLabel?string-
onClose?() => void-

Inherited attributes (except the ones set internally): HTMLAttributes<HTMLDivElement>

The wording this component draws (labels, placeholders, and so on) comes from the message dictionary unless a prop sets it. To replace it, see: i18n

k8ordo

React libraries that use Baseline features without holding back.