UNPKG

@selfcommunity/react-ui

Version:

React UI Components to integrate a Community created with SelfCommunity Platform.

46 lines (45 loc) 2.62 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { styled } from '@mui/material/styles'; import { Grid } from '@mui/material'; import Vote from './Vote'; import Comment from './Comment'; import Share from './Share'; import { useSCFetchFeedObject } from '@selfcommunity/react-core'; import { SCFeedObjectTemplateType } from '../../../types/feedObject'; import classNames from 'classnames'; import { PREFIX } from '../constants'; const classes = { root: `${PREFIX}-actions-root`, action: `${PREFIX}-actions-action` }; const Root = styled(Grid, { name: PREFIX, slot: 'ActionsRoot' })(() => ({})); export default 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 = SCFeedObjectTemplateType.PREVIEW, hideVoteAction = false, hideShareAction = false, hideCommentAction = false, handleExpandActivities, VoteActionProps = {}, CommentActionProps = {}, ShareActionProps = {} } = props; // STATE const { obj } = 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 (_jsxs(Root, Object.assign({ container: true, className: classNames(classes.root, className) }, { children: [!hideVoteAction && (_jsx(Grid, Object.assign({ item: true, xs: columnWidth, className: classes.action }, { children: _jsx(Vote, Object.assign({ feedObjectId: feedObjectId || obj.id, feedObject: obj, feedObjectType: feedObjectType || obj.type }, VoteActionProps)) }))), !hideCommentAction && (_jsx(Grid, Object.assign({ item: true, xs: columnWidth, className: classes.action }, { children: _jsx(Comment, Object.assign({ feedObject: obj, feedObjectType: feedObjectType, feedObjectTemplate: feedObjectTemplate, onCommentAction: handleExpandActivities }, CommentActionProps)) }))), !hideShareAction && (_jsx(Grid, Object.assign({ item: true, xs: columnWidth, className: classes.action }, { children: _jsx(Share, Object.assign({ feedObject: obj, feedObjectType: feedObjectType, id: feedObjectId }, ShareActionProps)) })))] }))); }