UNPKG

1.82 kBJavaScriptView Raw
1const _excluded = ["value", "valueText", "pad", "placeholder", "min", "max", "emptyChar"];
2
3function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
4
5function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
6
7import React from 'react';
8
9const padStart = (value, len, padding) => {
10 let str = String(value != null ? value : '');
11
12 while (str.length < len) str = padding + str;
13
14 return str;
15};
16
17const DateTimePartInput = /*#__PURE__*/React.forwardRef((_ref, ref) => {
18 let {
19 value,
20 valueText = String(value != null ? value : ''),
21 pad,
22 placeholder,
23 min,
24 max,
25 emptyChar
26 } = _ref,
27 props = _objectWithoutPropertiesLoose(_ref, _excluded);
28
29 return /*#__PURE__*/React.createElement("input", _extends({}, props, {
30 ref: ref,
31 "data-focusable": true,
32 autoComplete: "off",
33 role: "spinbutton",
34 "aria-valuenow": value != null ? value : void 0,
35 "aria-valuemin": min,
36 "aria-valuemax": max,
37 "aria-valuetext": valueText // seems readonly is not valid
38 ,
39 "aria-disabled": props.disabled || props.readOnly,
40 "arai-placeholder": placeholder,
41 placeholder: placeholder,
42 className: "rw-time-part-input",
43 value: placeholder && !value ? '' : padStart(value, pad || 0, value == null ? emptyChar : '0')
44 }));
45});
46export default DateTimePartInput;
\No newline at end of file