@evoke-platform/ui-components 1.0.0-dev.145 → 1.0.0-dev.146
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/dist/published/components/custom/FormField/FormField.js +4 -0
- package/dist/published/components/custom/FormField/TimePickerSelect/TimePickerSelect.d.ts +4 -0
- package/dist/published/components/custom/FormField/TimePickerSelect/TimePickerSelect.js +44 -0
- package/dist/published/components/custom/FormField/TimePickerSelect/index.d.ts +1 -0
- package/dist/published/components/custom/FormField/TimePickerSelect/index.js +1 -0
- package/dist/published/stories/TimePickerSelect.stories.d.ts +5 -0
- package/dist/published/stories/TimePickerSelect.stories.js +31 -0
- package/package.json +1 -1
@@ -5,6 +5,7 @@ import FileUploadControl from './FileUpload/FileUpload';
|
|
5
5
|
import InputFieldComponent from './InputFieldComponent/InputFieldComponent';
|
6
6
|
import Select from './Select/Select';
|
7
7
|
import AddressFieldComponent from './AddressFieldComponent/addressFieldComponent';
|
8
|
+
import TimePickerSelect from './TimePickerSelect/TimePickerSelect';
|
8
9
|
const FormField = (props) => {
|
9
10
|
const { defaultValue, error, onChange, property, readOnly, selectOptions, required, size, placeholder, errorMessage, onBlur, mask, max, min, isMultiLineText, rows, inputMaskPlaceholderChar, queryAddresses } = props;
|
10
11
|
const id = property.id;
|
@@ -36,6 +37,9 @@ const FormField = (props) => {
|
|
36
37
|
case 'date':
|
37
38
|
control = React.createElement(DatePickerSelect, Object.assign({}, commonProps));
|
38
39
|
break;
|
40
|
+
case 'time':
|
41
|
+
control = React.createElement(TimePickerSelect, Object.assign({}, commonProps));
|
42
|
+
break;
|
39
43
|
case 'fileUpload':
|
40
44
|
control = React.createElement(FileUploadControl, Object.assign({}, commonProps));
|
41
45
|
break;
|
@@ -0,0 +1,44 @@
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
2
|
+
import { LocalizationProvider, TextField } from '../../../core';
|
3
|
+
import { TimePicker } from '@mui/x-date-pickers';
|
4
|
+
import { LocalDateTime } from '@js-joda/core';
|
5
|
+
import { padStart } from 'lodash-es';
|
6
|
+
import { InvalidDate } from '../../../../util';
|
7
|
+
const TimePickerSelect = (props) => {
|
8
|
+
const { property, defaultValue, error, errorMessage, readOnly, required, size, onBlur, placeholder } = props;
|
9
|
+
const values = defaultValue ? defaultValue.split(':') : undefined;
|
10
|
+
const hour = values ? parseInt(values[0]) : undefined;
|
11
|
+
const minute = values ? parseInt(values[1]) : undefined;
|
12
|
+
const second = values ? parseInt(values[2]) : undefined;
|
13
|
+
const [value, setValue] = useState(defaultValue ? LocalDateTime.now().withHour(hour).withMinute(minute).withSecond(second) : null);
|
14
|
+
const id = property.id;
|
15
|
+
useEffect(() => {
|
16
|
+
if (defaultValue) {
|
17
|
+
const values = defaultValue.split(':');
|
18
|
+
const hour = parseInt(values[0]);
|
19
|
+
const minute = parseInt(values[1]);
|
20
|
+
const second = parseInt(values[2]);
|
21
|
+
const today = LocalDateTime.now();
|
22
|
+
setValue(today.withHour(hour).withMinute(minute).withSecond(second));
|
23
|
+
}
|
24
|
+
}, [defaultValue]);
|
25
|
+
const handleChange = (date) => {
|
26
|
+
if (date instanceof InvalidDate && date.invalid) {
|
27
|
+
return;
|
28
|
+
}
|
29
|
+
else if (date instanceof LocalDateTime) {
|
30
|
+
setValue(date);
|
31
|
+
const hour = padStart(date === null || date === void 0 ? void 0 : date.hour().toString(), 2, '0');
|
32
|
+
const minute = padStart(date === null || date === void 0 ? void 0 : date.minute().toString(), 2, '0');
|
33
|
+
const second = padStart(date === null || date === void 0 ? void 0 : date.second().toString(), 2, '0');
|
34
|
+
props.onChange(id, `${hour}:${minute}:${second}`, property);
|
35
|
+
}
|
36
|
+
else {
|
37
|
+
setValue(null);
|
38
|
+
props.onChange(id, date, property);
|
39
|
+
}
|
40
|
+
};
|
41
|
+
return (React.createElement(LocalizationProvider, null,
|
42
|
+
React.createElement(TimePicker, { value: value, onChange: handleChange, renderInput: (params) => (React.createElement(TextField, Object.assign({}, params, { id: id, error: error, errorMessage: errorMessage, onBlur: onBlur, fullWidth: true, required: required, sx: { background: 'white', borderRadius: '8px' }, size: size !== null && size !== void 0 ? size : 'medium', placeholder: placeholder, readOnly: readOnly }))), readOnly: readOnly })));
|
43
|
+
};
|
44
|
+
export default TimePickerSelect;
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './TimePickerSelect';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './TimePickerSelect';
|
@@ -0,0 +1,5 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
import { ComponentStory, ComponentMeta } from '@storybook/react';
|
3
|
+
declare const _default: ComponentMeta<(props: import("../components/custom/FormField/FormField").FormFieldProps) => JSX.Element>;
|
4
|
+
export default _default;
|
5
|
+
export declare const TimePicker: ComponentStory<(props: import("../components/custom/FormField/FormField").FormFieldProps) => JSX.Element>;
|
@@ -0,0 +1,31 @@
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
2
|
+
var t = {};
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
4
|
+
t[p] = s[p];
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
8
|
+
t[p[i]] = s[p[i]];
|
9
|
+
}
|
10
|
+
return t;
|
11
|
+
};
|
12
|
+
import React, { useState } from 'react';
|
13
|
+
import TimePickerSelect from '../components/custom/FormField/TimePickerSelect/TimePickerSelect';
|
14
|
+
export default {
|
15
|
+
title: 'Input/TimePickerSelect',
|
16
|
+
component: TimePickerSelect,
|
17
|
+
argTypes: {
|
18
|
+
defaultValue: {
|
19
|
+
type: 'string',
|
20
|
+
},
|
21
|
+
},
|
22
|
+
};
|
23
|
+
const TimePickerSelectTemplate = (args) => {
|
24
|
+
const { defaultValue } = args, rest = __rest(args, ["defaultValue"]);
|
25
|
+
const [value, setValue] = useState(defaultValue !== null && defaultValue !== void 0 ? defaultValue : null);
|
26
|
+
const handleChange = (id, newValue, property) => {
|
27
|
+
setValue(newValue);
|
28
|
+
};
|
29
|
+
return (React.createElement(TimePickerSelect, Object.assign({}, rest, { value: value, onChange: handleChange, property: { id: '1' } })));
|
30
|
+
};
|
31
|
+
export const TimePicker = TimePickerSelectTemplate.bind({});
|