@veritone-ce/design-system 2.8.1 → 2.8.3
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/Dialog/components.js +4 -2
- package/dist/cjs/Drawer/components.js +4 -2
- package/dist/cjs/extras/uploady/index.js +12 -0
- package/dist/cjs/extras/uploady/uploady.js +112 -0
- package/dist/cjs/unstable/extras/dialogs/index.js +48 -0
- package/dist/cjs/unstable/extras/drawers/index.js +2 -13
- package/dist/esm/Dialog/components.js +4 -2
- package/dist/esm/Drawer/components.js +4 -2
- package/dist/esm/extras/uploady/index.js +2 -0
- package/dist/esm/extras/uploady/uploady.js +106 -0
- package/dist/esm/unstable/extras/dialogs/index.js +46 -0
- package/dist/esm/unstable/extras/drawers/index.js +4 -15
- package/dist/types/extras/uploady/index.d.ts +1 -0
- package/dist/types/unstable/extras/dialogs/index.d.ts +17 -0
- package/dist/types/unstable/extras/drawers/index.d.ts +0 -1
- package/dist/types/unstable/extras/forms/select.d.ts +2 -2
- package/dist/types/unstable/extras/forms/upload.d.ts +1 -1
- package/package.json +1 -1
|
@@ -20,6 +20,7 @@ require('../styles/css-vars.js');
|
|
|
20
20
|
var index$1 = require('../Button/index.js');
|
|
21
21
|
var index = require('../Typography/index.js');
|
|
22
22
|
var index$2 = require('../IconButton/index.js');
|
|
23
|
+
var internal = require('../Icon/internal.js');
|
|
23
24
|
|
|
24
25
|
function _interopNamespaceDefault(e) {
|
|
25
26
|
var n = Object.create(null);
|
|
@@ -221,7 +222,7 @@ const DialogCloseButton = React__namespace.forwardRef(function DialogCloseButton
|
|
|
221
222
|
}
|
|
222
223
|
);
|
|
223
224
|
});
|
|
224
|
-
const DialogCloseIconButton = React__namespace.forwardRef(function DialogCloseIconButton2(props, ref) {
|
|
225
|
+
const DialogCloseIconButton = React__namespace.forwardRef(function DialogCloseIconButton2({ children = /* @__PURE__ */ jsxRuntime.jsx(internal.CloseIcon, {}), ...props }, ref) {
|
|
225
226
|
const { dismiss } = state.useDialogContext();
|
|
226
227
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
227
228
|
index$2.default,
|
|
@@ -231,7 +232,8 @@ const DialogCloseIconButton = React__namespace.forwardRef(function DialogCloseIc
|
|
|
231
232
|
onClick: (e) => {
|
|
232
233
|
dismiss();
|
|
233
234
|
props.onClick?.(e);
|
|
234
|
-
}
|
|
235
|
+
},
|
|
236
|
+
children
|
|
235
237
|
}
|
|
236
238
|
);
|
|
237
239
|
});
|
|
@@ -20,6 +20,7 @@ require('../styles/css-vars.js');
|
|
|
20
20
|
var index$1 = require('../Button/index.js');
|
|
21
21
|
var index = require('../Typography/index.js');
|
|
22
22
|
var index$2 = require('../IconButton/index.js');
|
|
23
|
+
var internal = require('../Icon/internal.js');
|
|
23
24
|
|
|
24
25
|
function _interopNamespaceDefault(e) {
|
|
25
26
|
var n = Object.create(null);
|
|
@@ -262,7 +263,7 @@ const DrawerCloseButton = React__namespace.forwardRef(function DrawerCloseButton
|
|
|
262
263
|
}
|
|
263
264
|
);
|
|
264
265
|
});
|
|
265
|
-
const DrawerCloseIconButton = React__namespace.forwardRef(function DrawerCloseIconButton2(props, ref) {
|
|
266
|
+
const DrawerCloseIconButton = React__namespace.forwardRef(function DrawerCloseIconButton2({ children = /* @__PURE__ */ jsxRuntime.jsx(internal.CloseIcon, {}), ...props }, ref) {
|
|
266
267
|
const { dismiss } = state.useDrawerContext();
|
|
267
268
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
268
269
|
index$2.default,
|
|
@@ -272,7 +273,8 @@ const DrawerCloseIconButton = React__namespace.forwardRef(function DrawerCloseIc
|
|
|
272
273
|
onClick: (e) => {
|
|
273
274
|
dismiss();
|
|
274
275
|
props.onClick?.(e);
|
|
275
|
-
}
|
|
276
|
+
},
|
|
277
|
+
children
|
|
276
278
|
}
|
|
277
279
|
);
|
|
278
280
|
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var uploady = require('./uploady.js');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
exports.UploadyButton = uploady.UploadyButton;
|
|
9
|
+
exports.UploadyDropzone = uploady.UploadyDropzone;
|
|
10
|
+
exports.UploadyList = uploady.UploadyList;
|
|
11
|
+
exports.UploadyListItem = uploady.UploadyListItem;
|
|
12
|
+
exports.useUploadStatus = uploady.useUploadStatus;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
'use client';
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
var uploady = require('@rpldy/uploady');
|
|
8
|
+
var index = require('../../Button/index.js');
|
|
9
|
+
var controlled = require('../../FileUploader/controlled.js');
|
|
10
|
+
|
|
11
|
+
function UploadyDropzone(props) {
|
|
12
|
+
const { upload, getOptions } = uploady.useUploady();
|
|
13
|
+
const [batchState, setBatchState] = React.useState(
|
|
14
|
+
uploady.BATCH_STATES.PENDING
|
|
15
|
+
);
|
|
16
|
+
uploady.useBatchFinalizeListener((batch) => {
|
|
17
|
+
setBatchState(batch.state);
|
|
18
|
+
});
|
|
19
|
+
uploady.useBatchProgressListener((batch) => {
|
|
20
|
+
setBatchState(batch.state);
|
|
21
|
+
});
|
|
22
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
23
|
+
controlled.UploadDropzone,
|
|
24
|
+
{
|
|
25
|
+
...props,
|
|
26
|
+
multiple: !getOptions().autoUpload,
|
|
27
|
+
state: batchState === uploady.BATCH_STATES.PROCESSING ? controlled.FILE_STATES.UPLOADING : batchState,
|
|
28
|
+
onDrop: (files) => {
|
|
29
|
+
upload(files);
|
|
30
|
+
setBatchState(uploady.BATCH_STATES.PENDING);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
function UploadyList(props) {
|
|
36
|
+
const [items, setItems] = React.useState([]);
|
|
37
|
+
uploady.useBatchAddListener((batch) => {
|
|
38
|
+
setItems((items2) => items2.concat(batch.items));
|
|
39
|
+
});
|
|
40
|
+
return /* @__PURE__ */ jsxRuntime.jsx(controlled.UploadListContainer, { ...props, children: items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsx(UploadyListItem, { item }, index)) });
|
|
41
|
+
}
|
|
42
|
+
function UploadyListItem({ item }) {
|
|
43
|
+
const [itemState, setState] = React.useState(item.state);
|
|
44
|
+
const [progress, setProgress] = React.useState(0);
|
|
45
|
+
const abortItem = uploady.useAbortItem();
|
|
46
|
+
uploady.useItemFinalizeListener((item2) => {
|
|
47
|
+
setState(item2.state);
|
|
48
|
+
}, item.id);
|
|
49
|
+
uploady.useItemProgressListener((item2) => {
|
|
50
|
+
setProgress(item2.completed);
|
|
51
|
+
});
|
|
52
|
+
const onAbortItem = () => {
|
|
53
|
+
abortItem(item.id);
|
|
54
|
+
};
|
|
55
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
56
|
+
controlled.UploadListItem,
|
|
57
|
+
{
|
|
58
|
+
item: {
|
|
59
|
+
file: item.file,
|
|
60
|
+
progress,
|
|
61
|
+
state: itemState
|
|
62
|
+
},
|
|
63
|
+
onAbort: onAbortItem
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
function useUploadStatus() {
|
|
68
|
+
const [batchState, setBatchState] = React.useState(
|
|
69
|
+
uploady.BATCH_STATES.PENDING
|
|
70
|
+
);
|
|
71
|
+
const [itemCount, setItemCount] = React.useState(0);
|
|
72
|
+
uploady.useBatchAddListener((batch) => {
|
|
73
|
+
setItemCount(batch.total);
|
|
74
|
+
});
|
|
75
|
+
const [loading, setLoading] = React.useState(false);
|
|
76
|
+
uploady.useBatchStartListener(() => {
|
|
77
|
+
setLoading(true);
|
|
78
|
+
});
|
|
79
|
+
uploady.useBatchFinalizeListener((batch) => {
|
|
80
|
+
setLoading(false);
|
|
81
|
+
setBatchState(batch.state);
|
|
82
|
+
});
|
|
83
|
+
return { loading, itemCount, batchState };
|
|
84
|
+
}
|
|
85
|
+
const UploadyButton = React.forwardRef(function UploadButton({ children, onClick, disabled, ...props }, ref) {
|
|
86
|
+
const { processPending } = uploady.useUploadyContext();
|
|
87
|
+
const { itemCount, batchState, loading } = useUploadStatus();
|
|
88
|
+
const onButtonClick = React.useCallback(
|
|
89
|
+
(e) => {
|
|
90
|
+
processPending();
|
|
91
|
+
onClick?.(e);
|
|
92
|
+
},
|
|
93
|
+
[processPending, onClick]
|
|
94
|
+
);
|
|
95
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
96
|
+
index.default,
|
|
97
|
+
{
|
|
98
|
+
ref,
|
|
99
|
+
onClick: onButtonClick,
|
|
100
|
+
disabled: disabled || itemCount === 0 || batchState === uploady.BATCH_STATES.FINISHED,
|
|
101
|
+
loading,
|
|
102
|
+
...props,
|
|
103
|
+
children: children || "Upload"
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
exports.UploadyButton = UploadyButton;
|
|
109
|
+
exports.UploadyDropzone = UploadyDropzone;
|
|
110
|
+
exports.UploadyList = UploadyList;
|
|
111
|
+
exports.UploadyListItem = UploadyListItem;
|
|
112
|
+
exports.useUploadStatus = useUploadStatus;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
'use client';
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
var components = require('../../../Dialog/components.js');
|
|
8
|
+
var index = require('../../../ErrorBoundary/index.js');
|
|
9
|
+
var vanilla = require('../../../bundled_modules/jotai/esm/vanilla.js');
|
|
10
|
+
var react = require('../../../bundled_modules/jotai/esm/react.js');
|
|
11
|
+
|
|
12
|
+
function createDialog(config, store = vanilla.getDefaultStore()) {
|
|
13
|
+
const dialogAtom = vanilla.atom(false);
|
|
14
|
+
return {
|
|
15
|
+
Component: createBoundDialogComponent(dialogAtom, config),
|
|
16
|
+
useDialog: () => react.useAtom(dialogAtom),
|
|
17
|
+
setOpen(open) {
|
|
18
|
+
store.set(dialogAtom, open);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function createBoundDialogComponent(dialogAtom, config) {
|
|
23
|
+
return function BoundDialog() {
|
|
24
|
+
const [open, setOpen] = react.useAtom(dialogAtom);
|
|
25
|
+
const cachedOpenRef = React.useRef(open);
|
|
26
|
+
React.useEffect(() => {
|
|
27
|
+
if (open !== false) {
|
|
28
|
+
cachedOpenRef.current = open;
|
|
29
|
+
}
|
|
30
|
+
}, [open]);
|
|
31
|
+
const cachedOpen = cachedOpenRef.current !== false ? cachedOpenRef.current : open;
|
|
32
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
33
|
+
components.default,
|
|
34
|
+
{
|
|
35
|
+
...config.dialogProps,
|
|
36
|
+
open: open !== false,
|
|
37
|
+
onDismiss: () => {
|
|
38
|
+
setOpen(false);
|
|
39
|
+
config.dialogProps?.onDismiss?.();
|
|
40
|
+
},
|
|
41
|
+
className: config.dialogProps?.className,
|
|
42
|
+
children: cachedOpen !== false && /* @__PURE__ */ jsxRuntime.jsx(React.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(index.default, { children: /* @__PURE__ */ jsxRuntime.jsx(React.Suspense, { children: /* @__PURE__ */ jsxRuntime.jsx(config.Content, { open: cachedOpen }) }) }) }, JSON.stringify(cachedOpen))
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
exports.createDialog = createDialog;
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
var React = require('react');
|
|
7
7
|
var index_module = require('./index.module.scss.js');
|
|
8
|
-
var internal = require('../../../Icon/internal.js');
|
|
9
8
|
var components = require('../../../Drawer/components.js');
|
|
10
9
|
var cx = require('../../../styles/cx.js');
|
|
11
10
|
require('../../../styles/defaultThemeOptions.js');
|
|
@@ -38,7 +37,7 @@ function createBoundDrawerComponent(drawerAtom, config) {
|
|
|
38
37
|
}
|
|
39
38
|
}, [open]);
|
|
40
39
|
const cachedOpen = cachedOpenRef.current !== false ? cachedOpenRef.current : open;
|
|
41
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
40
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
42
41
|
components.default,
|
|
43
42
|
{
|
|
44
43
|
disableAutoFocus: true,
|
|
@@ -50,17 +49,7 @@ function createBoundDrawerComponent(drawerAtom, config) {
|
|
|
50
49
|
config.drawerProps?.onDismiss?.();
|
|
51
50
|
},
|
|
52
51
|
className: cx.cx(index_module.default.drawer, config.drawerProps?.className),
|
|
53
|
-
children:
|
|
54
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
55
|
-
components.DrawerTitle,
|
|
56
|
-
{
|
|
57
|
-
container: "text",
|
|
58
|
-
actions: /* @__PURE__ */ jsxRuntime.jsx(components.DrawerCloseIconButton, { variant: "primary", children: /* @__PURE__ */ jsxRuntime.jsx(internal.CloseIcon, {}) }),
|
|
59
|
-
children: config.title
|
|
60
|
-
}
|
|
61
|
-
),
|
|
62
|
-
cachedOpen !== false && /* @__PURE__ */ jsxRuntime.jsx(React.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(index.default, { children: /* @__PURE__ */ jsxRuntime.jsx(React.Suspense, { children: /* @__PURE__ */ jsxRuntime.jsx(config.Content, { open: cachedOpen }) }) }) }, JSON.stringify(cachedOpen))
|
|
63
|
-
]
|
|
52
|
+
children: cachedOpen !== false && /* @__PURE__ */ jsxRuntime.jsx(React.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(index.default, { children: /* @__PURE__ */ jsxRuntime.jsx(React.Suspense, { children: /* @__PURE__ */ jsxRuntime.jsx(config.Content, { open: cachedOpen }) }) }) }, JSON.stringify(cachedOpen))
|
|
64
53
|
}
|
|
65
54
|
);
|
|
66
55
|
};
|
|
@@ -16,6 +16,7 @@ import '../styles/css-vars.js';
|
|
|
16
16
|
import Button from '../Button/index.js';
|
|
17
17
|
import Typography from '../Typography/index.js';
|
|
18
18
|
import IconButton from '../IconButton/index.js';
|
|
19
|
+
import { CloseIcon } from '../Icon/internal.js';
|
|
19
20
|
|
|
20
21
|
const Dialog = React.forwardRef(function Dialog2({
|
|
21
22
|
children,
|
|
@@ -198,7 +199,7 @@ const DialogCloseButton = React.forwardRef(function DialogCloseButton2(props, re
|
|
|
198
199
|
}
|
|
199
200
|
);
|
|
200
201
|
});
|
|
201
|
-
const DialogCloseIconButton = React.forwardRef(function DialogCloseIconButton2(props, ref) {
|
|
202
|
+
const DialogCloseIconButton = React.forwardRef(function DialogCloseIconButton2({ children = /* @__PURE__ */ jsx(CloseIcon, {}), ...props }, ref) {
|
|
202
203
|
const { dismiss } = useDialogContext();
|
|
203
204
|
return /* @__PURE__ */ jsx(
|
|
204
205
|
IconButton,
|
|
@@ -208,7 +209,8 @@ const DialogCloseIconButton = React.forwardRef(function DialogCloseIconButton2(p
|
|
|
208
209
|
onClick: (e) => {
|
|
209
210
|
dismiss();
|
|
210
211
|
props.onClick?.(e);
|
|
211
|
-
}
|
|
212
|
+
},
|
|
213
|
+
children
|
|
212
214
|
}
|
|
213
215
|
);
|
|
214
216
|
});
|
|
@@ -16,6 +16,7 @@ import '../styles/css-vars.js';
|
|
|
16
16
|
import Button from '../Button/index.js';
|
|
17
17
|
import Typography from '../Typography/index.js';
|
|
18
18
|
import IconButton from '../IconButton/index.js';
|
|
19
|
+
import { CloseIcon } from '../Icon/internal.js';
|
|
19
20
|
|
|
20
21
|
const Drawer = React.forwardRef(function Drawer2({
|
|
21
22
|
placement = "end",
|
|
@@ -239,7 +240,7 @@ const DrawerCloseButton = React.forwardRef(function DrawerCloseButton2(props, re
|
|
|
239
240
|
}
|
|
240
241
|
);
|
|
241
242
|
});
|
|
242
|
-
const DrawerCloseIconButton = React.forwardRef(function DrawerCloseIconButton2(props, ref) {
|
|
243
|
+
const DrawerCloseIconButton = React.forwardRef(function DrawerCloseIconButton2({ children = /* @__PURE__ */ jsx(CloseIcon, {}), ...props }, ref) {
|
|
243
244
|
const { dismiss } = useDrawerContext();
|
|
244
245
|
return /* @__PURE__ */ jsx(
|
|
245
246
|
IconButton,
|
|
@@ -249,7 +250,8 @@ const DrawerCloseIconButton = React.forwardRef(function DrawerCloseIconButton2(p
|
|
|
249
250
|
onClick: (e) => {
|
|
250
251
|
dismiss();
|
|
251
252
|
props.onClick?.(e);
|
|
252
|
-
}
|
|
253
|
+
},
|
|
254
|
+
children
|
|
253
255
|
}
|
|
254
256
|
);
|
|
255
257
|
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
'use client';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
import React__default, { useCallback, useState } from 'react';
|
|
5
|
+
import { useUploadyContext, BATCH_STATES, useBatchAddListener, useBatchStartListener, useBatchFinalizeListener, useUploady, useBatchProgressListener, useAbortItem, useItemFinalizeListener, useItemProgressListener } from '@rpldy/uploady';
|
|
6
|
+
import Button from '../../Button/index.js';
|
|
7
|
+
import { UploadDropzone, FILE_STATES, UploadListContainer, UploadListItem } from '../../FileUploader/controlled.js';
|
|
8
|
+
|
|
9
|
+
function UploadyDropzone(props) {
|
|
10
|
+
const { upload, getOptions } = useUploady();
|
|
11
|
+
const [batchState, setBatchState] = useState(
|
|
12
|
+
BATCH_STATES.PENDING
|
|
13
|
+
);
|
|
14
|
+
useBatchFinalizeListener((batch) => {
|
|
15
|
+
setBatchState(batch.state);
|
|
16
|
+
});
|
|
17
|
+
useBatchProgressListener((batch) => {
|
|
18
|
+
setBatchState(batch.state);
|
|
19
|
+
});
|
|
20
|
+
return /* @__PURE__ */ jsx(
|
|
21
|
+
UploadDropzone,
|
|
22
|
+
{
|
|
23
|
+
...props,
|
|
24
|
+
multiple: !getOptions().autoUpload,
|
|
25
|
+
state: batchState === BATCH_STATES.PROCESSING ? FILE_STATES.UPLOADING : batchState,
|
|
26
|
+
onDrop: (files) => {
|
|
27
|
+
upload(files);
|
|
28
|
+
setBatchState(BATCH_STATES.PENDING);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
function UploadyList(props) {
|
|
34
|
+
const [items, setItems] = useState([]);
|
|
35
|
+
useBatchAddListener((batch) => {
|
|
36
|
+
setItems((items2) => items2.concat(batch.items));
|
|
37
|
+
});
|
|
38
|
+
return /* @__PURE__ */ jsx(UploadListContainer, { ...props, children: items.map((item, index) => /* @__PURE__ */ jsx(UploadyListItem, { item }, index)) });
|
|
39
|
+
}
|
|
40
|
+
function UploadyListItem({ item }) {
|
|
41
|
+
const [itemState, setState] = useState(item.state);
|
|
42
|
+
const [progress, setProgress] = useState(0);
|
|
43
|
+
const abortItem = useAbortItem();
|
|
44
|
+
useItemFinalizeListener((item2) => {
|
|
45
|
+
setState(item2.state);
|
|
46
|
+
}, item.id);
|
|
47
|
+
useItemProgressListener((item2) => {
|
|
48
|
+
setProgress(item2.completed);
|
|
49
|
+
});
|
|
50
|
+
const onAbortItem = () => {
|
|
51
|
+
abortItem(item.id);
|
|
52
|
+
};
|
|
53
|
+
return /* @__PURE__ */ jsx(
|
|
54
|
+
UploadListItem,
|
|
55
|
+
{
|
|
56
|
+
item: {
|
|
57
|
+
file: item.file,
|
|
58
|
+
progress,
|
|
59
|
+
state: itemState
|
|
60
|
+
},
|
|
61
|
+
onAbort: onAbortItem
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
function useUploadStatus() {
|
|
66
|
+
const [batchState, setBatchState] = useState(
|
|
67
|
+
BATCH_STATES.PENDING
|
|
68
|
+
);
|
|
69
|
+
const [itemCount, setItemCount] = useState(0);
|
|
70
|
+
useBatchAddListener((batch) => {
|
|
71
|
+
setItemCount(batch.total);
|
|
72
|
+
});
|
|
73
|
+
const [loading, setLoading] = useState(false);
|
|
74
|
+
useBatchStartListener(() => {
|
|
75
|
+
setLoading(true);
|
|
76
|
+
});
|
|
77
|
+
useBatchFinalizeListener((batch) => {
|
|
78
|
+
setLoading(false);
|
|
79
|
+
setBatchState(batch.state);
|
|
80
|
+
});
|
|
81
|
+
return { loading, itemCount, batchState };
|
|
82
|
+
}
|
|
83
|
+
const UploadyButton = React__default.forwardRef(function UploadButton({ children, onClick, disabled, ...props }, ref) {
|
|
84
|
+
const { processPending } = useUploadyContext();
|
|
85
|
+
const { itemCount, batchState, loading } = useUploadStatus();
|
|
86
|
+
const onButtonClick = useCallback(
|
|
87
|
+
(e) => {
|
|
88
|
+
processPending();
|
|
89
|
+
onClick?.(e);
|
|
90
|
+
},
|
|
91
|
+
[processPending, onClick]
|
|
92
|
+
);
|
|
93
|
+
return /* @__PURE__ */ jsx(
|
|
94
|
+
Button,
|
|
95
|
+
{
|
|
96
|
+
ref,
|
|
97
|
+
onClick: onButtonClick,
|
|
98
|
+
disabled: disabled || itemCount === 0 || batchState === BATCH_STATES.FINISHED,
|
|
99
|
+
loading,
|
|
100
|
+
...props,
|
|
101
|
+
children: children || "Upload"
|
|
102
|
+
}
|
|
103
|
+
);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
export { UploadyButton, UploadyDropzone, UploadyList, UploadyListItem, useUploadStatus };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
'use client';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
import { useRef, useEffect, Fragment, Suspense } from 'react';
|
|
5
|
+
import Dialog from '../../../Dialog/components.js';
|
|
6
|
+
import ErrorBoundary from '../../../ErrorBoundary/index.js';
|
|
7
|
+
import { getDefaultStore, atom } from '../../../bundled_modules/jotai/esm/vanilla.js';
|
|
8
|
+
import { useAtom } from '../../../bundled_modules/jotai/esm/react.js';
|
|
9
|
+
|
|
10
|
+
function createDialog(config, store = getDefaultStore()) {
|
|
11
|
+
const dialogAtom = atom(false);
|
|
12
|
+
return {
|
|
13
|
+
Component: createBoundDialogComponent(dialogAtom, config),
|
|
14
|
+
useDialog: () => useAtom(dialogAtom),
|
|
15
|
+
setOpen(open) {
|
|
16
|
+
store.set(dialogAtom, open);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function createBoundDialogComponent(dialogAtom, config) {
|
|
21
|
+
return function BoundDialog() {
|
|
22
|
+
const [open, setOpen] = useAtom(dialogAtom);
|
|
23
|
+
const cachedOpenRef = useRef(open);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (open !== false) {
|
|
26
|
+
cachedOpenRef.current = open;
|
|
27
|
+
}
|
|
28
|
+
}, [open]);
|
|
29
|
+
const cachedOpen = cachedOpenRef.current !== false ? cachedOpenRef.current : open;
|
|
30
|
+
return /* @__PURE__ */ jsx(
|
|
31
|
+
Dialog,
|
|
32
|
+
{
|
|
33
|
+
...config.dialogProps,
|
|
34
|
+
open: open !== false,
|
|
35
|
+
onDismiss: () => {
|
|
36
|
+
setOpen(false);
|
|
37
|
+
config.dialogProps?.onDismiss?.();
|
|
38
|
+
},
|
|
39
|
+
className: config.dialogProps?.className,
|
|
40
|
+
children: cachedOpen !== false && /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(ErrorBoundary, { children: /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(config.Content, { open: cachedOpen }) }) }) }, JSON.stringify(cachedOpen))
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { createDialog };
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
'use client';
|
|
3
|
-
import {
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
4
|
import { useRef, useEffect, Fragment, Suspense } from 'react';
|
|
5
5
|
import styles from './index.module.scss.js';
|
|
6
|
-
import
|
|
7
|
-
import Drawer, { DrawerTitle, DrawerCloseIconButton } from '../../../Drawer/components.js';
|
|
6
|
+
import Drawer from '../../../Drawer/components.js';
|
|
8
7
|
import { cx } from '../../../styles/cx.js';
|
|
9
8
|
import '../../../styles/defaultThemeOptions.js';
|
|
10
9
|
import '@capsizecss/core';
|
|
@@ -36,7 +35,7 @@ function createBoundDrawerComponent(drawerAtom, config) {
|
|
|
36
35
|
}
|
|
37
36
|
}, [open]);
|
|
38
37
|
const cachedOpen = cachedOpenRef.current !== false ? cachedOpenRef.current : open;
|
|
39
|
-
return /* @__PURE__ */
|
|
38
|
+
return /* @__PURE__ */ jsx(
|
|
40
39
|
Drawer,
|
|
41
40
|
{
|
|
42
41
|
disableAutoFocus: true,
|
|
@@ -48,17 +47,7 @@ function createBoundDrawerComponent(drawerAtom, config) {
|
|
|
48
47
|
config.drawerProps?.onDismiss?.();
|
|
49
48
|
},
|
|
50
49
|
className: cx(styles.drawer, config.drawerProps?.className),
|
|
51
|
-
children:
|
|
52
|
-
/* @__PURE__ */ jsx(
|
|
53
|
-
DrawerTitle,
|
|
54
|
-
{
|
|
55
|
-
container: "text",
|
|
56
|
-
actions: /* @__PURE__ */ jsx(DrawerCloseIconButton, { variant: "primary", children: /* @__PURE__ */ jsx(CloseIcon, {}) }),
|
|
57
|
-
children: config.title
|
|
58
|
-
}
|
|
59
|
-
),
|
|
60
|
-
cachedOpen !== false && /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(ErrorBoundary, { children: /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(config.Content, { open: cachedOpen }) }) }) }, JSON.stringify(cachedOpen))
|
|
61
|
-
]
|
|
50
|
+
children: cachedOpen !== false && /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(ErrorBoundary, { children: /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(config.Content, { open: cachedOpen }) }) }) }, JSON.stringify(cachedOpen))
|
|
62
51
|
}
|
|
63
52
|
);
|
|
64
53
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './uploady.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createStore } from 'jotai';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { type DialogProps } from '../../../Dialog/index.js';
|
|
4
|
+
export type DialogAtom<O> = O | false;
|
|
5
|
+
export type OpenDialogContentProps<O> = {
|
|
6
|
+
open: O;
|
|
7
|
+
};
|
|
8
|
+
export type OpenDialogContentComponent<O> = (props: OpenDialogContentProps<O>) => ReactNode;
|
|
9
|
+
export type DialogConfig<O> = {
|
|
10
|
+
Content: OpenDialogContentComponent<O>;
|
|
11
|
+
dialogProps?: Partial<Omit<DialogProps, 'open' | 'children'>>;
|
|
12
|
+
};
|
|
13
|
+
export declare function createDialog<O = true>(config: DialogConfig<O>, store?: ReturnType<typeof createStore>): {
|
|
14
|
+
Component: () => import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
useDialog: () => [false | Awaited<O>, (args_0: DialogAtom<O> | ((prev: DialogAtom<O>) => DialogAtom<O>)) => void];
|
|
16
|
+
setOpen(open: DialogAtom<O>): void;
|
|
17
|
+
};
|
|
@@ -7,7 +7,6 @@ export type OpenDrawerContentProps<O> = {
|
|
|
7
7
|
};
|
|
8
8
|
export type OpenDrawerContentComponent<O> = (props: OpenDrawerContentProps<O>) => ReactNode;
|
|
9
9
|
export type DrawerConfig<O> = {
|
|
10
|
-
title: ReactNode;
|
|
11
10
|
Content: OpenDrawerContentComponent<O>;
|
|
12
11
|
drawerProps?: Partial<Omit<DrawerProps, 'open' | 'children'>>;
|
|
13
12
|
};
|
|
@@ -4,5 +4,5 @@ import { SelectProps } from '../../../Select/index.js';
|
|
|
4
4
|
import type { ComponentType } from 'react';
|
|
5
5
|
export type FormSelectControlledProps<OptionValue, Multiple extends boolean | undefined> = Pick<SelectProps<OptionValue, Multiple>, 'value' | 'onChange'>;
|
|
6
6
|
export type FormSelectProps<TFieldValues extends FieldValues, OptionValue, Multiple extends boolean | undefined, S extends FormSelectControlledProps<OptionValue, Multiple>, TName extends FieldPathByValue<TFieldValues, OptionValue | OptionValue[]> = FieldPathByValue<TFieldValues, OptionValue | OptionValue[]>> = UseControllerProps<TFieldValues, TName> & FormControlProps & S;
|
|
7
|
-
export declare function formSelectFactory<OptionValue,
|
|
8
|
-
export declare const FormSelect: <TFieldValues extends FieldValues, TName extends FieldPathByValue<TFieldValues, unknown> = FieldPathByValue<TFieldValues, unknown>>(props: FormSelectProps<TFieldValues, unknown,
|
|
7
|
+
export declare function formSelectFactory<OptionValue, S extends FormSelectControlledProps<OptionValue, boolean | undefined> = FormSelectControlledProps<OptionValue, boolean | undefined>>(Component: ComponentType<S>): <Multiple extends boolean | undefined, TFieldValues extends FieldValues, TName extends FieldPathByValue<TFieldValues, OptionValue | OptionValue[]> = FieldPathByValue<TFieldValues, OptionValue | OptionValue[]>>(props: FormSelectProps<TFieldValues, OptionValue, Multiple, S, TName>) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export declare const FormSelect: <Multiple extends boolean | undefined, TFieldValues extends FieldValues, TName extends FieldPathByValue<TFieldValues, unknown> = FieldPathByValue<TFieldValues, unknown>>(props: FormSelectProps<TFieldValues, unknown, Multiple, SelectProps<unknown, boolean | undefined>, TName>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type FieldPathByValue, FieldValues, UseControllerProps } from 'react-hook-form';
|
|
2
2
|
import type { FormControlProps } from '../../../FormControl/index.js';
|
|
3
3
|
import { type FileLike, type FileState, type UploadDropzoneProps, type UploadListItemState, type UploadListProps } from '../../../FileUploader/index.js';
|
|
4
|
-
type FilesFieldPath<TFieldValues extends FieldValues, F extends FileLike = FileLike> = FieldPathByValue<TFieldValues, F[]>;
|
|
4
|
+
type FilesFieldPath<TFieldValues extends FieldValues, F extends FileLike = FileLike> = FieldPathByValue<TFieldValues, F | F[]>;
|
|
5
5
|
type FormUploadDropzoneInputProps = Partial<UploadDropzoneProps> & Omit<UploadDropzoneProps, 'onDrop'>;
|
|
6
6
|
export type FormUploadDropzoneProps<TFieldValues extends FieldValues, TName extends FilesFieldPath<TFieldValues> = FilesFieldPath<TFieldValues>> = UseControllerProps<TFieldValues, TName> & FormControlProps & FormUploadDropzoneInputProps;
|
|
7
7
|
export declare function FormUploadDropzone<TFieldValues extends FieldValues, TName extends FilesFieldPath<TFieldValues> = FilesFieldPath<TFieldValues>>(props: FormUploadDropzoneProps<TFieldValues, TName>): import("react/jsx-runtime").JSX.Element;
|