axokit-react 0.0.5 → 0.0.7
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 +47 -5
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -2
- package/dist/index.mjs +6 -2
- package/package.json +18 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# AxoKit — AsyncButton & useAsyncAction
|
|
1
|
+
# AxoKit React — AsyncButton & useAsyncAction
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Production-ready async interaction primitives for React & Next.js.
|
|
4
4
|
|
|
5
5
|
Package name: `axokit-react` (install with `npm install axokit-react`).
|
|
6
6
|
|
|
@@ -12,12 +12,20 @@ Package name: `axokit-react` (install with `npm install axokit-react`).
|
|
|
12
12
|
- Minimal styles; load your own CSS or Tailwind classes
|
|
13
13
|
- Works with React 18+
|
|
14
14
|
|
|
15
|
+
## Why AxoKit?
|
|
16
|
+
|
|
17
|
+
- Production‑ready async state management with minimal boilerplate.
|
|
18
|
+
- Works with both component and hook patterns.
|
|
19
|
+
- Tiny footprint and zero runtime dependencies.
|
|
20
|
+
- Fully typed for TypeScript and compatible with React 18+.
|
|
21
|
+
- Accessible ARIA attributes and easy styling with Tailwind or CSS.
|
|
22
|
+
|
|
15
23
|
## Installation
|
|
16
24
|
|
|
17
25
|
```bash
|
|
18
26
|
npm install axokit-react
|
|
19
27
|
# also install peer dependencies
|
|
20
|
-
|
|
28
|
+
Requires `react` and `react-dom` 18+ as peer dependencies.
|
|
21
29
|
```
|
|
22
30
|
|
|
23
31
|
## Usage (component)
|
|
@@ -44,6 +52,16 @@ function SaveButton() {
|
|
|
44
52
|
}
|
|
45
53
|
```
|
|
46
54
|
|
|
55
|
+
## Next.js (App Router)
|
|
56
|
+
|
|
57
|
+
If you're using the App Router, add `'use client'` at the top of your component file:
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
'use client';
|
|
61
|
+
|
|
62
|
+
import { AsyncButton } from 'axokit-react';
|
|
63
|
+
```
|
|
64
|
+
|
|
47
65
|
## Usage (hook)
|
|
48
66
|
|
|
49
67
|
```tsx
|
|
@@ -64,11 +82,33 @@ function HookExample() {
|
|
|
64
82
|
}
|
|
65
83
|
```
|
|
66
84
|
|
|
85
|
+
## Example
|
|
86
|
+
|
|
87
|
+
```tsx
|
|
88
|
+
import { AsyncButton } from 'axokit-react';
|
|
89
|
+
|
|
90
|
+
function Demo() {
|
|
91
|
+
const doWork = () => fetch('/api/work');
|
|
92
|
+
return (
|
|
93
|
+
<AsyncButton
|
|
94
|
+
onAction={doWork}
|
|
95
|
+
loadingText="Working…"
|
|
96
|
+
successText="Done!"
|
|
97
|
+
errorText="Failed"
|
|
98
|
+
showSpinner
|
|
99
|
+
className="btn"
|
|
100
|
+
>
|
|
101
|
+
Click me
|
|
102
|
+
</AsyncButton>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
67
107
|
## API
|
|
68
108
|
|
|
69
109
|
### `AsyncButton(props)`
|
|
70
110
|
|
|
71
|
-
- `onAction: () => Promise<
|
|
111
|
+
- `onAction: () => Promise<unknown>` — **required**.
|
|
72
112
|
- `loadingText?: string` — default: `"Loading..."`.
|
|
73
113
|
- `successText?: string` — default: `"Done!"`.
|
|
74
114
|
- `errorText?: string` — default: `"Try again"`.
|
|
@@ -106,4 +146,6 @@ Use `data-state` to adjust styles via CSS/Tailwind.
|
|
|
106
146
|
|
|
107
147
|
MIT
|
|
108
148
|
|
|
109
|
-
|
|
149
|
+
## Keywords
|
|
150
|
+
|
|
151
|
+
async, react, async-button, useAsyncAction, hook, component, loading, success, error, state, nextjs, tailwind, aria, accessible, typescript
|
package/dist/index.d.ts
CHANGED
|
@@ -14,9 +14,9 @@ interface UseAsyncActionReturn {
|
|
|
14
14
|
trigger: () => Promise<void>;
|
|
15
15
|
reset: () => void;
|
|
16
16
|
}
|
|
17
|
-
declare function useAsyncAction(action: () => Promise<
|
|
17
|
+
declare function useAsyncAction(action: () => Promise<unknown>, options?: UseAsyncActionOptions): UseAsyncActionReturn;
|
|
18
18
|
interface AsyncButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
19
|
-
onAction: () => Promise<
|
|
19
|
+
onAction: () => Promise<unknown>;
|
|
20
20
|
loadingText?: string;
|
|
21
21
|
successText?: string;
|
|
22
22
|
errorText?: string;
|
package/dist/index.js
CHANGED
|
@@ -138,7 +138,7 @@ function AsyncButton({
|
|
|
138
138
|
const label = getLabel();
|
|
139
139
|
if (state === "loading" && showSpinner) {
|
|
140
140
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", gap: "0.5em", alignItems: "center" }, children: [
|
|
141
|
-
/* @__PURE__ */ (0, import_jsx_runtime.
|
|
141
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
142
142
|
"svg",
|
|
143
143
|
{
|
|
144
144
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -151,7 +151,11 @@ function AsyncButton({
|
|
|
151
151
|
"stroke-linecap": "round",
|
|
152
152
|
"stroke-linejoin": "round",
|
|
153
153
|
className: "lucide lucide-loader-circle-icon lucide-loader-circle",
|
|
154
|
-
|
|
154
|
+
style: { animation: "spin 1s linear infinite" },
|
|
155
|
+
children: [
|
|
156
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { children: `@keyframes spin { to { transform: rotate(360deg); } }` }),
|
|
157
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M21 12a9 9 0 1 1-6.219-8.56" })
|
|
158
|
+
]
|
|
155
159
|
}
|
|
156
160
|
),
|
|
157
161
|
label
|
package/dist/index.mjs
CHANGED
|
@@ -101,7 +101,7 @@ function AsyncButton({
|
|
|
101
101
|
const label = getLabel();
|
|
102
102
|
if (state === "loading" && showSpinner) {
|
|
103
103
|
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: "0.5em", alignItems: "center" }, children: [
|
|
104
|
-
/* @__PURE__ */
|
|
104
|
+
/* @__PURE__ */ jsxs(
|
|
105
105
|
"svg",
|
|
106
106
|
{
|
|
107
107
|
xmlns: "http://www.w3.org/2000/svg",
|
|
@@ -114,7 +114,11 @@ function AsyncButton({
|
|
|
114
114
|
"stroke-linecap": "round",
|
|
115
115
|
"stroke-linejoin": "round",
|
|
116
116
|
className: "lucide lucide-loader-circle-icon lucide-loader-circle",
|
|
117
|
-
|
|
117
|
+
style: { animation: "spin 1s linear infinite" },
|
|
118
|
+
children: [
|
|
119
|
+
/* @__PURE__ */ jsx("style", { children: `@keyframes spin { to { transform: rotate(360deg); } }` }),
|
|
120
|
+
/* @__PURE__ */ jsx("path", { d: "M21 12a9 9 0 1 1-6.219-8.56" })
|
|
121
|
+
]
|
|
118
122
|
}
|
|
119
123
|
),
|
|
120
124
|
label
|
package/package.json
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "axokit-react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Headless async button and hook for React",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"react",
|
|
7
|
+
"async",
|
|
8
|
+
"async-button",
|
|
9
|
+
"useAsyncAction",
|
|
10
|
+
"hook",
|
|
11
|
+
"component",
|
|
12
|
+
"loading",
|
|
13
|
+
"success",
|
|
14
|
+
"error",
|
|
15
|
+
"state",
|
|
16
|
+
"nextjs",
|
|
17
|
+
"tailwind",
|
|
18
|
+
"aria",
|
|
19
|
+
"accessible",
|
|
20
|
+
"typescript"
|
|
21
|
+
],
|
|
5
22
|
"main": "dist/index.js",
|
|
6
23
|
"module": "dist/index.mjs",
|
|
7
24
|
"types": "dist/index.d.ts",
|