UNPKG

@onesy/ui-react

Version:
158 lines (157 loc) 10.1 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _react = _interopRequireDefault(require("react")); var _utils = require("@onesy/utils"); var _styleReact = require("@onesy/style-react"); var _IconMaterialDraftW = _interopRequireDefault(require("@onesy/icons-material-rounded-react/IconMaterialDraftW100")); var _AudioPlayer = _interopRequireDefault(require("../AudioPlayer")); var _Image = _interopRequireDefault(require("../Image")); var _Interaction = _interopRequireDefault(require("../Interaction")); var _Line = _interopRequireDefault(require("../Line")); var _Section = _interopRequireDefault(require("../Section/Section")); var _Type = _interopRequireDefault(require("../Type")); var _VideoPlayer = _interopRequireDefault(require("../VideoPlayer")); var _utils2 = require("../utils"); var _jsxRuntime = require("react/jsx-runtime"); 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) { (0, _defineProperty2.default)(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; } const useStyle = (0, _styleReact.style)(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_ => { var _theme$ui, _theme$ui2, _theme$elements, _theme$elements2, _theme$elements3, _theme$elements4, _theme$elements5, _theme$elements6, _theme$elements7; const theme = (0, _styleReact.useOnesyTheme)(); const l = theme.l; const props = _objectSpread(_objectSpread(_objectSpread({}, theme === null || theme === void 0 || (_theme$ui = theme.ui) === null || _theme$ui === void 0 || (_theme$ui = _theme$ui.elements) === null || _theme$ui === void 0 || (_theme$ui = _theme$ui.all) === null || _theme$ui === void 0 || (_theme$ui = _theme$ui.props) === null || _theme$ui === void 0 ? void 0 : _theme$ui.default), theme === null || theme === void 0 || (_theme$ui2 = theme.ui) === null || _theme$ui2 === void 0 || (_theme$ui2 = _theme$ui2.elements) === null || _theme$ui2 === void 0 || (_theme$ui2 = _theme$ui2.onesySectionMedia) === null || _theme$ui2 === void 0 || (_theme$ui2 = _theme$ui2.props) === null || _theme$ui2 === void 0 ? void 0 : _theme$ui2.default), props_); const Line = (theme === null || theme === void 0 || (_theme$elements = theme.elements) === null || _theme$elements === void 0 ? void 0 : _theme$elements.Line) || _Line.default; const Section = (theme === null || theme === void 0 || (_theme$elements2 = theme.elements) === null || _theme$elements2 === void 0 ? void 0 : _theme$elements2.Section) || _Section.default; const Image = (theme === null || theme === void 0 || (_theme$elements3 = theme.elements) === null || _theme$elements3 === void 0 ? void 0 : _theme$elements3.Image) || _Image.default; const AudioPlayer = (theme === null || theme === void 0 || (_theme$elements4 = theme.elements) === null || _theme$elements4 === void 0 ? void 0 : _theme$elements4.AudioPlayer) || _AudioPlayer.default; const VideoPlayer = (theme === null || theme === void 0 || (_theme$elements5 = theme.elements) === null || _theme$elements5 === void 0 ? void 0 : _theme$elements5.VideoPlayer) || _VideoPlayer.default; const Interaction = (theme === null || theme === void 0 || (_theme$elements6 = theme.elements) === null || _theme$elements6 === void 0 ? void 0 : _theme$elements6.Interaction) || _Interaction.default; const Type = (theme === null || theme === void 0 || (_theme$elements7 = theme.elements) === null || _theme$elements7 === void 0 ? void 0 : _theme$elements7.Type) || _Type.default; const { ref, value, size = 'regular', name, IconDocument = _IconMaterialDraftW.default, MediaProps, ImageProps, AudioProps, VideoProps, OtherProps, className } = props, other = (0, _objectWithoutProperties2.default)(props, _excluded); const { classes } = useStyle(); const refs = { root: _react.default.useRef(undefined) }; const onOpenMedia = media => { window.open(media.url || media.urlSmall, 'blank_'); }; let element; if (value) { const mime = value.mime; if (mime !== null && mime !== void 0 && mime.includes('image')) element = /*#__PURE__*/(0, _jsxRuntime.jsx)(Image, _objectSpread(_objectSpread(_objectSpread({ src: (value === null || value === void 0 ? void 0 : value.url) || (value === null || value === void 0 ? void 0 : value.urlSmall) || ((0, _utils.is)('string', value) ? value : ''), maxWidth: "rg", fullWidth: true }, MediaProps), ImageProps), {}, { className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionMedia', theme) && ['onesy-SectionMedia-item', 'onesy-SectionMedia-item-image'], MediaProps === null || MediaProps === void 0 ? void 0 : MediaProps.className, ImageProps === null || ImageProps === void 0 ? void 0 : ImageProps.className]) }));else if (mime !== null && mime !== void 0 && mime.includes('audio')) element = /*#__PURE__*/(0, _jsxRuntime.jsx)(AudioPlayer, _objectSpread(_objectSpread(_objectSpread(_objectSpread({ size: size }, value), MediaProps), AudioProps), {}, { className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionMedia', theme) && ['onesy-SectionMedia-item', 'onesy-SectionMedia-item-audio'], MediaProps === null || MediaProps === void 0 ? void 0 : MediaProps.className, AudioProps === null || AudioProps === void 0 ? void 0 : AudioProps.className]) }));else if (mime !== null && mime !== void 0 && mime.includes('video')) element = /*#__PURE__*/(0, _jsxRuntime.jsx)(VideoPlayer, _objectSpread(_objectSpread(_objectSpread(_objectSpread({ size: size }, value), MediaProps), VideoProps), {}, { className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionMedia', theme) && ['onesy-SectionMedia-item', 'onesy-SectionMedia-item-video'], MediaProps === null || MediaProps === void 0 ? void 0 : MediaProps.className, VideoProps === null || VideoProps === void 0 ? void 0 : VideoProps.className]) }));else element = /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, { gap: 1, className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionMedia', theme) && ['onesy-SectionMedia-wrapper', 'onesy-SectionMedia-wrapper-other'], classes.wrapper, classes[`otherWrapper_size_${size}`]]), children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, _objectSpread(_objectSpread(_objectSpread({ align: "center", justify: "center", onClick: () => onOpenMedia(value), fullWidth: true }, MediaProps), OtherProps), {}, { className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionMedia', theme) && ['onesy-SectionMedia-item', 'onesy-SectionMedia-item-other'], MediaProps === null || MediaProps === void 0 ? void 0 : MediaProps.className, OtherProps === null || OtherProps === void 0 ? void 0 : OtherProps.className, classes.other, classes[`other_size_${size}`]]), children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Interaction, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(IconDocument, { size: size === 'large' ? 44 : size === 'regular' ? 34 : 24 })] })) }); } return /*#__PURE__*/(0, _jsxRuntime.jsx)(Section, _objectSpread(_objectSpread({ ref: item => { if (ref) { if ((0, _utils.is)('function', ref)) ref(item);else ref.current = item; } refs.root.current = item; }, maxWidth: "small", align: "center", className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionMedia', theme) && ['onesy-SectionMedia-root', `onesy-SectionMedia-size-${size}`], className, classes.root]) }, other), {}, { children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, { align: "center", fullWidth: true, children: [element, name && /*#__PURE__*/(0, _jsxRuntime.jsx)(Type, { version: size === 'large' ? 't1' : size === 'regular' ? 't2' : 't3', align: "center", fullWidth: true, className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionMedia', theme) && ['onesy-SectionMedia-name'], classes.name]), children: (0, _utils.cleanValue)((value === null || value === void 0 ? void 0 : value.name) || l('No name'), { capitalize: true }) })] }) })); }; Element.displayName = 'onesy-SectionMedia'; var _default = exports.default = Element;