|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415 |
- '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 _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
-
- var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
-
- var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
-
- var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
-
- var _createClass2 = require('babel-runtime/helpers/createClass');
-
- var _createClass3 = _interopRequireDefault(_createClass2);
-
- var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
-
- var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
-
- var _inherits2 = require('babel-runtime/helpers/inherits');
-
- var _inherits3 = _interopRequireDefault(_inherits2);
-
- var _simpleAssign = require('simple-assign');
-
- var _simpleAssign2 = _interopRequireDefault(_simpleAssign);
-
- var _react = require('react');
-
- var _react2 = _interopRequireDefault(_react);
-
- var _propTypes = require('prop-types');
-
- var _propTypes2 = _interopRequireDefault(_propTypes);
-
- var _reactDom = require('react-dom');
-
- var _reactDom2 = _interopRequireDefault(_reactDom);
-
- var _events = require('../utils/events');
-
- var _events2 = _interopRequireDefault(_events);
-
- var _propTypes3 = require('../utils/propTypes');
-
- var _propTypes4 = _interopRequireDefault(_propTypes3);
-
- var _Menu = require('../Menu/Menu');
-
- var _Menu2 = _interopRequireDefault(_Menu);
-
- var _Popover = require('../Popover/Popover');
-
- var _Popover2 = _interopRequireDefault(_Popover);
-
- var _warning = require('warning');
-
- var _warning2 = _interopRequireDefault(_warning);
-
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
-
- var IconMenu = function (_Component) {
- (0, _inherits3.default)(IconMenu, _Component);
-
- function IconMenu() {
- var _ref;
-
- var _temp, _this, _ret;
-
- (0, _classCallCheck3.default)(this, IconMenu);
-
- for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
- }
-
- return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_ref = IconMenu.__proto__ || (0, _getPrototypeOf2.default)(IconMenu)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
- menuInitiallyKeyboardFocused: false,
- open: false
- }, _this.handleItemClick = function (event, child) {
- if (_this.props.clickCloseDelay !== 0 && !child.props.hasOwnProperty('menuItems')) {
- var isKeyboard = _events2.default.isKeyboard(event);
- _this.timerCloseId = setTimeout(function () {
- _this.close(isKeyboard ? 'enter' : 'itemTap', isKeyboard);
- }, _this.props.clickCloseDelay);
- }
-
- _this.props.onItemClick(event, child);
- }, _this.handleRequestClose = function (reason) {
- _this.close(reason);
- }, _this.handleEscKeyDownMenu = function (event) {
- _this.close('escape', event);
- }, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
- }
-
- (0, _createClass3.default)(IconMenu, [{
- key: 'componentWillReceiveProps',
- value: function componentWillReceiveProps(nextProps) {
- if (nextProps.open != null) {
- this.setState({
- open: nextProps.open,
- anchorEl: this.refs.iconMenuContainer
- });
- }
- }
- }, {
- key: 'componentWillUnmount',
- value: function componentWillUnmount() {
- clearTimeout(this.timerCloseId);
- }
- }, {
- key: 'isOpen',
- value: function isOpen() {
- return this.state.open;
- }
- }, {
- key: 'close',
- value: function close(reason, isKeyboard) {
- var _this2 = this;
-
- if (!this.state.open) {
- return;
- }
-
- if (this.props.open !== null) {
- this.props.onRequestChange(false, reason);
- } else {
- this.setState({ open: false }, function () {
- // Set focus on the icon button when the menu close
- if (isKeyboard) {
- var iconButton = _this2.refs.iconButton;
- _reactDom2.default.findDOMNode(iconButton).focus();
- iconButton.setKeyboardFocus();
- }
- });
- }
- }
- }, {
- key: 'open',
- value: function open(reason, event) {
- if (this.props.open !== null) {
- this.props.onRequestChange(true, reason);
-
- return this.setState({
- menuInitiallyKeyboardFocused: _events2.default.isKeyboard(event),
- anchorEl: event.currentTarget
- });
- }
-
- this.setState({
- open: true,
- menuInitiallyKeyboardFocused: _events2.default.isKeyboard(event),
- anchorEl: event.currentTarget
- });
- }
- }, {
- key: 'render',
- value: function render() {
- var _this3 = this;
-
- var _props = this.props,
- anchorOrigin = _props.anchorOrigin,
- className = _props.className,
- animated = _props.animated,
- animation = _props.animation,
- iconButtonElement = _props.iconButtonElement,
- iconStyle = _props.iconStyle,
- onItemClick = _props.onItemClick,
- onKeyboardFocus = _props.onKeyboardFocus,
- onMouseDown = _props.onMouseDown,
- onMouseLeave = _props.onMouseLeave,
- onMouseEnter = _props.onMouseEnter,
- onMouseUp = _props.onMouseUp,
- onRequestChange = _props.onRequestChange,
- onClick = _props.onClick,
- listStyle = _props.listStyle,
- menuStyle = _props.menuStyle,
- style = _props.style,
- targetOrigin = _props.targetOrigin,
- clickCloseDelay = _props.clickCloseDelay,
- useLayerForClickAway = _props.useLayerForClickAway,
- other = (0, _objectWithoutProperties3.default)(_props, ['anchorOrigin', 'className', 'animated', 'animation', 'iconButtonElement', 'iconStyle', 'onItemClick', 'onKeyboardFocus', 'onMouseDown', 'onMouseLeave', 'onMouseEnter', 'onMouseUp', 'onRequestChange', 'onClick', 'listStyle', 'menuStyle', 'style', 'targetOrigin', 'clickCloseDelay', 'useLayerForClickAway']);
- var prepareStyles = this.context.muiTheme.prepareStyles;
- var _state = this.state,
- open = _state.open,
- anchorEl = _state.anchorEl;
-
-
- var styles = {
- root: {
- display: 'inline-block',
- position: 'relative'
- },
- menu: {
- position: 'relative'
- }
- };
-
- var mergedRootStyles = (0, _simpleAssign2.default)(styles.root, style);
- var mergedMenuStyles = (0, _simpleAssign2.default)(styles.menu, menuStyle);
-
- process.env.NODE_ENV !== "production" ? (0, _warning2.default)(iconButtonElement.type.muiName !== 'SvgIcon', 'Material-UI: You shoud not provide an <SvgIcon /> to the \'iconButtonElement\' property of <IconMenu />.\nYou should wrapped it with an <IconButton />.') : void 0;
-
- var iconButtonProps = {
- onKeyboardFocus: onKeyboardFocus,
- onClick: function onClick(event) {
- _this3.open(_events2.default.isKeyboard(event) ? 'keyboard' : 'iconTap', event);
- if (iconButtonElement.props.onClick) {
- iconButtonElement.props.onClick(event);
- }
- },
- ref: 'iconButton'
- };
- if (iconStyle || iconButtonElement.props.iconStyle) {
- iconButtonProps.iconStyle = iconStyle ? (0, _simpleAssign2.default)({}, iconStyle, iconButtonElement.props.iconStyle) : iconButtonElement.props.iconStyle;
- }
- var iconButton = _react2.default.cloneElement(iconButtonElement, iconButtonProps);
-
- var menu = _react2.default.createElement(
- _Menu2.default,
- (0, _extends3.default)({}, other, {
- initiallyKeyboardFocused: this.state.menuInitiallyKeyboardFocused,
- onEscKeyDown: this.handleEscKeyDownMenu,
- onItemClick: this.handleItemClick,
- style: mergedMenuStyles,
- listStyle: listStyle
- }),
- this.props.children
- );
-
- return _react2.default.createElement(
- 'div',
- {
- ref: 'iconMenuContainer',
- className: className,
- onMouseDown: onMouseDown,
- onMouseLeave: onMouseLeave,
- onMouseEnter: onMouseEnter,
- onMouseUp: onMouseUp,
- onClick: onClick,
- style: prepareStyles(mergedRootStyles)
- },
- iconButton,
- _react2.default.createElement(
- _Popover2.default,
- {
- anchorOrigin: anchorOrigin,
- targetOrigin: targetOrigin,
- open: open,
- anchorEl: anchorEl,
- childContextTypes: this.constructor.childContextTypes,
- useLayerForClickAway: useLayerForClickAway,
- onRequestClose: this.handleRequestClose,
- animated: animated,
- animation: animation,
- context: this.context
- },
- menu
- )
- );
- }
- }]);
- return IconMenu;
- }(_react.Component);
-
- IconMenu.muiName = 'IconMenu';
- IconMenu.defaultProps = {
- anchorOrigin: {
- vertical: 'top',
- horizontal: 'left'
- },
- animated: true,
- multiple: false,
- open: null,
- onItemClick: function onItemClick() {},
- onKeyboardFocus: function onKeyboardFocus() {},
- onMouseDown: function onMouseDown() {},
- onMouseLeave: function onMouseLeave() {},
- onMouseEnter: function onMouseEnter() {},
- onMouseUp: function onMouseUp() {},
- onRequestChange: function onRequestChange() {},
- onClick: function onClick() {},
- targetOrigin: {
- vertical: 'top',
- horizontal: 'left'
- },
- clickCloseDelay: 200,
- useLayerForClickAway: false
- };
- IconMenu.contextTypes = {
- muiTheme: _propTypes2.default.object.isRequired
- };
- IconMenu.propTypes = process.env.NODE_ENV !== "production" ? {
- /**
- * This is the point on the icon where the menu
- * `targetOrigin` will attach.
- * Options:
- * vertical: [top, center, bottom]
- * horizontal: [left, middle, right].
- */
- anchorOrigin: _propTypes4.default.origin,
- /**
- * If true, the popover will apply transitions when
- * it gets added to the DOM.
- */
- animated: _propTypes2.default.bool,
- /**
- * Override the default animation component used.
- */
- animation: _propTypes2.default.func,
- /**
- * Should be used to pass `MenuItem` components.
- */
- children: _propTypes2.default.node,
- /**
- * The CSS class name of the root element.
- */
- className: _propTypes2.default.string,
- /**
- * Sets the delay in milliseconds before closing the
- * menu when an item is clicked.
- * If set to 0 then the auto close functionality
- * will be disabled.
- */
- clickCloseDelay: _propTypes2.default.number,
- /**
- * This is the `IconButton` to render. This button will open the menu.
- */
- iconButtonElement: _propTypes2.default.element.isRequired,
- /**
- * Override the inline-styles of the underlying icon element.
- */
- iconStyle: _propTypes2.default.object,
- /**
- * Override the inline-styles of the underlying `List` element.
- */
- listStyle: _propTypes2.default.object,
- /**
- * Override the inline-styles of the menu element.
- */
- menuStyle: _propTypes2.default.object,
- /**
- * If true, the value can an be array and allow the menu to be a multi-select.
- */
- multiple: _propTypes2.default.bool,
- /**
- * Callback function fired when the `IconButton` element is clicked.
- *
- * @param {object} event Click event targeting the `IconButton` element.
- */
- onClick: _propTypes2.default.func,
- /**
- * Callback function fired when a menu item is selected with a click.
- *
- * @param {object} event Click event targeting the selected menu item element.
- * @param {object} child The selected element.
- */
- onItemClick: _propTypes2.default.func,
- /**
- * Callback function fired when the `IconButton` element is focused or blurred by the keyboard.
- *
- * @param {object} event `focus` or `blur` event targeting the `IconButton` element.
- * @param {boolean} keyboardFocused If true, the `IconButton` element is focused.
- */
- onKeyboardFocus: _propTypes2.default.func,
- /** @ignore */
- onMouseDown: _propTypes2.default.func,
- /** @ignore */
- onMouseEnter: _propTypes2.default.func,
- /** @ignore */
- onMouseLeave: _propTypes2.default.func,
- /** @ignore */
- onMouseUp: _propTypes2.default.func,
- /**
- * Callback function fired when the `open` state of the menu is requested to be changed.
- *
- * @param {boolean} open If true, the menu was requested to be opened.
- * @param {string} reason The reason for the open or close request. Possible values are
- * 'keyboard' and 'iconTap' for open requests; 'enter', 'escape', 'itemTap', and 'clickAway'
- * for close requests.
- */
- onRequestChange: _propTypes2.default.func,
- /**
- * If true, the `IconMenu` is opened.
- */
- open: _propTypes2.default.bool,
- /**
- * Override the inline-styles of the root element.
- */
- style: _propTypes2.default.object,
- /**
- * This is the point on the menu which will stick to the menu
- * origin.
- * Options:
- * vertical: [top, center, bottom]
- * horizontal: [left, middle, right].
- */
- targetOrigin: _propTypes4.default.origin,
- /**
- * If true, the popover will render on top of an invisible
- * layer, which will prevent clicks to the underlying elements.
- */
- useLayerForClickAway: _propTypes2.default.bool
- } : {};
- exports.default = IconMenu;
|