@tecsinapse/cortex-react 1.13.0 → 1.13.1-beta.1
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 +3 -2
- package/dist/cjs/components/DatePicker/DateRangePickerInput.js +3 -2
- package/dist/cjs/components/ScrollableDigitSelector.js +57 -0
- package/dist/cjs/components/Select/CustomMultiOption.js +38 -0
- package/dist/cjs/components/Select/CustomOption.js +31 -0
- package/dist/cjs/components/Select/MultiCheckAllOptions.js +1 -1
- package/dist/cjs/components/Select/MultiGroupedOptions.js +2 -8
- package/dist/cjs/components/Select/MultiOption.js +3 -12
- package/dist/cjs/components/Select/MultiOptions.js +2 -3
- package/dist/cjs/components/Select/Options.js +15 -10
- package/dist/cjs/components/Select/index.js +5 -1
- package/dist/cjs/components/Select/useMultiSelectOption.js +29 -0
- package/dist/cjs/components/Select/utils.js +2 -2
- 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 +3 -2
- package/dist/esm/components/DatePicker/DateRangePickerInput.js +3 -2
- package/dist/esm/components/ScrollableDigitSelector.js +55 -0
- package/dist/esm/components/Select/CustomMultiOption.js +36 -0
- package/dist/esm/components/Select/CustomOption.js +29 -0
- package/dist/esm/components/Select/MultiCheckAllOptions.js +1 -1
- package/dist/esm/components/Select/MultiGroupedOptions.js +2 -8
- package/dist/esm/components/Select/MultiOption.js +4 -13
- package/dist/esm/components/Select/MultiOptions.js +2 -3
- package/dist/esm/components/Select/Options.js +16 -11
- package/dist/esm/components/Select/index.js +5 -1
- package/dist/esm/components/Select/useMultiSelectOption.js +27 -0
- package/dist/esm/components/Select/utils.js +2 -2
- 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/Select/CustomMultiOption.d.ts +3 -0
- package/dist/types/components/Select/CustomOption.d.ts +3 -0
- package/dist/types/components/Select/MultiOption.d.ts +1 -1
- package/dist/types/components/Select/Options.d.ts +1 -1
- package/dist/types/components/Select/context.d.ts +1 -1
- package/dist/types/components/Select/index.d.ts +4 -2
- package/dist/types/components/Select/types.d.ts +10 -3
- package/dist/types/components/Select/useMultiSelectOption.d.ts +8 -0
- package/dist/types/components/Select/utils.d.ts +1 -1
- 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
|
|
|
@@ -66,7 +67,7 @@ const DatePickerInputWithPopover = (props) => {
|
|
|
66
67
|
)), /* @__PURE__ */ React.createElement(
|
|
67
68
|
index.Popover.Content,
|
|
68
69
|
{
|
|
69
|
-
className: "bg-inherit shadow-
|
|
70
|
+
className: "bg-inherit shadow-lg border-none",
|
|
70
71
|
initialFocus: -1
|
|
71
72
|
},
|
|
72
73
|
/* @__PURE__ */ React.createElement(Calendar.Calendar, { value, onChange: handleChangeCalendar })
|
|
@@ -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
|
|
|
@@ -79,7 +80,7 @@ const DateRangePickerInputWithPopover = (props) => {
|
|
|
79
80
|
)), /* @__PURE__ */ React.createElement(
|
|
80
81
|
index.Popover.Content,
|
|
81
82
|
{
|
|
82
|
-
className: "bg-inherit shadow-
|
|
83
|
+
className: "bg-inherit shadow-lg border-none",
|
|
83
84
|
initialFocus: -1
|
|
84
85
|
},
|
|
85
86
|
/* @__PURE__ */ React.createElement(RangeCalendar.RangeCalendar, { value, onChange: handleChangeCalendar })
|
|
@@ -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,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var cortexCore = require('@tecsinapse/cortex-core');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var useMultiSelectOption = require('./useMultiSelectOption.js');
|
|
6
|
+
|
|
7
|
+
const SelectCustomMultiOption = ({
|
|
8
|
+
onSelect,
|
|
9
|
+
option,
|
|
10
|
+
grouped = false,
|
|
11
|
+
children
|
|
12
|
+
}) => {
|
|
13
|
+
const { onClickOption, isChecked, inputRef } = useMultiSelectOption.useMultiSelectOption(
|
|
14
|
+
option,
|
|
15
|
+
onSelect
|
|
16
|
+
);
|
|
17
|
+
return /* @__PURE__ */ React.createElement(
|
|
18
|
+
"li",
|
|
19
|
+
{
|
|
20
|
+
onClick: onClickOption,
|
|
21
|
+
className: cortexCore.option({ grouped }),
|
|
22
|
+
role: "option"
|
|
23
|
+
},
|
|
24
|
+
/* @__PURE__ */ React.createElement(
|
|
25
|
+
"input",
|
|
26
|
+
{
|
|
27
|
+
type: "checkbox",
|
|
28
|
+
checked: isChecked,
|
|
29
|
+
className: cortexCore.checkbox({ className: "pointer-events-none" }),
|
|
30
|
+
onChange: () => false,
|
|
31
|
+
ref: inputRef
|
|
32
|
+
}
|
|
33
|
+
),
|
|
34
|
+
children
|
|
35
|
+
);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
exports.SelectCustomMultiOption = SelectCustomMultiOption;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var context = require('./context.js');
|
|
5
|
+
var cortexCore = require('@tecsinapse/cortex-core');
|
|
6
|
+
|
|
7
|
+
const SelectCustomOption = ({
|
|
8
|
+
option,
|
|
9
|
+
onSelectOption,
|
|
10
|
+
grouped = false,
|
|
11
|
+
children
|
|
12
|
+
}) => {
|
|
13
|
+
const { keyExtractor, value } = React.useContext(context.SelectContext);
|
|
14
|
+
return /* @__PURE__ */ React.createElement(
|
|
15
|
+
"li",
|
|
16
|
+
{
|
|
17
|
+
onClick: (e) => {
|
|
18
|
+
e.preventDefault();
|
|
19
|
+
onSelectOption(option);
|
|
20
|
+
},
|
|
21
|
+
className: cortexCore.option({
|
|
22
|
+
selected: value && keyExtractor(value) === keyExtractor(option),
|
|
23
|
+
grouped
|
|
24
|
+
}),
|
|
25
|
+
role: "option"
|
|
26
|
+
},
|
|
27
|
+
children
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
exports.SelectCustomOption = SelectCustomOption;
|
|
@@ -33,7 +33,7 @@ const SelectMultiCheckAllOptions = ({
|
|
|
33
33
|
updateSelected.splice(updateSelected.indexOf(it), 1);
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
|
-
onSelect(updateSelected);
|
|
36
|
+
onSelect?.(updateSelected);
|
|
37
37
|
}
|
|
38
38
|
}, [options, onSelect]);
|
|
39
39
|
return options?.length ? /* @__PURE__ */ React.createElement("div", { className: cortexCore.option(), onClick: checkAll }, /* @__PURE__ */ React.createElement(
|
|
@@ -14,7 +14,6 @@ var useSelectGroupedOptions = require('../../hooks/useSelectGroupedOptions.js');
|
|
|
14
14
|
var MultiOption = require('./MultiOption.js');
|
|
15
15
|
var SkeletonOptions = require('./SkeletonOptions.js');
|
|
16
16
|
var context = require('./context.js');
|
|
17
|
-
var utils = require('./utils.js');
|
|
18
17
|
|
|
19
18
|
const { groupedTitle, list } = cortexCore.selectVariants();
|
|
20
19
|
const SelectMultiGroupedOptions = ({
|
|
@@ -23,7 +22,7 @@ const SelectMultiGroupedOptions = ({
|
|
|
23
22
|
options,
|
|
24
23
|
children
|
|
25
24
|
}) => {
|
|
26
|
-
const {
|
|
25
|
+
const { keyExtractor } = React.useContext(context.SelectContext);
|
|
27
26
|
const { options: _options, isLoading } = useSelectGroupedOptions.useSelectGroupedOptions({ options });
|
|
28
27
|
const flattenMap = React.useMemo(
|
|
29
28
|
() => _options ? Array.from(_options?.values()).flatMap((value) => value) : [],
|
|
@@ -41,12 +40,7 @@ const SelectMultiGroupedOptions = ({
|
|
|
41
40
|
grouped: true,
|
|
42
41
|
option,
|
|
43
42
|
key: keyExtractor(option),
|
|
44
|
-
|
|
45
|
-
option2,
|
|
46
|
-
currentValue,
|
|
47
|
-
onSelect,
|
|
48
|
-
keyExtractor
|
|
49
|
-
)
|
|
43
|
+
onSelect
|
|
50
44
|
}
|
|
51
45
|
)))))
|
|
52
46
|
);
|
|
@@ -2,23 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
var cortexCore = require('@tecsinapse/cortex-core');
|
|
4
4
|
var React = require('react');
|
|
5
|
-
var
|
|
5
|
+
var useMultiSelectOption = require('./useMultiSelectOption.js');
|
|
6
6
|
|
|
7
7
|
const SelectMultiOption = ({
|
|
8
|
-
|
|
8
|
+
onSelect,
|
|
9
9
|
option,
|
|
10
10
|
grouped = false
|
|
11
11
|
}) => {
|
|
12
|
-
const {
|
|
13
|
-
const inputRef = React.useRef(null);
|
|
14
|
-
const isChecked = React.useMemo(
|
|
15
|
-
() => value?.length > 0 && value.find((it) => keyExtractor(it) === keyExtractor(option)) !== void 0,
|
|
16
|
-
[value, option]
|
|
17
|
-
);
|
|
18
|
-
const onClickOption = React.useCallback(() => {
|
|
19
|
-
onSelectOption(option);
|
|
20
|
-
inputRef.current?.click();
|
|
21
|
-
}, [onSelectOption, inputRef]);
|
|
12
|
+
const { onClickOption, isChecked, inputRef, labelExtractor } = useMultiSelectOption.useMultiSelectOption(option, onSelect);
|
|
22
13
|
return /* @__PURE__ */ React.createElement(
|
|
23
14
|
"li",
|
|
24
15
|
{
|
|
@@ -14,7 +14,6 @@ var useSelectOptions = require('../../hooks/useSelectOptions.js');
|
|
|
14
14
|
var MultiOption = require('./MultiOption.js');
|
|
15
15
|
var SkeletonOptions = require('./SkeletonOptions.js');
|
|
16
16
|
var context = require('./context.js');
|
|
17
|
-
var utils = require('./utils.js');
|
|
18
17
|
|
|
19
18
|
const { list } = cortexCore.selectVariants();
|
|
20
19
|
const SelectMultiOptions = ({
|
|
@@ -22,14 +21,14 @@ const SelectMultiOptions = ({
|
|
|
22
21
|
options,
|
|
23
22
|
children
|
|
24
23
|
}) => {
|
|
25
|
-
const { keyExtractor
|
|
24
|
+
const { keyExtractor } = React.useContext(context.SelectContext);
|
|
26
25
|
const { options: _options, isLoading } = useSelectOptions.useSelectOptions({ options });
|
|
27
26
|
return /* @__PURE__ */ React.createElement(context.SelectMultiOptionsContext.Provider, { value: { onSelect, options: _options } }, isLoading ? /* @__PURE__ */ React.createElement(SkeletonOptions.SkeletonOptions, null) : /* @__PURE__ */ React.createElement("ul", { role: "select", className: list() }, children, _options?.map((option) => /* @__PURE__ */ React.createElement(
|
|
28
27
|
MultiOption.SelectMultiOption,
|
|
29
28
|
{
|
|
30
29
|
option,
|
|
31
30
|
key: keyExtractor(option),
|
|
32
|
-
|
|
31
|
+
onSelect
|
|
33
32
|
}
|
|
34
33
|
))));
|
|
35
34
|
};
|
|
@@ -18,26 +18,31 @@ var context = require('./context.js');
|
|
|
18
18
|
const { list } = cortexCore.selectVariants();
|
|
19
19
|
const SelectOptions = ({
|
|
20
20
|
onSelect,
|
|
21
|
-
options
|
|
21
|
+
options,
|
|
22
|
+
children
|
|
22
23
|
}) => {
|
|
23
24
|
const { keyExtractor } = React.useContext(context.SelectContext);
|
|
24
25
|
const { setIsOpen } = Context.usePopoverContext();
|
|
25
26
|
const { options: _options, isLoading } = useSelectOptions.useSelectOptions({ options });
|
|
26
27
|
const handleSelect = React.useCallback(
|
|
27
28
|
(option) => {
|
|
28
|
-
onSelect(option);
|
|
29
|
+
onSelect?.(option);
|
|
29
30
|
setIsOpen?.(false);
|
|
30
31
|
},
|
|
31
32
|
[onSelect]
|
|
32
33
|
);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
const defaultOptions = React.useMemo(
|
|
35
|
+
() => _options?.map((option) => /* @__PURE__ */ React.createElement(
|
|
36
|
+
Option.SelectOption,
|
|
37
|
+
{
|
|
38
|
+
option,
|
|
39
|
+
key: keyExtractor(option),
|
|
40
|
+
onSelectOption: handleSelect
|
|
41
|
+
}
|
|
42
|
+
)) ?? [],
|
|
43
|
+
[_options, keyExtractor, handleSelect]
|
|
44
|
+
);
|
|
45
|
+
return isLoading ? /* @__PURE__ */ React.createElement(SkeletonOptions.SkeletonOptions, null) : /* @__PURE__ */ React.createElement("ul", { role: "select", className: list() }, children ?? defaultOptions);
|
|
41
46
|
};
|
|
42
47
|
|
|
43
48
|
exports.SelectOptions = SelectOptions;
|
|
@@ -10,6 +10,8 @@ var Options = require('./Options.js');
|
|
|
10
10
|
var Popover = require('./Popover.js');
|
|
11
11
|
var Root = require('./Root.js');
|
|
12
12
|
var Trigger = require('./Trigger.js');
|
|
13
|
+
var CustomOption = require('./CustomOption.js');
|
|
14
|
+
var CustomMultiOption = require('./CustomMultiOption.js');
|
|
13
15
|
|
|
14
16
|
const Select = {
|
|
15
17
|
Root: Root.SelectRoot,
|
|
@@ -21,7 +23,9 @@ const Select = {
|
|
|
21
23
|
MultiOptions: MultiOptions.SelectMultiOptions,
|
|
22
24
|
MultiGroupedOptions: MultiGroupedOptions.SelectMultiGroupedOptions,
|
|
23
25
|
MultiOption: MultiOption.SelectMultiOption,
|
|
24
|
-
MultiCheckAllOptions: MultiCheckAllOptions.SelectMultiCheckAllOptions
|
|
26
|
+
MultiCheckAllOptions: MultiCheckAllOptions.SelectMultiCheckAllOptions,
|
|
27
|
+
CustomOption: CustomOption.SelectCustomOption,
|
|
28
|
+
CustomMultiOption: CustomMultiOption.SelectCustomMultiOption
|
|
25
29
|
};
|
|
26
30
|
|
|
27
31
|
exports.Select = Select;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var context = require('./context.js');
|
|
5
|
+
var utils = require('./utils.js');
|
|
6
|
+
|
|
7
|
+
const useMultiSelectOption = (option, onSelect) => {
|
|
8
|
+
const { keyExtractor, value, labelExtractor } = React.useContext(context.SelectContext);
|
|
9
|
+
const inputRef = React.useRef(null);
|
|
10
|
+
const onSelectOption = (option2) => utils.handleSelectMulti(option2, value, keyExtractor, onSelect);
|
|
11
|
+
const isChecked = React.useMemo(
|
|
12
|
+
() => value?.length > 0 && value.find((it) => keyExtractor(it) === keyExtractor(option)) !== void 0,
|
|
13
|
+
[value, option]
|
|
14
|
+
);
|
|
15
|
+
const onClickOption = React.useCallback(() => {
|
|
16
|
+
onSelectOption(option);
|
|
17
|
+
inputRef.current?.click();
|
|
18
|
+
}, [onSelectOption, inputRef]);
|
|
19
|
+
return {
|
|
20
|
+
keyExtractor,
|
|
21
|
+
value,
|
|
22
|
+
isChecked,
|
|
23
|
+
onClickOption,
|
|
24
|
+
inputRef,
|
|
25
|
+
labelExtractor
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
exports.useMultiSelectOption = useMultiSelectOption;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const handleSelectMulti = (option, value,
|
|
3
|
+
const handleSelectMulti = (option, value, keyExtractor, onSelect) => {
|
|
4
4
|
const current = Array.from(value ?? []);
|
|
5
5
|
const indexOf = current.findIndex(
|
|
6
6
|
(it) => keyExtractor(it) === keyExtractor(option)
|
|
@@ -10,7 +10,7 @@ const handleSelectMulti = (option, value, onSelect, keyExtractor) => {
|
|
|
10
10
|
} else {
|
|
11
11
|
current.splice(indexOf, 1);
|
|
12
12
|
}
|
|
13
|
-
onSelect(current);
|
|
13
|
+
onSelect?.(current);
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
exports.handleSelectMulti = handleSelectMulti;
|
|
@@ -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-lg 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;
|