@onesy/ui-react
Version:
UI for React
164 lines • 8.31 kB
JavaScript
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
const _excluded = ["ref", "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';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const useStyle = styleMethod(theme => ({
root: {},
main: {
'&.onesy-Line-direction-row': {
'& > *': {
width: '50%'
}
}
}
}), {
name: 'onesy-SectionTextMedia'
});
const SectionTextMedia = props_ => {
const theme = useOnesyTheme();
const l = theme.l;
const props = _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.onesySectionTextMedia?.props?.default), props_);
const Line = theme?.elements?.Line || LineElement;
const Text = theme?.elements?.Text || TextElement;
const Image = theme?.elements?.Image || ImageElement;
const Section = theme?.elements?.Section || SectionElement;
const AudioPlayer = theme?.elements?.AudioPlayer || AudioPlayerElement;
const VideoPlayer = theme?.elements?.VideoPlayer || VideoPlayerElement;
const Type = theme?.elements?.Type || TypeElement;
const Button = theme?.elements?.Button || ButtonElement;
const {
classes
} = useStyle();
const {
ref,
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__*/_jsx(Image, _objectSpread(_objectSpread(_objectSpread(_objectSpread({
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__*/_jsx(AudioPlayer, _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, 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__*/_jsx(VideoPlayer, _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, media), mediaProps), MediaProps), VideoProps), {}, {
className: classNames([staticClassName('SectionTextMedia', theme) && ['onesy-SectionTextMedia-item', 'onesy-SectionTextMedia-item-video'], MediaProps?.className, VideoProps?.className])
}));
}
const main = /*#__PURE__*/_jsxs(Line, _objectSpread(_objectSpread({
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]),
children: [/*#__PURE__*/_jsxs(Line, _objectSpread(_objectSpread({
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]),
children: [is('string', title) && /*#__PURE__*/_jsx(Type, _objectSpread(_objectSpread({
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__*/_jsx(Text, _objectSpread(_objectSpread({
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__*/_jsx(Button, _objectSpread(_objectSpread({
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]),
children: button.text || l('Click here')
}))]
}));
return /*#__PURE__*/_jsx(Section, _objectSpread(_objectSpread({
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), {}, {
children: /*#__PURE__*/_jsxs(Line, _objectSpread(_objectSpread({
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]),
children: [['top', 'left'].includes(mediaPosition) && mediaElement, main, ['bottom', 'right'].includes(mediaPosition) && mediaElement]
}))
}));
};
SectionTextMedia.displayName = 'onesy-SectionTextMedia';
export default SectionTextMedia;