ColorPickerPanel
颜色选择面板(无输入框)
用于在表单中嵌入纯拾色面板或自定义弹层内容,拥有与 ColorPicker 相同的 props,默认遵循 ColorPicker 的格式化与禁用逻辑,因此在受控表单里不需要额外适配即可获取字符串值。
Markup Schema 案例
<script lang="ts" setup>
import { createForm } from '@formily/core'
import { ColorPickerPanel, Form, FormItem, Submit } from '@silver-formily/element-plus'
import { createSchemaField } from '@silver-formily/vue'
const form = createForm()
const predefine = ['#409eff', '#67c23a', '#e6a23c', 'rgba(255, 69, 0, 0.68)']
const { SchemaField, SchemaStringField } = createSchemaField({
components: {
FormItem,
ColorPickerPanel,
},
})
async function onSubmit(value: any) {
console.log(value)
}
</script>
<template>
<Form :form="form" layout="vertical">
<SchemaField>
<SchemaStringField
name="primary"
title="主题色"
x-decorator="FormItem"
x-component="ColorPickerPanel"
:x-component-props="{
style: 'width: 320px',
predefine,
}"
/>
<SchemaStringField
name="alpha"
title="透明主题色"
x-decorator="FormItem"
x-component="ColorPickerPanel"
:x-component-props="{
showAlpha: true,
style: 'width: 320px',
}"
/>
</SchemaField>
<Submit style="margin-top: 12px" @submit="onSubmit">
提交
</Submit>
</Form>
</template>查看源码
Template 案例
<script lang="ts" setup>
import { createForm } from '@formily/core'
import { ColorPickerPanel, Form, FormItem, Submit } from '@silver-formily/element-plus'
import { Field } from '@silver-formily/vue'
const form = createForm()
const predefine = ['#409eff', '#67c23a', '#e6a23c', 'rgba(255, 69, 0, 0.68)']
async function onSubmit(value: any) {
console.log(value)
}
</script>
<template>
<Form :form="form" layout="vertical">
<Field
name="primary"
title="主题色"
:decorator="[FormItem]"
:component="[
ColorPickerPanel,
{
style: 'width: 320px',
predefine,
},
]"
/>
<Field
name="alpha"
title="透明主题色"
:decorator="[FormItem]"
:component="[
ColorPickerPanel,
{
showAlpha: true,
style: 'width: 320px',
},
]"
/>
<Submit style="margin-top: 12px" @submit="onSubmit">
提交
</Submit>
</Form>
</template>查看源码
API
参考 https://cn.element-plus.org/zh-CN/component/color-picker.html