@selfcommunity/react-ui
Version:
React UI Components to integrate a Community created with SelfCommunity Platform.
50 lines (49 loc) • 3.15 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const styles_1 = require("@mui/material/styles");
const material_1 = require("@mui/material");
const Vote_1 = tslib_1.__importDefault(require("./Vote"));
const Comment_1 = tslib_1.__importDefault(require("./Comment"));
const Share_1 = tslib_1.__importDefault(require("./Share"));
const react_core_1 = require("@selfcommunity/react-core");
const feedObject_1 = require("../../../types/feedObject");
const classnames_1 = tslib_1.__importDefault(require("classnames"));
const constants_1 = require("../constants");
const classes = {
root: `${constants_1.PREFIX}-actions-root`,
action: `${constants_1.PREFIX}-actions-action`
};
const Root = (0, styles_1.styled)(material_1.Grid, {
name: constants_1.PREFIX,
slot: 'ActionsRoot'
})(() => ({}));
function Actions(props) {
// PROPS
const { className, feedObject, feedObjectId = feedObject === null || feedObject === void 0 ? void 0 : feedObject.id, feedObjectType = feedObject === null || feedObject === void 0 ? void 0 : feedObject.type, feedObjectTemplate = feedObject_1.SCFeedObjectTemplateType.PREVIEW, hideVoteAction = false, hideShareAction = false, hideCommentAction = false, handleExpandActivities, VoteActionProps = {}, CommentActionProps = {}, ShareActionProps = {} } = props;
// STATE
const { obj } = (0, react_core_1.useSCFetchFeedObject)({ id: feedObjectId, feedObject, feedObjectType });
if (!obj) {
return null;
}
/**
* Calculate column width
*/
function getColumnWidth() {
let width = 4;
if (hideShareAction && hideCommentAction) {
width = 12;
}
else if (hideCommentAction || hideCommentAction) {
width = 6;
}
return width;
}
/**
* Renders action section
*/
const columnWidth = getColumnWidth();
return ((0, jsx_runtime_1.jsxs)(Root, Object.assign({ container: true, className: (0, classnames_1.default)(classes.root, className) }, { children: [!hideVoteAction && ((0, jsx_runtime_1.jsx)(material_1.Grid, Object.assign({ item: true, xs: columnWidth, className: classes.action }, { children: (0, jsx_runtime_1.jsx)(Vote_1.default, Object.assign({ feedObjectId: feedObjectId || obj.id, feedObject: obj, feedObjectType: feedObjectType || obj.type }, VoteActionProps)) }))), !hideCommentAction && ((0, jsx_runtime_1.jsx)(material_1.Grid, Object.assign({ item: true, xs: columnWidth, className: classes.action }, { children: (0, jsx_runtime_1.jsx)(Comment_1.default, Object.assign({ feedObject: obj, feedObjectType: feedObjectType, feedObjectTemplate: feedObjectTemplate, onCommentAction: handleExpandActivities }, CommentActionProps)) }))), !hideShareAction && ((0, jsx_runtime_1.jsx)(material_1.Grid, Object.assign({ item: true, xs: columnWidth, className: classes.action }, { children: (0, jsx_runtime_1.jsx)(Share_1.default, Object.assign({ feedObject: obj, feedObjectType: feedObjectType, id: feedObjectId }, ShareActionProps)) })))] })));
}
exports.default = Actions;