@sparkstudio/common-ui 1.0.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/README.md +73 -0
- package/dist/index.cjs +88 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.css +32 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.cts +22 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +61 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -0
package/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# React + TypeScript + Vite
|
|
2
|
+
|
|
3
|
+
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
|
4
|
+
|
|
5
|
+
Currently, two official plugins are available:
|
|
6
|
+
|
|
7
|
+
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
|
|
8
|
+
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
|
9
|
+
|
|
10
|
+
## React Compiler
|
|
11
|
+
|
|
12
|
+
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
|
|
13
|
+
|
|
14
|
+
## Expanding the ESLint configuration
|
|
15
|
+
|
|
16
|
+
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
export default defineConfig([
|
|
20
|
+
globalIgnores(['dist']),
|
|
21
|
+
{
|
|
22
|
+
files: ['**/*.{ts,tsx}'],
|
|
23
|
+
extends: [
|
|
24
|
+
// Other configs...
|
|
25
|
+
|
|
26
|
+
// Remove tseslint.configs.recommended and replace with this
|
|
27
|
+
tseslint.configs.recommendedTypeChecked,
|
|
28
|
+
// Alternatively, use this for stricter rules
|
|
29
|
+
tseslint.configs.strictTypeChecked,
|
|
30
|
+
// Optionally, add this for stylistic rules
|
|
31
|
+
tseslint.configs.stylisticTypeChecked,
|
|
32
|
+
|
|
33
|
+
// Other configs...
|
|
34
|
+
],
|
|
35
|
+
languageOptions: {
|
|
36
|
+
parserOptions: {
|
|
37
|
+
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
38
|
+
tsconfigRootDir: import.meta.dirname,
|
|
39
|
+
},
|
|
40
|
+
// other options...
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
])
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
// eslint.config.js
|
|
50
|
+
import reactX from 'eslint-plugin-react-x'
|
|
51
|
+
import reactDom from 'eslint-plugin-react-dom'
|
|
52
|
+
|
|
53
|
+
export default defineConfig([
|
|
54
|
+
globalIgnores(['dist']),
|
|
55
|
+
{
|
|
56
|
+
files: ['**/*.{ts,tsx}'],
|
|
57
|
+
extends: [
|
|
58
|
+
// Other configs...
|
|
59
|
+
// Enable lint rules for React
|
|
60
|
+
reactX.configs['recommended-typescript'],
|
|
61
|
+
// Enable lint rules for React DOM
|
|
62
|
+
reactDom.configs.recommended,
|
|
63
|
+
],
|
|
64
|
+
languageOptions: {
|
|
65
|
+
parserOptions: {
|
|
66
|
+
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
67
|
+
tsconfigRootDir: import.meta.dirname,
|
|
68
|
+
},
|
|
69
|
+
// other options...
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
])
|
|
73
|
+
```
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
Button: () => Button
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/components/Button.tsx
|
|
28
|
+
var import_react = require("react");
|
|
29
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
30
|
+
function Button({
|
|
31
|
+
buttonClassName = "btn btn-primary btn-lg",
|
|
32
|
+
type = "button",
|
|
33
|
+
disabled = false,
|
|
34
|
+
onAction,
|
|
35
|
+
onClick,
|
|
36
|
+
onDone,
|
|
37
|
+
onError,
|
|
38
|
+
onFinally,
|
|
39
|
+
children = "Click me",
|
|
40
|
+
loadingChildren,
|
|
41
|
+
renderContent,
|
|
42
|
+
renderLoading,
|
|
43
|
+
loadingText = "Loading...",
|
|
44
|
+
showSpinner = true
|
|
45
|
+
}) {
|
|
46
|
+
const [loading, setLoading] = (0, import_react.useState)(false);
|
|
47
|
+
const handleClick = async (event) => {
|
|
48
|
+
if (loading) return;
|
|
49
|
+
onClick?.(event);
|
|
50
|
+
if (event.defaultPrevented) return;
|
|
51
|
+
if (!onAction) return;
|
|
52
|
+
try {
|
|
53
|
+
setLoading(true);
|
|
54
|
+
const result = await onAction();
|
|
55
|
+
onDone?.(result);
|
|
56
|
+
} catch (error) {
|
|
57
|
+
onError?.(error);
|
|
58
|
+
} finally {
|
|
59
|
+
setLoading(false);
|
|
60
|
+
onFinally?.();
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: `w-100 text-center mb-3`, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
64
|
+
"button",
|
|
65
|
+
{
|
|
66
|
+
type,
|
|
67
|
+
className: `${buttonClassName} ${loading ? "async-btn--loading" : ""}`,
|
|
68
|
+
onClick: handleClick,
|
|
69
|
+
disabled: disabled || loading,
|
|
70
|
+
children: loading ? renderLoading?.() ?? loadingChildren ?? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
71
|
+
showSpinner && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
72
|
+
"span",
|
|
73
|
+
{
|
|
74
|
+
className: "spinner-border spinner-border-sm me-2 async-btn__spinner",
|
|
75
|
+
role: "status",
|
|
76
|
+
"aria-hidden": "true"
|
|
77
|
+
}
|
|
78
|
+
),
|
|
79
|
+
loadingText
|
|
80
|
+
] }) : renderContent?.() ?? children
|
|
81
|
+
}
|
|
82
|
+
) });
|
|
83
|
+
}
|
|
84
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
85
|
+
0 && (module.exports = {
|
|
86
|
+
Button
|
|
87
|
+
});
|
|
88
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/components/Button.tsx"],"sourcesContent":["export * from \"./components/Button\";","import { useState, type ReactNode, type MouseEvent } from \"react\";\r\nimport \"./Button.scss\";\r\n\r\nexport interface ButtonProps {\r\n buttonClassName?: string;\r\n type?: \"button\" | \"submit\" | \"reset\";\r\n disabled?: boolean;\r\n\r\n onAction?: () => Promise<unknown>;\r\n onClick?: (event: MouseEvent<HTMLButtonElement>) => void;\r\n onDone?: (result: unknown) => void;\r\n onError?: (error: unknown) => void;\r\n onFinally?: () => void;\r\n\r\n children?: ReactNode;\r\n loadingChildren?: ReactNode;\r\n\r\n renderContent?: () => ReactNode;\r\n renderLoading?: () => ReactNode;\r\n\r\n loadingText?: string;\r\n showSpinner?: boolean;\r\n}\r\n\r\nexport function Button({\r\n buttonClassName = \"btn btn-primary btn-lg\",\r\n type = \"button\",\r\n disabled = false,\r\n\r\n onAction,\r\n onClick,\r\n onDone,\r\n onError,\r\n onFinally,\r\n\r\n children = \"Click me\",\r\n\r\n loadingChildren,\r\n renderContent,\r\n renderLoading,\r\n\r\n loadingText = \"Loading...\",\r\n showSpinner = true,\r\n}: ButtonProps) {\r\n const [loading, setLoading] = useState(false);\r\n\r\n const handleClick = async (event: MouseEvent<HTMLButtonElement>) => {\r\n if (loading) return;\r\n\r\n onClick?.(event);\r\n if (event.defaultPrevented) return;\r\n if (!onAction) return;\r\n\r\n try {\r\n setLoading(true);\r\n const result = await onAction();\r\n onDone?.(result);\r\n } catch (error) {\r\n onError?.(error);\r\n } finally {\r\n setLoading(false);\r\n onFinally?.();\r\n }\r\n };\r\n\r\n return (\r\n <div className={`w-100 text-center mb-3`}>\r\n <button\r\n type={type}\r\n className={`${buttonClassName} ${loading ? \"async-btn--loading\" : \"\"}`}\r\n onClick={handleClick}\r\n disabled={disabled || loading}\r\n >\r\n {loading ? (\r\n renderLoading?.() ??\r\n loadingChildren ?? (\r\n <>\r\n {showSpinner && (\r\n <span\r\n className=\"spinner-border spinner-border-sm me-2 async-btn__spinner\"\r\n role=\"status\"\r\n aria-hidden=\"true\"\r\n />\r\n )}\r\n {loadingText}\r\n </>\r\n )\r\n ) : (\r\n renderContent?.() ?? children\r\n )}\r\n </button>\r\n </div>\r\n );\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA0D;AA4E9C;AApDL,SAAS,OAAO;AAAA,EACrB,kBAAkB;AAAA,EAClB,OAAO;AAAA,EACP,WAAW;AAAA,EAEX;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,WAAW;AAAA,EAEX;AAAA,EACA;AAAA,EACA;AAAA,EAEA,cAAc;AAAA,EACd,cAAc;AAChB,GAAgB;AACd,QAAM,CAAC,SAAS,UAAU,QAAI,uBAAS,KAAK;AAE5C,QAAM,cAAc,OAAO,UAAyC;AAClE,QAAI,QAAS;AAEb,cAAU,KAAK;AACf,QAAI,MAAM,iBAAkB;AAC5B,QAAI,CAAC,SAAU;AAEf,QAAI;AACF,iBAAW,IAAI;AACf,YAAM,SAAS,MAAM,SAAS;AAC9B,eAAS,MAAM;AAAA,IACjB,SAAS,OAAO;AACd,gBAAU,KAAK;AAAA,IACjB,UAAE;AACA,iBAAW,KAAK;AAChB,kBAAY;AAAA,IACd;AAAA,EACF;AAEA,SACE,4CAAC,SAAI,WAAW,0BACd;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,WAAW,GAAG,eAAe,IAAI,UAAU,uBAAuB,EAAE;AAAA,MACpE,SAAS;AAAA,MACT,UAAU,YAAY;AAAA,MAErB,oBACC,gBAAgB,KAChB,mBACE,4EACG;AAAA,uBACC;AAAA,UAAC;AAAA;AAAA,YACC,WAAU;AAAA,YACV,MAAK;AAAA,YACL,eAAY;AAAA;AAAA,QACd;AAAA,QAED;AAAA,SACH,IAGF,gBAAgB,KAAK;AAAA;AAAA,EAEzB,GACF;AAEJ;","names":[]}
|
package/dist/index.css
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
@charset "UTF-8";
|
|
2
|
+
|
|
3
|
+
/* src/components/Button.scss */
|
|
4
|
+
.async-btn--loading {
|
|
5
|
+
opacity: 0.6;
|
|
6
|
+
cursor: not-allowed;
|
|
7
|
+
transform: scale(0.98);
|
|
8
|
+
}
|
|
9
|
+
.async-btn__spinner {
|
|
10
|
+
color: #ff9800;
|
|
11
|
+
}
|
|
12
|
+
button.btn.btn-primary.btn-lg {
|
|
13
|
+
background:
|
|
14
|
+
linear-gradient(
|
|
15
|
+
45deg,
|
|
16
|
+
#4caf50,
|
|
17
|
+
#2196f3);
|
|
18
|
+
border: none;
|
|
19
|
+
transition: all 0.2s ease;
|
|
20
|
+
}
|
|
21
|
+
button.btn.btn-primary.btn-lg:hover {
|
|
22
|
+
background:
|
|
23
|
+
linear-gradient(
|
|
24
|
+
45deg,
|
|
25
|
+
#66bb6a,
|
|
26
|
+
#42a5f5);
|
|
27
|
+
transform: translateY(-1px);
|
|
28
|
+
}
|
|
29
|
+
button.btn.btn-primary.btn-lg:active {
|
|
30
|
+
transform: translateY(0);
|
|
31
|
+
}
|
|
32
|
+
/*# sourceMappingURL=index.css.map */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/Button.scss"],"sourcesContent":["/* Simple styles so you can SEE that SCSS is working */\r\n\r\n/* Base async button look */\r\n.async-btn--loading {\r\n opacity: 0.6;\r\n cursor: not-allowed;\r\n transform: scale(0.98);\r\n}\r\n\r\n/* Custom spinner color */\r\n.async-btn__spinner {\r\n color: #ff9800; // orange\r\n}\r\n\r\n/* Just to prove SCSS compiled — scoped style */\r\nbutton.btn.btn-primary.btn-lg {\r\n background: linear-gradient(45deg, #4caf50, #2196f3);\r\n border: none;\r\n transition: all 0.2s ease;\r\n\r\n &:hover {\r\n background: linear-gradient(45deg, #66bb6a, #42a5f5);\r\n transform: translateY(-1px);\r\n }\r\n\r\n &:active {\r\n transform: translateY(0);\r\n }\r\n}\r\n"],"mappings":";;;AAGA,CAAA;AACE,WAAA;AACA,UAAA;AACA,aAAA,MAAA;;AAIF,CAAA;AACE,SAAA;;AAIF,MAAA,CAAA,GAAA,CAAA,WAAA,CAAA;AACE;IAAA;MAAA,KAAA;MAAA,OAAA;MAAA;AACA,UAAA;AACA,cAAA,IAAA,KAAA;;AAEA,MAAA,CALF,GAKE,CALF,WAKE,CALF,MAKE;AACE;IAAA;MAAA,KAAA;MAAA,OAAA;MAAA;AACA,aAAA,WAAA;;AAGF,MAAA,CAVF,GAUE,CAVF,WAUE,CAVF,MAUE;AACE,aAAA,WAAA;;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { MouseEvent, ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
interface ButtonProps {
|
|
5
|
+
buttonClassName?: string;
|
|
6
|
+
type?: "button" | "submit" | "reset";
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
onAction?: () => Promise<unknown>;
|
|
9
|
+
onClick?: (event: MouseEvent<HTMLButtonElement>) => void;
|
|
10
|
+
onDone?: (result: unknown) => void;
|
|
11
|
+
onError?: (error: unknown) => void;
|
|
12
|
+
onFinally?: () => void;
|
|
13
|
+
children?: ReactNode;
|
|
14
|
+
loadingChildren?: ReactNode;
|
|
15
|
+
renderContent?: () => ReactNode;
|
|
16
|
+
renderLoading?: () => ReactNode;
|
|
17
|
+
loadingText?: string;
|
|
18
|
+
showSpinner?: boolean;
|
|
19
|
+
}
|
|
20
|
+
declare function Button({ buttonClassName, type, disabled, onAction, onClick, onDone, onError, onFinally, children, loadingChildren, renderContent, renderLoading, loadingText, showSpinner, }: ButtonProps): react_jsx_runtime.JSX.Element;
|
|
21
|
+
|
|
22
|
+
export { Button, type ButtonProps };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { MouseEvent, ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
interface ButtonProps {
|
|
5
|
+
buttonClassName?: string;
|
|
6
|
+
type?: "button" | "submit" | "reset";
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
onAction?: () => Promise<unknown>;
|
|
9
|
+
onClick?: (event: MouseEvent<HTMLButtonElement>) => void;
|
|
10
|
+
onDone?: (result: unknown) => void;
|
|
11
|
+
onError?: (error: unknown) => void;
|
|
12
|
+
onFinally?: () => void;
|
|
13
|
+
children?: ReactNode;
|
|
14
|
+
loadingChildren?: ReactNode;
|
|
15
|
+
renderContent?: () => ReactNode;
|
|
16
|
+
renderLoading?: () => ReactNode;
|
|
17
|
+
loadingText?: string;
|
|
18
|
+
showSpinner?: boolean;
|
|
19
|
+
}
|
|
20
|
+
declare function Button({ buttonClassName, type, disabled, onAction, onClick, onDone, onError, onFinally, children, loadingChildren, renderContent, renderLoading, loadingText, showSpinner, }: ButtonProps): react_jsx_runtime.JSX.Element;
|
|
21
|
+
|
|
22
|
+
export { Button, type ButtonProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// src/components/Button.tsx
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
function Button({
|
|
5
|
+
buttonClassName = "btn btn-primary btn-lg",
|
|
6
|
+
type = "button",
|
|
7
|
+
disabled = false,
|
|
8
|
+
onAction,
|
|
9
|
+
onClick,
|
|
10
|
+
onDone,
|
|
11
|
+
onError,
|
|
12
|
+
onFinally,
|
|
13
|
+
children = "Click me",
|
|
14
|
+
loadingChildren,
|
|
15
|
+
renderContent,
|
|
16
|
+
renderLoading,
|
|
17
|
+
loadingText = "Loading...",
|
|
18
|
+
showSpinner = true
|
|
19
|
+
}) {
|
|
20
|
+
const [loading, setLoading] = useState(false);
|
|
21
|
+
const handleClick = async (event) => {
|
|
22
|
+
if (loading) return;
|
|
23
|
+
onClick?.(event);
|
|
24
|
+
if (event.defaultPrevented) return;
|
|
25
|
+
if (!onAction) return;
|
|
26
|
+
try {
|
|
27
|
+
setLoading(true);
|
|
28
|
+
const result = await onAction();
|
|
29
|
+
onDone?.(result);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
onError?.(error);
|
|
32
|
+
} finally {
|
|
33
|
+
setLoading(false);
|
|
34
|
+
onFinally?.();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
return /* @__PURE__ */ jsx("div", { className: `w-100 text-center mb-3`, children: /* @__PURE__ */ jsx(
|
|
38
|
+
"button",
|
|
39
|
+
{
|
|
40
|
+
type,
|
|
41
|
+
className: `${buttonClassName} ${loading ? "async-btn--loading" : ""}`,
|
|
42
|
+
onClick: handleClick,
|
|
43
|
+
disabled: disabled || loading,
|
|
44
|
+
children: loading ? renderLoading?.() ?? loadingChildren ?? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
45
|
+
showSpinner && /* @__PURE__ */ jsx(
|
|
46
|
+
"span",
|
|
47
|
+
{
|
|
48
|
+
className: "spinner-border spinner-border-sm me-2 async-btn__spinner",
|
|
49
|
+
role: "status",
|
|
50
|
+
"aria-hidden": "true"
|
|
51
|
+
}
|
|
52
|
+
),
|
|
53
|
+
loadingText
|
|
54
|
+
] }) : renderContent?.() ?? children
|
|
55
|
+
}
|
|
56
|
+
) });
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
Button
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/Button.tsx"],"sourcesContent":["import { useState, type ReactNode, type MouseEvent } from \"react\";\r\nimport \"./Button.scss\";\r\n\r\nexport interface ButtonProps {\r\n buttonClassName?: string;\r\n type?: \"button\" | \"submit\" | \"reset\";\r\n disabled?: boolean;\r\n\r\n onAction?: () => Promise<unknown>;\r\n onClick?: (event: MouseEvent<HTMLButtonElement>) => void;\r\n onDone?: (result: unknown) => void;\r\n onError?: (error: unknown) => void;\r\n onFinally?: () => void;\r\n\r\n children?: ReactNode;\r\n loadingChildren?: ReactNode;\r\n\r\n renderContent?: () => ReactNode;\r\n renderLoading?: () => ReactNode;\r\n\r\n loadingText?: string;\r\n showSpinner?: boolean;\r\n}\r\n\r\nexport function Button({\r\n buttonClassName = \"btn btn-primary btn-lg\",\r\n type = \"button\",\r\n disabled = false,\r\n\r\n onAction,\r\n onClick,\r\n onDone,\r\n onError,\r\n onFinally,\r\n\r\n children = \"Click me\",\r\n\r\n loadingChildren,\r\n renderContent,\r\n renderLoading,\r\n\r\n loadingText = \"Loading...\",\r\n showSpinner = true,\r\n}: ButtonProps) {\r\n const [loading, setLoading] = useState(false);\r\n\r\n const handleClick = async (event: MouseEvent<HTMLButtonElement>) => {\r\n if (loading) return;\r\n\r\n onClick?.(event);\r\n if (event.defaultPrevented) return;\r\n if (!onAction) return;\r\n\r\n try {\r\n setLoading(true);\r\n const result = await onAction();\r\n onDone?.(result);\r\n } catch (error) {\r\n onError?.(error);\r\n } finally {\r\n setLoading(false);\r\n onFinally?.();\r\n }\r\n };\r\n\r\n return (\r\n <div className={`w-100 text-center mb-3`}>\r\n <button\r\n type={type}\r\n className={`${buttonClassName} ${loading ? \"async-btn--loading\" : \"\"}`}\r\n onClick={handleClick}\r\n disabled={disabled || loading}\r\n >\r\n {loading ? (\r\n renderLoading?.() ??\r\n loadingChildren ?? (\r\n <>\r\n {showSpinner && (\r\n <span\r\n className=\"spinner-border spinner-border-sm me-2 async-btn__spinner\"\r\n role=\"status\"\r\n aria-hidden=\"true\"\r\n />\r\n )}\r\n {loadingText}\r\n </>\r\n )\r\n ) : (\r\n renderContent?.() ?? children\r\n )}\r\n </button>\r\n </div>\r\n );\r\n}\r\n"],"mappings":";AAAA,SAAS,gBAAiD;AA4E9C,mBAEI,KAFJ;AApDL,SAAS,OAAO;AAAA,EACrB,kBAAkB;AAAA,EAClB,OAAO;AAAA,EACP,WAAW;AAAA,EAEX;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,WAAW;AAAA,EAEX;AAAA,EACA;AAAA,EACA;AAAA,EAEA,cAAc;AAAA,EACd,cAAc;AAChB,GAAgB;AACd,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,KAAK;AAE5C,QAAM,cAAc,OAAO,UAAyC;AAClE,QAAI,QAAS;AAEb,cAAU,KAAK;AACf,QAAI,MAAM,iBAAkB;AAC5B,QAAI,CAAC,SAAU;AAEf,QAAI;AACF,iBAAW,IAAI;AACf,YAAM,SAAS,MAAM,SAAS;AAC9B,eAAS,MAAM;AAAA,IACjB,SAAS,OAAO;AACd,gBAAU,KAAK;AAAA,IACjB,UAAE;AACA,iBAAW,KAAK;AAChB,kBAAY;AAAA,IACd;AAAA,EACF;AAEA,SACE,oBAAC,SAAI,WAAW,0BACd;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA,WAAW,GAAG,eAAe,IAAI,UAAU,uBAAuB,EAAE;AAAA,MACpE,SAAS;AAAA,MACT,UAAU,YAAY;AAAA,MAErB,oBACC,gBAAgB,KAChB,mBACE,iCACG;AAAA,uBACC;AAAA,UAAC;AAAA;AAAA,YACC,WAAU;AAAA,YACV,MAAK;AAAA,YACL,eAAY;AAAA;AAAA,QACd;AAAA,QAED;AAAA,SACH,IAGF,gBAAgB,KAAK;AAAA;AAAA,EAEzB,GACF;AAEJ;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sparkstudio/common-ui",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.cjs",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.cjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"dev": "vite",
|
|
23
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --tsconfig tsconfig.lib.json",
|
|
24
|
+
"lint": "eslint .",
|
|
25
|
+
"preview": "vite preview",
|
|
26
|
+
"start": "vite"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"react": ">=18.0.0 <20.0.0",
|
|
30
|
+
"react-dom": ">=18.0.0 <20.0.0"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@fortawesome/fontawesome-free": "^7.1.0",
|
|
34
|
+
"@popperjs/core": "^2.11.8",
|
|
35
|
+
"bootstrap": "^5.3.8",
|
|
36
|
+
"esbuild-sass-plugin": "^3.3.1",
|
|
37
|
+
"highcharts": "^12.4.0",
|
|
38
|
+
"highcharts-react-official": "^3.2.3"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@eslint/js": "^9.36.0",
|
|
42
|
+
"@types/node": "^24.6.0",
|
|
43
|
+
"@types/react": "^18.3.0",
|
|
44
|
+
"@types/react-dom": "^18.3.0",
|
|
45
|
+
"@vitejs/plugin-react": "^5.0.4",
|
|
46
|
+
"eslint": "^9.36.0",
|
|
47
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
48
|
+
"eslint-plugin-react-refresh": "^0.4.22",
|
|
49
|
+
"globals": "^16.4.0",
|
|
50
|
+
"react": "^18.3.0",
|
|
51
|
+
"react-dom": "^18.3.0",
|
|
52
|
+
"sass": "^1.80.0",
|
|
53
|
+
"tsup": "^8.5.1",
|
|
54
|
+
"typescript": "~5.9.3",
|
|
55
|
+
"typescript-eslint": "^8.45.0",
|
|
56
|
+
"vite": "^7.1.7"
|
|
57
|
+
}
|
|
58
|
+
}
|