aws-northstar
Version:
NorthStar Design System
85 lines (81 loc) • 4.08 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;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = __importDefault(require("react"));
const styles_1 = require("@material-ui/core/styles");
const FormControlLabel_1 = __importDefault(require("@material-ui/core/FormControlLabel"));
const Radio_1 = __importDefault(require("@material-ui/core/Radio"));
const clsx_1 = __importDefault(require("clsx"));
const useUniqueId_1 = __importDefault(require("../../hooks/useUniqueId"));
const useStyles = (0, styles_1.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 = (0, useUniqueId_1.default)();
return (react_1.default.createElement(FormControlLabel_1.default, { key: id, className: classes.root, control: react_1.default.createElement(Radio_1.default, { 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: (0, clsx_1.default)(classes.radio, { [classes.withDescription]: description }) }), label: react_1.default.createElement("div", { className: classes.container },
react_1.default.createElement("span", null, children),
react_1.default.createElement("span", { className: classes.description }, description)) }));
};
exports.default = RadioButton;