Cài đặt
Chạy lệnh này trong app, sau shadcn-vue init và theme Beehexa (Button › Code):
npx shadcn-vue@latest add https://beehexa.design/r/number-field.json
Cách dùng
<script setup lang="ts">
import { ref } from 'vue'
import {
NumberField, NumberFieldContent, NumberFieldDecrement, NumberFieldIncrement, NumberFieldInput,
} from '@/components/ui/number-field'
const quantity = ref(12)
</script>
<template>
<NumberField id="stock-quantity" v-model="quantity" :min="0">
<label for="stock-quantity">Số lượng tồn kho</label>
<NumberFieldContent>
<NumberFieldDecrement aria-label="Giảm" />
<NumberFieldInput />
<NumberFieldIncrement aria-label="Tăng" />
</NumberFieldContent>
</NumberField>
</template>
Prop
| Phần | Prop | Giá trị | Ghi chú |
|---|---|---|---|
NumberField |
v-model, defaultValue |
số | |
NumberField |
min, max, step |
số | Nút và phím luôn ở trong giới hạn |
NumberField |
formatOptions, locale |
tùy chọn của Intl.NumberFormat, một locale |
Tiền tệ, phần trăm, số lẻ |
NumberField |
id |
chuỗi | Gắn vào input, cho <label for> |
NumberField |
disabled, readonly, required, name |
||
NumberFieldInput |
aria-invalid, aria-describedby |
Viền đỏ và thông báo lỗi | |
NumberFieldDecrement, NumberFieldIncrement |
aria-label |
chuỗi | Mặc định “Decrease” và “Increase” (tiếng Anh); hãy dịch |
Dựng từ
Bọc NumberField của reka-ui theo API NumberField của shadcn-vue. reka-ui lo vai trò spinbutton kèm aria-valuenow, aria-valuemin và aria-valuemax, các phím, đọc và định dạng số theo locale. Beehexa thêm style cho ô và các nút.