feat: establish shared field and form foundation
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from "vue";
|
||||
import {
|
||||
Description,
|
||||
FieldError,
|
||||
Input,
|
||||
Label,
|
||||
TextArea,
|
||||
TextField,
|
||||
} from "@heroui-vue/components";
|
||||
const username = ref("");
|
||||
const bio = ref("");
|
||||
const isUsernameInvalid = computed(
|
||||
() => username.value.length > 0 && username.value.length < 3,
|
||||
);
|
||||
const isBioInvalid = computed(
|
||||
() => bio.value.length > 0 && bio.value.length < 20,
|
||||
);
|
||||
</script>
|
||||
<template>
|
||||
<div class="flex w-full max-w-64 flex-col gap-4">
|
||||
<TextField
|
||||
v-model="username"
|
||||
is-required
|
||||
:is-invalid="isUsernameInvalid"
|
||||
name="username"
|
||||
>
|
||||
<Label>用户名</Label>
|
||||
<Input placeholder="jane_doe" />
|
||||
<FieldError v-if="isUsernameInvalid">
|
||||
用户名至少需要 3 个字符。
|
||||
</FieldError>
|
||||
<Description v-else>为你的资料选择一个唯一的用户名。</Description>
|
||||
</TextField>
|
||||
<TextField v-model="bio" is-required :is-invalid="isBioInvalid" name="bio">
|
||||
<Label>个人简介</Label>
|
||||
<TextArea placeholder="介绍一下你自己…" />
|
||||
<FieldError v-if="isBioInvalid">个人简介至少需要 20 个字符。</FieldError>
|
||||
<Description v-else>至少 20 个字符 ({{ bio.length }}/20).</Description>
|
||||
</TextField>
|
||||
</div>
|
||||
</template>
|
||||
Reference in New Issue
Block a user