@royaltics/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.
Files changed (2) hide show
  1. package/README.md +341 -25
  2. package/package.json +34 -5
package/README.md CHANGED
@@ -1,6 +1,8 @@
1
- # 📦 Royaltics Utils & UI
1
+ # 📦 Royaltics UI & Utils
2
2
 
3
- 🚀 Una librería de utilidades y componentes UI reutilizables para proyectos JavaScript y TypeScript. Compatible con utilsJS y ESM.
3
+ 🚀 Librería de utilidades y componentes UI reutilizables para proyectos JavaScript y TypeScript. Compatible con ESM y utilsJS.
4
+
5
+ ---
4
6
 
5
7
  ## 📌 Instalación
6
8
 
@@ -18,51 +20,366 @@ yarn add royaltics
18
20
 
19
21
  ## 📂 Estructura del Paquete
20
22
 
21
- Esta librería está dividida en dos módulos principales:
23
+ - `royaltics/ui` Componentes UI y hooks
24
+ - `royaltics/utils` → Funciones utilitarias
22
25
 
23
- - `` → Funciones utilitarias
24
- - `` → Componentes UI
26
+ ---
27
+
28
+ ## 🎨 Ejemplo de Uso
29
+
30
+ ```tsx
31
+ import { Button, Input, Checkbox, YouTubePlayer } from "royaltics/ui";
32
+
33
+ const [inputs, setInputs] = useState({});
34
+
35
+ const App = () => (
36
+ <>
37
+ <Button lb="Guardar" onClick={() => alert("Guardado!")} />
38
+ <Input id="nombre" state={{inputs, setInputs}} lb="Nombre" />
39
+ <Checkbox id="activo" state={{inputs, setInputs}} lb="Activo" />
40
+ <YouTubePlayer videoId="dQw4w9WgXcQ" />
41
+ </>
42
+ );
43
+ ```
25
44
 
26
45
  ---
27
46
 
28
- ## 🛠 **Uso de Utilidades (**``**)**
47
+ ## 🧩 Documentación de Componentes
29
48
 
30
- ### 📅 **Ejemplo: Formatear fecha en español**
49
+ ### Buttons
31
50
 
