zrmc
Version:
ZRMC is an ES7 React wrapper for Material Components Web.
112 lines (85 loc) • 2.88 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends2 = require("babel-runtime/helpers/extends");
var _extends3 = _interopRequireDefault(_extends2);
var _objectWithoutProperties2 = require("babel-runtime/helpers/objectWithoutProperties");
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _react = require("react");
var _react2 = _interopRequireDefault(_react);
var _propTypes = require("prop-types");
var _propTypes2 = _interopRequireDefault(_propTypes);
var _ = require("../");
var _2 = _interopRequireDefault(_);
var _icon = require("../components/icon");
var _icon2 = _interopRequireDefault(_icon);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* mdc-drawer__content
* See
* https://material.io/components/web/catalog/drawer/
*
*/
/**
* Copyright (c) 2015-present, CWB SAS
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var MDC_DRAWERCONTENT = "mdc-drawer__content";
var DrawerContent = function DrawerContent(_ref) {
var children = _ref.children,
list = _ref.list,
props = (0, _objectWithoutProperties3.default)(_ref, ["children", "list"]);
var classes = MDC_DRAWERCONTENT;
if (list) {
classes += " mdc-list";
}
var ch = _react.Children.map(children, function (child, index) {
if (child.props && !child.props.mdcElement) {
var _child$props = child.props,
activated = _child$props.activated,
icon = _child$props.icon,
chn = _child$props.children,
ps = (0, _objectWithoutProperties3.default)(_child$props, ["activated", "icon", "children"]);
ps.className = "mdc-list-item";
if (activated) {
ps.className += " mdc-list-item--activated";
}
ps.key = "d_" + index;
var c = "";
if (icon) {
c = _react2.default.createElement(
_icon2.default,
{
key: index,
className: "mdc-list-item__graphic",
"aria-hidden": "true"
},
icon
);
}
return _react2.default.createElement(child.type, ps, [c, chn]);
} else if (child.props && (!child.props.type || child.props.type !== "a")) {
return _react2.default.cloneElement(child, (0, _extends3.default)({ type: "a" }, child.props.type));
}
return child;
});
return _2.default.render(_react2.default.createElement(
"nav",
{ className: classes },
ch
), props);
};
DrawerContent.defaultProps = {
mdcElement: MDC_DRAWERCONTENT,
children: null,
list: false
};
DrawerContent.propTypes = {
mdcElement: _propTypes2.default.string,
children: _propTypes2.default.node,
list: _propTypes2.default.bool
};
exports.default = DrawerContent;