Result
Present an operation's outcome with a large icon, a title, and a description. Common full-page states include a successful submission, failed payment, or insufficient permissions.
Import
import { HuiResult } from '@nscode/handy-ui'
Basic Usage
status selects the icon and its color. title and subtitle provide the heading and description.
<script setup lang="ts">
import { HuiResult } from '@nscode/handy-ui'
</script>
<template>
<HuiResult
status="success"
title="Operation successful"
subtitle="Your request has been processed. Continue to the next step."
/>
</template>
Four Statuses
status accepts success, error, warning, or info and defaults to info. Their icons use the success, danger, warning, and information theme colors respectively.
<template>
<div class="grid">
<HuiResult status="success" title="Success (success)" subtitle="The operation is complete" />
<HuiResult status="error" title="Error (error)" subtitle="The operation failed" />
<HuiResult status="warning" title="Warning (warning)" subtitle="Please review the risks" />
<HuiResult status="info" title="Information (info)" subtitle="An informational message" />
</div>
</template>
<style scoped>
.grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
gap: var(--hui-spacing-4);
}
</style>
Omitting status is equivalent to info:
<template>
<HuiResult title="No status specified" subtitle="Uses the information icon and color" />
</template>
Actions
The extra slot appears below the description, usually with a back or retry button.
<script setup lang="ts">
import { HuiButton, HuiMessage, HuiResult, HuiSpace } from '@nscode/handy-ui'
const goHome = () => {
HuiMessage('Go to the home page')
}
const viewDetail = () => {
HuiMessage('Open review progress')
}
</script>
<template>
<HuiResult
status="success"
title="Submitted successfully"
subtitle="Your submission is awaiting review. The result will be sent by email."
>
<template #extra>
<HuiSpace wrap>
<HuiButton type="primary" @click="goHome">Back to home</HuiButton>
<HuiButton @click="viewDetail">View progress</HuiButton>
</HuiSpace>
</template>
</HuiResult>
</template>
Switching Status
Update one result view from an API response, changing its title, description, and actions together. Select a status above the result:
<script setup lang="ts">
import { computed, ref } from 'vue'
import {
HuiButton,
HuiMessage,
HuiRadio,
HuiRadioGroup,
HuiResult,
HuiSpace
} from '@nscode/handy-ui'
import type { ResultStatus } from '@nscode/handy-ui'
const status = ref<ResultStatus>('success')
const contents: Record<ResultStatus, { title: string; subtitle: string; action: string }> = {
success: {
title: 'Payment successful',
subtitle: 'Payment received. Shipping is expected within 3 days.',
action: 'View order'
},
error: {
title: 'Payment failed',
subtitle: 'Insufficient card balance. Please use another payment method.',
action: 'Retry payment'
},
warning: {
title: 'Order awaiting confirmation',
subtitle: 'Some items have limited stock. Confirm whether to continue.',
action: 'Continue order'
},
info: {
title: 'Processing order',
subtitle: 'Verifying the payment. Refresh again shortly.',
action: 'Refresh'
}
}
const content = computed(() => contents[status.value])
const handleAction = () => {
HuiMessage(`Clicked “${content.value.action}”`)
}
</script>
<template>
<HuiSpace direction="vertical" fill>
<div>
<HuiRadioGroup v-model="status" type="button">
<HuiRadio value="success" label="success" />
<HuiRadio value="error" label="error" />
<HuiRadio value="warning" label="warning" />
<HuiRadio value="info" label="info" />
</HuiRadioGroup>
</div>
<HuiResult :status="status" :title="content.title" :subtitle="content.subtitle">
<template #extra>
<HuiButton type="primary" @click="handleAction">{{ content.action }}</HuiButton>
</template>
</HuiResult>
</HuiSpace>
</template>
Custom Icon
The icon slot replaces the default icon. An HuiIcon in this slot also defaults to 72px and inherits the current status color. Override it with your own style if needed.
<script setup lang="ts">
import { HuiIcon, HuiResult } from '@nscode/handy-ui'
</script>
<template>
<HuiResult title="Custom icon" subtitle="Replace the default icon with the icon slot">
<template #icon>
<HuiIcon name="star" style="color: var(--hui-color-warning)" />
</template>
</HuiResult>
</template>
The icon on the left has no explicit color and inherits the success color from status="success". The icon on the right sets its own color, independently of the status:
<template>
<div class="grid">
<HuiResult status="success" title="Color follows the status" subtitle="status is success">
<template #icon>
<HuiIcon name="mail" />
</template>
</HuiResult>
<HuiResult status="success" title="Explicit icon color" subtitle="status is success">
<template #icon>
<HuiIcon name="lock" color="var(--hui-color-help)" />
</template>
</HuiResult>
</div>
</template>
<style scoped>
.grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
gap: var(--hui-spacing-4);
}
</style>
Custom Title and Description
The title and subtitle slots accept formatted content and take precedence over the matching props.
<template>
<HuiResult status="error">
<template #title>Payment failed</template>
<template #subtitle>
Order number <strong>20261117001</strong> Payment timed out. Please place the order again.
</template>
</HuiResult>
</template>
Inside a Card
The component centers its content without adding a background or border. Place it inside a card or another styled container for a result message within a section:
<script setup lang="ts">
import { HuiButton, HuiCard, HuiResult } from '@nscode/handy-ui'
</script>
<template>
<HuiCard>
<HuiResult
status="warning"
title="Access denied"
subtitle="Contact your administrator for permission to view financial reports."
>
<template #extra>
<HuiButton type="primary">Request access</HuiButton>
</template>
</HuiResult>
</HuiCard>
</template>
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| status | 'success' | 'error' | 'warning' | 'info' | 'info' | Result status, which selects the icon and its color. |
| title | string | '' | Title. Not rendered when empty and no title slot is provided. |
| subtitle | string | '' | Description. Not rendered when empty and no subtitle slot is provided. |
Slots
| Slot | Description |
|---|---|
| icon | Custom icon replacing the default status icon. |
| title | Custom title, taking precedence over the title prop. |
| subtitle | Custom description, taking precedence over the subtitle prop. |
| extra | Action area below the description. |
Types
import type { ResultStatus, ResultProps } from '@nscode/handy-ui'
type ResultStatus = 'success' | 'error' | 'warning' | 'info'
interface ResultProps {
status?: ResultStatus
title?: string
subtitle?: string
}