@worknice/whiteboard 0.42.1 → 0.43.0
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/forms/useForm.js +14 -28
- package/dist/presentation/ProgressBar.d.ts +9 -0
- package/dist/presentation/ProgressBar.js +21 -0
- package/dist/presentation/ProgressBar.module.js +6 -0
- package/dist/presentation/ProgressBar.stories.d.ts +28 -0
- package/dist/presentation/ProgressBar.stories.js +44 -0
- package/dist/presentation/ProgressBar_module.css +15 -0
- package/package.json +2 -2
package/dist/forms/useForm.js
CHANGED
|
@@ -2,26 +2,31 @@ import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
|
|
|
2
2
|
import * as __WEBPACK_EXTERNAL_MODULE_uuid__ from "uuid";
|
|
3
3
|
import * as __WEBPACK_EXTERNAL_MODULE__FormError_js_149fc952__ from "./FormError.js";
|
|
4
4
|
const useForm = ({ initialValues, onSubmit, onSuccess, validators })=>{
|
|
5
|
-
const
|
|
5
|
+
const statusTimeout = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(void 0);
|
|
6
|
+
(0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>()=>clearTimeout(statusTimeout.current), []);
|
|
6
7
|
const [status, setStatus] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)("fresh");
|
|
7
8
|
const [data, setData] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(initialValues);
|
|
8
9
|
const [errors, setErrors] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)([]);
|
|
10
|
+
const transitionStatus = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((newStatus)=>{
|
|
11
|
+
clearTimeout(statusTimeout.current);
|
|
12
|
+
setStatus(newStatus);
|
|
13
|
+
if ("success" === newStatus || "errored" === newStatus) statusTimeout.current = setTimeout(()=>setStatus("modified"), 1000);
|
|
14
|
+
}, [
|
|
15
|
+
setStatus
|
|
16
|
+
]);
|
|
9
17
|
const submit = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)(async (event)=>{
|
|
10
|
-
|
|
18
|
+
transitionStatus("loading");
|
|
11
19
|
event?.preventDefault();
|
|
12
20
|
setErrors([]);
|
|
13
21
|
const validationErrors = await Promise.all((validators ?? []).map((validator)=>validatorToValidationErrors(data, validator)));
|
|
14
22
|
const flatValidationErrors = validationErrors.flat();
|
|
15
23
|
if (flatValidationErrors.length > 0) {
|
|
16
|
-
await sleep(250, ()=>setStatus("modified"));
|
|
17
24
|
setErrors(flatValidationErrors);
|
|
18
|
-
|
|
19
|
-
await sleep(1000, ()=>setStatus("modified"));
|
|
25
|
+
transitionStatus("errored");
|
|
20
26
|
} else try {
|
|
21
27
|
const result = await onSubmit(data);
|
|
22
|
-
setStatus("success");
|
|
23
|
-
await sleep(1000, ()=>setStatus("modified"));
|
|
24
28
|
if (onSuccess) await onSuccess(result);
|
|
29
|
+
transitionStatus("success");
|
|
25
30
|
} catch (error) {
|
|
26
31
|
if (error instanceof __WEBPACK_EXTERNAL_MODULE__FormError_js_149fc952__["default"]) setErrors(error.validationErrors);
|
|
27
32
|
else error instanceof Error ? setErrors([
|
|
@@ -35,14 +40,13 @@ const useForm = ({ initialValues, onSubmit, onSuccess, validators })=>{
|
|
|
35
40
|
message: "Unknown error."
|
|
36
41
|
}
|
|
37
42
|
]);
|
|
38
|
-
|
|
39
|
-
await sleep(1000, ()=>setStatus("modified"));
|
|
43
|
+
transitionStatus("errored");
|
|
40
44
|
}
|
|
41
45
|
}, [
|
|
42
46
|
data,
|
|
43
47
|
onSubmit,
|
|
44
48
|
onSuccess,
|
|
45
|
-
|
|
49
|
+
transitionStatus,
|
|
46
50
|
validators
|
|
47
51
|
]);
|
|
48
52
|
const fieldErrors = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>Object.fromEntries(Object.keys(initialValues).map((key)=>[
|
|
@@ -83,24 +87,6 @@ const useForm = ({ initialValues, onSubmit, onSuccess, validators })=>{
|
|
|
83
87
|
reset
|
|
84
88
|
};
|
|
85
89
|
};
|
|
86
|
-
const useSleep = ()=>{
|
|
87
|
-
const timeout = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(void 0);
|
|
88
|
-
(0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>()=>{
|
|
89
|
-
if (timeout.current) {
|
|
90
|
-
clearTimeout(timeout.current.id);
|
|
91
|
-
if (timeout.current.finalFn) timeout.current.finalFn();
|
|
92
|
-
}
|
|
93
|
-
}, []);
|
|
94
|
-
return (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)(async (ms, finalFn)=>{
|
|
95
|
-
if (timeout.current) clearTimeout(timeout.current.id);
|
|
96
|
-
await new Promise((resolve)=>{
|
|
97
|
-
timeout.current = {
|
|
98
|
-
id: setTimeout(resolve, ms),
|
|
99
|
-
finalFn
|
|
100
|
-
};
|
|
101
|
-
});
|
|
102
|
-
}, []);
|
|
103
|
-
};
|
|
104
90
|
const validatorToValidationErrors = async (data, validator)=>{
|
|
105
91
|
if (null === validator) return [];
|
|
106
92
|
if (Array.isArray(validator)) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type Props = {
|
|
2
|
+
/** Progress from 0 to 1 (e.g. 0.4 for 40%) */
|
|
3
|
+
percentage: number;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Renders a horizontal progress bar with light green fill and rounded sides.
|
|
7
|
+
*/
|
|
8
|
+
declare const ProgressBar: ({ percentage }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export default ProgressBar;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/jsx-runtime";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE__ProgressBar_module_js_913c4023__ from "./ProgressBar.module.js";
|
|
3
|
+
const ProgressBar = ({ percentage })=>{
|
|
4
|
+
const clamped = Math.max(0, Math.min(1, percentage)) || 0;
|
|
5
|
+
const percent = 100 * clamped;
|
|
6
|
+
return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("div", {
|
|
7
|
+
className: __WEBPACK_EXTERNAL_MODULE__ProgressBar_module_js_913c4023__["default"].track,
|
|
8
|
+
role: "progressbar",
|
|
9
|
+
"aria-valuenow": percent,
|
|
10
|
+
"aria-valuemin": 0,
|
|
11
|
+
"aria-valuemax": 100,
|
|
12
|
+
children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("div", {
|
|
13
|
+
className: __WEBPACK_EXTERNAL_MODULE__ProgressBar_module_js_913c4023__["default"].fill,
|
|
14
|
+
style: {
|
|
15
|
+
width: `${percent}%`
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
const ProgressBar_rslib_entry_ = ProgressBar;
|
|
21
|
+
export { ProgressBar_rslib_entry_ as default };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { StoryObj } from "@storybook/nextjs-vite";
|
|
2
|
+
declare const meta: {
|
|
3
|
+
component: ({ percentage }: {
|
|
4
|
+
percentage: number;
|
|
5
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
args: {
|
|
7
|
+
percentage: number;
|
|
8
|
+
};
|
|
9
|
+
argTypes: {
|
|
10
|
+
percentage: {
|
|
11
|
+
control: {
|
|
12
|
+
type: "range";
|
|
13
|
+
min: number;
|
|
14
|
+
max: number;
|
|
15
|
+
step: number;
|
|
16
|
+
};
|
|
17
|
+
description: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
decorators: ((Story: import("storybook/internal/csf").PartialStoryFn<import("@storybook/nextjs-vite").ReactRenderer, {
|
|
21
|
+
percentage: number;
|
|
22
|
+
}>) => import("react/jsx-runtime").JSX.Element)[];
|
|
23
|
+
};
|
|
24
|
+
export default meta;
|
|
25
|
+
type Story = StoryObj<typeof meta>;
|
|
26
|
+
export declare const Default: Story;
|
|
27
|
+
export declare const Empty: Story;
|
|
28
|
+
export declare const Full: Story;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/jsx-runtime";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE__ProgressBar_js_0e285d3e__ from "./ProgressBar.js";
|
|
3
|
+
const meta = {
|
|
4
|
+
component: __WEBPACK_EXTERNAL_MODULE__ProgressBar_js_0e285d3e__["default"],
|
|
5
|
+
args: {
|
|
6
|
+
percentage: 0.6
|
|
7
|
+
},
|
|
8
|
+
argTypes: {
|
|
9
|
+
percentage: {
|
|
10
|
+
control: {
|
|
11
|
+
type: "range",
|
|
12
|
+
min: 0,
|
|
13
|
+
max: 1,
|
|
14
|
+
step: 0.01
|
|
15
|
+
},
|
|
16
|
+
description: "Progress from 0 to 1"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
decorators: [
|
|
20
|
+
(Story)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("div", {
|
|
21
|
+
style: {
|
|
22
|
+
width: 200
|
|
23
|
+
},
|
|
24
|
+
children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(Story, {})
|
|
25
|
+
})
|
|
26
|
+
]
|
|
27
|
+
};
|
|
28
|
+
const ProgressBar_stories_rslib_entry_ = meta;
|
|
29
|
+
const Default = {
|
|
30
|
+
args: {
|
|
31
|
+
percentage: 0.6
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const Empty = {
|
|
35
|
+
args: {
|
|
36
|
+
percentage: 0
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const Full = {
|
|
40
|
+
args: {
|
|
41
|
+
percentage: 1
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
export { Default, Empty, Full, ProgressBar_stories_rslib_entry_ as default };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
.track-q0A2R3 {
|
|
2
|
+
width: 100%;
|
|
3
|
+
height: var(--size-n1);
|
|
4
|
+
background-color: var(--color-grey-t09);
|
|
5
|
+
border-radius: var(--size-n2);
|
|
6
|
+
overflow: hidden;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.fill-ureadD {
|
|
10
|
+
background-color: var(--color-green-t07);
|
|
11
|
+
border-radius: var(--size-n2);
|
|
12
|
+
height: 100%;
|
|
13
|
+
transition: width .2s;
|
|
14
|
+
}
|
|
15
|
+
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@worknice/whiteboard",
|
|
3
3
|
"description": "",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.43.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
7
7
|
"files": [
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"react-markdown": "^10.1.0",
|
|
40
40
|
"utf8": "^3.0.0",
|
|
41
41
|
"zod": "^4.1.13",
|
|
42
|
-
"@worknice/utils": "^0.
|
|
42
|
+
"@worknice/utils": "^0.26.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@anolilab/semantic-release-pnpm": "^3.2.2",
|