@open-tender/ui
Version:
A component library for use with the Open Tender web app
23 lines (22 loc) • 1.05 kB
JavaScript
import { __rest } from "tslib";
import { makeProps } from './elements';
export const makeImageUrl = (entity) => {
const { app_image_url, small_image_url, large_image_url } = entity;
const imageUrl = large_image_url || small_image_url || app_image_url;
return imageUrl || null;
};
export const makeImageProps = (config, className, imageUrl, apiUrl, placeholder) => {
const props = makeProps(config, className);
const { style } = props, rest = __rest(props, ["style"]);
if (!imageUrl) {
if (!placeholder)
return props;
const imageStyle = Object.assign(Object.assign({}, style), { backgroundImage: `url(${placeholder})` });
return Object.assign(Object.assign({}, rest), { style: imageStyle });
}
const localUrl = imageUrl.startsWith('/cloud-files')
? `${apiUrl}` + imageUrl
: imageUrl;
const imageStyle = Object.assign(Object.assign({}, style), { backgroundImage: `url(${localUrl})` });
return Object.assign(Object.assign({}, rest), { style: imageStyle });
};