32
- ```ts
33
- import { dateToStringEs } from "royaltics/utils";
51
+ #### **Button**
52
+
53
+ Botón estilizado y accesible.
34
54
 
35
- const fecha = new Date();
36
- console.log(dateToStringEs(fecha)); // "Lunes, 30 de Marzo del 2023"
55
+ ```tsx
56
+ import { Button } from "royaltics/ui";
57
+ <Button lb="Guardar" onClick={...} theme="primary" />
37
58
  ```
38
59
 
39
- ### 🔢 **Ejemplo: formatear Numeros**
60
+ | Prop | Tipo | Requerido | Descripción |
61
+ |-----------|------------|-----------|-----------------------------------|
62
+ | lb | string | No | Texto del botón |
63
+ | onClick | function | No | Callback al hacer click |
64
+ | theme | string | No | `primary`, `secondary`, `danger`, `warn`, `default` |
65
+ | icon | ReactNode | No | Icono a mostrar |
66
+ | disabled | boolean | No | Deshabilita el botón |
67
+ | children | ReactNode | No | Contenido del botón |
40
68
 
41
- ```ts
42
- import { defaultFloat } from "royaltics/utils";
69
+ ---
70
+
71
+ ### Forms
72
+
73
+ #### **Input**
74
+
75
+ Campo de entrada de texto.
76
+
77
+ ```tsx
78
+ import { Input } from "royaltics/ui";
79
+ <Input id="nombre" state={{inputs, setInputs}} lb="Nombre" />
80
+ ```
81
+
82
+ | Prop | Tipo | Requerido | Descripción |
83
+ |-------------|------------|-----------|-----------------------------------|
84
+ | id | string | Sí | Identificador del input |
85
+ | state | object | Sí | `{inputs, setInputs}` |
86
+ | lb | string | No | Etiqueta |
87
+ | type | string | No | `text`, `number`, `email`, etc. |
88
+ | placeholder | string | No | Texto de ayuda |
89
+
90
+ ---
91
+
92
+ #### **Checkbox**
93
+
94
+ Checkbox controlado.
95
+
96
+ ```tsx
97
+ import { Checkbox } from "royaltics/ui";
98
+ <Checkbox id="activo" state={{inputs, setInputs}} lb="Activo" />
99
+ ```
100
+
101
+ | Prop | Tipo | Requerido | Descripción |
102
+ |-----------|------------|-----------|-----------------------------------|
103
+ | id | string | Sí | Identificador |
104
+ | state | object | Sí | `{inputs, setInputs}` |
105
+ | lb | string | No | Etiqueta |
106
+ | readOnly | boolean | No | Solo lectura |
107
+
108
+ ---
109
+
110
+ #### **RadioButton**
111
+
112
+ Radio button controlado.
113
+
114
+ ```tsx
115
+ import { RadioButton } from "royaltics/ui";
116
+ <RadioButton id="sexo" value="M" state={{inputs, setInputs}} lb="Masculino" />
117
+ ```
118
+
119
+ | Prop | Tipo | Requerido | Descripción |
120
+ |-----------|------------|-----------|-----------------------------------|
121
+ | id | string | Sí | Identificador |
122
+ | value | any | Sí | Valor del radio |
123
+ | state | object | Sí | `{inputs, setInputs}` |
124
+ | lb | string | No | Etiqueta |
125
+
126
+ ---
127
+
128
+ #### **Select**
129
+
130
+ Select estilizado.
131
+
132
+ ```tsx
133
+ import { Select } from "royaltics/ui";
134
+ <Select id="pais" data={paises} state={{inputs, setInputs}} lb="País" keyText="nombre" keyValue="id" />
135
+ ```
136
+
137
+ | Prop | Tipo | Requerido | Descripción |
138
+ |-----------|------------|-----------|-----------------------------------|
139
+ | id | string | Sí | Identificador |
140
+ | data | array | Sí | Opciones |
141
+ | state | object | Sí | `{inputs, setInputs}` |
142
+ | lb | string | No | Etiqueta |
143
+ | keyText | string | No | Propiedad de texto |
144
+ | keyValue | string | No | Propiedad de valor |
145
+
146
+ ---
147
+
148
+ #### **TextArea**
149
+
150
+ Área de texto multilínea.
151
+
152
+ ```tsx
153
+ import { TextArea } from "royaltics/ui";
154
+ <TextArea id="descripcion" state={{inputs, setInputs}} lb="Descripción" />
155
+ ```
156
+
157
+ | Prop | Tipo | Requerido | Descripción |
158
+ |-------------|------------|-----------|-----------------------------------|
159
+ | id | string | Sí | Identificador |
160
+ | state | object | Sí | `{inputs, setInputs}` |
161
+ | lb | string | No | Etiqueta |
162
+
163
+ ---
164
+
165
+ #### **ToogleSwitch**
166
+
167
+ Switch de activación.
168
+
169
+ ```tsx
170
+ import { ToogleSwitch } from "royaltics/ui";
171
+ <ToogleSwitch id="notificaciones" lb="Notificaciones" state={{inputs, setInputs}} />
172
+ ```
173
+
174
+ | Prop | Tipo | Requerido | Descripción |
175
+ |-----------|------------|-----------|-----------------------------------|
176
+ | id | string | Sí | Identificador |
177
+ | lb | string | Sí | Etiqueta |
178
+ | state | object | Sí | `{inputs, setInputs}` |
179
+
180
+ ---
43
181
 
44
- console.log(defaultFloat("5,599")); // 5.599
182
+ #### **InputAutocomplete**
183
+
184
+ Input con autocompletado remoto.
185
+
186
+ ```tsx
187
+ import { InputAutocomplete } from "royaltics/ui";
188
+ <InputAutocomplete id="usuario" api="/api/usuarios" state={{inputs, setInputs}} lb="Usuario" keyText="nombre" keyValue="id" />
45
189
  ```
46
190
 
191
+ | Prop | Tipo | Requerido | Descripción |
192
+ |-----------|------------|-----------|-----------------------------------|
193
+ | id | string | Sí | Identificador |
194
+ | api | string | Sí | Endpoint de búsqueda |
195
+ | state | object | Sí | `{inputs, setInputs}` |
196
+ | lb | string | No | Etiqueta |
197
+ | keyText | string | No | Propiedad de texto |
198
+ | keyValue | string | No | Propiedad de valor |
199
+
47
200
  ---
48
201
 
49
- ## 🎨 **Uso de Componentes UI (**``**)**
202
+ #### **Paginate**
50
203
 
