@activecollab/components
Version:
ActiveCollab Components
66 lines • 2.78 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["value", "onCancel", "onSave", "onEnterKeyPress", "allowEmptyValue", "withLeadingZero", "validation", "incrementOnlySelected", "minuteIncrement", "className", "onChange", "onClick", "align"];
import React, { useRef } from "react";
import { Input } from "./Input";
import { useInputHours } from "../../hooks/useInputHours";
import { validateTimeInput } from "../../utils";
import useForkRef from "../../utils/useForkRef";
export const InputHours = /*#__PURE__*/React.forwardRef((_ref, ref) => {
let defaultValue = _ref.value,
onCancel = _ref.onCancel,
onSave = _ref.onSave,
externalEnterKeyPress = _ref.onEnterKeyPress,
allowEmptyValue = _ref.allowEmptyValue,
_ref$withLeadingZero = _ref.withLeadingZero,
withLeadingZero = _ref$withLeadingZero === void 0 ? true : _ref$withLeadingZero,
_ref$validation = _ref.validation,
validation = _ref$validation === void 0 ? validateTimeInput : _ref$validation,
_ref$incrementOnlySel = _ref.incrementOnlySelected,
incrementOnlySelected = _ref$incrementOnlySel === void 0 ? false : _ref$incrementOnlySel,
_ref$minuteIncrement = _ref.minuteIncrement,
minuteIncrement = _ref$minuteIncrement === void 0 ? 1 : _ref$minuteIncrement,
className = _ref.className,
externalOnChange = _ref.onChange,
externalOnClick = _ref.onClick,
_ref$align = _ref.align,
align = _ref$align === void 0 ? "center" : _ref$align,
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
const inputRef = useRef(null);
const handleRef = useForkRef(ref, inputRef);
const _useInputHours = useInputHours({
value: defaultValue,
withLeadingZero,
onSave,
validation,
allowEmptyValue,
onCancel,
minuteIncrement,
incrementOnlySelected,
onEnterKeyPress: externalEnterKeyPress,
onChange: externalOnChange,
onClick: externalOnClick
}, inputRef),
inputProps = _useInputHours.inputProps;
const value = inputProps.value,
onBlur = inputProps.onBlur,
onKeyDown = inputProps.onKeyDown,
onChange = inputProps.onChange,
onClick = inputProps.onClick,
onDoubleClick = inputProps.onDoubleClick;
return /*#__PURE__*/React.createElement(Input, _extends({}, rest, {
align: align,
className: className,
placeholder: withLeadingZero ? "00:00" : "0:00",
value: value,
onBlur: onBlur,
onKeyDown: onKeyDown,
onChange: onChange,
onClick: onClick,
onDoubleClick: onDoubleClick,
ref: handleRef,
autoComplete: "off"
}));
});
InputHours.displayName = "InputHours";
//# sourceMappingURL=InputHours.js.map