parts
3 years ago
ActionBar.js
2 years ago
Behavior.js
2 years ago
CTA.js
2 years ago
Controls.js
5 years ago
Edit.js
2 years ago
Email.js
2 years ago
Preset.js
4 years ago
Search.js
3 years ago
Style.js
2 years ago
Watermark.js
4 years ago
index.js
4 years ago
Email.js
251 lines
| 1 | /** @jsx jsx */ |
| 2 | /** |
| 3 | * WordPress dependencies |
| 4 | */ |
| 5 | import { __ } from "@wordpress/i18n"; |
| 6 | import { |
| 7 | ToggleControl, |
| 8 | BaseControl, |
| 9 | RangeControl, |
| 10 | TextControl, |
| 11 | Button, |
| 12 | Flex, |
| 13 | TextareaControl, |
| 14 | Notice, |
| 15 | } from "@wordpress/components"; |
| 16 | import { useSelect } from "@wordpress/data"; |
| 17 | |
| 18 | import ChooseProvider from "./parts/ChooseProvider"; |
| 19 | import ColorPopup from "../components/ColorPopup"; |
| 20 | |
| 21 | import { css, jsx } from "@emotion/core"; |
| 22 | |
| 23 | export default function ({ state, updateState, className }) { |
| 24 | const { email_collection, cta } = state; |
| 25 | |
| 26 | const branding = useSelect((select) => { |
| 27 | return select("presto-player/player").branding(); |
| 28 | }); |
| 29 | |
| 30 | const updateEmailState = (updated) => { |
| 31 | updateState({ |
| 32 | ...state, |
| 33 | email_collection: { |
| 34 | ...email_collection, |
| 35 | ...updated, |
| 36 | }, |
| 37 | }); |
| 38 | }; |
| 39 | |
| 40 | const disableCTA = () => { |
| 41 | updateState({ |
| 42 | ...state, |
| 43 | cta: { |
| 44 | ...cta, |
| 45 | ...{ enabled: false }, |
| 46 | }, |
| 47 | }); |
| 48 | }; |
| 49 | |
| 50 | return ( |
| 51 | <div className={className}> |
| 52 | <BaseControl> |
| 53 | <h3>{__("Email Capture", "presto-player")}</h3> |
| 54 | </BaseControl> |
| 55 | <BaseControl className="presto-player__control--large-play"> |
| 56 | <ToggleControl |
| 57 | label={__("Enable", "presto-player")} |
| 58 | help={__( |
| 59 | "Show an email collection form and message over your player.", |
| 60 | "presto-player" |
| 61 | )} |
| 62 | onChange={(enabled) => { |
| 63 | updateEmailState({ |
| 64 | enabled, |
| 65 | }); |
| 66 | }} |
| 67 | checked={email_collection?.enabled} |
| 68 | /> |
| 69 | </BaseControl> |
| 70 | {!!email_collection?.enabled && ( |
| 71 | <> |
| 72 | <BaseControl |
| 73 | className="presto-player__control--percentage-watched" |
| 74 | css={css` |
| 75 | padding-left: 8px; |
| 76 | margin-bottom: 34px !important; |
| 77 | .components-range-control__root { |
| 78 | align-items: flex-start; |
| 79 | } |
| 80 | `} |
| 81 | > |
| 82 | <RangeControl |
| 83 | label={__("Display At (Percentage)", "presto-player")} |
| 84 | labelPosition="top" |
| 85 | onChange={(percentage) => { |
| 86 | updateEmailState({ |
| 87 | percentage, |
| 88 | }); |
| 89 | }} |
| 90 | marks={[ |
| 91 | { |
| 92 | value: 0, |
| 93 | label: __("Start", "presto-player"), |
| 94 | }, |
| 95 | { |
| 96 | value: 50, |
| 97 | label: __("50% Watched", "presto-player"), |
| 98 | }, |
| 99 | { |
| 100 | value: 100, |
| 101 | label: __("End", "presto-player"), |
| 102 | }, |
| 103 | ]} |
| 104 | shiftStep={5} |
| 105 | value={email_collection?.percentage || 0} |
| 106 | css={css` |
| 107 | .components-range-control__slider { |
| 108 | position: relative !important; |
| 109 | } |
| 110 | `} |
| 111 | /> |
| 112 | </BaseControl> |
| 113 | |
| 114 | {cta?.enabled && email_collection?.percentage === cta?.percentage && ( |
| 115 | <Notice |
| 116 | css={css` |
| 117 | margin: 0 0 30px 0 !important; |
| 118 | `} |
| 119 | status="warning" |
| 120 | isDismissible={false} |
| 121 | > |
| 122 | {__( |
| 123 | "You already have a Call To Action set display at the same time.", |
| 124 | "presto-player" |
| 125 | )} |
| 126 | <Button |
| 127 | onClick={disableCTA} |
| 128 | isLink |
| 129 | css={css` |
| 130 | margin-top: 10px !important; |
| 131 | `} |
| 132 | > |
| 133 | {__("Disable Call To Action", "presto-player")} |
| 134 | </Button> |
| 135 | </Notice> |
| 136 | )} |
| 137 | |
| 138 | <BaseControl className="presto-player__control--large-play"> |
| 139 | <ToggleControl |
| 140 | label={__("Allow Skipping", "presto-player")} |
| 141 | help={__("Let the viewer skip", "presto-player")} |
| 142 | onChange={(allow_skip) => { |
| 143 | updateEmailState({ |
| 144 | allow_skip, |
| 145 | }); |
| 146 | }} |
| 147 | checked={email_collection?.allow_skip} |
| 148 | /> |
| 149 | </BaseControl> |
| 150 | |
| 151 | <BaseControl className="presto-player__control--large-play"> |
| 152 | <TextareaControl |
| 153 | label={__("Headline", "presto-player")} |
| 154 | help={__("The headline for your form.", "presto-player")} |
| 155 | value={email_collection?.headline} |
| 156 | onChange={(headline) => { |
| 157 | updateEmailState({ |
| 158 | headline, |
| 159 | }); |
| 160 | }} |
| 161 | /> |
| 162 | </BaseControl> |
| 163 | |
| 164 | <BaseControl className="presto-player__control--large-play"> |
| 165 | <TextareaControl |
| 166 | label={__("Bottom Text", "presto-player")} |
| 167 | help={__( |
| 168 | "Text displayed below the form. HTML allowed.", |
| 169 | "presto-player" |
| 170 | )} |
| 171 | value={email_collection?.bottom_text} |
| 172 | onChange={(bottom_text) => { |
| 173 | updateEmailState({ |
| 174 | bottom_text, |
| 175 | }); |
| 176 | }} |
| 177 | /> |
| 178 | </BaseControl> |
| 179 | |
| 180 | <BaseControl className="presto-player__control--large-play"> |
| 181 | <TextControl |
| 182 | label={__("Play Button Text", "presto-player")} |
| 183 | help={<p>{__("Submit button text", "presto-player")}</p>} |
| 184 | value={email_collection?.button_text} |
| 185 | onChange={(button_text) => updateEmailState({ button_text })} |
| 186 | /> |
| 187 | </BaseControl> |
| 188 | |
| 189 | <BaseControl className="presto-player__control--button-color"> |
| 190 | <Flex> |
| 191 | <BaseControl.VisualLabel> |
| 192 | {__("Button Color", "presto-player")} |
| 193 | </BaseControl.VisualLabel> |
| 194 | <ColorPopup |
| 195 | color={cta?.button_color || branding?.color} |
| 196 | setColor={(value) => |
| 197 | updateEmailState({ |
| 198 | button_color: value && value.hex, |
| 199 | }) |
| 200 | } |
| 201 | /> |
| 202 | </Flex> |
| 203 | </BaseControl> |
| 204 | <BaseControl className="presto-player__control--button-text-color"> |
| 205 | <Flex> |
| 206 | <BaseControl.VisualLabel> |
| 207 | {__("Button Text Color", "presto-player")} |
| 208 | </BaseControl.VisualLabel> |
| 209 | <ColorPopup |
| 210 | color={cta?.button_text_color || "#ffffff"} |
| 211 | setColor={(value) => |
| 212 | updateEmailState({ |
| 213 | button_text_color: value && value.hex, |
| 214 | }) |
| 215 | } |
| 216 | /> |
| 217 | </Flex> |
| 218 | </BaseControl> |
| 219 | |
| 220 | <h3>{__("Integrate", "presto-player")}</h3> |
| 221 | <BaseControl> |
| 222 | <ChooseProvider |
| 223 | updateEmailState={updateEmailState} |
| 224 | options={email_collection} |
| 225 | /> |
| 226 | </BaseControl> |
| 227 | |
| 228 | <h3>{__("Style", "presto-player")}</h3> |
| 229 | |
| 230 | <BaseControl> |
| 231 | <RangeControl |
| 232 | label={__("Round Corners", "presto-player")} |
| 233 | help={__("Border radius of form elements.", "presto-player")} |
| 234 | value={email_collection?.border_radius || 0} |
| 235 | onChange={(border_radius) => updateEmailState({ border_radius })} |
| 236 | min={0} |
| 237 | max={25} |
| 238 | css={css` |
| 239 | padding-left: 4px; |
| 240 | .components-range-control__root { |
| 241 | align-items: flex-start; |
| 242 | } |
| 243 | `} |
| 244 | /> |
| 245 | </BaseControl> |
| 246 | </> |
| 247 | )} |
| 248 | </div> |
| 249 | ); |
| 250 | } |
| 251 |