@alfalab/core-components-time-input 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Component.d.ts +41 -0
- package/Component.js +91 -0
- package/cssm/Component.d.ts +41 -0
- package/cssm/Component.js +91 -0
- package/cssm/index.d.ts +2 -0
- package/cssm/index.js +13 -0
- package/cssm/utils/format.d.ts +6 -0
- package/cssm/utils/format.js +35 -0
- package/cssm/utils/index.d.ts +1 -0
- package/cssm/utils/index.js +13 -0
- package/esm/Component.d.ts +41 -0
- package/esm/Component.js +83 -0
- package/esm/index.d.ts +2 -0
- package/esm/index.js +4 -0
- package/esm/utils/format.d.ts +6 -0
- package/esm/utils/format.js +27 -0
- package/esm/utils/index.d.ts +1 -0
- package/esm/utils/index.js +1 -0
- package/index.d.ts +2 -0
- package/index.js +13 -0
- package/modern/Component.d.ts +41 -0
- package/modern/Component.js +43 -0
- package/modern/index.d.ts +2 -0
- package/modern/index.js +4 -0
- package/modern/utils/format.d.ts +6 -0
- package/modern/utils/format.js +23 -0
- package/modern/utils/index.d.ts +1 -0
- package/modern/utils/index.js +1 -0
- package/package.json +21 -0
- package/send-stats.js +82 -0
- package/utils/format.d.ts +6 -0
- package/utils/format.js +35 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +13 -0
package/Component.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ChangeEvent } from "react";
|
|
4
|
+
import { InputProps } from "@alfalab/core-components-input";
|
|
5
|
+
type TimeInputProps = Omit<InputProps, 'onChange'> & {
|
|
6
|
+
/**
|
|
7
|
+
* Обработчик изменения значения
|
|
8
|
+
*/
|
|
9
|
+
onChange?: (event: ChangeEvent<HTMLInputElement>, payload: {
|
|
10
|
+
hours: number;
|
|
11
|
+
mins: number;
|
|
12
|
+
value: string;
|
|
13
|
+
}) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Обработчик окончания ввода
|
|
16
|
+
*/
|
|
17
|
+
onComplete?: (event: ChangeEvent<HTMLInputElement>, payload: {
|
|
18
|
+
hours: number;
|
|
19
|
+
mins: number;
|
|
20
|
+
value: string;
|
|
21
|
+
}) => void;
|
|
22
|
+
};
|
|
23
|
+
declare const TimeInput: React.ForwardRefExoticComponent<Pick<InputProps, "className" | "dataTestId" | "form" | "label" | "slot" | "style" | "title" | "pattern" | "leftAddons" | "rightAddons" | "size" | "block" | "colors" | "children" | "type" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "list" | "step" | "autoFocus" | "disabled" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "name" | "value" | "fieldClassName" | "labelClassName" | "addonsClassName" | "error" | "hint" | "labelView" | "bottomAddons" | "accept" | "alt" | "autoComplete" | "capture" | "checked" | "crossOrigin" | "height" | "max" | "maxLength" | "min" | "minLength" | "multiple" | "readOnly" | "required" | "src" | "width" | "clear" | "success" | "inputClassName" | "focusedClassName" | "filledClassName" | "onClear" | "wrapperRef"> & {
|
|
24
|
+
/**
|
|
25
|
+
* Обработчик изменения значения
|
|
26
|
+
*/
|
|
27
|
+
onChange?: ((event: React.ChangeEvent<HTMLInputElement>, payload: {
|
|
28
|
+
hours: number;
|
|
29
|
+
mins: number;
|
|
30
|
+
value: string;
|
|
31
|
+
}) => void) | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Обработчик окончания ввода
|
|
34
|
+
*/
|
|
35
|
+
onComplete?: ((event: React.ChangeEvent<HTMLInputElement>, payload: {
|
|
36
|
+
hours: number;
|
|
37
|
+
mins: number;
|
|
38
|
+
value: string;
|
|
39
|
+
}) => void) | undefined;
|
|
40
|
+
} & React.RefAttributes<HTMLInputElement>>;
|
|
41
|
+
export { TimeInputProps, TimeInput };
|
package/Component.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var coreComponentsInput = require('@alfalab/core-components-input');
|
|
7
|
+
var utils_format = require('./utils/format.js');
|
|
8
|
+
|
|
9
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
+
|
|
11
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
12
|
+
|
|
13
|
+
/*! *****************************************************************************
|
|
14
|
+
Copyright (c) Microsoft Corporation.
|
|
15
|
+
|
|
16
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
17
|
+
purpose with or without fee is hereby granted.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
20
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
21
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
22
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
23
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
24
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
25
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
26
|
+
***************************************************************************** */
|
|
27
|
+
var __assign = function () {
|
|
28
|
+
__assign = Object.assign || function __assign(t) {
|
|
29
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
30
|
+
s = arguments[i];
|
|
31
|
+
for (var p in s)
|
|
32
|
+
if (Object.prototype.hasOwnProperty.call(s, p))
|
|
33
|
+
t[p] = s[p];
|
|
34
|
+
}
|
|
35
|
+
return t;
|
|
36
|
+
};
|
|
37
|
+
return __assign.apply(this, arguments);
|
|
38
|
+
};
|
|
39
|
+
function __rest(s, e) {
|
|
40
|
+
var t = {};
|
|
41
|
+
for (var p in s)
|
|
42
|
+
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
43
|
+
t[p] = s[p];
|
|
44
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
45
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
46
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
47
|
+
t[p[i]] = s[p[i]];
|
|
48
|
+
}
|
|
49
|
+
return t;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/* eslint-disable no-useless-escape */
|
|
53
|
+
var TimeInput = React__default['default'].forwardRef(function (_a, ref) {
|
|
54
|
+
var _b = _a.defaultValue, defaultValue = _b === void 0 ? '' : _b, propValue = _a.value, onChange = _a.onChange, onComplete = _a.onComplete, className = _a.className, restProps = __rest(_a, ["defaultValue", "value", "onChange", "onComplete", "className"]);
|
|
55
|
+
var _c = React.useState(propValue || defaultValue), value = _c[0], setValue = _c[1];
|
|
56
|
+
var handleChange = function (event) {
|
|
57
|
+
var newValue = event.target.value;
|
|
58
|
+
if (newValue.length > 5)
|
|
59
|
+
return;
|
|
60
|
+
// Позволяем вводить только цифры и двоеточия
|
|
61
|
+
if (/[^\d:]/.test(newValue)) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
var colon = newValue.match(/\:/g);
|
|
65
|
+
// Не даем вводить больше, чем одно двоеточие
|
|
66
|
+
if (colon && colon.length > 1) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
var formattedValue = utils_format.format(newValue);
|
|
70
|
+
var formattedValueArr = formattedValue.split(':');
|
|
71
|
+
var hours = Number(formattedValueArr[0]);
|
|
72
|
+
var mins = Number(formattedValueArr[1]);
|
|
73
|
+
setValue(formattedValue);
|
|
74
|
+
if (onChange)
|
|
75
|
+
onChange(event, { hours: hours, mins: mins, value: formattedValue });
|
|
76
|
+
if (utils_format.isCompleteTimeInput(formattedValue)) {
|
|
77
|
+
var valid = formattedValue.length > 0 && utils_format.isValidInputValue(formattedValue);
|
|
78
|
+
if (!valid)
|
|
79
|
+
return;
|
|
80
|
+
if (onComplete) {
|
|
81
|
+
onComplete(event, { hours: hours, mins: mins, value: formattedValue });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
var handleClearClick = function () {
|
|
86
|
+
setValue('');
|
|
87
|
+
};
|
|
88
|
+
return (React__default['default'].createElement(coreComponentsInput.Input, __assign({}, restProps, { ref: ref, value: value, className: className, onChange: handleChange, onClear: handleClearClick })));
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
exports.TimeInput = TimeInput;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ChangeEvent } from "react";
|
|
4
|
+
import { InputProps } from "@alfalab/core-components-input";
|
|
5
|
+
type TimeInputProps = Omit<InputProps, 'onChange'> & {
|
|
6
|
+
/**
|
|
7
|
+
* Обработчик изменения значения
|
|
8
|
+
*/
|
|
9
|
+
onChange?: (event: ChangeEvent<HTMLInputElement>, payload: {
|
|
10
|
+
hours: number;
|
|
11
|
+
mins: number;
|
|
12
|
+
value: string;
|
|
13
|
+
}) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Обработчик окончания ввода
|
|
16
|
+
*/
|
|
17
|
+
onComplete?: (event: ChangeEvent<HTMLInputElement>, payload: {
|
|
18
|
+
hours: number;
|
|
19
|
+
mins: number;
|
|
20
|
+
value: string;
|
|
21
|
+
}) => void;
|
|
22
|
+
};
|
|
23
|
+
declare const TimeInput: React.ForwardRefExoticComponent<Pick<InputProps, "className" | "dataTestId" | "form" | "label" | "slot" | "style" | "title" | "pattern" | "leftAddons" | "rightAddons" | "size" | "block" | "colors" | "children" | "type" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "list" | "step" | "autoFocus" | "disabled" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "name" | "value" | "fieldClassName" | "labelClassName" | "addonsClassName" | "error" | "hint" | "labelView" | "bottomAddons" | "accept" | "alt" | "autoComplete" | "capture" | "checked" | "crossOrigin" | "height" | "max" | "maxLength" | "min" | "minLength" | "multiple" | "readOnly" | "required" | "src" | "width" | "clear" | "success" | "inputClassName" | "focusedClassName" | "filledClassName" | "onClear" | "wrapperRef"> & {
|
|
24
|
+
/**
|
|
25
|
+
* Обработчик изменения значения
|
|
26
|
+
*/
|
|
27
|
+
onChange?: ((event: React.ChangeEvent<HTMLInputElement>, payload: {
|
|
28
|
+
hours: number;
|
|
29
|
+
mins: number;
|
|
30
|
+
value: string;
|
|
31
|
+
}) => void) | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Обработчик окончания ввода
|
|
34
|
+
*/
|
|
35
|
+
onComplete?: ((event: React.ChangeEvent<HTMLInputElement>, payload: {
|
|
36
|
+
hours: number;
|
|
37
|
+
mins: number;
|
|
38
|
+
value: string;
|
|
39
|
+
}) => void) | undefined;
|
|
40
|
+
} & React.RefAttributes<HTMLInputElement>>;
|
|
41
|
+
export { TimeInputProps, TimeInput };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var coreComponentsInput = require('@alfalab/core-components-input/cssm');
|
|
7
|
+
var utils_format = require('./utils/format.js');
|
|
8
|
+
|
|
9
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
+
|
|
11
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
12
|
+
|
|
13
|
+
/*! *****************************************************************************
|
|
14
|
+
Copyright (c) Microsoft Corporation.
|
|
15
|
+
|
|
16
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
17
|
+
purpose with or without fee is hereby granted.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
20
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
21
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
22
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
23
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
24
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
25
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
26
|
+
***************************************************************************** */
|
|
27
|
+
var __assign = function () {
|
|
28
|
+
__assign = Object.assign || function __assign(t) {
|
|
29
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
30
|
+
s = arguments[i];
|
|
31
|
+
for (var p in s)
|
|
32
|
+
if (Object.prototype.hasOwnProperty.call(s, p))
|
|
33
|
+
t[p] = s[p];
|
|
34
|
+
}
|
|
35
|
+
return t;
|
|
36
|
+
};
|
|
37
|
+
return __assign.apply(this, arguments);
|
|
38
|
+
};
|
|
39
|
+
function __rest(s, e) {
|
|
40
|
+
var t = {};
|
|
41
|
+
for (var p in s)
|
|
42
|
+
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
43
|
+
t[p] = s[p];
|
|
44
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
45
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
46
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
47
|
+
t[p[i]] = s[p[i]];
|
|
48
|
+
}
|
|
49
|
+
return t;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/* eslint-disable no-useless-escape */
|
|
53
|
+
var TimeInput = React__default['default'].forwardRef(function (_a, ref) {
|
|
54
|
+
var _b = _a.defaultValue, defaultValue = _b === void 0 ? '' : _b, propValue = _a.value, onChange = _a.onChange, onComplete = _a.onComplete, className = _a.className, restProps = __rest(_a, ["defaultValue", "value", "onChange", "onComplete", "className"]);
|
|
55
|
+
var _c = React.useState(propValue || defaultValue), value = _c[0], setValue = _c[1];
|
|
56
|
+
var handleChange = function (event) {
|
|
57
|
+
var newValue = event.target.value;
|
|
58
|
+
if (newValue.length > 5)
|
|
59
|
+
return;
|
|
60
|
+
// Позволяем вводить только цифры и двоеточия
|
|
61
|
+
if (/[^\d:]/.test(newValue)) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
var colon = newValue.match(/\:/g);
|
|
65
|
+
// Не даем вводить больше, чем одно двоеточие
|
|
66
|
+
if (colon && colon.length > 1) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
var formattedValue = utils_format.format(newValue);
|
|
70
|
+
var formattedValueArr = formattedValue.split(':');
|
|
71
|
+
var hours = Number(formattedValueArr[0]);
|
|
72
|
+
var mins = Number(formattedValueArr[1]);
|
|
73
|
+
setValue(formattedValue);
|
|
74
|
+
if (onChange)
|
|
75
|
+
onChange(event, { hours: hours, mins: mins, value: formattedValue });
|
|
76
|
+
if (utils_format.isCompleteTimeInput(formattedValue)) {
|
|
77
|
+
var valid = formattedValue.length > 0 && utils_format.isValidInputValue(formattedValue);
|
|
78
|
+
if (!valid)
|
|
79
|
+
return;
|
|
80
|
+
if (onComplete) {
|
|
81
|
+
onComplete(event, { hours: hours, mins: mins, value: formattedValue });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
var handleClearClick = function () {
|
|
86
|
+
setValue('');
|
|
87
|
+
};
|
|
88
|
+
return (React__default['default'].createElement(coreComponentsInput.Input, __assign({}, restProps, { ref: ref, value: value, className: className, onChange: handleChange, onClear: handleClearClick })));
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
exports.TimeInput = TimeInput;
|
package/cssm/index.d.ts
ADDED
package/cssm/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var Component = require('./Component.js');
|
|
6
|
+
require('react');
|
|
7
|
+
require('@alfalab/core-components-input/cssm');
|
|
8
|
+
var utils_format = require('./utils/format.js');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.TimeInput = Component.TimeInput;
|
|
13
|
+
exports.isValidInputValue = utils_format.isValidInputValue;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
declare const DATE_MASK: (string | RegExp)[];
|
|
2
|
+
declare const isCompleteTimeInput: (input: string) => boolean;
|
|
3
|
+
declare const isValidTimeFormat: (value: string) => boolean;
|
|
4
|
+
declare const isValidInputValue: (inputValue?: string | undefined) => boolean;
|
|
5
|
+
declare const format: (value: string) => string;
|
|
6
|
+
export { DATE_MASK, isCompleteTimeInput, isValidTimeFormat, isValidInputValue, format };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
/* eslint-disable no-useless-escape */
|
|
6
|
+
var DATE_MASK = [/\d/, /\d/, ':', /\d/, /\d/];
|
|
7
|
+
var isCompleteTimeInput = function (input) { return input.length === DATE_MASK.length; };
|
|
8
|
+
var isValidTimeFormat = function (value) {
|
|
9
|
+
var timeArr = value.split(':');
|
|
10
|
+
var hours = timeArr[0];
|
|
11
|
+
var mins = timeArr[1];
|
|
12
|
+
if (hours.length !== 2 || Number(hours) > 23) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
if (mins.length !== 2 || Number(mins) > 59) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
};
|
|
20
|
+
var isValidInputValue = function (inputValue) {
|
|
21
|
+
return !inputValue || (isCompleteTimeInput(inputValue) && isValidTimeFormat(inputValue));
|
|
22
|
+
};
|
|
23
|
+
var format = function (value) {
|
|
24
|
+
return value
|
|
25
|
+
.replace(/^(\d\d)(\d)$/, '$1:$2') // 123 => 12:3
|
|
26
|
+
.replace(/^(\d\d)(\d\d)/, '$1:$2') // 12345 => 12:45 (если вместо двоеточия введена цифра, она обратно заменяется на двоеточие)
|
|
27
|
+
.replace(/^(\d):(\d\d)(\d)/, '$1:$2') // 1:234 => 1:23
|
|
28
|
+
.replace(/\:$/, '');
|
|
29
|
+
}; // 12: => 12 || : => void
|
|
30
|
+
|
|
31
|
+
exports.DATE_MASK = DATE_MASK;
|
|
32
|
+
exports.format = format;
|
|
33
|
+
exports.isCompleteTimeInput = isCompleteTimeInput;
|
|
34
|
+
exports.isValidInputValue = isValidInputValue;
|
|
35
|
+
exports.isValidTimeFormat = isValidTimeFormat;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./format";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var utils_format = require('./format.js');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports.DATE_MASK = utils_format.DATE_MASK;
|
|
10
|
+
exports.format = utils_format.format;
|
|
11
|
+
exports.isCompleteTimeInput = utils_format.isCompleteTimeInput;
|
|
12
|
+
exports.isValidInputValue = utils_format.isValidInputValue;
|
|
13
|
+
exports.isValidTimeFormat = utils_format.isValidTimeFormat;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ChangeEvent } from "react";
|
|
4
|
+
import { InputProps } from "@alfalab/core-components-input";
|
|
5
|
+
type TimeInputProps = Omit<InputProps, 'onChange'> & {
|
|
6
|
+
/**
|
|
7
|
+
* Обработчик изменения значения
|
|
8
|
+
*/
|
|
9
|
+
onChange?: (event: ChangeEvent<HTMLInputElement>, payload: {
|
|
10
|
+
hours: number;
|
|
11
|
+
mins: number;
|
|
12
|
+
value: string;
|
|
13
|
+
}) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Обработчик окончания ввода
|
|
16
|
+
*/
|
|
17
|
+
onComplete?: (event: ChangeEvent<HTMLInputElement>, payload: {
|
|
18
|
+
hours: number;
|
|
19
|
+
mins: number;
|
|
20
|
+
value: string;
|
|
21
|
+
}) => void;
|
|
22
|
+
};
|
|
23
|
+
declare const TimeInput: React.ForwardRefExoticComponent<Pick<InputProps, "className" | "dataTestId" | "form" | "label" | "slot" | "style" | "title" | "pattern" | "leftAddons" | "rightAddons" | "size" | "block" | "colors" | "children" | "type" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "list" | "step" | "autoFocus" | "disabled" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "name" | "value" | "fieldClassName" | "labelClassName" | "addonsClassName" | "error" | "hint" | "labelView" | "bottomAddons" | "accept" | "alt" | "autoComplete" | "capture" | "checked" | "crossOrigin" | "height" | "max" | "maxLength" | "min" | "minLength" | "multiple" | "readOnly" | "required" | "src" | "width" | "clear" | "success" | "inputClassName" | "focusedClassName" | "filledClassName" | "onClear" | "wrapperRef"> & {
|
|
24
|
+
/**
|
|
25
|
+
* Обработчик изменения значения
|
|
26
|
+
*/
|
|
27
|
+
onChange?: ((event: React.ChangeEvent<HTMLInputElement>, payload: {
|
|
28
|
+
hours: number;
|
|
29
|
+
mins: number;
|
|
30
|
+
value: string;
|
|
31
|
+
}) => void) | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Обработчик окончания ввода
|
|
34
|
+
*/
|
|
35
|
+
onComplete?: ((event: React.ChangeEvent<HTMLInputElement>, payload: {
|
|
36
|
+
hours: number;
|
|
37
|
+
mins: number;
|
|
38
|
+
value: string;
|
|
39
|
+
}) => void) | undefined;
|
|
40
|
+
} & React.RefAttributes<HTMLInputElement>>;
|
|
41
|
+
export { TimeInputProps, TimeInput };
|
package/esm/Component.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { Input } from '@alfalab/core-components-input/esm';
|
|
3
|
+
import { format, isCompleteTimeInput, isValidInputValue } from './utils/format.js';
|
|
4
|
+
|
|
5
|
+
/*! *****************************************************************************
|
|
6
|
+
Copyright (c) Microsoft Corporation.
|
|
7
|
+
|
|
8
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
9
|
+
purpose with or without fee is hereby granted.
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
12
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
13
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
14
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
15
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
16
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
17
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
18
|
+
***************************************************************************** */
|
|
19
|
+
var __assign = function () {
|
|
20
|
+
__assign = Object.assign || function __assign(t) {
|
|
21
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
22
|
+
s = arguments[i];
|
|
23
|
+
for (var p in s)
|
|
24
|
+
if (Object.prototype.hasOwnProperty.call(s, p))
|
|
25
|
+
t[p] = s[p];
|
|
26
|
+
}
|
|
27
|
+
return t;
|
|
28
|
+
};
|
|
29
|
+
return __assign.apply(this, arguments);
|
|
30
|
+
};
|
|
31
|
+
function __rest(s, e) {
|
|
32
|
+
var t = {};
|
|
33
|
+
for (var p in s)
|
|
34
|
+
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
35
|
+
t[p] = s[p];
|
|
36
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
37
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
38
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
39
|
+
t[p[i]] = s[p[i]];
|
|
40
|
+
}
|
|
41
|
+
return t;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* eslint-disable no-useless-escape */
|
|
45
|
+
var TimeInput = React.forwardRef(function (_a, ref) {
|
|
46
|
+
var _b = _a.defaultValue, defaultValue = _b === void 0 ? '' : _b, propValue = _a.value, onChange = _a.onChange, onComplete = _a.onComplete, className = _a.className, restProps = __rest(_a, ["defaultValue", "value", "onChange", "onComplete", "className"]);
|
|
47
|
+
var _c = useState(propValue || defaultValue), value = _c[0], setValue = _c[1];
|
|
48
|
+
var handleChange = function (event) {
|
|
49
|
+
var newValue = event.target.value;
|
|
50
|
+
if (newValue.length > 5)
|
|
51
|
+
return;
|
|
52
|
+
// Позволяем вводить только цифры и двоеточия
|
|
53
|
+
if (/[^\d:]/.test(newValue)) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
var colon = newValue.match(/\:/g);
|
|
57
|
+
// Не даем вводить больше, чем одно двоеточие
|
|
58
|
+
if (colon && colon.length > 1) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
var formattedValue = format(newValue);
|
|
62
|
+
var formattedValueArr = formattedValue.split(':');
|
|
63
|
+
var hours = Number(formattedValueArr[0]);
|
|
64
|
+
var mins = Number(formattedValueArr[1]);
|
|
65
|
+
setValue(formattedValue);
|
|
66
|
+
if (onChange)
|
|
67
|
+
onChange(event, { hours: hours, mins: mins, value: formattedValue });
|
|
68
|
+
if (isCompleteTimeInput(formattedValue)) {
|
|
69
|
+
var valid = formattedValue.length > 0 && isValidInputValue(formattedValue);
|
|
70
|
+
if (!valid)
|
|
71
|
+
return;
|
|
72
|
+
if (onComplete) {
|
|
73
|
+
onComplete(event, { hours: hours, mins: mins, value: formattedValue });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
var handleClearClick = function () {
|
|
78
|
+
setValue('');
|
|
79
|
+
};
|
|
80
|
+
return (React.createElement(Input, __assign({}, restProps, { ref: ref, value: value, className: className, onChange: handleChange, onClear: handleClearClick })));
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
export { TimeInput };
|
package/esm/index.d.ts
ADDED
package/esm/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
declare const DATE_MASK: (string | RegExp)[];
|
|
2
|
+
declare const isCompleteTimeInput: (input: string) => boolean;
|
|
3
|
+
declare const isValidTimeFormat: (value: string) => boolean;
|
|
4
|
+
declare const isValidInputValue: (inputValue?: string | undefined) => boolean;
|
|
5
|
+
declare const format: (value: string) => string;
|
|
6
|
+
export { DATE_MASK, isCompleteTimeInput, isValidTimeFormat, isValidInputValue, format };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/* eslint-disable no-useless-escape */
|
|
2
|
+
var DATE_MASK = [/\d/, /\d/, ':', /\d/, /\d/];
|
|
3
|
+
var isCompleteTimeInput = function (input) { return input.length === DATE_MASK.length; };
|
|
4
|
+
var isValidTimeFormat = function (value) {
|
|
5
|
+
var timeArr = value.split(':');
|
|
6
|
+
var hours = timeArr[0];
|
|
7
|
+
var mins = timeArr[1];
|
|
8
|
+
if (hours.length !== 2 || Number(hours) > 23) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
if (mins.length !== 2 || Number(mins) > 59) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
return true;
|
|
15
|
+
};
|
|
16
|
+
var isValidInputValue = function (inputValue) {
|
|
17
|
+
return !inputValue || (isCompleteTimeInput(inputValue) && isValidTimeFormat(inputValue));
|
|
18
|
+
};
|
|
19
|
+
var format = function (value) {
|
|
20
|
+
return value
|
|
21
|
+
.replace(/^(\d\d)(\d)$/, '$1:$2') // 123 => 12:3
|
|
22
|
+
.replace(/^(\d\d)(\d\d)/, '$1:$2') // 12345 => 12:45 (если вместо двоеточия введена цифра, она обратно заменяется на двоеточие)
|
|
23
|
+
.replace(/^(\d):(\d\d)(\d)/, '$1:$2') // 1:234 => 1:23
|
|
24
|
+
.replace(/\:$/, '');
|
|
25
|
+
}; // 12: => 12 || : => void
|
|
26
|
+
|
|
27
|
+
export { DATE_MASK, format, isCompleteTimeInput, isValidInputValue, isValidTimeFormat };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./format";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DATE_MASK, format, isCompleteTimeInput, isValidInputValue, isValidTimeFormat } from './format.js';
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var Component = require('./Component.js');
|
|
6
|
+
require('react');
|
|
7
|
+
require('@alfalab/core-components-input');
|
|
8
|
+
var utils_format = require('./utils/format.js');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.TimeInput = Component.TimeInput;
|
|
13
|
+
exports.isValidInputValue = utils_format.isValidInputValue;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ChangeEvent } from "react";
|
|
4
|
+
import { InputProps } from "@alfalab/core-components-input";
|
|
5
|
+
type TimeInputProps = Omit<InputProps, 'onChange'> & {
|
|
6
|
+
/**
|
|
7
|
+
* Обработчик изменения значения
|
|
8
|
+
*/
|
|
9
|
+
onChange?: (event: ChangeEvent<HTMLInputElement>, payload: {
|
|
10
|
+
hours: number;
|
|
11
|
+
mins: number;
|
|
12
|
+
value: string;
|
|
13
|
+
}) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Обработчик окончания ввода
|
|
16
|
+
*/
|
|
17
|
+
onComplete?: (event: ChangeEvent<HTMLInputElement>, payload: {
|
|
18
|
+
hours: number;
|
|
19
|
+
mins: number;
|
|
20
|
+
value: string;
|
|
21
|
+
}) => void;
|
|
22
|
+
};
|
|
23
|
+
declare const TimeInput: React.ForwardRefExoticComponent<Pick<InputProps, "className" | "dataTestId" | "form" | "label" | "slot" | "style" | "title" | "pattern" | "leftAddons" | "rightAddons" | "size" | "block" | "colors" | "children" | "type" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "list" | "step" | "autoFocus" | "disabled" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "name" | "value" | "fieldClassName" | "labelClassName" | "addonsClassName" | "error" | "hint" | "labelView" | "bottomAddons" | "accept" | "alt" | "autoComplete" | "capture" | "checked" | "crossOrigin" | "height" | "max" | "maxLength" | "min" | "minLength" | "multiple" | "readOnly" | "required" | "src" | "width" | "clear" | "success" | "inputClassName" | "focusedClassName" | "filledClassName" | "onClear" | "wrapperRef"> & {
|
|
24
|
+
/**
|
|
25
|
+
* Обработчик изменения значения
|
|
26
|
+
*/
|
|
27
|
+
onChange?: ((event: React.ChangeEvent<HTMLInputElement>, payload: {
|
|
28
|
+
hours: number;
|
|
29
|
+
mins: number;
|
|
30
|
+
value: string;
|
|
31
|
+
}) => void) | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Обработчик окончания ввода
|
|
34
|
+
*/
|
|
35
|
+
onComplete?: ((event: React.ChangeEvent<HTMLInputElement>, payload: {
|
|
36
|
+
hours: number;
|
|
37
|
+
mins: number;
|
|
38
|
+
value: string;
|
|
39
|
+
}) => void) | undefined;
|
|
40
|
+
} & React.RefAttributes<HTMLInputElement>>;
|
|
41
|
+
export { TimeInputProps, TimeInput };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { Input } from '@alfalab/core-components-input/modern';
|
|
3
|
+
import { format, isCompleteTimeInput, isValidInputValue } from './utils/format.js';
|
|
4
|
+
|
|
5
|
+
/* eslint-disable no-useless-escape */
|
|
6
|
+
const TimeInput = React.forwardRef(({ defaultValue = '', value: propValue, onChange, onComplete, className, ...restProps }, ref) => {
|
|
7
|
+
const [value, setValue] = useState(propValue || defaultValue);
|
|
8
|
+
const handleChange = (event) => {
|
|
9
|
+
const { value: newValue } = event.target;
|
|
10
|
+
if (newValue.length > 5)
|
|
11
|
+
return;
|
|
12
|
+
// Позволяем вводить только цифры и двоеточия
|
|
13
|
+
if (/[^\d:]/.test(newValue)) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const colon = newValue.match(/\:/g);
|
|
17
|
+
// Не даем вводить больше, чем одно двоеточие
|
|
18
|
+
if (colon && colon.length > 1) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const formattedValue = format(newValue);
|
|
22
|
+
const formattedValueArr = formattedValue.split(':');
|
|
23
|
+
const hours = Number(formattedValueArr[0]);
|
|
24
|
+
const mins = Number(formattedValueArr[1]);
|
|
25
|
+
setValue(formattedValue);
|
|
26
|
+
if (onChange)
|
|
27
|
+
onChange(event, { hours, mins, value: formattedValue });
|
|
28
|
+
if (isCompleteTimeInput(formattedValue)) {
|
|
29
|
+
const valid = formattedValue.length > 0 && isValidInputValue(formattedValue);
|
|
30
|
+
if (!valid)
|
|
31
|
+
return;
|
|
32
|
+
if (onComplete) {
|
|
33
|
+
onComplete(event, { hours, mins, value: formattedValue });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const handleClearClick = () => {
|
|
38
|
+
setValue('');
|
|
39
|
+
};
|
|
40
|
+
return (React.createElement(Input, Object.assign({}, restProps, { ref: ref, value: value, className: className, onChange: handleChange, onClear: handleClearClick })));
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export { TimeInput };
|
package/modern/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
declare const DATE_MASK: (string | RegExp)[];
|
|
2
|
+
declare const isCompleteTimeInput: (input: string) => boolean;
|
|
3
|
+
declare const isValidTimeFormat: (value: string) => boolean;
|
|
4
|
+
declare const isValidInputValue: (inputValue?: string | undefined) => boolean;
|
|
5
|
+
declare const format: (value: string) => string;
|
|
6
|
+
export { DATE_MASK, isCompleteTimeInput, isValidTimeFormat, isValidInputValue, format };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/* eslint-disable no-useless-escape */
|
|
2
|
+
const DATE_MASK = [/\d/, /\d/, ':', /\d/, /\d/];
|
|
3
|
+
const isCompleteTimeInput = (input) => input.length === DATE_MASK.length;
|
|
4
|
+
const isValidTimeFormat = (value) => {
|
|
5
|
+
const timeArr = value.split(':');
|
|
6
|
+
const hours = timeArr[0];
|
|
7
|
+
const mins = timeArr[1];
|
|
8
|
+
if (hours.length !== 2 || Number(hours) > 23) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
if (mins.length !== 2 || Number(mins) > 59) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
return true;
|
|
15
|
+
};
|
|
16
|
+
const isValidInputValue = (inputValue) => !inputValue || (isCompleteTimeInput(inputValue) && isValidTimeFormat(inputValue));
|
|
17
|
+
const format = (value) => value
|
|
18
|
+
.replace(/^(\d\d)(\d)$/, '$1:$2') // 123 => 12:3
|
|
19
|
+
.replace(/^(\d\d)(\d\d)/, '$1:$2') // 12345 => 12:45 (если вместо двоеточия введена цифра, она обратно заменяется на двоеточие)
|
|
20
|
+
.replace(/^(\d):(\d\d)(\d)/, '$1:$2') // 1:234 => 1:23
|
|
21
|
+
.replace(/\:$/, ''); // 12: => 12 || : => void
|
|
22
|
+
|
|
23
|
+
export { DATE_MASK, format, isCompleteTimeInput, isValidInputValue, isValidTimeFormat };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./format";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DATE_MASK, format, isCompleteTimeInput, isValidInputValue, isValidTimeFormat } from './format.js';
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@alfalab/core-components-time-input",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"keywords": [],
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "index.js",
|
|
8
|
+
"module": "./esm/index.js",
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public",
|
|
11
|
+
"directory": "dist"
|
|
12
|
+
},
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"react": "^16.9.0 || ^17.0.1 || ^18.0.0",
|
|
15
|
+
"react-dom": "^16.9.0 || ^17.0.1 || ^18.0.0"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@alfalab/core-components-input": "^10.1.0",
|
|
19
|
+
"@alfalab/core-components-icon-button": "^5.0.3"
|
|
20
|
+
}
|
|
21
|
+
}
|
package/send-stats.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
const http = require('http');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const { promisify } = require('util');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
const readFile = promisify(fs.readFile);
|
|
7
|
+
|
|
8
|
+
async function main() {
|
|
9
|
+
const remoteHost = process.env.NIS_HOST || 'digital';
|
|
10
|
+
const remotePort = process.env.NIS_PORT || 80;
|
|
11
|
+
const remotePath = process.env.NIS_PATH || '/npm-install-stats/api/install-stats';
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
const [_, node, os, arch] =
|
|
15
|
+
/node\/v(\d+\.\d+\.\d+) (\w+) (\w+)/.exec(process.env.npm_config_user_agent) || [];
|
|
16
|
+
const [__, npm] = /npm\/(\d+\.\d+\.\d+)/.exec(process.env.npm_config_user_agent) || [];
|
|
17
|
+
const [___, yarn] = /yarn\/(\d+\.\d+\.\d+)/.exec(process.env.npm_config_user_agent) || [];
|
|
18
|
+
|
|
19
|
+
let ownPackageJson, packageJson;
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
const result = await Promise.all([
|
|
23
|
+
readFile(path.join(process.cwd(), 'package.json'), 'utf-8'),
|
|
24
|
+
readFile(path.join(process.cwd(), '../../../package.json'), 'utf-8'),
|
|
25
|
+
]);
|
|
26
|
+
|
|
27
|
+
ownPackageJson = JSON.parse(result[0]);
|
|
28
|
+
packageJson = JSON.parse(result[1]);
|
|
29
|
+
} catch (err) {
|
|
30
|
+
ownPackageJson = '';
|
|
31
|
+
packageJson = '';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const data = {
|
|
35
|
+
node,
|
|
36
|
+
npm,
|
|
37
|
+
yarn,
|
|
38
|
+
os,
|
|
39
|
+
arch,
|
|
40
|
+
ownPackageJson: JSON.stringify(ownPackageJson),
|
|
41
|
+
packageJson: JSON.stringify(packageJson),
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const body = JSON.stringify(data);
|
|
45
|
+
|
|
46
|
+
const options = {
|
|
47
|
+
host: remoteHost,
|
|
48
|
+
port: remotePort,
|
|
49
|
+
path: remotePath,
|
|
50
|
+
method: 'POST',
|
|
51
|
+
headers: {
|
|
52
|
+
'Content-Type': 'application/json',
|
|
53
|
+
'Content-Length': body.length,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
return new Promise((resolve, reject) => {
|
|
58
|
+
const req = http.request(options, res => {
|
|
59
|
+
res.on('end', () => {
|
|
60
|
+
resolve();
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
req.on('error', () => {
|
|
65
|
+
reject();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
req.write(body);
|
|
69
|
+
req.end();
|
|
70
|
+
});
|
|
71
|
+
} catch (error) {
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
main()
|
|
77
|
+
.then(() => {
|
|
78
|
+
process.exit(0);
|
|
79
|
+
})
|
|
80
|
+
.catch(() => {
|
|
81
|
+
process.exit(0);
|
|
82
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
declare const DATE_MASK: (string | RegExp)[];
|
|
2
|
+
declare const isCompleteTimeInput: (input: string) => boolean;
|
|
3
|
+
declare const isValidTimeFormat: (value: string) => boolean;
|
|
4
|
+
declare const isValidInputValue: (inputValue?: string | undefined) => boolean;
|
|
5
|
+
declare const format: (value: string) => string;
|
|
6
|
+
export { DATE_MASK, isCompleteTimeInput, isValidTimeFormat, isValidInputValue, format };
|
package/utils/format.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
/* eslint-disable no-useless-escape */
|
|
6
|
+
var DATE_MASK = [/\d/, /\d/, ':', /\d/, /\d/];
|
|
7
|
+
var isCompleteTimeInput = function (input) { return input.length === DATE_MASK.length; };
|
|
8
|
+
var isValidTimeFormat = function (value) {
|
|
9
|
+
var timeArr = value.split(':');
|
|
10
|
+
var hours = timeArr[0];
|
|
11
|
+
var mins = timeArr[1];
|
|
12
|
+
if (hours.length !== 2 || Number(hours) > 23) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
if (mins.length !== 2 || Number(mins) > 59) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
};
|
|
20
|
+
var isValidInputValue = function (inputValue) {
|
|
21
|
+
return !inputValue || (isCompleteTimeInput(inputValue) && isValidTimeFormat(inputValue));
|
|
22
|
+
};
|
|
23
|
+
var format = function (value) {
|
|
24
|
+
return value
|
|
25
|
+
.replace(/^(\d\d)(\d)$/, '$1:$2') // 123 => 12:3
|
|
26
|
+
.replace(/^(\d\d)(\d\d)/, '$1:$2') // 12345 => 12:45 (если вместо двоеточия введена цифра, она обратно заменяется на двоеточие)
|
|
27
|
+
.replace(/^(\d):(\d\d)(\d)/, '$1:$2') // 1:234 => 1:23
|
|
28
|
+
.replace(/\:$/, '');
|
|
29
|
+
}; // 12: => 12 || : => void
|
|
30
|
+
|
|
31
|
+
exports.DATE_MASK = DATE_MASK;
|
|
32
|
+
exports.format = format;
|
|
33
|
+
exports.isCompleteTimeInput = isCompleteTimeInput;
|
|
34
|
+
exports.isValidInputValue = isValidInputValue;
|
|
35
|
+
exports.isValidTimeFormat = isValidTimeFormat;
|
package/utils/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./format";
|
package/utils/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var utils_format = require('./format.js');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports.DATE_MASK = utils_format.DATE_MASK;
|
|
10
|
+
exports.format = utils_format.format;
|
|
11
|
+
exports.isCompleteTimeInput = utils_format.isCompleteTimeInput;
|
|
12
|
+
exports.isValidInputValue = utils_format.isValidInputValue;
|
|
13
|
+
exports.isValidTimeFormat = utils_format.isValidTimeFormat;
|