@tecsinapse/cortex-react 1.13.0-beta.5 → 1.13.1-beta.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/dist/cjs/components/DatePicker/DatePickerInput.js +2 -1
- package/dist/cjs/components/DatePicker/DateRangePickerInput.js +2 -1
- package/dist/cjs/components/ScrollableDigitSelector.js +57 -0
- package/dist/cjs/components/TimePicker/TimeField.js +48 -0
- package/dist/cjs/components/TimePicker/TimeFieldInput.js +82 -0
- package/dist/cjs/components/TimePicker/TimePickerInput.js +78 -0
- package/dist/cjs/components/TimePicker/TimePickerSelector.js +118 -0
- package/dist/cjs/hooks/useTimePickerInput.js +45 -0
- package/dist/cjs/index.js +8 -2
- package/dist/cjs/styles/time-field-input.js +18 -0
- package/dist/cjs/utils/date.js +0 -5
- package/dist/esm/components/DatePicker/DatePickerInput.js +2 -1
- package/dist/esm/components/DatePicker/DateRangePickerInput.js +2 -1
- package/dist/esm/components/ScrollableDigitSelector.js +55 -0
- package/dist/esm/components/TimePicker/TimeField.js +46 -0
- package/dist/esm/components/TimePicker/TimeFieldInput.js +80 -0
- package/dist/esm/components/TimePicker/TimePickerInput.js +76 -0
- package/dist/esm/components/TimePicker/TimePickerSelector.js +116 -0
- package/dist/esm/hooks/useTimePickerInput.js +43 -0
- package/dist/esm/index.js +5 -2
- package/dist/esm/styles/time-field-input.js +16 -0
- package/dist/esm/utils/date.js +2 -6
- package/dist/types/components/ScrollableDigitSelector.d.ts +10 -0
- package/dist/types/components/{TimeField → TimePicker}/TimeField.d.ts +2 -1
- package/dist/types/components/TimePicker/TimeFieldInput.d.ts +14 -0
- package/dist/types/components/TimePicker/TimePickerInput.d.ts +15 -0
- package/dist/types/components/TimePicker/TimePickerSelector.d.ts +14 -0
- package/dist/types/components/TimePicker/index.d.ts +4 -0
- package/dist/types/components/index.d.ts +1 -1
- package/dist/types/hooks/index.d.ts +1 -0
- package/dist/types/hooks/useTimePickerInput.d.ts +14 -0
- package/dist/types/styles/time-field-input.d.ts +25 -0
- package/package.json +2 -2
- package/dist/cjs/components/TimeField/TimeField.js +0 -24
- package/dist/cjs/components/TimeField/TimeFieldInput.js +0 -42
- package/dist/esm/components/TimeField/TimeField.js +0 -22
- package/dist/esm/components/TimeField/TimeFieldInput.js +0 -40
- package/dist/types/components/TimeField/TimeFieldInput.d.ts +0 -11
- package/dist/types/components/TimeField/index.d.ts +0 -2
- /package/dist/cjs/components/{DatePicker/Content.js → Content.js} +0 -0
- /package/dist/esm/components/{DatePicker/Content.js → Content.js} +0 -0
- /package/dist/types/components/{DatePicker/Content.d.ts → Content.d.ts} +0 -0
|
@@ -11,9 +11,10 @@ require('react-dropzone');
|
|
|
11
11
|
require('uuid');
|
|
12
12
|
require('@floating-ui/react');
|
|
13
13
|
require('currency.js');
|
|
14
|
+
require('../Popover/Context.js');
|
|
14
15
|
var Calendar = require('../Calendar/Calendar.js');
|
|
15
16
|
var index = require('../Popover/index.js');
|
|
16
|
-
var Content = require('../
|
|
17
|
+
var Content = require('../Content.js');
|
|
17
18
|
var DateField = require('./DateField.js');
|
|
18
19
|
var DatePickerInputBase = require('./DatePickerInputBase.js');
|
|
19
20
|
|
|
@@ -11,9 +11,10 @@ require('react-dropzone');
|
|
|
11
11
|
require('uuid');
|
|
12
12
|
require('@floating-ui/react');
|
|
13
13
|
require('currency.js');
|
|
14
|
+
require('../Popover/Context.js');
|
|
14
15
|
var RangeCalendar = require('../Calendar/RangeCalendar.js');
|
|
15
16
|
var index = require('../Popover/index.js');
|
|
16
|
-
var Content = require('
|
|
17
|
+
var Content = require('../Content.js');
|
|
17
18
|
var DateField = require('./DateField.js');
|
|
18
19
|
var DatePickerInputBase = require('./DatePickerInputBase.js');
|
|
19
20
|
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var clsx = require('clsx');
|
|
5
|
+
|
|
6
|
+
const formatValue = (val) => {
|
|
7
|
+
return val.toString().padStart(2, "0");
|
|
8
|
+
};
|
|
9
|
+
const ScrollableDigitSelector = ({
|
|
10
|
+
value,
|
|
11
|
+
onChange,
|
|
12
|
+
min,
|
|
13
|
+
max,
|
|
14
|
+
step = 1
|
|
15
|
+
}) => {
|
|
16
|
+
const containerRef = React.useRef(null);
|
|
17
|
+
const values = React.useMemo(() => {
|
|
18
|
+
const vals = [];
|
|
19
|
+
for (let i = min; i <= max; i += step) {
|
|
20
|
+
vals.push(i);
|
|
21
|
+
}
|
|
22
|
+
return vals;
|
|
23
|
+
}, [min, max, step]);
|
|
24
|
+
const scrollToValue = (targetValue) => {
|
|
25
|
+
if (containerRef.current) {
|
|
26
|
+
const index = values.indexOf(targetValue);
|
|
27
|
+
if (index !== -1) {
|
|
28
|
+
const itemHeight = 27;
|
|
29
|
+
const scrollTop = index * itemHeight;
|
|
30
|
+
containerRef.current.scrollTop = scrollTop;
|
|
31
|
+
containerRef.current.scrollTo({ top: scrollTop, behavior: "smooth" });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
React.useEffect(() => {
|
|
36
|
+
scrollToValue(value);
|
|
37
|
+
}, []);
|
|
38
|
+
return /* @__PURE__ */ React.createElement(
|
|
39
|
+
"div",
|
|
40
|
+
{
|
|
41
|
+
className: "flex flex-col items-center gap-y-micro p-micro overflow-auto",
|
|
42
|
+
ref: containerRef
|
|
43
|
+
},
|
|
44
|
+
values.map((val) => /* @__PURE__ */ React.createElement("div", { key: val }, /* @__PURE__ */ React.createElement("div", { onClick: () => onChange(val), className: "flex justify-center" }, /* @__PURE__ */ React.createElement(
|
|
45
|
+
"span",
|
|
46
|
+
{
|
|
47
|
+
className: clsx(
|
|
48
|
+
"p-micro rounded-micro border-1 border-transparent hover:bg-primary-light hover:border-primary cursor-pointer",
|
|
49
|
+
value === val && "bg-primary-medium text-white"
|
|
50
|
+
)
|
|
51
|
+
},
|
|
52
|
+
formatValue(val)
|
|
53
|
+
))))
|
|
54
|
+
);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
exports.ScrollableDigitSelector = ScrollableDigitSelector;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var reactAria = require('react-aria');
|
|
5
|
+
var reactStately = require('react-stately');
|
|
6
|
+
var DateSegment = require('../DatePicker/DateSegment.js');
|
|
7
|
+
|
|
8
|
+
const formatLiteralSegment = (text) => {
|
|
9
|
+
return text.includes(",") ? text.replace(/,/g, " ") : text;
|
|
10
|
+
};
|
|
11
|
+
const TimeField = ({ onClickTime, ...props }) => {
|
|
12
|
+
const { value } = props;
|
|
13
|
+
const { locale } = reactAria.useLocale();
|
|
14
|
+
const state = reactStately.useTimeFieldState({
|
|
15
|
+
...props,
|
|
16
|
+
locale,
|
|
17
|
+
shouldForceLeadingZeros: true
|
|
18
|
+
});
|
|
19
|
+
const ref = React.useRef(null);
|
|
20
|
+
const { fieldProps } = reactAria.useTimeField(
|
|
21
|
+
{ "aria-label": "time-field" },
|
|
22
|
+
state,
|
|
23
|
+
ref
|
|
24
|
+
);
|
|
25
|
+
const handleOnClickSegment = React.useCallback(
|
|
26
|
+
(segment) => {
|
|
27
|
+
if (!segment.isEditable || state.isDisabled) return;
|
|
28
|
+
if (["hour", "minute", "second", "dayPeriod"].includes(segment.type)) {
|
|
29
|
+
onClickTime?.();
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
[onClickTime, state.isDisabled]
|
|
33
|
+
);
|
|
34
|
+
React.useEffect(() => {
|
|
35
|
+
if (!value) {
|
|
36
|
+
state.setValue(null);
|
|
37
|
+
}
|
|
38
|
+
}, [value]);
|
|
39
|
+
return /* @__PURE__ */ React.createElement("div", { ...fieldProps, ref, className: "flex flex-row" }, state.segments.map((segment, i) => {
|
|
40
|
+
if (segment.type === "literal") {
|
|
41
|
+
const text = formatLiteralSegment(segment.text);
|
|
42
|
+
return /* @__PURE__ */ React.createElement("span", { key: i, style: { whiteSpace: "pre" } }, text);
|
|
43
|
+
}
|
|
44
|
+
return /* @__PURE__ */ React.createElement("div", { key: i, onClick: () => handleOnClickSegment(segment) }, /* @__PURE__ */ React.createElement(DateSegment.DateSegment, { segment, state }));
|
|
45
|
+
}));
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
exports.TimeField = TimeField;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var cortexCore = require('@tecsinapse/cortex-core');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var index = require('../Input/index.js');
|
|
6
|
+
var lia = require('react-icons/lia');
|
|
7
|
+
var timeFieldInput = require('../../styles/time-field-input.js');
|
|
8
|
+
var io = require('react-icons/io');
|
|
9
|
+
var TimeField = require('./TimeField.js');
|
|
10
|
+
|
|
11
|
+
const { icon } = timeFieldInput.timePickerInputBase();
|
|
12
|
+
const TimeFieldInput = ({
|
|
13
|
+
variants,
|
|
14
|
+
label,
|
|
15
|
+
disabled = false,
|
|
16
|
+
value,
|
|
17
|
+
onChange,
|
|
18
|
+
onToggle,
|
|
19
|
+
onClean,
|
|
20
|
+
hourCycle,
|
|
21
|
+
granularity
|
|
22
|
+
}) => {
|
|
23
|
+
const showCloseIcon = React.useMemo(() => {
|
|
24
|
+
const hasTime = value != void 0;
|
|
25
|
+
return hasTime;
|
|
26
|
+
}, [value]);
|
|
27
|
+
return /* @__PURE__ */ React.createElement(
|
|
28
|
+
index.Input.Face,
|
|
29
|
+
{
|
|
30
|
+
variants,
|
|
31
|
+
className: "flex flex-row justify-between",
|
|
32
|
+
"data-testid": "time-field-input"
|
|
33
|
+
},
|
|
34
|
+
/* @__PURE__ */ React.createElement("span", { className: cortexCore.labelStyle({}) }, label),
|
|
35
|
+
/* @__PURE__ */ React.createElement("div", { className: cortexCore.inputBox("", label) }, /* @__PURE__ */ React.createElement(
|
|
36
|
+
TimeField.TimeField,
|
|
37
|
+
{
|
|
38
|
+
onClickTime: onToggle,
|
|
39
|
+
disabled,
|
|
40
|
+
value,
|
|
41
|
+
onChange,
|
|
42
|
+
hourCycle,
|
|
43
|
+
granularity
|
|
44
|
+
}
|
|
45
|
+
)),
|
|
46
|
+
/* @__PURE__ */ React.createElement(index.Input.Right, { className: "h-full justify-center" }, showCloseIcon ? /* @__PURE__ */ React.createElement(
|
|
47
|
+
"button",
|
|
48
|
+
{
|
|
49
|
+
className: "flex bg-transparent items-center",
|
|
50
|
+
onClick: onClean,
|
|
51
|
+
disabled,
|
|
52
|
+
"data-testid": "time-picker-input-base-clean-button",
|
|
53
|
+
type: "button"
|
|
54
|
+
},
|
|
55
|
+
/* @__PURE__ */ React.createElement(
|
|
56
|
+
io.IoMdClose,
|
|
57
|
+
{
|
|
58
|
+
className: icon({ disabled }),
|
|
59
|
+
"data-testid": "time-picker-input-base-clean-icon"
|
|
60
|
+
}
|
|
61
|
+
)
|
|
62
|
+
) : /* @__PURE__ */ React.createElement(
|
|
63
|
+
"button",
|
|
64
|
+
{
|
|
65
|
+
className: "flex bg-transparent items-center",
|
|
66
|
+
onClick: onToggle,
|
|
67
|
+
disabled,
|
|
68
|
+
"data-testid": "time-picker-input-base-calendar-button",
|
|
69
|
+
type: "button"
|
|
70
|
+
},
|
|
71
|
+
/* @__PURE__ */ React.createElement(
|
|
72
|
+
lia.LiaClock,
|
|
73
|
+
{
|
|
74
|
+
className: icon({ disabled }),
|
|
75
|
+
"data-testid": "time-picker-input-base-calendar-icon"
|
|
76
|
+
}
|
|
77
|
+
)
|
|
78
|
+
))
|
|
79
|
+
);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
exports.TimeFieldInput = TimeFieldInput;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
require('@internationalized/date');
|
|
5
|
+
require('react-aria');
|
|
6
|
+
require('react-stately');
|
|
7
|
+
require('../Popover/Context.js');
|
|
8
|
+
require('react-dropzone');
|
|
9
|
+
require('uuid');
|
|
10
|
+
require('@floating-ui/react');
|
|
11
|
+
require('currency.js');
|
|
12
|
+
var useTimePickerInput = require('../../hooks/useTimePickerInput.js');
|
|
13
|
+
var index = require('../Popover/index.js');
|
|
14
|
+
var Content = require('../Content.js');
|
|
15
|
+
var TimeFieldInput = require('./TimeFieldInput.js');
|
|
16
|
+
var TimePickerSelector = require('./TimePickerSelector.js');
|
|
17
|
+
|
|
18
|
+
const TimePickerInputWithPopover = (props) => {
|
|
19
|
+
const {
|
|
20
|
+
onChange,
|
|
21
|
+
value,
|
|
22
|
+
label,
|
|
23
|
+
variants,
|
|
24
|
+
hourCycle = 24,
|
|
25
|
+
disabled = false,
|
|
26
|
+
granularity = "minute",
|
|
27
|
+
minuteInterval = 1,
|
|
28
|
+
hourLabel,
|
|
29
|
+
minuteLabel,
|
|
30
|
+
dayPeriodLabel
|
|
31
|
+
} = props;
|
|
32
|
+
const {
|
|
33
|
+
handleTogglePopover,
|
|
34
|
+
handleTimeFieldChange,
|
|
35
|
+
handleChangeTimeOnSelector,
|
|
36
|
+
popoverTime
|
|
37
|
+
} = useTimePickerInput.useTimePickerInput({
|
|
38
|
+
value,
|
|
39
|
+
onChange,
|
|
40
|
+
minuteInterval
|
|
41
|
+
});
|
|
42
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(index.Popover.Trigger, { disabled: true }, /* @__PURE__ */ React.createElement(
|
|
43
|
+
TimeFieldInput.TimeFieldInput,
|
|
44
|
+
{
|
|
45
|
+
variants,
|
|
46
|
+
label,
|
|
47
|
+
disabled,
|
|
48
|
+
value,
|
|
49
|
+
onChange: handleTimeFieldChange,
|
|
50
|
+
onClean: () => handleTimeFieldChange(null),
|
|
51
|
+
onToggle: handleTogglePopover,
|
|
52
|
+
hourCycle,
|
|
53
|
+
granularity
|
|
54
|
+
}
|
|
55
|
+
)), /* @__PURE__ */ React.createElement(
|
|
56
|
+
index.Popover.Content,
|
|
57
|
+
{
|
|
58
|
+
className: "bg-white shadow-none border-none p-deca flex flex-col",
|
|
59
|
+
initialFocus: -1
|
|
60
|
+
},
|
|
61
|
+
/* @__PURE__ */ React.createElement(
|
|
62
|
+
TimePickerSelector.TimePickerSelector,
|
|
63
|
+
{
|
|
64
|
+
onChangeTime: handleChangeTimeOnSelector,
|
|
65
|
+
value: popoverTime,
|
|
66
|
+
hourCycle,
|
|
67
|
+
minuteInterval,
|
|
68
|
+
onPressOkButton: handleTogglePopover,
|
|
69
|
+
hourLabel,
|
|
70
|
+
minuteLabel,
|
|
71
|
+
dayPeriodLabel
|
|
72
|
+
}
|
|
73
|
+
)
|
|
74
|
+
));
|
|
75
|
+
};
|
|
76
|
+
const TimePickerInput = (props) => /* @__PURE__ */ React.createElement(index.Popover.Root, { placement: "bottom-start", trigger: "click" }, /* @__PURE__ */ React.createElement(Content.Content, null, /* @__PURE__ */ React.createElement(TimePickerInputWithPopover, { ...props })));
|
|
77
|
+
|
|
78
|
+
exports.TimePickerInput = TimePickerInput;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var date = require('@internationalized/date');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var ScrollableDigitSelector = require('../ScrollableDigitSelector.js');
|
|
6
|
+
var clsx = require('clsx');
|
|
7
|
+
var Button = require('../Button.js');
|
|
8
|
+
var md = require('react-icons/md');
|
|
9
|
+
|
|
10
|
+
const dayPeriodStyle = "p-micro rounded-micro border-1 border-transparent hover:bg-primary-light hover:border-primary cursor-pointer";
|
|
11
|
+
const TimePickerSelector = ({
|
|
12
|
+
value,
|
|
13
|
+
hourCycle,
|
|
14
|
+
minuteInterval,
|
|
15
|
+
onPressOkButton,
|
|
16
|
+
onChangeTime,
|
|
17
|
+
hourLabel = "Hour",
|
|
18
|
+
minuteLabel = "Minute",
|
|
19
|
+
dayPeriodLabel = "Day Period"
|
|
20
|
+
}) => {
|
|
21
|
+
const handleHourChange = (hour) => {
|
|
22
|
+
let newHour = hour;
|
|
23
|
+
if (hourCycle === 12) {
|
|
24
|
+
if (isPM && newHour < 12) {
|
|
25
|
+
newHour += 12;
|
|
26
|
+
} else if (!isPM && newHour >= 12) {
|
|
27
|
+
newHour -= 12;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const newTime = new date.Time(newHour, value.minute, value.second);
|
|
31
|
+
onChangeTime(newTime);
|
|
32
|
+
};
|
|
33
|
+
const handleMinuteChange = (minute) => {
|
|
34
|
+
const newTime = new date.Time(value.hour, minute, value.second);
|
|
35
|
+
onChangeTime(newTime);
|
|
36
|
+
};
|
|
37
|
+
const handlePeriodChange = (isPM2) => {
|
|
38
|
+
if (value === void 0) return;
|
|
39
|
+
let newHour = value.hour;
|
|
40
|
+
if (hourCycle === 12) {
|
|
41
|
+
if (isPM2 && newHour < 12) {
|
|
42
|
+
newHour += 12;
|
|
43
|
+
} else if (!isPM2 && newHour >= 12) {
|
|
44
|
+
newHour -= 12;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const newTime = new date.Time(newHour, value.minute, value.second);
|
|
48
|
+
onChangeTime(newTime);
|
|
49
|
+
};
|
|
50
|
+
const isPM = value && value?.hour >= 12;
|
|
51
|
+
const displayHour = React.useMemo(() => {
|
|
52
|
+
if (value === void 0) return 0;
|
|
53
|
+
return hourCycle === 12 ? value.hour === 0 ? 12 : value.hour > 12 ? value.hour - 12 : value.hour : value.hour;
|
|
54
|
+
}, [value, hourCycle]);
|
|
55
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", { className: "flex justify-end" }, /* @__PURE__ */ React.createElement(
|
|
56
|
+
Button.Button,
|
|
57
|
+
{
|
|
58
|
+
className: "p-micro",
|
|
59
|
+
variants: {
|
|
60
|
+
size: "circle",
|
|
61
|
+
variant: "outline"
|
|
62
|
+
},
|
|
63
|
+
onClick: onPressOkButton
|
|
64
|
+
},
|
|
65
|
+
/* @__PURE__ */ React.createElement(md.MdClose, null)
|
|
66
|
+
)), /* @__PURE__ */ React.createElement("div", { className: "flex flex-row gap-x-deca max-h-[300px] overflow-hidden" }, /* @__PURE__ */ React.createElement("div", { className: "min-w-7 flex flex-col gap-y-micro p-micro" }, /* @__PURE__ */ React.createElement("span", { className: "text-base font-bold text-center" }, hourLabel), /* @__PURE__ */ React.createElement(
|
|
67
|
+
ScrollableDigitSelector.ScrollableDigitSelector,
|
|
68
|
+
{
|
|
69
|
+
value: displayHour,
|
|
70
|
+
onChange: handleHourChange,
|
|
71
|
+
min: hourCycle === 12 ? 1 : 0,
|
|
72
|
+
max: hourCycle === 12 ? 12 : 23
|
|
73
|
+
}
|
|
74
|
+
)), /* @__PURE__ */ React.createElement("div", { className: "min-w-7 flex flex-col gap-y-micro p-micro" }, /* @__PURE__ */ React.createElement("span", { className: "text-base font-bold text-center" }, minuteLabel), /* @__PURE__ */ React.createElement(
|
|
75
|
+
ScrollableDigitSelector.ScrollableDigitSelector,
|
|
76
|
+
{
|
|
77
|
+
value: value?.minute ?? 0,
|
|
78
|
+
onChange: handleMinuteChange,
|
|
79
|
+
min: 0,
|
|
80
|
+
max: 59,
|
|
81
|
+
step: minuteInterval
|
|
82
|
+
}
|
|
83
|
+
)), hourCycle === 12 && /* @__PURE__ */ React.createElement("div", { className: "min-w-7 flex flex-col gap-y-micro p-micro" }, /* @__PURE__ */ React.createElement("span", { className: "text-base font-bold text-center" }, dayPeriodLabel), /* @__PURE__ */ React.createElement("div", { className: "flex flex-col gap-y-micro p-micro overflow-auto" }, /* @__PURE__ */ React.createElement(
|
|
84
|
+
"div",
|
|
85
|
+
{
|
|
86
|
+
onClick: () => handlePeriodChange(false),
|
|
87
|
+
className: "flex justify-center"
|
|
88
|
+
},
|
|
89
|
+
/* @__PURE__ */ React.createElement(
|
|
90
|
+
"span",
|
|
91
|
+
{
|
|
92
|
+
className: clsx(
|
|
93
|
+
dayPeriodStyle,
|
|
94
|
+
!isPM && "bg-primary-medium text-white"
|
|
95
|
+
)
|
|
96
|
+
},
|
|
97
|
+
"AM"
|
|
98
|
+
)
|
|
99
|
+
), /* @__PURE__ */ React.createElement(
|
|
100
|
+
"div",
|
|
101
|
+
{
|
|
102
|
+
onClick: () => handlePeriodChange(true),
|
|
103
|
+
className: "flex justify-center"
|
|
104
|
+
},
|
|
105
|
+
/* @__PURE__ */ React.createElement(
|
|
106
|
+
"span",
|
|
107
|
+
{
|
|
108
|
+
className: clsx(
|
|
109
|
+
dayPeriodStyle,
|
|
110
|
+
isPM && "bg-primary-medium text-white"
|
|
111
|
+
)
|
|
112
|
+
},
|
|
113
|
+
"PM"
|
|
114
|
+
)
|
|
115
|
+
)))));
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
exports.TimePickerSelector = TimePickerSelector;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var Context = require('../components/Popover/Context.js');
|
|
5
|
+
var date = require('@internationalized/date');
|
|
6
|
+
|
|
7
|
+
const useTimePickerInput = ({
|
|
8
|
+
value,
|
|
9
|
+
onChange,
|
|
10
|
+
minuteInterval
|
|
11
|
+
}) => {
|
|
12
|
+
const { setIsOpen } = Context.usePopoverContext();
|
|
13
|
+
const [popoverTime, setPopoverTime] = React.useState(value ?? new date.Time(0, 0));
|
|
14
|
+
const handleTimeFieldChange = (newValue) => {
|
|
15
|
+
if (newValue && minuteInterval > 1) {
|
|
16
|
+
const time = newValue;
|
|
17
|
+
const adjustedMinute = Math.round(time.minute / minuteInterval) * minuteInterval % 60;
|
|
18
|
+
const adjustedTime = time.set({ minute: adjustedMinute });
|
|
19
|
+
onChange?.(adjustedTime);
|
|
20
|
+
setPopoverTime(adjustedTime);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const newTime = newValue ? new date.Time(newValue.hour, newValue.minute, newValue.second) : void 0;
|
|
24
|
+
onChange?.(newTime);
|
|
25
|
+
setPopoverTime(newTime ?? new date.Time(0, 0));
|
|
26
|
+
};
|
|
27
|
+
const handleTogglePopover = React.useCallback(() => {
|
|
28
|
+
setIsOpen((open) => !open);
|
|
29
|
+
}, []);
|
|
30
|
+
const handleChangeTimeOnSelector = React.useCallback(
|
|
31
|
+
(time) => {
|
|
32
|
+
setPopoverTime(time);
|
|
33
|
+
handleTimeFieldChange(time);
|
|
34
|
+
},
|
|
35
|
+
[handleTimeFieldChange]
|
|
36
|
+
);
|
|
37
|
+
return {
|
|
38
|
+
handleTogglePopover,
|
|
39
|
+
handleTimeFieldChange,
|
|
40
|
+
handleChangeTimeOnSelector,
|
|
41
|
+
popoverTime
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
exports.useTimePickerInput = useTimePickerInput;
|
package/dist/cjs/index.js
CHANGED
|
@@ -37,8 +37,10 @@ var index$5 = require('./components/Stepper/index.js');
|
|
|
37
37
|
var Table = require('./components/Table.js');
|
|
38
38
|
var Tag = require('./components/Tag.js');
|
|
39
39
|
var index$6 = require('./components/TextArea/index.js');
|
|
40
|
-
var TimeField = require('./components/
|
|
41
|
-
var
|
|
40
|
+
var TimeField = require('./components/TimePicker/TimeField.js');
|
|
41
|
+
var TimePickerInput = require('./components/TimePicker/TimePickerInput.js');
|
|
42
|
+
var TimePickerSelector = require('./components/TimePicker/TimePickerSelector.js');
|
|
43
|
+
var TimeFieldInput = require('./components/TimePicker/TimeFieldInput.js');
|
|
42
44
|
var Toggle = require('./components/Toggle.js');
|
|
43
45
|
var Tooltip = require('./components/Tooltip.js');
|
|
44
46
|
var index$7 = require('./components/Uploader/index.js');
|
|
@@ -58,6 +60,7 @@ var useRangeCalendar = require('./hooks/useRangeCalendar.js');
|
|
|
58
60
|
var useSelectGroupedOptions = require('./hooks/useSelectGroupedOptions.js');
|
|
59
61
|
var useSelectOptions = require('./hooks/useSelectOptions.js');
|
|
60
62
|
var useStringMask = require('./hooks/useStringMask.js');
|
|
63
|
+
var useTimePickerInput = require('./hooks/useTimePickerInput.js');
|
|
61
64
|
var SnackbarSonner = require('./service/SnackbarSonner.js');
|
|
62
65
|
var MenubarProvider = require('./provider/MenubarProvider.js');
|
|
63
66
|
var SnackbarProvider = require('./provider/SnackbarProvider.js');
|
|
@@ -116,6 +119,8 @@ exports.Td = Table.Td;
|
|
|
116
119
|
exports.Tag = Tag.Tag;
|
|
117
120
|
exports.TextArea = index$6.TextArea;
|
|
118
121
|
exports.TimeField = TimeField.TimeField;
|
|
122
|
+
exports.TimePickerInput = TimePickerInput.TimePickerInput;
|
|
123
|
+
exports.TimePickerSelector = TimePickerSelector.TimePickerSelector;
|
|
119
124
|
exports.TimeFieldInput = TimeFieldInput.TimeFieldInput;
|
|
120
125
|
exports.Toggle = Toggle.Toggle;
|
|
121
126
|
exports.Tooltip = Tooltip.Tooltip;
|
|
@@ -141,6 +146,7 @@ exports.applyStringMask = useStringMask.applyStringMask;
|
|
|
141
146
|
exports.getMask = useStringMask.getMask;
|
|
142
147
|
exports.mergeMask = useStringMask.mergeMask;
|
|
143
148
|
exports.useStringMask = useStringMask.useStringMask;
|
|
149
|
+
exports.useTimePickerInput = useTimePickerInput.useTimePickerInput;
|
|
144
150
|
exports.SnackbarSonner = SnackbarSonner.SnackbarSonner;
|
|
145
151
|
exports.MenubarProvider = MenubarProvider.MenubarProvider;
|
|
146
152
|
exports.SnackbarProvider = SnackbarProvider.SnackbarProvider;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var tailwindVariants = require('tailwind-variants');
|
|
4
|
+
|
|
5
|
+
const timePickerInputBase = tailwindVariants.tv({
|
|
6
|
+
slots: {
|
|
7
|
+
icon: "cursor-pointer text-deca"
|
|
8
|
+
},
|
|
9
|
+
variants: {
|
|
10
|
+
disabled: {
|
|
11
|
+
true: {
|
|
12
|
+
icon: "text-secondary-light cursor-default"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
exports.timePickerInputBase = timePickerInputBase;
|
package/dist/cjs/utils/date.js
CHANGED
|
@@ -16,11 +16,6 @@ const calendarDateToDate = (value) => {
|
|
|
16
16
|
if (!value) return void 0;
|
|
17
17
|
return value.toDate(date.getLocalTimeZone());
|
|
18
18
|
};
|
|
19
|
-
const timeFromTimeValue = (value) => {
|
|
20
|
-
if (!value) return void 0;
|
|
21
|
-
return new date.Time(value.hour, value.minute, value.second, value.millisecond);
|
|
22
|
-
};
|
|
23
19
|
|
|
24
20
|
exports.calendarDateToDate = calendarDateToDate;
|
|
25
21
|
exports.dateToCalendarDateTime = dateToCalendarDateTime;
|
|
26
|
-
exports.timeFromTimeValue = timeFromTimeValue;
|
|
@@ -9,9 +9,10 @@ import 'react-dropzone';
|
|
|
9
9
|
import 'uuid';
|
|
10
10
|
import '@floating-ui/react';
|
|
11
11
|
import 'currency.js';
|
|
12
|
+
import '../Popover/Context.js';
|
|
12
13
|
import { Calendar } from '../Calendar/Calendar.js';
|
|
13
14
|
import { Popover } from '../Popover/index.js';
|
|
14
|
-
import { Content } from '../
|
|
15
|
+
import { Content } from '../Content.js';
|
|
15
16
|
import { DateField } from './DateField.js';
|
|
16
17
|
import { DatePickerInputBase } from './DatePickerInputBase.js';
|
|
17
18
|
|
|
@@ -9,9 +9,10 @@ import 'react-dropzone';
|
|
|
9
9
|
import 'uuid';
|
|
10
10
|
import '@floating-ui/react';
|
|
11
11
|
import 'currency.js';
|
|
12
|
+
import '../Popover/Context.js';
|
|
12
13
|
import { RangeCalendar } from '../Calendar/RangeCalendar.js';
|
|
13
14
|
import { Popover } from '../Popover/index.js';
|
|
14
|
-
import { Content } from '
|
|
15
|
+
import { Content } from '../Content.js';
|
|
15
16
|
import { DateField } from './DateField.js';
|
|
16
17
|
import { DatePickerInputBase } from './DatePickerInputBase.js';
|
|
17
18
|
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import React__default, { useRef, useMemo, useEffect } from 'react';
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
|
|
4
|
+
const formatValue = (val) => {
|
|
5
|
+
return val.toString().padStart(2, "0");
|
|
6
|
+
};
|
|
7
|
+
const ScrollableDigitSelector = ({
|
|
8
|
+
value,
|
|
9
|
+
onChange,
|
|
10
|
+
min,
|
|
11
|
+
max,
|
|
12
|
+
step = 1
|
|
13
|
+
}) => {
|
|
14
|
+
const containerRef = useRef(null);
|
|
15
|
+
const values = useMemo(() => {
|
|
16
|
+
const vals = [];
|
|
17
|
+
for (let i = min; i <= max; i += step) {
|
|
18
|
+
vals.push(i);
|
|
19
|
+
}
|
|
20
|
+
return vals;
|
|
21
|
+
}, [min, max, step]);
|
|
22
|
+
const scrollToValue = (targetValue) => {
|
|
23
|
+
if (containerRef.current) {
|
|
24
|
+
const index = values.indexOf(targetValue);
|
|
25
|
+
if (index !== -1) {
|
|
26
|
+
const itemHeight = 27;
|
|
27
|
+
const scrollTop = index * itemHeight;
|
|
28
|
+
containerRef.current.scrollTop = scrollTop;
|
|
29
|
+
containerRef.current.scrollTo({ top: scrollTop, behavior: "smooth" });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
scrollToValue(value);
|
|
35
|
+
}, []);
|
|
36
|
+
return /* @__PURE__ */ React__default.createElement(
|
|
37
|
+
"div",
|
|
38
|
+
{
|
|
39
|
+
className: "flex flex-col items-center gap-y-micro p-micro overflow-auto",
|
|
40
|
+
ref: containerRef
|
|
41
|
+
},
|
|
42
|
+
values.map((val) => /* @__PURE__ */ React__default.createElement("div", { key: val }, /* @__PURE__ */ React__default.createElement("div", { onClick: () => onChange(val), className: "flex justify-center" }, /* @__PURE__ */ React__default.createElement(
|
|
43
|
+
"span",
|
|
44
|
+
{
|
|
45
|
+
className: clsx(
|
|
46
|
+
"p-micro rounded-micro border-1 border-transparent hover:bg-primary-light hover:border-primary cursor-pointer",
|
|
47
|
+
value === val && "bg-primary-medium text-white"
|
|
48
|
+
)
|
|
49
|
+
},
|
|
50
|
+
formatValue(val)
|
|
51
|
+
))))
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export { ScrollableDigitSelector };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React__default, { useCallback, useEffect } from 'react';
|
|
2
|
+
import { useLocale, useTimeField } from 'react-aria';
|
|
3
|
+
import { useTimeFieldState } from 'react-stately';
|
|
4
|
+
import { DateSegment } from '../DatePicker/DateSegment.js';
|
|
5
|
+
|
|
6
|
+
const formatLiteralSegment = (text) => {
|
|
7
|
+
return text.includes(",") ? text.replace(/,/g, " ") : text;
|
|
8
|
+
};
|
|
9
|
+
const TimeField = ({ onClickTime, ...props }) => {
|
|
10
|
+
const { value } = props;
|
|
11
|
+
const { locale } = useLocale();
|
|
12
|
+
const state = useTimeFieldState({
|
|
13
|
+
...props,
|
|
14
|
+
locale,
|
|
15
|
+
shouldForceLeadingZeros: true
|
|
16
|
+
});
|
|
17
|
+
const ref = React__default.useRef(null);
|
|
18
|
+
const { fieldProps } = useTimeField(
|
|
19
|
+
{ "aria-label": "time-field" },
|
|
20
|
+
state,
|
|
21
|
+
ref
|
|
22
|
+
);
|
|
23
|
+
const handleOnClickSegment = useCallback(
|
|
24
|
+
(segment) => {
|
|
25
|
+
if (!segment.isEditable || state.isDisabled) return;
|
|
26
|
+
if (["hour", "minute", "second", "dayPeriod"].includes(segment.type)) {
|
|
27
|
+
onClickTime?.();
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
[onClickTime, state.isDisabled]
|
|
31
|
+
);
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if (!value) {
|
|
34
|
+
state.setValue(null);
|
|
35
|
+
}
|
|
36
|
+
}, [value]);
|
|
37
|
+
return /* @__PURE__ */ React__default.createElement("div", { ...fieldProps, ref, className: "flex flex-row" }, state.segments.map((segment, i) => {
|
|
38
|
+
if (segment.type === "literal") {
|
|
39
|
+
const text = formatLiteralSegment(segment.text);
|
|
40
|
+
return /* @__PURE__ */ React__default.createElement("span", { key: i, style: { whiteSpace: "pre" } }, text);
|
|
41
|
+
}
|
|
42
|
+
return /* @__PURE__ */ React__default.createElement("div", { key: i, onClick: () => handleOnClickSegment(segment) }, /* @__PURE__ */ React__default.createElement(DateSegment, { segment, state }));
|
|
43
|
+
}));
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export { TimeField };
|