Approval Card
Questions
ApprovalCard.vueHow focused should the first release be?How focused should the first release be?
1/3<script setup lang="ts">
import { ApprovalCard, type ApprovalAnswers, type ApprovalCardStatus, type ApprovalQuestion } from 'beui-vue'
import { computed, onBeforeUnmount, shallowRef, watch, onMounted, ref } from 'vue'
function useAgentVariant(selected: () => string | undefined, choices: Record<string,string>) {
const pinned = undefined as string | undefined
const fixed = Boolean(pinned)
const query = ref('')
const options = Object.keys(choices)
const variant = computed(() => {
const requested = pinned || selected() || query.value
return options.find(slug => requested === slug || requested === choices[slug]) ?? options[0]
})
function refresh() {
query.value = new URL(location.href).searchParams.get('variant') ?? ''
}
function choose(slug:string) {
if (fixed || !options.includes(slug)) return
const url = new URL(location.href)
url.searchParams.set('variant',slug)
history.replaceState(history.state,'',url)
refresh()
}
onMounted(() => {
if (fixed) return
refresh()
window.addEventListener('popstate',refresh)
})
onBeforeUnmount(() => window.removeEventListener('popstate',refresh))
return { variant, choose, options, fixed }
}
const props = defineProps<{ variant?: string }>()
const { variant, choose, options, fixed } = useAgentVariant(() => props.variant, {
questions: 'agents/approval-card-question', review: 'agents/approval-card-review',
})
const QUESTIONS: ApprovalQuestion[] = [
{
id: 'scope',
title: 'How focused should the first release be?',
options: [
{ value: 'focused', label: 'A focused starter set', description: 'Ship a few polished pieces first.' },
{ value: 'broad', label: 'A broader collection', description: 'Cover more ground with lighter depth.' },
{ value: 'flagship', label: 'One flagship experience', description: 'Pour everything into a single showcase.' },
],
allowCustom: true,
customPlaceholder: 'Describe another scope…',
},
{
id: 'checks',
title: 'Which checks should block publishing?',
description: 'Select every check the agent must pass before it can continue.',
multiple: true,
options: [{ value: 'types', label: 'Type safety' }, { value: 'accessibility', label: 'Accessibility' }, { value: 'registry', label: 'Registry validation' }],
},
{ id: 'preserve', title: 'Anything the agent should preserve?', allowCustom: true, customPlaceholder: 'Add a final constraint…' },
]
const run = shallowRef(0)
const status = shallowRef<ApprovalCardStatus>('pending')
let timer: ReturnType<typeof setTimeout> | undefined
const isQuestions = computed(() => variant.value === 'questions')
function submit(_answers: ApprovalAnswers) {
status.value = 'submitting'
timer = setTimeout(() => { status.value = 'answered' }, 750)
}
function finish(next: ApprovalCardStatus) {
status.value = 'submitting'
timer = setTimeout(() => { status.value = next }, 700)
}
function replay() { clearTimeout(timer); status.value = 'pending'; run.value += 1 }
const reviewResult = computed(() => status.value === 'approved' ? 'Publishing was approved.' : status.value === 'changes-requested' ? 'The agent will wait for revision notes.' : 'Publishing was declined.')
watch(variant, replay)
onBeforeUnmount(() => clearTimeout(timer))
</script>
<template>
<div class="demo" :class="{ review: !isQuestions }" :data-example-variant="variant">
<ApprovalCard v-if="isQuestions" :key="`q-${run}`" :questions="QUESTIONS" :status="status" result="Three responses sent to the agent." @submit="submit" />
<ApprovalCard v-else :key="`r-${run}`" title="Publish the component update?" description="The agent has prepared the release and is waiting for your decision." :status="status" :result="reviewResult" @approve="finish('approved')" @request-changes="finish('changes-requested')" @reject="finish('rejected')">
<dl class="facts">
<div class="fact"><dt>Release</dt><dd class="mono">approval-card</dd></div>
<div class="fact"><dt>Checks</dt><dd>4 passed</dd></div>
<div class="fact"><dt>Visibility</dt><dd>Public registry</dd></div>
</dl>
</ApprovalCard>
<button type="button" class="replay" @click="replay"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8" /><path d="M3 3v5h5" /></svg>Replay</button>
<label v-if="!fixed" class="variant">Example <select :value="variant" @change="choose(($event.target as HTMLSelectElement).value)"><option v-for="option in options" :key="option">{{ option }}</option></select></label>
</div>
</template>
<style scoped>
.demo { position: relative; width: 100%; max-width: 32rem; height: 470px; }
.demo.review { height: 360px; }
.facts { display: grid; gap: 0.25rem; margin: 0; font-size: 0.75rem; line-height: 1rem; }
.fact { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.25rem 0; }
.fact dt { margin: 0; color: var(--beui-muted-foreground); }
.fact dd { margin: 0; color: color-mix(in srgb, var(--beui-foreground) 80%, transparent); }
.fact dd.mono { font-family: var(--font-mono, ui-monospace, monospace); }
.replay { position: absolute; bottom: 0; left: 0; display: inline-flex; align-items: center; gap: 0.375rem; padding: 0.25rem 0.5rem; border: 0; border-radius: 9999px; background: transparent; color: var(--beui-muted-foreground); font: inherit; font-size: 0.75rem; line-height: 1rem; font-weight: 500; cursor: pointer; outline: none; transition: color 0.15s, background-color 0.15s; }
.replay:hover { background: var(--beui-muted); color: var(--beui-foreground); }
.replay:focus-visible { box-shadow: 0 0 0 2px var(--beui-ring); }
.variant { position: absolute; right: 0; bottom: 0; display: inline-flex; align-items: center; gap: 0.375rem; color: var(--beui-muted-foreground); font-size: 0.75rem; }
.variant select { padding: 0.125rem 0.25rem; border: 1px solid var(--beui-border); border-radius: 0.375rem; background: var(--beui-background); color: var(--beui-foreground); font: inherit; }
</style><script lang="ts">
export const approvalCardMessages = {
title: 'Approval required', approve: 'Approve', submit: 'Submit response', requestChanges: 'Request changes', reject: 'Reject', dismiss: 'Dismiss',
previousQuestion: 'Previous question', nextQuestion: 'Next question', customPlaceholder: 'Add another response…',
questionProgress: 'Question {current} of {total}', stepCount: '{current}/{total}',
inputRequired: 'Input required', submitting: 'Submitting', approved: 'Approved', rejected: 'Rejected', changesRequested: 'Changes requested', answered: 'Response submitted',
}
export type ApprovalCardStatus = 'pending' | 'submitting' | 'approved' | 'rejected' | 'changes-requested' | 'answered'
</script>
<script setup lang="ts">
import { AnimatePresence, motion } from 'motion-v'
import { useReducedMotion } from '../core/reduced-motion'
import { computed, onBeforeUnmount, useId } from 'vue'
import ButtonBase from '../ButtonBase.vue'
import { easeOut, swapSpring } from '../core/motion'
import AgentIcon from './AgentIcon.vue'
import AgentReveal from './AgentReveal.vue'
import AgentRollText from './AgentRollText.vue'
import ApprovalChoice from './ApprovalChoice.vue'
import './agent-tokens.css'
import { useHasListener, useValue, type Labels, type Option } from './shared'
export type ApprovalAnswer = { selected: string[], custom?: string }
export type ApprovalAnswers = Record<string, ApprovalAnswer>
export type ApprovalQuestion = { id: string, title: string, description?: string, options?: Option[], multiple?: boolean, autoAdvance?: boolean, allowCustom?: boolean, customPlaceholder?: string }
const props = withDefaults(defineProps<{
title?: string, description?: string, questions?: ApprovalQuestion[], answers?: ApprovalAnswers, defaultAnswers?: ApprovalAnswers, step?: number, defaultStep?: number,
status?: ApprovalCardStatus, approveLabel?: string, submitLabel?: string, result?: string,
labels?: Labels
}>(), { questions: () => [], defaultAnswers: () => ({}), defaultStep: 0, status: 'pending' })
const emit = defineEmits<{ 'update:answers': [value: ApprovalAnswers], answersChange: [value: ApprovalAnswers], 'update:step': [value: number], stepChange: [value: number], submit: [value: ApprovalAnswers], approve: [], reject: [], requestChanges: [], dismiss: [] }>()
defineSlots<{ default?(): unknown, title?(): unknown, description?(): unknown, approveLabel?(): unknown, submitLabel?(): unknown, result?(): unknown }>()
const reduce = useReducedMotion()
const uid = useId()
// Optional actions only show when a listener is bound, like upstream's optional callback props.
const hasReject = useHasListener('reject')
const hasRequestChanges = useHasListener('requestChanges')
const hasDismiss = useHasListener('dismiss')
const { value: answers, set: setAnswers } = useValue<ApprovalAnswers>(() => props.answers, props.defaultAnswers, value => { emit('update:answers', value); emit('answersChange', value) })
const steps = useValue(() => props.step, props.defaultStep, value => { emit('update:step', value); emit('stepChange', value) })
const t = (key: keyof typeof approvalCardMessages, values?: Record<string, string | number>) => (props.labels?.[key] ?? approvalCardMessages[key]).replace(/\{(\w+)\}/g, (_, name: string) => String(values?.[name] ?? ''))
const questionMode = computed(() => props.questions.length > 0)
const multipleQuestions = computed(() => props.questions.length > 1)
const step = computed(() => Math.min(Math.max(0, steps.value.value), Math.max(0, props.questions.length - 1)))
const question = computed(() => props.questions[step.value])
const last = computed(() => step.value === props.questions.length - 1)
const pending = computed(() => props.status === 'pending')
const busy = computed(() => props.status === 'submitting')
const interactive = computed(() => pending.value || busy.value)
const EMPTY: ApprovalAnswer = { selected: [], custom: '' }
const answer = computed(() => (question.value ? answers.value[question.value.id] : undefined) ?? EMPTY)
const ready = computed(() => answer.value.selected.length > 0 || Boolean(answer.value.custom?.trim()))
const displayTitle = computed(() => question.value?.title ?? props.title ?? t('title'))
const titleKey = computed(() => question.value?.id ?? props.status)
const statusKey = { pending: 'inputRequired', submitting: 'submitting', approved: 'approved', rejected: 'rejected', 'changes-requested': 'changesRequested', answered: 'answered' } as const
const statusLabel = computed(() => t(statusKey[props.status]))
const tone = computed(() => props.status === 'pending' || props.status === 'changes-requested' ? 'amber' : props.status === 'submitting' ? 'blue' : props.status === 'approved' || props.status === 'answered' ? 'green' : 'rose')
const iconTone = computed(() => props.status === 'approved' || props.status === 'answered' ? 'green' : props.status === 'rejected' ? 'rose' : props.status === 'changes-requested' ? 'amber' : 'muted')
const icon = computed(() => busy.value ? 'LoaderCircle' : interactive.value ? (questionMode.value ? 'CircleHelp' : 'MessageSquareText') : props.status === 'rejected' ? 'X' : 'Check')
let autoAdvance: ReturnType<typeof setTimeout> | undefined
function clearAutoAdvance() { clearTimeout(autoAdvance); autoAdvance = undefined }
onBeforeUnmount(clearAutoAdvance)
function goTo(next: number) { clearAutoAdvance(); steps.set(next) }
function update(next: ApprovalAnswer) {
if (question.value) setAnswers({ ...answers.value, [question.value.id]: next })
}
function proceed() {
if (!last.value) goTo(step.value + 1)
else emit('submit', answers.value)
}
function queueAutoAdvance() {
const current = question.value
if (!current || current.multiple || current.autoAdvance === false || last.value || busy.value) return
clearAutoAdvance()
autoAdvance = setTimeout(() => goTo(step.value + 1), 240)
}
function toggle(option: Option, checked: boolean) {
update({ ...answer.value, selected: checked ? [...answer.value.selected, option.value] : answer.value.selected.filter(value => value !== option.value) })
}
function choose(value: string | undefined) {
if (value === undefined) return
update({ selected: [value], custom: '' })
queueAutoAdvance()
}
const progressDots = computed(() => props.questions.map((item, index) => ({ id: item.id, index })))
const dotState = (index: number) => ({ scale: reduce.value || index === step.value ? 1 : 0.75, opacity: index <= step.value ? 1 : 0.35 })
</script>
<template>
<div class="be-ag be-ac" :data-state="status" :aria-busy="busy">
<div class="be-ac-row">
<span aria-hidden="true" class="be-ac-icon" :data-tone="iconTone"><AgentIcon :name="icon" :size="16" :class="{ 'be-ag-spin': busy && !reduce }" /></span>
<div class="be-ac-main">
<div class="be-ac-head">
<h3 class="be-ac-title"><AgentRollText :value="titleKey"><slot name="title">{{ displayTitle }}</slot></AgentRollText></h3>
<template v-if="questionMode && interactive"><span v-if="multipleQuestions" class="be-ac-step">{{ t('stepCount', { current: step + 1, total: questions.length }) }}</span></template>
<span v-else class="be-ac-badge" :data-tone="tone">{{ statusLabel }}</span>
<button v-if="hasDismiss()" type="button" class="be-ac-dismiss" :aria-label="t('dismiss')" @click="emit('dismiss')"><AgentIcon name="X" :size="16" /></button>
</div>
<AgentReveal :open="interactive">
<AnimatePresence v-if="questionMode && question" :initial="false" mode="wait">
<motion.div :key="question.id" :initial="reduce ? { opacity: 1 } : { opacity: 0, x: 8 }" :animate="{ opacity: 1, x: 0 }" :exit="reduce ? { opacity: 0 } : { opacity: 0, x: -6 }" :transition="{ duration: reduce ? 0 : 0.2, ease: easeOut }">
<p v-if="question.description" class="be-ac-desc">{{ question.description }}</p>
<div class="be-ac-options">
<template v-if="question.options?.length">
<div v-if="question.multiple" class="be-ac-list"><ApprovalChoice v-for="option in question.options" :key="option.value" type="checkbox" :group="`${uid}-${question.id}`" :checked="answer.selected.includes(option.value)" :disabled="busy || option.disabled" :label="option.label" :description="option.description" @change="toggle(option, $event)" /></div>
<div v-else role="radiogroup" :aria-label="displayTitle" class="be-ac-list"><ApprovalChoice v-for="option in question.options" :key="option.value" type="radio" :group="`${uid}-${question.id}`" :name="`${uid}-${question.id}`" :value="option.value" :checked="answer.selected[0] === option.value" :disabled="busy || option.disabled" :label="option.label" :description="option.description" @change="choose(option.value)" /></div>
</template>
<div v-if="question.allowCustom" class="be-ac-custom" :class="{ 'be-ac-custom-gap': question.options?.length }"><div class="be-ac-field"><input class="be-ac-input" type="text" :value="answer.custom ?? ''" :disabled="busy" :placeholder="question.customPlaceholder ?? t('customPlaceholder')" :aria-label="question.customPlaceholder ?? t('customPlaceholder')" @input="update({ selected: question.multiple ? answer.selected : [], custom: ($event.target as HTMLInputElement).value })" /></div></div>
</div>
</motion.div>
</AnimatePresence>
<div v-else>
<p v-if="description || $slots.description" class="be-ac-desc"><slot name="description">{{ description }}</slot></p>
<div v-if="$slots.default" class="be-ac-children"><slot /></div>
</div>
<div v-if="questionMode" class="be-ac-footer">
<template v-if="multipleQuestions">
<ButtonBase variant="ghost" size="icon" class="be-ac-round" :aria-label="t('previousQuestion')" :disabled="busy || step === 0" @click="goTo(step - 1)"><AgentIcon name="ArrowLeft" :size="16" /></ButtonBase>
<span class="be-ac-dots"><span class="be-ag-sr">{{ t('questionProgress', { current: step + 1, total: questions.length }) }}</span><motion.span v-for="dot in progressDots" :key="dot.id" aria-hidden="true" class="be-ac-dot" :initial="dotState(dot.index)" :animate="dotState(dot.index)" :transition="swapSpring" /></span>
</template>
<ButtonBase :size="last ? 'sm' : 'icon'" class="be-ac-round be-ac-next" :aria-label="last ? t('submit') : t('nextQuestion')" :disabled="busy || !ready" @click="proceed">
<AgentIcon v-if="busy" name="LoaderCircle" :size="16" :class="{ 'be-ag-spin': !reduce }" />
<template v-else-if="last"><slot name="submitLabel">{{ submitLabel ?? t('submit') }}</slot><AgentIcon name="ArrowRight" :size="14" /></template>
<AgentIcon v-else name="ArrowRight" :size="16" />
</ButtonBase>
</div>
<div v-else class="be-ac-actions">
<ButtonBase size="sm" class="be-ac-round" :disabled="busy" @click="emit('approve')"><slot name="approveLabel">{{ approveLabel ?? t('approve') }}</slot></ButtonBase>
<ButtonBase v-if="hasRequestChanges()" variant="secondary" size="sm" class="be-ac-round" :disabled="busy" @click="emit('requestChanges')">{{ t('requestChanges') }}</ButtonBase>
<ButtonBase v-if="hasReject()" variant="ghost" size="sm" class="be-ac-round be-ac-reject" :disabled="busy" @click="emit('reject')">{{ t('reject') }}</ButtonBase>
</div>
</AgentReveal>
<p v-if="!interactive" class="be-ac-result"><slot name="result">{{ result ?? statusLabel }}</slot></p>
</div>
</div>
</div>
</template>
<style scoped>
.be-ac { box-sizing: border-box; width: 100%; overflow: hidden; border-radius: 1rem; background: var(--beui-muted); padding: 1rem; font-size: 0.875rem; line-height: 1.25rem; color: var(--beui-foreground); }
.be-ac-row { display: flex; align-items: flex-start; gap: 0.75rem; }
.be-ac-icon { display: grid; flex: none; width: 1.25rem; height: 1.25rem; place-items: center; color: var(--beui-muted-foreground); }
.be-ac-icon[data-tone=green] { color: var(--ag-green); }
.be-ac-icon[data-tone=rose] { color: var(--ag-rose); }
.be-ac-icon[data-tone=amber] { color: var(--ag-amber); }
.be-ac-main { min-width: 0; flex: 1; }
.be-ac-head { display: flex; min-width: 0; align-items: flex-start; gap: 0.75rem; }
.be-ac-title { min-width: 0; flex: 1; margin: 0; padding: 0; border: 0; letter-spacing: normal; font-size: 1rem; line-height: 1.25rem; font-weight: 500; color: var(--beui-foreground); }
.be-ac-step { flex: none; font-size: 0.75rem; line-height: 1rem; font-variant-numeric: tabular-nums; color: color-mix(in srgb, var(--beui-muted-foreground) 65%, transparent); }
.be-ac-badge { flex: none; border: 1px solid; border-radius: 9999px; padding: 0.125rem 0.5rem; font-size: 11px; line-height: calc(1.25 / .875); font-weight: 500; transition: color 0.15s, background-color 0.15s, border-color 0.15s; }
.be-ac-badge[data-tone=amber] { border-color: color-mix(in srgb, var(--ag-amber-500) 30%, transparent); background: color-mix(in srgb, var(--ag-amber-500) 10%, transparent); color: var(--ag-amber); }
.be-ac-badge[data-tone=blue] { border-color: color-mix(in srgb, var(--ag-blue-500) 30%, transparent); background: color-mix(in srgb, var(--ag-blue-500) 10%, transparent); color: var(--ag-blue); }
.be-ac-badge[data-tone=green] { border-color: color-mix(in srgb, var(--ag-green-500) 30%, transparent); background: color-mix(in srgb, var(--ag-green-500) 10%, transparent); color: var(--ag-green); }
.be-ac-badge[data-tone=rose] { border-color: color-mix(in srgb, var(--ag-rose-500) 30%, transparent); background: color-mix(in srgb, var(--ag-rose-500) 10%, transparent); color: var(--ag-rose); }
.be-ac-dismiss { display: grid; flex: none; width: 1.25rem; height: 1.25rem; place-items: center; padding: 0; border: 0; border-radius: 9999px; background: transparent; color: var(--beui-muted-foreground); cursor: pointer; outline: none; transition: color 0.15s; }
.be-ac-dismiss:hover { color: var(--beui-foreground); }
.be-ac-dismiss:focus-visible { box-shadow: 0 0 0 2px var(--beui-ring); }
.be-ac-desc { margin: 0.25rem 0 0; line-height: 1.25rem; color: var(--beui-muted-foreground); }
.be-ac-children { margin-top: 0.75rem; }
.be-ac-options { margin-top: 0.75rem; }
.be-ac-list { display: grid; gap: 0.125rem; }
.be-ac-custom { padding: 0.125rem; }
.be-ac-custom-gap { margin-top: 0.375rem; }
.be-ac-field { position: relative; box-sizing: border-box; height: 2.5rem; overflow: hidden; border-radius: 0.75rem; background: color-mix(in srgb, var(--beui-background) 70%, transparent); transition: background-color 0.2s, box-shadow 0.2s; }
.be-ac-field:focus-within { background: var(--beui-background); box-shadow: 0 0 0 2px color-mix(in srgb, var(--beui-ring) 40%, transparent); }
.be-ac-field:has(:disabled) { opacity: 0.6; }
.be-ac-input { box-sizing: border-box; width: 100%; height: 100%; padding: 0 0.75rem; border: 0; background: transparent; color: var(--beui-foreground); caret-color: var(--beui-foreground); font: inherit; font-size: 0.875rem; line-height: 1.5rem; outline: none; }
.be-ac-input::placeholder { color: color-mix(in srgb, var(--beui-muted-foreground) 60%, transparent); }
.be-ac-input:disabled { cursor: not-allowed; }
.be-ac-footer { display: flex; align-items: center; gap: 0.75rem; margin-top: 1rem; }
.be-ac-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-top: 1rem; }
.be-ac-dots { display: flex; gap: 0.375rem; }
.be-ac-dot { width: 0.375rem; height: 0.375rem; border-radius: 9999px; background: var(--beui-foreground); }
.be-ac-next { margin-inline-start: auto; }
.be-ac :deep(.be-button.be-ac-round) { border-radius: 9999px; }
.be-ac :deep(.be-button.be-ac-reject:hover) { color: var(--ag-rose); }
.be-ac-result { margin: 0.25rem 0 0; font-size: 0.875rem; line-height: 1.25rem; color: var(--beui-muted-foreground); }
</style>Review and Approve
ApprovalCard.vuePublish the component update?Publish the component update?
Input requiredThe agent has prepared the release and is waiting for your decision.
- Release
- approval-card
- Checks
- 4 passed
- Visibility
- Public registry
<script setup lang="ts">
import { ApprovalCard, type ApprovalAnswers, type ApprovalCardStatus, type ApprovalQuestion } from 'beui-vue'
import { computed, onBeforeUnmount, shallowRef, watch, onMounted, ref } from 'vue'
function useAgentVariant(selected: () => string | undefined, choices: Record<string,string>) {
const pinned = undefined as string | undefined
const fixed = Boolean(pinned)
const query = ref('')
const options = Object.keys(choices)
const variant = computed(() => {
const requested = pinned || selected() || query.value
return options.find(slug => requested === slug || requested === choices[slug]) ?? options[0]
})
function refresh() {
query.value = new URL(location.href).searchParams.get('variant') ?? ''
}
function choose(slug:string) {
if (fixed || !options.includes(slug)) return
const url = new URL(location.href)
url.searchParams.set('variant',slug)
history.replaceState(history.state,'',url)
refresh()
}
onMounted(() => {
if (fixed) return
refresh()
window.addEventListener('popstate',refresh)
})
onBeforeUnmount(() => window.removeEventListener('popstate',refresh))
return { variant, choose, options, fixed }
}
const props = defineProps<{ variant?: string }>()
const { variant, choose, options, fixed } = useAgentVariant(() => props.variant, {
questions: 'agents/approval-card-question', review: 'agents/approval-card-review',
})
const QUESTIONS: ApprovalQuestion[] = [
{
id: 'scope',
title: 'How focused should the first release be?',
options: [
{ value: 'focused', label: 'A focused starter set', description: 'Ship a few polished pieces first.' },
{ value: 'broad', label: 'A broader collection', description: 'Cover more ground with lighter depth.' },
{ value: 'flagship', label: 'One flagship experience', description: 'Pour everything into a single showcase.' },
],
allowCustom: true,
customPlaceholder: 'Describe another scope…',
},
{
id: 'checks',
title: 'Which checks should block publishing?',
description: 'Select every check the agent must pass before it can continue.',
multiple: true,
options: [{ value: 'types', label: 'Type safety' }, { value: 'accessibility', label: 'Accessibility' }, { value: 'registry', label: 'Registry validation' }],
},
{ id: 'preserve', title: 'Anything the agent should preserve?', allowCustom: true, customPlaceholder: 'Add a final constraint…' },
]
const run = shallowRef(0)
const status = shallowRef<ApprovalCardStatus>('pending')
let timer: ReturnType<typeof setTimeout> | undefined
const isQuestions = computed(() => variant.value === 'questions')
function submit(_answers: ApprovalAnswers) {
status.value = 'submitting'
timer = setTimeout(() => { status.value = 'answered' }, 750)
}
function finish(next: ApprovalCardStatus) {
status.value = 'submitting'
timer = setTimeout(() => { status.value = next }, 700)
}
function replay() { clearTimeout(timer); status.value = 'pending'; run.value += 1 }
const reviewResult = computed(() => status.value === 'approved' ? 'Publishing was approved.' : status.value === 'changes-requested' ? 'The agent will wait for revision notes.' : 'Publishing was declined.')
watch(variant, replay)
onBeforeUnmount(() => clearTimeout(timer))
</script>
<template>
<div class="demo" :class="{ review: !isQuestions }" :data-example-variant="variant">
<ApprovalCard v-if="isQuestions" :key="`q-${run}`" :questions="QUESTIONS" :status="status" result="Three responses sent to the agent." @submit="submit" />
<ApprovalCard v-else :key="`r-${run}`" title="Publish the component update?" description="The agent has prepared the release and is waiting for your decision." :status="status" :result="reviewResult" @approve="finish('approved')" @request-changes="finish('changes-requested')" @reject="finish('rejected')">
<dl class="facts">
<div class="fact"><dt>Release</dt><dd class="mono">approval-card</dd></div>
<div class="fact"><dt>Checks</dt><dd>4 passed</dd></div>
<div class="fact"><dt>Visibility</dt><dd>Public registry</dd></div>
</dl>
</ApprovalCard>
<button type="button" class="replay" @click="replay"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8" /><path d="M3 3v5h5" /></svg>Replay</button>
<label v-if="!fixed" class="variant">Example <select :value="variant" @change="choose(($event.target as HTMLSelectElement).value)"><option v-for="option in options" :key="option">{{ option }}</option></select></label>
</div>
</template>
<style scoped>
.demo { position: relative; width: 100%; max-width: 32rem; height: 470px; }
.demo.review { height: 360px; }
.facts { display: grid; gap: 0.25rem; margin: 0; font-size: 0.75rem; line-height: 1rem; }
.fact { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.25rem 0; }
.fact dt { margin: 0; color: var(--beui-muted-foreground); }
.fact dd { margin: 0; color: color-mix(in srgb, var(--beui-foreground) 80%, transparent); }
.fact dd.mono { font-family: var(--font-mono, ui-monospace, monospace); }
.replay { position: absolute; bottom: 0; left: 0; display: inline-flex; align-items: center; gap: 0.375rem; padding: 0.25rem 0.5rem; border: 0; border-radius: 9999px; background: transparent; color: var(--beui-muted-foreground); font: inherit; font-size: 0.75rem; line-height: 1rem; font-weight: 500; cursor: pointer; outline: none; transition: color 0.15s, background-color 0.15s; }
.replay:hover { background: var(--beui-muted); color: var(--beui-foreground); }
.replay:focus-visible { box-shadow: 0 0 0 2px var(--beui-ring); }
.variant { position: absolute; right: 0; bottom: 0; display: inline-flex; align-items: center; gap: 0.375rem; color: var(--beui-muted-foreground); font-size: 0.75rem; }
.variant select { padding: 0.125rem 0.25rem; border: 1px solid var(--beui-border); border-radius: 0.375rem; background: var(--beui-background); color: var(--beui-foreground); font: inherit; }
</style><script lang="ts">
export const approvalCardMessages = {
title: 'Approval required', approve: 'Approve', submit: 'Submit response', requestChanges: 'Request changes', reject: 'Reject', dismiss: 'Dismiss',
previousQuestion: 'Previous question', nextQuestion: 'Next question', customPlaceholder: 'Add another response…',
questionProgress: 'Question {current} of {total}', stepCount: '{current}/{total}',
inputRequired: 'Input required', submitting: 'Submitting', approved: 'Approved', rejected: 'Rejected', changesRequested: 'Changes requested', answered: 'Response submitted',
}
export type ApprovalCardStatus = 'pending' | 'submitting' | 'approved' | 'rejected' | 'changes-requested' | 'answered'
</script>
<script setup lang="ts">
import { AnimatePresence, motion } from 'motion-v'
import { useReducedMotion } from '../core/reduced-motion'
import { computed, onBeforeUnmount, useId } from 'vue'
import ButtonBase from '../ButtonBase.vue'
import { easeOut, swapSpring } from '../core/motion'
import AgentIcon from './AgentIcon.vue'
import AgentReveal from './AgentReveal.vue'
import AgentRollText from './AgentRollText.vue'
import ApprovalChoice from './ApprovalChoice.vue'
import './agent-tokens.css'
import { useHasListener, useValue, type Labels, type Option } from './shared'
export type ApprovalAnswer = { selected: string[], custom?: string }
export type ApprovalAnswers = Record<string, ApprovalAnswer>
export type ApprovalQuestion = { id: string, title: string, description?: string, options?: Option[], multiple?: boolean, autoAdvance?: boolean, allowCustom?: boolean, customPlaceholder?: string }
const props = withDefaults(defineProps<{
title?: string, description?: string, questions?: ApprovalQuestion[], answers?: ApprovalAnswers, defaultAnswers?: ApprovalAnswers, step?: number, defaultStep?: number,
status?: ApprovalCardStatus, approveLabel?: string, submitLabel?: string, result?: string,
labels?: Labels
}>(), { questions: () => [], defaultAnswers: () => ({}), defaultStep: 0, status: 'pending' })
const emit = defineEmits<{ 'update:answers': [value: ApprovalAnswers], answersChange: [value: ApprovalAnswers], 'update:step': [value: number], stepChange: [value: number], submit: [value: ApprovalAnswers], approve: [], reject: [], requestChanges: [], dismiss: [] }>()
defineSlots<{ default?(): unknown, title?(): unknown, description?(): unknown, approveLabel?(): unknown, submitLabel?(): unknown, result?(): unknown }>()
const reduce = useReducedMotion()
const uid = useId()
// Optional actions only show when a listener is bound, like upstream's optional callback props.
const hasReject = useHasListener('reject')
const hasRequestChanges = useHasListener('requestChanges')
const hasDismiss = useHasListener('dismiss')
const { value: answers, set: setAnswers } = useValue<ApprovalAnswers>(() => props.answers, props.defaultAnswers, value => { emit('update:answers', value); emit('answersChange', value) })
const steps = useValue(() => props.step, props.defaultStep, value => { emit('update:step', value); emit('stepChange', value) })
const t = (key: keyof typeof approvalCardMessages, values?: Record<string, string | number>) => (props.labels?.[key] ?? approvalCardMessages[key]).replace(/\{(\w+)\}/g, (_, name: string) => String(values?.[name] ?? ''))
const questionMode = computed(() => props.questions.length > 0)
const multipleQuestions = computed(() => props.questions.length > 1)
const step = computed(() => Math.min(Math.max(0, steps.value.value), Math.max(0, props.questions.length - 1)))
const question = computed(() => props.questions[step.value])
const last = computed(() => step.value === props.questions.length - 1)
const pending = computed(() => props.status === 'pending')
const busy = computed(() => props.status === 'submitting')
const interactive = computed(() => pending.value || busy.value)
const EMPTY: ApprovalAnswer = { selected: [], custom: '' }
const answer = computed(() => (question.value ? answers.value[question.value.id] : undefined) ?? EMPTY)
const ready = computed(() => answer.value.selected.length > 0 || Boolean(answer.value.custom?.trim()))
const displayTitle = computed(() => question.value?.title ?? props.title ?? t('title'))
const titleKey = computed(() => question.value?.id ?? props.status)
const statusKey = { pending: 'inputRequired', submitting: 'submitting', approved: 'approved', rejected: 'rejected', 'changes-requested': 'changesRequested', answered: 'answered' } as const
const statusLabel = computed(() => t(statusKey[props.status]))
const tone = computed(() => props.status === 'pending' || props.status === 'changes-requested' ? 'amber' : props.status === 'submitting' ? 'blue' : props.status === 'approved' || props.status === 'answered' ? 'green' : 'rose')
const iconTone = computed(() => props.status === 'approved' || props.status === 'answered' ? 'green' : props.status === 'rejected' ? 'rose' : props.status === 'changes-requested' ? 'amber' : 'muted')
const icon = computed(() => busy.value ? 'LoaderCircle' : interactive.value ? (questionMode.value ? 'CircleHelp' : 'MessageSquareText') : props.status === 'rejected' ? 'X' : 'Check')
let autoAdvance: ReturnType<typeof setTimeout> | undefined
function clearAutoAdvance() { clearTimeout(autoAdvance); autoAdvance = undefined }
onBeforeUnmount(clearAutoAdvance)
function goTo(next: number) { clearAutoAdvance(); steps.set(next) }
function update(next: ApprovalAnswer) {
if (question.value) setAnswers({ ...answers.value, [question.value.id]: next })
}
function proceed() {
if (!last.value) goTo(step.value + 1)
else emit('submit', answers.value)
}
function queueAutoAdvance() {
const current = question.value
if (!current || current.multiple || current.autoAdvance === false || last.value || busy.value) return
clearAutoAdvance()
autoAdvance = setTimeout(() => goTo(step.value + 1), 240)
}
function toggle(option: Option, checked: boolean) {
update({ ...answer.value, selected: checked ? [...answer.value.selected, option.value] : answer.value.selected.filter(value => value !== option.value) })
}
function choose(value: string | undefined) {
if (value === undefined) return
update({ selected: [value], custom: '' })
queueAutoAdvance()
}
const progressDots = computed(() => props.questions.map((item, index) => ({ id: item.id, index })))
const dotState = (index: number) => ({ scale: reduce.value || index === step.value ? 1 : 0.75, opacity: index <= step.value ? 1 : 0.35 })
</script>
<template>
<div class="be-ag be-ac" :data-state="status" :aria-busy="busy">
<div class="be-ac-row">
<span aria-hidden="true" class="be-ac-icon" :data-tone="iconTone"><AgentIcon :name="icon" :size="16" :class="{ 'be-ag-spin': busy && !reduce }" /></span>
<div class="be-ac-main">
<div class="be-ac-head">
<h3 class="be-ac-title"><AgentRollText :value="titleKey"><slot name="title">{{ displayTitle }}</slot></AgentRollText></h3>
<template v-if="questionMode && interactive"><span v-if="multipleQuestions" class="be-ac-step">{{ t('stepCount', { current: step + 1, total: questions.length }) }}</span></template>
<span v-else class="be-ac-badge" :data-tone="tone">{{ statusLabel }}</span>
<button v-if="hasDismiss()" type="button" class="be-ac-dismiss" :aria-label="t('dismiss')" @click="emit('dismiss')"><AgentIcon name="X" :size="16" /></button>
</div>
<AgentReveal :open="interactive">
<AnimatePresence v-if="questionMode && question" :initial="false" mode="wait">
<motion.div :key="question.id" :initial="reduce ? { opacity: 1 } : { opacity: 0, x: 8 }" :animate="{ opacity: 1, x: 0 }" :exit="reduce ? { opacity: 0 } : { opacity: 0, x: -6 }" :transition="{ duration: reduce ? 0 : 0.2, ease: easeOut }">
<p v-if="question.description" class="be-ac-desc">{{ question.description }}</p>
<div class="be-ac-options">
<template v-if="question.options?.length">
<div v-if="question.multiple" class="be-ac-list"><ApprovalChoice v-for="option in question.options" :key="option.value" type="checkbox" :group="`${uid}-${question.id}`" :checked="answer.selected.includes(option.value)" :disabled="busy || option.disabled" :label="option.label" :description="option.description" @change="toggle(option, $event)" /></div>
<div v-else role="radiogroup" :aria-label="displayTitle" class="be-ac-list"><ApprovalChoice v-for="option in question.options" :key="option.value" type="radio" :group="`${uid}-${question.id}`" :name="`${uid}-${question.id}`" :value="option.value" :checked="answer.selected[0] === option.value" :disabled="busy || option.disabled" :label="option.label" :description="option.description" @change="choose(option.value)" /></div>
</template>
<div v-if="question.allowCustom" class="be-ac-custom" :class="{ 'be-ac-custom-gap': question.options?.length }"><div class="be-ac-field"><input class="be-ac-input" type="text" :value="answer.custom ?? ''" :disabled="busy" :placeholder="question.customPlaceholder ?? t('customPlaceholder')" :aria-label="question.customPlaceholder ?? t('customPlaceholder')" @input="update({ selected: question.multiple ? answer.selected : [], custom: ($event.target as HTMLInputElement).value })" /></div></div>
</div>
</motion.div>
</AnimatePresence>
<div v-else>
<p v-if="description || $slots.description" class="be-ac-desc"><slot name="description">{{ description }}</slot></p>
<div v-if="$slots.default" class="be-ac-children"><slot /></div>
</div>
<div v-if="questionMode" class="be-ac-footer">
<template v-if="multipleQuestions">
<ButtonBase variant="ghost" size="icon" class="be-ac-round" :aria-label="t('previousQuestion')" :disabled="busy || step === 0" @click="goTo(step - 1)"><AgentIcon name="ArrowLeft" :size="16" /></ButtonBase>
<span class="be-ac-dots"><span class="be-ag-sr">{{ t('questionProgress', { current: step + 1, total: questions.length }) }}</span><motion.span v-for="dot in progressDots" :key="dot.id" aria-hidden="true" class="be-ac-dot" :initial="dotState(dot.index)" :animate="dotState(dot.index)" :transition="swapSpring" /></span>
</template>
<ButtonBase :size="last ? 'sm' : 'icon'" class="be-ac-round be-ac-next" :aria-label="last ? t('submit') : t('nextQuestion')" :disabled="busy || !ready" @click="proceed">
<AgentIcon v-if="busy" name="LoaderCircle" :size="16" :class="{ 'be-ag-spin': !reduce }" />
<template v-else-if="last"><slot name="submitLabel">{{ submitLabel ?? t('submit') }}</slot><AgentIcon name="ArrowRight" :size="14" /></template>
<AgentIcon v-else name="ArrowRight" :size="16" />
</ButtonBase>
</div>
<div v-else class="be-ac-actions">
<ButtonBase size="sm" class="be-ac-round" :disabled="busy" @click="emit('approve')"><slot name="approveLabel">{{ approveLabel ?? t('approve') }}</slot></ButtonBase>
<ButtonBase v-if="hasRequestChanges()" variant="secondary" size="sm" class="be-ac-round" :disabled="busy" @click="emit('requestChanges')">{{ t('requestChanges') }}</ButtonBase>
<ButtonBase v-if="hasReject()" variant="ghost" size="sm" class="be-ac-round be-ac-reject" :disabled="busy" @click="emit('reject')">{{ t('reject') }}</ButtonBase>
</div>
</AgentReveal>
<p v-if="!interactive" class="be-ac-result"><slot name="result">{{ result ?? statusLabel }}</slot></p>
</div>
</div>
</div>
</template>
<style scoped>
.be-ac { box-sizing: border-box; width: 100%; overflow: hidden; border-radius: 1rem; background: var(--beui-muted); padding: 1rem; font-size: 0.875rem; line-height: 1.25rem; color: var(--beui-foreground); }
.be-ac-row { display: flex; align-items: flex-start; gap: 0.75rem; }
.be-ac-icon { display: grid; flex: none; width: 1.25rem; height: 1.25rem; place-items: center; color: var(--beui-muted-foreground); }
.be-ac-icon[data-tone=green] { color: var(--ag-green); }
.be-ac-icon[data-tone=rose] { color: var(--ag-rose); }
.be-ac-icon[data-tone=amber] { color: var(--ag-amber); }
.be-ac-main { min-width: 0; flex: 1; }
.be-ac-head { display: flex; min-width: 0; align-items: flex-start; gap: 0.75rem; }
.be-ac-title { min-width: 0; flex: 1; margin: 0; padding: 0; border: 0; letter-spacing: normal; font-size: 1rem; line-height: 1.25rem; font-weight: 500; color: var(--beui-foreground); }
.be-ac-step { flex: none; font-size: 0.75rem; line-height: 1rem; font-variant-numeric: tabular-nums; color: color-mix(in srgb, var(--beui-muted-foreground) 65%, transparent); }
.be-ac-badge { flex: none; border: 1px solid; border-radius: 9999px; padding: 0.125rem 0.5rem; font-size: 11px; line-height: calc(1.25 / .875); font-weight: 500; transition: color 0.15s, background-color 0.15s, border-color 0.15s; }
.be-ac-badge[data-tone=amber] { border-color: color-mix(in srgb, var(--ag-amber-500) 30%, transparent); background: color-mix(in srgb, var(--ag-amber-500) 10%, transparent); color: var(--ag-amber); }
.be-ac-badge[data-tone=blue] { border-color: color-mix(in srgb, var(--ag-blue-500) 30%, transparent); background: color-mix(in srgb, var(--ag-blue-500) 10%, transparent); color: var(--ag-blue); }
.be-ac-badge[data-tone=green] { border-color: color-mix(in srgb, var(--ag-green-500) 30%, transparent); background: color-mix(in srgb, var(--ag-green-500) 10%, transparent); color: var(--ag-green); }
.be-ac-badge[data-tone=rose] { border-color: color-mix(in srgb, var(--ag-rose-500) 30%, transparent); background: color-mix(in srgb, var(--ag-rose-500) 10%, transparent); color: var(--ag-rose); }
.be-ac-dismiss { display: grid; flex: none; width: 1.25rem; height: 1.25rem; place-items: center; padding: 0; border: 0; border-radius: 9999px; background: transparent; color: var(--beui-muted-foreground); cursor: pointer; outline: none; transition: color 0.15s; }
.be-ac-dismiss:hover { color: var(--beui-foreground); }
.be-ac-dismiss:focus-visible { box-shadow: 0 0 0 2px var(--beui-ring); }
.be-ac-desc { margin: 0.25rem 0 0; line-height: 1.25rem; color: var(--beui-muted-foreground); }
.be-ac-children { margin-top: 0.75rem; }
.be-ac-options { margin-top: 0.75rem; }
.be-ac-list { display: grid; gap: 0.125rem; }
.be-ac-custom { padding: 0.125rem; }
.be-ac-custom-gap { margin-top: 0.375rem; }
.be-ac-field { position: relative; box-sizing: border-box; height: 2.5rem; overflow: hidden; border-radius: 0.75rem; background: color-mix(in srgb, var(--beui-background) 70%, transparent); transition: background-color 0.2s, box-shadow 0.2s; }
.be-ac-field:focus-within { background: var(--beui-background); box-shadow: 0 0 0 2px color-mix(in srgb, var(--beui-ring) 40%, transparent); }
.be-ac-field:has(:disabled) { opacity: 0.6; }
.be-ac-input { box-sizing: border-box; width: 100%; height: 100%; padding: 0 0.75rem; border: 0; background: transparent; color: var(--beui-foreground); caret-color: var(--beui-foreground); font: inherit; font-size: 0.875rem; line-height: 1.5rem; outline: none; }
.be-ac-input::placeholder { color: color-mix(in srgb, var(--beui-muted-foreground) 60%, transparent); }
.be-ac-input:disabled { cursor: not-allowed; }
.be-ac-footer { display: flex; align-items: center; gap: 0.75rem; margin-top: 1rem; }
.be-ac-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-top: 1rem; }
.be-ac-dots { display: flex; gap: 0.375rem; }
.be-ac-dot { width: 0.375rem; height: 0.375rem; border-radius: 9999px; background: var(--beui-foreground); }
.be-ac-next { margin-inline-start: auto; }
.be-ac :deep(.be-button.be-ac-round) { border-radius: 9999px; }
.be-ac :deep(.be-button.be-ac-reject:hover) { color: var(--ag-rose); }
.be-ac-result { margin: 0.25rem 0 0; font-size: 0.875rem; line-height: 1.25rem; color: var(--beui-muted-foreground); }
</style>API Reference
title?string—description?string—questions?ApprovalQuestion[][]status?ApprovalCardStatuspendingv-model:answers?ApprovalAnswers—defaultAnswers?ApprovalAnswers{}v-model:step?number—defaultStep?number0@submit?(value: ApprovalAnswers) => void—@approve?() => void—@reject?() => void—@request-changes?() => void—@dismiss?() => void—approveLabel?string—submitLabel?string—result?string—labels?LabelsOverride any built-in string.
—class?string—@answers-change?(value: ApprovalAnswers) => void—@step-change?(value: number) => void—#default?slot—#title?slot—#description?slot—#approveLabel?slot—#submitLabel?slot—#result?slot—Install
Add it with your package manager, or copy the source manually.
Run it in a project set up with shadcn-vue. The source is copied to components/beui and its dependencies are added to your package.json. Read the shadcn-vue guide
$ bunx --bun shadcn-vue@latest add @beui-vue/approval-card$ bun add beui-vueDownload the release archive to your project root, then install the local file.
$ bun add ./beui-vue-0.1.0.tgzImport the shared styles once in your application.
import ApprovalCard from '@/components/beui/agents/ApprovalCard.vue'
import '@/components/beui/styles.css'Composition
Place the approval surface inside the message that pauses the agent run.
Message
└── MessageContent
└── ApprovalCardNote: Tool Approval handles the narrower case of one tool permission. Message places the decision inside the conversation history. Todo List shows which planned work is paused by the decision.
How it works
Human-in-the-loop work is a temporary transfer of control. The card should state the decision clearly, collect only the required input, and return a durable answer to the paused agent run.
Related components
Tool Approval
A human-in-the-loop permission card for reviewing tool details, allowing once, remembering access, or denying execution.
Chat App
A complete agent conversation workspace composing navigation, messages, streaming, planning, approvals, tools, code, diffs, generated media, sources, and prompt input.
Tool Result
A lightweight execution disclosure for syntax-highlighted terminal output and request responses that collapses into a compact completed state.
Updated