@selfcommunity/react-ui
Version:
React UI Components to integrate a Community created with SelfCommunity Platform.
64 lines (58 loc) • 2.22 kB
JavaScript
import { __rest } from "tslib";
import { jsx as _jsx } from "react/jsx-runtime";
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import { useSCMediaClick } from '@selfcommunity/react-core';
import { useThemeProps } from '@mui/system';
import { File, Link, Share } from '../../shared/Media';
import classNames from 'classnames';
const PREFIX = 'SCFeedObjectMediaPreview';
const classes = {
root: `${PREFIX}-root`
};
const Root = styled(Box, {
name: PREFIX,
slot: 'Root'
})(() => ({}));
/**
* > API documentation for the Community-JS FeedObjectMediaPreview component. Learn about the available props and the CSS API.
*
*
* The FeedObjectMediaPreview component render the list of medias in a feed object thanks to given configurations.
#### Import
```jsx
import {FeedObjectMediaPreview} from '@selfcommunity/react-ui';
```
#### Component Name
The name `SCFeedObjectMediaPreview` can be used when providing style overrides in the theme.
#### CSS
|Rule Name|Global class|Description|
|---|---|---|
|root|.SCFeedObjectMediaPreview-root|Styles applied to the root element.|
* @param inProps
*/
export default (inProps) => {
//PROPS
const props = useThemeProps({
props: inProps,
name: PREFIX
});
const { className, medias, mediaObjectTypes = [File, Link, Share] } = props, rest = __rest(props, ["className", "medias", "mediaObjectTypes"]);
const { handleMediaClick } = useSCMediaClick();
if (!medias.length) {
/**
* Feed without any medias:
* don't render anything
*/
return null;
}
/**
* Renders list of media preview
* The adornment prop is used to insert the controls
* for re-editing the media at the top of the group of elements
*/
return (_jsx(Root, Object.assign({ className: classNames(className, classes.root) }, rest, { children: mediaObjectTypes.map((mediaObject) => {
const { displayProps = {} } = mediaObject;
return (_jsx("div", { children: _jsx(mediaObject.displayComponent, Object.assign({ medias: medias }, displayProps, { onMediaClick: handleMediaClick })) }, mediaObject.name));
}) })));
};