@codella-software/react 2.0.0 → 2.1.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 +124 -0
- package/dist/index.cjs +0 -119
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +1 -120
- package/dist/index.mjs.map +1 -1
- package/dist/react/src/tabs/index.d.ts +5 -7
- package/dist/react/src/tabs/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/react/src/tabs/ResponsiveTabs.d.ts +0 -50
- package/dist/react/src/tabs/ResponsiveTabs.d.ts.map +0 -1
package/README.md
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# @codella-software/react
|
|
2
|
+
|
|
3
|
+
React hooks for Codella core services - FormBuilder, TableBuilder, FiltersAndSort, TabsService, APIService, and LiveUpdatesService.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **useFormBuilder** - Manage form state, validation, and submission
|
|
8
|
+
- **useTableService** - Manage dynamic table data, filtering, and sorting
|
|
9
|
+
- **useFiltersAndSort** - Handle complex filtering and sorting logic
|
|
10
|
+
- **useTabsService** - Manage tab state and navigation (use CLI templates for responsive components)
|
|
11
|
+
- **useAPIService** - RESTful API client with authentication, interceptors, and middleware hooks
|
|
12
|
+
- **useLiveUpdates** - Real-time data updates via WebSocket or Server-Sent Events
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @codella-software/utils @codella-software/react
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
### useFormBuilder
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { useFormBuilder } from '@codella-software/react';
|
|
26
|
+
|
|
27
|
+
function MyForm() {
|
|
28
|
+
const { values, errors, submit } = useFormBuilder({
|
|
29
|
+
fields: [
|
|
30
|
+
{ name: 'email', type: 'text', validators: ['required', 'email'] },
|
|
31
|
+
{ name: 'password', type: 'password', validators: ['required'] }
|
|
32
|
+
],
|
|
33
|
+
onSubmit: (data) => console.log(data)
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<form onSubmit={submit}>
|
|
38
|
+
{/* Form fields */}
|
|
39
|
+
</form>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### useTableService
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { useTableService } from '@codella-software/react';
|
|
48
|
+
|
|
49
|
+
function MyTable() {
|
|
50
|
+
const {
|
|
51
|
+
data,
|
|
52
|
+
filteredData,
|
|
53
|
+
sort,
|
|
54
|
+
filter
|
|
55
|
+
} = useTableService({
|
|
56
|
+
data: users,
|
|
57
|
+
columns: userColumns
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<table>
|
|
62
|
+
{/* Table content */}
|
|
63
|
+
</table>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### useAPIService
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import { useAPIService } from '@codella-software/react';
|
|
72
|
+
import { useEffect, useState } from 'react';
|
|
73
|
+
|
|
74
|
+
function UsersList() {
|
|
75
|
+
const [users, setUsers] = useState([]);
|
|
76
|
+
const [loading, setLoading] = useState(false);
|
|
77
|
+
|
|
78
|
+
const api = useAPIService({
|
|
79
|
+
baseURL: 'https://api.example.com',
|
|
80
|
+
hooks: {
|
|
81
|
+
onBeforeRequest: () => setLoading(true),
|
|
82
|
+
onAfterResponse: () => setLoading(false),
|
|
83
|
+
onError: (ctx) => console.error('Error:', ctx.error)
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// Add request interceptor to include custom headers
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
api.interceptors.request.use((config) => ({
|
|
90
|
+
...config,
|
|
91
|
+
headers: { ...config.headers, 'X-App-Version': '2.0' }
|
|
92
|
+
}));
|
|
93
|
+
|
|
94
|
+
// Add response interceptor to transform data
|
|
95
|
+
api.interceptors.response.use((response) => ({
|
|
96
|
+
...response,
|
|
97
|
+
data: Array.isArray(response.data) ? response.data : [response.data]
|
|
98
|
+
}));
|
|
99
|
+
}, [api]);
|
|
100
|
+
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
api.get('/users').then(setUsers);
|
|
103
|
+
}, [api]);
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<div>
|
|
107
|
+
{loading && <p>Loading...</p>}
|
|
108
|
+
<ul>
|
|
109
|
+
{users.map(user => <li key={user.id}>{user.name}</li>)}
|
|
110
|
+
</ul>
|
|
111
|
+
</div>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
See [API Service Documentation](https://CodellaSoftware.github.io/codella-utils/api-service/) for interceptors, middleware hooks, and authentication patterns.
|
|
117
|
+
|
|
118
|
+
## Documentation
|
|
119
|
+
|
|
120
|
+
For full API documentation, visit [https://CodellaSoftware.github.io/codella-utils/](https://CodellaSoftware.github.io/codella-utils/)
|
|
121
|
+
|
|
122
|
+
## License
|
|
123
|
+
|
|
124
|
+
MIT
|
package/dist/index.cjs
CHANGED
|
@@ -1983,127 +1983,8 @@ function useSetActiveTab() {
|
|
|
1983
1983
|
previousTab: () => service.previousTab()
|
|
1984
1984
|
};
|
|
1985
1985
|
}
|
|
1986
|
-
function ResponsiveTabs({
|
|
1987
|
-
className = "",
|
|
1988
|
-
tabClassName = "",
|
|
1989
|
-
activeTabClassName = "",
|
|
1990
|
-
selectClassName = "",
|
|
1991
|
-
breakpoint = 768,
|
|
1992
|
-
showBadges = true,
|
|
1993
|
-
icon = true
|
|
1994
|
-
}) {
|
|
1995
|
-
const [isMobile, setIsMobile] = react.useState(false);
|
|
1996
|
-
const activeTab = useActiveTab();
|
|
1997
|
-
const tabs = useTabs();
|
|
1998
|
-
const { setActiveTab } = useSetActiveTab();
|
|
1999
|
-
react.useEffect(() => {
|
|
2000
|
-
const handleResize = () => {
|
|
2001
|
-
setIsMobile(window.innerWidth < breakpoint);
|
|
2002
|
-
};
|
|
2003
|
-
handleResize();
|
|
2004
|
-
window.addEventListener("resize", handleResize);
|
|
2005
|
-
return () => {
|
|
2006
|
-
window.removeEventListener("resize", handleResize);
|
|
2007
|
-
};
|
|
2008
|
-
}, [breakpoint]);
|
|
2009
|
-
if (!activeTab) {
|
|
2010
|
-
return null;
|
|
2011
|
-
}
|
|
2012
|
-
return isMobile ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
2013
|
-
TabsSelect,
|
|
2014
|
-
{
|
|
2015
|
-
tabs,
|
|
2016
|
-
activeTabId: activeTab.id,
|
|
2017
|
-
onTabChange: setActiveTab,
|
|
2018
|
-
className: selectClassName
|
|
2019
|
-
}
|
|
2020
|
-
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
2021
|
-
TabsList,
|
|
2022
|
-
{
|
|
2023
|
-
tabs,
|
|
2024
|
-
activeTabId: activeTab.id,
|
|
2025
|
-
onTabChange: setActiveTab,
|
|
2026
|
-
className,
|
|
2027
|
-
tabClassName,
|
|
2028
|
-
activeTabClassName,
|
|
2029
|
-
showBadges,
|
|
2030
|
-
icon
|
|
2031
|
-
}
|
|
2032
|
-
);
|
|
2033
|
-
}
|
|
2034
|
-
function TabsList({
|
|
2035
|
-
tabs,
|
|
2036
|
-
activeTabId,
|
|
2037
|
-
onTabChange,
|
|
2038
|
-
className = "",
|
|
2039
|
-
tabClassName = "",
|
|
2040
|
-
activeTabClassName = "",
|
|
2041
|
-
showBadges = true,
|
|
2042
|
-
icon = true
|
|
2043
|
-
}) {
|
|
2044
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2045
|
-
"div",
|
|
2046
|
-
{
|
|
2047
|
-
role: "tablist",
|
|
2048
|
-
className: `flex border-b border-gray-200 ${className}`,
|
|
2049
|
-
"aria-label": "Tabs",
|
|
2050
|
-
children: tabs.map((tab) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2051
|
-
"button",
|
|
2052
|
-
{
|
|
2053
|
-
role: "tab",
|
|
2054
|
-
"aria-selected": tab.id === activeTabId,
|
|
2055
|
-
"aria-controls": `tabpanel-${tab.id}`,
|
|
2056
|
-
id: `tab-${tab.id}`,
|
|
2057
|
-
onClick: () => !tab.disabled && onTabChange(tab.id),
|
|
2058
|
-
disabled: tab.disabled,
|
|
2059
|
-
className: `
|
|
2060
|
-
relative px-4 py-2 text-sm font-medium transition-colors
|
|
2061
|
-
${tab.disabled ? "text-gray-400 cursor-not-allowed" : "text-gray-700 hover:text-gray-900"}
|
|
2062
|
-
${tab.id === activeTabId ? `text-blue-600 border-b-2 border-blue-600 ${activeTabClassName}` : ""}
|
|
2063
|
-
${tabClassName}
|
|
2064
|
-
`,
|
|
2065
|
-
children: /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex items-center gap-2", children: [
|
|
2066
|
-
icon && tab.icon && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-lg", children: tab.icon }),
|
|
2067
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { children: tab.label }),
|
|
2068
|
-
showBadges && tab.badge && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "ml-1 inline-flex items-center justify-center px-2 py-1 text-xs font-semibold leading-none text-white transform translate-y-px bg-red-600 rounded-full", children: tab.badge })
|
|
2069
|
-
] })
|
|
2070
|
-
},
|
|
2071
|
-
tab.id
|
|
2072
|
-
))
|
|
2073
|
-
}
|
|
2074
|
-
);
|
|
2075
|
-
}
|
|
2076
|
-
function TabsSelect({
|
|
2077
|
-
tabs,
|
|
2078
|
-
activeTabId,
|
|
2079
|
-
onTabChange,
|
|
2080
|
-
className = ""
|
|
2081
|
-
}) {
|
|
2082
|
-
tabs.find((t) => t.id === activeTabId);
|
|
2083
|
-
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: `w-full ${className}`, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2084
|
-
"select",
|
|
2085
|
-
{
|
|
2086
|
-
value: activeTabId,
|
|
2087
|
-
onChange: (e) => onTabChange(e.target.value),
|
|
2088
|
-
"aria-label": "Select a tab",
|
|
2089
|
-
className: `
|
|
2090
|
-
w-full px-3 py-2 text-sm font-medium border border-gray-300 rounded-md
|
|
2091
|
-
bg-white text-gray-900 hover:border-gray-400 focus:outline-none focus:ring-2
|
|
2092
|
-
focus:ring-blue-500 focus:ring-offset-0
|
|
2093
|
-
`,
|
|
2094
|
-
children: tabs.map((tab) => /* @__PURE__ */ jsxRuntime.jsxs("option", { value: tab.id, disabled: tab.disabled, children: [
|
|
2095
|
-
tab.label,
|
|
2096
|
-
" ",
|
|
2097
|
-
tab.badge ? `(${tab.badge})` : ""
|
|
2098
|
-
] }, tab.id))
|
|
2099
|
-
}
|
|
2100
|
-
) });
|
|
2101
|
-
}
|
|
2102
1986
|
exports.LiveUpdateProvider = LiveUpdateProvider;
|
|
2103
|
-
exports.ResponsiveTabs = ResponsiveTabs;
|
|
2104
|
-
exports.TabsList = TabsList;
|
|
2105
1987
|
exports.TabsProvider = TabsProvider;
|
|
2106
|
-
exports.TabsSelect = TabsSelect;
|
|
2107
1988
|
exports.useActiveTab = useActiveTab;
|
|
2108
1989
|
exports.useFiltersAndSort = useFiltersAndSort;
|
|
2109
1990
|
exports.useFormBuilder = useFormBuilder;
|