如何在 ColorPicker 中设置颜色
How set color in ColorPicker in react
我使用来自 react-color 的 CirclePicker。我有包含表单的模态 window,ColorPicker 在哪里。我以十六进制格式 (#123123) 将有关当前颜色的信息发送到我的表单。我想在用户打开表单时设置 selected 颜色。怎样才能select一个彩圈?
const [settingWidget, setSettingWidget] = useState({
color: '#f44336', //default
});
function changeColor(colorChoice, event){
setSettingWidget({
color: colorChoice.hex
});
}
<div>
<Modal
visible={visible}
title='Edit'
okText='Save'
cancelText='Cancel'
onCancel={onCancel}
onOk={() => {
form.resetFields();
onSave(values);
}}
>
<Form
{...formItemLayout}
layout={formLayout}
form={form}
initialValues={{
colorPicker: settingWidget.color,
}}
>
<Form.Item />
<Form.Item name='colorPicker' label='Color'>
<CirclePicker onChange={changeColor} />
</Form.Item>
</Form>
</Modal>
</div>
您可以设置颜色属性。它将使用该特定颜色进行初始化。
Color accepts either a string of a hex color '#333' or a object of rgb or hsl values { r: 51, g: 51, b: 51 } or { h: 0, s: 0, l: .10 }. Both rgb and hsl will also take a a: 1 value for alpha. You can also use transparent.
<CirclePicker onChange={changeColor} color={color}/>
我使用来自 react-color 的 CirclePicker。我有包含表单的模态 window,ColorPicker 在哪里。我以十六进制格式 (#123123) 将有关当前颜色的信息发送到我的表单。我想在用户打开表单时设置 selected 颜色。怎样才能select一个彩圈?
const [settingWidget, setSettingWidget] = useState({
color: '#f44336', //default
});
function changeColor(colorChoice, event){
setSettingWidget({
color: colorChoice.hex
});
}
<div>
<Modal
visible={visible}
title='Edit'
okText='Save'
cancelText='Cancel'
onCancel={onCancel}
onOk={() => {
form.resetFields();
onSave(values);
}}
>
<Form
{...formItemLayout}
layout={formLayout}
form={form}
initialValues={{
colorPicker: settingWidget.color,
}}
>
<Form.Item />
<Form.Item name='colorPicker' label='Color'>
<CirclePicker onChange={changeColor} />
</Form.Item>
</Form>
</Modal>
</div>
您可以设置颜色属性。它将使用该特定颜色进行初始化。
Color accepts either a string of a hex color '#333' or a object of rgb or hsl values { r: 51, g: 51, b: 51 } or { h: 0, s: 0, l: .10 }. Both rgb and hsl will also take a a: 1 value for alpha. You can also use transparent.
<CirclePicker onChange={changeColor} color={color}/>