import {
createElement,
Component,
useState,
useRef,
useContext,
Fragment,
} from '@wordpress/element'
import OutsideClickHandler from './react-outside-click-handler'
import classnames from 'classnames'
import ColorPicker from './ct-color-picker'
import { __ } from 'ct-i18n'
const clamp = (min, max, value) => Math.max(min, Math.min(max, value))
const Border = ({ value, option, onChange }) => {
const [isOpen, setIsOpen] = useState(false)
return (
{value.style !== 'none' && !value.inherit && (
onChange({
...value,
width: clamp(1, 5, parseInt(width, 10) || 1),
})
}
/>
)}
setIsOpen(!isOpen)}>
{value.inherit
? __('Inherit', 'blocksy')
: value.style === 'none'
? __('none', 'blocksy')
: null}
{
if (!isOpen) return
setIsOpen(false)
}}>
{['solid', 'dashed', 'dotted', 'none'].map((style) => (
{
onChange({
...value,
style,
...(Object.keys(option.value).indexOf(
'inherit'
) > -1
? {
inherit: false,
}
: {}),
})
setIsOpen(false)
}}
data-style={style}>
{style === 'none' ? __('None', 'blocksy') : null}
))}
{value.style !== 'none' && !value.inherit && (
onChange({
...value,
color: colorValue.default,
})
}
option={{
pickers: [
{
id: 'default',
title: __('Initial', 'blocksy'),
},
],
}}
value={{
default: value.color,
}}
/>
{option.secondColor && (
onChange({
...value,
secondColor: colorValue.default,
})
}
option={{
pickers: [
{
id: 'default',
title: __('Hover', 'blocksy'),
},
],
}}
value={{
default:
value.secondColor ||
option.value.secondColor,
}}
/>
)}
)}
)
}
export default Border