@onesy/ui-react
Version:
UI for React
172 lines (171 loc) • 12 kB
JavaScript
"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 _Text = _interopRequireDefault(require("../Text"));
var _Image = _interopRequireDefault(require("../Image"));
var _Section = _interopRequireDefault(require("../Section/Section"));
var _AudioPlayer = _interopRequireDefault(require("../AudioPlayer"));
var _VideoPlayer = _interopRequireDefault(require("../VideoPlayer"));
var _Line = _interopRequireDefault(require("../Line"));
var _Type = _interopRequireDefault(require("../Type"));
var _Button = _interopRequireDefault(require("../Button"));
var _utils2 = require("../utils");
var _jsxRuntime = require("react/jsx-runtime");
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) { (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: {},
main: {
'&.onesy-Line-direction-row': {
'& > *': {
width: '50%'
}
}
}
}), {
name: 'onesy-SectionTextMedia'
});
const SectionTextMedia = props_ => {
var _theme$ui, _theme$ui2, _theme$elements, _theme$elements2, _theme$elements3, _theme$elements4, _theme$elements5, _theme$elements6, _theme$elements7, _theme$elements8, _button$props;
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.onesySectionTextMedia) === 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 Text = (theme === null || theme === void 0 || (_theme$elements2 = theme.elements) === null || _theme$elements2 === void 0 ? void 0 : _theme$elements2.Text) || _Text.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 Section = (theme === null || theme === void 0 || (_theme$elements4 = theme.elements) === null || _theme$elements4 === void 0 ? void 0 : _theme$elements4.Section) || _Section.default;
const AudioPlayer = (theme === null || theme === void 0 || (_theme$elements5 = theme.elements) === null || _theme$elements5 === void 0 ? void 0 : _theme$elements5.AudioPlayer) || _AudioPlayer.default;
const VideoPlayer = (theme === null || theme === void 0 || (_theme$elements6 = theme.elements) === null || _theme$elements6 === void 0 ? void 0 : _theme$elements6.VideoPlayer) || _VideoPlayer.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 Button = (theme === null || theme === void 0 || (_theme$elements8 = theme.elements) === null || _theme$elements8 === void 0 ? void 0 : _theme$elements8.Button) || _Button.default;
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 = (0, _objectWithoutProperties2.default)(props, _excluded);
const refs = {
root: _react.default.useRef(undefined)
};
let mediaElement;
const mediaProps = _objectSpread({
size,
themed: true,
color: 'primary'
}, MediaProps);
const mime = (media === null || media === void 0 ? void 0 : media.mime) || '';
if (mime.includes('image')) {
mediaElement = /*#__PURE__*/(0, _jsxRuntime.jsx)(Image, _objectSpread(_objectSpread(_objectSpread(_objectSpread({
src: (media === null || media === void 0 ? void 0 : media.url) || (media === null || media === void 0 ? void 0 : media.urlSmall) || ((0, _utils.is)('string', media) ? media : '')
}, mediaProps), MediaProps), ImageProps), {}, {
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionTextMedia', theme) && ['onesy-SectionTextMedia-item', 'onesy-SectionTextMedia-item-image'], MediaProps === null || MediaProps === void 0 ? void 0 : MediaProps.className, ImageProps === null || ImageProps === void 0 ? void 0 : ImageProps.className])
}));
}
if (mime.includes('audio')) {
mediaElement = /*#__PURE__*/(0, _jsxRuntime.jsx)(AudioPlayer, _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, media), mediaProps), MediaProps), AudioProps), {}, {
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionTextMedia', theme) && ['onesy-SectionTextMedia-item', 'onesy-SectionTextMedia-item-audio'], MediaProps === null || MediaProps === void 0 ? void 0 : MediaProps.className, AudioProps === null || AudioProps === void 0 ? void 0 : AudioProps.className])
}));
}
if (mime.includes('video')) {
mediaElement = /*#__PURE__*/(0, _jsxRuntime.jsx)(VideoPlayer, _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, media), mediaProps), MediaProps), VideoProps), {}, {
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionTextMedia', theme) && ['onesy-SectionTextMedia-item', 'onesy-SectionTextMedia-item-video'], MediaProps === null || MediaProps === void 0 ? void 0 : MediaProps.className, VideoProps === null || VideoProps === void 0 ? void 0 : VideoProps.className])
}));
}
const main = /*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, _objectSpread(_objectSpread({
gap: 3,
direction: "column",
align: ['left', 'top', 'bottom'].includes(mediaPosition) ? 'flex-start' : 'flex-end',
fullWidth: true
}, WrapperMainProps), {}, {
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionTextMedia', theme) && ['onesy-SectionTextMedia-wrapper-main'], WrapperMainProps === null || WrapperMainProps === void 0 ? void 0 : WrapperMainProps.className]),
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, _objectSpread(_objectSpread({
gap: 2,
direction: "column",
align: ['left', 'top', 'bottom'].includes(mediaPosition) ? 'flex-start' : 'flex-end',
fullWidth: true
}, WrapperTextProps), {}, {
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionTextMedia', theme) && ['onesy-SectionTextMedia-wrapper-text'], WrapperTextProps === null || WrapperTextProps === void 0 ? void 0 : WrapperTextProps.className]),
children: [(0, _utils.is)('string', title) && /*#__PURE__*/(0, _jsxRuntime.jsx)(Type, _objectSpread(_objectSpread({
version: size === 'large' ? 'h1' : size === 'regular' ? 'h2' : 'h3',
align: ['left', 'top', 'bottom'].includes(mediaPosition) ? 'start' : 'end',
dangerouslySetInnerHTML: {
__html: (0, _utils.textToInnerHTML)(title)
}
}, TitleProps), {}, {
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionTextMedia', theme) && ['onesy-SectionTextMedia-title'], TitleProps === null || TitleProps === void 0 ? void 0 : TitleProps.className])
})), (0, _utils.is)('string', description) && /*#__PURE__*/(0, _jsxRuntime.jsx)(Text, _objectSpread(_objectSpread({
align: ['left', 'top', 'bottom'].includes(mediaPosition) ? 'start' : 'end',
columns: 1,
TypeProps: _objectSpread(_objectSpread({}, DescriptionProps === null || DescriptionProps === void 0 ? void 0 : DescriptionProps.TypeProps), {}, {
version: size === 'large' ? 'b1' : [undefined, 'regular'].includes(size) ? 'b2' : 'b3'
}),
value: description
}, DescriptionProps), {}, {
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionTextMedia', theme) && ['onesy-SectionTextMedia-description'], DescriptionProps === null || DescriptionProps === void 0 ? void 0 : DescriptionProps.className])
}))]
})), button && /*#__PURE__*/(0, _jsxRuntime.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: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionAction', theme) && ['onesy-SectionTextMedia-button'], (_button$props = button.props) === null || _button$props === void 0 ? void 0 : _button$props.className, classes.button]),
children: button.text || l('Click here')
}))]
}));
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;
},
size: size,
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionTextMedia', theme) && ['onesy-SectionTextMedia-root', `onesy-SectionTextMedia-size-${size}`], className, classes.root])
}, other), {}, {
children: /*#__PURE__*/(0, _jsxRuntime.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: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionTextMedia', theme) && ['onesy-SectionTextMedia-main'], MainProps === null || MainProps === void 0 ? void 0 : MainProps.className, classes.main]),
children: [['top', 'left'].includes(mediaPosition) && mediaElement, main, ['bottom', 'right'].includes(mediaPosition) && mediaElement]
}))
}));
};
SectionTextMedia.displayName = 'onesy-SectionTextMedia';
var _default = exports.default = SectionTextMedia;