UNPKG

rmwc

Version:

A thin React wrapper for Material Design (Web) Components

223 lines (180 loc) 8.23 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.SimpleListItem = exports.List = exports.ListDivider = exports.ListGroupSubheader = exports.ListGroup = exports.ListItemMeta = exports.ListItemGraphic = exports.ListItemSecondaryText = exports.ListItemText = exports.ListItem = exports.ListItemRoot = undefined; var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; var _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _react = require('react'); var React = _interopRequireWildcard(_react); var _propTypes = require('prop-types'); var PropTypes = _interopRequireWildcard(_propTypes); var _Provider = require('../Provider'); var _Base = require('../Base'); var _Icon = require('../Icon'); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } 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; } var ListItemRoot = exports.ListItemRoot = (0, _Base.withRipple)()((0, _Base.simpleTag)({ displayName: 'ListItemRoot', classNames: function classNames(props) { return ['mdc-list-item', { 'mdc-list-item--selected': props.selected, 'mdc-list-item--activated': props.activated }]; }, consumeProps: ['selected', 'activated', 'options'] //options is from the select element })); /** * The ListItem component. */ var ListItem = exports.ListItem = function (_React$Component) { _inherits(ListItem, _React$Component); function ListItem() { _classCallCheck(this, ListItem); return _possibleConstructorReturn(this, (ListItem.__proto__ || Object.getPrototypeOf(ListItem)).apply(this, arguments)); } _createClass(ListItem, [{ key: 'componentWillMount', value: function componentWillMount() { this.providerOptions = (0, _Provider.getProviderOptions)(this.context); } }, { key: 'render', value: function render() { var listItemDefaultRipple = this.providerOptions.listItemDefaultRipple; var _props = this.props, ripple = _props.ripple, rest = _objectWithoutProperties(_props, ['ripple']); var shouldRipple = ripple === undefined ? listItemDefaultRipple : ripple; return React.createElement(ListItemRoot, Object.assign({ ripple: shouldRipple }, rest)); } }]); return ListItem; }(React.Component); /** Text for the ListItem */ Object.defineProperty(ListItem, 'displayName', { enumerable: true, writable: true, value: 'ListItem' }); Object.defineProperty(ListItem, 'defaultProps', { enumerable: true, writable: true, value: { ripple: true } }); Object.defineProperty(ListItem, 'contextTypes', { enumerable: true, writable: true, value: { RMWCOptions: PropTypes.object } }); var ListItemText = exports.ListItemText = (0, _Base.simpleTag)({ displayName: 'ListItemText', tag: 'span', classNames: 'mdc-list-item__text' }); /** Secondary text for the ListItem */ var ListItemSecondaryText = exports.ListItemSecondaryText = (0, _Base.simpleTag)({ displayName: 'ListItemSecondaryText', tag: 'span', classNames: 'mdc-list-item__secondary-text' }); /** A graphic / icon for the ListItem */ var ListItemGraphic = exports.ListItemGraphic = (0, _Base.simpleTag)({ displayName: 'ListItemGraphic', classNames: 'mdc-list-item__graphic', tag: _Icon.Icon }); /** A meta icon for the ListItem. By default this is an icon component. If you need to render text, specify a tag="span" and basename="" to ensure proper rendering. See the examples above.*/ var ListItemMeta = exports.ListItemMeta = (0, _Base.simpleTag)({ displayName: 'ListItemMeta', classNames: 'mdc-list-item__meta', tag: _Icon.Icon }); /** A container to group ListItems */ var ListGroup = exports.ListGroup = (0, _Base.simpleTag)({ displayName: 'ListGroup', classNames: 'mdc-list-group' }); /** A subheader for the ListGroup */ var ListGroupSubheader = exports.ListGroupSubheader = (0, _Base.simpleTag)({ displayName: 'ListGroupSubheader', classNames: 'mdc-list-group__subheader' }); /** A divider for the List */ var ListDivider = exports.ListDivider = (0, _Base.simpleTag)({ displayName: 'ListDivider', classNames: 'mdc-list-divider' }); var List = exports.List = function (_simpleTag) { _inherits(List, _simpleTag); function List() { _classCallCheck(this, List); return _possibleConstructorReturn(this, (List.__proto__ || Object.getPrototypeOf(List)).apply(this, arguments)); } _createClass(List, [{ key: 'render', value: function render() { return _get(List.prototype.__proto__ || Object.getPrototypeOf(List.prototype), 'render', this).call(this); } }]); return List; }((0, _Base.simpleTag)({ displayName: 'List', defaultProps: { dense: undefined, twoLine: undefined, avatarList: undefined, nonInteractive: undefined }, classNames: function classNames(props) { return ['mdc-list', { 'mdc-list--dense': props.dense, 'mdc-list--two-line': props.twoLine, 'mdc-list--avatar-list': props.avatarList, 'mdc-list--non-interactive': props.nonInteractive }]; }, consumeProps: ['dense', 'twoLine', 'avatarList', 'nonInteractive'] })); var SimpleListItem = function SimpleListItem(_ref) { var text = _ref.text, secondaryText = _ref.secondaryText, graphic = _ref.graphic, meta = _ref.meta, children = _ref.children, rest = _objectWithoutProperties(_ref, ['text', 'secondaryText', 'graphic', 'meta', 'children']); return React.createElement( ListItem, rest, graphic !== undefined && React.createElement( ListItemGraphic, null, graphic ), React.createElement( ListItemText, null, text, secondaryText !== undefined && React.createElement( ListItemSecondaryText, null, secondaryText ) ), meta !== undefined && React.createElement( ListItemMeta, null, meta ), children ); }; exports.SimpleListItem = SimpleListItem; SimpleListItem.displayName = 'SimpleListItem';