UNPKG

@appbuckets/react-ui-forms

Version:

An utilities package to manage and create Form using AppBuckets ReactUI

57 lines (54 loc) 1.53 kB
import { __assign, __read } from '../_virtual/_tslib.js'; import * as React from 'react'; import Input from '@appbuckets/react-ui/Input'; import { createHookedField } from '../utils/createHookedField.js'; /* -------- * Component Definition * -------- */ var HookedTimeInput = createHookedField({ displayName: 'HookedTimeInput', Component: function HookedTimeInputComponent(props) { var meta = props.meta, rest = props.rest; return React.createElement( Input, __assign({}, rest, meta.appearance, { hint: meta.message, type: 'time' }) ); }, parseValue: function (_a) { var props = _a.props; if ( typeof (props === null || props === void 0 ? void 0 : props.value) !== 'string' || !props.value.length ) { return null; } var _b = __read( props.value.split(':').map(function (value) { return Number(value); }), 2 ), hours = _b[0], minutes = _b[1]; return ( (Number.isNaN(hours) ? 0 : hours) * 3600000 + (Number.isNaN(minutes) ? 0 : minutes) * 60000 ); }, formatValue: function (value) { if (typeof value !== 'number') { return ''; } if (value === 0) { return '00:00'; } var minutes = (value % 3600000) / 60000; var hours = Math.trunc((value - minutes) / 3600000); return '' .concat(hours.toString().padStart(2, '0'), ':') .concat(minutes.toString().padStart(2, '0')); }, }); export { HookedTimeInput as default };