@amaui/ui-react
Version:
UI for React
158 lines • 8.46 kB
JavaScript
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(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
import React from 'react';
import { useNavigate } from 'react-router-dom';
import { is, isEnvironment, textToInnerHTML } from '@amaui/utils';
import { classNames, style as styleMethod, useAmauiTheme } from '@amaui/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: {
'&.amaui-Line-direction-row': {
'& > *': {
width: '50%'
}
}
}
}), {
name: 'amaui-SectionTextMedia'
});
const SectionTextMedia = /*#__PURE__*/React.forwardRef((props_, ref) => {
const theme = useAmauiTheme();
const props = React.useMemo(() => _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.amauiSectionTextMedia?.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 || '';
const navigate = isEnvironment('browser') && useNavigate();
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) && ['amaui-SectionTextMedia-item', 'amaui-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) && ['amaui-SectionTextMedia-item', 'amaui-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) && ['amaui-SectionTextMedia-item', 'amaui-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) && ['amaui-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) && ['amaui-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) && ['amaui-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) && ['amaui-SectionTextMedia-description'], DescriptionProps?.className])
}))), button && /*#__PURE__*/React.createElement(Button, _extends({
tonal: true,
version: "filled",
color: "primary",
size: size,
onClick: button.to || button.link ? () => button.to ? navigate(button.to) : window.open(button.link, 'blank') : undefined
}, button.props, {
className: classNames([staticClassName('SectionAction', theme) && ['amaui-SectionTextMedia-button'], button.props?.className, classes.button])
}), button.text || '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) && ['amaui-SectionTextMedia-root', `amaui-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) && ['amaui-SectionTextMedia-main'], MainProps?.className, classes.main])
}), ['top', 'left'].includes(mediaPosition) && mediaElement, main, ['bottom', 'right'].includes(mediaPosition) && mediaElement));
});
SectionTextMedia.displayName = 'amaui-SectionTextMedia';
export default SectionTextMedia;