@salesforce/design-system-react
Version:
Salesforce Lightning Design System for React
127 lines (110 loc) • 4.92 kB
JavaScript
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, 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; }
/* 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 Section Component
// ## Dependencies
// ### React
import React from 'react';
import createReactClass from 'create-react-class';
import PropTypes from 'prop-types'; // ### isFunction
import isFunction from 'lodash.isfunction'; // ### 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'; // ## Children
import Button from '../button'; // ## Constants
import { APP_LAUNCHER_SECTION } from '../../utilities/constants';
var defaultProps = {
assistiveText: {
collapseSection: 'Toggle visibility of section'
}
};
/**
* App Launcher Sections allow users to categorize App Tiles as well as toggle their display
*/
var AppLauncherSection = createReactClass({
// ### Display Name
// Always use the canonical component name as the React display name.
displayName: APP_LAUNCHER_SECTION,
// ### Prop Types
propTypes: {
/**
* **Assistive text for accessibility.**
* This object is merged with the default props object on every render.
* * `collapseSection`: The assistive text for the section collapse icons.
*/
assistiveText: PropTypes.shape({
collapseSection: PropTypes.string
}),
/**
* The title for this section of apps
*/
title: PropTypes.string.isRequired,
/**
* Allows the user to show/hide the section
*/
toggleable: PropTypes.bool,
/**
* An array of applications to display
*/
children: PropTypes.node.isRequired,
/**
* Controls the open/closed state of the section
*/
isOpen: PropTypes.bool,
/**
* Callback for when section is toggled. Passes "isOpen" bool. Forces `toggleable` to true
*/
onToggleClick: PropTypes.func
},
getDefaultProps: function getDefaultProps() {
return defaultProps;
},
getInitialState: function getInitialState() {
return {
isOpen: true
};
},
componentWillMount: function componentWillMount() {
checkProps(APP_LAUNCHER_SECTION, this.props);
},
toggleOpen: function toggleOpen(event) {
this.setState({
isOpen: !this.state.isOpen
});
if (isFunction(this.props.onToggleClick)) {
this.props.onToggleClick(event, {});
}
},
render: function render() {
var isOpen = this.props.isOpen !== undefined ? this.props.isOpen : this.state.isOpen;
var iconIsOpenClass = isOpen ? 'slds-is-open' : 'slds-is-close';
var sectionIsOpenClass = isOpen ? 'slds-is-expanded' : 'slds-is-collapsed';
var assistiveText = _objectSpread({}, defaultProps.assistiveText, this.props.assistiveText);
return React.createElement("div", {
className: classNames('slds-section', iconIsOpenClass)
}, React.createElement("div", {
className: "slds-section__title"
}, this.props.toggleable || this.props.onToggleClick ? React.createElement(Button, {
assistiveText: {
icon: this.props.collapseSectionAssistiveText || assistiveText.collapseSection
},
iconCategory: "utility",
iconName: "switch",
onClick: this.toggleOpen,
className: "slds-m-right--small",
variant: "icon"
}) : null, React.createElement("h3", null, this.props.title)), React.createElement("div", {
className: "slds-section__content"
}, React.createElement("ul", {
className: classNames('slds-grid slds-grid--pull-padded slds-wrap', sectionIsOpenClass)
}, React.Children.map(this.props.children, function (child) {
return React.createElement("li", {
className: classNames('slds-col--padded slds-grow-none', child.props.size === 'small' ? 'slds-size--xx-small' : 'slds-size--1-of-1 slds-medium-size--1-of-3')
}, child);
}))));
}
});
export default AppLauncherSection;
//# sourceMappingURL=section.js.map