51
- ### ▶️ **Ejemplo: Reproductor de YouTube**
204
+ Paginador para listas.
205
+
206
+ ```tsx
207
+ import { Paginate } from "royaltics/ui";
208
+ <Paginate rows={100} rowsPage={10} onChangue={...}>{/* contenido */}</Paginate>
209
+ ```
210
+
211
+ | Prop | Tipo | Requerido | Descripción |
212
+ |-------------|------------|-----------|-----------------------------------|
213
+ | rows | number | Sí | Total de filas |
214
+ | rowsPage | number | Sí | Filas por página |
215
+ | onChangue | function | Sí | Callback de cambio de página |
216
+ | children | ReactNode | Sí | Contenido |
217
+
218
+ ---
219
+
220
+ #### **PhotoCard**
221
+
222
+ Carga y muestra de foto de perfil.
223
+
224
+ ```tsx
225
+ import { PhotoCard } from "royaltics/ui";
226
+ <PhotoCard api="/api/usuarios/foto" photo={inputs.photo} set={setInputs} />
227
+ ```
228
+
229
+ | Prop | Tipo | Requerido | Descripción |
230
+ |-----------|------------|-----------|-----------------------------------|
231
+ | api | string | Sí | Endpoint de la foto |
232
+ | photo | string | Sí | URL de la foto |
233
+ | set | function | Sí | Setter para actualizar foto |
234
+ | theme | string | No | `small` o `default` |
235
+
236
+ ---
237
+
238
+ #### **YouTubePlayer**
239
+
240
+ Reproductor de videos de YouTube embebido.
52
241
 
53
242
  ```tsx
54
243
  import { YouTubePlayer } from "royaltics/ui";
244
+ <YouTubePlayer videoId="dQw4w9WgXcQ" />
245
+ ```
55
246
 
56
- const App = () => (
57
- <YouTubePlayer videoId="dQw4w9WgXcQ" />
58
- );
247
+ | Prop | Tipo | Requerido | Descripción |
248
+ |-----------|----------|-----------|-----------------------------------|
249
+ | videoId | string | Sí | ID del video de YouTube |
250
+ | className | string | No | Clase para el contenedor |
251
+ | options | object | No | `{ autoplay, controls, loop, mute }` |
252
+
253
+ ---
254
+
255
+ ## 🪝 Hooks
256
+
257
+ Todos los hooks están en `royaltics/ui/hooks`.
258
+
259
+ ### **useHttpState**
260
+
261
+ Hook para peticiones HTTP con estado y manejo de errores.
262
+
263
+ ```ts
264
+ import useHttpState from "royaltics/ui/hooks/useHttpState";
265
+ const { post, get, patch, deleteReq, file, isSending } = useHttpState();
266
+
267
+ get('/webhooks/googleapi/calendar/list', { data: { limit: 1 }, onSuccess: (data) => { setState({ event: data?.[0] }) } })
268
+ post('/services/generate-ats', {
269
+ data: {
270
+ action: action, date_start: inputs.date_start,
271
+ date_end: inputs.date_end, generate_sales: inputs.generate_sales, generate_buys: inputs.generate_buys,
272
+ type_report: inputs.type_report, cost_center_id: inputs.cost_center_id,
273
+ enterprise_id: enterprise?.id, all_sucursal: inputs.all_sucursal
274
+ },
275
+ onSuccess: (data) => {
276
+
277
+ }
278
+ })
279
+
280
+ patch(api, {
281
+ data: { user_id: Auth?.id, enterprise_id: 1, photo: e.target.files[0] },
282
+ content_type: 'file',
283
+ onSuccess: (data) => {
284
+
285
+ set({ photo: data.photo });
286
+ toast.success('Imagen Actualizada Correctamente!');
287
+ }
288
+ })
289
+
290
+ deleteReq(api, {
291
+ onSuccess: (data) => {
292
+ set({ photo: 'Photo.jpg' });
293
+ toast.success('Imagen Eliminada Correctamente!');
294
+ setPreview(null)
295
+ }
296
+ })
59
297
 
60
- export default App;
298
+ ```
299
+
300
+ ### **useNavigatorOnline**
301
+
302
+ Detecta si el navegador está online/offline.
303
+
304
+ ```ts
305
+ import useNavigatorOnline from "royaltics/ui/hooks/useNavigatorOnline";
306
+ const online = useNavigatorOnline();
307
+ ```
308
+
309
+ ### **useRouter**
310
+
311
+ Utilidades para navegación con React Router.
312
+
313
+ ```ts
314
+ import useRouter from "royaltics/ui/hooks/useRouter";
315
+ const { pathname, query, params, push, refresh } = useRouter();
316
+ ```
317
+
318
+ ---
319
+
320
+ ## 🧰 Reducers
321
+
322
+ ### **Reducer**
323
+
324
+ Reducer genérico para formularios.
325
+
326
+ ```ts
327
+ import { Reducer } from "royaltics/ui/reducers";
328
+ const [state, setState] = useReducer(Reducer, {});
61
329
  ```
62
330
 
63
331
  ---
64
332
 
