@ttoss/components 2.14.20 → 2.14.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.
- package/dist/Accordion/index.d.mts +157 -0
- package/dist/Accordion/index.mjs +175 -0
- package/dist/DatePicker/index.d.mts +26 -0
- package/dist/DatePicker/index.mjs +339 -0
- package/dist/Drawer/index.d.mts +17 -0
- package/dist/{esm/Drawer/index.js → Drawer/index.mjs} +21 -14
- package/dist/EnhancedTitle/{index.d.ts → index.d.mts} +57 -47
- package/dist/EnhancedTitle/index.mjs +234 -0
- package/dist/FileUploader/index.d.mts +77 -0
- package/dist/FileUploader/index.mjs +386 -0
- package/dist/InstallPwa/index.d.mts +13 -0
- package/dist/InstallPwa/index.mjs +64 -0
- package/dist/JsonEditor/index.d.mts +3 -0
- package/dist/{esm/JsonEditor/index.js → JsonEditor/index.mjs} +0 -3
- package/dist/JsonView/index.d.mts +3 -0
- package/dist/{esm/JsonView/index.js → JsonView/index.mjs} +0 -3
- package/dist/List/{index.d.ts → index.d.mts} +9 -6
- package/dist/List/index.mjs +34 -0
- package/dist/LockedOverlay/index.d.mts +162 -0
- package/dist/LockedOverlay/index.mjs +386 -0
- package/dist/Markdown/index.d.mts +16 -0
- package/dist/Markdown/index.mjs +26 -0
- package/dist/Menu/index.d.mts +16 -0
- package/dist/{esm/Menu/index.js → Menu/index.mjs} +56 -51
- package/dist/MetricCard/index.d.mts +153 -0
- package/dist/MetricCard/index.mjs +408 -0
- package/dist/Modal/index.d.mts +11 -0
- package/dist/{esm/Modal/index.js → Modal/index.mjs} +11 -12
- package/dist/NavList/index.d.mts +64 -0
- package/dist/{esm/NavList/index.js → NavList/index.mjs} +79 -73
- package/dist/NotificationCard/index.d.mts +22 -0
- package/dist/NotificationCard/index.mjs +173 -0
- package/dist/NotificationsMenu/index.d.mts +47 -0
- package/dist/NotificationsMenu/index.mjs +380 -0
- package/dist/Search/index.d.mts +18 -0
- package/dist/{esm/Search/index.js → Search/index.mjs} +11 -9
- package/dist/SpotlightCard/index.d.mts +36 -0
- package/dist/SpotlightCard/index.mjs +219 -0
- package/dist/Table/index.d.mts +17 -0
- package/dist/Table/index.mjs +64 -0
- package/dist/Tabs/index.d.mts +17 -0
- package/dist/{esm/Tabs/index.js → Tabs/index.mjs} +24 -12
- package/dist/Toast/index.d.mts +8 -0
- package/dist/Toast/index.mjs +43 -0
- package/package.json +15 -15
- package/dist/Accordion/index.d.ts +0 -148
- package/dist/DatePicker/index.d.ts +0 -20
- package/dist/Drawer/index.d.ts +0 -12
- package/dist/LockedOverlay/index.d.ts +0 -151
- package/dist/Markdown/index.d.ts +0 -11
- package/dist/Menu/index.d.ts +0 -11
- package/dist/MetricCard/index.d.ts +0 -148
- package/dist/Modal/index.d.ts +0 -10
- package/dist/NavList/index.d.ts +0 -55
- package/dist/NotificationCard/index.d.ts +0 -21
- package/dist/NotificationsMenu/index.d.ts +0 -36
- package/dist/Search/index.d.ts +0 -11
- package/dist/SpotlightCard/index.d.ts +0 -27
- package/dist/Table/index.d.ts +0 -16
- package/dist/esm/Accordion/index.js +0 -119
- package/dist/esm/DatePicker/index.js +0 -331
- package/dist/esm/EnhancedTitle/index.js +0 -190
- package/dist/esm/FileUploader/index.js +0 -401
- package/dist/esm/InstallPwa/index.js +0 -61
- package/dist/esm/List/index.js +0 -30
- package/dist/esm/LockedOverlay/index.js +0 -316
- package/dist/esm/Markdown/index.js +0 -23
- package/dist/esm/MetricCard/index.js +0 -327
- package/dist/esm/NotificationCard/index.js +0 -156
- package/dist/esm/NotificationsMenu/index.js +0 -359
- package/dist/esm/SpotlightCard/index.js +0 -212
- package/dist/esm/Table/index.js +0 -63
- package/dist/esm/Toast/index.js +0 -38
- package/dist/esm/chunk-V4MHYKRI.js +0 -7
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
|
|
2
|
+
import { BoxProps } from "@ttoss/ui";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/components/Accordion/Accordion.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Individual item for the Accordion component.
|
|
8
|
+
*/
|
|
9
|
+
type AccordionItem = {
|
|
10
|
+
/**
|
|
11
|
+
* Unique identifier for the accordion item.
|
|
12
|
+
* If not provided, will use the index as the key.
|
|
13
|
+
*/
|
|
14
|
+
id?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Title displayed in the accordion header.
|
|
17
|
+
*/
|
|
18
|
+
title: React.ReactNode;
|
|
19
|
+
/**
|
|
20
|
+
* Content displayed when the accordion item is expanded.
|
|
21
|
+
*/
|
|
22
|
+
content: React.ReactNode;
|
|
23
|
+
/**
|
|
24
|
+
* Whether the item is disabled.
|
|
25
|
+
* @default false
|
|
26
|
+
*/
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Render props for custom accordion item rendering.
|
|
31
|
+
*/
|
|
32
|
+
type AccordionRenderItemProps = {
|
|
33
|
+
/**
|
|
34
|
+
* The accordion item data.
|
|
35
|
+
*/
|
|
36
|
+
item: AccordionItem;
|
|
37
|
+
/**
|
|
38
|
+
* Index of the item in the items array.
|
|
39
|
+
*/
|
|
40
|
+
index: number;
|
|
41
|
+
/**
|
|
42
|
+
* Whether the item is currently expanded.
|
|
43
|
+
*/
|
|
44
|
+
isExpanded: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Function to toggle the item's expanded state.
|
|
47
|
+
*/
|
|
48
|
+
toggle: () => void;
|
|
49
|
+
/**
|
|
50
|
+
* Generated IDs for accessibility.
|
|
51
|
+
*/
|
|
52
|
+
ids: {
|
|
53
|
+
itemId: string;
|
|
54
|
+
headingId: string;
|
|
55
|
+
panelId: string;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Props for the Accordion component.
|
|
60
|
+
*/
|
|
61
|
+
type AccordionProps = BoxProps & {
|
|
62
|
+
/**
|
|
63
|
+
* Array of accordion items to render.
|
|
64
|
+
*/
|
|
65
|
+
items: AccordionItem[];
|
|
66
|
+
/**
|
|
67
|
+
* Whether multiple items can be expanded at once.
|
|
68
|
+
* @default false
|
|
69
|
+
*/
|
|
70
|
+
multiple?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Index or array of indices for initially expanded items.
|
|
73
|
+
*/
|
|
74
|
+
defaultExpanded?: number | number[];
|
|
75
|
+
/**
|
|
76
|
+
* Callback invoked when items are expanded or collapsed.
|
|
77
|
+
* Receives array of currently expanded indices.
|
|
78
|
+
*/
|
|
79
|
+
onAccordionChange?: (expandedIndices: number[]) => void;
|
|
80
|
+
/**
|
|
81
|
+
* Custom render function for accordion items.
|
|
82
|
+
* Provides full control over item rendering while maintaining accessibility.
|
|
83
|
+
*/
|
|
84
|
+
renderItem?: (props: AccordionRenderItemProps) => React.ReactNode;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Accessible accordion component with collapsible content sections.
|
|
88
|
+
*
|
|
89
|
+
* This component provides a simplified API for creating expandable/collapsible
|
|
90
|
+
* content sections. It uses design tokens from @ttoss/theme for consistent styling
|
|
91
|
+
* and follows WAI-ARIA accordion pattern for accessibility.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```tsx
|
|
95
|
+
* <Accordion
|
|
96
|
+
* items={[
|
|
97
|
+
* {
|
|
98
|
+
* title: 'Section 1',
|
|
99
|
+
* content: 'Content for section 1',
|
|
100
|
+
* },
|
|
101
|
+
* {
|
|
102
|
+
* title: 'Section 2',
|
|
103
|
+
* content: 'Content for section 2',
|
|
104
|
+
* },
|
|
105
|
+
* ]}
|
|
106
|
+
* />
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```tsx
|
|
111
|
+
* <Accordion
|
|
112
|
+
* multiple
|
|
113
|
+
* defaultExpanded={[0, 1]}
|
|
114
|
+
* items={[
|
|
115
|
+
* {
|
|
116
|
+
* id: 'item-1',
|
|
117
|
+
* title: 'Pre-expanded Section 1',
|
|
118
|
+
* content: <div>Rich content</div>,
|
|
119
|
+
* },
|
|
120
|
+
* {
|
|
121
|
+
* id: 'item-2',
|
|
122
|
+
* title: 'Pre-expanded Section 2',
|
|
123
|
+
* content: <p>More content</p>,
|
|
124
|
+
* },
|
|
125
|
+
* ]}
|
|
126
|
+
* onAccordionChange={(expanded) => console.log('Expanded items:', expanded)}
|
|
127
|
+
* />
|
|
128
|
+
* ```
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```tsx
|
|
132
|
+
* // Custom rendering with renderItem
|
|
133
|
+
* <Accordion
|
|
134
|
+
* items={items}
|
|
135
|
+
* renderItem={({ item, isExpanded, toggle, ids }) => (
|
|
136
|
+
* <CustomAccordionItem
|
|
137
|
+
* item={item}
|
|
138
|
+
* isExpanded={isExpanded}
|
|
139
|
+
* onToggle={toggle}
|
|
140
|
+
* headingId={ids.headingId}
|
|
141
|
+
* panelId={ids.panelId}
|
|
142
|
+
* />
|
|
143
|
+
* )}
|
|
144
|
+
* />
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
declare const Accordion: ({
|
|
148
|
+
items,
|
|
149
|
+
multiple,
|
|
150
|
+
defaultExpanded,
|
|
151
|
+
onAccordionChange,
|
|
152
|
+
renderItem,
|
|
153
|
+
sx,
|
|
154
|
+
...boxProps
|
|
155
|
+
}: AccordionProps) => import("react/jsx-runtime").JSX.Element;
|
|
156
|
+
//#endregion
|
|
157
|
+
export { Accordion, AccordionItem, AccordionProps, AccordionRenderItemProps };
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
+
import { Box, Button } from "@ttoss/ui";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
|
|
6
|
+
//#region src/components/Accordion/Accordion.tsx
|
|
7
|
+
/**
|
|
8
|
+
* Accessible accordion component with collapsible content sections.
|
|
9
|
+
*
|
|
10
|
+
* This component provides a simplified API for creating expandable/collapsible
|
|
11
|
+
* content sections. It uses design tokens from @ttoss/theme for consistent styling
|
|
12
|
+
* and follows WAI-ARIA accordion pattern for accessibility.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* <Accordion
|
|
17
|
+
* items={[
|
|
18
|
+
* {
|
|
19
|
+
* title: 'Section 1',
|
|
20
|
+
* content: 'Content for section 1',
|
|
21
|
+
* },
|
|
22
|
+
* {
|
|
23
|
+
* title: 'Section 2',
|
|
24
|
+
* content: 'Content for section 2',
|
|
25
|
+
* },
|
|
26
|
+
* ]}
|
|
27
|
+
* />
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```tsx
|
|
32
|
+
* <Accordion
|
|
33
|
+
* multiple
|
|
34
|
+
* defaultExpanded={[0, 1]}
|
|
35
|
+
* items={[
|
|
36
|
+
* {
|
|
37
|
+
* id: 'item-1',
|
|
38
|
+
* title: 'Pre-expanded Section 1',
|
|
39
|
+
* content: <div>Rich content</div>,
|
|
40
|
+
* },
|
|
41
|
+
* {
|
|
42
|
+
* id: 'item-2',
|
|
43
|
+
* title: 'Pre-expanded Section 2',
|
|
44
|
+
* content: <p>More content</p>,
|
|
45
|
+
* },
|
|
46
|
+
* ]}
|
|
47
|
+
* onAccordionChange={(expanded) => console.log('Expanded items:', expanded)}
|
|
48
|
+
* />
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```tsx
|
|
53
|
+
* // Custom rendering with renderItem
|
|
54
|
+
* <Accordion
|
|
55
|
+
* items={items}
|
|
56
|
+
* renderItem={({ item, isExpanded, toggle, ids }) => (
|
|
57
|
+
* <CustomAccordionItem
|
|
58
|
+
* item={item}
|
|
59
|
+
* isExpanded={isExpanded}
|
|
60
|
+
* onToggle={toggle}
|
|
61
|
+
* headingId={ids.headingId}
|
|
62
|
+
* panelId={ids.panelId}
|
|
63
|
+
* />
|
|
64
|
+
* )}
|
|
65
|
+
* />
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
const Accordion = ({
|
|
69
|
+
items,
|
|
70
|
+
multiple = false,
|
|
71
|
+
defaultExpanded,
|
|
72
|
+
onAccordionChange,
|
|
73
|
+
renderItem,
|
|
74
|
+
sx,
|
|
75
|
+
...boxProps
|
|
76
|
+
}) => {
|
|
77
|
+
const [expandedIndices, setExpandedIndices] = React.useState(() => {
|
|
78
|
+
if (defaultExpanded === void 0) return [];
|
|
79
|
+
return Array.isArray(defaultExpanded) ? defaultExpanded : [defaultExpanded];
|
|
80
|
+
});
|
|
81
|
+
const toggleItem = React.useCallback(index => {
|
|
82
|
+
setExpandedIndices(prev => {
|
|
83
|
+
const isExpanded = prev.includes(index);
|
|
84
|
+
let newExpanded;
|
|
85
|
+
if (isExpanded) newExpanded = prev.filter(i => {
|
|
86
|
+
return i !== index;
|
|
87
|
+
});else newExpanded = multiple ? [...prev, index] : [index];
|
|
88
|
+
onAccordionChange?.(newExpanded);
|
|
89
|
+
return newExpanded;
|
|
90
|
+
});
|
|
91
|
+
}, [multiple, onAccordionChange]);
|
|
92
|
+
return /* @__PURE__ */jsx(Box, {
|
|
93
|
+
sx: {
|
|
94
|
+
display: "flex",
|
|
95
|
+
flexDirection: "column",
|
|
96
|
+
gap: 2,
|
|
97
|
+
...sx
|
|
98
|
+
},
|
|
99
|
+
...boxProps,
|
|
100
|
+
children: items.map((item, index) => {
|
|
101
|
+
const isExpanded = expandedIndices.includes(index);
|
|
102
|
+
const itemId = item.id || `accordion-item-${index}`;
|
|
103
|
+
const headingId = `${itemId}-heading`;
|
|
104
|
+
const panelId = `${itemId}-panel`;
|
|
105
|
+
if (renderItem) return /* @__PURE__ */jsx(React.Fragment, {
|
|
106
|
+
children: renderItem({
|
|
107
|
+
item,
|
|
108
|
+
index,
|
|
109
|
+
isExpanded,
|
|
110
|
+
toggle: () => {
|
|
111
|
+
return toggleItem(index);
|
|
112
|
+
},
|
|
113
|
+
ids: {
|
|
114
|
+
itemId,
|
|
115
|
+
headingId,
|
|
116
|
+
panelId
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
}, itemId);
|
|
120
|
+
return /* @__PURE__ */jsxs(Box, {
|
|
121
|
+
sx: {
|
|
122
|
+
border: "sm",
|
|
123
|
+
borderColor: "display.border.muted.default",
|
|
124
|
+
borderRadius: "md",
|
|
125
|
+
overflow: "hidden"
|
|
126
|
+
},
|
|
127
|
+
children: [/* @__PURE__ */jsx(Button, {
|
|
128
|
+
id: headingId,
|
|
129
|
+
type: "button",
|
|
130
|
+
disabled: item.disabled,
|
|
131
|
+
onClick: () => {
|
|
132
|
+
toggleItem(index);
|
|
133
|
+
},
|
|
134
|
+
"aria-expanded": isExpanded,
|
|
135
|
+
"aria-controls": panelId,
|
|
136
|
+
rightIcon: isExpanded ? "chevron-up" : "chevron-down",
|
|
137
|
+
sx: {
|
|
138
|
+
width: "100%",
|
|
139
|
+
justifyContent: "space-between",
|
|
140
|
+
backgroundColor: isExpanded ? "display.background.muted.default" : "display.background.primary.default",
|
|
141
|
+
color: item.disabled ? "display.text.muted.default" : "display.text.primary.default",
|
|
142
|
+
fontWeight: 500,
|
|
143
|
+
border: "none",
|
|
144
|
+
borderRadius: 0,
|
|
145
|
+
transition: "background-color 0.2s ease",
|
|
146
|
+
"&:hover:not(:disabled)": {
|
|
147
|
+
backgroundColor: "display.background.muted.default"
|
|
148
|
+
},
|
|
149
|
+
"&:focus": {
|
|
150
|
+
outline: "none",
|
|
151
|
+
boxShadow: theme => {
|
|
152
|
+
return `inset 0 0 0 1px ${theme.colors?.input?.border?.accent?.default || "currentColor"}`;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
children: item.title
|
|
157
|
+
}), isExpanded && /* @__PURE__ */jsx(Box, {
|
|
158
|
+
id: panelId,
|
|
159
|
+
role: "region",
|
|
160
|
+
"aria-labelledby": headingId,
|
|
161
|
+
sx: {
|
|
162
|
+
padding: 4,
|
|
163
|
+
borderTop: "sm",
|
|
164
|
+
borderColor: "display.border.muted.default",
|
|
165
|
+
backgroundColor: "display.background.primary.default"
|
|
166
|
+
},
|
|
167
|
+
children: item.content
|
|
168
|
+
})]
|
|
169
|
+
}, itemId);
|
|
170
|
+
})
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
//#endregion
|
|
175
|
+
export { Accordion };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/components/DatePicker/DatePicker.d.ts
|
|
3
|
+
interface DateRange {
|
|
4
|
+
from: Date | undefined;
|
|
5
|
+
to: Date | undefined;
|
|
6
|
+
}
|
|
7
|
+
interface DateRangePreset {
|
|
8
|
+
label: string;
|
|
9
|
+
getValue: () => DateRange;
|
|
10
|
+
}
|
|
11
|
+
interface DatePickerProps {
|
|
12
|
+
label?: string;
|
|
13
|
+
value?: DateRange;
|
|
14
|
+
presets?: DateRangePreset[];
|
|
15
|
+
onChange?: (range: DateRange | undefined) => void;
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
}
|
|
18
|
+
declare const DatePicker: ({
|
|
19
|
+
label,
|
|
20
|
+
value,
|
|
21
|
+
presets,
|
|
22
|
+
onChange,
|
|
23
|
+
disabled
|
|
24
|
+
}: DatePickerProps) => import("react/jsx-runtime").JSX.Element;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { DatePicker, DateRange };
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
+
import { Box, Button, Flex, Label, Text } from "@ttoss/ui";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { Icon } from "@ttoss/react-icons";
|
|
6
|
+
import { DayPicker } from "react-day-picker";
|
|
7
|
+
import { ptBR } from "react-day-picker/locale";
|
|
8
|
+
|
|
9
|
+
//#region src/components/DatePicker/DatePicker.tsx
|
|
10
|
+
const formatDate = date => {
|
|
11
|
+
return date.toLocaleDateString("pt-BR");
|
|
12
|
+
};
|
|
13
|
+
const DatePicker = ({
|
|
14
|
+
label,
|
|
15
|
+
value,
|
|
16
|
+
presets,
|
|
17
|
+
onChange,
|
|
18
|
+
disabled
|
|
19
|
+
}) => {
|
|
20
|
+
const [date, setDate] = React.useState(value);
|
|
21
|
+
const [pickerSelection, setPickerSelection] = React.useState(value);
|
|
22
|
+
const [isOpen, setIsOpen] = React.useState(false);
|
|
23
|
+
const containerRef = React.useRef(null);
|
|
24
|
+
const isResettingRangeRef = React.useRef(false);
|
|
25
|
+
React.useEffect(() => {
|
|
26
|
+
setDate(value);
|
|
27
|
+
}, [value]);
|
|
28
|
+
React.useEffect(() => {
|
|
29
|
+
if (isOpen) setPickerSelection(date);
|
|
30
|
+
}, [isOpen, date]);
|
|
31
|
+
React.useEffect(() => {
|
|
32
|
+
const handleClickOutside = event => {
|
|
33
|
+
if (containerRef.current && !containerRef.current.contains(event.target)) setIsOpen(false);
|
|
34
|
+
};
|
|
35
|
+
if (isOpen) document.addEventListener("mousedown", handleClickOutside);
|
|
36
|
+
return () => {
|
|
37
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
38
|
+
};
|
|
39
|
+
}, [isOpen]);
|
|
40
|
+
const commitSelection = range => {
|
|
41
|
+
setDate(range);
|
|
42
|
+
onChange?.(range);
|
|
43
|
+
};
|
|
44
|
+
const handlePresetClick = preset => {
|
|
45
|
+
commitSelection(preset.getValue());
|
|
46
|
+
setIsOpen(false);
|
|
47
|
+
};
|
|
48
|
+
const handleDayPickerSelect = selected => {
|
|
49
|
+
if (isResettingRangeRef.current && !selected && pickerSelection?.from && !pickerSelection?.to) {
|
|
50
|
+
commitSelection({
|
|
51
|
+
from: pickerSelection.from,
|
|
52
|
+
to: pickerSelection.from
|
|
53
|
+
});
|
|
54
|
+
setIsOpen(false);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
isResettingRangeRef.current = false;
|
|
58
|
+
const hadFullRange = date?.from && date?.to;
|
|
59
|
+
const hadPartialPicker = pickerSelection?.from && !pickerSelection?.to;
|
|
60
|
+
if (hadFullRange && !hadPartialPicker && selected?.from && selected?.to) {
|
|
61
|
+
setPickerSelection({
|
|
62
|
+
from: selected.from.getTime() === date?.from?.getTime() ? selected.to : selected.from,
|
|
63
|
+
to: void 0
|
|
64
|
+
});
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
setPickerSelection(selected);
|
|
68
|
+
if (selected?.from && selected?.to) {
|
|
69
|
+
commitSelection(selected);
|
|
70
|
+
setIsOpen(false);
|
|
71
|
+
} else if (!selected?.from && !selected?.to) commitSelection(void 0);
|
|
72
|
+
};
|
|
73
|
+
const handleDayClick = day => {
|
|
74
|
+
if (date?.from && date?.to) {
|
|
75
|
+
isResettingRangeRef.current = true;
|
|
76
|
+
setPickerSelection({
|
|
77
|
+
from: day,
|
|
78
|
+
to: void 0
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
return /* @__PURE__ */jsxs(Flex, {
|
|
83
|
+
ref: containerRef,
|
|
84
|
+
sx: {
|
|
85
|
+
flexDirection: "column",
|
|
86
|
+
gap: "1",
|
|
87
|
+
position: "relative"
|
|
88
|
+
},
|
|
89
|
+
children: [label && /* @__PURE__ */jsx(Label, {
|
|
90
|
+
children: label
|
|
91
|
+
}), /* @__PURE__ */jsx(Button, {
|
|
92
|
+
disabled,
|
|
93
|
+
variant: "secondary",
|
|
94
|
+
onClick: () => {
|
|
95
|
+
return setIsOpen(!isOpen);
|
|
96
|
+
},
|
|
97
|
+
sx: {
|
|
98
|
+
width: "100%",
|
|
99
|
+
justifyContent: "space-between",
|
|
100
|
+
fontSize: ["14px", "14px"],
|
|
101
|
+
fontWeight: 400,
|
|
102
|
+
backgroundColor: "white",
|
|
103
|
+
padding: "8px 12px",
|
|
104
|
+
borderRadius: "lg",
|
|
105
|
+
border: "md",
|
|
106
|
+
borderColor: "display.border.muted.default",
|
|
107
|
+
height: "40px",
|
|
108
|
+
minWidth: ["auto", "240px"],
|
|
109
|
+
"&:disabled": {
|
|
110
|
+
borderColor: "display.border.muted.default"
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
children: date?.from ? date.to ? /* @__PURE__ */jsxs(Text, {
|
|
114
|
+
sx: {
|
|
115
|
+
fontSize: ["12px", "14px"],
|
|
116
|
+
overflow: "hidden",
|
|
117
|
+
textOverflow: "ellipsis",
|
|
118
|
+
whiteSpace: "nowrap"
|
|
119
|
+
},
|
|
120
|
+
children: [formatDate(date.from), " - ", formatDate(date.to)]
|
|
121
|
+
}) : /* @__PURE__ */jsx(Text, {
|
|
122
|
+
sx: {
|
|
123
|
+
fontSize: ["12px", "14px"],
|
|
124
|
+
overflow: "hidden",
|
|
125
|
+
textOverflow: "ellipsis",
|
|
126
|
+
whiteSpace: "nowrap"
|
|
127
|
+
},
|
|
128
|
+
children: formatDate(date.from)
|
|
129
|
+
}) : /* @__PURE__ */jsx(Text, {
|
|
130
|
+
sx: {
|
|
131
|
+
fontSize: ["12px", "14px"]
|
|
132
|
+
},
|
|
133
|
+
children: "Selecione o período"
|
|
134
|
+
})
|
|
135
|
+
}), isOpen && /* @__PURE__ */jsxs(Fragment, {
|
|
136
|
+
children: [/* @__PURE__ */jsx(Box, {
|
|
137
|
+
sx: {
|
|
138
|
+
display: ["block", "none"],
|
|
139
|
+
position: "fixed",
|
|
140
|
+
top: 0,
|
|
141
|
+
left: 0,
|
|
142
|
+
right: 0,
|
|
143
|
+
bottom: 0,
|
|
144
|
+
backgroundColor: "rgba(0, 0, 0, 0.5)",
|
|
145
|
+
zIndex: 49
|
|
146
|
+
},
|
|
147
|
+
onClick: () => {
|
|
148
|
+
return setIsOpen(false);
|
|
149
|
+
}
|
|
150
|
+
}), /* @__PURE__ */jsxs(Box, {
|
|
151
|
+
sx: {
|
|
152
|
+
position: ["fixed", "absolute"],
|
|
153
|
+
top: ["auto", "calc(100% + 4px)"],
|
|
154
|
+
bottom: ["0", "auto"],
|
|
155
|
+
left: ["0", "0"],
|
|
156
|
+
right: ["0", "auto"],
|
|
157
|
+
width: ["100%", "auto"],
|
|
158
|
+
maxWidth: ["100%", "650px"],
|
|
159
|
+
zIndex: 50,
|
|
160
|
+
backgroundColor: "white",
|
|
161
|
+
border: "1px solid",
|
|
162
|
+
borderColor: "display.border.muted.default",
|
|
163
|
+
borderRadius: ["16px 16px 0 0", "8px"],
|
|
164
|
+
boxShadow: ["0 -4px 6px -1px rgba(0, 0, 0, 0.1)", "0 4px 6px -1px rgba(0, 0, 0, 0.1)"],
|
|
165
|
+
overflow: "hidden",
|
|
166
|
+
maxHeight: ["80vh", "none"],
|
|
167
|
+
display: "flex",
|
|
168
|
+
flexDirection: "column"
|
|
169
|
+
},
|
|
170
|
+
children: [/* @__PURE__ */jsxs(Flex, {
|
|
171
|
+
sx: {
|
|
172
|
+
display: ["flex", "none"],
|
|
173
|
+
justifyContent: "space-between",
|
|
174
|
+
alignItems: "center",
|
|
175
|
+
padding: "12px 16px",
|
|
176
|
+
borderBottom: "1px solid",
|
|
177
|
+
borderColor: "display.border.muted.default"
|
|
178
|
+
},
|
|
179
|
+
children: [/* @__PURE__ */jsx(Text, {
|
|
180
|
+
sx: {
|
|
181
|
+
fontSize: "16px",
|
|
182
|
+
fontWeight: 600
|
|
183
|
+
},
|
|
184
|
+
children: label || "Selecione o período"
|
|
185
|
+
}), /* @__PURE__ */jsx(Button, {
|
|
186
|
+
variant: "ghost",
|
|
187
|
+
onClick: () => {
|
|
188
|
+
return setIsOpen(false);
|
|
189
|
+
},
|
|
190
|
+
sx: {
|
|
191
|
+
padding: "4px",
|
|
192
|
+
minWidth: "auto",
|
|
193
|
+
width: "32px",
|
|
194
|
+
height: "32px"
|
|
195
|
+
},
|
|
196
|
+
children: /* @__PURE__ */jsx(Icon, {
|
|
197
|
+
icon: "mdi:close",
|
|
198
|
+
size: 20
|
|
199
|
+
})
|
|
200
|
+
})]
|
|
201
|
+
}), /* @__PURE__ */jsxs(Flex, {
|
|
202
|
+
sx: {
|
|
203
|
+
minHeight: "300px",
|
|
204
|
+
flexDirection: ["column", "row"],
|
|
205
|
+
maxHeight: ["calc(80vh - 60px)", "none"],
|
|
206
|
+
overflow: ["auto", "visible"]
|
|
207
|
+
},
|
|
208
|
+
children: [presets && presets.length > 0 && /* @__PURE__ */jsx(Flex, {
|
|
209
|
+
sx: {
|
|
210
|
+
flexDirection: ["row", "column"],
|
|
211
|
+
gap: "4px",
|
|
212
|
+
padding: ["8px", "12px"],
|
|
213
|
+
borderRight: ["none", "1px solid"],
|
|
214
|
+
borderBottom: ["1px solid", "none"],
|
|
215
|
+
borderColor: "display.border.muted.default",
|
|
216
|
+
backgroundColor: "navigation.background.muted.default",
|
|
217
|
+
minWidth: ["auto", "140px"],
|
|
218
|
+
width: ["100%", "auto"],
|
|
219
|
+
overflowX: ["auto", "visible"],
|
|
220
|
+
overflowY: ["visible", "auto"],
|
|
221
|
+
flexWrap: ["nowrap", "wrap"],
|
|
222
|
+
"@media (max-width: 768px)": {
|
|
223
|
+
"&::-webkit-scrollbar": {
|
|
224
|
+
display: "none"
|
|
225
|
+
},
|
|
226
|
+
scrollbarWidth: "none"
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
children: presets?.map(preset => {
|
|
230
|
+
return /* @__PURE__ */jsx(Button, {
|
|
231
|
+
variant: "ghost",
|
|
232
|
+
onClick: () => {
|
|
233
|
+
return handlePresetClick(preset);
|
|
234
|
+
},
|
|
235
|
+
sx: {
|
|
236
|
+
justifyContent: ["center", "flex-start"],
|
|
237
|
+
fontSize: ["12px", "14px"],
|
|
238
|
+
fontWeight: 400,
|
|
239
|
+
padding: ["6px 8px", "8px 12px"],
|
|
240
|
+
color: "display.text.secondary.default",
|
|
241
|
+
backgroundColor: "transparent",
|
|
242
|
+
whiteSpace: "nowrap",
|
|
243
|
+
minWidth: ["auto", "auto"],
|
|
244
|
+
flexShrink: 0,
|
|
245
|
+
"&:hover": {
|
|
246
|
+
backgroundColor: "input.background.muted.active"
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
children: preset.label
|
|
250
|
+
}, preset.label);
|
|
251
|
+
})
|
|
252
|
+
}), /* @__PURE__ */jsx(Box, {
|
|
253
|
+
sx: {
|
|
254
|
+
padding: ["12px", "16px"],
|
|
255
|
+
flex: 1,
|
|
256
|
+
overflow: "auto",
|
|
257
|
+
"& .rdp": {
|
|
258
|
+
margin: 0
|
|
259
|
+
},
|
|
260
|
+
"& .rdp-month": {
|
|
261
|
+
width: "100%"
|
|
262
|
+
},
|
|
263
|
+
"& .rdp-day_button": {
|
|
264
|
+
borderRadius: "50% !important",
|
|
265
|
+
border: "none",
|
|
266
|
+
fontSize: ["12px", "14px"],
|
|
267
|
+
width: ["32px", "36px"],
|
|
268
|
+
height: ["32px", "36px"],
|
|
269
|
+
cursor: "pointer"
|
|
270
|
+
},
|
|
271
|
+
"& .rdp-range_start .rdp-day_button": {
|
|
272
|
+
backgroundColor: "action.background.accent.default",
|
|
273
|
+
color: "black"
|
|
274
|
+
},
|
|
275
|
+
"& .rdp-range_end .rdp-day_button": {
|
|
276
|
+
backgroundColor: "action.background.accent.default",
|
|
277
|
+
color: "black"
|
|
278
|
+
},
|
|
279
|
+
"& .rdp-day_button:hover": {
|
|
280
|
+
backgroundColor: "action.background.primary.default",
|
|
281
|
+
color: "action.text.primary.default"
|
|
282
|
+
},
|
|
283
|
+
"& .rdp-day_selected": {
|
|
284
|
+
backgroundColor: "action.background.accent.default",
|
|
285
|
+
color: "white",
|
|
286
|
+
fontWeight: 600
|
|
287
|
+
},
|
|
288
|
+
"& .rdp-day_range_middle": {
|
|
289
|
+
backgroundColor: "action.background.accent.default",
|
|
290
|
+
color: "white"
|
|
291
|
+
},
|
|
292
|
+
"& .rdp-day_range_start, & .rdp-day_range_end": {
|
|
293
|
+
backgroundColor: "action.background.accent.default",
|
|
294
|
+
color: "white",
|
|
295
|
+
fontWeight: 600
|
|
296
|
+
},
|
|
297
|
+
"& .rdp-weekday": {
|
|
298
|
+
fontSize: ["10px", "12px"],
|
|
299
|
+
fontWeight: 500,
|
|
300
|
+
color: "display.text.muted.default"
|
|
301
|
+
},
|
|
302
|
+
"& .rdp-month_caption": {
|
|
303
|
+
fontSize: ["12px", "14px"],
|
|
304
|
+
fontWeight: 600,
|
|
305
|
+
marginBottom: ["12px", "16px"]
|
|
306
|
+
},
|
|
307
|
+
"@media (max-width: 768px)": {
|
|
308
|
+
"& .rdp-caption": {
|
|
309
|
+
marginBottom: "8px"
|
|
310
|
+
},
|
|
311
|
+
"& .rdp-table": {
|
|
312
|
+
width: "100%"
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
},
|
|
316
|
+
children: /* @__PURE__ */jsx(DayPicker, {
|
|
317
|
+
disabled,
|
|
318
|
+
mode: "range",
|
|
319
|
+
locale: ptBR,
|
|
320
|
+
selected: pickerSelection?.from ? {
|
|
321
|
+
from: pickerSelection.from,
|
|
322
|
+
to: pickerSelection.to ?? pickerSelection.from
|
|
323
|
+
} : void 0,
|
|
324
|
+
onSelect: selected => {
|
|
325
|
+
return handleDayPickerSelect(selected);
|
|
326
|
+
},
|
|
327
|
+
onDayClick: handleDayClick,
|
|
328
|
+
weekStartsOn: 1,
|
|
329
|
+
showOutsideDays: true
|
|
330
|
+
})
|
|
331
|
+
})]
|
|
332
|
+
})]
|
|
333
|
+
})]
|
|
334
|
+
})]
|
|
335
|
+
});
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
//#endregion
|
|
339
|
+
export { DatePicker };
|