flysoft-react-ui 1.0.1 → 1.0.3
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/AI_CONTEXT.md +156 -23
- package/README.md +4 -3
- package/dist/contexts/AuthContext.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/AI_CONTEXT.md
CHANGED
|
@@ -14,53 +14,81 @@ This document serves as the source of truth for AI models (Gemini, Claude, GPT,
|
|
|
14
14
|
|
|
15
15
|
## Component Categorization
|
|
16
16
|
|
|
17
|
-
### 1. Layouts
|
|
17
|
+
### 1. Layouts & Structure
|
|
18
18
|
- **AppLayout**: The main wrapper for applications.
|
|
19
19
|
- **Props**: `navbar` (NavbarInterface), `leftDrawer` (LeftDrawerInterface), `children`.
|
|
20
|
-
|
|
20
|
+
- **Card**: Generic container with shadow and rounded corners.
|
|
21
|
+
- **Accordion**: Collapsible content sections.
|
|
22
|
+
- **Collection**: Renders a list of items using a render prop or component.
|
|
23
|
+
- **TabsGroup / TabPanel**: Tabbed interfaces.
|
|
24
|
+
- **Menu**: Menu component.
|
|
25
|
+
- **DropdownMenu / DropdownPanel**: Components for building drop-down menus.
|
|
21
26
|
- **DashboardLayout**: Specialized layout for dashboard views with statistics.
|
|
22
27
|
- **SidebarLayout**: Layout with a persistent sidebar.
|
|
23
28
|
|
|
24
29
|
### 2. Form Controls
|
|
25
30
|
- **Button / LinkButton**: Standard buttons. Supports `variant` ('primary' | 'secondary' | 'danger' | 'ghost') and `icon`.
|
|
26
31
|
- **Input**: Text inputs.
|
|
27
|
-
- **AutocompleteInput**: Searchable dropdown.
|
|
28
|
-
- **
|
|
29
|
-
- **
|
|
30
|
-
- **
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
- **AutocompleteInput**: Searchable dropdown.
|
|
33
|
+
- **SearchSelectInput**: Specialized input for selecting from search results.
|
|
34
|
+
- **DatePicker / DateInput**: Date picking and input.
|
|
35
|
+
- **Checkbox**: Boolean selection.
|
|
36
|
+
- **RadioButtonGroup**: Single selection from a group.
|
|
37
|
+
- **ThemeSwitcher**: Component to toggle theme (light/dark).
|
|
38
|
+
- **FormPattern**: Template pattern for building forms.
|
|
39
|
+
|
|
40
|
+
### 3. Data Display
|
|
33
41
|
- **DataTable<T>**: High-performance table.
|
|
34
42
|
- **Props**: `columns` (array of definitions), `rows` (data), `isLoading`.
|
|
35
|
-
- **Card**: Generic container with shadow and rounded corners.
|
|
36
43
|
- **DataField**: Displays a Label + Value pair, useful for detail views.
|
|
37
|
-
- **
|
|
38
|
-
- **Collection**: Renders a list of items using a render prop or component.
|
|
39
|
-
- **TabsGroup / TabPanel**: Tabbed interfaces.
|
|
44
|
+
- **Pagination**: Pagination controls.
|
|
40
45
|
|
|
41
46
|
### 4. Utilities & Feedback
|
|
42
47
|
- **Dialog**: Modal windows for confirmation or complex forms.
|
|
48
|
+
- **Filter / FiltersDialog**: Components for filtering lists/tables.
|
|
43
49
|
- **Snackbar**: Toast notifications. Requires `SnackbarContainer` at the app root.
|
|
44
50
|
- **Loader**: Visual loading indicator.
|
|
45
|
-
- **Badge
|
|
51
|
+
- **Badge**: Status indicators.
|
|
52
|
+
- **Avatar**: User profile images.
|
|
53
|
+
- **RoadMap**: Progress or stage visualization.
|
|
54
|
+
|
|
55
|
+
### 5. Ready-to-use Templates
|
|
56
|
+
- **LoginForm**
|
|
57
|
+
- **RegistrationForm**
|
|
58
|
+
- **ContactForm**
|
|
46
59
|
|
|
47
60
|
## Common Patterns
|
|
48
61
|
|
|
49
|
-
### Basic Page
|
|
62
|
+
### Basic Page Usage (Simple Card)
|
|
63
|
+
Use this pattern for simple pages that do not require the full `AppLayout` wrapper or when inserting into an existing structure.
|
|
64
|
+
```tsx
|
|
65
|
+
import { Card, Button } from 'flysoft-react-ui';
|
|
66
|
+
|
|
67
|
+
export default function SimplePage() {
|
|
68
|
+
return (
|
|
69
|
+
<div className="p-4">
|
|
70
|
+
<Card>
|
|
71
|
+
<h2 className="text-xl font-bold mb-4">Content Title</h2>
|
|
72
|
+
<p className="mb-4">This is the content within a basic card.</p>
|
|
73
|
+
<Button variant="primary" onClick={() => console.log('Clicked')}>
|
|
74
|
+
Action
|
|
75
|
+
</Button>
|
|
76
|
+
</Card>
|
|
77
|
+
</div>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Full Page Layout
|
|
50
83
|
```tsx
|
|
51
|
-
import { AppLayout
|
|
84
|
+
import { AppLayout } from 'flysoft-react-ui';
|
|
52
85
|
|
|
53
86
|
export default function Page() {
|
|
54
87
|
return (
|
|
55
88
|
<AppLayout
|
|
56
89
|
navbar={{ title: "My Page" }}
|
|
57
90
|
>
|
|
58
|
-
|
|
59
|
-
<Card>
|
|
60
|
-
<h2>Content</h2>
|
|
61
|
-
<Button variant="primary" onClick={() => {}}>Action</Button>
|
|
62
|
-
</Card>
|
|
63
|
-
</div>
|
|
91
|
+
{/* Children content goes here */}
|
|
64
92
|
</AppLayout>
|
|
65
93
|
);
|
|
66
94
|
}
|
|
@@ -80,5 +108,110 @@ const columns: DataTableColumn<User>[] = [
|
|
|
80
108
|
<DataTable columns={columns} rows={users} />
|
|
81
109
|
```
|
|
82
110
|
|
|
83
|
-
##
|
|
84
|
-
|
|
111
|
+
## Contexts & State Management
|
|
112
|
+
|
|
113
|
+
### 1. AuthContext
|
|
114
|
+
Manages user authentication state.
|
|
115
|
+
- **Provider**: `AuthProvider`
|
|
116
|
+
- **Hook**: `useContext(AuthContext)`
|
|
117
|
+
- **Key Features**: `user`, `login`, `logout`, `isAuthenticated`.
|
|
118
|
+
```tsx
|
|
119
|
+
import { AuthProvider, AuthContext } from 'flysoft-react-ui';
|
|
120
|
+
|
|
121
|
+
// Wrap app
|
|
122
|
+
<AuthProvider
|
|
123
|
+
getToken={async (user, pass) => ({ token: '...' })}
|
|
124
|
+
getUserData={async (token) => ({ id: 1, name: 'User' })}
|
|
125
|
+
>
|
|
126
|
+
<App />
|
|
127
|
+
</AuthProvider>
|
|
128
|
+
|
|
129
|
+
// Use
|
|
130
|
+
const { login, user } = useContext(AuthContext);
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### 2. CrudContext<T>
|
|
134
|
+
Powerful context for managing standard CRUD operations with pagination, filtering, and loading states.
|
|
135
|
+
- **Provider**: `CrudProvider<T>`
|
|
136
|
+
- **Hook**: `useCrud<T>()`
|
|
137
|
+
- **Key Features**: Auto-fetching, `list`, `item`, `pagination` node, `isLoading`, CRUD actions (`createItem`, `updateItem`, `deleteItem`).
|
|
138
|
+
|
|
139
|
+
**Usage:**
|
|
140
|
+
```tsx
|
|
141
|
+
import { CrudProvider, useCrud, DataTable } from 'flysoft-react-ui';
|
|
142
|
+
|
|
143
|
+
function UserList() {
|
|
144
|
+
const { list, isLoading, pagination } = useCrud<User>();
|
|
145
|
+
return (
|
|
146
|
+
<div>
|
|
147
|
+
<DataTable rows={list} isLoading={isLoading} ... />
|
|
148
|
+
{pagination}
|
|
149
|
+
</div>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Wrapper
|
|
154
|
+
<CrudProvider
|
|
155
|
+
getPromise={userApi.getAll}
|
|
156
|
+
postPromise={userApi.create}
|
|
157
|
+
putPromise={userApi.update}
|
|
158
|
+
deletePromise={userApi.delete}
|
|
159
|
+
>
|
|
160
|
+
<UserList />
|
|
161
|
+
</CrudProvider>
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### 3. AppLayoutContext
|
|
165
|
+
Controls the global layout state (navbar, visual settings). usually handled internally by `AppLayout` but accessible if needed.
|
|
166
|
+
- **Provider**: `AppLayoutProvider`
|
|
167
|
+
- **Hook**: `useAppLayout()`
|
|
168
|
+
|
|
169
|
+
### 4. ThemeContext
|
|
170
|
+
Manages the visual theme of the application.
|
|
171
|
+
- **Provider**: `ThemeProvider`
|
|
172
|
+
- **Hook**: `useTheme()`
|
|
173
|
+
- **Features**: Switch between `light`, `dark`, `blue`, `green` themes or custom themes.
|
|
174
|
+
|
|
175
|
+
```tsx
|
|
176
|
+
## Hooks & Services
|
|
177
|
+
|
|
178
|
+
### 1. apiClient (Service)
|
|
179
|
+
A singleton wrapper around Axios with built-in token management and simplified methods.
|
|
180
|
+
- **Methods**: `get`, `post`, `put`, `del`, `getFile`, `downloadFile`, `uploadFile`.
|
|
181
|
+
- **Configuration**: Use `setApiClientTokenProvider(() => token)` to handle auth globally.
|
|
182
|
+
|
|
183
|
+
```tsx
|
|
184
|
+
import { apiClient } from 'flysoft-react-ui';
|
|
185
|
+
|
|
186
|
+
// GET request
|
|
187
|
+
const users = await apiClient.get<User[]>({ url: '/api/users' });
|
|
188
|
+
|
|
189
|
+
// POST request with body
|
|
190
|
+
const result = await apiClient.post({ url: '/api/users', body: newUser });
|
|
191
|
+
|
|
192
|
+
// Download file (handles blob and filename automatically)
|
|
193
|
+
await apiClient.downloadFile({ url: '/api/report/pdf' });
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### 2. useAsyncRequest (Hook)
|
|
197
|
+
Simplifies handling async operations (loading states, success/error messages via Snackbar).
|
|
198
|
+
- **Props**: `successMessage`, `errorMessage`, `onSuccess`, `onError`.
|
|
199
|
+
- **Returns**: `execute(promiseFn)`, `isLoading`.
|
|
200
|
+
|
|
201
|
+
```tsx
|
|
202
|
+
import { useAsyncRequest, apiClient } from 'flysoft-react-ui';
|
|
203
|
+
|
|
204
|
+
function UserForm() {
|
|
205
|
+
const { execute, isLoading } = useAsyncRequest({
|
|
206
|
+
successMessage: "User created successfully!",
|
|
207
|
+
errorMessage: "Failed to create user."
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
const handleSubmit = async (data) => {
|
|
211
|
+
await execute(async () => {
|
|
212
|
+
await apiClient.post({ url: '/api/users', body: data });
|
|
213
|
+
});
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
return <Button loading={isLoading} onClick={handleSubmit}>Save</Button>;
|
|
217
|
+
}
|
package/README.md
CHANGED
|
@@ -91,9 +91,10 @@ SIEMPRE usa los componentes de flysoft-react-ui antes de crear nuevos:
|
|
|
91
91
|
|
|
92
92
|
## Componentes Disponibles:
|
|
93
93
|
|
|
94
|
-
-
|
|
95
|
-
-
|
|
96
|
-
-
|
|
94
|
+
- Layouts: AppLayout, DashboardLayout, SidebarLayout, Card, Menu, TabsGroup
|
|
95
|
+
- Forms: Button, Input, AutocompleteInput, DatePicker, Checkbox
|
|
96
|
+
- Data: DataTable, DataField, Pagination
|
|
97
|
+
- Templates: LoginForm, RegistrationForm, ContactForm
|
|
97
98
|
|
|
98
99
|
## Para formularios:
|
|
99
100
|
|
|
@@ -117,9 +117,9 @@ export const AuthProvider = ({ children, getToken, getUserData, removeToken, })
|
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
catch (error) {
|
|
120
|
-
console.error("Error durante el login:", error);
|
|
121
120
|
setUser(null);
|
|
122
121
|
setIsAuthenticated(false);
|
|
122
|
+
throw error;
|
|
123
123
|
}
|
|
124
124
|
finally {
|
|
125
125
|
setIsLoading(false);
|