65
- ## ⚙️ **Compilación y Desarrollo**
333
+ ## 🛡️ Validator
334
+
335
+ Funciones para validación de formularios en `royaltics/ui/validator/validator`.
336
+
337
+ - **isEmpty(value, minLength?)**
338
+ - **isInteger(value)**
339
+ - **isFloat(value)**
340
+ - **isUUID(value)**
341
+ - **isNumberDocument(doc_number)**
342
+ - **isEmail(value)**
343
+ - **isURL(value)**
344
+ - **isValidForm(inputs, rulesObject, toast?)**
345
+
346
+ ```ts
347
+ import { isEmail, isEmpty, isValidForm } from "royaltics/ui/validator/validator";
348
+ ```
349
+
350
+
351
+
352
+ Funciones para validación inputs completos en `royaltics/ui/validator/validator`.
353
+
354
+ - **isValidForm(inputs, rulesObject, toast?)**
355
+
356
+ ```ts
357
+ import { isValidForm } from "royaltics/ui/validator/validator";
358
+ import { toast } from "react-toastify"; //(optional)
359
+
360
+ /**
361
+ * type stringRules = 'req' | 'number' | 'str' | 'date' | 'array' | 'cb' | 'email' | `len:${number},${number}` | `max:${number}` | `min:${number}` | `len:${number}`;
362
+ * - type Rules = {
363
+ [Key: string]: { rules: stringRules[], name?: string, message?: string, cb?: (value?: any) => boolean | string, format?: (value: any) => any }
364
+ }**/
365
+
366
+ //
367
+ return isValidForm(inputs, {
368
+ business_names: { rules: ['req'], name: "Razon Social" },
369
+ cardid: { rules: ['req', 'str', 'len:5,13'], name: "Identificacion" },
370
+ datedoc: { rules: ['req'], name: "Fecha/Emision" },
371
+ emails: { rules: ['email'], name: 'Correo' },
372
+ vendor_id: { rules: ['req'], name: "Vendedor" },
373
+ box_id: { rules: ['req'], message: 'Se requiere la configuracion de caja, dirijase a la ventana de configuracion local' },
374
+ direction: { rules: ['req'], message: 'Ingresar una dirección' },
375
+ details: { rules: ['cb'], message: 'Ingrese al menos un empaque', cb: () => details.length > 0 && details [0].factor > 0 },
376
+ total: { rules: ['number', 'req'], name: 'Total' },
377
+ }, toast);
378
+
379
+ ```
380
+ ---
381
+
382
+ ## ⚙️ Compilación y Desarrollo
66
383
 
67
384
  Para compilar la librería:
68
385
 
@@ -78,7 +395,6 @@ pnpm dev
78
395
 
79
396
  ---
80
397
 
81
- ## 📜 **Licencia**
82
-
83
- MIT License © 2025 - Royaltics Solutions
398
+ ## 📜 Licencia
84
399
 
400
+ MIT License © 2025 - Royaltics
package/package.json CHANGED
@@ -1,19 +1,48 @@
1
1
  {
2
2
  "name": "@royaltics/ui",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "private": false,
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "type": "module",
9
9
  "files": [
10
- "dist",
11
- "dist/ui"
10
+ "dist"
12
11
  ],
13
12
  "exports": {
14
13
  ".": {
15
14
  "import": "./dist/index.js",
16
15
  "require": "./dist/index.cjs"
16
+ },
17
+ "./buttons": {
18
+ "import": "./dist/buttons/index.js",
19
+ "require": "./dist/buttons/index.cjs",
20
+ "types": "./dist/buttons/index.d.ts"
21
+ },
22
+ "./forms": {
23
+ "import": "./dist/forms/index.js",
24
+ "require": "./dist/forms/index.cjs",
25
+ "types": "./dist/forms/index.d.ts"
26
+ },
27
+ "./hooks": {
28
+ "import": "./dist/hooks/index.js",
29
+ "require": "./dist/hooks/index.cjs",
30
+ "types": "./dist/hooks/index.d.ts"
31
+ },
32
+ "./reducers": {
33
+ "import": "./dist/reducers/index.js",
34
+ "require": "./dist/reducers/index.cjs",
35
+ "types": "./dist/reducers/index.d.ts"
36
+ },
37
+ "./cards": {
38
+ "import": "./dist/cards/index.js",
39
+ "require": "./dist/cards/index.cjs",
40
+ "types": "./dist/cards/index.d.ts"
41
+ },
42
+ "./validators": {
43
+ "import": "./dist/validators/index.js",
44
+ "require": "./dist/validators/index.cjs",
45
+ "types": "./dist/validators/index.d.ts"
17
46
  }
18
47
  },
19
48
  "scripts": {
@@ -24,8 +53,8 @@
24
53
  "build:esm": "tsc --module ESNext --outDir dist/esm"
25
54
  },
26
55
  "peerDependencies": {
27
- "react": "^18.0.0",
28
- "react-dom": "^18.0.0"
56
+ "react": "^18 || ^19",
57
+ "react-dom": "^18 || ^19"
29
58
  },
30
59
  "devDependencies": {
31
60
  "@types/react": "^18.0.0",