UNPKG

@selfcommunity/react-ui

Version:

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

19 lines (18 loc) 1.26 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { FormControl, FormControlLabel, FormLabel, Switch, Typography } from '@mui/material'; import { memo, useCallback, useState } from 'react'; import { FormattedMessage } from 'react-intl'; function SwitchForm(props) { // PROPS const { name, title, description, checked, handleChangeOptions } = props; // STATES const [value, setValue] = useState(checked); // HANDLERS const handleChange = useCallback((e) => { const _checked = e.target.checked; setValue(_checked); handleChangeOptions(name, _checked); }, [setValue]); return (_jsxs(FormControl, Object.assign({ component: "fieldset", variant: "standard" }, { children: [_jsx(FormLabel, Object.assign({ component: "legend" }, { children: _jsx(Typography, Object.assign({ variant: "h5" }, { children: _jsx(FormattedMessage, { id: title, defaultMessage: title }) })) })), _jsx(FormControlLabel, { control: _jsx(Switch, { color: "primary", checked: value, name: name, onChange: handleChange }), label: _jsx(Typography, Object.assign({ variant: "body1" }, { children: _jsx(FormattedMessage, { id: description, defaultMessage: description }) })) })] }))); } export default memo(SwitchForm);