@codella-software/react 2.0.1 → 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 CHANGED
@@ -7,8 +7,8 @@ React hooks for Codella core services - FormBuilder, TableBuilder, FiltersAndSor
7
7
  - **useFormBuilder** - Manage form state, validation, and submission
8
8
  - **useTableService** - Manage dynamic table data, filtering, and sorting
9
9
  - **useFiltersAndSort** - Handle complex filtering and sorting logic
10
- - **useTabsService** - Manage tab state and navigation
11
- - **useAPIService** - RESTful API client with authentication
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
12
  - **useLiveUpdates** - Real-time data updates via WebSocket or Server-Sent Events
13
13
 
14
14
  ## Installation
@@ -69,20 +69,52 @@ function MyTable() {
69
69
 
70
70
  ```typescript
71
71
  import { useAPIService } from '@codella-software/react';
72
+ import { useEffect, useState } from 'react';
72
73
 
73
74
  function UsersList() {
75
+ const [users, setUsers] = useState([]);
76
+ const [loading, setLoading] = useState(false);
77
+
74
78
  const api = useAPIService({
75
- baseURL: 'https://api.example.com'
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
+ }
76
85
  });
77
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
+
78
101
  useEffect(() => {
79
102
  api.get('/users').then(setUsers);
80
103
  }, [api]);
81
104
 
82
- return <div>{/* Display users */}</div>;
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
+ );
83
113
  }
84
114
  ```
85
115
 
116
+ See [API Service Documentation](https://CodellaSoftware.github.io/codella-utils/api-service/) for interceptors, middleware hooks, and authentication patterns.
117
+
86
118
  ## Documentation
87
119
 
88
120
  For full API documentation, visit [https://CodellaSoftware.github.io/codella-utils/](https://CodellaSoftware.github.io/codella-utils/)
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;