UNPKG

@onesy/ui-react

Version:
146 lines 6.86 kB
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(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 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: 'auto hidden', padding: '0px 16px 24px' }, reviews: { maxWidth: '100%' }, review: { background: theme.palette.background.primary.secondary, boxShadow: '0px 4px 32px 0px rgba(0, 0, 0, 0.024)' }, 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: 'onesy-SectionReviews' }); const Element = /*#__PURE__*/React.forwardRef((props_, ref) => { const theme = useOnesyTheme(); const props = React.useMemo(() => _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.onesySectionReviews?.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", fullWidth: true, className: classNames([staticClassName('SectionReviews', theme) && ['onesy-SectionReviews-root', `onesy-SectionReviews-size-${size}`], className, classes.root]) }, other), /*#__PURE__*/React.createElement(Line, _extends({ gap: 2, direction: "row", justify: "flex-start", align: "flex-start" }, ReviewsProps, { className: classNames([staticClassName('SectionReviews', theme) && ['onesy-SectionReviews-reviews'], ReviewsProps?.className, classes.reviews]) }), values.filter(Boolean).map((item, index) => /*#__PURE__*/React.createElement(Line, _extends({ key: index, gap: 1.4, direction: "column", flexNo: true }, ReviewProps, { className: classNames([staticClassName('SectionReviews', theme) && ['onesy-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) && ['onesy-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) && ['onesy-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) && ['onesy-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) && ['onesy-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) && ['onesy-SectionReviews-description'], DescriptionProps?.className]) }))))))); }); Element.displayName = 'onesy-SectionReviews'; export default Element;