| 1 |
import { BaseControl, TextControl } from '@wordpress/components'; |
| 2 |
import { __ } from '@wordpress/i18n'; |
| 3 |
|
| 4 |
import ToggleGroup from '../toggle-group'; |
| 5 |
|
| 6 |
const GAP_VALUES = { |
| 7 |
no: 0, |
| 8 |
sm: 15, |
| 9 |
md: 30, |
| 10 |
lg: 45, |
| 11 |
}; |
| 12 |
|
| 13 |
/** |
| 14 |
* Component Class |
| 15 |
* |
| 16 |
* @param props |
| 17 |
*/ |
| 18 |
export default function GapSettings(props) { |
| 19 |
const { gap, gapCustom, gapVerticalCustom, allowVerticalGap, onChange } = |
| 20 |
props; |
| 21 |
|
| 22 |
return ( |
| 23 |
<BaseControl |
| 24 |
id={__('Gap', 'ghostkit')} |
| 25 |
label={__('Gap', 'ghostkit')} |
| 26 |
className="ghostkit-components-gap-settings" |
| 27 |
> |
| 28 |
<ToggleGroup |
| 29 |
value={gap} |
| 30 |
options={[ |
| 31 |
{ |
| 32 |
label: __('None', 'ghostkit'), |
| 33 |
value: 'no', |
| 34 |
}, |
| 35 |
{ |
| 36 |
label: __('S', 'ghostkit'), |
| 37 |
value: 'sm', |
| 38 |
}, |
| 39 |
{ |
| 40 |
label: __('M', 'ghostkit'), |
| 41 |
value: 'md', |
| 42 |
}, |
| 43 |
{ |
| 44 |
label: __('L', 'ghostkit'), |
| 45 |
value: 'lg', |
| 46 |
}, |
| 47 |
{ |
| 48 |
label: ( |
| 49 |
<svg |
| 50 |
width="24" |
| 51 |
height="24" |
| 52 |
xmlns="http://www.w3.org/2000/svg" |
| 53 |
viewBox="0 0 24 24" |
| 54 |
role="img" |
| 55 |
aria-hidden="true" |
| 56 |
focusable="false" |
| 57 |
> |
| 58 |
<path |
| 59 |
d="M14.5 13.8c-1.1 0-2.1.7-2.4 1.8H4V17h8.1c.3 1 1.3 1.8 2.4 1.8s2.1-.7 2.4-1.8H20v-1.5h-3.1c-.3-1-1.3-1.7-2.4-1.7zM11.9 7c-.3-1-1.3-1.8-2.4-1.8S7.4 6 7.1 7H4v1.5h3.1c.3 1 1.3 1.8 2.4 1.8s2.1-.7 2.4-1.8H20V7h-8.1z" |
| 60 |
fill="currentColor" |
| 61 |
/> |
| 62 |
</svg> |
| 63 |
), |
| 64 |
value: 'custom', |
| 65 |
}, |
| 66 |
]} |
| 67 |
onChange={(value) => { |
| 68 |
const result = { |
| 69 |
gap: value, |
| 70 |
}; |
| 71 |
|
| 72 |
// Add current predefined gap to custom value. |
| 73 |
if ( |
| 74 |
value === 'custom' && |
| 75 |
gap !== 'custom' && |
| 76 |
typeof GAP_VALUES[gap] !== 'undefined' |
| 77 |
) { |
| 78 |
result.gapCustom = GAP_VALUES[gap]; |
| 79 |
} |
| 80 |
|
| 81 |
// Reset vertical gap when use predefined value. |
| 82 |
if (value !== 'custom') { |
| 83 |
result.gapVerticalCustom = undefined; |
| 84 |
} |
| 85 |
|
| 86 |
onChange(result); |
| 87 |
}} |
| 88 |
isBlock |
| 89 |
/> |
| 90 |
{gap === 'custom' ? ( |
| 91 |
<div className="ghostkit-components-gap-settings-custom"> |
| 92 |
<TextControl |
| 93 |
type="number" |
| 94 |
help={ |
| 95 |
allowVerticalGap ? __('Horizontal', 'ghostkit') : '' |
| 96 |
} |
| 97 |
value={gapCustom} |
| 98 |
onChange={(value) => |
| 99 |
onChange({ |
| 100 |
gapCustom: |
| 101 |
value === '' |
| 102 |
? undefined |
| 103 |
: parseFloat(value), |
| 104 |
}) |
| 105 |
} |
| 106 |
min={0} |
| 107 |
/> |
| 108 |
{allowVerticalGap ? ( |
| 109 |
<TextControl |
| 110 |
type="number" |
| 111 |
help={__('Vertical', 'ghostkit')} |
| 112 |
placeholder={gapCustom} |
| 113 |
value={gapVerticalCustom} |
| 114 |
onChange={(value) => |
| 115 |
onChange({ |
| 116 |
gapVerticalCustom: |
| 117 |
value === '' |
| 118 |
? undefined |
| 119 |
: parseFloat(value), |
| 120 |
}) |
| 121 |
} |
| 122 |
min={0} |
| 123 |
/> |
| 124 |
) : null} |
| 125 |
</div> |
| 126 |
) : null} |
| 127 |
</BaseControl> |
| 128 |
); |
| 129 |
} |
| 130 |
|