-
Notifications
You must be signed in to change notification settings - Fork 815
/
Copy pathsave.js
130 lines (118 loc) · 3.7 KB
/
save.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**
* External dependencies
*/
import { RawHTML } from '@wordpress/element';
import {
getColorClassName,
__experimentalGetGradientClass as getGradientClass,
getFontSizeClass,
} from '@wordpress/block-editor';
import classnames from 'classnames';
/**
* Internal dependencies
*/
import {
DEFAULT_BORDER_RADIUS_VALUE,
DEFAULT_BORDER_WEIGHT_VALUE,
DEFAULT_PADDING_VALUE,
DEFAULT_SPACING_VALUE,
DEFAULT_FONTSIZE_VALUE,
} from './constants';
export default function Save( { className, attributes } ) {
const {
subscribePlaceholder,
showSubscribersTotal,
buttonOnNewLine,
submitButtonText,
emailFieldBackgroundColor,
customEmailFieldBackgroundColor,
emailFieldGradient,
customEmailFieldGradient,
buttonBackgroundColor,
customButtonBackgroundColor,
buttonGradient,
customButtonGradient,
textColor,
customTextColor,
fontSize,
customFontSize,
borderRadius,
borderWeight,
borderColor,
customBorderColor,
padding,
spacing,
} = attributes;
const isGradientAvailable = !! getGradientClass;
const textColorClass = getColorClassName( 'color', textColor );
const fontSizeClass = getFontSizeClass( fontSize );
const borderClass = getColorClassName( 'border-color', borderColor );
const buttonBackgroundClass = getColorClassName( 'background-color', buttonBackgroundColor );
const buttonGradientClass = isGradientAvailable ? getGradientClass( buttonGradient ) : undefined;
const emailFieldBackgroundClass = getColorClassName(
'background-color',
emailFieldBackgroundColor
);
const emailFieldGradientClass = isGradientAvailable
? getGradientClass( emailFieldGradient )
: undefined;
const sharedClasses = classnames(
borderRadius === 0 ? 'no-border-radius' : undefined,
fontSizeClass,
borderClass
);
const submitButtonClasses = classnames(
sharedClasses,
textColor ? 'has-text-color' : undefined,
textColorClass,
buttonBackgroundColor || buttonGradient ? 'has-background' : undefined,
buttonBackgroundClass,
buttonGradientClass
);
const emailFieldClasses = classnames(
sharedClasses,
emailFieldBackgroundClass,
emailFieldGradientClass
);
const emailFieldBackgroundStyle =
! emailFieldBackgroundClass && customEmailFieldGradient
? customEmailFieldGradient
: customEmailFieldBackgroundColor;
const buttonBackgroundStyle =
! buttonBackgroundClass && customButtonGradient
? customButtonGradient
: customButtonBackgroundColor;
const getBlockClassName = () => {
return classnames(
className,
'wp-block-jetpack-subscriptions__supports-newline',
buttonOnNewLine ? 'wp-block-jetpack-subscriptions__use-newline' : undefined,
showSubscribersTotal ? 'wp-block-jetpack-subscriptions__show-subs' : undefined
);
};
return (
<div className={ getBlockClassName() }>
<RawHTML>
{ `
[jetpack_subscription_form
subscribe_placeholder="${ subscribePlaceholder }"
show_subscribers_total="${ showSubscribersTotal }"
button_on_newline="${ buttonOnNewLine }"
submit_button_text="${ submitButtonText }"
custom_background_emailfield_color="${ emailFieldBackgroundStyle }"
custom_background_button_color="${ buttonBackgroundStyle }"
custom_text_button_color="${ customTextColor }"
custom_font_size="${ customFontSize || DEFAULT_FONTSIZE_VALUE }"
custom_border_radius="${ borderRadius || DEFAULT_BORDER_RADIUS_VALUE }"
custom_border_weight="${ borderWeight || DEFAULT_BORDER_WEIGHT_VALUE }"
custom_border_color="${ customBorderColor }"
custom_padding="${ padding || DEFAULT_PADDING_VALUE }"
custom_spacing="${ spacing || DEFAULT_SPACING_VALUE }"
submit_button_classes="${ submitButtonClasses }"
email_field_classes="${ emailFieldClasses }"
show_only_email_and_button="true"
]` }
</RawHTML>
</div>
);
}