UNPKG

@onesy/ui-react

Version:
157 lines 8.17 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; const _excluded = ["size", "title", "description", "button", "mediaPosition", "media", "MainProps", "TitleProps", "WrapperProps", "WrapperMainProps", "WrapperTextProps", "DescriptionProps", "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 { is, textToInnerHTML } from '@onesy/utils'; import { classNames, style as styleMethod, useOnesyTheme } from '@onesy/style-react'; import TextElement from '../Text'; import ImageElement from '../Image'; import SectionElement from '../Section/Section'; import AudioPlayerElement from '../AudioPlayer'; import VideoPlayerElement from '../VideoPlayer'; import LineElement from '../Line'; import TypeElement from '../Type'; import ButtonElement from '../Button'; import { staticClassName } from '../utils'; const useStyle = styleMethod(theme => ({ root: {}, main: { '&.onesy-Line-direction-row': { '& > *': { width: '50%' } } } }), { name: 'onesy-SectionTextMedia' }); const SectionTextMedia = /*#__PURE__*/React.forwardRef((props_, ref) => { const theme = useOnesyTheme(); const l = theme.l; const props = React.useMemo(() => _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.onesySectionTextMedia?.props?.default), props_), [props_]); const Line = React.useMemo(() => theme?.elements?.Line || LineElement, [theme]); const Text = React.useMemo(() => theme?.elements?.Text || TextElement, [theme]); const Image = React.useMemo(() => theme?.elements?.Image || ImageElement, [theme]); const Section = React.useMemo(() => theme?.elements?.Section || SectionElement, [theme]); const AudioPlayer = React.useMemo(() => theme?.elements?.AudioPlayer || AudioPlayerElement, [theme]); const VideoPlayer = React.useMemo(() => theme?.elements?.VideoPlayer || VideoPlayerElement, [theme]); const Type = React.useMemo(() => theme?.elements?.Type || TypeElement, [theme]); const Button = React.useMemo(() => theme?.elements?.Button || ButtonElement, [theme]); const { classes } = useStyle(); const { size, title, description, button, mediaPosition = 'top', media, MainProps, TitleProps, WrapperProps, WrapperMainProps, WrapperTextProps, DescriptionProps, MediaProps, ImageProps, AudioProps, VideoProps, OtherProps, className } = props, other = _objectWithoutProperties(props, _excluded); const refs = { root: React.useRef(undefined) }; let mediaElement; const mediaProps = _objectSpread({ size, themed: true, color: 'primary' }, MediaProps); const mime = media?.mime || ''; if (mime.includes('image')) { mediaElement = /*#__PURE__*/React.createElement(Image, _extends({ src: media?.url || media?.urlSmall || (is('string', media) ? media : '') }, mediaProps, MediaProps, ImageProps, { className: classNames([staticClassName('SectionTextMedia', theme) && ['onesy-SectionTextMedia-item', 'onesy-SectionTextMedia-item-image'], MediaProps?.className, ImageProps?.className]) })); } if (mime.includes('audio')) { mediaElement = /*#__PURE__*/React.createElement(AudioPlayer, _extends({}, media, mediaProps, MediaProps, AudioProps, { className: classNames([staticClassName('SectionTextMedia', theme) && ['onesy-SectionTextMedia-item', 'onesy-SectionTextMedia-item-audio'], MediaProps?.className, AudioProps?.className]) })); } if (mime.includes('video')) { mediaElement = /*#__PURE__*/React.createElement(VideoPlayer, _extends({}, media, mediaProps, MediaProps, VideoProps, { className: classNames([staticClassName('SectionTextMedia', theme) && ['onesy-SectionTextMedia-item', 'onesy-SectionTextMedia-item-video'], MediaProps?.className, VideoProps?.className]) })); } const main = /*#__PURE__*/React.createElement(Line, _extends({ gap: 3, direction: "column", align: ['left', 'top', 'bottom'].includes(mediaPosition) ? 'flex-start' : 'flex-end', fullWidth: true }, WrapperMainProps, { className: classNames([staticClassName('SectionTextMedia', theme) && ['onesy-SectionTextMedia-wrapper-main'], WrapperMainProps?.className]) }), /*#__PURE__*/React.createElement(Line, _extends({ gap: 2, direction: "column", align: ['left', 'top', 'bottom'].includes(mediaPosition) ? 'flex-start' : 'flex-end', fullWidth: true }, WrapperTextProps, { className: classNames([staticClassName('SectionTextMedia', theme) && ['onesy-SectionTextMedia-wrapper-text'], WrapperTextProps?.className]) }), is('string', title) && /*#__PURE__*/React.createElement(Type, _extends({ version: size === 'large' ? 'h1' : size === 'regular' ? 'h2' : 'h3', align: ['left', 'top', 'bottom'].includes(mediaPosition) ? 'start' : 'end', dangerouslySetInnerHTML: { __html: textToInnerHTML(title) } }, TitleProps, { className: classNames([staticClassName('SectionTextMedia', theme) && ['onesy-SectionTextMedia-title'], TitleProps?.className]) })), is('string', description) && /*#__PURE__*/React.createElement(Text, _extends({ align: ['left', 'top', 'bottom'].includes(mediaPosition) ? 'start' : 'end', columns: 1, TypeProps: _objectSpread(_objectSpread({}, DescriptionProps?.TypeProps), {}, { version: size === 'large' ? 'b1' : [undefined, 'regular'].includes(size) ? 'b2' : 'b3' }), value: description }, DescriptionProps, { className: classNames([staticClassName('SectionTextMedia', theme) && ['onesy-SectionTextMedia-description'], DescriptionProps?.className]) }))), button && /*#__PURE__*/React.createElement(Button, _extends({ tonal: true, version: "filled", color: "primary", size: size, onClick: (button.to || button.link) && window.open(button.to || button.link, 'blank') }, button.props, { className: classNames([staticClassName('SectionAction', theme) && ['onesy-SectionTextMedia-button'], button.props?.className, classes.button]) }), button.text || l('Click here'))); return /*#__PURE__*/React.createElement(Section, _extends({ ref: item => { if (ref) { if (is('function', ref)) ref(item);else ref.current = item; } refs.root.current = item; }, size: size, className: classNames([staticClassName('SectionTextMedia', theme) && ['onesy-SectionTextMedia-root', `onesy-SectionTextMedia-size-${size}`], className, classes.root]) }, other), /*#__PURE__*/React.createElement(Line, _extends({ gap: 5, direction: { default: ['left', 'right'].includes(mediaPosition) ? 'row' : 'column', 1100: 'column' }, align: ['left', 'right'].includes(mediaPosition) ? 'flex-start' : 'center', justify: ['left', 'right'].includes(mediaPosition) ? 'flex-start' : 'center', fullWidth: true }, MainProps, { className: classNames([staticClassName('SectionTextMedia', theme) && ['onesy-SectionTextMedia-main'], MainProps?.className, classes.main]) }), ['top', 'left'].includes(mediaPosition) && mediaElement, main, ['bottom', 'right'].includes(mediaPosition) && mediaElement)); }); SectionTextMedia.displayName = 'onesy-SectionTextMedia'; export default SectionTextMedia;