@amaui/ui-react
Version:
UI for React
135 lines (134 loc) • 10.6 kB
JavaScript
"use strict";
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = __importDefault(require("react"));
const utils_1 = require("@amaui/utils");
const style_react_1 = require("@amaui/style-react");
const Line_1 = __importDefault(require("../Line"));
const Section_1 = __importDefault(require("../Section/Section"));
const Type_1 = __importDefault(require("../Type"));
const Avatar_1 = __importDefault(require("../Avatar"));
const Rating_1 = __importDefault(require("../Rating"));
const utils_2 = require("../utils");
const useStyle = (0, style_react_1.style)(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 = react_1.default.forwardRef((props_, ref) => {
const theme = (0, style_react_1.useAmauiTheme)();
const props = react_1.default.useMemo(() => { var _a, _b, _c, _d, _e, _f, _g, _h; return (Object.assign(Object.assign(Object.assign({}, (_d = (_c = (_b = (_a = theme === null || theme === void 0 ? void 0 : theme.ui) === null || _a === void 0 ? void 0 : _a.elements) === null || _b === void 0 ? void 0 : _b.all) === null || _c === void 0 ? void 0 : _c.props) === null || _d === void 0 ? void 0 : _d.default), (_h = (_g = (_f = (_e = theme === null || theme === void 0 ? void 0 : theme.ui) === null || _e === void 0 ? void 0 : _e.elements) === null || _f === void 0 ? void 0 : _f.amauiSectionReviews) === null || _g === void 0 ? void 0 : _g.props) === null || _h === void 0 ? void 0 : _h.default), props_)); }, [props_]);
const Line = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Line) || Line_1.default; }, [theme]);
const Section = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Section) || Section_1.default; }, [theme]);
const Type = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Type) || Type_1.default; }, [theme]);
const Avatar = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Avatar) || Avatar_1.default; }, [theme]);
const Rating = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Rating) || Rating_1.default; }, [theme]);
const { values = [], size = 'regular', AvatarProps, TypeProps, NameProps, MetaProps, DescriptionProps, RatingProps, ReviewProps, ReviewsProps, className } = props, other = __rest(props, ["values", "size", "AvatarProps", "TypeProps", "NameProps", "MetaProps", "DescriptionProps", "RatingProps", "ReviewProps", "ReviewsProps", "className"]);
const { classes } = useStyle();
const refs = {
root: react_1.default.useRef(undefined)
};
return ((0, jsx_runtime_1.jsx)(Section, Object.assign({ ref: (item) => {
if (ref) {
if ((0, utils_1.is)('function', ref))
ref(item);
else
ref.current = item;
}
refs.root.current = item;
}, align: 'center', className: (0, style_react_1.classNames)([
(0, utils_2.staticClassName)('SectionReviews', theme) && [
'amaui-SectionReviews-root',
`amaui-SectionReviews-size-${size}`
],
className,
classes.root
]) }, other, { children: (0, jsx_runtime_1.jsx)(Line, Object.assign({ gap: 2, direction: 'row', align: 'flex-start', fullWidth: true }, ReviewsProps, { className: (0, style_react_1.classNames)([
(0, utils_2.staticClassName)('SectionReviews', theme) && [
'amaui-SectionReviews-reviews'
],
ReviewsProps === null || ReviewsProps === void 0 ? void 0 : ReviewsProps.className,
classes.reviews
]) }, { children: values.filter(Boolean).map((item, index) => {
var _a, _b, _c;
return ((0, jsx_runtime_1.jsxs)(Line, Object.assign({ gap: 1.4, direction: 'column' }, ReviewProps, { className: (0, style_react_1.classNames)([
(0, utils_2.staticClassName)('SectionReviews', theme) && [
'amaui-SectionReviews-review'
],
ReviewProps === null || ReviewProps === void 0 ? void 0 : ReviewProps.className,
classes.review,
classes[`review_size_${size}`]
]) }, { children: [(0, jsx_runtime_1.jsxs)(Line, Object.assign({ gap: 1.7, direction: 'row', align: 'center' }, { children: [(0, jsx_runtime_1.jsx)(Avatar, Object.assign({ size: size, image: ((0, utils_1.is)('string', item.image) ? item.image : ((_a = item.image) === null || _a === void 0 ? void 0 : _a.url) || ((_b = item.image) === null || _b === void 0 ? void 0 : _b.urlSmall)) }, AvatarProps, { className: (0, style_react_1.classNames)([
(0, utils_2.staticClassName)('SectionReviews', theme) && [
'amaui-SectionReviews-avatar'
],
AvatarProps === null || AvatarProps === void 0 ? void 0 : AvatarProps.className
]) }, { children: (_c = item.name) === null || _c === void 0 ? void 0 : _c.split(' ').map(item_ => item_[0]).join('') })), (0, jsx_runtime_1.jsxs)(Line, Object.assign({ gap: 0.5, direction: 'column' }, { children: [(0, jsx_runtime_1.jsx)(Rating, Object.assign({ value: item.rating, size: ['regular', 'small'].includes(size) ? 'small' : 'regular', readOnly: true }, RatingProps, { className: (0, style_react_1.classNames)([
(0, utils_2.staticClassName)('SectionReviews', theme) && [
'amaui-SectionReviews-rating'
],
RatingProps === null || RatingProps === void 0 ? void 0 : RatingProps.className
]) })), (0, jsx_runtime_1.jsxs)(Line, Object.assign({ gap: 0.14, direction: 'column' }, { children: [(0, jsx_runtime_1.jsx)(Type, Object.assign({ version: size === 'large' ? 't2' : size === 'regular' ? 't3' : 'l1', dangerouslySetInnerHTML: {
__html: (0, utils_1.textToInnerHTML)(item.name)
} }, NameProps, { className: (0, style_react_1.classNames)([
(0, utils_2.staticClassName)('SectionReviews', theme) && [
'amaui-SectionReviews-name'
],
NameProps === null || NameProps === void 0 ? void 0 : NameProps.className
]) })), item.meta && ((0, jsx_runtime_1.jsx)(Type, Object.assign({ version: size === 'large' ? 'b2' : size === 'regular' ? 'b3' : 'b3', dangerouslySetInnerHTML: {
__html: (0, utils_1.textToInnerHTML)(item.meta)
} }, MetaProps, { className: (0, style_react_1.classNames)([
(0, utils_2.staticClassName)('SectionReviews', theme) && [
'amaui-SectionReviews-meta'
],
MetaProps === null || MetaProps === void 0 ? void 0 : MetaProps.className
]) })))] }))] }))] })), (0, jsx_runtime_1.jsx)(Line, Object.assign({ gap: 1, direction: 'column' }, { children: (0, jsx_runtime_1.jsx)(Type, Object.assign({ version: size === 'large' ? 'b1' : size === 'regular' ? 'b2' : 'b3', dangerouslySetInnerHTML: {
__html: (0, utils_1.textToInnerHTML)(item.description)
} }, DescriptionProps, { className: (0, style_react_1.classNames)([
(0, utils_2.staticClassName)('SectionReviews', theme) && [
'amaui-SectionReviews-description'
],
DescriptionProps === null || DescriptionProps === void 0 ? void 0 : DescriptionProps.className
]) })) }))] }), index));
}) })) })));
});
Element.displayName = 'amaui-SectionReviews';
exports.default = Element;