feat: publish ColorField and shared color input parts
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<script setup lang="ts">
|
||||
import { shallowRef, useTemplateRef } from "vue";
|
||||
import {
|
||||
ColorField,
|
||||
ColorFieldGroup,
|
||||
ColorFieldInput,
|
||||
ColorFieldPrefix,
|
||||
ColorFieldSuffix,
|
||||
Label,
|
||||
parseColor,
|
||||
type Color,
|
||||
} from "@heroui-vue/components";
|
||||
const color = shallowRef<Color | null>(parseColor("#123456"));
|
||||
const field = useTemplateRef<InstanceType<typeof ColorField>>("field");
|
||||
const input = useTemplateRef<InstanceType<typeof ColorFieldInput>>("input");
|
||||
function focus() {
|
||||
field.value?.focus();
|
||||
field.value?.color?.toString("hex");
|
||||
field.value?.element?.select();
|
||||
input.value?.select();
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<button @click="focus">聚焦</button>
|
||||
<ColorField
|
||||
ref="field"
|
||||
v-model="color"
|
||||
channel="hue"
|
||||
color-space="hsl"
|
||||
v-slot="state"
|
||||
:style-fn="(s) => ({ opacity: s.isFocused ? 1 : 0.8 })"
|
||||
>
|
||||
<Label>颜色</Label>
|
||||
<ColorFieldGroup variant="secondary" v-slot="group">
|
||||
<ColorFieldPrefix>{{ state.value?.toString("hex") }}</ColorFieldPrefix>
|
||||
<ColorFieldInput ref="input" />
|
||||
<ColorFieldSuffix>{{ group.isHovered }}</ColorFieldSuffix>
|
||||
</ColorFieldGroup>
|
||||
</ColorField>
|
||||
<!-- @vue-expect-error invalid public model -->
|
||||
<ColorField :model-value="123" />
|
||||
<!-- @vue-expect-error invalid public color channel -->
|
||||
<ColorField channel="cyan" />
|
||||
<!-- @vue-expect-error invalid public color space -->
|
||||
<ColorField color-space="lab" />
|
||||
<!-- @vue-expect-error unsupported group variant -->
|
||||
<ColorFieldGroup variant="tertiary" />
|
||||
</template>
|
||||
Reference in New Issue
Block a user