@kirill.konshin/bootstrap 0.0.2 → 0.0.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/adaptiveContainer.d.ts.map +1 -1
- package/dist/adaptiveContainer.js +14 -9
- package/dist/adaptiveContainer.js.map +1 -1
- package/dist/adaptiveContainer.stories.d.ts +2 -2
- package/dist/adaptiveContainer.stories.d.ts.map +1 -1
- package/dist/controls.d.ts +4 -4
- package/dist/controls.d.ts.map +1 -1
- package/dist/controls.js +79 -72
- package/dist/controls.js.map +1 -1
- package/dist/controls.stories.d.ts +2 -2
- package/dist/controls.stories.d.ts.map +1 -1
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +23 -24
- package/dist/error.js.map +1 -1
- package/dist/error.stories.d.ts +2 -2
- package/dist/error.stories.d.ts.map +1 -1
- package/dist/field.d.ts.map +1 -1
- package/dist/field.js +27 -27
- package/dist/field.js.map +1 -1
- package/dist/field.stories.d.ts +2 -2
- package/dist/field.stories.d.ts.map +1 -1
- package/dist/footer.d.ts.map +1 -1
- package/dist/footer.js +41 -42
- package/dist/footer.js.map +1 -1
- package/dist/footer.stories.d.ts +2 -2
- package/dist/footer.stories.d.ts.map +1 -1
- package/dist/globalLoading.d.ts.map +1 -1
- package/dist/globalLoading.js +13 -9
- package/dist/globalLoading.js.map +1 -1
- package/dist/globalLoading.stories.d.ts +2 -2
- package/dist/globalLoading.stories.d.ts.map +1 -1
- package/dist/index.d.ts +12 -12
- package/dist/index.js +3 -25
- package/dist/loading.d.ts.map +1 -1
- package/dist/loading.js +19 -17
- package/dist/loading.js.map +1 -1
- package/dist/loading.stories.d.ts +2 -2
- package/dist/loading.stories.d.ts.map +1 -1
- package/dist/responsiveHelper.d.ts.map +1 -1
- package/dist/responsiveHelper.js +69 -42
- package/dist/responsiveHelper.js.map +1 -1
- package/dist/responsiveHelper.stories.d.ts +2 -2
- package/dist/responsiveHelper.stories.d.ts.map +1 -1
- package/dist/screen.d.ts.map +1 -1
- package/dist/screen.js +84 -77
- package/dist/screen.js.map +1 -1
- package/dist/screen.stories.d.ts +2 -2
- package/dist/screen.stories.d.ts.map +1 -1
- package/dist/toaster.d.ts.map +1 -1
- package/dist/toaster.js +29 -30
- package/dist/toaster.js.map +1 -1
- package/dist/toaster.stories.d.ts +2 -2
- package/dist/toaster.stories.d.ts.map +1 -1
- package/dist/useModal.d.ts.map +1 -1
- package/dist/useModal.js +58 -47
- package/dist/useModal.js.map +1 -1
- package/dist/useModal.stories.d.ts +2 -2
- package/dist/useModal.stories.d.ts.map +1 -1
- package/dist/useWrappedForm.d.ts.map +1 -1
- package/dist/useWrappedForm.js +40 -29
- package/dist/useWrappedForm.js.map +1 -1
- package/package.json +17 -5
- package/.ctirc +0 -20
- package/.storybook/main.ts +0 -2
- package/.storybook/preview.ts +0 -2
- package/.turbo/turbo-build.log +0 -31
- package/CHANGELOG.md +0 -8
- package/dist/index.js.map +0 -1
- package/src/adaptiveContainer.stories.tsx +0 -59
- package/src/adaptiveContainer.tsx +0 -14
- package/src/controls.stories.tsx +0 -62
- package/src/controls.tsx +0 -119
- package/src/error.stories.tsx +0 -34
- package/src/error.tsx +0 -37
- package/src/field.stories.tsx +0 -42
- package/src/field.tsx +0 -37
- package/src/footer.stories.tsx +0 -121
- package/src/footer.tsx +0 -65
- package/src/globalLoading.stories.tsx +0 -25
- package/src/globalLoading.tsx +0 -19
- package/src/index.ts +0 -12
- package/src/loading.stories.tsx +0 -35
- package/src/loading.tsx +0 -24
- package/src/main.scss +0 -86
- package/src/responsiveHelper.stories.tsx +0 -109
- package/src/responsiveHelper.tsx +0 -55
- package/src/screen.stories.tsx +0 -160
- package/src/screen.tsx +0 -146
- package/src/toaster.stories.tsx +0 -32
- package/src/toaster.tsx +0 -40
- package/src/useModal.stories.tsx +0 -51
- package/src/useModal.tsx +0 -93
- package/src/useWrappedForm.ts +0 -42
- package/tsconfig.json +0 -10
- package/turbo.json +0 -10
- package/vite.config.ts +0 -2
package/dist/toaster.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toaster.d.ts","sourceRoot":"","sources":["../src/toaster.tsx"],"names":[],"mappings":"AAEA,OAAc,EAAY,EAAE,EAAQ,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"toaster.d.ts","sourceRoot":"","sources":["../src/toaster.tsx"],"names":[],"mappings":"AAEA,OAAc,EAAY,KAAK,EAAE,EAAQ,MAAM,OAAO,CAAC;AACvD,OAAO,EAAS,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGzD,MAAM,MAAM,YAAY,GAAG;IACvB,KAAK,EAAE,MAAM,GAAG;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,QAAQ,CAAA;KAAE,CAAC;CAChG,GAAG,UAAU,CAAC;AAEf,eAAO,MAAM,OAAO,EAAE,EAAE,CAAC,YAAY,CA6BnC,CAAC"}
|
package/dist/toaster.js
CHANGED
|
@@ -1,34 +1,33 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsxs, jsx } from "react/jsx-runtime";
|
|
3
2
|
import { memo, useState } from "react";
|
|
4
3
|
import { Toast } from "react-bootstrap";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
//#region src/toaster.tsx
|
|
6
|
+
var Toaster = memo(function Toaster({ toast }) {
|
|
7
|
+
const [dismissed, setDismissed] = useState(false);
|
|
8
|
+
const msg = typeof toast === "string" ? toast : toast?.message;
|
|
9
|
+
const variant = typeof toast === "string" ? "" : toast?.variant;
|
|
10
|
+
return /* @__PURE__ */ jsxs(Toast, {
|
|
11
|
+
onClose: () => setDismissed(true),
|
|
12
|
+
show: !dismissed,
|
|
13
|
+
delay: 1e4,
|
|
14
|
+
autohide: true,
|
|
15
|
+
bg: variant?.toLowerCase(),
|
|
16
|
+
className: "position-fixed top-50 right-50 min-w-200px z-3",
|
|
17
|
+
children: [/* @__PURE__ */ jsx(Toast.Header, { children: /* @__PURE__ */ jsx("strong", {
|
|
18
|
+
className: "me-auto",
|
|
19
|
+
children: "Notification"
|
|
20
|
+
}) }), /* @__PURE__ */ jsx(Toast.Body, {
|
|
21
|
+
className: [
|
|
22
|
+
"dark",
|
|
23
|
+
"success",
|
|
24
|
+
"danger"
|
|
25
|
+
].includes(variant?.toLowerCase()) ? "text-white" : "",
|
|
26
|
+
children: msg
|
|
27
|
+
})]
|
|
28
|
+
});
|
|
30
29
|
});
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
//# sourceMappingURL=toaster.js.map
|
|
30
|
+
//#endregion
|
|
31
|
+
export { Toaster };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=toaster.js.map
|
package/dist/toaster.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toaster.js","sources":["../src/toaster.tsx"],"sourcesContent":["'use client';\n\nimport React, { useState, FC, memo } from 'react';\nimport { Toast, ToastProps } from 'react-bootstrap';\n// import { useToaster } from '../redux/toasterSlice';\n\nexport type ToasterProps = {\n toast: string | { message: string; title?: string; variant?: 'dark' | 'success' | 'danger' };\n} & ToastProps;\n\nexport const Toaster: FC<ToasterProps> = memo(function Toaster({ toast }) {\n //const { toast, setToast } = useToaster();\n const [dismissed, setDismissed] = useState(false);\n\n const msg = typeof toast === 'string' ? toast : toast?.message;\n // const title = typeof toast === 'string' ? 'Notification' : toast?.title;\n const variant = typeof toast === 'string' ? '' : toast?.variant;\n\n return (\n <Toast\n onClose={() => setDismissed(true)}\n show={!dismissed}\n delay={10000}\n autohide\n bg={variant?.toLowerCase()}\n className=\"position-fixed top-50 right-50 min-w-200px z-3\"\n >\n <Toast.Header>\n <strong className=\"me-auto\">Notification</strong>\n </Toast.Header>\n <Toast.Body\n className={\n ['dark', 'success', 'danger'].includes((variant as string)?.toLowerCase()) ? 'text-white' : ''\n }\n >\n {msg}\n </Toast.Body>\n </Toast>\n );\n});\n"],"
|
|
1
|
+
{"version":3,"file":"toaster.js","names":[],"sources":["../src/toaster.tsx"],"sourcesContent":["'use client';\n\nimport React, { useState, type FC, memo } from 'react';\nimport { Toast, type ToastProps } from 'react-bootstrap';\n// import { useToaster } from '../redux/toasterSlice';\n\nexport type ToasterProps = {\n toast: string | { message: string; title?: string; variant?: 'dark' | 'success' | 'danger' };\n} & ToastProps;\n\nexport const Toaster: FC<ToasterProps> = memo(function Toaster({ toast }) {\n //const { toast, setToast } = useToaster();\n const [dismissed, setDismissed] = useState(false);\n\n const msg = typeof toast === 'string' ? toast : toast?.message;\n // const title = typeof toast === 'string' ? 'Notification' : toast?.title;\n const variant = typeof toast === 'string' ? '' : toast?.variant;\n\n return (\n <Toast\n onClose={() => setDismissed(true)}\n show={!dismissed}\n delay={10000}\n autohide\n bg={variant?.toLowerCase()}\n className=\"position-fixed top-50 right-50 min-w-200px z-3\"\n >\n <Toast.Header>\n <strong className=\"me-auto\">Notification</strong>\n </Toast.Header>\n <Toast.Body\n className={\n ['dark', 'success', 'danger'].includes((variant as string)?.toLowerCase()) ? 'text-white' : ''\n }\n >\n {msg}\n </Toast.Body>\n </Toast>\n );\n});\n"],"mappings":";;;;;AAUA,IAAa,UAA4B,KAAK,SAAS,QAAQ,EAAE,SAAS;CAEtE,MAAM,CAAC,WAAW,gBAAgB,SAAS,KAAK;CAEhD,MAAM,MAAM,OAAO,UAAU,WAAW,QAAQ,OAAO;CAEvD,MAAM,UAAU,OAAO,UAAU,WAAW,KAAK,OAAO;CAExD,OACI,qBAAC,OAAD;EACI,eAAe,aAAa,IAAI;EAChC,MAAM,CAAC;EACP,OAAO;EACP,UAAA;EACA,IAAI,SAAS,YAAY;EACzB,WAAU;YANd,CAQI,oBAAC,MAAM,QAAP,EAAA,UACI,oBAAC,UAAD;GAAQ,WAAU;aAAU;EAAoB,CAAA,EACtC,CAAA,GACd,oBAAC,MAAM,MAAP;GACI,WACI;IAAC;IAAQ;IAAW;GAAQ,CAAC,CAAC,SAAU,SAAoB,YAAY,CAAC,IAAI,eAAe;aAG/F;EACO,CAAA,CACT;;AAEf,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
-
import { Toaster } from './toaster';
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
import { Toaster } from './toaster.js';
|
|
3
3
|
declare const meta: Meta<typeof Toaster>;
|
|
4
4
|
export default meta;
|
|
5
5
|
type Story = StoryObj<typeof meta>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toaster.stories.d.ts","sourceRoot":"","sources":["../src/toaster.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"toaster.stories.d.ts","sourceRoot":"","sources":["../src/toaster.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAG5D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,OAAO,CAS9B,CAAC;AAEF,eAAe,IAAI,CAAC;AAEpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAEnC,eAAO,MAAM,OAAO,EAAE,KAIrB,CAAC;AAEF,eAAO,MAAM,MAAM,EAAE,KAIpB,CAAC"}
|
package/dist/useModal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useModal.d.ts","sourceRoot":"","sources":["../src/useModal.tsx"],"names":[],"mappings":"AAAA,OAAc,
|
|
1
|
+
{"version":3,"file":"useModal.d.ts","sourceRoot":"","sources":["../src/useModal.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAkC,KAAK,EAAE,EAAQ,MAAM,OAAO,CAAC;AAC7E,OAAO,EAAiB,KAAK,UAAU,EAAa,KAAK,cAAc,EAAS,MAAM,iBAAiB,CAAC;AAExG,MAAM,MAAM,YAAY,GAAG;IAAE,OAAO,CAAC,EAAE,GAAG,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAEpE,MAAM,MAAM,aAAa,GAAG;IACxB,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;IAC5B,YAAY,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IAC5B,YAAY,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IAC5B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IACrB,cAAc,CAAC,EAAE,UAAU,GAAG,cAAc,CAAC;CAChD,CAAC;AAEF,wBAAgB,QAAQ,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,GAAE,YAAiB,GAAG;IACnE,IAAI,EAAE,OAAO,GAAG,SAAS,CAAC;IAC1B,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,WAAW,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC;CAC/B,CAuEA"}
|
package/dist/useModal.js
CHANGED
|
@@ -1,50 +1,61 @@
|
|
|
1
|
+
import { memo, useCallback, useMemo, useState } from "react";
|
|
2
|
+
import { Button, Modal, Offcanvas, Stack } from "react-bootstrap";
|
|
1
3
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
|
|
3
|
-
import { Offcanvas, Modal, Stack, Button } from "react-bootstrap";
|
|
4
|
+
//#region src/useModal.tsx
|
|
4
5
|
function useModal({ onClose, showOnMount } = {}) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
6
|
+
const [show, setShow] = useState(showOnMount);
|
|
7
|
+
const close = useCallback(() => {
|
|
8
|
+
setShow(false);
|
|
9
|
+
onClose?.();
|
|
10
|
+
}, [onClose]);
|
|
11
|
+
const open = useCallback(() => setShow(true), []);
|
|
12
|
+
const defaultOnSubmit = useCallback((e) => {
|
|
13
|
+
e.preventDefault();
|
|
14
|
+
close();
|
|
15
|
+
}, [close]);
|
|
16
|
+
return {
|
|
17
|
+
show,
|
|
18
|
+
close,
|
|
19
|
+
open,
|
|
20
|
+
ModalDialog: useMemo(() => memo(function ModalDialog({ children, show, onSubmit = defaultOnSubmit, submitButton = "Done", cancelButton = "Cancel", offcanvas = false, title = null, containerProps = {} }) {
|
|
21
|
+
const Container = offcanvas ? Offcanvas : Modal;
|
|
22
|
+
const containerDefaultProps = offcanvas ? { style: { maxWidth: "85%" } } : {};
|
|
23
|
+
const Body = offcanvas ? Offcanvas.Body : Modal.Body;
|
|
24
|
+
const Header = offcanvas ? Offcanvas.Header : Modal.Header;
|
|
25
|
+
const Title = offcanvas ? Offcanvas.Title : Modal.Title;
|
|
26
|
+
return /* @__PURE__ */ jsx(Container, {
|
|
27
|
+
...containerDefaultProps,
|
|
28
|
+
...containerProps,
|
|
29
|
+
show,
|
|
30
|
+
onHide: close,
|
|
31
|
+
children: /* @__PURE__ */ jsxs("form", {
|
|
32
|
+
onSubmit,
|
|
33
|
+
children: [
|
|
34
|
+
title && /* @__PURE__ */ jsx(Header, {
|
|
35
|
+
closeButton: true,
|
|
36
|
+
children: /* @__PURE__ */ jsx(Title, { children: title })
|
|
37
|
+
}),
|
|
38
|
+
/* @__PURE__ */ jsx(Body, {
|
|
39
|
+
as: Stack,
|
|
40
|
+
gap: 3,
|
|
41
|
+
children: show && children
|
|
42
|
+
}),
|
|
43
|
+
!offcanvas && (submitButton || cancelButton) && /* @__PURE__ */ jsxs(Modal.Footer, { children: [cancelButton && /* @__PURE__ */ jsx(Button, {
|
|
44
|
+
variant: "outline-secondary",
|
|
45
|
+
onClick: close,
|
|
46
|
+
children: cancelButton
|
|
47
|
+
}), submitButton && /* @__PURE__ */ jsx(Button, {
|
|
48
|
+
variant: "secondary",
|
|
49
|
+
type: "submit",
|
|
50
|
+
children: submitButton
|
|
51
|
+
})] })
|
|
52
|
+
]
|
|
53
|
+
})
|
|
54
|
+
});
|
|
55
|
+
}), [close, defaultOnSubmit])
|
|
56
|
+
};
|
|
46
57
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
//# sourceMappingURL=useModal.js.map
|
|
58
|
+
//#endregion
|
|
59
|
+
export { useModal };
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=useModal.js.map
|
package/dist/useModal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useModal.js","sources":["../src/useModal.tsx"],"sourcesContent":["import React, { useCallback, useMemo, useState,
|
|
1
|
+
{"version":3,"file":"useModal.js","names":[],"sources":["../src/useModal.tsx"],"sourcesContent":["import React, { useCallback, useMemo, useState, type FC, memo } from 'react';\nimport { Button, Modal, type ModalProps, Offcanvas, type OffcanvasProps, Stack } from 'react-bootstrap';\n\nexport type UseModalArgs = { onClose?: any; showOnMount?: boolean };\n\nexport type UseModalProps = {\n children?: any;\n show?: boolean;\n onSubmit?: (e: any) => void;\n submitButton?: string | any;\n cancelButton?: string | any;\n offcanvas?: boolean;\n title?: string | any;\n containerProps?: ModalProps | OffcanvasProps;\n};\n\nexport function useModal({ onClose, showOnMount }: UseModalArgs = {}): {\n show: boolean | undefined;\n close: () => void;\n open: () => void;\n ModalDialog: FC<ModalProps>;\n} {\n const [show, setShow] = useState(showOnMount);\n\n const close = useCallback((): void => {\n setShow(false);\n onClose?.();\n }, [onClose]);\n\n const open = useCallback((): void => setShow(true), []);\n\n const defaultOnSubmit = useCallback(\n (e: any) => {\n e.preventDefault();\n close();\n },\n [close],\n );\n\n const ModalDialog: FC<UseModalProps> = useMemo(\n () =>\n memo(function ModalDialog({\n children,\n show,\n onSubmit = defaultOnSubmit,\n submitButton = 'Done',\n cancelButton = 'Cancel',\n offcanvas = false,\n title = null as any,\n containerProps = {},\n }) {\n const Container = offcanvas ? Offcanvas : Modal;\n const containerDefaultProps = offcanvas ? { style: { maxWidth: '85%' } } : {};\n const Body = offcanvas ? Offcanvas.Body : Modal.Body;\n const Header = offcanvas ? Offcanvas.Header : Modal.Header;\n const Title = offcanvas ? Offcanvas.Title : Modal.Title;\n\n return (\n <Container {...{ ...containerDefaultProps, ...containerProps }} show={show} onHide={close}>\n <form onSubmit={onSubmit}>\n {title && (\n <Header closeButton>\n <Title>{title}</Title>\n </Header>\n )}\n\n <Body as={Stack} gap={3}>\n {show && children}\n </Body>\n\n {!offcanvas && (submitButton || cancelButton) && (\n <Modal.Footer>\n {cancelButton && (\n <Button variant=\"outline-secondary\" onClick={close}>\n {cancelButton}\n </Button>\n )}\n {submitButton && (\n <Button variant=\"secondary\" type=\"submit\">\n {submitButton}\n </Button>\n )}\n </Modal.Footer>\n )}\n </form>\n </Container>\n );\n }),\n [close, defaultOnSubmit],\n );\n\n return { show, close, open, ModalDialog };\n}\n"],"mappings":";;;;AAgBA,SAAgB,SAAS,EAAE,SAAS,gBAA8B,CAAC,GAKjE;CACE,MAAM,CAAC,MAAM,WAAW,SAAS,WAAW;CAE5C,MAAM,QAAQ,kBAAwB;EAClC,QAAQ,KAAK;EACb,UAAU;CACd,GAAG,CAAC,OAAO,CAAC;CAEZ,MAAM,OAAO,kBAAwB,QAAQ,IAAI,GAAG,CAAC,CAAC;CAEtD,MAAM,kBAAkB,aACnB,MAAW;EACR,EAAE,eAAe;EACjB,MAAM;CACV,GACA,CAAC,KAAK,CACV;CAsDA,OAAO;EAAE;EAAM;EAAO;EAAM,aApDW,cAE/B,KAAK,SAAS,YAAY,EACtB,UACA,MACA,WAAW,iBACX,eAAe,QACf,eAAe,UACf,YAAY,OACZ,QAAQ,MACR,iBAAiB,CAAC,KACnB;GACC,MAAM,YAAY,YAAY,YAAY;GAC1C,MAAM,wBAAwB,YAAY,EAAE,OAAO,EAAE,UAAU,MAAM,EAAE,IAAI,CAAC;GAC5E,MAAM,OAAO,YAAY,UAAU,OAAO,MAAM;GAChD,MAAM,SAAS,YAAY,UAAU,SAAS,MAAM;GACpD,MAAM,QAAQ,YAAY,UAAU,QAAQ,MAAM;GAElD,OACI,oBAAC,WAAD;IAAiB,GAAG;IAAuB,GAAG;IAAwB;IAAM,QAAQ;cAChF,qBAAC,QAAD;KAAgB;eAAhB;MACK,SACG,oBAAC,QAAD;OAAQ,aAAA;iBACJ,oBAAC,OAAD,EAAA,UAAQ,MAAa,CAAA;MACjB,CAAA;MAGZ,oBAAC,MAAD;OAAM,IAAI;OAAO,KAAK;iBACjB,QAAQ;MACP,CAAA;MAEL,CAAC,cAAc,gBAAgB,iBAC5B,qBAAC,MAAM,QAAP,EAAA,UAAA,CACK,gBACG,oBAAC,QAAD;OAAQ,SAAQ;OAAoB,SAAS;iBACxC;MACG,CAAA,GAEX,gBACG,oBAAC,QAAD;OAAQ,SAAQ;OAAY,MAAK;iBAC5B;MACG,CAAA,CAEF,EAAA,CAAA;KAEhB;;GACC,CAAA;EAEnB,CAAC,GACL,CAAC,OAAO,eAAe,CAGC;CAAY;AAC5C"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
|
-
import { Meta, StoryObj } from '@storybook/react';
|
|
3
|
-
import { UseModalProps } from './useModal';
|
|
2
|
+
import { Meta, StoryObj } from '@storybook/react-vite';
|
|
3
|
+
import { UseModalProps } from './useModal.js';
|
|
4
4
|
declare const meta: Meta<FC<UseModalProps>>;
|
|
5
5
|
export default meta;
|
|
6
6
|
type Story = StoryObj<typeof meta>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useModal.stories.d.ts","sourceRoot":"","sources":["../src/useModal.stories.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"useModal.stories.d.ts","sourceRoot":"","sources":["../src/useModal.stories.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,KAAK,EAAE,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAY,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAI1D,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,CA8BjC,CAAC;AAEF,eAAe,IAAI,CAAC;AAEpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAEnC,eAAO,MAAM,OAAO,EAAE,KAErB,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,KAIvB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWrappedForm.d.ts","sourceRoot":"","sources":["../src/useWrappedForm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"useWrappedForm.d.ts","sourceRoot":"","sources":["../src/useWrappedForm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG1D,eAAO,MAAM,aAAa,GAAI,WAAW,SAAS,CAAC,GAAG,CAAC,KAAG,OAAwD,CAAC;AAEnH,eAAO,MAAM,cAAc,EAAE,OAAO,OAmBnC,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,GACvB,UAAU,GAAG,MACb,GAAG,KAAK,KAAG,IAIX,CAAC"}
|
package/dist/useWrappedForm.js
CHANGED
|
@@ -1,32 +1,43 @@
|
|
|
1
|
-
import { useForm } from "react-hook-form";
|
|
2
1
|
import { useCallback } from "react";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
2
|
+
import { useForm } from "react-hook-form";
|
|
3
|
+
//#region src/useWrappedForm.ts
|
|
4
|
+
var isFormLoading = (formState) => formState.isLoading || formState.isSubmitting;
|
|
5
|
+
var useWrappedForm = (options) => {
|
|
6
|
+
const form = useForm(options);
|
|
7
|
+
const handleSubmit = useCallback((onSubmit, onError) => {
|
|
8
|
+
const wrappedSubmit = async (data) => {
|
|
9
|
+
try {
|
|
10
|
+
await onSubmit(data);
|
|
11
|
+
} catch (e) {
|
|
12
|
+
form.setError("root", {
|
|
13
|
+
type: "server",
|
|
14
|
+
message: e.message
|
|
15
|
+
});
|
|
16
|
+
console.error("Error submitting form", e);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
return form.handleSubmit(wrappedSubmit, onError);
|
|
20
|
+
}, [form]);
|
|
21
|
+
return {
|
|
22
|
+
...form,
|
|
23
|
+
handleSubmit
|
|
24
|
+
};
|
|
26
25
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Issue #3: Submit event still propagates to parent when using portal
|
|
28
|
+
* https://reactjs.org/docs/portals.html#event-bubbling-through-portals
|
|
29
|
+
* Event bubbling goes through React DOM instead of HTML DOM
|
|
30
|
+
* Portals don't have an effect on this one, we need to stop event propagation
|
|
31
|
+
* This should be our default form handling method
|
|
32
|
+
* https://codesandbox.io/s/react-hook-form-nested-portal-6x3fvy?file=/src/App.tsx:1905-2261
|
|
33
|
+
* https://github.com/react-hook-form/react-hook-form/issues/1005#issuecomment-988380981
|
|
34
|
+
*/
|
|
35
|
+
var stopPropagation = (callback) => (e) => {
|
|
36
|
+
e.stopPropagation();
|
|
37
|
+
e.preventDefault();
|
|
38
|
+
callback(e);
|
|
31
39
|
};
|
|
32
|
-
//#
|
|
40
|
+
//#endregion
|
|
41
|
+
export { isFormLoading, stopPropagation, useWrappedForm };
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=useWrappedForm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWrappedForm.js","sources":["../src/useWrappedForm.ts"],"sourcesContent":["import { useForm, FormState } from 'react-hook-form';\nimport { useCallback } from 'react';\n\nexport const isFormLoading = (formState: FormState<any>): boolean => formState.isLoading || formState.isSubmitting;\n\nexport const useWrappedForm: typeof useForm = (options) => {\n const form = useForm(options);\n\n const handleSubmit: typeof form.handleSubmit = useCallback(\n (onSubmit, onError) => {\n const wrappedSubmit: typeof onSubmit = async (data) => {\n try {\n await onSubmit(data);\n } catch (e) {\n form.setError('root', { type: 'server', message: (e as Error).message });\n console.error('Error submitting form', e);\n }\n };\n return form.handleSubmit(wrappedSubmit, onError);\n },\n [form],\n );\n\n return { ...form, handleSubmit };\n};\n\n/**\n * Issue #3: Submit event still propagates to parent when using portal\n * https://reactjs.org/docs/portals.html#event-bubbling-through-portals\n * Event bubbling goes through React DOM instead of HTML DOM\n * Portals don't have an effect on this one, we need to stop event propagation\n * This should be our default form handling method\n * https://codesandbox.io/s/react-hook-form-nested-portal-6x3fvy?file=/src/App.tsx:1905-2261\n * https://github.com/react-hook-form/react-hook-form/issues/1005#issuecomment-988380981\n */\nexport const stopPropagation =\n (callback: any) =>\n (e: Event): void => {\n e.stopPropagation();\n e.preventDefault();\n callback(e);\n };\n"],"
|
|
1
|
+
{"version":3,"file":"useWrappedForm.js","names":[],"sources":["../src/useWrappedForm.ts"],"sourcesContent":["import { useForm, type FormState } from 'react-hook-form';\nimport { useCallback } from 'react';\n\nexport const isFormLoading = (formState: FormState<any>): boolean => formState.isLoading || formState.isSubmitting;\n\nexport const useWrappedForm: typeof useForm = (options) => {\n const form = useForm(options);\n\n const handleSubmit: typeof form.handleSubmit = useCallback(\n (onSubmit, onError) => {\n const wrappedSubmit: typeof onSubmit = async (data) => {\n try {\n await onSubmit(data);\n } catch (e) {\n form.setError('root', { type: 'server', message: (e as Error).message });\n console.error('Error submitting form', e);\n }\n };\n return form.handleSubmit(wrappedSubmit, onError);\n },\n [form],\n );\n\n return { ...form, handleSubmit };\n};\n\n/**\n * Issue #3: Submit event still propagates to parent when using portal\n * https://reactjs.org/docs/portals.html#event-bubbling-through-portals\n * Event bubbling goes through React DOM instead of HTML DOM\n * Portals don't have an effect on this one, we need to stop event propagation\n * This should be our default form handling method\n * https://codesandbox.io/s/react-hook-form-nested-portal-6x3fvy?file=/src/App.tsx:1905-2261\n * https://github.com/react-hook-form/react-hook-form/issues/1005#issuecomment-988380981\n */\nexport const stopPropagation =\n (callback: any) =>\n (e: Event): void => {\n e.stopPropagation();\n e.preventDefault();\n callback(e);\n };\n"],"mappings":";;;AAGA,IAAa,iBAAiB,cAAuC,UAAU,aAAa,UAAU;AAEtG,IAAa,kBAAkC,YAAY;CACvD,MAAM,OAAO,QAAQ,OAAO;CAE5B,MAAM,eAAyC,aAC1C,UAAU,YAAY;EACnB,MAAM,gBAAiC,OAAO,SAAS;GACnD,IAAI;IACA,MAAM,SAAS,IAAI;GACvB,SAAS,GAAG;IACR,KAAK,SAAS,QAAQ;KAAE,MAAM;KAAU,SAAU,EAAY;IAAQ,CAAC;IACvE,QAAQ,MAAM,yBAAyB,CAAC;GAC5C;EACJ;EACA,OAAO,KAAK,aAAa,eAAe,OAAO;CACnD,GACA,CAAC,IAAI,CACT;CAEA,OAAO;EAAE,GAAG;EAAM;CAAa;AACnC;;;;;;;;;;AAWA,IAAa,mBACR,cACA,MAAmB;CAChB,EAAE,gBAAgB;CAClB,EAAE,eAAe;CACjB,SAAS,CAAC;AACd"}
|
package/package.json
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kirill.konshin/bootstrap",
|
|
3
3
|
"description": "Utilities",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.3",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"hasStorybook": true,
|
|
6
7
|
"scripts": {
|
|
7
8
|
"----- BUILD -----": "",
|
|
8
9
|
"clean": "rm -rf dist .tscache tsconfig.tsbuildinfo",
|
|
9
10
|
"build": "vite build",
|
|
10
|
-
"build:index": "ctix build",
|
|
11
|
-
"build:check-types": "attw --pack .",
|
|
12
11
|
"start": "yarn build --watch",
|
|
13
12
|
"wait": "wait-on ./dist/index.js",
|
|
14
13
|
"----- TEST -----": "",
|
|
15
|
-
"test
|
|
14
|
+
"test": "vitest run --coverage",
|
|
16
15
|
"test:watch": "vitest watch --coverage",
|
|
17
16
|
"----- STORYBOOK -----": "",
|
|
18
17
|
"storybook:start": "storybook dev -p 6006",
|
|
@@ -64,5 +63,18 @@
|
|
|
64
63
|
},
|
|
65
64
|
"main": "./dist/index.js",
|
|
66
65
|
"module": "./dist/index.js",
|
|
67
|
-
"types": "./dist/index.d.ts"
|
|
66
|
+
"types": "./dist/index.d.ts",
|
|
67
|
+
"repository": {
|
|
68
|
+
"type": "git",
|
|
69
|
+
"url": "https://github.com/kirill-konshin/utils.git",
|
|
70
|
+
"directory": "packages/bootstrap"
|
|
71
|
+
},
|
|
72
|
+
"nx": {
|
|
73
|
+
"tags": [
|
|
74
|
+
"platform:react"
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
"files": [
|
|
78
|
+
"dist"
|
|
79
|
+
]
|
|
68
80
|
}
|
package/.ctirc
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"options": [
|
|
3
|
-
{
|
|
4
|
-
"mode": "create",
|
|
5
|
-
"project": "tsconfig.json",
|
|
6
|
-
"include": "src/**/*.{ts,tsx}",
|
|
7
|
-
"exclude": [
|
|
8
|
-
"**/*.stories.*",
|
|
9
|
-
"**/*.test.*",
|
|
10
|
-
"**/*.fixture.*"
|
|
11
|
-
],
|
|
12
|
-
"startFrom": "src",
|
|
13
|
-
"backup": false,
|
|
14
|
-
"overwrite": true,
|
|
15
|
-
"generationStyle": "default-alias-named-star",
|
|
16
|
-
"output": "src",
|
|
17
|
-
"verbose": true
|
|
18
|
-
}
|
|
19
|
-
]
|
|
20
|
-
}
|
package/.storybook/main.ts
DELETED
package/.storybook/preview.ts
DELETED
package/.turbo/turbo-build.log
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
[36mvite v7.0.6 [32mbuilding SSR bundle for production...[36m[39m
|
|
2
|
-
- ctix 'create' mode start, ...
|
|
3
|
-
✔ /home/runner/work/utils/utils/packages/bootstrap/tsconfig.json loading complete!
|
|
4
|
-
✔ analysis export statements completed!
|
|
5
|
-
- build "index.ts" file start
|
|
6
|
-
- output file exists check, ...
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
✔ ctix 'create' mode complete!
|
|
10
|
-
transforming...
|
|
11
|
-
[32m✓[39m 13 modules transformed.
|
|
12
|
-
rendering chunks...
|
|
13
|
-
|
|
14
|
-
[vite:dts] Start generate declaration files...
|
|
15
|
-
[2mdist/[22m[36madaptiveContainer.js [39m[1m[2m0.46 kB[22m[1m[22m[2m │ map: 0.80 kB[22m
|
|
16
|
-
[2mdist/[22m[36mglobalLoading.js [39m[1m[2m0.49 kB[22m[1m[22m[2m │ map: 0.94 kB[22m
|
|
17
|
-
[2mdist/[22m[36mloading.js [39m[1m[2m0.59 kB[22m[1m[22m[2m │ map: 1.12 kB[22m
|
|
18
|
-
[2mdist/[22m[36merror.js [39m[1m[2m0.84 kB[22m[1m[22m[2m │ map: 1.72 kB[22m
|
|
19
|
-
[2mdist/[22m[36mfield.js [39m[1m[2m0.85 kB[22m[1m[22m[2m │ map: 1.68 kB[22m
|
|
20
|
-
[2mdist/[22m[36museWrappedForm.js [39m[1m[2m0.90 kB[22m[1m[22m[2m │ map: 2.27 kB[22m
|
|
21
|
-
[2mdist/[22m[36mindex.js [39m[1m[2m0.97 kB[22m[1m[22m[2m │ map: 0.10 kB[22m
|
|
22
|
-
[2mdist/[22m[36mtoaster.js [39m[1m[2m1.09 kB[22m[1m[22m[2m │ map: 2.14 kB[22m
|
|
23
|
-
[2mdist/[22m[36mfooter.js [39m[1m[2m1.62 kB[22m[1m[22m[2m │ map: 2.97 kB[22m
|
|
24
|
-
[2mdist/[22m[36mresponsiveHelper.js [39m[1m[2m1.83 kB[22m[1m[22m[2m │ map: 3.04 kB[22m
|
|
25
|
-
[2mdist/[22m[36museModal.js [39m[1m[2m2.08 kB[22m[1m[22m[2m │ map: 4.91 kB[22m
|
|
26
|
-
[2mdist/[22m[36mcontrols.js [39m[1m[2m2.69 kB[22m[1m[22m[2m │ map: 5.90 kB[22m
|
|
27
|
-
[2mdist/[22m[36mscreen.js [39m[1m[2m3.42 kB[22m[1m[22m[2m │ map: 7.17 kB[22m
|
|
28
|
-
[vite:dts] Declaration files built in 3640ms.
|
|
29
|
-
|
|
30
|
-
[32m✓ built in 7.24s[39m
|
|
31
|
-
Updated package.json with exports
|
package/CHANGELOG.md
DELETED
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;"}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import type { Meta, StoryObj } from '@storybook/react';
|
|
3
|
-
|
|
4
|
-
import { AdaptiveContainer } from './adaptiveContainer';
|
|
5
|
-
|
|
6
|
-
const meta: Meta<typeof AdaptiveContainer> = {
|
|
7
|
-
title: 'Bootstrap / AdaptiveContainer',
|
|
8
|
-
component: AdaptiveContainer,
|
|
9
|
-
parameters: {
|
|
10
|
-
layout: 'fullscreen',
|
|
11
|
-
},
|
|
12
|
-
tags: ['autodocs'],
|
|
13
|
-
argTypes: {
|
|
14
|
-
children: { control: 'text' },
|
|
15
|
-
className: { control: 'text' },
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export default meta;
|
|
20
|
-
|
|
21
|
-
type Story = StoryObj<typeof meta>;
|
|
22
|
-
|
|
23
|
-
export const Default: Story = {
|
|
24
|
-
args: {
|
|
25
|
-
children:
|
|
26
|
-
'This container adapts to the viewport size. On mobile it becomes fluid, on desktop it has max-width.',
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export const WithClassName: Story = {
|
|
31
|
-
args: {
|
|
32
|
-
children: 'Container with custom class',
|
|
33
|
-
className: 'bg-light p-3',
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export const WithContent: Story = {
|
|
38
|
-
render: () => (
|
|
39
|
-
<AdaptiveContainer className="py-4">
|
|
40
|
-
<h1>Adaptive Container Demo</h1>
|
|
41
|
-
<p>
|
|
42
|
-
Resize the viewport to see how this container behaves. On mobile viewports (xs, sm, md), it becomes
|
|
43
|
-
fluid and takes full width. On desktop viewports (lg, xl, xxl), it has a max-width constraint.
|
|
44
|
-
</p>
|
|
45
|
-
<div className="row">
|
|
46
|
-
<div className="col-md-6">
|
|
47
|
-
<div className="card">
|
|
48
|
-
<div className="card-body">Column 1</div>
|
|
49
|
-
</div>
|
|
50
|
-
</div>
|
|
51
|
-
<div className="col-md-6">
|
|
52
|
-
<div className="card">
|
|
53
|
-
<div className="card-body">Column 2</div>
|
|
54
|
-
</div>
|
|
55
|
-
</div>
|
|
56
|
-
</div>
|
|
57
|
-
</AdaptiveContainer>
|
|
58
|
-
),
|
|
59
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import React, { FC, memo } from 'react';
|
|
2
|
-
import { Container, ContainerProps } from 'react-bootstrap';
|
|
3
|
-
import { useBreakpoint } from './responsiveHelper';
|
|
4
|
-
|
|
5
|
-
export type AdaptiveContainerProps = ContainerProps;
|
|
6
|
-
|
|
7
|
-
export const AdaptiveContainer: FC<AdaptiveContainerProps> = memo(function AdaptiveContainer({ children, ...props }) {
|
|
8
|
-
const { isMobile } = useBreakpoint();
|
|
9
|
-
return (
|
|
10
|
-
<Container fluid={isMobile} {...props}>
|
|
11
|
-
{children}
|
|
12
|
-
</Container>
|
|
13
|
-
);
|
|
14
|
-
});
|
package/src/controls.stories.tsx
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import React, { cloneElement, useCallback, useState } from 'react';
|
|
2
|
-
import type { Meta, StoryObj } from '@storybook/react';
|
|
3
|
-
import { fn } from '@storybook/test';
|
|
4
|
-
|
|
5
|
-
import { Select, Control, Range, Checkbox } from './controls';
|
|
6
|
-
|
|
7
|
-
const defaultOptions = { num: 1, bool: false, select: 'bar' };
|
|
8
|
-
|
|
9
|
-
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
|
|
10
|
-
const meta: Meta<typeof Control> = {
|
|
11
|
-
title: 'Bootstrap / Controls',
|
|
12
|
-
parameters: {
|
|
13
|
-
layout: 'centered',
|
|
14
|
-
},
|
|
15
|
-
tags: ['autodocs'],
|
|
16
|
-
argTypes: {},
|
|
17
|
-
args: { options: { ...defaultOptions }, setOptions: fn(), defaultOptions: { ...defaultOptions }, name: 'unused' },
|
|
18
|
-
render: function Demo(args) {
|
|
19
|
-
const [options, setOptionsRaw] = useState(args.options);
|
|
20
|
-
|
|
21
|
-
const setOptions = useCallback(
|
|
22
|
-
(options: any) =>
|
|
23
|
-
setOptionsRaw((currentOptions) => {
|
|
24
|
-
return { ...currentOptions, ...options };
|
|
25
|
-
}),
|
|
26
|
-
[],
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
const controlProps = { options, setOptions, defaultOptions };
|
|
30
|
-
|
|
31
|
-
const { children, name, ...safeArgs } = args;
|
|
32
|
-
|
|
33
|
-
return <div style={{ width: '300px' }}>{cloneElement(children as any, { ...safeArgs, ...controlProps })}</div>;
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export default meta;
|
|
38
|
-
|
|
39
|
-
type Story = StoryObj<typeof meta>;
|
|
40
|
-
|
|
41
|
-
export const RangeControl: Story = {
|
|
42
|
-
args: {
|
|
43
|
-
children: <Range name="Num" min={0} max={1} />,
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export const CheckboxControl: Story = {
|
|
48
|
-
args: {
|
|
49
|
-
children: <Checkbox name="Bool" />,
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export const SelectControl: Story = {
|
|
54
|
-
args: {
|
|
55
|
-
children: (
|
|
56
|
-
<Select name="Select">
|
|
57
|
-
<option value="foo">Foo</option>
|
|
58
|
-
<option value="bar">Bar</option>
|
|
59
|
-
</Select>
|
|
60
|
-
),
|
|
61
|
-
},
|
|
62
|
-
};
|