组件说明
颜色选择器组件用于选择颜色值,支持多种颜色格式。
用法示例
use plugin\xbCode\builder\Builder;
use plugin\xbCode\builder\Renders\Form;
Builder::form(function (Form $builder) {
// 基础用法
$builder->addRowColor('color', '颜色', '#FF0000', function($component) {
$component->format('hex'); // 颜色格式
$component->clearable(true);
});
// 带预设颜色
$builder->addRowColor('theme_color', '主题色', '', [
'format' => 'rgba',
'presetColors' => [
'#FF0000', '#00FF00', '#0000FF',
'#FFFF00', '#FF00FF', '#00FFFF'
],
'allowCustomColor' => true
]);
// 不允许自定义颜色
$builder->addRowColor('preset_color', '预设颜色', '', function($component) {
$component->presetColors(['#FF5733', '#33FF57', '#3357FF']);
$component->allowCustomColor(false);
$component->resetValue('#FFFFFF');
});
});
组件参数
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| name | string | - | 字段名称 |
| label | string | - | 字段标签 |
| value | string | - | 默认颜色值 |
| format | string | 'hex' | 颜色格式,支持:hex、hexa、hls、rgb、rgba |
| presetColors | array | - | 预设颜色值数组,会显示在选择器底部 |
| allowCustomColor | bool | true | 是否允许自定义颜色 |
| clearable | bool | true | 是否显示清除按钮 |
| resetValue | string | '' | 清除后的默认值 |
| required | bool | false | 是否必填 |
| disabled | bool | false | 是否禁用 |
使用说明
- format支持的颜色格式:
- presetColors可以设置常用颜色,方便快速选择
- allowCustomColor为false时,只能从预设颜色中选择
- clearable为true时,可以清除颜色,恢复到resetValue设置的值