Completely updated React, fixed #11, (hopefully)
This commit is contained in:
368
goTorrentWebUI/node_modules/material-ui/Select/SelectInput.js
generated
vendored
368
goTorrentWebUI/node_modules/material-ui/Select/SelectInput.js
generated
vendored
@@ -44,6 +44,10 @@ var _react = require('react');
|
||||
|
||||
var _react2 = _interopRequireDefault(_react);
|
||||
|
||||
var _propTypes = require('prop-types');
|
||||
|
||||
var _propTypes2 = _interopRequireDefault(_propTypes);
|
||||
|
||||
var _classnames = require('classnames');
|
||||
|
||||
var _classnames2 = _interopRequireDefault(_classnames);
|
||||
@@ -56,117 +60,18 @@ var _warning = require('warning');
|
||||
|
||||
var _warning2 = _interopRequireDefault(_warning);
|
||||
|
||||
var _ArrowDropDown = require('../internal/svg-icons/ArrowDropDown');
|
||||
|
||||
var _ArrowDropDown2 = _interopRequireDefault(_ArrowDropDown);
|
||||
|
||||
var _Menu = require('../Menu/Menu');
|
||||
|
||||
var _Menu2 = _interopRequireDefault(_Menu);
|
||||
|
||||
var _Input = require('../Input/Input');
|
||||
|
||||
var _ArrowDropDown = require('../svg-icons/ArrowDropDown');
|
||||
|
||||
var _ArrowDropDown2 = _interopRequireDefault(_ArrowDropDown);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
|
||||
|
||||
var babelPluginFlowReactPropTypes_proptype_Element = require('react').babelPluginFlowReactPropTypes_proptype_Element || require('prop-types').any;
|
||||
|
||||
var babelPluginFlowReactPropTypes_proptype_Props = {
|
||||
/**
|
||||
* If true, the width of the popover will automatically be set according to the items inside the
|
||||
* menu, otherwise it will be at least the width of the select input.
|
||||
*/
|
||||
autoWidth: require('prop-types').bool.isRequired,
|
||||
|
||||
/**
|
||||
* The option elements to populate the select with.
|
||||
* Can be some `MenuItem` when `native` is false and `option` when `native` is true.
|
||||
*/
|
||||
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node.isRequired ? babelPluginFlowReactPropTypes_proptype_Node.isRequired : babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node).isRequired,
|
||||
|
||||
/**
|
||||
* Useful to extend the style applied to components.
|
||||
*/
|
||||
classes: require('prop-types').object,
|
||||
|
||||
/**
|
||||
* The CSS class name of the select element.
|
||||
*/
|
||||
className: require('prop-types').string,
|
||||
|
||||
/**
|
||||
* If `true`, the select will be disabled.
|
||||
*/
|
||||
disabled: require('prop-types').bool,
|
||||
|
||||
/**
|
||||
* If `true`, the selected item is displayed even if its value is empty.
|
||||
* You can only use it when the `native` property is `false` (default).
|
||||
*/
|
||||
displayEmpty: require('prop-types').bool.isRequired,
|
||||
|
||||
/**
|
||||
* If `true`, the component will be using a native `select` element.
|
||||
*/
|
||||
native: require('prop-types').bool.isRequired,
|
||||
|
||||
/**
|
||||
* If true, `value` must be an array and the menu will support multiple selections.
|
||||
* You can only use it when the `native` property is `false` (default).
|
||||
*/
|
||||
multiple: require('prop-types').bool.isRequired,
|
||||
|
||||
/**
|
||||
* Properties applied to the `Menu` element.
|
||||
*/
|
||||
MenuProps: require('prop-types').object,
|
||||
|
||||
/**
|
||||
* Name attribute of the `select` or hidden `input` element.
|
||||
*/
|
||||
name: require('prop-types').string,
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
onBlur: require('prop-types').func,
|
||||
|
||||
/**
|
||||
* Callback function fired when a menu item is selected.
|
||||
*
|
||||
* @param {object} event The event source of the callback
|
||||
* @param {object} child The react element that was selected
|
||||
*/
|
||||
onChange: require('prop-types').func,
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
onFocus: require('prop-types').func,
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
readOnly: require('prop-types').bool,
|
||||
|
||||
/**
|
||||
* Render the selected value.
|
||||
* You can only use it when the `native` property is `false` (default).
|
||||
*/
|
||||
renderValue: require('prop-types').func,
|
||||
|
||||
/**
|
||||
* Use that property to pass a ref callback to the native select element.
|
||||
*/
|
||||
selectRef: require('prop-types').func,
|
||||
|
||||
/**
|
||||
* The value of the component, required for a controlled component.
|
||||
*/
|
||||
value: require('prop-types').oneOfType([require('prop-types').string, require('prop-types').number, typeof $ReadOnlyArray === 'function' ? require('prop-types').instanceOf($ReadOnlyArray) : require('prop-types').any])
|
||||
};
|
||||
|
||||
/**
|
||||
* @ignore - internal component.
|
||||
*/
|
||||
@@ -185,53 +90,69 @@ var SelectInput = function (_React$Component) {
|
||||
}
|
||||
|
||||
return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_ref = SelectInput.__proto__ || (0, _getPrototypeOf2.default)(SelectInput)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
|
||||
anchorEl: null,
|
||||
open: false
|
||||
}, _this.ignoreNextBlur = false, _this.handleClick = function (event) {
|
||||
}, _this.ignoreNextBlur = false, _this.displayNode = null, _this.isControlled = _this.props.open !== undefined, _this.update = _this.isControlled ? function (_ref2) {
|
||||
var event = _ref2.event,
|
||||
open = _ref2.open;
|
||||
|
||||
if (open) {
|
||||
_this.props.onOpen(event);
|
||||
} else {
|
||||
_this.props.onClose(event);
|
||||
}
|
||||
} : function (_ref3) {
|
||||
var open = _ref3.open;
|
||||
return _this.setState({ open: open });
|
||||
}, _this.handleClick = function (event) {
|
||||
// Opening the menu is going to blur the. It will be focused back when closed.
|
||||
_this.ignoreNextBlur = true;
|
||||
_this.setState({
|
||||
_this.update({
|
||||
open: true,
|
||||
anchorEl: event.currentTarget
|
||||
event: event
|
||||
});
|
||||
}, _this.handleRequestClose = function () {
|
||||
_this.setState({
|
||||
open: false
|
||||
}, _this.handleClose = function (event) {
|
||||
_this.update({
|
||||
open: false,
|
||||
event: event
|
||||
});
|
||||
}, _this.handleItemClick = function (child) {
|
||||
return function (event) {
|
||||
if (!_this.props.multiple) {
|
||||
_this.setState({
|
||||
open: false
|
||||
_this.update({
|
||||
open: false,
|
||||
event: event
|
||||
});
|
||||
}
|
||||
|
||||
if (_this.props.onChange) {
|
||||
var _onChange = _this.props.onChange;
|
||||
var _this$props = _this.props,
|
||||
onChange = _this$props.onChange,
|
||||
name = _this$props.name;
|
||||
|
||||
var _value = void 0;
|
||||
var _target = void 0;
|
||||
|
||||
if (onChange) {
|
||||
var value = void 0;
|
||||
var target = void 0;
|
||||
|
||||
if (event.target) {
|
||||
_target = event.target;
|
||||
target = event.target;
|
||||
}
|
||||
|
||||
if (_this.props.multiple) {
|
||||
_value = Array.isArray(_this.props.value) ? [].concat((0, _toConsumableArray3.default)(_this.props.value)) : [];
|
||||
var itemIndex = _value.indexOf(child.props.value);
|
||||
value = Array.isArray(_this.props.value) ? [].concat((0, _toConsumableArray3.default)(_this.props.value)) : [];
|
||||
var itemIndex = value.indexOf(child.props.value);
|
||||
if (itemIndex === -1) {
|
||||
_value.push(child.props.value);
|
||||
value.push(child.props.value);
|
||||
} else {
|
||||
_value.splice(itemIndex, 1);
|
||||
value.splice(itemIndex, 1);
|
||||
}
|
||||
} else {
|
||||
_value = child.props.value;
|
||||
value = child.props.value;
|
||||
}
|
||||
|
||||
event.persist();
|
||||
event.target = (0, _extends3.default)({}, _target, { value: _value });
|
||||
event.target = (0, _extends3.default)({}, target, { value: value, name: name });
|
||||
|
||||
_onChange(event, child);
|
||||
onChange(event, child);
|
||||
}
|
||||
};
|
||||
}, _this.handleBlur = function (event) {
|
||||
@@ -254,17 +175,17 @@ var SelectInput = function (_React$Component) {
|
||||
event.preventDefault();
|
||||
// Opening the menu is going to blur the. It will be focused back when closed.
|
||||
_this.ignoreNextBlur = true;
|
||||
_this.setState({
|
||||
_this.update({
|
||||
open: true,
|
||||
anchorEl: event.currentTarget
|
||||
event: event
|
||||
});
|
||||
}
|
||||
}, _this.handleSelectRef = function (node) {
|
||||
if (!_this.props.selectRef) {
|
||||
if (!_this.props.inputRef) {
|
||||
return;
|
||||
}
|
||||
|
||||
_this.props.selectRef({
|
||||
_this.props.inputRef({
|
||||
node: node,
|
||||
// By pass the native input as we expose a rich object (array).
|
||||
value: _this.props.value
|
||||
@@ -273,6 +194,17 @@ var SelectInput = function (_React$Component) {
|
||||
}
|
||||
|
||||
(0, _createClass3.default)(SelectInput, [{
|
||||
key: 'componentDidMount',
|
||||
value: function componentDidMount() {
|
||||
if (this.isControlled && this.props.open) {
|
||||
// Focus the display node so the focus is restored on this element once
|
||||
// the menu is closed.
|
||||
this.displayNode.focus();
|
||||
// Rerender with the resolve `displayNode` reference.
|
||||
this.forceUpdate();
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: 'render',
|
||||
value: function render() {
|
||||
var _this2 = this;
|
||||
@@ -280,24 +212,32 @@ var SelectInput = function (_React$Component) {
|
||||
var _props = this.props,
|
||||
autoWidth = _props.autoWidth,
|
||||
children = _props.children,
|
||||
classNameProp = _props.className,
|
||||
classes = _props.classes,
|
||||
classNameProp = _props.className,
|
||||
disabled = _props.disabled,
|
||||
displayEmpty = _props.displayEmpty,
|
||||
name = _props.name,
|
||||
native = _props.native,
|
||||
multiple = _props.multiple,
|
||||
inputRef = _props.inputRef,
|
||||
_props$MenuProps = _props.MenuProps,
|
||||
MenuProps = _props$MenuProps === undefined ? {} : _props$MenuProps,
|
||||
multiple = _props.multiple,
|
||||
name = _props.name,
|
||||
native = _props.native,
|
||||
onBlur = _props.onBlur,
|
||||
onChange = _props.onChange,
|
||||
onClose = _props.onClose,
|
||||
onFocus = _props.onFocus,
|
||||
onOpen = _props.onOpen,
|
||||
openProp = _props.open,
|
||||
readOnly = _props.readOnly,
|
||||
renderValue = _props.renderValue,
|
||||
selectRef = _props.selectRef,
|
||||
SelectDisplayProps = _props.SelectDisplayProps,
|
||||
tabIndexProp = _props.tabIndex,
|
||||
_props$type = _props.type,
|
||||
type = _props$type === undefined ? 'hidden' : _props$type,
|
||||
value = _props.value,
|
||||
other = (0, _objectWithoutProperties3.default)(_props, ['autoWidth', 'children', 'className', 'classes', 'disabled', 'displayEmpty', 'name', 'native', 'multiple', 'MenuProps', 'onBlur', 'onChange', 'onFocus', 'readOnly', 'renderValue', 'selectRef', 'value']);
|
||||
other = (0, _objectWithoutProperties3.default)(_props, ['autoWidth', 'children', 'classes', 'className', 'disabled', 'displayEmpty', 'inputRef', 'MenuProps', 'multiple', 'name', 'native', 'onBlur', 'onChange', 'onClose', 'onFocus', 'onOpen', 'open', 'readOnly', 'renderValue', 'SelectDisplayProps', 'tabIndex', 'type', 'value']);
|
||||
|
||||
var open = this.isControlled && this.displayNode ? openProp : this.state.open;
|
||||
|
||||
if (native) {
|
||||
process.env.NODE_ENV !== "production" ? (0, _warning2.default)(multiple === false, 'Material-UI: you can not use the `native` and `multiple` properties ' + 'at the same time on a `Select` component.') : void 0;
|
||||
@@ -317,10 +257,9 @@ var SelectInput = function (_React$Component) {
|
||||
onChange: onChange,
|
||||
onFocus: onFocus,
|
||||
value: value,
|
||||
readOnly: readOnly
|
||||
}, other, {
|
||||
ref: selectRef
|
||||
}),
|
||||
readOnly: readOnly,
|
||||
ref: inputRef
|
||||
}, other),
|
||||
children
|
||||
),
|
||||
_react2.default.createElement(_ArrowDropDown2.default, { className: classes.icon })
|
||||
@@ -378,51 +317,61 @@ var SelectInput = function (_React$Component) {
|
||||
display = multiple ? displayMultiple.join(', ') : displaySingle;
|
||||
}
|
||||
|
||||
var minimumMenuWidth = this.state.anchorEl != null && !autoWidth ? this.state.anchorEl.clientWidth : undefined;
|
||||
var MenuMinWidth = this.displayNode && !autoWidth ? this.displayNode.clientWidth : undefined;
|
||||
|
||||
var tabIndex = void 0;
|
||||
if (typeof tabIndexProp !== 'undefined') {
|
||||
tabIndex = tabIndexProp;
|
||||
} else {
|
||||
tabIndex = disabled ? null : 0;
|
||||
}
|
||||
|
||||
return _react2.default.createElement(
|
||||
'div',
|
||||
{ className: classes.root },
|
||||
_react2.default.createElement(
|
||||
'div',
|
||||
{
|
||||
(0, _extends3.default)({
|
||||
className: (0, _classnames2.default)(classes.select, classes.selectMenu, (0, _defineProperty3.default)({}, classes.disabled, disabled), classNameProp),
|
||||
ref: function ref(node) {
|
||||
_this2.displayNode = node;
|
||||
},
|
||||
|
||||
'aria-pressed': this.state.open ? 'true' : 'false',
|
||||
tabIndex: disabled ? null : 0,
|
||||
'aria-pressed': open ? 'true' : 'false',
|
||||
tabIndex: tabIndex,
|
||||
role: 'button',
|
||||
'aria-owns': this.state.open ? 'menu-' + (name || '') : null,
|
||||
'aria-owns': open ? 'menu-' + (name || '') : null,
|
||||
'aria-haspopup': 'true',
|
||||
onKeyDown: this.handleKeyDown,
|
||||
onBlur: this.handleBlur,
|
||||
onClick: disabled || readOnly ? null : this.handleClick,
|
||||
onFocus: onFocus
|
||||
},
|
||||
}, SelectDisplayProps),
|
||||
_react2.default.createElement('span', { dangerouslySetInnerHTML: { __html: '​' } }),
|
||||
display
|
||||
),
|
||||
_react2.default.createElement('input', (0, _extends3.default)({
|
||||
value: Array.isArray(value) ? value.join(',') : value,
|
||||
name: name,
|
||||
readOnly: readOnly
|
||||
}, other, {
|
||||
readOnly: readOnly,
|
||||
ref: this.handleSelectRef,
|
||||
type: 'hidden'
|
||||
})),
|
||||
type: type
|
||||
}, other)),
|
||||
_react2.default.createElement(_ArrowDropDown2.default, { className: classes.icon }),
|
||||
_react2.default.createElement(
|
||||
_Menu2.default,
|
||||
(0, _extends3.default)({
|
||||
id: 'menu-' + (name || ''),
|
||||
anchorEl: this.state.anchorEl,
|
||||
open: this.state.open,
|
||||
onRequestClose: this.handleRequestClose
|
||||
anchorEl: this.displayNode,
|
||||
open: open,
|
||||
onClose: this.handleClose
|
||||
}, MenuProps, {
|
||||
MenuListProps: (0, _extends3.default)({}, MenuProps.MenuListProps, {
|
||||
MenuListProps: (0, _extends3.default)({
|
||||
role: 'listbox'
|
||||
}),
|
||||
}, MenuProps.MenuListProps),
|
||||
PaperProps: (0, _extends3.default)({}, MenuProps.PaperProps, {
|
||||
style: (0, _extends3.default)({
|
||||
minWidth: minimumMenuWidth
|
||||
minWidth: MenuMinWidth
|
||||
}, MenuProps.PaperProps != null ? MenuProps.PaperProps.style : null)
|
||||
})
|
||||
}),
|
||||
@@ -434,5 +383,114 @@ var SelectInput = function (_React$Component) {
|
||||
return SelectInput;
|
||||
}(_react2.default.Component);
|
||||
|
||||
SelectInput.muiName = 'SelectInput';
|
||||
SelectInput.propTypes = process.env.NODE_ENV !== "production" ? {
|
||||
/**
|
||||
* If true, the width of the popover will automatically be set according to the items inside the
|
||||
* menu, otherwise it will be at least the width of the select input.
|
||||
*/
|
||||
autoWidth: _propTypes2.default.bool,
|
||||
/**
|
||||
* The option elements to populate the select with.
|
||||
* Can be some `MenuItem` when `native` is false and `option` when `native` is true.
|
||||
*/
|
||||
children: _propTypes2.default.node,
|
||||
/**
|
||||
* Useful to extend the style applied to components.
|
||||
*/
|
||||
classes: _propTypes2.default.object.isRequired,
|
||||
/**
|
||||
* The CSS class name of the select element.
|
||||
*/
|
||||
className: _propTypes2.default.string,
|
||||
/**
|
||||
* If `true`, the select will be disabled.
|
||||
*/
|
||||
disabled: _propTypes2.default.bool,
|
||||
/**
|
||||
* If `true`, the selected item is displayed even if its value is empty.
|
||||
* You can only use it when the `native` property is `false` (default).
|
||||
*/
|
||||
displayEmpty: _propTypes2.default.bool,
|
||||
/**
|
||||
* Use that property to pass a ref callback to the native select element.
|
||||
*/
|
||||
inputRef: _propTypes2.default.func,
|
||||
/**
|
||||
* Properties applied to the `Menu` element.
|
||||
*/
|
||||
MenuProps: _propTypes2.default.object,
|
||||
/**
|
||||
* If true, `value` must be an array and the menu will support multiple selections.
|
||||
* You can only use it when the `native` property is `false` (default).
|
||||
*/
|
||||
multiple: _propTypes2.default.bool,
|
||||
/**
|
||||
* Name attribute of the `select` or hidden `input` element.
|
||||
*/
|
||||
name: _propTypes2.default.string,
|
||||
/**
|
||||
* If `true`, the component will be using a native `select` element.
|
||||
*/
|
||||
native: _propTypes2.default.bool,
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
onBlur: _propTypes2.default.func,
|
||||
/**
|
||||
* Callback function fired when a menu item is selected.
|
||||
*
|
||||
* @param {object} event The event source of the callback
|
||||
* @param {object} child The react element that was selected
|
||||
*/
|
||||
onChange: _propTypes2.default.func,
|
||||
/**
|
||||
* Callback fired when the component requests to be closed.
|
||||
* Useful in controlled mode (see open).
|
||||
*
|
||||
* @param {object} event The event source of the callback
|
||||
*/
|
||||
onClose: _propTypes2.default.func,
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
onFocus: _propTypes2.default.func,
|
||||
/**
|
||||
* Callback fired when the component requests to be opened.
|
||||
* Useful in controlled mode (see open).
|
||||
*
|
||||
* @param {object} event The event source of the callback
|
||||
*/
|
||||
onOpen: _propTypes2.default.func,
|
||||
/**
|
||||
* Control `select` open state.
|
||||
* You can only use it when the `native` property is `false` (default).
|
||||
*/
|
||||
open: _propTypes2.default.bool,
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
readOnly: _propTypes2.default.bool,
|
||||
/**
|
||||
* Render the selected value.
|
||||
* You can only use it when the `native` property is `false` (default).
|
||||
*/
|
||||
renderValue: _propTypes2.default.func,
|
||||
/**
|
||||
* Properties applied to the clickable div element.
|
||||
*/
|
||||
SelectDisplayProps: _propTypes2.default.object,
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
tabIndex: _propTypes2.default.oneOfType([_propTypes2.default.number, _propTypes2.default.string]),
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
type: _propTypes2.default.string,
|
||||
/**
|
||||
* The value of the component, required for a controlled component.
|
||||
*/
|
||||
value: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.number, _propTypes2.default.arrayOf(_propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.number]))])
|
||||
} : {};
|
||||
|
||||
exports.default = SelectInput;
|
Reference in New Issue
Block a user