@amaui/ui-react
Version:
UI for React
142 lines • 7.09 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 = ["value", "size", "name", "IconDocument", "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 { cleanValue, is } from '@amaui/utils';
import { classNames, style as styleMethod, useAmauiTheme } from '@amaui/style-react';
import IconMaterialDraft from '@amaui/icons-material-rounded-react/IconMaterialDraftW100';
import AudioPlayerElement from '../AudioPlayer';
import ImageElement from '../Image';
import InteractionElement from '../Interaction';
import LineElement from '../Line';
import SectionElement from '../Section/Section';
import TypeElement from '../Type';
import VideoPlayerElement from '../VideoPlayer';
import { staticClassName } from '../utils';
const useStyle = styleMethod(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: 'amaui-SectionMedia'
});
const Element = /*#__PURE__*/React.forwardRef((props_, ref) => {
const theme = useAmauiTheme();
const props = React.useMemo(() => _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.amauiSectionMedia?.props?.default), props_), [props_]);
const Line = React.useMemo(() => theme?.elements?.Line || LineElement, [theme]);
const Section = React.useMemo(() => theme?.elements?.Section || SectionElement, [theme]);
const Image = React.useMemo(() => theme?.elements?.Image || ImageElement, [theme]);
const AudioPlayer = React.useMemo(() => theme?.elements?.AudioPlayer || AudioPlayerElement, [theme]);
const VideoPlayer = React.useMemo(() => theme?.elements?.VideoPlayer || VideoPlayerElement, [theme]);
const Interaction = React.useMemo(() => theme?.elements?.Interaction || InteractionElement, [theme]);
const Type = React.useMemo(() => theme?.elements?.Type || TypeElement, [theme]);
const {
value,
size = 'regular',
name,
IconDocument = IconMaterialDraft,
MediaProps,
ImageProps,
AudioProps,
VideoProps,
OtherProps,
className
} = props,
other = _objectWithoutProperties(props, _excluded);
const {
classes
} = useStyle();
const refs = {
root: React.useRef(undefined)
};
const onOpenMedia = React.useCallback(media => {
window.open(media.url || media.urlSmall, 'blank_');
}, []);
let element;
if (value) {
const mime = value.mime;
if (mime?.includes('image')) element = /*#__PURE__*/React.createElement(Image, _extends({
src: value?.url || value?.urlSmall || (is('string', value) ? value : ''),
maxWidth: "rg",
fullWidth: true
}, MediaProps, ImageProps, {
className: classNames([staticClassName('SectionMedia', theme) && ['amaui-SectionMedia-item', 'amaui-SectionMedia-item-image'], MediaProps?.className, ImageProps?.className])
}));else if (mime?.includes('audio')) element = /*#__PURE__*/React.createElement(AudioPlayer, _extends({
size: size
}, value, MediaProps, AudioProps, {
className: classNames([staticClassName('SectionMedia', theme) && ['amaui-SectionMedia-item', 'amaui-SectionMedia-item-audio'], MediaProps?.className, AudioProps?.className])
}));else if (mime?.includes('video')) element = /*#__PURE__*/React.createElement(VideoPlayer, _extends({
size: size
}, value, MediaProps, VideoProps, {
className: classNames([staticClassName('SectionMedia', theme) && ['amaui-SectionMedia-item', 'amaui-SectionMedia-item-video'], MediaProps?.className, VideoProps?.className])
}));else element = /*#__PURE__*/React.createElement(Line, {
gap: 1,
className: classNames([staticClassName('SectionMedia', theme) && ['amaui-SectionMedia-wrapper', 'amaui-SectionMedia-wrapper-other'], classes.wrapper, classes[`otherWrapper_size_${size}`]])
}, /*#__PURE__*/React.createElement(Line, _extends({
align: "center",
justify: "center",
onClick: () => onOpenMedia(value),
fullWidth: true
}, MediaProps, OtherProps, {
className: classNames([staticClassName('SectionMedia', theme) && ['amaui-SectionMedia-item', 'amaui-SectionMedia-item-other'], MediaProps?.className, OtherProps?.className, classes.other, classes[`other_size_${size}`]])
}), /*#__PURE__*/React.createElement(Interaction, null), /*#__PURE__*/React.createElement(IconDocument, {
size: size === 'large' ? 44 : size === 'regular' ? 34 : 24
})));
}
return /*#__PURE__*/React.createElement(Section, _extends({
ref: item => {
if (ref) {
if (is('function', ref)) ref(item);else ref.current = item;
}
refs.root.current = item;
},
maxWidth: "small",
align: "center",
className: classNames([staticClassName('SectionMedia', theme) && ['amaui-SectionMedia-root', `amaui-SectionMedia-size-${size}`], className, classes.root])
}, other), /*#__PURE__*/React.createElement(Line, {
align: "center",
fullWidth: true
}, element, name && /*#__PURE__*/React.createElement(Type, {
version: size === 'large' ? 't1' : size === 'regular' ? 't2' : 't3',
align: "center",
fullWidth: true,
className: classNames([staticClassName('SectionMedia', theme) && ['amaui-SectionMedia-name'], classes.name])
}, cleanValue(value?.name || 'No name', {
capitalize: true
}))));
});
Element.displayName = 'amaui-SectionMedia';
export default Element;