UNPKG

@salesforce/design-system-react

Version:

Salesforce Lightning Design System for React

174 lines (147 loc) 7.49 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 */ // ### React import React from 'react'; import PropTypes from 'prop-types'; // ### classNames import classNames from 'classnames'; // ### find import find from 'lodash.find'; // ## Children import Checkbox from '../../checkbox'; import Radio from '../../radio'; // ## Constants import { DATA_TABLE_ROW, DATA_TABLE_ROW_ACTIONS, DATA_TABLE_CELL } from '../../../utilities/constants'; /** * Used internally, provides row rendering to the DataTable. */ var DataTableRow = /*#__PURE__*/ function (_React$Component) { _inherits(DataTableRow, _React$Component); function DataTableRow() { var _ref; var _temp, _this; _classCallCheck(this, DataTableRow); 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 = DataTableRow.__proto__ || Object.getPrototypeOf(DataTableRow)).call.apply(_ref, [this].concat(args))), Object.defineProperty(_assertThisInitialized(_this), "isSelected", { configurable: true, enumerable: true, writable: true, value: function value() { return !!find(_this.props.selection, _this.props.item); } }), Object.defineProperty(_assertThisInitialized(_this), "handleToggle", { configurable: true, enumerable: true, writable: true, value: function value(e, _ref2) { var checked = _ref2.checked; return _this.props.onToggle(_this.props.item, checked, e); } }), _temp)); } _createClass(DataTableRow, [{ key: "render", // ### Render value: function render() { var _this2 = this; var ariaProps = {}; var isSelected = this.isSelected(); if (this.props.canSelectRows) { ariaProps['aria-selected'] = isSelected ? 'true' : 'false'; } // i18n return React.createElement("tr", _extends({}, ariaProps, { className: classNames({ 'slds-hint-parent': this.props.rowActions, 'slds-is-selected': this.props.canSelectRows && isSelected }) }), this.props.canSelectRows ? React.createElement("td", { role: this.props.fixedLayout ? 'gridcell' : null, className: "slds-text-align_right", "data-label": this.props.stacked ? 'Select Row' : undefined, style: { width: '3.25rem' } }, this.props.canSelectRows === 'radio' ? React.createElement(Radio, { assistiveText: { label: this.props.assistiveText.selectRow }, checked: isSelected, className: "slds-m-right_x-small", id: "".concat(this.props.id, "-SelectRow"), label: "", name: "".concat(this.props.tableId, "-SelectRow"), onChange: this.handleToggle }) : React.createElement(Checkbox, { assistiveText: { label: this.props.assistiveText.selectRow }, checked: isSelected, id: "".concat(this.props.id, "-SelectRow"), name: "SelectRow", onChange: this.handleToggle })) : null, this.props.columns.map(function (column) { var Cell = column.Cell; var cellId = "".concat(_this2.props.id, "-").concat(DATA_TABLE_CELL, "-").concat(column.props.property); return React.createElement(Cell, _extends({}, column.props, { className: column.props.truncate ? 'slds-truncate' : null, fixedLayout: _this2.props.fixedLayout, rowHeader: column.props.primaryColumn, id: cellId, item: _this2.props.item, key: cellId, width: column.props.width }), _this2.props.item[column.props.property]); }), this.props.rowActions ? React.cloneElement(this.props.rowActions, { id: "".concat(this.props.id, "-").concat(DATA_TABLE_ROW_ACTIONS), item: this.props.item }) : null); } }]); return DataTableRow; }(React.Component); Object.defineProperty(DataTableRow, "displayName", { configurable: true, enumerable: true, writable: true, value: DATA_TABLE_ROW }); Object.defineProperty(DataTableRow, "propTypes", { configurable: true, enumerable: true, writable: true, value: { assistiveText: PropTypes.shape({ actionsHeader: PropTypes.string, columnSort: PropTypes.string, columnSortedAscending: PropTypes.string, columnSortedDescending: PropTypes.string, selectAllRows: PropTypes.string, selectRow: PropTypes.string }), canSelectRows: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf(['checkbox', 'radio'])]), columns: PropTypes.arrayOf(PropTypes.shape({ Cell: PropTypes.func, props: PropTypes.object })), /** * Use this if you are creating an advanced table (selectable, sortable, or resizable rows) */ fixedLayout: PropTypes.bool, id: PropTypes.string.isRequired, item: PropTypes.object.isRequired, onToggle: PropTypes.func, rowActions: PropTypes.element, selection: PropTypes.array, tableId: PropTypes.string } }); export default DataTableRow; //# sourceMappingURL=row.js.map