# Alert > An in-page status message with a type icon, optional actions and close button. ```tsx title="hero.tsx" import { Alert, AlertDescription, AlertTitle } from '@langgenius/dify-ui/alert' export function AlertHeroDemo() { return ( Some logs in this time range may have been archived. Archived logs are kept for 30 days and can be exported. ) } ``` ## Usage guidelines - Use `Alert` for a status that stays relevant while the user works on the surrounding content, such as an archived range, a conflicting edit or a form rejection that belongs to no field. Feedback on an action that is over once it is seen is a `Toast`, and a decision the user must answer before continuing is an `AlertDialog`. - `type` sets the icon, the halo and the default role. An `error` alert uses `role="alert"` and interrupts assistive technology; the other types use `role="status"` and wait for a pause. - Pass `role` when the default does not fit. An error that is already present when the page loads, rather than the result of something the user did, takes a non-live role such as `note` so it does not interrupt. - The icon comes from `type` and cannot be replaced. A banner that needs a product or business icon is not an `Alert`. - Every alert has an `AlertTitle`. A one-sentence message uses the title alone; add `AlertDescription` for detail and `AlertActions` for buttons below the text, using small `Button`s. - `AlertClose` is a stateless button with a required `aria-label`. The caller owns whether the alert is visible, whether the dismissal persists and where focus goes, because the focused close button leaves the page with the alert. ## Anatomy ```tsx import { Alert, AlertActions, AlertClose, AlertDescription, AlertTitle, } from '@langgenius/dify-ui/alert' ``` ```tsx ``` `Alert` renders the icon and halo for its `type` and lays out the content beside it. `AlertClose` sits at the inline end and the content reserves space for it. ## Examples ### Types `info`, `success`, `warning` and `error` set the icon, the halo and the default role. These alerts are present when the page loads, so the error alert passes `role="note"`. ```tsx title="types.tsx" import { Alert, AlertTitle } from '@langgenius/dify-ui/alert' export function AlertTypesDemo() { return (
Changes to this connection apply to every app that uses it. The connection is ready. This connection was updated by someone else. The last sync of this connection failed.
) } ``` ### Actions `AlertActions` places buttons below the title and description. ```tsx title="actions.tsx" import { Alert, AlertActions, AlertDescription, AlertTitle } from '@langgenius/dify-ui/alert' import { Button } from '@langgenius/dify-ui/button' export function AlertActionsDemo() { return ( Knowledge base index is out of date. Three documents changed since the last sync. Re-index to include the latest edits in retrieval. ) } ``` ### Dismissible `AlertClose` only reports the click. The caller removes the alert, moves focus to the button that replaces it and decides when the alert comes back. ```tsx title="dismissible.tsx" import { Alert, AlertClose, AlertTitle } from '@langgenius/dify-ui/alert' import { Button } from '@langgenius/dify-ui/button' import * as React from 'react' export function AlertDismissibleDemo() { const [visible, setVisible] = React.useState(true) const focusOnMountRef = React.useRef(false) const toggle = (nextVisible: boolean) => { focusOnMountRef.current = true setVisible(nextVisible) } const focusOnMount = (node: HTMLElement | null) => { if (node && focusOnMountRef.current) { focusOnMountRef.current = false node.focus() } } if (!visible) { return ( ) } return ( This sample app has limited trial messages. Create your own copy to keep using it. toggle(false)} /> ) } ``` ## API reference ### Alert An in-page status message with a semantic icon and background halo. Renders a `
` element. Sets `role="alert"` when `type="error"` and `role="status"` otherwise; pass `role` explicitly when an error is already present on load. **Props** | Prop | Type | Default | Description | | ------ | --------------------------------------------- | ------- | ------------------------------------------------------------------------ | | `type` | `'error' \| 'info' \| 'success' \| 'warning'` | — | The tone of the message, which sets its icon, color, and default `role`. | **Data attributes** | Attribute | Description | | ----------- | ------------------------------------------------------------------- | | `data-type` | The alert type, which sets the icon, the halo and the default role. | ### AlertActions Accepts the props of the element it renders. ### AlertClose A stateless close button for dismissing an alert; callers own visibility state. Renders a `
) } ``` ## Usage guidelines - Use `Button` for an action with a visible text label. An icon-only command uses [`IconButton`](/components/icon-button.md), a persistent pressed state uses `Toggle`, and navigation uses a native link. - Keep one `primary` button per surface for the action the user most likely wants. Supporting actions use `secondary`; low-emphasis actions in toolbars and dense rows use `ghost` or `tertiary`. - Mark an action that deletes or discards data with `tone="destructive"`. The accent variants exist for highlighted secondary actions and do not take a destructive tone. - `Button` renders `type="button"`. Set `type="submit"` when it submits a form. - Do not render a link through `Button`: Base UI applies button semantics, keyboard interaction and disabled behavior to the rendered element. Keep navigation on a native anchor or routing link and reuse the look with `buttonVariants`. - Use `render` with `nativeButton={false}` only when a non-button element intentionally needs button semantics. It is not a link mode. - Use `loading` for an action that was triggered and is now pending, and `disabled` for an action that is unavailable. They are separate facts and can both apply: pass the pending state only to `loading` and keep independent availability conditions in `disabled`. - Pass `focusableWhenDisabled={false}` only when a loading button should opt into native disabled behavior and may leave the tab order. Pass `focusableWhenDisabled` on a `disabled` button only when focus must still land on it: the return target of a closing surface, or a control whose tooltip explains why it is unavailable. - Keep a non-empty visible label throughout loading; the spinner is decorative. Do not replace a changing label with `aria-label`. See [Accessible names](/guides/accessible-names.md) for choosing a naming source. - `Button` does not add `aria-busy`, which describes an element whose own updates assistive technology may defer, not a pending action. Long-running announcements and progress stay with the feature's status, live-region or progress owner. ## Anatomy ```tsx import { Button } from '@langgenius/dify-ui/button' ``` ```tsx ``` `Button` owns the spacing between its children, so call sites do not add icon margins or a `gap-*` class. Override the gap through `className` only for a documented layout exception. ## Examples ### Variants and tones Six variants set the emphasis. `primary`, `secondary`, `tertiary` and `ghost` also take `tone="destructive"`. ```tsx title="variants.tsx" import { Button } from '@langgenius/dify-ui/button' import * as React from 'react' export function ButtonVariantsDemo() { const defaultId = React.useId() const accentId = React.useId() const destructiveId = React.useId() return (
Default
Accent
Destructive
) } ``` ### Sizes `small`, `medium` (the default) and `large` set the height, padding and gap together. `medium` and `large` use 4px and 6px gaps; `small` uses 3px for `primary` and 4px for the other variants. ```tsx title="sizes.tsx" import { Button } from '@langgenius/dify-ui/button' export function ButtonSizesDemo() { return (
) } ``` ### Loading `loading` blocks activation while the button keeps focus, and shows a decorative spinner. When the visible label changes during loading, give the label a stable ID and reference it with `aria-labelledby` so screen readers announce the new name; some browser and screen-reader combinations do not reliably announce changes to a focused button's descendant text. The consumer owns this relationship because only it knows whether the label changes and whether other visible context must also be referenced. A label that stays the same keeps naming the button through its text. ```tsx title="loading.tsx" import { Button } from '@langgenius/dify-ui/button' import * as React from 'react' export function ButtonLoadingDemo() { const [saving, setSaving] = React.useState(false) const labelId = React.useId() const timerRef = React.useRef | null>(null) React.useEffect(() => { return () => { if (timerRef.current) clearTimeout(timerRef.current) } }, []) return ( ) } ``` ### Disabled `disabled` removes the button from the tab order. Add `focusableWhenDisabled` when focus must still reach it, such as a disabled action whose [`Tooltip`](/components/tooltip.md) explains why it is unavailable. ```tsx title="disabled.tsx" import { Button } from '@langgenius/dify-ui/button' import { Tooltip, TooltipContent, TooltipTrigger } from '@langgenius/dify-ui/tooltip' export function ButtonDisabledDemo() { return (
}> Publish Add at least one node before publishing
) } ``` ### Link Keep navigation on a native anchor or router link and apply `buttonVariants` to reuse the button appearance without turning the link into a button. ```tsx title="link.tsx" import { buttonVariants } from '@langgenius/dify-ui/button' export function ButtonLinkDemo() { return (
Read docs ) } ``` ## Keyboard | Key | Action | | ------- | -------------------------------------------------------------------------------------------------------------------------------------------- | | `Enter` | Activates the button. | | `Space` | Activates the button. | | `Tab` | Moves focus to the next control. A loading button stays in the tab order; a disabled button leaves it unless `focusableWhenDisabled` is set. | ## API reference ### Button A styled button that triggers an action. Renders a `

