Trên trang này

Trường

Ví dụ trực tiếp của Trường, kèm đúng file Vue hiển thị từng ví dụ.

Mỗi ví dụ là một file Vue hoàn chỉnh. Chép vào ứng dụng đã cài registry, hoặc mở trong StackBlitz.

Một phần của biểu mẫu

Một field set có legend, rồi các field cách nhau 16 px. Chữ hướng dẫn nằm dưới field; khi cần đọc trước lúc gõ, như chính sách đổi trả, nó nằm giữa nhãn và field, bọc cùng nhãn trong một FieldContent.

Thông tin cửa hàng
FieldStoreDetails.vue
<script setup lang="ts">
import { Button } from '@/components/ui/button'
import { Field, FieldContent, FieldDescription, FieldGroup, FieldLabel, FieldLegend, FieldSet } from '@/components/ui/field'
import { Input } from '@/components/ui/input'
import { Textarea } from '@/components/ui/textarea'
</script>

<template>
  <form class="w-full max-w-md" @submit.prevent>
    <FieldSet>
      <FieldLegend>Thông tin cửa hàng</FieldLegend>
      <FieldDescription>Khách hàng thấy các thông tin này trên hóa đơn và email đơn hàng.</FieldDescription>
      <FieldGroup>
        <Field>
          <FieldLabel for="details-name">Tên cửa hàng</FieldLabel>
          <Input id="details-name" autocomplete="organization" />
        </Field>
        <Field>
          <FieldLabel for="details-email">Email hỗ trợ</FieldLabel>
          <Input id="details-email" type="email" autocomplete="email" aria-describedby="details-email-help" />
          <FieldDescription id="details-email-help">Thư trả lời email đơn hàng sẽ về địa chỉ này.</FieldDescription>
        </Field>
        <Field>
          <FieldContent>
            <FieldLabel for="details-returns">Chính sách đổi trả</FieldLabel>
            <FieldDescription id="details-returns-help">Một hoặc hai câu. In trên phiếu đóng gói.</FieldDescription>
          </FieldContent>
          <Textarea id="details-returns" aria-describedby="details-returns-help" />
        </Field>
        <Field orientation="horizontal">
          <Button type="submit">Lưu thông tin cửa hàng</Button>
        </Field>
      </FieldGroup>
    </FieldSet>
  </form>
</template>

Checkbox có mô tả

orientation="horizontal" đặt checkbox cạnh nhãn. Ô thẳng hàng với dòng đầu của nhãn.

Gửi email cho tôi khi
FieldCheckboxes.vue
<script setup lang="ts">
import { Checkbox } from '@/components/ui/checkbox'
import { Field, FieldContent, FieldDescription, FieldGroup, FieldLabel, FieldLegend, FieldSet } from '@/components/ui/field'

const alerts = [
  { id: 'alert-failed', label: 'Một lần đồng bộ bị lỗi', description: 'Gửi ngay, kèm các đơn hàng chưa đồng bộ được.', checked: true },
  { id: 'alert-stock', label: 'Tồn kho sắp hết', description: 'Khi một sản phẩm xuống dưới mức đặt hàng lại trong ERP.', checked: true },
  { id: 'alert-new-channel', label: 'Có kênh bán hàng mới', description: 'Mỗi ngày một lần, trong bản tóm tắt buổi sáng.', checked: false },
]
</script>

<template>
  <FieldSet class="w-full max-w-md">
    <FieldLegend variant="label">Gửi email cho tôi khi</FieldLegend>
    <FieldGroup data-slot="checkbox-group">
      <Field v-for="alert in alerts" :key="alert.id" orientation="horizontal">
        <Checkbox :id="alert.id" :default-value="alert.checked" />
        <FieldContent>
          <FieldLabel :for="alert.id">{{ alert.label }}</FieldLabel>
          <FieldDescription>{{ alert.description }}</FieldDescription>
        </FieldContent>
      </Field>
    </FieldGroup>
  </FieldSet>
</template>

Thẻ lựa chọn

Một FieldLabel bao cả field tạo thành thẻ bấm được ở mọi chỗ. Thẻ được chọn dùng nền và viền đang chọn.

Đồng bộ đơn hàng
FieldChoiceCards.vue
<script setup lang="ts">
import { ref } from 'vue'
import { Field, FieldContent, FieldDescription, FieldLabel, FieldLegend, FieldSet, FieldTitle } from '@/components/ui/field'
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'

// FieldLabel bọc cả một Field thành thẻ lựa chọn: bấm vào đâu trên thẻ cũng được.
const plans = [
  { value: 'realtime', title: 'Ngay khi có đơn', description: 'Mỗi đơn hàng tới ERP trong vòng một phút.' },
  { value: 'hourly', title: 'Mỗi giờ', description: 'Ít yêu cầu tới cửa hàng online hơn. Hợp với hầu hết cửa hàng.' },
  { value: 'nightly', title: 'Mỗi đêm', description: 'Chạy một lần lúc 2:00. Tồn kho có thể chậm tới một ngày.' },
]
const plan = ref('hourly')
</script>

<template>
  <FieldSet class="max-w-md">
    <FieldLegend variant="label">Đồng bộ đơn hàng</FieldLegend>
    <RadioGroup v-model="plan">
      <FieldLabel v-for="option in plans" :key="option.value" :for="`plan-${option.value}`">
        <Field orientation="horizontal">
          <FieldContent>
            <FieldTitle>{{ option.title }}</FieldTitle>
            <FieldDescription>{{ option.description }}</FieldDescription>
          </FieldContent>
          <RadioGroupItem :id="`plan-${option.value}`" :value="option.value" />
        </Field>
      </FieldLabel>
    </RadioGroup>
  </FieldSet>
</template>