index.js
165 lines
| 1 | /** |
| 2 | * WordPress dependencies |
| 3 | */ |
| 4 | const { __ } = wp.i18n; |
| 5 | const { |
| 6 | ColorPicker, |
| 7 | Button, |
| 8 | withNotices, |
| 9 | BaseControl, |
| 10 | RangeControl, |
| 11 | } = wp.components; |
| 12 | const { MediaUpload, MediaUploadCheck } = wp.blockEditor; |
| 13 | const { useInstanceId } = wp.compose; |
| 14 | const { useState } = wp.element; |
| 15 | const { dispatch, useSelect } = wp.data; |
| 16 | import ProBadge from "@/admin/blocks/shared/components/ProBadge"; |
| 17 | |
| 18 | const VIDEO_LOGO_ALLOWED_MEDIA_TYPES = ["image"]; |
| 19 | |
| 20 | function PlayerSettings({ setAttributes, attributes, type }) { |
| 21 | const instanceId = useInstanceId(PlayerSettings); |
| 22 | const [pickerRender, setPickerRender] = useState(1); |
| 23 | |
| 24 | // get branding options |
| 25 | const branding = useSelect((select) => { |
| 26 | return select("presto-player/player").branding(); |
| 27 | }); |
| 28 | // save options |
| 29 | const saveOptions = async () => { |
| 30 | await dispatch("presto-player/player").saveOptions({ |
| 31 | branding, |
| 32 | }); |
| 33 | wp.data.dispatch("core/notices").createNotice( |
| 34 | "success", // Can be one of: success, info, warning, error. |
| 35 | "Player branding saved.", // Text string to display. |
| 36 | { |
| 37 | type: "snackbar", |
| 38 | isDismissible: true, // Whether the user can dismiss the notice. |
| 39 | // Any actions the user can perform. |
| 40 | } |
| 41 | ); |
| 42 | }; |
| 43 | |
| 44 | function onSelectLogo(image) { |
| 45 | dispatch("presto-player/player").updateBranding("logo", image.url); |
| 46 | } |
| 47 | |
| 48 | function onRemoveLogo() { |
| 49 | dispatch("presto-player/player").updateBranding("logo", ""); |
| 50 | } |
| 51 | |
| 52 | return ( |
| 53 | <div className="presto-player__panel--branding"> |
| 54 | {type !== "audio" && ( |
| 55 | <p> |
| 56 | {__( |
| 57 | "Here you can select the global player branding This will apply to all players on the site.", |
| 58 | "presto-player" |
| 59 | )} |
| 60 | </p> |
| 61 | )} |
| 62 | |
| 63 | <MediaUploadCheck> |
| 64 | <BaseControl className="editor-video-poster-control"> |
| 65 | {type !== "audio" && ( |
| 66 | <> |
| 67 | <BaseControl.VisualLabel> |
| 68 | <p> |
| 69 | {__("Logo Overlay", "presto-player")}{" "} |
| 70 | {!prestoPlayer?.isPremium && <ProBadge />} |
| 71 | </p> |
| 72 | </BaseControl.VisualLabel> |
| 73 | <MediaUpload |
| 74 | title={__("Select logo overlay image", "presto-player")} |
| 75 | onSelect={onSelectLogo} |
| 76 | allowedTypes={VIDEO_LOGO_ALLOWED_MEDIA_TYPES} |
| 77 | render={({ open }) => ( |
| 78 | <Button |
| 79 | className="presto-setting__logo" |
| 80 | isSecondary |
| 81 | onClick={() => { |
| 82 | if (!prestoPlayer?.isPremium) { |
| 83 | dispatch("presto-player/player").setProModal(true); |
| 84 | return; |
| 85 | } |
| 86 | open(); |
| 87 | }} |
| 88 | aria-describedby={`video-block__logo-image-description-${instanceId}`} |
| 89 | > |
| 90 | {!branding?.logo |
| 91 | ? __("Select", "presto-player") |
| 92 | : __("Replace", "presto-player")} |
| 93 | </Button> |
| 94 | )} |
| 95 | /> |
| 96 | </> |
| 97 | )} |
| 98 | |
| 99 | <p id={`video-block__logo-image-description-${instanceId}`} hidden> |
| 100 | {branding?.logo |
| 101 | ? sprintf( |
| 102 | /* translators: %s: poster image URL. */ |
| 103 | __("The current logo image url is %s", "presto-player"), |
| 104 | branding?.logo |
| 105 | ) |
| 106 | : __( |
| 107 | "There is no logo image currently selected", |
| 108 | "presto-player" |
| 109 | )} |
| 110 | </p> |
| 111 | {!!branding?.logo && ( |
| 112 | <Button onClick={onRemoveLogo} isTertiary> |
| 113 | {__("Remove", "presto-player")} |
| 114 | </Button> |
| 115 | )} |
| 116 | </BaseControl> |
| 117 | </MediaUploadCheck> |
| 118 | |
| 119 | {!!branding?.logo && ( |
| 120 | <RangeControl |
| 121 | label={__("Logo Max Width", "presto-player")} |
| 122 | value={branding?.logo_width || 150} |
| 123 | onChange={(width) => |
| 124 | dispatch("presto-player/player").updateBranding("logo_width", width) |
| 125 | } |
| 126 | min={1} |
| 127 | max={400} |
| 128 | /> |
| 129 | )} |
| 130 | |
| 131 | <ColorPicker |
| 132 | color={branding?.color} |
| 133 | onChangeComplete={(value) => { |
| 134 | dispatch("presto-player/player").updateBranding("color", value.hex); |
| 135 | }} |
| 136 | key={pickerRender} |
| 137 | disableAlpha |
| 138 | /> |
| 139 | |
| 140 | {branding?.color && ( |
| 141 | <BaseControl> |
| 142 | <Button |
| 143 | isSecondary |
| 144 | onClick={() => { |
| 145 | dispatch("presto-player/player").updateBranding( |
| 146 | "color", |
| 147 | prestoPlayer?.defaults?.color || "#00b3ff" |
| 148 | ); |
| 149 | setPickerRender(pickerRender + 1); |
| 150 | }} |
| 151 | > |
| 152 | {__("Reset Color", "presto-player")} |
| 153 | </Button> |
| 154 | </BaseControl> |
| 155 | )} |
| 156 | |
| 157 | <Button isPrimary onClick={saveOptions}> |
| 158 | {__("Save Branding", "presto-player")} |
| 159 | </Button> |
| 160 | </div> |
| 161 | ); |
| 162 | } |
| 163 | |
| 164 | export default withNotices(PlayerSettings); |
| 165 |