@onesy/ui-react
Version:
UI for React
155 lines • 7.32 kB
JavaScript
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
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) { _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';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
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 = props_ => {
const theme = useOnesyTheme();
const props = _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.onesySectionReviews?.props?.default), props_);
const Line = theme?.elements?.Line || LineElement;
const Section = theme?.elements?.Section || SectionElement;
const Type = theme?.elements?.Type || TypeElement;
const Avatar = theme?.elements?.Avatar || AvatarElement;
const Rating = theme?.elements?.Rating || RatingElement;
const {
ref,
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__*/_jsx(Section, _objectSpread(_objectSpread({
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), {}, {
children: /*#__PURE__*/_jsx(Line, _objectSpread(_objectSpread({
gap: 2,
direction: "row",
justify: "flex-start",
align: "flex-start"
}, ReviewsProps), {}, {
className: classNames([staticClassName('SectionReviews', theme) && ['onesy-SectionReviews-reviews'], ReviewsProps?.className, classes.reviews]),
children: values.filter(Boolean).map((item_0, index) => /*#__PURE__*/_jsxs(Line, _objectSpread(_objectSpread({
gap: 1.4,
direction: "column",
flexNo: true
}, ReviewProps), {}, {
className: classNames([staticClassName('SectionReviews', theme) && ['onesy-SectionReviews-review'], ReviewProps?.className, classes.review, classes[`review_size_${size}`]]),
children: [/*#__PURE__*/_jsxs(Line, {
gap: 1.7,
direction: "row",
align: "center",
children: [/*#__PURE__*/_jsx(Avatar, _objectSpread(_objectSpread({
size: size,
image: is('string', item_0.image) ? item_0.image : item_0.image?.url || item_0.image?.urlSmall
}, AvatarProps), {}, {
className: classNames([staticClassName('SectionReviews', theme) && ['onesy-SectionReviews-avatar'], AvatarProps?.className]),
children: item_0.name?.split(' ').map(item_ => item_[0]).join('')
})), /*#__PURE__*/_jsxs(Line, {
gap: 0.5,
direction: "column",
children: [/*#__PURE__*/_jsx(Rating, _objectSpread(_objectSpread({
value: item_0.rating,
size: ['regular', 'small'].includes(size) ? 'small' : 'regular',
readOnly: true
}, RatingProps), {}, {
className: classNames([staticClassName('SectionReviews', theme) && ['onesy-SectionReviews-rating'], RatingProps?.className])
})), /*#__PURE__*/_jsxs(Line, {
gap: 0.14,
direction: "column",
children: [/*#__PURE__*/_jsx(Type, _objectSpread(_objectSpread({
version: size === 'large' ? 't2' : size === 'regular' ? 't3' : 'l1',
dangerouslySetInnerHTML: {
__html: textToInnerHTML(item_0.name)
}
}, NameProps), {}, {
className: classNames([staticClassName('SectionReviews', theme) && ['onesy-SectionReviews-name'], NameProps?.className])
})), item_0.meta && /*#__PURE__*/_jsx(Type, _objectSpread(_objectSpread({
version: size === 'large' ? 'b2' : size === 'regular' ? 'b3' : 'b3',
dangerouslySetInnerHTML: {
__html: textToInnerHTML(item_0.meta)
}
}, MetaProps), {}, {
className: classNames([staticClassName('SectionReviews', theme) && ['onesy-SectionReviews-meta'], MetaProps?.className])
}))]
})]
})]
}), /*#__PURE__*/_jsx(Line, {
gap: 1,
direction: "column",
children: /*#__PURE__*/_jsx(Type, _objectSpread(_objectSpread({
version: size === 'large' ? 'b1' : size === 'regular' ? 'b2' : 'b3',
dangerouslySetInnerHTML: {
__html: textToInnerHTML(item_0.description)
}
}, DescriptionProps), {}, {
className: classNames([staticClassName('SectionReviews', theme) && ['onesy-SectionReviews-description'], DescriptionProps?.className])
}))
})]
}), index))
}))
}));
};
Element.displayName = 'onesy-SectionReviews';
export default Element;