parts
3 years ago
ActionBar.js
4 years ago
Behavior.js
4 years ago
CTA.js
4 years ago
Controls.js
5 years ago
Edit.js
3 years ago
Email.js
4 years ago
Preset.js
4 years ago
Search.js
3 years ago
Style.js
5 years ago
Watermark.js
4 years ago
index.js
4 years ago
ActionBar.js
290 lines
| 1 | /** |
| 2 | * WordPress dependencies |
| 3 | */ |
| 4 | const { __ } = wp.i18n; |
| 5 | const { |
| 6 | ToggleControl, |
| 7 | Flex, |
| 8 | Button, |
| 9 | BaseControl, |
| 10 | RangeControl, |
| 11 | TextControl, |
| 12 | SelectControl, |
| 13 | TextareaControl, |
| 14 | } = wp.components; |
| 15 | |
| 16 | const { useEffect, useState } = wp.element; |
| 17 | const { useSelect } = wp.data; |
| 18 | |
| 19 | import ColorPopup from "../components/ColorPopup"; |
| 20 | import UrlSelect from "../components/UrlSelect"; |
| 21 | import YoutubeChannelId from "./parts/YoutubeChannelId"; |
| 22 | |
| 23 | export default function ({ state, updateState, className, value, setValue }) { |
| 24 | const { action_bar } = state; |
| 25 | const [editYoutube, setEditYoutube] = useState(false); |
| 26 | |
| 27 | const branding = useSelect((select) => { |
| 28 | return select("presto-player/player").branding(); |
| 29 | }); |
| 30 | const youtube = useSelect((select) => { |
| 31 | return select("presto-player/player").youtube(); |
| 32 | }); |
| 33 | |
| 34 | const updateActionBar = (updated) => { |
| 35 | updateState({ |
| 36 | ...state, |
| 37 | action_bar: { |
| 38 | ...action_bar, |
| 39 | ...updated, |
| 40 | }, |
| 41 | }); |
| 42 | }; |
| 43 | |
| 44 | useEffect(() => { |
| 45 | if (!action_bar?.text) { |
| 46 | updateActionBar({ |
| 47 | text: "Like this?", |
| 48 | }); |
| 49 | } |
| 50 | if (!action_bar?.button_type) { |
| 51 | updateActionBar({ |
| 52 | button_type: "custom", |
| 53 | }); |
| 54 | } |
| 55 | |
| 56 | if (!action_bar?.button_text) { |
| 57 | updateActionBar({ |
| 58 | button_text: "Click Here", |
| 59 | }); |
| 60 | } |
| 61 | }, [state]); |
| 62 | |
| 63 | const renderYoutubeChannelForm = () => { |
| 64 | if (action_bar?.button_type !== "youtube") { |
| 65 | return; |
| 66 | } |
| 67 | |
| 68 | return editYoutube ? ( |
| 69 | <YoutubeChannelId |
| 70 | onClose={() => setEditYoutube(false)} |
| 71 | value={value} |
| 72 | setValue={setValue} |
| 73 | /> |
| 74 | ) : ( |
| 75 | <div> |
| 76 | <Button |
| 77 | isSecondary |
| 78 | onClick={(e) => { |
| 79 | e.preventDefault(); |
| 80 | setEditYoutube(true); |
| 81 | }} |
| 82 | > |
| 83 | {youtube?.channel_id |
| 84 | ? __("Update Youtube Channel Id", "presto-player") |
| 85 | : __("Add Youtube Channel Id", "presto-player")} |
| 86 | </Button> |
| 87 | <br /> |
| 88 | <br /> |
| 89 | <br /> |
| 90 | </div> |
| 91 | ); |
| 92 | }; |
| 93 | |
| 94 | return ( |
| 95 | <div className={className}> |
| 96 | <BaseControl> |
| 97 | <h3>{__("Action Bar", "presto-player")}</h3> |
| 98 | </BaseControl> |
| 99 | <BaseControl className="presto-player__control--large-play"> |
| 100 | <ToggleControl |
| 101 | label={__("Enable", "presto-player")} |
| 102 | help={__( |
| 103 | "Show an action bar below your player while it's playing.", |
| 104 | "presto-player" |
| 105 | )} |
| 106 | onChange={(enabled) => { |
| 107 | updateActionBar({ |
| 108 | enabled, |
| 109 | }); |
| 110 | }} |
| 111 | checked={action_bar?.enabled} |
| 112 | /> |
| 113 | </BaseControl> |
| 114 | {!!action_bar?.enabled && ( |
| 115 | <> |
| 116 | <BaseControl className="presto-player__control--percentage-watched"> |
| 117 | <RangeControl |
| 118 | label={__("Display At (Percentage)", "presto-player")} |
| 119 | labelPosition="top" |
| 120 | onChange={(percentage_start) => { |
| 121 | updateActionBar({ |
| 122 | percentage_start, |
| 123 | }); |
| 124 | }} |
| 125 | marks={[ |
| 126 | { |
| 127 | value: 0, |
| 128 | label: __("Start", "presto-player"), |
| 129 | }, |
| 130 | { |
| 131 | value: 50, |
| 132 | label: __("50% Watched", "presto-player"), |
| 133 | }, |
| 134 | { |
| 135 | value: 100, |
| 136 | label: __("End", "presto-player"), |
| 137 | }, |
| 138 | ]} |
| 139 | shiftStep={5} |
| 140 | value={action_bar?.percentage_start || 0} |
| 141 | /> |
| 142 | </BaseControl> |
| 143 | |
| 144 | <BaseControl className="presto-player__control--large-play"> |
| 145 | <TextareaControl |
| 146 | label={__("Text", "presto-player")} |
| 147 | help={__("Action bar text.", "presto-player")} |
| 148 | value={action_bar?.text} |
| 149 | onChange={(text) => |
| 150 | updateActionBar({ |
| 151 | text, |
| 152 | }) |
| 153 | } |
| 154 | /> |
| 155 | </BaseControl> |
| 156 | |
| 157 | <BaseControl className="presto-player__control--large-play"> |
| 158 | <Flex> |
| 159 | <BaseControl.VisualLabel> |
| 160 | {__("Action Bar Background", "presto-player")} |
| 161 | </BaseControl.VisualLabel> |
| 162 | <ColorPopup |
| 163 | color={action_bar?.background_color || "#1d1d1d"} |
| 164 | setColor={(value) => |
| 165 | updateActionBar({ |
| 166 | background_color: value && value.hex, |
| 167 | }) |
| 168 | } |
| 169 | /> |
| 170 | </Flex> |
| 171 | </BaseControl> |
| 172 | |
| 173 | <BaseControl> |
| 174 | <h3>{__("Button", "presto-player")}</h3> |
| 175 | </BaseControl> |
| 176 | |
| 177 | <BaseControl className="presto-player__control--button-type"> |
| 178 | <SelectControl |
| 179 | label={__("Button Type", "presto-player")} |
| 180 | value={action_bar?.button_type} |
| 181 | options={[ |
| 182 | { |
| 183 | value: "custom", |
| 184 | label: __("Custom", "presto-player"), |
| 185 | }, |
| 186 | { |
| 187 | value: "youtube", |
| 188 | label: __("YouTube Subscribe", "presto-player"), |
| 189 | }, |
| 190 | { |
| 191 | value: "none", |
| 192 | label: __("None", "presto-player"), |
| 193 | }, |
| 194 | ]} |
| 195 | onChange={(button_type) => |
| 196 | updateActionBar({ |
| 197 | button_type, |
| 198 | }) |
| 199 | } |
| 200 | /> |
| 201 | </BaseControl> |
| 202 | |
| 203 | {action_bar?.button_type === "youtube" && youtube?.channel_id && ( |
| 204 | <ToggleControl |
| 205 | label={__("Show Count", "presto-player")} |
| 206 | help={__("Show your follower count.", "presto-player")} |
| 207 | onChange={(button_count) => { |
| 208 | updateActionBar({ |
| 209 | button_count, |
| 210 | }); |
| 211 | }} |
| 212 | checked={action_bar?.button_count} |
| 213 | /> |
| 214 | )} |
| 215 | |
| 216 | {renderYoutubeChannelForm()} |
| 217 | |
| 218 | {action_bar?.button_type === "custom" && ( |
| 219 | <div> |
| 220 | <BaseControl className="presto-player__control--button-text"> |
| 221 | <TextControl |
| 222 | label={__("Button Text", "presto-player")} |
| 223 | help={<p>{__("Submit button text", "presto-player")}</p>} |
| 224 | value={action_bar?.button_text} |
| 225 | onChange={(button_text) => updateActionBar({ button_text })} |
| 226 | /> |
| 227 | </BaseControl> |
| 228 | <BaseControl className="presto-player__control--button-text"> |
| 229 | <BaseControl.VisualLabel> |
| 230 | <p> {__("Button Link", "presto-player")}</p> |
| 231 | </BaseControl.VisualLabel> |
| 232 | <UrlSelect |
| 233 | setSettings={(val) => { |
| 234 | updateActionBar({ |
| 235 | button_link: val, |
| 236 | }); |
| 237 | }} |
| 238 | settings={action_bar?.button_link || {}} |
| 239 | /> |
| 240 | </BaseControl> |
| 241 | <BaseControl className="presto-player__control--button-radius"> |
| 242 | <RangeControl |
| 243 | label={__("Round Corners", "presto-player")} |
| 244 | help={__("Border radius of the button", "presto-player")} |
| 245 | value={action_bar?.button_radius || 0} |
| 246 | onChange={(button_radius) => |
| 247 | updateActionBar({ button_radius }) |
| 248 | } |
| 249 | min={0} |
| 250 | max={25} |
| 251 | /> |
| 252 | </BaseControl> |
| 253 | <BaseControl className="presto-player__control--button-color"> |
| 254 | <Flex> |
| 255 | <BaseControl.VisualLabel> |
| 256 | {__("Button Color", "presto-player")} |
| 257 | </BaseControl.VisualLabel> |
| 258 | <ColorPopup |
| 259 | color={action_bar?.button_color || branding?.color} |
| 260 | setColor={(value) => |
| 261 | updateActionBar({ |
| 262 | button_color: value && value.hex, |
| 263 | }) |
| 264 | } |
| 265 | /> |
| 266 | </Flex> |
| 267 | </BaseControl> |
| 268 | <BaseControl className="presto-player__control--button-text-color"> |
| 269 | <Flex> |
| 270 | <BaseControl.VisualLabel> |
| 271 | {__("Button Text Color", "presto-player")} |
| 272 | </BaseControl.VisualLabel> |
| 273 | <ColorPopup |
| 274 | color={action_bar?.button_text_color || "#ffffff"} |
| 275 | setColor={(value) => |
| 276 | updateActionBar({ |
| 277 | button_text_color: value && value.hex, |
| 278 | }) |
| 279 | } |
| 280 | /> |
| 281 | </Flex> |
| 282 | </BaseControl> |
| 283 | </div> |
| 284 | )} |
| 285 | </> |
| 286 | )} |
| 287 | </div> |
| 288 | ); |
| 289 | } |
| 290 |