| 1 |
/** |
| 2 |
* WordPress dependencies |
| 3 |
*/ |
| 4 |
import { ColorIndicator, ColorPicker, Popover, RangeControl } from '@wordpress/components'; |
| 5 |
import { useState } from '@wordpress/element'; |
| 6 |
import { __ } from '@wordpress/i18n'; |
| 7 |
|
| 8 |
/** |
| 9 |
* Internal dependencies |
| 10 |
*/ |
| 11 |
import ResLabelControl from '../res-label-control'; |
| 12 |
import ResetButton from '../reset-btn'; |
| 13 |
const TextStrokeControl = ({ label, value, onChange, onClickReset, min, max, step, strokeColor, onColorChange }) => { |
| 14 |
const [colorPanel, setColorPanel] = useState(false); |
| 15 |
const colors = wp.data.select('core/editor').getEditorSettings().colors; |
| 16 |
|
| 17 |
return ( |
| 18 |
<div className="gkits-stroke gkits-control-container gkits-color-control gkits-mb-24"> |
| 19 |
<div className="gkits-label-flex"> |
| 20 |
<ResLabelControl label={label} noResBtns={true} /> |
| 21 |
<div className="gkits-stroke-color"> |
| 22 |
<button className="color-indicator" onClick={() => setColorPanel(true)}> |
| 23 |
<ColorIndicator colorValue={strokeColor} /> |
| 24 |
</button> |
| 25 |
{colorPanel && ( |
| 26 |
<Popover position="bottom right" onFocusOutside={() => setColorPanel(false)} offset={10}> |
| 27 |
<div className="gkits-color-panel"> |
| 28 |
<ColorPicker color={strokeColor} onChangeComplete={v => onColorChange(v.hex)} disableAlpha={false} /> |
| 29 |
<div className="gkits-colors-palette"> |
| 30 |
<label className="gkits-label gkits-mb-8" htmlFor="gkits-colors-palette"> |
| 31 |
{__('Theme Colors', 'slider-blocks')} |
| 32 |
</label> |
| 33 |
<div id="gkits-colors-palette"> |
| 34 |
{colors && |
| 35 |
colors.map((paletteColor, index) => { |
| 36 |
return ( |
| 37 |
<ColorIndicator |
| 38 |
className={`gkits-color-indicator ${ |
| 39 |
paletteColor.color === strokeColor ? 'active' : '' |
| 40 |
}`} |
| 41 |
title={paletteColor.name} |
| 42 |
key={index} |
| 43 |
colorValue={paletteColor.color} |
| 44 |
onClick={() => onColorChange(paletteColor.color)} |
| 45 |
/> |
| 46 |
); |
| 47 |
})} |
| 48 |
</div> |
| 49 |
</div> |
| 50 |
</div> |
| 51 |
</Popover> |
| 52 |
)} |
| 53 |
</div> |
| 54 |
</div> |
| 55 |
|
| 56 |
<div className="gkits-controls-body"> |
| 57 |
<ResetButton onReset={onClickReset} value={value || strokeColor}> |
| 58 |
<RangeControl value={value} onChange={v => onChange(v)} min={min} max={max} step={step} /> |
| 59 |
</ResetButton> |
| 60 |
</div> |
| 61 |
</div> |
| 62 |
); |
| 63 |
}; |
| 64 |
|
| 65 |
export default TextStrokeControl; |
| 66 |
|