parts
1 week ago
ActionBar.js
1 week ago
ActionBar.scss
1 week ago
Behavior.js
2 years ago
CTA.js
1 week ago
CTA.scss
1 week ago
Controls.js
5 years ago
Edit.js
1 week ago
Edit.scss
1 week ago
Email.js
1 week ago
Email.scss
1 week ago
Preset.js
4 years ago
Search.js
3 years ago
Style.js
1 week ago
Style.scss
1 week ago
Watermark.js
4 years ago
index.js
1 week ago
index.scss
1 week ago
Watermark.js
149 lines
| 1 | /** |
| 2 | * WordPress dependencies |
| 3 | */ |
| 4 | const { __ } = wp.i18n; |
| 5 | |
| 6 | const { |
| 7 | ToggleControl, |
| 8 | BaseControl, |
| 9 | RadioControl, |
| 10 | Flex, |
| 11 | RangeControl, |
| 12 | } = wp.components; |
| 13 | |
| 14 | const { useEffect } = wp.element; |
| 15 | |
| 16 | import DynamicText from "../overlays/components/DynamicText"; |
| 17 | |
| 18 | import ColorPopup from "../components/ColorPopup"; |
| 19 | |
| 20 | export default ({ state, updateState, className }) => { |
| 21 | const { watermark } = state; |
| 22 | |
| 23 | const defaults = { |
| 24 | text: __("Enter your watermark text.", "presto-player"), |
| 25 | position: "top-right", |
| 26 | color: "#fff", |
| 27 | backgroundColor: "#333", |
| 28 | opacity: 80, |
| 29 | }; |
| 30 | useEffect(() => { |
| 31 | Object.keys(defaults).forEach((key) => { |
| 32 | if (state?.watermark?.[key] === undefined) { |
| 33 | updateWatermarkState({ |
| 34 | [key]: defaults[key], |
| 35 | }); |
| 36 | } |
| 37 | }); |
| 38 | }, [state]); |
| 39 | |
| 40 | const updateWatermarkState = (updated) => { |
| 41 | updateState({ |
| 42 | ...state, |
| 43 | watermark: { |
| 44 | ...watermark, |
| 45 | ...updated, |
| 46 | }, |
| 47 | }); |
| 48 | }; |
| 49 | |
| 50 | return ( |
| 51 | <div className={className}> |
| 52 | <BaseControl> |
| 53 | <h3>{__("Dynamic Watermark Text", "presto-player")}</h3> |
| 54 | </BaseControl> |
| 55 | <BaseControl className="presto-player__control--watermark"> |
| 56 | <ToggleControl |
| 57 | label={__("Enable", "presto-player")} |
| 58 | help={__( |
| 59 | "Add a simulated dynamic watermark over your video.", |
| 60 | "presto-player" |
| 61 | )} |
| 62 | onChange={(enabled) => { |
| 63 | updateWatermarkState({ |
| 64 | enabled, |
| 65 | }); |
| 66 | }} |
| 67 | checked={watermark?.enabled} |
| 68 | /> |
| 69 | </BaseControl> |
| 70 | |
| 71 | {watermark?.enabled && ( |
| 72 | <div> |
| 73 | <DynamicText |
| 74 | text={watermark?.text} |
| 75 | update={({ text }) => { |
| 76 | updateWatermarkState({ |
| 77 | text, |
| 78 | }); |
| 79 | }} |
| 80 | /> |
| 81 | |
| 82 | <BaseControl className={className}> |
| 83 | <RadioControl |
| 84 | label={__("Position", "presto-player")} |
| 85 | options={[ |
| 86 | { label: __("Top Right", "presto-player"), value: "top-right" }, |
| 87 | { label: __("Top Left", "presto-player"), value: "top-left" }, |
| 88 | { |
| 89 | label: __("Change Every 10 Seconds", "presto-player"), |
| 90 | value: "randomize", |
| 91 | }, |
| 92 | ]} |
| 93 | selected={watermark?.position || "top-right"} |
| 94 | onChange={(position) => |
| 95 | updateWatermarkState({ |
| 96 | position, |
| 97 | }) |
| 98 | } |
| 99 | /> |
| 100 | </BaseControl> |
| 101 | |
| 102 | <BaseControl className="presto-player__control-text-color"> |
| 103 | <Flex> |
| 104 | <BaseControl.VisualLabel> |
| 105 | {__("Text Color", "presto-player")} |
| 106 | </BaseControl.VisualLabel> |
| 107 | <ColorPopup |
| 108 | color={watermark?.color || "#fff"} |
| 109 | setColor={(value) => |
| 110 | updateWatermarkState({ |
| 111 | color: value && value.hex, |
| 112 | }) |
| 113 | } |
| 114 | /> |
| 115 | </Flex> |
| 116 | </BaseControl> |
| 117 | |
| 118 | <BaseControl className="presto-player__control-text-color"> |
| 119 | <Flex> |
| 120 | <BaseControl.VisualLabel> |
| 121 | {__("Background Color", "presto-player")} |
| 122 | </BaseControl.VisualLabel> |
| 123 | <ColorPopup |
| 124 | color={watermark?.backgroundColor || "#333"} |
| 125 | setColor={(value) => |
| 126 | updateWatermarkState({ |
| 127 | backgroundColor: value && value.hex, |
| 128 | }) |
| 129 | } |
| 130 | /> |
| 131 | </Flex> |
| 132 | </BaseControl> |
| 133 | |
| 134 | <BaseControl> |
| 135 | <RangeControl |
| 136 | label={__("Opacity", "presto-player")} |
| 137 | help={__("Opacity percentage of the watermark.", "presto-player")} |
| 138 | value={watermark?.opacity || 100} |
| 139 | onChange={(opacity) => updateWatermarkState({ opacity })} |
| 140 | min={0} |
| 141 | max={100} |
| 142 | /> |
| 143 | </BaseControl> |
| 144 | </div> |
| 145 | )} |
| 146 | </div> |
| 147 | ); |
| 148 | }; |
| 149 |