AncrelDocumentationv0.3.0

Search documentation

    Documentation / frontend

    用 title 指出哪个操作遇到了什么问题。需要更多上下文时,用 detail 说明用户可以怎样继续。可选的 code 使用等宽字体,方便核对或抄录。

    Live example

    Open playground ↗

    App.tsx

    'use client'
    
    import { useState } from 'react'
    import { Button, ErrorCard } from '@ancrel/ui'
    import '@ancrel/tokens/css'
    import '@ancrel/ui/styles.css'
    
    export default function App() {
      const [editing, setEditing] = useState(false)
      return editing ? <label>Document title <input defaultValue="Untitled" /></label> :
        <ErrorCard title="Document title already in use" tone="warning" code="E_DUPLICATE"
          detail="Choose another title to save a separate copy."
          actions={<Button onClick={() => setEditing(true)}>Rename document</Button>} />
    }
    

    Expected behavior

    The warning explains the duplicate title and displays its code. Rename document opens a title field.

    Build @ancrel/tokens and @ancrel/ui from the workspace root, then run pnpm --filter @ancrel/example-error-card test.

    选择语气和操作

    错误默认使用 danger,可继续处理的提醒可设置为 warning。卡片以 alert 区域播报内容,标题提供可访问名称。用文字说明严重程度,方便高对比度模式下的阅读。

    通过 actions 传入带有明确标签的按钮或链接,点击后的行为由调用方实现。若用户只需阅读说明,可以省略操作区域。

    Props

    PropTypeRequiredDefault
    actionsReactNodeNo—
    classNamestringNo—
    codestringNo—
    detailReactNodeNo—
    keyReact.Key | null | undefinedNo—
    refReact.Ref<HTMLDivElement> | undefinedNo—
    titleReactNodeYes—
    toneToneNo—
    --ac-sys-status-warning-fg

    Constraints

    • Choose danger or warning and state the problem in the title.
    • Provide only actions the caller can perform in the current context.

    Anti-patterns

    • Using a code as the only explanation.
    • Inferring available actions from the displayed message.