UNPKG

@onesy/ui-react

Version:
150 lines 6.9 kB
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; const _excluded = ["ref", "value", "size", "name", "IconDocument", "MediaProps", "ImageProps", "AudioProps", "VideoProps", "OtherProps", "className"]; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } import React from 'react'; import { cleanValue, is } from '@onesy/utils'; import { classNames, style as styleMethod, useOnesyTheme } from '@onesy/style-react'; import IconMaterialDraft from '@onesy/icons-material-rounded-react/IconMaterialDraftW100'; import AudioPlayerElement from '../AudioPlayer'; import ImageElement from '../Image'; import InteractionElement from '../Interaction'; import LineElement from '../Line'; import SectionElement from '../Section/Section'; import TypeElement from '../Type'; import VideoPlayerElement from '../VideoPlayer'; import { staticClassName } from '../utils'; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; const useStyle = styleMethod(theme => ({ root: {}, name: { wordBreak: 'break-word' }, other: { position: 'relative', aspectRatio: '3 / 4', cursor: 'pointer', userSelect: 'none', background: theme.palette.background.secondary.tertiary, boxShadow: theme.shadows.values.default[1] }, otherWrapper_size_small: { maxWidth: '74px', width: '90vw' }, otherWrapper_size_regular: { maxWidth: '94px', width: '90vw' }, otherWrapper_size_large: { maxWidth: '114px', width: '90vw' }, other_size_small: { borderRadius: theme.methods.shape.radius.value(1) }, other_size_regular: { borderRadius: theme.methods.shape.radius.value(2) }, other_size_large: { borderRadius: theme.methods.shape.radius.value(3) } }), { name: 'onesy-SectionMedia' }); const Element = props_ => { const theme = useOnesyTheme(); const l = theme.l; const props = _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.onesySectionMedia?.props?.default), props_); const Line = theme?.elements?.Line || LineElement; const Section = theme?.elements?.Section || SectionElement; const Image = theme?.elements?.Image || ImageElement; const AudioPlayer = theme?.elements?.AudioPlayer || AudioPlayerElement; const VideoPlayer = theme?.elements?.VideoPlayer || VideoPlayerElement; const Interaction = theme?.elements?.Interaction || InteractionElement; const Type = theme?.elements?.Type || TypeElement; const { ref, value, size = 'regular', name, IconDocument = IconMaterialDraft, MediaProps, ImageProps, AudioProps, VideoProps, OtherProps, className } = props, other = _objectWithoutProperties(props, _excluded); const { classes } = useStyle(); const refs = { root: React.useRef(undefined) }; const onOpenMedia = media => { window.open(media.url || media.urlSmall, 'blank_'); }; let element; if (value) { const mime = value.mime; if (mime?.includes('image')) element = /*#__PURE__*/_jsx(Image, _objectSpread(_objectSpread(_objectSpread({ src: value?.url || value?.urlSmall || (is('string', value) ? value : ''), maxWidth: "rg", fullWidth: true }, MediaProps), ImageProps), {}, { className: classNames([staticClassName('SectionMedia', theme) && ['onesy-SectionMedia-item', 'onesy-SectionMedia-item-image'], MediaProps?.className, ImageProps?.className]) }));else if (mime?.includes('audio')) element = /*#__PURE__*/_jsx(AudioPlayer, _objectSpread(_objectSpread(_objectSpread(_objectSpread({ size: size }, value), MediaProps), AudioProps), {}, { className: classNames([staticClassName('SectionMedia', theme) && ['onesy-SectionMedia-item', 'onesy-SectionMedia-item-audio'], MediaProps?.className, AudioProps?.className]) }));else if (mime?.includes('video')) element = /*#__PURE__*/_jsx(VideoPlayer, _objectSpread(_objectSpread(_objectSpread(_objectSpread({ size: size }, value), MediaProps), VideoProps), {}, { className: classNames([staticClassName('SectionMedia', theme) && ['onesy-SectionMedia-item', 'onesy-SectionMedia-item-video'], MediaProps?.className, VideoProps?.className]) }));else element = /*#__PURE__*/_jsx(Line, { gap: 1, className: classNames([staticClassName('SectionMedia', theme) && ['onesy-SectionMedia-wrapper', 'onesy-SectionMedia-wrapper-other'], classes.wrapper, classes[`otherWrapper_size_${size}`]]), children: /*#__PURE__*/_jsxs(Line, _objectSpread(_objectSpread(_objectSpread({ align: "center", justify: "center", onClick: () => onOpenMedia(value), fullWidth: true }, MediaProps), OtherProps), {}, { className: classNames([staticClassName('SectionMedia', theme) && ['onesy-SectionMedia-item', 'onesy-SectionMedia-item-other'], MediaProps?.className, OtherProps?.className, classes.other, classes[`other_size_${size}`]]), children: [/*#__PURE__*/_jsx(Interaction, {}), /*#__PURE__*/_jsx(IconDocument, { size: size === 'large' ? 44 : size === 'regular' ? 34 : 24 })] })) }); } return /*#__PURE__*/_jsx(Section, _objectSpread(_objectSpread({ ref: item => { if (ref) { if (is('function', ref)) ref(item);else ref.current = item; } refs.root.current = item; }, maxWidth: "small", align: "center", className: classNames([staticClassName('SectionMedia', theme) && ['onesy-SectionMedia-root', `onesy-SectionMedia-size-${size}`], className, classes.root]) }, other), {}, { children: /*#__PURE__*/_jsxs(Line, { align: "center", fullWidth: true, children: [element, name && /*#__PURE__*/_jsx(Type, { version: size === 'large' ? 't1' : size === 'regular' ? 't2' : 't3', align: "center", fullWidth: true, className: classNames([staticClassName('SectionMedia', theme) && ['onesy-SectionMedia-name'], classes.name]), children: cleanValue(value?.name || l('No name'), { capitalize: true }) })] }) })); }; Element.displayName = 'onesy-SectionMedia'; export default Element;