@tecsinapse/cortex-react 1.3.0-beta.0 → 1.3.0-beta.2
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/Calendar.js +1 -0
- package/dist/cjs/components/DateField.js +25 -0
- package/dist/cjs/components/DatePickerInput.js +48 -0
- package/dist/cjs/components/DatePickerInputBase.js +24 -0
- package/dist/cjs/components/DateRangePickerInput.js +62 -0
- package/dist/cjs/components/DateSegment.js +9 -1
- package/dist/cjs/components/Input.js +16 -16
- package/dist/cjs/components/RangeCalendar.js +24 -32
- package/dist/cjs/components/Select/GroupedOptions.js +32 -0
- package/dist/cjs/components/Select/Option.js +25 -0
- package/dist/cjs/components/Select/Options.js +29 -0
- package/dist/cjs/components/Select/Popover.js +13 -0
- package/dist/cjs/components/Select/Root.js +31 -0
- package/dist/cjs/components/Select/Trigger.js +28 -0
- package/dist/cjs/components/Select/context.js +10 -0
- package/dist/cjs/components/Select/index.js +19 -0
- package/dist/cjs/components/Table.js +2 -2
- package/dist/cjs/components/utils.js +14 -0
- package/dist/cjs/hooks/useCalendar.js +3 -6
- package/dist/cjs/hooks/useDatePickerInput.js +31 -0
- package/dist/cjs/hooks/useDateRangePickerInput.js +33 -0
- package/dist/cjs/hooks/useOutsideClickListener.js +22 -0
- package/dist/cjs/hooks/useRangeCalendar.js +36 -0
- package/dist/cjs/index.js +33 -17
- package/dist/cjs/service/SnackbarSonner.js +10 -3
- package/dist/cjs/styles/calendar-cell.js +3 -3
- package/dist/esm/components/Calendar.js +1 -0
- package/dist/esm/components/DateField.js +23 -0
- package/dist/esm/components/DatePickerInput.js +46 -0
- package/dist/esm/components/DatePickerInputBase.js +22 -0
- package/dist/esm/components/DateRangePickerInput.js +60 -0
- package/dist/esm/components/DateSegment.js +9 -1
- package/dist/esm/components/Input.js +12 -12
- package/dist/esm/components/RangeCalendar.js +24 -32
- package/dist/esm/components/Select/GroupedOptions.js +30 -0
- package/dist/esm/components/Select/Option.js +23 -0
- package/dist/esm/components/Select/Options.js +27 -0
- package/dist/esm/components/Select/Popover.js +11 -0
- package/dist/esm/components/Select/Root.js +29 -0
- package/dist/esm/components/Select/Trigger.js +26 -0
- package/dist/esm/components/Select/context.js +8 -0
- package/dist/esm/components/Select/index.js +17 -0
- package/dist/esm/components/Table.js +2 -2
- package/dist/esm/components/utils.js +13 -1
- package/dist/esm/hooks/useCalendar.js +4 -7
- package/dist/esm/hooks/useDatePickerInput.js +29 -0
- package/dist/esm/hooks/useDateRangePickerInput.js +31 -0
- package/dist/esm/hooks/useOutsideClickListener.js +20 -0
- package/dist/esm/hooks/useRangeCalendar.js +34 -0
- package/dist/esm/index.js +17 -7
- package/dist/esm/service/SnackbarSonner.js +10 -3
- package/dist/esm/styles/calendar-cell.js +3 -3
- package/dist/types/components/Calendar.d.ts +1 -1
- package/dist/types/components/DateField.d.ts +5 -0
- package/dist/types/components/DatePickerInput.d.ts +6 -0
- package/dist/types/components/DatePickerInputBase.d.ts +8 -0
- package/dist/types/components/DateRangePickerInput.d.ts +7 -0
- package/dist/types/components/Input.d.ts +5 -5
- package/dist/types/components/RangeCalendar.d.ts +1 -1
- package/dist/types/components/SearchInput.d.ts +3 -2
- package/dist/types/components/Select/GroupedOptions.d.ts +6 -0
- package/dist/types/components/Select/Option.d.ts +5 -0
- package/dist/types/components/Select/Options.d.ts +5 -0
- package/dist/types/components/Select/Popover.d.ts +5 -0
- package/dist/types/components/Select/Root.d.ts +8 -0
- package/dist/types/components/Select/Trigger.d.ts +5 -0
- package/dist/types/components/Select/context.d.ts +10 -0
- package/dist/types/components/Select/index.d.ts +8 -0
- package/dist/types/components/index.d.ts +5 -2
- package/dist/types/components/utils.d.ts +3 -0
- package/dist/types/hooks/index.d.ts +4 -0
- package/dist/types/hooks/useCalendar.d.ts +1 -1
- package/dist/types/hooks/useDatePickerInput.d.ts +10 -0
- package/dist/types/hooks/useDateRangePickerInput.d.ts +12 -0
- package/dist/types/hooks/useOutsideClickListener.d.ts +7 -0
- package/dist/types/hooks/useRangeCalendar.d.ts +12 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/tests/DateField.test.d.ts +1 -0
- package/dist/types/tests/DatePickerInput.test.d.ts +1 -0
- package/dist/types/tests/DatePickerInputBase.test.d.ts +1 -0
- package/dist/types/tests/DateRangePickerInput.test.d.ts +1 -0
- package/dist/types/tests/RangeCalendar.test.d.ts +1 -0
- package/dist/types/tests/useOutsideClickListener.test.d.ts +1 -0
- package/package.json +6 -4
- package/dist/cjs/components/SearchInput.js +0 -82
- package/dist/cjs/components/Select.js +0 -101
- package/dist/esm/components/SearchInput.js +0 -80
- package/dist/esm/components/Select.js +0 -96
- package/dist/types/components/Select.d.ts +0 -27
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
|
|
5
|
+
const useOutsideClickListener = ({
|
|
6
|
+
ref,
|
|
7
|
+
onClickOutside
|
|
8
|
+
}) => {
|
|
9
|
+
const handleClickOutside = React.useCallback((event) => {
|
|
10
|
+
if (ref.current && !ref.current.contains(event.target)) {
|
|
11
|
+
onClickOutside?.();
|
|
12
|
+
}
|
|
13
|
+
}, []);
|
|
14
|
+
React.useEffect(() => {
|
|
15
|
+
document.addEventListener("click", handleClickOutside, true);
|
|
16
|
+
return () => {
|
|
17
|
+
document.removeEventListener("click", handleClickOutside, true);
|
|
18
|
+
};
|
|
19
|
+
}, [handleClickOutside]);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
exports.useOutsideClickListener = useOutsideClickListener;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var date = require('@internationalized/date');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var reactAria = require('react-aria');
|
|
6
|
+
var reactStately = require('react-stately');
|
|
7
|
+
var utils = require('../components/utils.js');
|
|
8
|
+
|
|
9
|
+
const useRangeCalendar = ({
|
|
10
|
+
value,
|
|
11
|
+
onChange
|
|
12
|
+
}) => {
|
|
13
|
+
const { locale } = reactAria.useLocale();
|
|
14
|
+
const state = reactStately.useRangeCalendarState({
|
|
15
|
+
locale,
|
|
16
|
+
createCalendar: date.createCalendar,
|
|
17
|
+
defaultValue: {
|
|
18
|
+
start: utils.dateToCalendarDate(value?.start),
|
|
19
|
+
end: utils.dateToCalendarDate(value?.end)
|
|
20
|
+
},
|
|
21
|
+
onChange: (value2) => onChange({
|
|
22
|
+
start: utils.calendarDateToDate(value2.start),
|
|
23
|
+
end: utils.calendarDateToDate(value2.end)
|
|
24
|
+
})
|
|
25
|
+
});
|
|
26
|
+
const ref = React.useRef(null);
|
|
27
|
+
const { calendarProps, title } = reactAria.useRangeCalendar({}, state, ref);
|
|
28
|
+
return {
|
|
29
|
+
calendarProps,
|
|
30
|
+
title,
|
|
31
|
+
state,
|
|
32
|
+
ref
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.useRangeCalendar = useRangeCalendar;
|
package/dist/cjs/index.js
CHANGED
|
@@ -7,6 +7,8 @@ var Breadcrumbs = require('./components/Breadcrumbs.js');
|
|
|
7
7
|
var Button = require('./components/Button.js');
|
|
8
8
|
var Calendar = require('./components/Calendar.js');
|
|
9
9
|
var Card = require('./components/Card.js');
|
|
10
|
+
var DatePickerInput = require('./components/DatePickerInput.js');
|
|
11
|
+
var DateRangePickerInput = require('./components/DateRangePickerInput.js');
|
|
10
12
|
var DefaultSnack = require('./components/DefaultSnack.js');
|
|
11
13
|
var Drawer = require('./components/Drawer.js');
|
|
12
14
|
var GroupButton = require('./components/GroupButton.js');
|
|
@@ -15,18 +17,26 @@ var Input = require('./components/Input.js');
|
|
|
15
17
|
var Modal = require('./components/Modal.js');
|
|
16
18
|
var ProgressBar = require('./components/ProgressBar.js');
|
|
17
19
|
var RangeCalendar = require('./components/RangeCalendar.js');
|
|
18
|
-
|
|
20
|
+
require('react');
|
|
21
|
+
require('react-icons/ai');
|
|
22
|
+
require('react-icons/io5');
|
|
23
|
+
require('tailwind-merge');
|
|
24
|
+
var useCalendar = require('./hooks/useCalendar.js');
|
|
25
|
+
var useCalendarCell = require('./hooks/useCalendarCell.js');
|
|
26
|
+
var useCalendarGrid = require('./hooks/useCalendarGrid.js');
|
|
27
|
+
var useDatePickerInput = require('./hooks/useDatePickerInput.js');
|
|
28
|
+
var useDateRangePickerInput = require('./hooks/useDateRangePickerInput.js');
|
|
29
|
+
var useDebouncedState = require('./hooks/useDebouncedState.js');
|
|
30
|
+
var useOutsideClickListener = require('./hooks/useOutsideClickListener.js');
|
|
31
|
+
var useRangeCalendar = require('./hooks/useRangeCalendar.js');
|
|
32
|
+
var index = require('./components/Select/index.js');
|
|
19
33
|
var Skeleton = require('./components/Skeleton.js');
|
|
20
34
|
var Table = require('./components/Table.js');
|
|
21
35
|
var Tag = require('./components/Tag.js');
|
|
22
36
|
var TextArea = require('./components/TextArea.js');
|
|
23
|
-
var Toggle = require('./components/Toggle.js');
|
|
24
37
|
var TimeFieldInput = require('./components/TimeFieldInput.js');
|
|
38
|
+
var Toggle = require('./components/Toggle.js');
|
|
25
39
|
var SnackbarSonner = require('./service/SnackbarSonner.js');
|
|
26
|
-
var useCalendar = require('./hooks/useCalendar.js');
|
|
27
|
-
var useCalendarCell = require('./hooks/useCalendarCell.js');
|
|
28
|
-
var useCalendarGrid = require('./hooks/useCalendarGrid.js');
|
|
29
|
-
var useDebouncedState = require('./hooks/useDebouncedState.js');
|
|
30
40
|
|
|
31
41
|
|
|
32
42
|
|
|
@@ -38,20 +48,30 @@ exports.Breadcrumbs = Breadcrumbs.Breadcrumbs;
|
|
|
38
48
|
exports.Button = Button.Button;
|
|
39
49
|
exports.Calendar = Calendar.Calendar;
|
|
40
50
|
exports.Card = Card.Card;
|
|
51
|
+
exports.DatePickerInput = DatePickerInput.DatePickerInput;
|
|
52
|
+
exports.DateRangePickerInput = DateRangePickerInput.DateRangePickerInput;
|
|
41
53
|
exports.DefaultSnack = DefaultSnack.DefaultSnack;
|
|
42
54
|
exports.Drawer = Drawer.Drawer;
|
|
43
55
|
exports.GroupButton = GroupButton.GroupButton;
|
|
44
56
|
exports.Hint = Hint.Hint;
|
|
45
|
-
exports.Box = Input.Box;
|
|
46
|
-
exports.Face = Input.Face;
|
|
47
57
|
exports.Input = Input.Input;
|
|
48
|
-
exports.
|
|
49
|
-
exports.
|
|
50
|
-
exports.
|
|
58
|
+
exports.InputBox = Input.InputBox;
|
|
59
|
+
exports.InputFace = Input.InputFace;
|
|
60
|
+
exports.InputLeft = Input.InputLeft;
|
|
61
|
+
exports.InputRight = Input.InputRight;
|
|
62
|
+
exports.InputRoot = Input.InputRoot;
|
|
51
63
|
exports.Modal = Modal.Modal;
|
|
52
64
|
exports.ProgressBar = ProgressBar.ProgressBar;
|
|
53
65
|
exports.RangeCalendar = RangeCalendar.RangeCalendar;
|
|
54
|
-
exports.
|
|
66
|
+
exports.useCalendar = useCalendar.useCalendar;
|
|
67
|
+
exports.useCalendarCell = useCalendarCell.useCalendarCell;
|
|
68
|
+
exports.useCalendarGrid = useCalendarGrid.useCalendarGrid;
|
|
69
|
+
exports.useDatePickerInput = useDatePickerInput.useDatePickerInput;
|
|
70
|
+
exports.useDateRangePickerInput = useDateRangePickerInput.useDateRangePickerInput;
|
|
71
|
+
exports.useDebouncedState = useDebouncedState.useDebouncedState;
|
|
72
|
+
exports.useOutsideClickListener = useOutsideClickListener.useOutsideClickListener;
|
|
73
|
+
exports.useRangeCalendar = useRangeCalendar.useRangeCalendar;
|
|
74
|
+
exports.Select = index.Select;
|
|
55
75
|
exports.Skeleton = Skeleton.Skeleton;
|
|
56
76
|
exports.TCell = Table.TCell;
|
|
57
77
|
exports.TFoot = Table.TFoot;
|
|
@@ -63,10 +83,6 @@ exports.Table = Table.Table;
|
|
|
63
83
|
exports.Td = Table.Td;
|
|
64
84
|
exports.Tag = Tag.Tag;
|
|
65
85
|
exports.TextArea = TextArea.TextArea;
|
|
66
|
-
exports.Toggle = Toggle.Toggle;
|
|
67
86
|
exports.TimeFieldInput = TimeFieldInput.TimeFieldInput;
|
|
87
|
+
exports.Toggle = Toggle.Toggle;
|
|
68
88
|
exports.SnackbarSonner = SnackbarSonner.SnackbarSonner;
|
|
69
|
-
exports.useCalendar = useCalendar.useCalendar;
|
|
70
|
-
exports.useCalendarCell = useCalendarCell.useCalendarCell;
|
|
71
|
-
exports.useCalendarGrid = useCalendarGrid.useCalendarGrid;
|
|
72
|
-
exports.useDebouncedState = useDebouncedState.useDebouncedState;
|
|
@@ -3,26 +3,33 @@
|
|
|
3
3
|
var sonner = require('sonner');
|
|
4
4
|
var React = require('react');
|
|
5
5
|
require('clsx');
|
|
6
|
+
require('@internationalized/date');
|
|
6
7
|
require('../components/Badge.js');
|
|
7
8
|
require('../components/BaseSnackbar.js');
|
|
8
9
|
require('react-icons/md');
|
|
9
10
|
require('../components/Card.js');
|
|
10
11
|
require('../components/Button.js');
|
|
11
|
-
require('@internationalized/date');
|
|
12
12
|
require('react-aria');
|
|
13
13
|
require('react-stately');
|
|
14
14
|
require('../components/CalendarCell.js');
|
|
15
15
|
require('@tecsinapse/cortex-core');
|
|
16
16
|
require('react-icons/fa');
|
|
17
|
+
require('react-icons/lia');
|
|
18
|
+
require('../components/Input.js');
|
|
17
19
|
var DefaultSnack = require('../components/DefaultSnack.js');
|
|
18
20
|
require('../components/GroupButton.js');
|
|
19
21
|
require('../components/Hint.js');
|
|
20
|
-
require('../components/Input.js');
|
|
21
22
|
require('../components/Modal.js');
|
|
22
23
|
require('../styles/calendar-cell.js');
|
|
23
24
|
require('../styles/groupButton.js');
|
|
24
25
|
require('../styles/progressBar.js');
|
|
25
|
-
require('
|
|
26
|
+
require('react-icons/ai');
|
|
27
|
+
require('react-icons/io5');
|
|
28
|
+
require('tailwind-merge');
|
|
29
|
+
require('../components/Select/GroupedOptions.js');
|
|
30
|
+
require('../components/Select/context.js');
|
|
31
|
+
require('../components/Select/Popover.js');
|
|
32
|
+
require('../components/Select/Trigger.js');
|
|
26
33
|
require('../components/Tag.js');
|
|
27
34
|
require('../components/TextArea.js');
|
|
28
35
|
require('../components/Toggle.js');
|
|
@@ -4,13 +4,13 @@ var tailwindVariants = require('tailwind-variants');
|
|
|
4
4
|
|
|
5
5
|
const calendarCell = tailwindVariants.tv({
|
|
6
6
|
slots: {
|
|
7
|
-
cell: "text-center rounded-mili text-black",
|
|
7
|
+
cell: "text-center rounded-mili text-black hover:bg-primary-light",
|
|
8
8
|
button: "flex aspect-square items-center justify-center"
|
|
9
9
|
},
|
|
10
10
|
variants: {
|
|
11
11
|
isSelected: {
|
|
12
12
|
true: {
|
|
13
|
-
cell: "bg-primary-medium text-white"
|
|
13
|
+
cell: "bg-primary-medium text-white hover:bg-primary-medium"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
isSelectionStart: {
|
|
@@ -30,7 +30,7 @@ const calendarCell = tailwindVariants.tv({
|
|
|
30
30
|
},
|
|
31
31
|
isOutsideVisibleRange: {
|
|
32
32
|
true: {
|
|
33
|
-
cell: "text-secondary-light cursor-default",
|
|
33
|
+
cell: "text-secondary-light cursor-default hover:bg-white-500",
|
|
34
34
|
button: "cursor-default"
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -2,6 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { useCalendar } from '../hooks/useCalendar.js';
|
|
3
3
|
import '@internationalized/date';
|
|
4
4
|
import 'react-aria';
|
|
5
|
+
import 'react-stately';
|
|
5
6
|
import { CalendarGrid } from './CalendarGrid.js';
|
|
6
7
|
import { CalendarHeader } from './CalendarHeader.js';
|
|
7
8
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createCalendar } from '@internationalized/date';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { useLocale, useDateField } from 'react-aria';
|
|
4
|
+
import { useDateFieldState } from 'react-stately';
|
|
5
|
+
import { DateSegment } from './DateSegment.js';
|
|
6
|
+
|
|
7
|
+
const DateField = (props) => {
|
|
8
|
+
const { locale } = useLocale();
|
|
9
|
+
const state = useDateFieldState({
|
|
10
|
+
...props,
|
|
11
|
+
createCalendar,
|
|
12
|
+
locale
|
|
13
|
+
});
|
|
14
|
+
const ref = React.useRef(null);
|
|
15
|
+
const { fieldProps } = useDateField(
|
|
16
|
+
{ "aria-label": "date-field" },
|
|
17
|
+
state,
|
|
18
|
+
ref
|
|
19
|
+
);
|
|
20
|
+
return /* @__PURE__ */ React.createElement("div", { ...fieldProps, ref, className: "flex flex-row" }, state.segments.map((segment, i) => /* @__PURE__ */ React.createElement(DateSegment, { key: i, segment, state })));
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { DateField };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import '@internationalized/date';
|
|
3
|
+
import 'react-aria';
|
|
4
|
+
import 'react-stately';
|
|
5
|
+
import { dateToCalendarDate } from './utils.js';
|
|
6
|
+
import { useDatePickerInput } from '../hooks/useDatePickerInput.js';
|
|
7
|
+
import { Calendar } from './Calendar.js';
|
|
8
|
+
import { DateField } from './DateField.js';
|
|
9
|
+
import { DatePickerInputBase } from './DatePickerInputBase.js';
|
|
10
|
+
|
|
11
|
+
const DatePickerInput = (props) => {
|
|
12
|
+
const { onChange, value, label, variants } = props;
|
|
13
|
+
const { fieldProps, state, ref } = useDatePickerInput({ value, onChange });
|
|
14
|
+
return /* @__PURE__ */ React.createElement("div", { "data-testid": "date-picker-input" }, /* @__PURE__ */ React.createElement(
|
|
15
|
+
DatePickerInputBase,
|
|
16
|
+
{
|
|
17
|
+
onClickCalendar: () => state.isOpen ? state.close() : state.open(),
|
|
18
|
+
variants: {
|
|
19
|
+
...variants,
|
|
20
|
+
intent: state.isInvalid ? "error" : variants?.intent
|
|
21
|
+
},
|
|
22
|
+
label
|
|
23
|
+
},
|
|
24
|
+
/* @__PURE__ */ React.createElement("div", { ref }, /* @__PURE__ */ React.createElement(
|
|
25
|
+
DateField,
|
|
26
|
+
{
|
|
27
|
+
...fieldProps,
|
|
28
|
+
onChange: (value2) => {
|
|
29
|
+
state.setDateValue(value2);
|
|
30
|
+
state.close();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
))
|
|
34
|
+
), state.isOpen ? /* @__PURE__ */ React.createElement("div", { className: "absolute" }, /* @__PURE__ */ React.createElement(
|
|
35
|
+
Calendar,
|
|
36
|
+
{
|
|
37
|
+
value,
|
|
38
|
+
onChange: (value2) => {
|
|
39
|
+
state.setDateValue(dateToCalendarDate(value2));
|
|
40
|
+
state.close();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
)) : /* @__PURE__ */ React.createElement(React.Fragment, null));
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export { DatePickerInput };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { labelStyle, inputBox } from '@tecsinapse/cortex-core';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { LiaCalendar } from 'react-icons/lia';
|
|
4
|
+
import { Input } from './Input.js';
|
|
5
|
+
|
|
6
|
+
const DatePickerInputBase = ({
|
|
7
|
+
children,
|
|
8
|
+
variants,
|
|
9
|
+
label,
|
|
10
|
+
onClickCalendar
|
|
11
|
+
}) => {
|
|
12
|
+
return /* @__PURE__ */ React.createElement(Input.Face, { variants, "data-testid": "date-picker-input-base" }, /* @__PURE__ */ React.createElement("span", { className: labelStyle({}) }, label), /* @__PURE__ */ React.createElement("div", { className: inputBox("", label) }, children), /* @__PURE__ */ React.createElement(Input.Right, { className: "" }, /* @__PURE__ */ React.createElement(
|
|
13
|
+
LiaCalendar,
|
|
14
|
+
{
|
|
15
|
+
className: "cursor-pointer mt-centi",
|
|
16
|
+
onClick: onClickCalendar,
|
|
17
|
+
"data-testid": "date-picker-input-base-calendar"
|
|
18
|
+
}
|
|
19
|
+
)));
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { DatePickerInputBase };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import '@internationalized/date';
|
|
3
|
+
import 'react-aria';
|
|
4
|
+
import 'react-stately';
|
|
5
|
+
import { dateToCalendarDate } from './utils.js';
|
|
6
|
+
import { useDateRangePickerInput } from '../hooks/useDateRangePickerInput.js';
|
|
7
|
+
import { DateField } from './DateField.js';
|
|
8
|
+
import { DatePickerInputBase } from './DatePickerInputBase.js';
|
|
9
|
+
import { RangeCalendar } from './RangeCalendar.js';
|
|
10
|
+
|
|
11
|
+
const DateRangePickerInput = (props) => {
|
|
12
|
+
const { onChange, value, label, variants } = props;
|
|
13
|
+
const { endFieldProps, startFieldProps, ref, state } = useDateRangePickerInput({ value, onChange });
|
|
14
|
+
return /* @__PURE__ */ React.createElement("div", { "data-testid": "date-range-picker-input" }, /* @__PURE__ */ React.createElement(
|
|
15
|
+
DatePickerInputBase,
|
|
16
|
+
{
|
|
17
|
+
onClickCalendar: () => state.isOpen ? state.close() : state.open(),
|
|
18
|
+
variants: {
|
|
19
|
+
...variants,
|
|
20
|
+
intent: state.isInvalid ? "error" : variants?.intent
|
|
21
|
+
},
|
|
22
|
+
label
|
|
23
|
+
},
|
|
24
|
+
/* @__PURE__ */ React.createElement("div", { ref, className: "flex flex-row gap-x-micro items-center" }, /* @__PURE__ */ React.createElement(
|
|
25
|
+
DateField,
|
|
26
|
+
{
|
|
27
|
+
...startFieldProps,
|
|
28
|
+
value: dateToCalendarDate(value?.start),
|
|
29
|
+
onChange: (value2) => {
|
|
30
|
+
state.setDate("start", value2);
|
|
31
|
+
state.close();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
), /* @__PURE__ */ React.createElement("span", null, "-"), /* @__PURE__ */ React.createElement(
|
|
35
|
+
DateField,
|
|
36
|
+
{
|
|
37
|
+
...endFieldProps,
|
|
38
|
+
value: dateToCalendarDate(value?.end),
|
|
39
|
+
onChange: (value2) => {
|
|
40
|
+
state.setDate("end", value2);
|
|
41
|
+
state.close();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
))
|
|
45
|
+
), state.isOpen ? /* @__PURE__ */ React.createElement("div", { className: "absolute" }, /* @__PURE__ */ React.createElement(
|
|
46
|
+
RangeCalendar,
|
|
47
|
+
{
|
|
48
|
+
value,
|
|
49
|
+
onChange: (value2) => {
|
|
50
|
+
state.setDateRange({
|
|
51
|
+
start: dateToCalendarDate(value2.start),
|
|
52
|
+
end: dateToCalendarDate(value2.end)
|
|
53
|
+
});
|
|
54
|
+
state.close();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
)) : /* @__PURE__ */ React.createElement(React.Fragment, null));
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export { DateRangePickerInput };
|
|
@@ -4,7 +4,15 @@ import { useDateSegment } from 'react-aria';
|
|
|
4
4
|
const DateSegment = ({ segment, state }) => {
|
|
5
5
|
const ref = React.useRef(null);
|
|
6
6
|
const { segmentProps } = useDateSegment(segment, state, ref);
|
|
7
|
-
return /* @__PURE__ */ React.createElement(
|
|
7
|
+
return /* @__PURE__ */ React.createElement(
|
|
8
|
+
"div",
|
|
9
|
+
{
|
|
10
|
+
...segmentProps,
|
|
11
|
+
ref,
|
|
12
|
+
className: "focus:outline-none focus:bg-secondary-light"
|
|
13
|
+
},
|
|
14
|
+
segment.text
|
|
15
|
+
);
|
|
8
16
|
};
|
|
9
17
|
|
|
10
18
|
export { DateSegment };
|
|
@@ -7,7 +7,7 @@ const getValidChildren = (children) => {
|
|
|
7
7
|
(el) => React.isValidElement(el)
|
|
8
8
|
);
|
|
9
9
|
};
|
|
10
|
-
const
|
|
10
|
+
const InputBox = React.forwardRef(
|
|
11
11
|
({ id, name, variants, label, placeholder, className, ...rest }, ref) => {
|
|
12
12
|
return /* @__PURE__ */ React.createElement("div", { className: "flex w-full flex-col" }, /* @__PURE__ */ React.createElement(
|
|
13
13
|
"input",
|
|
@@ -31,7 +31,7 @@ const Box = React.forwardRef(
|
|
|
31
31
|
));
|
|
32
32
|
}
|
|
33
33
|
);
|
|
34
|
-
const
|
|
34
|
+
const InputFace = React.forwardRef(
|
|
35
35
|
({ children, variants, className, ...rest }, ref) => {
|
|
36
36
|
const clones = getValidChildren(children).map((el) => {
|
|
37
37
|
return React.cloneElement(el, { ...el.props, variants });
|
|
@@ -48,27 +48,27 @@ const Face = React.forwardRef(
|
|
|
48
48
|
);
|
|
49
49
|
}
|
|
50
50
|
);
|
|
51
|
-
const
|
|
51
|
+
const InputRoot = React.forwardRef(
|
|
52
52
|
({ variants, className, ...rest }, ref) => {
|
|
53
|
-
return /* @__PURE__ */ React.createElement(
|
|
53
|
+
return /* @__PURE__ */ React.createElement(InputFace, { variants, className }, /* @__PURE__ */ React.createElement(InputBox, { ...rest, ref }));
|
|
54
54
|
}
|
|
55
55
|
);
|
|
56
|
-
const
|
|
56
|
+
const InputLeft = React.forwardRef(
|
|
57
57
|
({ children, className, ...rest }, ref) => {
|
|
58
58
|
return /* @__PURE__ */ React.createElement("div", { className: clsx(className, "mr-2.5"), ...rest, ref }, children);
|
|
59
59
|
}
|
|
60
60
|
);
|
|
61
|
-
const
|
|
61
|
+
const InputRight = React.forwardRef(
|
|
62
62
|
({ children, className, ...rest }, ref) => {
|
|
63
63
|
return /* @__PURE__ */ React.createElement("div", { className: clsx(className, "ml-2.5"), ...rest, ref }, children);
|
|
64
64
|
}
|
|
65
65
|
);
|
|
66
66
|
const Input = {
|
|
67
|
-
Root,
|
|
68
|
-
Face,
|
|
69
|
-
Box,
|
|
70
|
-
Left,
|
|
71
|
-
Right
|
|
67
|
+
Root: InputRoot,
|
|
68
|
+
Face: InputFace,
|
|
69
|
+
Box: InputBox,
|
|
70
|
+
Left: InputLeft,
|
|
71
|
+
Right: InputRight
|
|
72
72
|
};
|
|
73
73
|
|
|
74
|
-
export {
|
|
74
|
+
export { Input, InputBox, InputFace, InputLeft, InputRight, InputRoot };
|
|
@@ -1,42 +1,34 @@
|
|
|
1
|
-
import { createCalendar, CalendarDate, getLocalTimeZone } from '@internationalized/date';
|
|
2
1
|
import React from 'react';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
2
|
+
import '@internationalized/date';
|
|
3
|
+
import 'react-aria';
|
|
4
|
+
import 'react-stately';
|
|
5
|
+
import { useRangeCalendar } from '../hooks/useRangeCalendar.js';
|
|
5
6
|
import { CalendarGrid } from './CalendarGrid.js';
|
|
6
7
|
import { CalendarHeader } from './CalendarHeader.js';
|
|
7
8
|
|
|
8
9
|
const RangeCalendar = ({ value, onChange }) => {
|
|
9
|
-
const {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
createCalendar,
|
|
13
|
-
defaultValue: {
|
|
14
|
-
start: new CalendarDate(
|
|
15
|
-
value.start.getFullYear(),
|
|
16
|
-
value.start.getMonth(),
|
|
17
|
-
value.start.getDate()
|
|
18
|
-
),
|
|
19
|
-
end: new CalendarDate(
|
|
20
|
-
value.end.getFullYear(),
|
|
21
|
-
value.end.getMonth(),
|
|
22
|
-
value.end.getDate()
|
|
23
|
-
)
|
|
24
|
-
},
|
|
25
|
-
onChange: (value2) => onChange({
|
|
26
|
-
start: value2.start.toDate(getLocalTimeZone()),
|
|
27
|
-
end: value2.end.toDate(getLocalTimeZone())
|
|
28
|
-
})
|
|
10
|
+
const { calendarProps, state, title, ref } = useRangeCalendar({
|
|
11
|
+
value,
|
|
12
|
+
onChange
|
|
29
13
|
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return /* @__PURE__ */ React.createElement("div", { ...calendarProps, className: "calendar", ref }, /* @__PURE__ */ React.createElement(
|
|
33
|
-
CalendarHeader,
|
|
14
|
+
return /* @__PURE__ */ React.createElement(
|
|
15
|
+
"div",
|
|
34
16
|
{
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
17
|
+
...calendarProps,
|
|
18
|
+
className: "calendar",
|
|
19
|
+
ref,
|
|
20
|
+
"data-testid": "calendar-range-div"
|
|
21
|
+
},
|
|
22
|
+
/* @__PURE__ */ React.createElement(
|
|
23
|
+
CalendarHeader,
|
|
24
|
+
{
|
|
25
|
+
onClickPrevButton: () => state.focusPreviousPage(),
|
|
26
|
+
onClickNextButton: () => state.focusNextPage(),
|
|
27
|
+
title
|
|
28
|
+
}
|
|
29
|
+
),
|
|
30
|
+
/* @__PURE__ */ React.createElement(CalendarGrid, { state })
|
|
31
|
+
);
|
|
40
32
|
};
|
|
41
33
|
|
|
42
34
|
export { RangeCalendar };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { selectVariants } from '@tecsinapse/cortex-core';
|
|
2
|
+
import React, { useContext, useCallback } from 'react';
|
|
3
|
+
import { Select } from './index.js';
|
|
4
|
+
import { SelectContext } from './context.js';
|
|
5
|
+
|
|
6
|
+
const { groupedTitle, containerGrouped } = selectVariants();
|
|
7
|
+
const SelectGroupedOptions = ({
|
|
8
|
+
onSelect,
|
|
9
|
+
groupedLabelExtractor,
|
|
10
|
+
options
|
|
11
|
+
}) => {
|
|
12
|
+
const { setOpen, keyExtractor } = useContext(SelectContext);
|
|
13
|
+
const handleSelect = useCallback(
|
|
14
|
+
(option) => {
|
|
15
|
+
onSelect(option);
|
|
16
|
+
setOpen?.(false);
|
|
17
|
+
},
|
|
18
|
+
[onSelect]
|
|
19
|
+
);
|
|
20
|
+
return /* @__PURE__ */ React.createElement("ul", { role: "select", className: containerGrouped() }, [...options ?? []].map(([key, value]) => /* @__PURE__ */ React.createElement("div", { key }, /* @__PURE__ */ React.createElement("span", { className: groupedTitle() }, groupedLabelExtractor?.(key)), value.map((option) => /* @__PURE__ */ React.createElement(
|
|
21
|
+
Select.Option,
|
|
22
|
+
{
|
|
23
|
+
option,
|
|
24
|
+
key: keyExtractor(option),
|
|
25
|
+
onSelectOption: handleSelect
|
|
26
|
+
}
|
|
27
|
+
)))));
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export { SelectGroupedOptions };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { option } from '@tecsinapse/cortex-core';
|
|
2
|
+
import React, { useContext } from 'react';
|
|
3
|
+
import { SelectContext } from './context.js';
|
|
4
|
+
|
|
5
|
+
const SelectOption = ({
|
|
6
|
+
onSelectOption,
|
|
7
|
+
option: option$1
|
|
8
|
+
}) => {
|
|
9
|
+
const { keyExtractor, labelExtractor, value } = useContext(SelectContext);
|
|
10
|
+
return /* @__PURE__ */ React.createElement(
|
|
11
|
+
"li",
|
|
12
|
+
{
|
|
13
|
+
onClick: () => onSelectOption(option$1),
|
|
14
|
+
className: option({
|
|
15
|
+
selected: value && keyExtractor(value) === keyExtractor(option$1)
|
|
16
|
+
}),
|
|
17
|
+
role: "option"
|
|
18
|
+
},
|
|
19
|
+
labelExtractor(option$1)
|
|
20
|
+
);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { SelectOption };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React, { useContext, useCallback } from 'react';
|
|
2
|
+
import { Select } from './index.js';
|
|
3
|
+
import { SelectContext } from './context.js';
|
|
4
|
+
|
|
5
|
+
const SelectOptions = ({
|
|
6
|
+
onSelect,
|
|
7
|
+
options
|
|
8
|
+
}) => {
|
|
9
|
+
const { setOpen, keyExtractor } = useContext(SelectContext);
|
|
10
|
+
const handleSelect = useCallback(
|
|
11
|
+
(option) => {
|
|
12
|
+
onSelect(option);
|
|
13
|
+
setOpen?.(false);
|
|
14
|
+
},
|
|
15
|
+
[onSelect]
|
|
16
|
+
);
|
|
17
|
+
return /* @__PURE__ */ React.createElement("ul", { role: "select" }, (options ?? []).map((option) => /* @__PURE__ */ React.createElement(
|
|
18
|
+
Select.Option,
|
|
19
|
+
{
|
|
20
|
+
option,
|
|
21
|
+
key: keyExtractor(option),
|
|
22
|
+
onSelectOption: handleSelect
|
|
23
|
+
}
|
|
24
|
+
)));
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export { SelectOptions };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { selectVariants } from '@tecsinapse/cortex-core';
|
|
2
|
+
import React, { useContext } from 'react';
|
|
3
|
+
import { SelectContext } from './context.js';
|
|
4
|
+
|
|
5
|
+
const { dropdown } = selectVariants();
|
|
6
|
+
const SelectPopover = ({ children }) => {
|
|
7
|
+
const { open } = useContext(SelectContext);
|
|
8
|
+
return /* @__PURE__ */ React.createElement("div", { className: dropdown({ open }), "data-testid": "select-popover" }, children);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { SelectPopover };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React, { useState, useRef } from 'react';
|
|
2
|
+
import '@internationalized/date';
|
|
3
|
+
import 'react-aria';
|
|
4
|
+
import 'react-stately';
|
|
5
|
+
import { useOutsideClickListener } from '../../hooks/useOutsideClickListener.js';
|
|
6
|
+
import { SelectContext } from './context.js';
|
|
7
|
+
|
|
8
|
+
const SelectRoot = ({
|
|
9
|
+
children,
|
|
10
|
+
value,
|
|
11
|
+
keyExtractor,
|
|
12
|
+
labelExtractor
|
|
13
|
+
}) => {
|
|
14
|
+
const [open, setOpen] = useState(false);
|
|
15
|
+
const ref = useRef(null);
|
|
16
|
+
useOutsideClickListener({
|
|
17
|
+
ref,
|
|
18
|
+
onClickOutside: () => setOpen?.(false)
|
|
19
|
+
});
|
|
20
|
+
return /* @__PURE__ */ React.createElement(
|
|
21
|
+
SelectContext.Provider,
|
|
22
|
+
{
|
|
23
|
+
value: { value, open, setOpen, keyExtractor, labelExtractor }
|
|
24
|
+
},
|
|
25
|
+
/* @__PURE__ */ React.createElement("div", { className: "w-full relative bg-white", ref }, children)
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { SelectRoot };
|