aws-northstar
Version:
NorthStar Design System
80 lines (76 loc) • 3.65 kB
JavaScript
/** *******************************************************************************************************************
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 from 'react';
import { makeStyles } from '@material-ui/core/styles';
import FormControlLabel from '@material-ui/core/FormControlLabel';
import MaterialRadioButton from '@material-ui/core/Radio';
import clsx from 'clsx';
import useUniqueId from '../../hooks/useUniqueId';
const useStyles = makeStyles((theme) => ({
root: {
marginLeft: 0,
'&:not(:first-child)': {
marginTop: theme.spacing(0.5),
},
},
radio: {
display: 'inline-block',
padding: '0',
'& .MuiSvgIcon-root': {
width: '16px',
height: '16px',
marginTop: '2px',
},
},
container: {
display: 'flex',
flexDirection: 'column',
alignItems: 'start',
paddingLeft: theme.spacing(1),
},
withDescription: {
alignSelf: 'flex-start',
},
description: {
fontSize: '12px',
color: theme.palette.grey['600'],
},
}));
/**
* Radio buttons allow the user to select one option from a set.
*/
const RadioButton = (_a) => {
var { name, value, disabled, controlId, checked, ariaLabelledby, ariaDescribedby, ariaLabel, onChange, children, description } = _a, props = __rest(_a, ["name", "value", "disabled", "controlId", "checked", "ariaLabelledby", "ariaDescribedby", "ariaLabel", "onChange", "children", "description"]);
const classes = useStyles();
const id = useUniqueId();
return (React.createElement(FormControlLabel, { key: id, className: classes.root, control: React.createElement(MaterialRadioButton, { id: controlId, "data-testid": props['data-testid'], value: value, checked: checked, disabled: disabled, onChange: onChange, inputProps: {
'aria-describedby': ariaDescribedby,
'aria-label': ariaLabel,
'aria-labelledby': ariaLabelledby,
name,
}, className: clsx(classes.radio, { [classes.withDescription]: description }) }), label: React.createElement("div", { className: classes.container },
React.createElement("span", null, children),
React.createElement("span", { className: classes.description }, description)) }));
};
export default RadioButton;