@siratik/wp-component-library 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Settings Media Upload Component
|
|
3
3
|
* Designed for admin settings contexts (not block editor)
|
|
4
4
|
*/
|
|
5
|
-
import { MediaUpload
|
|
5
|
+
import { MediaUpload } from "@wordpress/media-utils";
|
|
6
6
|
import { Button, Flex, Placeholder } from "@wordpress/components";
|
|
7
7
|
import { useSelect } from "@wordpress/data";
|
|
8
8
|
import { __ } from "@wordpress/i18n";
|
|
@@ -145,40 +145,39 @@ function SettingsMediaUpload({
|
|
|
145
145
|
|
|
146
146
|
{/* Buttons */}
|
|
147
147
|
<StyledButtons>
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
<Button
|
|
156
|
-
variant="secondary"
|
|
157
|
-
onClick={open}
|
|
158
|
-
size="default"
|
|
159
|
-
>
|
|
160
|
-
{buttonTitle ||
|
|
161
|
-
(hasImage
|
|
162
|
-
? __("Change Image", "wp-component-library")
|
|
163
|
-
: __("Upload Image", "wp-component-library")
|
|
164
|
-
)
|
|
165
|
-
}
|
|
166
|
-
</Button>
|
|
167
|
-
)}
|
|
168
|
-
/>
|
|
169
|
-
|
|
170
|
-
{hasImage && (
|
|
148
|
+
{/* Settings pages are admin-only; the media frame and upload endpoint check upload permissions. */}
|
|
149
|
+
<Flex gap={2}>
|
|
150
|
+
<MediaUpload
|
|
151
|
+
onSelect={onSelect}
|
|
152
|
+
allowedTypes={ALLOWED_MEDIA_TYPES}
|
|
153
|
+
value={imageId}
|
|
154
|
+
render={({ open }) => (
|
|
171
155
|
<Button
|
|
172
156
|
variant="secondary"
|
|
173
|
-
|
|
174
|
-
onClick={onRemove}
|
|
157
|
+
onClick={open}
|
|
175
158
|
size="default"
|
|
176
159
|
>
|
|
177
|
-
{
|
|
160
|
+
{buttonTitle ||
|
|
161
|
+
(hasImage
|
|
162
|
+
? __("Change Image", "wp-component-library")
|
|
163
|
+
: __("Upload Image", "wp-component-library")
|
|
164
|
+
)
|
|
165
|
+
}
|
|
178
166
|
</Button>
|
|
179
167
|
)}
|
|
180
|
-
|
|
181
|
-
|
|
168
|
+
/>
|
|
169
|
+
|
|
170
|
+
{hasImage && (
|
|
171
|
+
<Button
|
|
172
|
+
variant="secondary"
|
|
173
|
+
isDestructive={true}
|
|
174
|
+
onClick={onRemove}
|
|
175
|
+
size="default"
|
|
176
|
+
>
|
|
177
|
+
{__("Remove Image", "wp-component-library")}
|
|
178
|
+
</Button>
|
|
179
|
+
)}
|
|
180
|
+
</Flex>
|
|
182
181
|
</StyledButtons>
|
|
183
182
|
</StyledSettingsMediaUpload>
|
|
184
183
|
);
|