UNPKG

@salesforce/design-system-react

Version:

Salesforce Lightning Design System for React

244 lines (212 loc) 9.34 kB
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } /* Copyright (c) 2015-present, salesforce.com, inc. All rights reserved */ /* Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license */ /* eslint-disable jsx-a11y/no-noninteractive-element-interactions */ // # List Item Component // ## Dependencies // ### React import React from 'react'; import PropTypes from 'prop-types'; // ### classNames import classNames from 'classnames'; // ### Icon import Icon from '../../icon'; // ## Children import ListItemLabelRenderer from './item-label'; // ### Event Helpers import EventUtil from '../../../utilities/event'; // ## Constants import { LIST_ITEM } from '../../../utilities/constants'; /** * Component description. */ var ListItem = /*#__PURE__*/ function (_React$Component) { _inherits(ListItem, _React$Component); function ListItem() { var _ref; var _temp, _this; _classCallCheck(this, ListItem); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return _possibleConstructorReturn(_this, (_temp = _this = _possibleConstructorReturn(this, (_ref = ListItem.__proto__ || Object.getPrototypeOf(ListItem)).call.apply(_ref, [this].concat(args))), Object.defineProperty(_assertThisInitialized(_this), "getLabel", { configurable: true, enumerable: true, writable: true, value: function value() { var Label = _this.props.labelRenderer; return React.createElement(Label, { checkmark: _this.props.checkmark, data: _this.props.data, icon: _this.getIcon('left'), index: _this.props.index, inverted: _this.props.inverted, isSelected: _this.props.isSelected, label: _this.props.label, value: _this.props.value }); } }), Object.defineProperty(_assertThisInitialized(_this), "getIcon", { configurable: true, enumerable: true, writable: true, value: function value(position) { var classnames = ['slds-icon-text-default']; var iconProps = _this.props["".concat(position, "Icon")]; if (position === 'left') { if (_this.props.checkmark) { classnames.push('slds-icon_selected'); iconProps = { category: 'utility', name: 'check' }; } classnames.push('slds-m-right_x-small'); } else { classnames.push('slds-m-left_small'); } if (iconProps) { return React.createElement(Icon, _extends({ className: classNames(classnames), position: position, size: "x-small" }, iconProps)); } return null; } }), Object.defineProperty(_assertThisInitialized(_this), "handleClick", { configurable: true, enumerable: true, writable: true, value: function value(event) { if (_this.props.type !== 'link' || _this.props.href === 'javascript:void(0);' // eslint-disable-line no-script-url ) { // eslint-disable-line no-script-url EventUtil.trapImmediate(event); } if (_this.props.onSelect) { _this.props.onSelect(_this.props.index); } } }), Object.defineProperty(_assertThisInitialized(_this), "handleMouseDown", { configurable: true, enumerable: true, writable: true, value: function value(event) { EventUtil.trapImmediate(event); } }), _temp)); } _createClass(ListItem, [{ key: "render", value: function render() { switch (this.props.type) { case 'header': { return React.createElement("li", { className: classNames('slds-dropdown__header', { 'slds-has-divider_top-space': this.props.divider === 'top', 'slds-has-divider_bottom-space': this.props.divider === 'bottom' }, this.props.className), onMouseDown: this.handleMouseDown, role: "separator" }, React.createElement("span", { className: "slds-text-title_caps" }, this.props.label)); } case 'divider': { return React.createElement("li", { className: classNames('slds-has-divider', this.props.className), onMouseDown: this.handleMouseDown, role: "separator" }); } case 'link': case 'item': default: { return ( /* eslint-disable jsx-a11y/role-supports-aria-props */ // disabled eslint, but using aria-selected on presentation role seems suspicious... React.createElement("li", { "aria-selected": this.props.checkmark === null ? this.props.isSelected : null, className: classNames('slds-dropdown__item', { 'slds-is-selected': this.props.isSelected }, this.props.className), id: this.props.id, onMouseDown: this.handleMouseDown, role: "presentation" }, React.createElement("a", { "aria-checked": this.props.checkmark && this.props.isSelected, "aria-disabled": this.props['aria-disabled'], href: this.props.href, "data-index": this.props.index, onClick: this.handleClick, role: this.props.checkmark ? 'menuitemcheckbox' : 'menuitem', tabIndex: "-1" }, this.getLabel(), this.getIcon('right'))) ); } } } }]); return ListItem; }(React.Component); Object.defineProperty(ListItem, "displayName", { configurable: true, enumerable: true, writable: true, value: LIST_ITEM }); Object.defineProperty(ListItem, "propTypes", { configurable: true, enumerable: true, writable: true, value: { 'aria-disabled': PropTypes.bool, className: PropTypes.oneOfType([PropTypes.array, PropTypes.object, PropTypes.string]), checkmark: PropTypes.bool, data: PropTypes.object, divider: PropTypes.oneOf(['top', 'bottom']), href: PropTypes.string, id: PropTypes.string.isRequired, index: PropTypes.number.isRequired, inverted: PropTypes.bool, isSelected: PropTypes.bool, label: PropTypes.string, labelRenderer: PropTypes.func, leftIcon: PropTypes.shape({ category: PropTypes.string, name: PropTypes.string }), onSelect: PropTypes.func.isRequired, rightIcon: PropTypes.shape({ category: PropTypes.string, name: PropTypes.string }), type: PropTypes.string, value: PropTypes.any } }); Object.defineProperty(ListItem, "defaultProps", { configurable: true, enumerable: true, writable: true, value: { data: {}, href: 'javascript:void(0);', // eslint-disable-line no-script-url inverted: false, isSelected: false, label: '', labelRenderer: ListItemLabelRenderer, value: null } }); export default ListItem; //# sourceMappingURL=item.js.map