| 1 |
import classnames from 'classnames/dedupe'; |
| 2 |
|
| 3 |
import { |
| 4 |
InspectorControls, |
| 5 |
RichText, |
| 6 |
useBlockProps, |
| 7 |
} from '@wordpress/block-editor'; |
| 8 |
import { PanelBody, TextControl, ToggleControl } from '@wordpress/components'; |
| 9 |
import { applyFilters } from '@wordpress/hooks'; |
| 10 |
import { __ } from '@wordpress/i18n'; |
| 11 |
|
| 12 |
import { |
| 13 |
FieldDefaultSettings, |
| 14 |
getFieldAttributes, |
| 15 |
} from '../../field-attributes'; |
| 16 |
import FieldDescription from '../../field-description'; |
| 17 |
import FieldLabel from '../../field-label'; |
| 18 |
|
| 19 |
/** |
| 20 |
* Block Edit Class. |
| 21 |
* |
| 22 |
* @param props |
| 23 |
*/ |
| 24 |
export default function BlockEdit(props) { |
| 25 |
const { attributes, setAttributes } = props; |
| 26 |
|
| 27 |
const { |
| 28 |
description, |
| 29 |
emailConfirmation, |
| 30 |
descriptionConfirmation, |
| 31 |
placeholderConfirmation, |
| 32 |
defaultConfirmation, |
| 33 |
} = attributes; |
| 34 |
|
| 35 |
let { className = '' } = props; |
| 36 |
|
| 37 |
className = classnames( |
| 38 |
'ghostkit-form-field ghostkit-form-field-email', |
| 39 |
className |
| 40 |
); |
| 41 |
className = applyFilters('ghostkit.editor.className', className, props); |
| 42 |
|
| 43 |
const blockProps = useBlockProps({ className }); |
| 44 |
|
| 45 |
return ( |
| 46 |
<> |
| 47 |
<InspectorControls> |
| 48 |
<PanelBody> |
| 49 |
<FieldDefaultSettings {...props} /> |
| 50 |
</PanelBody> |
| 51 |
<PanelBody title={__('Email Confirmation', 'ghostkit')}> |
| 52 |
<ToggleControl |
| 53 |
label={__('Yes', 'ghostkit')} |
| 54 |
checked={emailConfirmation} |
| 55 |
onChange={() => { |
| 56 |
if (emailConfirmation) { |
| 57 |
setAttributes({ |
| 58 |
emailConfirmation: !emailConfirmation, |
| 59 |
}); |
| 60 |
} else { |
| 61 |
setAttributes({ |
| 62 |
emailConfirmation: !emailConfirmation, |
| 63 |
description: |
| 64 |
description || __('Email', 'ghostkit'), |
| 65 |
descriptionConfirmation: |
| 66 |
descriptionConfirmation || |
| 67 |
__('Confirm Email', 'ghostkit'), |
| 68 |
}); |
| 69 |
} |
| 70 |
}} |
| 71 |
/> |
| 72 |
{emailConfirmation ? ( |
| 73 |
<> |
| 74 |
<TextControl |
| 75 |
label={__('Placeholder', 'ghostkit')} |
| 76 |
value={placeholderConfirmation} |
| 77 |
onChange={(val) => |
| 78 |
setAttributes({ |
| 79 |
placeholderConfirmation: val, |
| 80 |
}) |
| 81 |
} |
| 82 |
/> |
| 83 |
<TextControl |
| 84 |
label={__('Default', 'ghostkit')} |
| 85 |
value={defaultConfirmation} |
| 86 |
onChange={(val) => |
| 87 |
setAttributes({ defaultConfirmation: val }) |
| 88 |
} |
| 89 |
/> |
| 90 |
</> |
| 91 |
) : null} |
| 92 |
</PanelBody> |
| 93 |
</InspectorControls> |
| 94 |
<div {...blockProps}> |
| 95 |
<FieldLabel {...props} /> |
| 96 |
|
| 97 |
{emailConfirmation ? ( |
| 98 |
<div className="ghostkit-form-field-row"> |
| 99 |
<div className="ghostkit-form-field-email-primary"> |
| 100 |
<TextControl |
| 101 |
type="email" |
| 102 |
{...getFieldAttributes(attributes)} |
| 103 |
/> |
| 104 |
<FieldDescription {...props} /> |
| 105 |
</div> |
| 106 |
<div className="ghostkit-form-field-email-confirm"> |
| 107 |
<TextControl |
| 108 |
type="email" |
| 109 |
{...getFieldAttributes({ |
| 110 |
slug: attributes.slug |
| 111 |
? `${attributes.slug}-confirmation` |
| 112 |
: null, |
| 113 |
placeholder: |
| 114 |
attributes.placeholderConfirmation, |
| 115 |
default: attributes.defaultConfirmation, |
| 116 |
required: attributes.required, |
| 117 |
})} |
| 118 |
/> |
| 119 |
<RichText |
| 120 |
inlineToolbar |
| 121 |
tagName="small" |
| 122 |
className="ghostkit-form-field-description" |
| 123 |
value={descriptionConfirmation} |
| 124 |
placeholder={__( |
| 125 |
'Write description…', |
| 126 |
'ghostkit' |
| 127 |
)} |
| 128 |
onChange={(val) => |
| 129 |
setAttributes({ |
| 130 |
descriptionConfirmation: val, |
| 131 |
}) |
| 132 |
} |
| 133 |
/> |
| 134 |
</div> |
| 135 |
</div> |
| 136 |
) : ( |
| 137 |
<> |
| 138 |
<TextControl |
| 139 |
type="email" |
| 140 |
{...getFieldAttributes(attributes)} |
| 141 |
/> |
| 142 |
<FieldDescription {...props} /> |
| 143 |
</> |
| 144 |
)} |
| 145 |
</div> |
| 146 |
</> |
| 147 |
); |
| 148 |
} |
| 149 |
|