semantic-ui-react
Version:
The official Semantic-UI-React integration.
59 lines (45 loc) • 2.14 kB
JavaScript
import _includes from 'lodash/includes';
import _forEach from 'lodash/forEach';
export var htmlInputAttrs = [
// REACT
'selected', 'defaultValue', 'defaultChecked',
// LIMITED HTML PROPS
'autoCapitalize', 'autoComplete', 'autoCorrect', 'autoFocus', 'checked', 'disabled', 'form', 'id', 'list', 'max', 'maxLength', 'min', 'minLength', 'multiple', 'name', 'pattern', 'placeholder', 'readOnly', 'required', 'step', 'type', 'value'];
export var htmlInputEvents = [
// EVENTS
// keyboard
'onKeyDown', 'onKeyPress', 'onKeyUp',
// focus
'onFocus', 'onBlur',
// form
'onChange', 'onInput',
// mouse
'onClick', 'onContextMenu', 'onDrag', 'onDragEnd', 'onDragEnter', 'onDragExit', 'onDragLeave', 'onDragOver', 'onDragStart', 'onDrop', 'onMouseDown', 'onMouseEnter', 'onMouseLeave', 'onMouseMove', 'onMouseOut', 'onMouseOver', 'onMouseUp',
// selection
'onSelect',
// touch
'onTouchCancel', 'onTouchEnd', 'onTouchMove', 'onTouchStart'];
export var htmlInputProps = [].concat(htmlInputAttrs, htmlInputEvents);
/**
* Returns an array of objects consisting of: props of html input element and rest.
* @param {object} props A ReactElement props object
* @param {Object} [options={}]
* @param {Array} [options.htmlProps] An array of html input props
* @param {boolean} [options.includeAria] Includes all input props that starts with "aria-"
* @returns {[{}, {}]} An array of objects
*/
export var partitionHTMLInputProps = function partitionHTMLInputProps(props) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var _options$htmlProps = options.htmlProps,
htmlProps = _options$htmlProps === undefined ? htmlInputProps : _options$htmlProps,
_options$includeAria = options.includeAria,
includeAria = _options$includeAria === undefined ? true : _options$includeAria;
var inputProps = {};
var rest = {};
_forEach(props, function (val, prop) {
var possibleAria = includeAria && (/^aria-.*$/.test(prop) || prop === 'role');
var target = _includes(htmlProps, prop) || possibleAria ? inputProps : rest;
target[prop] = val;
});
return [inputProps, rest];
};