UNPKG

@fluentui/react-northstar

Version:
59 lines (57 loc) 2.65 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); exports.__esModule = true; exports.partitionHTMLProps = exports.htmlInputProps = exports.htmlInputEvents = exports.htmlInputAttrs = exports.htmlImageProps = void 0; var _includes2 = _interopRequireDefault(require("lodash/includes")); var _forEach2 = _interopRequireDefault(require("lodash/forEach")); var htmlImageProps = ['alt', 'height', 'src', 'srcSet', 'width']; exports.htmlImageProps = htmlImageProps; var htmlInputAttrs = [ // REACT 'selected', 'defaultValue', 'defaultChecked', // LIMITED HTML PROPS 'accept', 'autoCapitalize', 'autoComplete', 'autoCorrect', 'autoFocus', 'checked', 'disabled', 'form', 'id', 'list', 'max', 'maxLength', 'min', 'minLength', 'multiple', 'name', 'pattern', 'placeholder', 'readOnly', 'required', 'step', 'type', 'value']; exports.htmlInputAttrs = htmlInputAttrs; 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']; exports.htmlInputEvents = htmlInputEvents; var htmlInputProps = [].concat(htmlInputAttrs, htmlInputEvents); exports.htmlInputProps = htmlInputProps; /** * Returns props of html input element and restProps. * @param props - A ReactElement props object * @param options - Options for * @returns - 2-element array. First element is props of HTML input element and second element is the other props. */ var partitionHTMLProps = function partitionHTMLProps(props, options) { if (options === void 0) { options = {}; } var _options = options, _options$htmlProps = _options.htmlProps, htmlProps = _options$htmlProps === void 0 ? htmlInputProps : _options$htmlProps, _options$includeAria = _options.includeAria, includeAria = _options$includeAria === void 0 ? true : _options$includeAria; var inputProps = {}; var restProps = {}; (0, _forEach2.default)(props, function (val, prop) { var possibleAria = includeAria && (/^aria-.*$/.test(prop) || prop === 'role'); var target = (0, _includes2.default)(htmlProps, prop) || possibleAria ? inputProps : restProps; target[prop] = val; }); return [inputProps, restProps]; }; exports.partitionHTMLProps = partitionHTMLProps; //# sourceMappingURL=htmlPropsUtils.js.map