UNPKG

@momentum-ui/react

Version:

Cisco Momentum UI framework for ReactJs applications

96 lines (82 loc) 2.7 kB
/** @component radio */ import PropTypes from 'prop-types'; import React from 'react'; import { Label } from "./.."; var Radio = function Radio(props) { var checked = props.checked, children = props.children, className = props.className, disabled = props.disabled, htmlId = props.htmlId, inputRef = props.inputRef, label = props.label, name = props.name, nestedLevel = props.nestedLevel, onChange = props.onChange, required = props.required, tabIndex = props.tabIndex, value = props.value; return /*#__PURE__*/React.createElement("div", { className: 'md-input-container md-radio' + ("" + (nestedLevel && " md-input--nested-" + nestedLevel || '')) + (" " + className) }, /*#__PURE__*/React.createElement("input", { className: 'md-input md-radio__input', type: "radio", ref: inputRef, disabled: disabled, checked: checked, required: required, name: name, value: value, id: htmlId, onChange: onChange, tabIndex: tabIndex }), /*#__PURE__*/React.createElement(Label, { className: "md-radio__label", label: label, htmlFor: htmlId }), children); }; Radio.propTypes = { /** @prop Boolean for whether the Radio button is checked | false */ checked: PropTypes.bool, /** @prop Children nodes to render insdie Radio component | null */ children: PropTypes.node, /** @prop Optional CSS class name | '' */ className: PropTypes.string, /** @prop Sets the attribute disabled to the Radio | false */ disabled: PropTypes.bool, /** @prop Unique HTML ID used for tying label to HTML input for automated testing */ htmlId: PropTypes.string.isRequired, /** @prop Optional ref attribute for Radio input element | null */ inputRef: PropTypes.func, /** @prop Radio label text | '' */ label: PropTypes.string, /** @prop Radio name string | '' */ name: PropTypes.string, /** @prop Set the level of nested Radios | 0 */ nestedLevel: PropTypes.number, /** @prop Callback function invoked when user makes a change with the Radio button | null */ onChange: PropTypes.func, /** @prop Requires the user to populate the Radio input | false */ required: PropTypes.bool, /** @prop Set the tabIndex of radio | 0 */ tabIndex: PropTypes.number, /** @prop String value that corresponds with Radio button | '' */ value: PropTypes.string }; Radio.defaultProps = { checked: false, children: null, className: '', disabled: false, inputRef: null, label: '', name: '', nestedLevel: 0, onChange: function onChange() {}, required: false, tabIndex: 0, value: '' }; Radio.displayName = 'Radio'; export default Radio;