@k8ordo/ui

Alert

操作の結果やアプリの状態を知らせます。表示されるとスクリーンリーダーが読み上げます。

インポート

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

使い方

情報

This is an info alert.

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

トーン

成功

Operation completed successfully.

情報

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" />

複数のメッセージ

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

操作のリンク

情報

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>
    ),
  }}
/>

閉じられるアラート

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-

継承する属性(内部で固定するものを除く): HTMLAttributes<HTMLDivElement>

ラベルやプレースホルダーなど、このコンポーネントが描く文言は、propsで指定しないと文言辞書から読まれます。差し替え方は次を見てください: コンポーネントの文言

k8ordo

Baselineに入った機能を、制限なく使うReactのライブラリ群。