{exported ? `Exported with secrets ${exported.includeSecrets ? 'included' : 'excluded'} and run logs ${exported.stripLogs ? 'stripped' : 'kept'}.` : ''}

) } ``` ## Usage guidelines - Use `Checkbox` for one boolean field value saved with its form, or for one option inside `CheckboxGroup`. Use `CheckboxGroup` for several values from a visible set, `Switch` for an on/off setting that takes effect immediately, and `Toggle` for the pressed state of a button. - Label the checkbox with a visible `FieldLabel` that wraps it, so clicking the text toggles it. Use `aria-label` only when no visible label exists, because a non-blank `aria-label` overrides the associated label. - Use `indeterminate` when the checkbox summarizes a partial selection. It is controlled by the owner, which clears it once the user decides. Inside `CheckboxGroup`, a `parent` checkbox derives the mixed state on its own. - `Checkbox` renders a `` with a hidden `` beside it. Set `name`, `value` and `uncheckedValue` for native form submission. - Use `disabled` for a value the user cannot change, and say why in `FieldDescription`. `readOnly` keeps the value visible and focusable without allowing changes. ## Anatomy ```tsx import { Checkbox } from '@langgenius/dify-ui/checkbox' import { Field, FieldDescription, FieldLabel } from '@langgenius/dify-ui/field' ``` ```tsx Label ``` `Checkbox` owns its indicator: a check mark when checked and a dash when indeterminate. ## Examples ### Indeterminate `indeterminate` shows the mixed state and sets `aria-checked="mixed"`. The owner turns it off when the user picks a side. ```tsx title="indeterminate.tsx" import { Button } from '@langgenius/dify-ui/button' import { Checkbox } from '@langgenius/dify-ui/checkbox' import { Field, FieldDescription, FieldLabel } from '@langgenius/dify-ui/field' import * as React from 'react' type GrantState = boolean | 'mixed' export function CheckboxIndeterminateDemo() { const [grant, setGrant] = React.useState('mixed') return (
Grant the editor role to all members {grant === 'mixed' ? '3 of 8 members already have the editor role.' : grant ? 'All 8 members get the editor role.' : 'No member gets the editor role.'}
) } ``` ### Disabled Set `disabled` on `Field` to disable the checkbox and its label together. The description explains why the value is fixed. ```tsx title="disabled.tsx" import { Checkbox } from '@langgenius/dify-ui/checkbox' import { Field, FieldDescription, FieldLabel } from '@langgenius/dify-ui/field' export function CheckboxDisabledDemo() { return (
Allow members to sign up with email Your workspace signs in through SSO only. Keep an audit log of workspace changes Required by your Enterprise plan.
) } ``` ### Read-only `readOnly` keeps the checkbox focusable, readable and included in form submission without allowing changes. ```tsx title="read-only.tsx" import { Checkbox } from '@langgenius/dify-ui/checkbox' import { Field, FieldDescription, FieldLabel } from '@langgenius/dify-ui/field' export function CheckboxReadOnlyDemo() { return ( Require source citations in published replies Locked by workspace policy. Focusable and submitted with the form, but cannot be toggled. ) } ``` ## Keyboard | Key | Action | | ------- | ---------------------------------------------------------------- | | `Space` | Toggles the focused checkbox. | | `Tab` | Moves focus to the next control. A disabled checkbox is skipped. | ## API reference ### Checkbox A checkbox control supporting checked, unchecked, and indeterminate states. Renders a `` element and a hidden `` beside. Pair with a visible `FieldLabel` or `