UNPKG

@momentum-ui/react-collaboration

Version:

Cisco Momentum UI Framework for React Collaboration Applications

106 lines 5.36 kB
/** @component select-option */ var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; 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 ReactDOM from 'react-dom'; import PropTypes from 'prop-types'; import { Icon, ListItem, ListItemSection } from '@momentum-ui/react-collaboration'; import Checkbox from '../Checkbox'; import SelectContext from '../SelectContext'; import ListContext from '../ListContext'; import { UIDConsumer } from 'react-uid'; /** * @deprecated - Components in the legacy folder (/src/legacy) are deprecated. Please use a component from the components folder (/src/components) instead. Legacy components may not follow accessibility standards. **/ var SelectOption = /** @class */ (function (_super) { __extends(SelectOption, _super); function SelectOption() { return _super !== null && _super.apply(this, arguments) || this; } SelectOption.prototype.render = function () { var _this = this; var _a = this.props, className = _a.className, active = _a.active, children = _a.children, label = _a.label, title = _a.title, props = __rest(_a, ["className", "active", "children", "label", "title"]); var separateChildren = function (isMulti, cxtActive, uniqueId) { return isMulti ? (React.createElement(Checkbox, { htmlId: "".concat(uniqueId, "__checkbox"), label: label, checked: cxtActive || false, onChange: function () { } })) : ([ React.createElement(ListItemSection, { key: "child-0", position: "center" }, label || children), React.createElement(ListItemSection, { key: "child-1", position: "right" }, cxtActive && React.createElement(Icon, { color: "blue-50", name: "check_20" })), ]); }; var keySource = function (isMulti) { return "data-md-".concat(isMulti ? 'keyboard' : 'event', "-key"); }; return (React.createElement(UIDConsumer, { name: function (id) { return "md-select-option-".concat(id); } }, function (id) { return (React.createElement(SelectContext.Consumer, null, function (isMulti) { return (React.createElement(ListContext.Consumer, null, function (listContext) { var cxtActive = active || (listContext && listContext.active && ReactDOM.findDOMNode(_this) && ReactDOM.findDOMNode(_this).attributes[keySource(isMulti)] && ReactDOM.findDOMNode(_this).attributes[keySource(isMulti)].value && listContext.active.includes(ReactDOM.findDOMNode(_this).attributes[keySource(isMulti)].value)); var uniqueId = _this.props.id || id; return (React.createElement(ListItem, __assign({ className: "".concat((className && " ".concat(className)) || ''), id: uniqueId, label: label, title: title || label }, props), separateChildren(isMulti, cxtActive, uniqueId))); })); })); })); }; return SelectOption; }(React.Component)); SelectOption.propTypes = { /** @prop SelectOption Boolean that describes active state | false */ active: PropTypes.bool, /** @prop Children nodes to render inside SelectOption | null */ children: PropTypes.node, /** @prop Optional HTML Class Name for ListItem | '' */ className: PropTypes.string, /** @prop SelectOption ID | '' */ id: PropTypes.string, /** @prop SelectOption label text | '' */ label: PropTypes.string, /** @prop ListItem Title | '' */ title: PropTypes.string, /** @prop SelectOption value | '' */ value: PropTypes.string, }; SelectOption.defaultProps = { active: false, children: null, className: '', id: '', label: '', title: '', value: '', }; SelectOption.displayName = 'SelectOption'; export default SelectOption; //# sourceMappingURL=index.js.map