diginet-core-ui 1.4.20-beta.1 → 1.4.21

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.
@@ -1,784 +0,0 @@
1
- /** @jsxRuntime classic */
2
- /** @jsx jsx */
3
- import { css, jsx } from '@emotion/core';
4
- import { Button, ButtonIcon, Divider, HelperText, InputBase, Label, NumberInput, Popover, Typography } from "../../..";
5
- import { getGlobal } from "../../../../global";
6
- import PropTypes from 'prop-types';
7
- import React, { forwardRef, memo, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
8
- import { bgColor, border, borderColor, borderNone, borderRadius4px, displayFlex, flexCol, itemsCenter, justifyBetween, justifyCenter, parseHeight, parseMinHeight, parseWidth, positionRelative, textCenter, textColor } from "../../../../styles/general";
9
- import { useTheme } from "../../../../theme";
10
- import { classNames, date, getProp, hexToRGBA } from "../../../../utils";
11
- const TimePicker = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
12
- action = {},
13
- actionIconAt,
14
- className,
15
- disabled,
16
- displayFormat,
17
- error,
18
- errorProps,
19
- id,
20
- inputProps,
21
- inputStyle,
22
- placeholder: placeholderProp,
23
- onChange,
24
- mode12h,
25
- min,
26
- max,
27
- minuteStep,
28
- label,
29
- labelProps,
30
- style,
31
- value,
32
- viewType,
33
- returnFormat,
34
- readOnly,
35
- required,
36
- ...other
37
- }, reference) => {
38
- const placeholder = placeholderProp !== null && placeholderProp !== void 0 ? placeholderProp : displayFormat;
39
-
40
- // ref
41
- const ref = useRef(null);
42
- const timePickerRef = useRef(null);
43
-
44
- // states
45
- const [currentInputFocus, setCurrentInputFocus] = useState(null);
46
- const [displayTime, setDisplayTime] = useState(value);
47
- const [minValue, setMinValue] = useState(min);
48
- const [maxValue, setMaxValue] = useState(max);
49
- const [timeValue, setTimeValue] = useState({
50
- hour: mode12h ? 1 : 0,
51
- minute: 0,
52
- second: 0,
53
- text: 'AM'
54
- });
55
- const theme = useTheme();
56
-
57
- // css
58
- const _TimePickerBodyCSS = TimePickerBodyCSS(currentInputFocus, theme);
59
- const _TimePickerAMPMCSS = TimePickerAMPMCSS(timeValue === null || timeValue === void 0 ? void 0 : timeValue.text, theme);
60
- const _TimePickerCSS = TimePickerCSS(theme);
61
- const _TimePickerFooterCSS = TimePickerFooterCSS(theme);
62
-
63
- // variables
64
- const isError = !!error && !value;
65
- const currentHour = Number(timeValue === null || timeValue === void 0 ? void 0 : timeValue.hour);
66
- const currentMinute = Number(timeValue === null || timeValue === void 0 ? void 0 : timeValue.minute);
67
- const currentSecond = Number(timeValue === null || timeValue === void 0 ? void 0 : timeValue.second);
68
- const currentTime = new Date(new Date().getFullYear(), 0, 1, currentHour, currentMinute, currentSecond);
69
- const maxHour = maxValue.slice(0, 2) ? Number(maxValue.slice(0, 2)) : mode12h ? 12 : 23;
70
- const maxMinute = maxValue.slice(3, 5) ? Number(maxValue.slice(3, 5)) : 59;
71
- const maxSecond = maxValue.slice(6, 8) ? Number(maxValue.slice(6, 8)) : 59;
72
- const minHour = minValue.slice(0, 2) ? Number(minValue.slice(0, 2)) : mode12h ? 1 : 0;
73
- const minMinute = minValue.slice(3, 5) ? Number(minValue.slice(3, 5)) : 0;
74
- const minSecond = minValue.slice(6, 8) ? Number(minValue.slice(6, 8)) : 0;
75
- const startHour = minHour ? minHour : mode12h ? 1 : 0;
76
- const startMinute = currentHour === minHour ? minMinute : 0;
77
- const startSecond = currentHour === minHour && currentMinute === minMinute ? minSecond : 0;
78
- const lastHour = maxHour ? maxHour : mode12h ? 12 : 23;
79
- const lastMinute = currentHour === maxHour ? maxMinute : 59;
80
- const lastSecond = currentHour === maxHour && currentMinute === maxMinute ? maxSecond : 59;
81
- const saveText = getGlobal(['save']);
82
- const nowText = getGlobal(['now']);
83
-
84
- /**
85
- * onChange handler with condition base on min max
86
- * @param {*} e
87
- * @param {String} key one of ['hour', 'minute', 'second']
88
- */
89
- const onChangeHandler = (e, key) => {
90
- var _e$target;
91
- if (!e) return;
92
- value = +(e === null || e === void 0 ? void 0 : (_e$target = e.target) === null || _e$target === void 0 ? void 0 : _e$target.value) || 0;
93
- if (key === 'hour') {
94
- if (maxHour === value && maxMinute <= currentMinute) {
95
- if (maxSecond <= currentSecond) {
96
- setTimeValue({
97
- ...timeValue,
98
- hour: maxHour,
99
- minute: maxMinute,
100
- second: maxSecond
101
- });
102
- return;
103
- }
104
- setTimeValue({
105
- ...timeValue,
106
- hour: maxHour,
107
- minute: maxMinute
108
- });
109
- } else if (minHour >= value && minMinute >= currentMinute && minSecond >= currentSecond) {
110
- setTimeValue({
111
- ...timeValue,
112
- hour: minHour,
113
- minute: minMinute,
114
- second: minSecond
115
- });
116
- } else {
117
- setTimeValue({
118
- ...timeValue,
119
- [key]: value
120
- });
121
- }
122
- } else if (key === 'minute') {
123
- if (currentHour === maxHour && maxMinute <= value && currentSecond >= maxSecond) {
124
- setTimeValue({
125
- ...timeValue,
126
- minute: maxMinute,
127
- second: maxSecond
128
- });
129
- } else {
130
- setTimeValue({
131
- ...timeValue,
132
- [key]: value
133
- });
134
- }
135
- } else {
136
- setTimeValue({
137
- ...timeValue,
138
- [key]: value
139
- });
140
- }
141
- };
142
-
143
- /**
144
- *
145
- * @param {String} key
146
- * @param {Number} value
147
- */
148
- const setTimeAfterChange = (key, value) => {
149
- setTimeValue({
150
- ...timeValue,
151
- [key]: value
152
- });
153
- };
154
-
155
- /**
156
- *
157
- * Arrow up hour input onClick in the following cases:
158
- * (1): Increase current hour by 1
159
- * (2): If current hour is equal to max hour value, set current hour equal to min hour
160
- * (3): If current hour plus 1 is equal to max hour, set current minute equal to max minute if current minute greater than max minute value
161
- * (4): If current hour plus 1 is equal to max hour, set current second equal to max second if current second greater than max second value
162
- * (5): Set current minute, second to min minute, second if current hour is greater than max hour value and current minute, second is greater than min minute, second value
163
- */
164
- const onIncreaseHour = () => {
165
- if (maxHour === currentHour + 1 && maxMinute < currentMinute) {
166
- // (3)
167
- if (maxSecond < currentSecond) {
168
- // (4)
169
- setTimeValue({
170
- ...timeValue,
171
- hour: maxHour,
172
- minute: maxMinute,
173
- second: maxSecond
174
- });
175
- } else {
176
- setTimeValue({
177
- ...timeValue,
178
- hour: maxHour,
179
- minute: maxMinute
180
- });
181
- }
182
- } else if (maxHour <= currentHour) {
183
- // (2)
184
- if (minMinute <= currentMinute) {
185
- // (5)
186
- setTimeValue({
187
- ...timeValue,
188
- hour: minHour
189
- });
190
- } else {
191
- setTimeValue({
192
- ...timeValue,
193
- hour: minHour,
194
- minute: minMinute,
195
- second: minSecond
196
- });
197
- }
198
- } else {
199
- setTimeAfterChange('hour', currentHour + 1); // (1)
200
- }
201
- };
202
-
203
- /**
204
- *
205
- * @constant {Number} minuteStep
206
- * @constant {Number} lastMinute
207
- * Arrow up minute input onClick in the following cases:
208
- * (1): Increase current minute by minute step (default 1).
209
- * (2): If current minute plus minute step is greater than lastMinute, set current minute equal to min minute.
210
- * (3): If current second greater than max second value, set current second equal to max second.
211
- * (4): (3) and current second is greater than max second value, set current second equal to max second.
212
- */
213
- const onIncreaseMinute = () => {
214
- if (lastMinute < currentMinute + minuteStep) {
215
- // (2)
216
- setTimeAfterChange('minute', startMinute);
217
- } else if (lastMinute === currentMinute + minuteStep) {
218
- if (currentSecond > maxSecond) {
219
- // (4)
220
- setTimeValue({
221
- ...timeValue,
222
- minute: currentMinute + minuteStep,
223
- second: maxSecond
224
- });
225
- } else {
226
- // (3)
227
- setTimeValue({
228
- ...timeValue,
229
- minute: currentMinute + minuteStep
230
- });
231
- }
232
- } else {
233
- // (1)
234
- setTimeAfterChange('minute', currentMinute + minuteStep);
235
- }
236
- };
237
-
238
- /**
239
- *
240
- * Arrow up second input onClick in the following cases:
241
- * (1): Increase current second by 1
242
- * (2): If current second plus 1 equal to max second value, set current second to min second
243
- */
244
- const onIncreaseSecond = () => {
245
- if (lastSecond < currentSecond + 1) {
246
- // (2)
247
- setTimeAfterChange('second', startSecond);
248
- } else {
249
- // (1)
250
- setTimeAfterChange('second', currentSecond + 1);
251
- }
252
- };
253
-
254
- /**
255
- *
256
- * Arrow down hour input onClick in the following cases:
257
- * (1): Decrease current hour by 1
258
- * (2): If current hour is equal to min hour value, set current hour equal to max hour
259
- * (3): (2) and current minute is greater than max minute value, set minute to max minute value
260
- * (4): (3) and current second is greater than min second value, set second to max second value
261
- * (5): If current hour minus 1 is equal to min hour and current minute greater than min minute value, set current minute equal to min minute
262
- * (6): (5) and current second is greater than min second value, set current second equal to min second
263
- */
264
- const onDecreaseHour = () => {
265
- if (minHour === currentHour - 1 && minMinute > currentMinute) {
266
- if (minSecond > currentSecond) {
267
- // (6)
268
- setTimeValue({
269
- ...timeValue,
270
- hour: minHour,
271
- minute: minMinute,
272
- second: minSecond
273
- });
274
- } else {
275
- // (5)
276
- setTimeValue({
277
- ...timeValue,
278
- hour: minHour,
279
- minute: minMinute
280
- });
281
- }
282
- } else if (minHour >= currentHour) {
283
- if (maxMinute < currentMinute) {
284
- if (maxSecond < currentSecond) {
285
- // (4)
286
- setTimeValue({
287
- ...timeValue,
288
- hour: maxHour,
289
- minute: maxMinute,
290
- second: maxSecond
291
- });
292
- } else {
293
- // (3)
294
- setTimeValue({
295
- ...timeValue,
296
- hour: maxHour,
297
- minute: maxMinute
298
- });
299
- }
300
- } else {
301
- // (2)
302
- setTimeValue({
303
- ...timeValue,
304
- hour: maxHour
305
- });
306
- }
307
- } else {
308
- // (1)
309
- setTimeAfterChange('hour', currentHour - 1);
310
- }
311
- };
312
-
313
- /**
314
- *
315
- * @constant {Number} minuteStep
316
- * @constant {Number} startMinute
317
- * @constant {Number} lastMinute
318
- * Arrow down minute input onClick in the following cases:
319
- * (1): Decrease current minute by @minuteStep
320
- * (2): If current minute minus @minuteStep is smaller than @startMinute , set current minute to @lastMinute - @lastMinute % @minuteStep
321
- * (3): (2) and current second is greater than max second, set current second to max second
322
- */
323
- const onDecreaseMinute = () => {
324
- if (startMinute > currentMinute - minuteStep) {
325
- if (currentHour === maxHour && currentSecond > maxSecond) {
326
- // (3)
327
- setTimeValue({
328
- ...timeValue,
329
- minute: lastMinute - lastMinute % minuteStep,
330
- second: maxSecond
331
- });
332
- } else {
333
- // (2)
334
- setTimeAfterChange('minute', lastMinute - lastMinute % minuteStep);
335
- }
336
- } else {
337
- // (1)
338
- setTimeAfterChange('minute', currentMinute - minuteStep);
339
- }
340
- };
341
-
342
- /**
343
- *
344
- * @constant {Number} startSecond
345
- * @constant {Number} lastSecond
346
- * Arrow down second input onClick in the following cases:
347
- * (1): Decrease current second by 1
348
- * (2): If current second minus 1 is smaller than start second, set current second to last second
349
- */
350
- const onDecreaseSecond = () => {
351
- if (startSecond >= currentSecond - 1) {
352
- // (2)
353
- setTimeAfterChange('second', lastSecond);
354
- } else {
355
- // (1)
356
- setTimeAfterChange('second', currentSecond - 1);
357
- }
358
- };
359
-
360
- /**
361
- *
362
- * onClose Popover Timepicker when click Save button
363
- */
364
- const onCloseTimePicker = () => {
365
- timePickerRef.current.close();
366
- setCurrentInputFocus(null);
367
- };
368
-
369
- /**
370
- *
371
- * Format value using date().format() in utils
372
- * @param {Date} value
373
- * @param {String} outputFormat
374
- * @returns
375
- */
376
- const formatTime = (value, outputFormat) => {
377
- return mode12h ? date(value).format(`hh${outputFormat.slice(2)} A`) : date(value).format(outputFormat);
378
- };
379
-
380
- /**
381
- *
382
- * Button Save onClick
383
- * @param {Boolean} now
384
- */
385
- const onSelectTime = (now = false) => {
386
- let displayTimeValue = '00:00:00';
387
- let returnTimeValue = '00:00:00';
388
- if (now) {
389
- displayTimeValue = formatTime(null, displayFormat);
390
- returnTimeValue = formatTime(null, returnFormat);
391
- setTimeValue({
392
- hour: displayTimeValue.slice(0, 2).includes(':') ? displayTimeValue.slice(0, 1) : displayTimeValue.slice(0, 2),
393
- minute: displayTimeValue.slice(0, 2).includes(':') ? displayTimeValue.slice(2, 4) : displayTimeValue.slice(3, 5),
394
- second: displayTimeValue.slice(0, 2).includes(':') ? displayTimeValue.slice(5, 7) : displayTimeValue.slice(6, 8),
395
- text: displayTimeValue.slice(0, 2).includes(':') ? displayTimeValue.slice(9, 11) : displayTimeValue.slice(10, 12)
396
- });
397
- } else {
398
- displayTimeValue = `${date(currentTime).format(displayFormat)} ${mode12h ? timeValue === null || timeValue === void 0 ? void 0 : timeValue.text : ''}`;
399
- returnTimeValue = `${date(currentTime).format(returnFormat)} ${mode12h ? timeValue === null || timeValue === void 0 ? void 0 : timeValue.text : ''}`;
400
- }
401
- if (!now) {
402
- setDisplayTime(displayTimeValue);
403
- const e = {
404
- value: returnTimeValue
405
- };
406
- !!onChange && onChange(e);
407
- onCloseTimePicker();
408
- }
409
- };
410
-
411
- // useEffect for prop value
412
- useEffect(() => {
413
- if (!value) {
414
- setTimeValue({
415
- hour: min ? min.slice(0, 2) : mode12h ? 1 : 0,
416
- minute: min ? min.slice(3, 5) : 0,
417
- second: min ? min.slice(6, 8) : 0,
418
- text: min ? min.slice(10, 12) || 'AM' : 'AM'
419
- });
420
- setDisplayTime(null);
421
- } else {
422
- let displayTimeValue = '00:00:00';
423
- const valueHour = Number(value.slice(0, 2)) || '00';
424
- const valueMinute = Number(value.slice(3, 5)) || '00';
425
- const valueSecond = Number(value.slice(6, 8)) || '00';
426
- const valueTime = new Date(new Date().getFullYear(), 0, 1, valueHour, valueMinute, valueSecond);
427
- displayTimeValue = formatTime(valueTime, displayFormat);
428
- setTimeValue({
429
- hour: value.slice(0, 2),
430
- minute: value.slice(3, 5),
431
- second: value.slice(6, 8),
432
- text: value.slice(10, 12)
433
- });
434
- setDisplayTime(displayTimeValue);
435
- }
436
- }, [value, displayFormat, returnFormat, mode12h, min, max]);
437
-
438
- // useEffect for prop min/max
439
- useEffect(() => {
440
- setMinValue(min);
441
- setMaxValue(max);
442
- }, [min, max]);
443
- useImperativeHandle(reference, () => {
444
- const currentRef = ref.current || {};
445
- currentRef.element = ref.current;
446
- const _instance = {
447
- ...action
448
- }; // methods
449
- _instance.__proto__ = {}; // hidden methods
450
- currentRef.instance = _instance;
451
- return currentRef;
452
- });
453
- const IconComp = jsx(ButtonIcon, {
454
- disabled: disabled || readOnly,
455
- viewType: 'ghost',
456
- viewBox: true,
457
- name: 'clock'
458
- });
459
- const endIcon = actionIconAt === 'end' ? IconComp : null;
460
- const startIcon = actionIconAt === 'start' ? IconComp : null;
461
- return useMemo(() => {
462
- return jsx("div", {
463
- ref: ref,
464
- css: positionRelative,
465
- style: style,
466
- className: classNames('DGN-UI-TimePicker-Root', className, disabled && 'disabled'),
467
- ...other
468
- }, label && jsx(Label, {
469
- disabled: disabled,
470
- required: required,
471
- ...labelProps
472
- }, label), jsx(Popover, {
473
- css: _TimePickerCSS,
474
- anchor: jsx(InputBase, {
475
- inputProps: {
476
- placeholder: !readOnly && !disabled ? placeholder : '',
477
- ...inputProps
478
- },
479
- disabled: disabled,
480
- viewType: viewType,
481
- inputStyle: {
482
- ...inputStyle
483
- },
484
- value: displayTime,
485
- endIcon: endIcon,
486
- startIcon: startIcon,
487
- onKeyDown: e => e.preventDefault(),
488
- status: error ? 'danger' : 'default',
489
- readOnly: true
490
- }),
491
- ref: timePickerRef,
492
- transformOrigin: {
493
- vertical: 'top',
494
- horizontal: 'left'
495
- },
496
- anchorOrigin: {
497
- vertical: 'bottom',
498
- horizontal: 'left'
499
- }
500
- }, jsx("div", {
501
- className: "DGN-UI-TimePicker"
502
- }, jsx("div", {
503
- className: "DGN-UI-TimePicker-Body",
504
- css: _TimePickerBodyCSS
505
- }, jsx("div", {
506
- className: "DGN-UI-TimePicker-Input",
507
- css: TimePickerInputCSS
508
- }, currentInputFocus === 1 && jsx(ButtonIcon, {
509
- viewType: "ghost",
510
- name: "ArrowUp",
511
- onClick: onIncreaseHour
512
- }), jsx(NumberInput, {
513
- delayOnChange: 0,
514
- onFocus: () => setCurrentInputFocus(1),
515
- viewType: "outlined",
516
- placeholder: "",
517
- value: currentHour,
518
- onChange: e => onChangeHandler(e, 'hour'),
519
- onKeyDown: e => onChangeHandler(e, 'hour'),
520
- min: startHour,
521
- max: lastHour,
522
- disabledNegative: true
523
- }), currentInputFocus === 1 && jsx(ButtonIcon, {
524
- viewType: "ghost",
525
- name: "ArrowDown",
526
- onClick: onDecreaseHour
527
- })), jsx(Typography, {
528
- type: "title1"
529
- }, ":"), jsx("div", {
530
- className: "DGN-UI-TimePicker-Input",
531
- css: TimePickerInputCSS
532
- }, currentInputFocus === 2 && jsx(ButtonIcon, {
533
- viewType: "ghost",
534
- name: "ArrowUp",
535
- onClick: onIncreaseMinute
536
- }), jsx(NumberInput, {
537
- delayOnChange: 0,
538
- onFocus: () => setCurrentInputFocus(2),
539
- viewType: "outlined",
540
- placeholder: "",
541
- value: currentMinute || 0,
542
- onChange: e => onChangeHandler(e, 'minute'),
543
- onKeyDown: e => onChangeHandler(e, 'minute'),
544
- min: startMinute,
545
- max: lastMinute,
546
- disabledNegative: true
547
- }), currentInputFocus === 2 && jsx(ButtonIcon, {
548
- viewType: "ghost",
549
- name: "ArrowDown",
550
- onClick: onDecreaseMinute
551
- })), displayFormat === 'HH:mm:ss' && jsx(React.Fragment, null, jsx(Typography, {
552
- type: "title1"
553
- }, ":"), jsx("div", {
554
- className: "DGN-UI-TimePicker-Input",
555
- css: TimePickerInputCSS
556
- }, currentInputFocus === 3 && jsx(ButtonIcon, {
557
- viewType: "ghost",
558
- name: "ArrowUp",
559
- onClick: onIncreaseSecond
560
- }), jsx(NumberInput, {
561
- delayOnChange: 0,
562
- onFocus: () => setCurrentInputFocus(3),
563
- viewType: "outlined",
564
- placeholder: "",
565
- value: currentSecond || 0,
566
- onChange: e => onChangeHandler(e, 'second'),
567
- onKeyDown: e => onChangeHandler(e, 'second'),
568
- min: startSecond,
569
- max: lastSecond,
570
- disabledNegative: true
571
- }), currentInputFocus === 3 && jsx(ButtonIcon, {
572
- viewType: "ghost",
573
- name: "ArrowDown",
574
- onClick: onDecreaseSecond
575
- }))), mode12h && jsx("div", {
576
- className: "TimePicker-AM/PM",
577
- css: _TimePickerAMPMCSS
578
- }, jsx(Button, {
579
- onClick: () => setTimeValue({
580
- ...timeValue,
581
- text: 'AM'
582
- }),
583
- label: "AM",
584
- labelProps: {
585
- type: 'heading4'
586
- }
587
- }), jsx(Button, {
588
- onClick: () => setTimeValue({
589
- ...timeValue,
590
- text: 'PM'
591
- }),
592
- label: "PM",
593
- labelProps: {
594
- type: 'heading4'
595
- }
596
- }))), jsx(Divider, null), jsx("div", {
597
- className: "DGN-UI-TimePicker-Footer",
598
- css: _TimePickerFooterCSS
599
- }, jsx(Button, {
600
- viewType: "link",
601
- size: "medium",
602
- label: nowText,
603
- onClick: () => onSelectTime(true),
604
- labelProps: {
605
- format: ['sentence']
606
- },
607
- color: "system/rest"
608
- }), jsx(Button, {
609
- viewType: "link",
610
- size: "medium",
611
- label: saveText,
612
- onClick: () => onSelectTime(false),
613
- labelProps: {
614
- format: ['sentence']
615
- },
616
- color: "info"
617
- })))), isError && jsx(HelperText, {
618
- ...errorProps,
619
- style: {
620
- minHeight: 16,
621
- position: 'absolute',
622
- top: '100%'
623
- },
624
- disabled: disabled
625
- }, error));
626
- }, [actionIconAt, className, currentInputFocus, disabled, displayTime, displayFormat, error, errorProps, id, inputProps, inputStyle, placeholder, onChange, mode12h, minValue, maxValue, label, labelProps, style, minuteStep, timeValue, value, viewType, required, returnFormat, readOnly]);
627
- }));
628
- const TimePickerCSS = ({
629
- spacing
630
- }) => css`
631
- margin-top: ${spacing([1])};
632
- `;
633
- const TimePickerBodyCSS = (currentInputFocus, {
634
- colors,
635
- spacing,
636
- typography
637
- }) => css`
638
- ${typography.body1};
639
- margin: ${spacing([2, 4])};
640
- ${displayFlex};
641
- ${justifyCenter};
642
- ${itemsCenter};
643
- ${parseMinHeight(88)};
644
- .DGN-UI-NumberInput {
645
- margin: ${spacing([0])};
646
- .DGN-UI-InputBase {
647
- ${parseHeight(40)};
648
- ${parseWidth(48)};
649
- margin: ${spacing([0])};
650
- padding: ${spacing([0])};
651
- ${bgColor(hexToRGBA(getProp(colors, 'system/active'), 0.1))}
652
- ${borderNone};
653
- ${borderColor(getProp(colors, 'semantic/info'))};
654
- input {
655
- width: 100%;
656
- height: 100%;
657
- ${textCenter};
658
- ${typography.body1};
659
- &:hover,
660
- &:focus {
661
- ${bgColor(hexToRGBA(getProp(colors, 'semantic/info'), 0.2))};
662
- ${textColor(getProp(colors, 'semantic/info'))};
663
- }
664
- }
665
- }
666
- }
667
- .DGN-UI-TimePicker-Input:nth-of-type(${currentInputFocus}) {
668
- .DGN-UI-NumberInput {
669
- .DGN-UI-InputBase {
670
- ${border(2)};
671
- ${borderColor(getProp(colors, 'semantic/info'))};
672
- input {
673
- ${borderRadius4px};
674
- ${bgColor(hexToRGBA(getProp(colors, 'semantic/info'), 0.2))};
675
- ${textColor(getProp(colors, 'semantic/info'))};
676
- }
677
- }
678
- }
679
- }
680
- .DGN-UI-Typography {
681
- padding: ${spacing([0, 0.5])};
682
- }
683
- `;
684
- const TimePickerInputCSS = css`
685
- ${flexCol};
686
- ${itemsCenter};
687
- `;
688
- const TimePickerFooterCSS = ({
689
- spacing
690
- }) => css`
691
- ${displayFlex};
692
- ${justifyBetween};
693
- ${itemsCenter};
694
- .DGN-UI-Button {
695
- padding: ${spacing([2, 4])};
696
- }
697
- `;
698
- const TimePickerAMPMCSS = (currentText, {
699
- colors,
700
- spacing
701
- }) => css`
702
- ${flexCol};
703
- ${parseHeight(40)};
704
- ${justifyBetween};
705
- margin-left: ${spacing([2])};
706
- button:nth-of-type(${currentText === 'AM' ? 1 : 2}) {
707
- ${bgColor(hexToRGBA(getProp(colors, 'semantic/info'), 0.2))};
708
- ${textColor(getProp(colors, 'semantic/info'))};
709
- }
710
- button {
711
- &:hover,
712
- &:focus {
713
- ${bgColor(hexToRGBA(getProp(colors, 'semantic/info'), 0.2))};
714
- ${textColor(getProp(colors, 'semantic/info'))};
715
- }
716
- padding: ${spacing([0])};
717
- ${parseHeight(18)};
718
- ${parseMinHeight(18)};
719
- ${parseWidth(32)};
720
- }
721
- `;
722
- TimePicker.defaultProps = {
723
- actionIconAt: 'end',
724
- className: '',
725
- disabled: false,
726
- displayFormat: 'HH:mm:ss',
727
- mode12h: false,
728
- readOnly: false,
729
- required: false,
730
- returnFormat: 'HH:mm:ss',
731
- error: '',
732
- minuteStep: 1,
733
- min: '',
734
- max: '',
735
- label: '',
736
- value: ''
737
- };
738
- TimePicker.propTypes = {
739
- /** Class for component. ({container: '', header: '', body: '', footer: ''}) */
740
- className: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
741
- /** If `true`, the form control will be disabled. */
742
- disabled: PropTypes.bool,
743
- /** Format to display value. */
744
- displayFormat: PropTypes.oneOfType([PropTypes.oneOf(['HH:mm', 'HH:mm:ss']), PropTypes.string]),
745
- /** The default value of the component. */
746
- defaultValue: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.string, PropTypes.object]),
747
- /** Error of the form control. */
748
- error: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
749
- /** [Props](https://core.diginet.com.vn/ui/?path=/story/form-control-text-helpertext) of helper text. */
750
- errorProps: PropTypes.object,
751
- /** [Attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attributes) applied to the input element. */
752
- inputProps: PropTypes.object,
753
- /** Style inline of input element. */
754
- inputStyle: PropTypes.object,
755
- /** Hints for input. */
756
- placeholder: PropTypes.string,
757
- /** Components style mode */
758
- mode12h: PropTypes.bool,
759
- /** Min value of time picker. */
760
- min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.string, PropTypes.object]),
761
- /** Max value of time picker. */
762
- max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.string, PropTypes.object]),
763
- /** Step of minute */
764
- minuteStep: PropTypes.number,
765
- /** Content of the label element. */
766
- label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
767
- /** [Props](https://core.diginet.com.vn/ui/?path=/docs/form-control-text-label--simple) of label. */
768
- labelProps: PropTypes.object,
769
- /** A callback function when value input change. */
770
- onChange: PropTypes.func,
771
- /** Style inline of component. */
772
- style: PropTypes.object,
773
- /** The value of the input element, required for a controlled component. */
774
- value: PropTypes.oneOfType([PropTypes.string]),
775
- /** View type of the form control. */
776
- viewType: PropTypes.oneOf(['outlined', 'underlined']),
777
- /** If `true`, the component is readonly. */
778
- readOnly: PropTypes.bool,
779
- /** If `true`, the input element is required. */
780
- required: PropTypes.bool,
781
- /** Format to display value. */
782
- returnFormat: PropTypes.oneOfType([PropTypes.oneOf(['HH:mm', 'HH:mm:ss']), PropTypes.string])
783
- };
784
- export default TimePicker;