UNPKG

aws-northstar

Version:
77 lines (73 loc) 3.76 kB
/** ******************************************************************************************************************* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. * ******************************************************************************************************************** */ var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import React, { useMemo } from 'react'; import Typography from '@material-ui/core/Typography'; import MaterialCheckbox from '@material-ui/core/Checkbox'; import FormControlLabel from '@material-ui/core/FormControlLabel'; import { makeStyles } from '@material-ui/core/styles'; import clsx from 'clsx'; const useStyles = makeStyles((theme) => ({ checkbox: { marginRight: theme.spacing(0.4), '&:hover': { backgroundColor: 'transparent', }, '&.Mui-checked': { color: theme.palette.info.dark, }, '& .MuiSvgIcon-root': { height: '16px', width: '16px', }, }, checkboxWithDesc: { alignSelf: 'flex-start', }, checkboxLabel: { marginLeft: 0, }, checkboxLabelWitDesc: { '& > .MuiFormControlLabel-label': { marginTop: '-2px', }, }, })); /** * A Checkboxes allow the user to select one or more items from a set. */ const Checkbox = (_a) => { var { children, checked, disabled, description, indeterminate = false, onChange, controlId, ariaDescribedby, ariaLabel, ariaLabelledby, name, value } = _a, props = __rest(_a, ["children", "checked", "disabled", "description", "indeterminate", "onChange", "controlId", "ariaDescribedby", "ariaLabel", "ariaLabelledby", "name", "value"]); const classes = useStyles(); const label = useMemo(() => (React.createElement(React.Fragment, null, children, description && (React.createElement(Typography, { variant: "subtitle1", component: "div" }, description)))), [children, description]); const muiCheckBox = (React.createElement(MaterialCheckbox, { disableRipple: true, className: clsx(classes.checkbox, { [classes.checkboxWithDesc]: description }), id: controlId, checked: checked, disabled: disabled, indeterminate: indeterminate, onChange: onChange, value: value, inputProps: { 'aria-describedby': ariaDescribedby, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby, name, }, "data-testid": props['data-testid'] })); return (React.createElement(FormControlLabel, { control: muiCheckBox, label: label, className: clsx(classes.checkboxLabel, { [classes.checkboxLabelWitDesc]: description }) })); }; export default Checkbox;