| 1 |
import classnames from 'classnames/dedupe'; |
| 2 |
|
| 3 |
import { BaseControl, Button, Dropdown } from '@wordpress/components'; |
| 4 |
|
| 5 |
import ColorPalette from '../color-palette'; |
| 6 |
|
| 7 |
/** |
| 8 |
* Component |
| 9 |
* |
| 10 |
* @param props |
| 11 |
*/ |
| 12 |
export default function ColorPicker(props) { |
| 13 |
const { |
| 14 |
value, |
| 15 |
onChange, |
| 16 |
label, |
| 17 |
colorPalette = true, |
| 18 |
alpha = false, |
| 19 |
gradient = false, // PRO. |
| 20 |
afterDropdownContent, |
| 21 |
} = props; |
| 22 |
|
| 23 |
return ( |
| 24 |
<BaseControl className="ghostkit-component-color-picker-wrapper"> |
| 25 |
<Dropdown |
| 26 |
className="ghostkit-component-color-picker__dropdown" |
| 27 |
contentClassName="ghostkit-component-color-picker__dropdown-content" |
| 28 |
popoverProps={{ |
| 29 |
placement: 'left-start', |
| 30 |
offset: 36, |
| 31 |
shift: true, |
| 32 |
}} |
| 33 |
renderToggle={({ isOpen, onToggle }) => ( |
| 34 |
<Button |
| 35 |
className={classnames( |
| 36 |
'ghostkit-component-color-toggle', |
| 37 |
isOpen |
| 38 |
? 'ghostkit-component-color-toggle-active' |
| 39 |
: '' |
| 40 |
)} |
| 41 |
onClick={onToggle} |
| 42 |
> |
| 43 |
<span |
| 44 |
className="ghostkit-component-color-toggle-indicator" |
| 45 |
style={{ background: value || '' }} |
| 46 |
/> |
| 47 |
<span className="ghostkit-component-color-toggle-label"> |
| 48 |
{label} |
| 49 |
</span> |
| 50 |
</Button> |
| 51 |
)} |
| 52 |
renderContent={() => ( |
| 53 |
<div className="ghostkit-component-color-picker"> |
| 54 |
<ColorPalette |
| 55 |
value={value} |
| 56 |
palette={colorPalette} |
| 57 |
alpha={alpha} |
| 58 |
gradient={gradient} |
| 59 |
onChange={(color) => { |
| 60 |
onChange(color || ''); |
| 61 |
}} |
| 62 |
/> |
| 63 |
{afterDropdownContent || ''} |
| 64 |
</div> |
| 65 |
)} |
| 66 |
/> |
| 67 |
</BaseControl> |
| 68 |
); |
| 69 |
} |
| 70 |
|