Skip to content

Commit bf7e174

Browse files
authored
feat: inital setup (#2)
2 parents f173dab + ce13ab1 commit bf7e174

11 files changed

Lines changed: 282 additions & 86 deletions

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @basmasking @petermasking

.github/pull_request_template.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Fixes #
2+
3+
Changes proposed in this pull request:
4+
-
5+
-
6+
-

.github/workflows/nodejsci.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Node.js CI
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
build:
12+
13+
runs-on: ubuntu-latest
14+
15+
strategy:
16+
matrix:
17+
node-version: [lts/*]
18+
19+
steps:
20+
- name: ⚙️ Checkout Repository
21+
uses: actions/checkout@v6
22+
23+
- name: Use Node.js ${{ matrix.node-version }}
24+
uses: actions/setup-node@v6
25+
with:
26+
node-version: ${{ matrix.node-version }}
27+
cache: npm
28+
cache-dependency-path: '**/package-lock.json'
29+
30+
- name: 📦 Install Dependencies
31+
run: npm ci
32+
33+
- name: 🚀 Build Package
34+
run: npm run build
35+
36+
- name: ✅ Lint Package
37+
run: npm run lint

.github/workflows/publish.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
6+
permissions:
7+
id-token: write
8+
contents: read
9+
10+
jobs:
11+
publish:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: ⚙️ Checkout Repository
15+
uses: actions/checkout@v6
16+
17+
- name: 🛠️ Set up Node.js
18+
uses: actions/setup-node@v6
19+
with:
20+
node-version: '24.x'
21+
registry-url: 'https://registry.npmjs.org/'
22+
23+
- name: 📦 Install Dependencies
24+
run: npm ci
25+
26+
- name: 🚀 Publish Package
27+
run: npm publish
28+
29+
- name: ✅ Publish Complete
30+
run: echo "Package published successfully."

README.md

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# React Toolkit
2+
3+
A set of reusables for React mainly used by ourselves.
4+
5+
## Components
6+
7+
### ErrorBoundary
8+
9+
Catches errors and passes it to the provided element.
10+
11+
Usage:
12+
13+
```tsx
14+
import { ErrorBoundary } from '@maskingtech/react-toolkit';
15+
16+
function ErrorHandler({ error }: { error: unknown })
17+
{
18+
return <>Oops...</>;
19+
}
20+
21+
<ErrorBoundary element={ErrorHandler}>
22+
{/* Content goes here */}
23+
</ErrorBoundary>;
24+
```
25+
26+
## Hooks
27+
28+
### useDebouncedValue
29+
30+
Delays value updates for a period of time.
31+
32+
Usage:
33+
34+
```tsx
35+
import { useDebouncedValue } from '@maskingtech/react-toolkit';
36+
37+
function MyComponent()
38+
{
39+
const initialValue: number = 0; // required
40+
const onChange = (debouncedValue: number) => { }; // optional
41+
const delay = 300; // optional, default 500
42+
43+
const [debouncedValue, setValue] = useDebouncedValue(initialValue, onChange, delay);
44+
45+
return <p>
46+
{debouncedValue}
47+
<button onClick={() => setValue(debouncedValue + 1)}>Increase</button>
48+
</p>;
49+
}
50+
```
51+
52+
### useFocusOnMount
53+
54+
Gives a form element focus after mount.
55+
56+
Usage:
57+
58+
```tsx
59+
import { useFocusOnMount } from '@maskingtech/react-toolkit';
60+
61+
function MyComponent()
62+
{
63+
const ref = useFocusOnMount();
64+
65+
return <input type="text" ref={ref} />;
66+
}
67+
```
68+
69+
### useForm
70+
71+
Provides access to the data of a form after submitting.
72+
73+
Usage:
74+
75+
```tsx
76+
import { useForm } from '@maskingtech/react-toolkit';
77+
78+
function MyComponent()
79+
{
80+
const submitHandler = (data: FormData) { console.log(data.get('name')); };
81+
82+
const [ref, state, handleSubmit] = useForm(submitHandler);
83+
84+
// states: 'pristine' | 'dirty' | 'submitting'
85+
86+
return <form ref={ref} onSubmit={handleSubmit}>
87+
<input type="text" name="name" />
88+
<input type="submit" value="Submit" disabled={state !== 'dirty'} />
89+
</form>;
90+
}
91+
```
92+
93+
### useFormData
94+
95+
Provides access to the data of a form without submitting.
96+
97+
Usage:
98+
99+
```tsx
100+
import { useFormData } from '@maskingtech/react-toolkit';
101+
102+
function MyComponent()
103+
{
104+
const dataHandler = (data: FormData) { console.log(data.get('name')); };
105+
106+
const [ref, state, handleData] = useFormData(dataHandler);
107+
108+
// states: 'idle' | 'working'
109+
110+
return <form ref={ref}>
111+
<input type="text" name="name" />
112+
<input type="button" value="Go!" disabled={state !== 'working'} />
113+
</form>;
114+
}
115+
```
116+
117+
### useLoadData
118+
119+
Provides helpers for loading data.
120+
121+
Usage:
122+
123+
```tsx
124+
import { useLoadData } from '@maskingtech/react-toolkit';
125+
126+
async function getData() { /* get data here */ }
127+
128+
function MyComponent()
129+
{
130+
const [data, isLoading, refresh, setData] = useLoadData(getData);
131+
132+
if (isLoading) return <>Loading...</>;
133+
134+
return <p>
135+
{data}
136+
<button onClick={() => refresh()}>Refresh</button>
137+
</p>;
138+
}
139+
```
140+
141+
### usePagination
142+
143+
Provides helpers for loading paginated data.
144+
145+
Usage:
146+
147+
```tsx
148+
import { useLoadData } from '@maskingtech/react-toolkit';
149+
150+
async function getPageData(page: number) { /* get data here */ }
151+
152+
function MyComponent()
153+
{
154+
const [data, isLoading, isFinished, next, previous, reset, setData] = useLoadData(useLoadData);
155+
156+
if (isLoading) return <>Loading...</>;
157+
158+
return <p>
159+
{data}
160+
<button onClick={() => previous()}>Previous</button>
161+
<button onClick={() => next()}>Next</button>
162+
<button onClick={() => reset()}>Reset</button>
163+
</p>;
164+
}
165+
```

0 commit comments

Comments
 (0)