@amaui/ui-react
Version:
UI for React
145 lines • 6.95 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 = ["values", "size", "AvatarProps", "TypeProps", "NameProps", "MetaProps", "DescriptionProps", "RatingProps", "ReviewProps", "ReviewsProps", "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 { is, textToInnerHTML } from '@amaui/utils';
import { classNames, style as styleMethod, useAmauiTheme } from '@amaui/style-react';
import LineElement from '../Line';
import SectionElement from '../Section/Section';
import TypeElement from '../Type';
import AvatarElement from '../Avatar';
import RatingElement from '../Rating';
import { staticClassName } from '../utils';
const useStyle = styleMethod(theme => ({
root: {
overflow: 'hidden'
},
reviews: {
overflowX: 'auto',
padding: '0px 4px 12px',
maxWidth: '100%'
},
review: {
flex: '0 0 auto',
background: theme.palette.background.primary.secondary
},
review_size_small: {
width: '240px',
padding: `${theme.methods.space.value(2, 'px')} ${theme.methods.space.value(2.5, 'px')}`,
borderRadius: theme.methods.shape.radius.value(2)
},
review_size_regular: {
width: '340px',
padding: `${theme.methods.space.value(3, 'px')} ${theme.methods.space.value(3.5, 'px')}`,
borderRadius: theme.methods.shape.radius.value(3)
},
review_size_large: {
width: '440px',
padding: `${theme.methods.space.value(4, 'px')} ${theme.methods.space.value(4.5, 'px')}`,
borderRadius: theme.methods.shape.radius.value(4)
}
}), {
name: 'amaui-SectionReviews'
});
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?.amauiSectionReviews?.props?.default), props_), [props_]);
const Line = React.useMemo(() => theme?.elements?.Line || LineElement, [theme]);
const Section = React.useMemo(() => theme?.elements?.Section || SectionElement, [theme]);
const Type = React.useMemo(() => theme?.elements?.Type || TypeElement, [theme]);
const Avatar = React.useMemo(() => theme?.elements?.Avatar || AvatarElement, [theme]);
const Rating = React.useMemo(() => theme?.elements?.Rating || RatingElement, [theme]);
const {
values = [],
size = 'regular',
AvatarProps,
TypeProps,
NameProps,
MetaProps,
DescriptionProps,
RatingProps,
ReviewProps,
ReviewsProps,
className
} = props,
other = _objectWithoutProperties(props, _excluded);
const {
classes
} = useStyle();
const refs = {
root: React.useRef(undefined)
};
return /*#__PURE__*/React.createElement(Section, _extends({
ref: item => {
if (ref) {
if (is('function', ref)) ref(item);else ref.current = item;
}
refs.root.current = item;
},
align: "center",
className: classNames([staticClassName('SectionReviews', theme) && ['amaui-SectionReviews-root', `amaui-SectionReviews-size-${size}`], className, classes.root])
}, other), /*#__PURE__*/React.createElement(Line, _extends({
gap: 2,
direction: "row",
align: "flex-start",
fullWidth: true
}, ReviewsProps, {
className: classNames([staticClassName('SectionReviews', theme) && ['amaui-SectionReviews-reviews'], ReviewsProps?.className, classes.reviews])
}), values.filter(Boolean).map((item, index) => /*#__PURE__*/React.createElement(Line, _extends({
key: index,
gap: 1.4,
direction: "column"
}, ReviewProps, {
className: classNames([staticClassName('SectionReviews', theme) && ['amaui-SectionReviews-review'], ReviewProps?.className, classes.review, classes[`review_size_${size}`]])
}), /*#__PURE__*/React.createElement(Line, {
gap: 1.7,
direction: "row",
align: "center"
}, /*#__PURE__*/React.createElement(Avatar, _extends({
size: size,
image: is('string', item.image) ? item.image : item.image?.url || item.image?.urlSmall
}, AvatarProps, {
className: classNames([staticClassName('SectionReviews', theme) && ['amaui-SectionReviews-avatar'], AvatarProps?.className])
}), item.name?.split(' ').map(item_ => item_[0]).join('')), /*#__PURE__*/React.createElement(Line, {
gap: 0.5,
direction: "column"
}, /*#__PURE__*/React.createElement(Rating, _extends({
value: item.rating,
size: ['regular', 'small'].includes(size) ? 'small' : 'regular',
readOnly: true
}, RatingProps, {
className: classNames([staticClassName('SectionReviews', theme) && ['amaui-SectionReviews-rating'], RatingProps?.className])
})), /*#__PURE__*/React.createElement(Line, {
gap: 0.14,
direction: "column"
}, /*#__PURE__*/React.createElement(Type, _extends({
version: size === 'large' ? 't2' : size === 'regular' ? 't3' : 'l1',
dangerouslySetInnerHTML: {
__html: textToInnerHTML(item.name)
}
}, NameProps, {
className: classNames([staticClassName('SectionReviews', theme) && ['amaui-SectionReviews-name'], NameProps?.className])
})), item.meta && /*#__PURE__*/React.createElement(Type, _extends({
version: size === 'large' ? 'b2' : size === 'regular' ? 'b3' : 'b3',
dangerouslySetInnerHTML: {
__html: textToInnerHTML(item.meta)
}
}, MetaProps, {
className: classNames([staticClassName('SectionReviews', theme) && ['amaui-SectionReviews-meta'], MetaProps?.className])
}))))), /*#__PURE__*/React.createElement(Line, {
gap: 1,
direction: "column"
}, /*#__PURE__*/React.createElement(Type, _extends({
version: size === 'large' ? 'b1' : size === 'regular' ? 'b2' : 'b3',
dangerouslySetInnerHTML: {
__html: textToInnerHTML(item.description)
}
}, DescriptionProps, {
className: classNames([staticClassName('SectionReviews', theme) && ['amaui-SectionReviews-description'], DescriptionProps?.className])
})))))));
});
Element.displayName = 'amaui-SectionReviews';
export default Element;