@selfcommunity/react-ui
Version:
React UI Components to integrate a Community created with SelfCommunity Platform.
91 lines (86 loc) • 5.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const styles_1 = require("@mui/material/styles");
const material_1 = require("@mui/material");
const react_core_1 = require("@selfcommunity/react-core");
const types_1 = require("@selfcommunity/types");
const Skeleton_1 = tslib_1.__importDefault(require("./Skeleton"));
const CategoryFollowButton_1 = tslib_1.__importDefault(require("../CategoryFollowButton"));
const react_intl_1 = require("react-intl");
const classnames_1 = tslib_1.__importDefault(require("classnames"));
const system_1 = require("@mui/system");
const BaseItemButton_1 = tslib_1.__importDefault(require("../../shared/BaseItemButton"));
const constants_1 = require("./constants");
const messages = (0, react_intl_1.defineMessages)({
categoryFollowers: {
id: 'ui.category.categoryFollowers',
defaultMessage: 'ui.category.categoryFollowers'
}
});
const classes = {
root: `${constants_1.PREFIX}-root`,
categoryImage: `${constants_1.PREFIX}-category-image`,
primary: `${constants_1.PREFIX}-primary`,
secondary: `${constants_1.PREFIX}-secondary`,
title: `${constants_1.PREFIX}-title`,
followed: `${constants_1.PREFIX}-followed`,
autoFollowed: `${constants_1.PREFIX}-auto-followed`,
actions: `${constants_1.PREFIX}-actions`
};
const Root = (0, styles_1.styled)(BaseItemButton_1.default, {
name: constants_1.PREFIX,
slot: 'Root'
})(() => ({}));
/**
* > API documentation for the Community-JS Category component. Learn about the available props and the CSS API.
*
*
* This component renders a category item.
* Take a look at our <strong>demo</strong> component [here](/docs/sdk/community-js/react-ui/Components/Category)
#### Import
```jsx
import {Category} from '@selfcommunity/react-ui';
```
#### Component Name
The name `SCCategory` can be used when providing style overrides in the theme.
#### CSS
|Rule Name|Global class|Description|
|---|---|---|
|root|.SCCategory-root|Styles applied to the root element.|
|categoryImage|.SCCategory-category-image|Styles applied to category image element.|
|title|.SCCategory-title|Styles applied to the title element.|
|actions|.SCCategory-actions|Styles applied to action section.|
|primary|.SCCategory-primary|Styles applied to category primary section (when showTooltip prop is set to true)|
|secondary|.SCCategory-secondary|Styles applied to category secondary section (when showTooltip prop is set to true)|
|followed|.SCCategory-followed|Styles applied to a category item when it is followed|
|autoFollowed|.SCCategory-auto-followed|Styles applied to a category item when auto followed is set to true|
* @param inProps
*/
function Category(inProps) {
// PROPS
const props = (0, system_1.useThemeProps)({
props: inProps,
name: constants_1.PREFIX
});
const { categoryId = null, category = null, className = null, elevation, autoHide = false, categoryFollowButtonProps = {}, showFollowers = true, showTooltip = false, ButtonBaseProps = null } = props, rest = tslib_1.__rest(props, ["categoryId", "category", "className", "elevation", "autoHide", "categoryFollowButtonProps", "showFollowers", "showTooltip", "ButtonBaseProps"]);
// CONTEXT
const scRoutingContext = (0, react_core_1.useSCRouting)();
// STATE
const { scCategory, setSCCategory } = (0, react_core_1.useSCFetchCategory)({ id: categoryId, category });
// MEMO
const _ButtonBaseProps = (0, react_1.useMemo)(() => (ButtonBaseProps ? ButtonBaseProps : { component: react_core_1.Link, to: scRoutingContext.url(react_core_1.SCRoutes.CATEGORY_ROUTE_NAME, scCategory) }), [ButtonBaseProps, scRoutingContext, scCategory]);
// HOOKS
const intl = (0, react_intl_1.useIntl)();
if (!scCategory) {
return (0, jsx_runtime_1.jsx)(Skeleton_1.default, { elevation: elevation });
}
// RENDER
if (!autoHide) {
return ((0, jsx_runtime_1.jsx)(Root, Object.assign({ disableTypography: showTooltip, elevation: elevation, className: (0, classnames_1.default)(classes.root, className, { [classes.followed]: scCategory.followed }, { [classes.autoFollowed]: scCategory.auto_follow === types_1.SCCategoryAutoFollowType.FORCED }), ButtonBaseProps: _ButtonBaseProps, image: (0, jsx_runtime_1.jsx)(material_1.Avatar, { alt: scCategory.name, src: scCategory.image_medium, variant: "square", className: classes.categoryImage }), primary: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: showTooltip ? ((0, jsx_runtime_1.jsx)(material_1.Tooltip, Object.assign({ title: scCategory.name }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ className: classes.primary, component: "span", variant: "body1" }, { children: scCategory.name })) }))) : (scCategory.name) }), secondary: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: showTooltip ? ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ className: classes.secondary, component: "p", variant: "body2" }, { children: showFollowers ? `${intl.formatMessage(messages.categoryFollowers, { total: scCategory.followers_counter })}` : scCategory.slogan }))) : ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: showFollowers ? `${intl.formatMessage(messages.categoryFollowers, { total: scCategory.followers_counter })}` : scCategory.slogan })) }), actions: (0, jsx_runtime_1.jsx)(CategoryFollowButton_1.default, Object.assign({ category: scCategory }, categoryFollowButtonProps)) }, rest)));
}
return null;
}
exports.default = Category;