Files
heroui-vue/apps/docs/demos/color-field-controlled.vue
T

42 lines
1.2 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import { shallowRef } from "vue";
import type { Color } from "@heroui-vue/components";
import {
Button,
ColorField,
ColorFieldGroup,
ColorFieldInput,
ColorFieldPrefix,
ColorSwatch,
Description,
Label,
parseColor,
} from "@heroui-vue/components";
const value = shallowRef<Color | null>(parseColor("#0485F7"));
</script>
<template>
<div class="flex flex-col gap-4">
<ColorField class="w-[280px]" name="color" v-model="value">
<Label>颜色</Label>
<ColorFieldGroup>
<ColorFieldPrefix>
<ColorSwatch :color="value ?? undefined" size="xs" />
</ColorFieldPrefix>
<ColorFieldInput />
</ColorFieldGroup>
<Description>
当前值:{{ value ? value.toString("hex") : "(空)" }}
</Description>
</ColorField>
<div class="flex gap-2">
<Button variant="tertiary" @click="value = parseColor('#EF4444')">
设为红色
</Button>
<Button variant="tertiary" @click="value = parseColor('#10B981')">
设为绿色
</Button>
<Button variant="tertiary" @click="value = null">清空</Button>
</div>
</div>
</template>