UNPKG

@selfcommunity/react-ui

Version:

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

70 lines (62 loc) 2.81 kB
import { __rest } from "tslib"; import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; import { useContext, useState } from 'react'; import { styled } from '@mui/material/styles'; import { Button } from '@mui/material'; import ChangePictureDialog from './ChangePictureDialog/ChangePictureDialog'; import { FormattedMessage } from 'react-intl'; import Icon from '@mui/material/Icon'; import { SCUserContext } from '@selfcommunity/react-core'; import classNames from 'classnames'; import { useThemeProps } from '@mui/system'; import { PREFIX } from './constants'; const classes = { root: `${PREFIX}-root`, dialog: `${PREFIX}-dialog` }; const Root = styled(Button, { name: PREFIX, slot: 'Root' })(() => ({})); /** * > API documentation for the Community-JS Change Picture component. Learn about the available props and the CSS API. * * * This component renders a button that allows users to manage their profile pictures. * Take a look at our <strong>demo</strong> component [here](/docs/sdk/community-js/react-ui/Components/ChangePicture) #### Import ```jsx import {ChangePicture} from '@selfcommunity/react-ui'; ``` #### Component Name The name `SCChangePictureButton` can be used when providing style overrides in the theme. #### CSS |Rule Name|Global class|Description| |---|---|---| |root|.SCChangePictureButton-root|Styles applied to the root element.| |root|.SCChangePictureButton-dialog|Styles applied to the dialog element.| * @param inProps */ export default function ChangePicture(inProps) { //PROPS const props = useThemeProps({ props: inProps, name: PREFIX }); const { iconButton, onChange, autoHide, className } = props, rest = __rest(props, ["iconButton", "onChange", "autoHide", "className"]); //STATE const [openChangePictureDialog, setOpenChangePictureDialog] = useState(false); //CONTEXT const scUserContext = useContext(SCUserContext); // Anonymous if (!scUserContext.user) { return null; } /** * Renders the component (if not hidden by autoHide prop) */ if (!autoHide) { return (_jsxs(_Fragment, { children: [_jsx(Root, Object.assign({ className: classNames(classes.root, className), size: "small", variant: "contained", onClick: () => setOpenChangePictureDialog(true) }, rest, { children: iconButton ? (_jsx(Icon, { children: "photo_camera" })) : (_jsx(FormattedMessage, { id: "ui.changePicture.button.change", defaultMessage: "ui.changePicture.button.change" })) })), openChangePictureDialog && (_jsx(ChangePictureDialog, { className: classes.dialog, open: openChangePictureDialog, onChange: (avatar) => onChange && onChange(avatar), onClose: () => setOpenChangePictureDialog(false) }))] })); } return null; }