Set default values for older dividers
[MAILPOET-2835]
This commit is contained in:
@@ -23,6 +23,16 @@ export interface Attributes {
|
|||||||
color: string;
|
color: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const defaultAttributes = {
|
||||||
|
className: undefined,
|
||||||
|
height: 1,
|
||||||
|
type: Types.Divider,
|
||||||
|
style: Style.Solid,
|
||||||
|
dividerHeight: 1,
|
||||||
|
dividerWidth: 100,
|
||||||
|
color: 'black',
|
||||||
|
};
|
||||||
|
|
||||||
export const name = 'mailpoet-form/divider';
|
export const name = 'mailpoet-form/divider';
|
||||||
|
|
||||||
export const settings = {
|
export const settings = {
|
||||||
@@ -33,26 +43,27 @@ export const settings = {
|
|||||||
attributes: {
|
attributes: {
|
||||||
height: {
|
height: {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
default: 1,
|
default: defaultAttributes.height,
|
||||||
},
|
},
|
||||||
type: {
|
type: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: Types.Divider,
|
default: defaultAttributes.type,
|
||||||
},
|
},
|
||||||
style: {
|
style: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: Style.Solid,
|
default: defaultAttributes.style,
|
||||||
},
|
},
|
||||||
dividerHeight: {
|
dividerHeight: {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
default: 1,
|
default: defaultAttributes.dividerHeight,
|
||||||
},
|
},
|
||||||
dividerWidth: {
|
dividerWidth: {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
default: 100,
|
default: defaultAttributes.dividerWidth,
|
||||||
},
|
},
|
||||||
color: {
|
color: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
|
default: defaultAttributes.color,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
supports: {
|
supports: {
|
||||||
|
@@ -10,7 +10,12 @@ import {
|
|||||||
SelectControl,
|
SelectControl,
|
||||||
ToggleControl,
|
ToggleControl,
|
||||||
} from '@wordpress/components';
|
} from '@wordpress/components';
|
||||||
import { Attributes, Style, Types } from './divider';
|
import {
|
||||||
|
Attributes,
|
||||||
|
Style,
|
||||||
|
Types,
|
||||||
|
defaultAttributes,
|
||||||
|
} from './divider';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
attributes: Attributes,
|
attributes: Attributes,
|
||||||
@@ -18,11 +23,18 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const DividerEdit = ({ attributes, setAttributes }: Props) => {
|
const DividerEdit = ({ attributes, setAttributes }: Props) => {
|
||||||
|
const attributeStyle = attributes.style ?? defaultAttributes.style;
|
||||||
|
const attributeDividerHeight = attributes.dividerHeight ?? defaultAttributes.dividerHeight;
|
||||||
|
const attributeDividerWidth = attributes.dividerWidth ?? defaultAttributes.dividerWidth;
|
||||||
|
const attributeHeight = attributes.height ?? defaultAttributes.height;
|
||||||
|
const attributeType = attributes.type ?? defaultAttributes.type;
|
||||||
|
const attributeColor = attributes.color ?? defaultAttributes.color;
|
||||||
|
|
||||||
const dividerSettings = (
|
const dividerSettings = (
|
||||||
<>
|
<>
|
||||||
<SelectControl
|
<SelectControl
|
||||||
label={MailPoet.I18n.t('blockDividerStyle')}
|
label={MailPoet.I18n.t('blockDividerStyle')}
|
||||||
value={attributes.style}
|
value={attributeStyle}
|
||||||
onChange={(style) => (setAttributes({ style }))}
|
onChange={(style) => (setAttributes({ style }))}
|
||||||
options={[
|
options={[
|
||||||
{ value: Style.Solid, label: MailPoet.I18n.t('blockDividerStyleSolid') },
|
{ value: Style.Solid, label: MailPoet.I18n.t('blockDividerStyleSolid') },
|
||||||
@@ -32,20 +44,20 @@ const DividerEdit = ({ attributes, setAttributes }: Props) => {
|
|||||||
/>
|
/>
|
||||||
<RangeControl
|
<RangeControl
|
||||||
label={MailPoet.I18n.t('blockDividerDividerHeight')}
|
label={MailPoet.I18n.t('blockDividerDividerHeight')}
|
||||||
value={attributes.dividerHeight}
|
value={attributeDividerHeight}
|
||||||
min={1}
|
min={1}
|
||||||
max={40}
|
max={40}
|
||||||
allowReset
|
allowReset
|
||||||
onChange={(dividerHeight) => {
|
onChange={(dividerHeight) => {
|
||||||
setAttributes({
|
setAttributes({
|
||||||
dividerHeight,
|
dividerHeight,
|
||||||
height: Math.max(dividerHeight, attributes.height),
|
height: Math.max(dividerHeight, attributeHeight),
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<RangeControl
|
<RangeControl
|
||||||
label={MailPoet.I18n.t('blockDividerDividerWidth')}
|
label={MailPoet.I18n.t('blockDividerDividerWidth')}
|
||||||
value={attributes.dividerWidth}
|
value={attributeDividerWidth}
|
||||||
min={1}
|
min={1}
|
||||||
max={100}
|
max={100}
|
||||||
allowReset
|
allowReset
|
||||||
@@ -53,19 +65,19 @@ const DividerEdit = ({ attributes, setAttributes }: Props) => {
|
|||||||
/>
|
/>
|
||||||
<ColorSettings
|
<ColorSettings
|
||||||
name={MailPoet.I18n.t('blockDividerColor')}
|
name={MailPoet.I18n.t('blockDividerColor')}
|
||||||
value={attributes.color}
|
value={attributeColor}
|
||||||
onChange={(color) => (setAttributes({ color }))}
|
onChange={(color) => (setAttributes({ color }))}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
const dividerStyles = {} as React.CSSProperties;
|
const dividerStyles = {} as React.CSSProperties;
|
||||||
if (attributes.type === Types.Divider) {
|
if (attributeType === Types.Divider) {
|
||||||
dividerStyles.borderTopStyle = attributes.style;
|
dividerStyles.borderTopStyle = attributeStyle;
|
||||||
dividerStyles.borderTopWidth = attributes.dividerHeight;
|
dividerStyles.borderTopWidth = attributeDividerHeight;
|
||||||
dividerStyles.borderTopColor = attributes.color;
|
dividerStyles.borderTopColor = attributeColor;
|
||||||
dividerStyles.height = attributes.dividerHeight;
|
dividerStyles.height = attributeDividerHeight;
|
||||||
dividerStyles.width = `${attributes.dividerWidth}%`;
|
dividerStyles.width = `${attributeDividerWidth}%`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -75,7 +87,7 @@ const DividerEdit = ({ attributes, setAttributes }: Props) => {
|
|||||||
<PanelBody title={MailPoet.I18n.t('formSettingsStyles')} initialOpen>
|
<PanelBody title={MailPoet.I18n.t('formSettingsStyles')} initialOpen>
|
||||||
<RangeControl
|
<RangeControl
|
||||||
label={MailPoet.I18n.t('blockSpacerHeight')}
|
label={MailPoet.I18n.t('blockSpacerHeight')}
|
||||||
value={attributes.height}
|
value={attributeHeight}
|
||||||
min={1}
|
min={1}
|
||||||
max={400}
|
max={400}
|
||||||
allowReset
|
allowReset
|
||||||
@@ -83,13 +95,13 @@ const DividerEdit = ({ attributes, setAttributes }: Props) => {
|
|||||||
/>
|
/>
|
||||||
<ToggleControl
|
<ToggleControl
|
||||||
label={MailPoet.I18n.t('blockSpacerEnableDivider')}
|
label={MailPoet.I18n.t('blockSpacerEnableDivider')}
|
||||||
checked={attributes.type === Types.Divider}
|
checked={attributeType === Types.Divider}
|
||||||
onChange={(checked) => setAttributes({
|
onChange={(checked) => setAttributes({
|
||||||
type: checked ? Types.Divider : Types.Spacer,
|
type: checked ? Types.Divider : Types.Spacer,
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
{(
|
{(
|
||||||
(attributes.type === Types.Divider) && (dividerSettings)
|
(attributeType === Types.Divider) && (dividerSettings)
|
||||||
)}
|
)}
|
||||||
</PanelBody>
|
</PanelBody>
|
||||||
</Panel>
|
</Panel>
|
||||||
@@ -98,7 +110,7 @@ const DividerEdit = ({ attributes, setAttributes }: Props) => {
|
|||||||
<div
|
<div
|
||||||
className={classnames('mailpoet_spacer', attributes.className)}
|
className={classnames('mailpoet_spacer', attributes.className)}
|
||||||
style={{
|
style={{
|
||||||
height: attributes.height,
|
height: attributeHeight,
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'column',
|
flexDirection: 'column',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
|
Reference in New Issue
Block a user