Doc Callout
A tinted note box in four tones - info, warning, danger, success - whose icon cycles the tone.
npx shadcn@latest add @velaui/doc-calloutpnpm dlx velaui add @velaui/doc-calloutyarn dlx shadcn@latest add @velaui/doc-calloutbunx --bun shadcn@latest add @velaui/doc-calloutveni add doc-calloutInstalls the copy of vela-ui that veni-builder serves to Venizia apps; veni-builder serves the Radix UI copy only, so this tab exists for that base alone.
npx shadcn@latest add @velaui/doc-calloutpnpm dlx velaui add @velaui/doc-calloutyarn dlx shadcn@latest add @velaui/doc-calloutbunx --bun shadcn@latest add @velaui/doc-calloutExamples
- Default
- Tones
Usage
Props
| Prop | Type | Default |
|---|---|---|
highlights | string[] | — |
onChange | (value: string, caret: number) => void | — |
onToneChange | (tone: DocCalloutTone) => void | — |
tone | DocCalloutTone | "info" |
valuerequired | string | — |
Takes these and every prop of DocCalloutProps.
Dependencies
- npm
- none besides React
- Installs with it
- Doc Typography4 icons
Source
components/ui/doc-callout.tsx
/* eslint-disable react-refresh/only-export-components */
import { AlertTriangle } from "@/components/icons/alert-triangle";
import { CheckContained } from "@/components/icons/check-contained";
import { CloseCircleContained } from "@/components/icons/close-circle-contained";
import { InformationCircleContained } from "@/components/icons/information-circle-contained";
import { DocTypography, type DocTypographyProps } from "@/components/ui/doc-typography";
import { cn } from "@/lib/utils";
export type DocCalloutTone = "info" | "warning" | "danger" | "success";
export const DOC_CALLOUT_TONES: DocCalloutTone[] = ["info", "warning", "danger", "success"];
const TONE = {
info: { box: "bg-info text-info-middle", icon: InformationCircleContained },
warning: { box: "bg-warning text-warning-middle", icon: AlertTriangle },
danger: { box: "bg-negative text-negative-middle", icon: CloseCircleContained },
success: { box: "bg-success text-success-middle", icon: CheckContained },
};
export interface DocCalloutProps extends Omit<DocTypographyProps, "type"> {
tone?: DocCalloutTone;
/** Clicking the icon asks for the next tone; omit to keep the tone fixed. */
onToneChange?: (tone: DocCalloutTone) => void;
}
/** A tinted note box: info, warning, danger or success. */
function DocCallout({ tone = "info", onToneChange, readOnly, className, ...props }: DocCalloutProps) {
const { box, icon: Icon } = TONE[tone];
const next = DOC_CALLOUT_TONES[(DOC_CALLOUT_TONES.indexOf(tone) + 1) % DOC_CALLOUT_TONES.length];
return (
<div className={cn("my-2 flex gap-2 rounded-md p-3", box, className)}>
<button
type="button"
aria-label={`${tone} callout`}
disabled={readOnly || !onToneChange}
className="flex h-5 shrink-0 items-center justify-center enabled:cursor-pointer pointer-coarse:-m-3 pointer-coarse:size-11"
onClick={() => onToneChange?.(next)}
>
<Icon size={20} />
</button>
<div className="min-w-0 flex-1">
<DocTypography aria-label={`Callout ${tone}`} readOnly={readOnly} className="text-inherit" {...props} />
</div>
</div>
);
}
export { DocCallout };