@ttoss/components 2.3.0 → 2.4.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.
@@ -1,4 +1,5 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
+ import { __name } from "../chunk-V4MHYKRI.js";
2
3
 
3
4
  // src/components/Accordion/Accordion.tsx
4
5
  import * as React from "react";
@@ -6,8 +7,7 @@ import { AccordionItem, AccordionItemButton, AccordionItemHeading, AccordionItem
6
7
  import { Box, useTheme } from "@ttoss/ui";
7
8
  import { css as createClassName } from "@emotion/css";
8
9
  import { css as transformStyleObject } from "@theme-ui/css";
9
- import { jsx } from "react/jsx-runtime";
10
- var Accordion = ({
10
+ var Accordion = /* @__PURE__ */__name(({
11
11
  children,
12
12
  allowMultipleExpanded,
13
13
  allowZeroExpanded,
@@ -35,19 +35,15 @@ var Accordion = ({
35
35
  })(theme);
36
36
  return createClassName(styles);
37
37
  }, [theme]);
38
- return /* @__PURE__ */jsx(Box, {
38
+ return /* @__PURE__ */React.createElement(Box, {
39
39
  variant: "accordion",
40
40
  className,
41
- ...boxProps,
42
- children: /* @__PURE__ */jsx(ReactAccessibleAccordion, {
43
- ...{
44
- allowMultipleExpanded,
45
- allowZeroExpanded,
46
- preExpanded,
47
- onChange
48
- },
49
- children
50
- })
51
- });
52
- };
41
+ ...boxProps
42
+ }, /* @__PURE__ */React.createElement(ReactAccessibleAccordion, {
43
+ allowMultipleExpanded,
44
+ allowZeroExpanded,
45
+ preExpanded,
46
+ onChange
47
+ }, children));
48
+ }, "Accordion");
53
49
  export { Accordion, AccordionItem, AccordionItemButton, AccordionItemHeading, AccordionItemPanel };
@@ -1,20 +1,21 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
+ import { __name } from "../chunk-V4MHYKRI.js";
2
3
 
3
4
  // src/components/Drawer/Drawer.tsx
4
5
  import { Box } from "@ttoss/ui";
6
+ import * as React from "react";
5
7
  import DrawerUi from "react-modern-drawer";
6
- import { jsx } from "react/jsx-runtime";
7
- var Drawer = ({
8
+ var Drawer = /* @__PURE__ */__name(({
8
9
  children,
9
10
  sx,
10
11
  ...props
11
12
  }) => {
12
- return /* @__PURE__ */jsx(Box, {
13
+ return /* @__PURE__ */React.createElement(Box, {
13
14
  "data-testid": "drawer-container",
14
15
  sx: {
15
16
  /**
16
- * https://github.com/Farzin-Firoozi/react-modern-drawer/blob/master/src/styles.css
17
- */
17
+ * https://github.com/Farzin-Firoozi/react-modern-drawer/blob/master/src/styles.css
18
+ */
18
19
  zIndex: "overlay",
19
20
  width: "100%",
20
21
  height: "100%",
@@ -47,17 +48,12 @@ var Drawer = ({
47
48
  overflowY: "auto"
48
49
  },
49
50
  ...sx
50
- },
51
- children: /* @__PURE__ */jsx(DrawerUi, {
52
- ...props,
53
- children: /* @__PURE__ */jsx(Box, {
54
- sx: {
55
- width: "100%",
56
- height: "100%"
57
- },
58
- children
59
- })
60
- })
61
- });
62
- };
51
+ }
52
+ }, /* @__PURE__ */React.createElement(DrawerUi, props, /* @__PURE__ */React.createElement(Box, {
53
+ sx: {
54
+ width: "100%",
55
+ height: "100%"
56
+ }
57
+ }, children)));
58
+ }, "Drawer");
63
59
  export { Drawer };
@@ -0,0 +1,346 @@
1
+ /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
+ import { __name } from "../chunk-V4MHYKRI.js";
3
+
4
+ // src/components/FileUploader/FileUploader.tsx
5
+ import { useI18n } from "@ttoss/react-i18n";
6
+ import { Box, Button, Flex, Stack, Text } from "@ttoss/ui";
7
+ import * as React from "react";
8
+ var FileUploader = /* @__PURE__ */__name(({
9
+ onUpload,
10
+ onUploadStart,
11
+ onUploadProgress,
12
+ onUploadComplete,
13
+ onUploadError,
14
+ onFilesChange,
15
+ onRemoveFile,
16
+ accept,
17
+ multiple = true,
18
+ maxSize = 10 * 1024 * 1024,
19
+ maxFiles = 5,
20
+ disabled = false,
21
+ autoUpload = true,
22
+ retryAttempts = 2,
23
+ placeholder,
24
+ error,
25
+ children,
26
+ showFileList = true,
27
+ FileListComponent
28
+ }) => {
29
+ const {
30
+ intl
31
+ } = useI18n();
32
+ const [files, setFiles] = React.useState([]);
33
+ const [isDragOver, setIsDragOver] = React.useState(false);
34
+ const fileInputRef = React.useRef(null);
35
+ const formatFileSize = /* @__PURE__ */__name(bytes => {
36
+ if (bytes === 0) return "0 Bytes";
37
+ const k = 1024;
38
+ const sizes = ["Bytes", "KB", "MB", "GB"];
39
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
40
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i];
41
+ }, "formatFileSize");
42
+ const validateFiles = /* @__PURE__ */__name(newFiles => {
43
+ const fileArray = Array.from(newFiles);
44
+ const validFiles = [];
45
+ const currentFileCount = files.length;
46
+ for (const file of fileArray) {
47
+ if (maxSize && file.size > maxSize) {
48
+ continue;
49
+ }
50
+ if (validFiles.length + currentFileCount >= maxFiles) {
51
+ break;
52
+ }
53
+ validFiles.push(file);
54
+ }
55
+ return validFiles;
56
+ }, "validateFiles");
57
+ const updateFileState = React.useCallback((file, updates) => {
58
+ setFiles(prevFiles => {
59
+ const newFiles = prevFiles.map(f => {
60
+ return f.file === file ? {
61
+ ...f,
62
+ ...updates
63
+ } : f;
64
+ });
65
+ onFilesChange?.(newFiles);
66
+ return newFiles;
67
+ });
68
+ }, [onFilesChange]);
69
+ const uploadFile = React.useCallback(async (fileState, attempts = 0) => {
70
+ try {
71
+ onUploadStart?.(fileState.file);
72
+ updateFileState(fileState.file, {
73
+ status: "uploading",
74
+ progress: 0
75
+ });
76
+ const result = await onUpload(fileState.file, progress => {
77
+ updateFileState(fileState.file, {
78
+ progress
79
+ });
80
+ onUploadProgress?.(fileState.file, progress);
81
+ });
82
+ updateFileState(fileState.file, {
83
+ status: "completed",
84
+ progress: 100,
85
+ result
86
+ });
87
+ onUploadComplete?.(fileState.file, result);
88
+ } catch (error_) {
89
+ const error2 = error_;
90
+ if (attempts < retryAttempts) {
91
+ setTimeout(() => {
92
+ return uploadFile(fileState, attempts + 1);
93
+ }, 1e3 * (attempts + 1));
94
+ } else {
95
+ updateFileState(fileState.file, {
96
+ status: "error",
97
+ error: error2
98
+ });
99
+ onUploadError?.(fileState.file, error2);
100
+ }
101
+ }
102
+ }, [onUpload, onUploadStart, onUploadProgress, onUploadComplete, onUploadError, retryAttempts, updateFileState]);
103
+ const addFiles = /* @__PURE__ */__name(newFiles => {
104
+ const newFileStates = newFiles.map(file => {
105
+ return {
106
+ file,
107
+ status: "pending"
108
+ };
109
+ });
110
+ setFiles(prevFiles => {
111
+ const updatedFiles = [...prevFiles, ...newFileStates];
112
+ onFilesChange?.(updatedFiles);
113
+ return updatedFiles;
114
+ });
115
+ if (autoUpload) {
116
+ for (const fileState of newFileStates) {
117
+ uploadFile(fileState);
118
+ }
119
+ }
120
+ }, "addFiles");
121
+ const handleFileChange = /* @__PURE__ */__name(event => {
122
+ if (event.target.files) {
123
+ const validFiles = validateFiles(event.target.files);
124
+ addFiles(validFiles);
125
+ }
126
+ }, "handleFileChange");
127
+ const handleDrop = /* @__PURE__ */__name(event => {
128
+ event.preventDefault();
129
+ setIsDragOver(false);
130
+ if (disabled) return;
131
+ const droppedFiles = event.dataTransfer.files;
132
+ if (droppedFiles) {
133
+ const validFiles = validateFiles(droppedFiles);
134
+ addFiles(validFiles);
135
+ }
136
+ }, "handleDrop");
137
+ const handleDragOver = /* @__PURE__ */__name(event => {
138
+ event.preventDefault();
139
+ if (!disabled) {
140
+ setIsDragOver(true);
141
+ }
142
+ }, "handleDragOver");
143
+ const handleDragLeave = /* @__PURE__ */__name(event => {
144
+ event.preventDefault();
145
+ setIsDragOver(false);
146
+ }, "handleDragLeave");
147
+ const handleClick = /* @__PURE__ */__name(() => {
148
+ if (!disabled && fileInputRef.current) {
149
+ fileInputRef.current.click();
150
+ }
151
+ }, "handleClick");
152
+ const handleRemoveFile = React.useCallback(index => {
153
+ const fileToRemove = files[index];
154
+ setFiles(prevFiles => {
155
+ const newFiles = prevFiles.filter((_, i) => {
156
+ return i !== index;
157
+ });
158
+ onFilesChange?.(newFiles);
159
+ return newFiles;
160
+ });
161
+ onRemoveFile?.(fileToRemove, index);
162
+ }, [files, onFilesChange, onRemoveFile]);
163
+ const retryUpload = React.useCallback(index => {
164
+ const fileState = files[index];
165
+ if (fileState.status === "error") {
166
+ uploadFile(fileState);
167
+ }
168
+ }, [files, uploadFile]);
169
+ const isUploading = files.some(f => {
170
+ return f.status === "uploading";
171
+ });
172
+ const fileListNode = React.useMemo(() => {
173
+ if (!showFileList || files.length === 0) {
174
+ return null;
175
+ }
176
+ if (FileListComponent) {
177
+ return /* @__PURE__ */React.createElement(FileListComponent, {
178
+ files,
179
+ onRemoveFile: handleRemoveFile
180
+ });
181
+ }
182
+ return /* @__PURE__ */React.createElement(Stack, {
183
+ sx: {
184
+ gap: 1
185
+ }
186
+ }, files.map((fileState, index) => {
187
+ return /* @__PURE__ */React.createElement(Flex, {
188
+ key: index,
189
+ sx: {
190
+ alignItems: "center",
191
+ justifyContent: "space-between",
192
+ p: 2,
193
+ backgroundColor: "display.background.secondary.default",
194
+ borderRadius: "md",
195
+ gap: 2
196
+ }
197
+ }, /* @__PURE__ */React.createElement(Flex, {
198
+ sx: {
199
+ alignItems: "center",
200
+ gap: 2,
201
+ flex: 1
202
+ }
203
+ }, /* @__PURE__ */React.createElement(Text, {
204
+ sx: {
205
+ fontSize: "lg"
206
+ }
207
+ }, fileState.status === "completed" ? "\u2713" : fileState.status === "error" ? "\u2717" : fileState.status === "uploading" ? "\u21BB" : "\u{1F4C4}"), /* @__PURE__ */React.createElement(Box, {
208
+ sx: {
209
+ flex: 1
210
+ }
211
+ }, /* @__PURE__ */React.createElement(Text, {
212
+ variant: "body",
213
+ sx: {
214
+ fontWeight: "medium"
215
+ }
216
+ }, fileState.file.name), fileState.status === "uploading" && fileState.progress && /* @__PURE__ */React.createElement(Text, {
217
+ variant: "caption",
218
+ sx: {
219
+ color: "primary.default"
220
+ }
221
+ }, fileState.progress.toFixed(0), "%"), fileState.status === "error" && /* @__PURE__ */React.createElement(Text, {
222
+ variant: "caption",
223
+ sx: {
224
+ color: "error.default"
225
+ }
226
+ }, "Failed")), /* @__PURE__ */React.createElement(Text, {
227
+ variant: "caption",
228
+ sx: {
229
+ color: "text.muted"
230
+ }
231
+ }, formatFileSize(fileState.file.size))), /* @__PURE__ */React.createElement(Flex, {
232
+ sx: {
233
+ gap: 1
234
+ }
235
+ }, fileState.status === "error" && /* @__PURE__ */React.createElement(Button, {
236
+ variant: "destructive",
237
+ onClick: /* @__PURE__ */__name(() => {
238
+ return retryUpload(index);
239
+ }, "onClick"),
240
+ sx: {
241
+ fontSize: "xs"
242
+ }
243
+ }, "Retry"), /* @__PURE__ */React.createElement(Button, {
244
+ variant: "destructive",
245
+ onClick: /* @__PURE__ */__name(() => {
246
+ return handleRemoveFile(index);
247
+ }, "onClick"),
248
+ sx: {
249
+ fontSize: "sm",
250
+ color: "text.muted",
251
+ "&:hover": {
252
+ color: "error.default"
253
+ }
254
+ }
255
+ }, "Remove")));
256
+ }));
257
+ }, [FileListComponent, files, handleRemoveFile, retryUpload, showFileList]);
258
+ return /* @__PURE__ */React.createElement(Stack, {
259
+ sx: {
260
+ gap: 3
261
+ }
262
+ }, /* @__PURE__ */React.createElement(Box, {
263
+ onDrop: handleDrop,
264
+ onDragOver: handleDragOver,
265
+ onDragLeave: handleDragLeave,
266
+ onClick: handleClick,
267
+ sx: {
268
+ border: "2px dashed",
269
+ borderColor: error ? "error.default" : isDragOver ? "primary.default" : "display.border.muted.default",
270
+ borderRadius: "xl",
271
+ padding: 6,
272
+ textAlign: "center",
273
+ cursor: disabled || isUploading ? "not-allowed" : "pointer",
274
+ backgroundColor: isDragOver ? "primary.muted" : "display.background.secondary.default",
275
+ transition: "all 0.2s ease",
276
+ opacity: disabled ? 0.6 : 1,
277
+ "&:hover": {
278
+ borderColor: !disabled && !isUploading && !error ? "primary.default" : void 0,
279
+ backgroundColor: !disabled && !isUploading ? "primary.muted" : void 0
280
+ }
281
+ }
282
+ }, /* @__PURE__ */React.createElement("input", {
283
+ ref: fileInputRef,
284
+ type: "file",
285
+ accept,
286
+ multiple,
287
+ onChange: handleFileChange,
288
+ disabled: disabled || isUploading,
289
+ style: {
290
+ display: "none"
291
+ }
292
+ }), children || /* @__PURE__ */React.createElement(Flex, {
293
+ sx: {
294
+ flexDirection: "column",
295
+ alignItems: "center",
296
+ gap: 3,
297
+ justifyContent: "center"
298
+ }
299
+ }, /* @__PURE__ */React.createElement(Text, {
300
+ sx: {
301
+ fontSize: "3xl"
302
+ }
303
+ }, "\u{1F4C1}"), /* @__PURE__ */React.createElement(Box, {
304
+ sx: {
305
+ textAlign: "center"
306
+ }
307
+ }, /* @__PURE__ */React.createElement(Text, {
308
+ variant: "body",
309
+ sx: {
310
+ color: "text.default",
311
+ mb: 1
312
+ }
313
+ }, isUploading ? intl.formatMessage({
314
+ id: "JEsxDw",
315
+ defaultMessage: [{
316
+ "type": 0,
317
+ "value": "Uploading..."
318
+ }]
319
+ }) : placeholder || intl.formatMessage({
320
+ id: "gy0Ynb",
321
+ defaultMessage: [{
322
+ "type": 0,
323
+ "value": "Click or drag files here"
324
+ }]
325
+ })), /* @__PURE__ */React.createElement(Text, {
326
+ variant: "caption",
327
+ sx: {
328
+ color: "text.muted"
329
+ }
330
+ }, [accept && accept, maxSize && `Max ${formatFileSize(maxSize)}`, multiple && maxFiles && `Up to ${maxFiles} files`].filter(Boolean).join(" \u2022 "))), !isUploading && /* @__PURE__ */React.createElement(Button, {
331
+ variant: "secondary",
332
+ disabled
333
+ }, intl.formatMessage({
334
+ id: "fDCMA6",
335
+ defaultMessage: [{
336
+ "type": 0,
337
+ "value": "Select Files"
338
+ }]
339
+ })))), error && /* @__PURE__ */React.createElement(Text, {
340
+ variant: "caption",
341
+ sx: {
342
+ color: "error.default"
343
+ }
344
+ }, error), fileListNode);
345
+ }, "FileUploader");
346
+ export { FileUploader };
@@ -1,66 +1,61 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
+ import { __name } from "../chunk-V4MHYKRI.js";
2
3
 
3
4
  // src/components/InstallPwa/InstallPwa.tsx
4
5
  import * as React from "react";
5
6
  import { Button, Flex, Text } from "@ttoss/ui";
6
- import { jsx, jsxs } from "react/jsx-runtime";
7
- var InstallPwaUi = ({
7
+ var InstallPwaUi = /* @__PURE__ */__name(({
8
8
  onInstall
9
9
  }) => {
10
- return /* @__PURE__ */jsx(Flex, {
10
+ return /* @__PURE__ */React.createElement(Flex, {
11
11
  sx: {
12
12
  position: "absolute",
13
13
  bottom: 4,
14
14
  width: "100%",
15
15
  justifyContent: "center"
16
- },
17
- children: /* @__PURE__ */jsxs(Flex, {
18
- sx: {
19
- backgroundColor: "background",
20
- justifyContent: "center",
21
- alignItems: "center",
22
- gap: 3,
23
- width: "auto",
24
- border: "1px solid",
25
- borderColor: "muted",
26
- borderRadius: 1,
27
- padding: 4
28
- },
29
- children: [/* @__PURE__ */jsx(Text, {
30
- children: "Deseja instalar o nosso aplicativo?"
31
- }), /* @__PURE__ */jsx(Button, {
32
- onClick: onInstall,
33
- children: "Instalar"
34
- })]
35
- })
36
- });
37
- };
38
- var InstallPwa = () => {
16
+ }
17
+ }, /* @__PURE__ */React.createElement(Flex, {
18
+ sx: {
19
+ backgroundColor: "background",
20
+ justifyContent: "center",
21
+ alignItems: "center",
22
+ gap: 3,
23
+ width: "auto",
24
+ border: "1px solid",
25
+ borderColor: "muted",
26
+ borderRadius: 1,
27
+ padding: 4
28
+ }
29
+ }, /* @__PURE__ */React.createElement(Text, null, "Deseja instalar o nosso aplicativo?"), /* @__PURE__ */React.createElement(Button, {
30
+ onClick: onInstall
31
+ }, "Instalar")));
32
+ }, "InstallPwaUi");
33
+ var InstallPwa = /* @__PURE__ */__name(() => {
39
34
  const [supportsPwa, setSupportsPwa] = React.useState(false);
40
35
  const [promptInstall, setPromptInstall] = React.useState(null);
41
36
  React.useEffect(() => {
42
- const handler = e => {
37
+ const handler = /* @__PURE__ */__name(e => {
43
38
  e.preventDefault();
44
39
  setSupportsPwa(true);
45
40
  setPromptInstall(e);
46
- };
41
+ }, "handler");
47
42
  window.addEventListener("beforeinstallprompt", handler);
48
43
  return () => {
49
44
  return window.removeEventListener("transitionend", handler);
50
45
  };
51
46
  }, []);
52
- const onInstall = e => {
47
+ const onInstall = /* @__PURE__ */__name(e => {
53
48
  e.preventDefault();
54
49
  if (!promptInstall) {
55
50
  return;
56
51
  }
57
52
  promptInstall.prompt();
58
- };
53
+ }, "onInstall");
59
54
  if (!supportsPwa) {
60
55
  return null;
61
56
  }
62
- return /* @__PURE__ */jsx(InstallPwaUi, {
57
+ return /* @__PURE__ */React.createElement(InstallPwaUi, {
63
58
  onInstall
64
59
  });
65
- };
60
+ }, "InstallPwa");
66
61
  export { InstallPwa, InstallPwaUi };
@@ -1,4 +1,5 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
+ import "../chunk-V4MHYKRI.js";
2
3
 
3
4
  // src/components/JsonEditor/index.ts
4
5
  import { JsonEditor } from "json-edit-react";
@@ -1,4 +1,5 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
+ import "../chunk-V4MHYKRI.js";
2
3
 
3
4
  // src/components/JsonView/index.ts
4
5
  import { JsonView } from "react-json-view-lite";
@@ -1,33 +1,30 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
+ import "../chunk-V4MHYKRI.js";
2
3
 
3
4
  // src/components/List/List.tsx
4
5
  import * as React from "react";
5
- import { jsx } from "react/jsx-runtime";
6
- var List = React.forwardRef(({
6
+ var List = /* @__PURE__ */React.forwardRef(({
7
7
  children,
8
8
  ...props
9
9
  }, ref) => {
10
- return /* @__PURE__ */jsx("ul", {
10
+ return /* @__PURE__ */React.createElement("ul", {
11
11
  ...props,
12
- ref,
13
- children
14
- });
12
+ ref
13
+ }, children);
15
14
  });
16
15
  List.displayName = "List";
17
16
 
18
17
  // src/components/List/ListItem.tsx
19
18
  import * as React2 from "react";
20
- import { jsx as jsx2 } from "react/jsx-runtime";
21
- var ListItem = React2.forwardRef((props, ref) => {
19
+ var ListItem = /* @__PURE__ */React2.forwardRef((props, ref) => {
22
20
  const {
23
21
  children,
24
22
  ...rest
25
23
  } = props;
26
- return /* @__PURE__ */jsx2("li", {
24
+ return /* @__PURE__ */React2.createElement("li", {
27
25
  ...rest,
28
- ref,
29
- children
30
- });
26
+ ref
27
+ }, children);
31
28
  });
32
29
  ListItem.displayName = "ListItem";
33
30
  export { List, ListItem };
@@ -1,24 +1,22 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
+ import { __name } from "../chunk-V4MHYKRI.js";
2
3
 
3
4
  // src/components/Markdown/Markdown.tsx
4
5
  import { BaseStyles } from "@ttoss/ui";
5
6
  import ReactMarkdown from "react-markdown";
6
7
  import rehypeRaw from "rehype-raw";
7
8
  import remarkGfm from "remark-gfm";
8
- import { jsx } from "react/jsx-runtime";
9
- var Markdown = ({
9
+ var Markdown = /* @__PURE__ */__name(({
10
10
  children,
11
11
  sx,
12
12
  ...props
13
13
  }) => {
14
- return /* @__PURE__ */jsx(BaseStyles, {
15
- sx,
16
- children: /* @__PURE__ */jsx(ReactMarkdown, {
17
- rehypePlugins: [rehypeRaw],
18
- remarkPlugins: [remarkGfm],
19
- ...props,
20
- children
21
- })
22
- });
23
- };
14
+ return /* @__PURE__ */React.createElement(BaseStyles, {
15
+ sx
16
+ }, /* @__PURE__ */React.createElement(ReactMarkdown, {
17
+ rehypePlugins: [rehypeRaw],
18
+ remarkPlugins: [remarkGfm],
19
+ ...props
20
+ }, children));
21
+ }, "Markdown");
24
22
  export { Markdown };