UNPKG

@onesy/ui-react

Version:
166 lines (165 loc) 10.4 kB
"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 _Line = _interopRequireDefault(require("../Line")); var _Section = _interopRequireDefault(require("../Section/Section")); var _Type = _interopRequireDefault(require("../Type")); var _Avatar = _interopRequireDefault(require("../Avatar")); var _Rating = _interopRequireDefault(require("../Rating")); var _utils2 = require("../utils"); var _jsxRuntime = require("react/jsx-runtime"); const _excluded = ["ref", "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) { (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: { 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 = props_ => { var _theme$ui, _theme$ui2, _theme$elements, _theme$elements2, _theme$elements3, _theme$elements4, _theme$elements5; const theme = (0, _styleReact.useOnesyTheme)(); 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.onesySectionReviews) === 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 Section = (theme === null || theme === void 0 || (_theme$elements2 = theme.elements) === null || _theme$elements2 === void 0 ? void 0 : _theme$elements2.Section) || _Section.default; const Type = (theme === null || theme === void 0 || (_theme$elements3 = theme.elements) === null || _theme$elements3 === void 0 ? void 0 : _theme$elements3.Type) || _Type.default; const Avatar = (theme === null || theme === void 0 || (_theme$elements4 = theme.elements) === null || _theme$elements4 === void 0 ? void 0 : _theme$elements4.Avatar) || _Avatar.default; const Rating = (theme === null || theme === void 0 || (_theme$elements5 = theme.elements) === null || _theme$elements5 === void 0 ? void 0 : _theme$elements5.Rating) || _Rating.default; const { ref, values = [], size = 'regular', AvatarProps, TypeProps, NameProps, MetaProps, DescriptionProps, RatingProps, ReviewProps, ReviewsProps, className } = props, other = (0, _objectWithoutProperties2.default)(props, _excluded); const { classes } = useStyle(); const refs = { root: _react.default.useRef(undefined) }; 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; }, align: "center", fullWidth: true, className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionReviews', theme) && ['onesy-SectionReviews-root', `onesy-SectionReviews-size-${size}`], className, classes.root]) }, other), {}, { children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, _objectSpread(_objectSpread({ gap: 2, direction: "row", justify: "flex-start", align: "flex-start" }, ReviewsProps), {}, { className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionReviews', theme) && ['onesy-SectionReviews-reviews'], ReviewsProps === null || ReviewsProps === void 0 ? void 0 : ReviewsProps.className, classes.reviews]), children: values.filter(Boolean).map((item_0, index) => { var _item_0$image, _item_0$image2, _item_0$name; return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, _objectSpread(_objectSpread({ gap: 1.4, direction: "column", flexNo: true }, ReviewProps), {}, { className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionReviews', theme) && ['onesy-SectionReviews-review'], ReviewProps === null || ReviewProps === void 0 ? void 0 : ReviewProps.className, classes.review, classes[`review_size_${size}`]]), children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, { gap: 1.7, direction: "row", align: "center", children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Avatar, _objectSpread(_objectSpread({ size: size, image: (0, _utils.is)('string', item_0.image) ? item_0.image : ((_item_0$image = item_0.image) === null || _item_0$image === void 0 ? void 0 : _item_0$image.url) || ((_item_0$image2 = item_0.image) === null || _item_0$image2 === void 0 ? void 0 : _item_0$image2.urlSmall) }, AvatarProps), {}, { className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionReviews', theme) && ['onesy-SectionReviews-avatar'], AvatarProps === null || AvatarProps === void 0 ? void 0 : AvatarProps.className]), children: (_item_0$name = item_0.name) === null || _item_0$name === void 0 ? void 0 : _item_0$name.split(' ').map(item_ => item_[0]).join('') })), /*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, { gap: 0.5, direction: "column", children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Rating, _objectSpread(_objectSpread({ value: item_0.rating, size: ['regular', 'small'].includes(size) ? 'small' : 'regular', readOnly: true }, RatingProps), {}, { className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionReviews', theme) && ['onesy-SectionReviews-rating'], RatingProps === null || RatingProps === void 0 ? void 0 : RatingProps.className]) })), /*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, { gap: 0.14, direction: "column", children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Type, _objectSpread(_objectSpread({ version: size === 'large' ? 't2' : size === 'regular' ? 't3' : 'l1', dangerouslySetInnerHTML: { __html: (0, _utils.textToInnerHTML)(item_0.name) } }, NameProps), {}, { className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionReviews', theme) && ['onesy-SectionReviews-name'], NameProps === null || NameProps === void 0 ? void 0 : NameProps.className]) })), item_0.meta && /*#__PURE__*/(0, _jsxRuntime.jsx)(Type, _objectSpread(_objectSpread({ version: size === 'large' ? 'b2' : size === 'regular' ? 'b3' : 'b3', dangerouslySetInnerHTML: { __html: (0, _utils.textToInnerHTML)(item_0.meta) } }, MetaProps), {}, { className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionReviews', theme) && ['onesy-SectionReviews-meta'], MetaProps === null || MetaProps === void 0 ? void 0 : MetaProps.className]) }))] })] })] }), /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, { gap: 1, direction: "column", children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Type, _objectSpread(_objectSpread({ version: size === 'large' ? 'b1' : size === 'regular' ? 'b2' : 'b3', dangerouslySetInnerHTML: { __html: (0, _utils.textToInnerHTML)(item_0.description) } }, DescriptionProps), {}, { className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)('SectionReviews', theme) && ['onesy-SectionReviews-description'], DescriptionProps === null || DescriptionProps === void 0 ? void 0 : DescriptionProps.className]) })) })] }), index); }) })) })); }; Element.displayName = 'onesy-SectionReviews'; var _default = exports.default = Element;