import React from "react"; import classes from "./WpMediaField.pcss"; import {WpUploadMedia} from "spotlight/admin-common/components/Wp/WpUploadMedia"; import {Button, ButtonType} from "spotlight/admin-common/components/Button"; import wp from "spotlight/admin-common/libs/wp"; interface Props { value: string; onChange: (url: string) => void; id?: string; title?: string; mediaType?: string; button?: string; buttonSet?: string; buttonChange?: string; } export const WpMediaField = ({id, title, mediaType, button, buttonSet, buttonChange, value, onChange}: Props) => { // If `button` prop is given, ignore `buttonSet` and `buttonChange` buttonSet = button === undefined ? buttonSet : button; buttonChange = button === undefined ? buttonChange : button; const hasValue = !!value; const buttonText = hasValue ? buttonChange : buttonSet; const handleSelect = (attachments: wp.media.Attachment[]) => { onChange && onChange(attachments[0].attributes.url); }; const handleRemove = () => { onChange && onChange(""); }; return ( { ({open}) => (
{hasValue && (
Custom profile picture
)} {hasValue && ( )}
) }
); };