UNPKG

lucid-ui

Version:

A UI component library from AppNexus.

80 lines (69 loc) 5.7 kB
import _keys from "lodash/keys"; import _map from "lodash/map"; import _first from "lodash/first"; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } import React from 'react'; import PropTypes from 'react-peek/prop-types'; import { lucidClassNames } from '../../util/style-helpers'; import { findTypes, omitProps } from '../../util/component-types'; import RadioButton, { defaultProps as radioButtonDefaultProps } from '../RadioButton/RadioButton'; var cx = lucidClassNames.bind('&-RadioButtonLabeled'); var any = PropTypes.any, object = PropTypes.object, string = PropTypes.string; var RadioButtonLabeledLabel = function RadioButtonLabeledLabel(_props) { return null; }; RadioButtonLabeledLabel.displayName = 'RadioButtonLabeled.Label'; RadioButtonLabeledLabel.peek = { description: "\n\t\tUsed to identify the purpose of this radio button to the user -- can\n\t\tbe any renderable content.\n\t" }; RadioButtonLabeledLabel.propName = 'Label'; export var RadioButtonLabeled = function RadioButtonLabeled(props) { var className = props.className, isDisabled = props.isDisabled, isSelected = props.isSelected, onSelect = props.onSelect, style = props.style, passThroughs = _objectWithoutProperties(props, ["className", "isDisabled", "isSelected", "onSelect", "style"]); var labelChildProps = _first(_map(findTypes(props, RadioButtonLabeled.Label), 'props')); return /*#__PURE__*/React.createElement("label", { className: cx('&', { '&-is-disabled': isDisabled, '&-is-selected': isSelected }, className), style: style }, /*#__PURE__*/React.createElement(RadioButton, _extends({ className: className, isDisabled: isDisabled, isSelected: isSelected, onSelect: onSelect }, omitProps(passThroughs, undefined, _keys(RadioButtonLabeled.propTypes), false))), /*#__PURE__*/React.createElement("div", _extends({}, labelChildProps, { className: cx('&-label') }))); }; RadioButtonLabeled.displayName = 'RadioButtonLabeled'; RadioButtonLabeled.defaultProps = radioButtonDefaultProps; RadioButtonLabeled.peek = { description: "\n\t\tThis is a composite of the `RadioButton` component and the native\n\t\t`label` element.\n\t", notes: { overview: "\n\t\t\tA round two-state toggle with a label that explains the action or selection. This is a composite of `RadioButton` and the native\n\t\t\t`label` element.\t\t", intendedUse: "\n\t\t\t- Use radio button to allow users to select one item. Commonly used to select filters or settings. For interactions where users can select mutiple options, use `CheckboxLabeled`. \n\t\t\t- Use radio buttons for 2-3 options where you want to expose all options.\n\t\t\t- Use `SingleSelect` for 3-10 options where it is not a priority to expose all options.\n\t\t\t- Use `RadioButtonLabeled` for vertical lists of options. Use `RadioGroup` for horizontal lists of options.\n\t\t", technicalRecommendations: "\n\t\t\t- Use the styles on the parent container of `RadioButtonLabeled` to ensure only the radio buttons and their labels are clickable.\n\t\t\t- Any props that are not explicitly defined in `propTypes` are passed to the native radio button control.\n\t\t\t" }, categories: ['controls', 'toggles'], extend: 'RadioButton', madeFrom: ['RadioButton'] }; RadioButtonLabeled.propTypes = _objectSpread(_objectSpread({}, RadioButton.propTypes), {}, { className: string, style: object, Label: any }); RadioButtonLabeled.Label = RadioButtonLabeledLabel; export default RadioButtonLabeled;