UNPKG

@salesforce/design-system-react

Version:

Salesforce Lightning Design System for React

171 lines (128 loc) 8.91 kB
function _typeof(obj) { "@babel/helpers - typeof"; 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 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 _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 _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, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } 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; } /* Copyright (c) 2015-present, salesforce.com, inc. All rights reserved */ /* Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license */ // # App Launcher Expandable Section Component // ## Dependencies // ### React import React from 'react'; import PropTypes from 'prop-types'; // ### classNames // [github.com/JedWatson/classnames](https://github.com/JedWatson/classnames) // A simple javascript utility for conditionally joining classNames together. import classNames from 'classnames'; // This component's `checkProps` which issues warnings to developers about properties when in development mode (similar to React's built in development tools) import checkProps from './check-props'; import componentDoc from './component.json'; // ## Children import ExpandableSection from '../expandable-section'; // ## Constants import { APP_LAUNCHER_EXPANDABLE_SECTION, APP_LAUNCHER_TILE } from '../../utilities/constants'; /** * App Launcher Sections allow users to categorize App Tiles & Links as well as toggle their display. It is a superset of components/expandable-section with content formatting. * All Expandable Section props are compatible with props passed to this component. */ var AppLauncherExpandableSection = /*#__PURE__*/function (_React$Component) { _inherits(AppLauncherExpandableSection, _React$Component); var _super = _createSuper(AppLauncherExpandableSection); // ### Display Name // Always use the canonical component name as the React display name. // ### Prop Types function AppLauncherExpandableSection(props) { var _this; _classCallCheck(this, AppLauncherExpandableSection); _this = _super.call(this, props); _defineProperty(_assertThisInitialized(_this), "state", { isOpen: true }); _defineProperty(_assertThisInitialized(_this), "toggleOpen", function (event, data) { if (_this.props.onToggleOpen) { _this.props.onToggleOpen(event, data); } else { _this.setState(function (prevState) { return { isOpen: !prevState.isOpen }; }); } }); checkProps(APP_LAUNCHER_EXPANDABLE_SECTION, props, componentDoc); return _this; } _createClass(AppLauncherExpandableSection, [{ key: "render", value: function render() { var expandableSectionProps = _objectSpread(_objectSpread({}, this.props), { isOpen: this.props.isOpen !== undefined ? this.props.isOpen : this.state.isOpen, onToggleOpen: this.toggleOpen }); var ulChildrenType = 'tiles'; var ulContent = React.Children.map(this.props.children, function (child) { var liClasses = 'slds-p-horizontal_small slds-size_1-of-1 slds-medium-size_1-of-3'; if (child && child.type && child.type.displayName !== APP_LAUNCHER_TILE || child && !child.type) { ulChildrenType = 'links'; } if (ulChildrenType === 'links') { liClasses = 'slds-col_padded slds-p-vertical_xx-small slds-size_1-of-5'; } return /*#__PURE__*/React.createElement("li", { className: liClasses }, child); }); return /*#__PURE__*/React.createElement(ExpandableSection, expandableSectionProps, /*#__PURE__*/React.createElement("ul", { className: classNames('slds-grid slds-wrap', { 'slds-grid_pull-padded': ulChildrenType === 'tiles' }) }, ulContent)); } }]); return AppLauncherExpandableSection; }(React.Component); _defineProperty(AppLauncherExpandableSection, "displayName", APP_LAUNCHER_EXPANDABLE_SECTION); _defineProperty(AppLauncherExpandableSection, "propTypes", { /** * **Assistive text for accessibility.** * * `toggleSection`: Label for the icon that expands / collapses the section */ assistiveText: PropTypes.shape({ toggleSection: PropTypes.string }), /** * Contents of the section */ children: PropTypes.node, /** * Class names to be added to the `slds-section` classed node */ className: PropTypes.oneOfType([PropTypes.array, PropTypes.object, PropTypes.string]), /** * Unique identifier for the expandable section. The id is automatically generated if not provided */ id: PropTypes.string, /** * Specifies whether the section is expanded or collapsed. If not provided, component will use its own state to manage this itself */ isOpen: PropTypes.bool, /** * Specifies whether the section can be expanded or collapsed. Defaults to `false` */ nonCollapsible: PropTypes.bool, /** * Callback for when the section is expanded or collapsed. Passes event object and data object with `isOpen` bool. */ onToggleOpen: PropTypes.func, /** * The title for the section */ title: PropTypes.string.isRequired }); export default AppLauncherExpandableSection; //# sourceMappingURL=expandable-section.js.map