flysoft-react-ui 0.2.10 → 0.3.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 +0 -22
- package/dist/App.d.ts.map +1 -1
- package/dist/App.js +2 -1
- package/dist/components/form-controls/Input.js +5 -5
- package/dist/contexts/AuthContext.d.ts +29 -0
- package/dist/contexts/AuthContext.d.ts.map +1 -0
- package/dist/contexts/AuthContext.js +62 -0
- package/dist/contexts/ThemeContext.d.ts.map +1 -1
- package/dist/contexts/ThemeContext.js +14 -42
- package/dist/contexts/index.d.ts +2 -0
- package/dist/contexts/index.d.ts.map +1 -1
- package/dist/contexts/index.js +2 -0
- package/dist/docs/AuthDocs.tsx/AuthDocs.d.ts +2 -0
- package/dist/docs/AuthDocs.tsx/AuthDocs.d.ts.map +1 -0
- package/dist/docs/AuthDocs.tsx/AuthDocs.js +37 -0
- package/dist/docs/AuthDocs.tsx/AuthDocsContent.d.ts +2 -0
- package/dist/docs/AuthDocs.tsx/AuthDocsContent.d.ts.map +1 -0
- package/dist/docs/AuthDocs.tsx/AuthDocsContent.js +14 -0
- package/dist/index.css +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -123,28 +123,6 @@ npx tailwindcss init -p
|
|
|
123
123
|
|
|
124
124
|
La librería incluye FontAwesome 5. Si quieres usar tu propia instalación, puedes sobrescribir los estilos.
|
|
125
125
|
|
|
126
|
-
**⚠️ Importante:** Si usas FontAwesome en tu proyecto, asegúrate de:
|
|
127
|
-
|
|
128
|
-
1. Importar los estilos de `flysoft-react-ui` **después** de FontAwesome (si es posible)
|
|
129
|
-
2. Usar `ThemeProvider` para envolver tu aplicación (esto evita conflictos de variables CSS)
|
|
130
|
-
|
|
131
|
-
```tsx
|
|
132
|
-
// Orden recomendado de importación
|
|
133
|
-
import "fontawesome/css/all.min.css"; // Primero FontAwesome
|
|
134
|
-
import "flysoft-react-ui/styles"; // Luego flysoft-react-ui
|
|
135
|
-
|
|
136
|
-
// En tu App.tsx
|
|
137
|
-
import { ThemeProvider } from "flysoft-react-ui";
|
|
138
|
-
|
|
139
|
-
function App() {
|
|
140
|
-
return (
|
|
141
|
-
<ThemeProvider initialTheme="light">{/* Tu aplicación */}</ThemeProvider>
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
El `ThemeProvider` aplica automáticamente las variables CSS con mayor especificidad, evitando que FontAwesome sobrescriba los colores del tema (como `gray-200`).
|
|
147
|
-
|
|
148
126
|
## 🎨 Sistema de Temas
|
|
149
127
|
|
|
150
128
|
Flysoft React UI incluye un sistema completo de temas personalizables que permite cambiar dinámicamente la apariencia de todos los componentes.
|
package/dist/App.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../src/App.tsx"],"names":[],"mappings":"AAUA,OAAO,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../src/App.tsx"],"names":[],"mappings":"AAUA,OAAO,aAAa,CAAC;AAoCrB,iBAAS,GAAG,4CAkBX;AAED,eAAe,GAAG,CAAC"}
|
package/dist/App.js
CHANGED
|
@@ -5,8 +5,9 @@ import { ThemeProvider } from "./index";
|
|
|
5
5
|
import "./index.css";
|
|
6
6
|
import { DocsMenu } from "./docs/DocsMenu";
|
|
7
7
|
import DocsRouter from "./docs/DocsRouter";
|
|
8
|
+
import { AuthDocs } from "./docs/AuthDocs.tsx/AuthDocs";
|
|
8
9
|
function HomeContent() {
|
|
9
|
-
return (
|
|
10
|
+
return (_jsxs(_Fragment, { children: [_jsx(Card, { title: "Empleados", className: "bg-gray-50", children: _jsx(Card, { className: "w-1/2", title: "FALCONE WALTER ALDO", subtitle: "3558-03 - Titular", footer: _jsx(Button, { children: "Ver" }), headerActions: _jsxs(_Fragment, { children: [_jsx(Badge, { variant: "secondary", children: "OSOCNA" }), _jsx(Badge, { variant: "secondary", children: "B\u00C1SICO" })] }), children: _jsxs(Collection, { direction: "row", gap: "1rem", wrap: true, children: [_jsx(DataField, { label: "Cuil", value: "20179902711" }), _jsx(DataField, { label: "Doc", value: "17990271" }), _jsx(DataField, { label: "F Nac", value: "23/06/1966" }), _jsx(DataField, { label: "F Alta", value: "01/03/2012" })] }) }) }), _jsx("div", { children: _jsx(AuthDocs, {}) })] }));
|
|
10
11
|
}
|
|
11
12
|
function App() {
|
|
12
13
|
return (_jsx(ThemeProvider, { initialTheme: "light", forceInitialTheme: false, children: _jsx(AppLayout, { navBarDrawer: _jsx("h2", { children: _jsx(Link, { to: "/", children: "Flysoft React UI" }) }), leftDrawer: _jsx(DocsMenu, {}), children: _jsxs(Routes, { children: [_jsx(Route, { path: "/", element: _jsx(HomeContent, {}) }), _jsx(Route, { path: "/docs/*", element: _jsx(DocsRouter, {}) })] }) }) }));
|
|
@@ -2,11 +2,11 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
export const Input = ({ label, error, icon, iconPosition = "left", size = "md", className = "", id, ...props }) => {
|
|
4
4
|
const inputId = id || `input-${Math.random().toString(36).substr(2, 9)}`;
|
|
5
|
-
const baseClasses = `
|
|
6
|
-
w-full border rounded-lg transition-colors focus:outline-none focus:ring-1
|
|
7
|
-
disabled:opacity-50 disabled:cursor-not-allowed
|
|
8
|
-
font-[var(--font-default)] text-[var(--color-text-primary)]
|
|
9
|
-
bg-[var(--color-bg-default)]
|
|
5
|
+
const baseClasses = `
|
|
6
|
+
w-full border rounded-lg transition-colors focus:outline-none focus:ring-1
|
|
7
|
+
disabled:opacity-50 disabled:cursor-not-allowed
|
|
8
|
+
font-[var(--font-default)] text-[var(--color-text-primary)]
|
|
9
|
+
bg-[var(--color-bg-default)]
|
|
10
10
|
`;
|
|
11
11
|
const sizeClasses = {
|
|
12
12
|
sm: "px-3 py-1.5 text-sm",
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface AuthContextUserInterface {
|
|
2
|
+
id?: number;
|
|
3
|
+
name?: string;
|
|
4
|
+
aditionalData?: any;
|
|
5
|
+
token?: AuthTokenInterface;
|
|
6
|
+
}
|
|
7
|
+
export interface AuthTokenInterface {
|
|
8
|
+
accessToken?: string;
|
|
9
|
+
expires?: string;
|
|
10
|
+
tokenType?: string;
|
|
11
|
+
refreshToken?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface AuthContextType {
|
|
14
|
+
user: AuthContextUserInterface | null;
|
|
15
|
+
login: (username: string, password: string) => Promise<void>;
|
|
16
|
+
logout: () => void;
|
|
17
|
+
isAuthenticated: boolean;
|
|
18
|
+
isLoading: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare const AuthContext: import("react").Context<AuthContextType>;
|
|
21
|
+
interface AuthProviderProps {
|
|
22
|
+
children: React.ReactNode;
|
|
23
|
+
getToken: (username: string, password: string) => Promise<AuthTokenInterface>;
|
|
24
|
+
getUserData: (token: string) => Promise<AuthContextUserInterface>;
|
|
25
|
+
removeToken?: (token: string) => Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
export declare const AuthProvider: React.FC<AuthProviderProps>;
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=AuthContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthContext.d.ts","sourceRoot":"","sources":["../../src/contexts/AuthContext.tsx"],"names":[],"mappings":"AAEA,MAAM,WAAW,wBAAwB;IACvC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE,GAAG,CAAC;IACpB,KAAK,CAAC,EAAE,kBAAkB,CAAC;CAC5B;AAED,MAAM,WAAW,kBAAkB;IACjC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,wBAAwB,GAAG,IAAI,CAAC;IACtC,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7D,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,eAAe,EAAE,OAAO,CAAC;IACzB,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,eAAO,MAAM,WAAW,0CAMtB,CAAC;AAiBH,UAAU,iBAAiB;IACzB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC9E,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,wBAAwB,CAAC,CAAC;IAClE,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAChD;AAED,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CA4DpD,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useEffect, useState } from "react";
|
|
3
|
+
export const AuthContext = createContext({
|
|
4
|
+
user: null,
|
|
5
|
+
login: async () => { },
|
|
6
|
+
logout: async () => { },
|
|
7
|
+
isAuthenticated: false,
|
|
8
|
+
isLoading: false,
|
|
9
|
+
});
|
|
10
|
+
const initAuth = () => {
|
|
11
|
+
const authString = localStorage.getItem("auth");
|
|
12
|
+
if (!authString)
|
|
13
|
+
return {};
|
|
14
|
+
return JSON.parse(authString);
|
|
15
|
+
};
|
|
16
|
+
const storeAuth = (auth) => {
|
|
17
|
+
localStorage.setItem("auth", JSON.stringify(auth));
|
|
18
|
+
};
|
|
19
|
+
const removeStoredAuth = () => {
|
|
20
|
+
localStorage.removeItem("auth");
|
|
21
|
+
};
|
|
22
|
+
export const AuthProvider = ({ children, getToken, getUserData, removeToken, }) => {
|
|
23
|
+
const [user, setUser] = useState(null);
|
|
24
|
+
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
|
25
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
const auth = initAuth();
|
|
28
|
+
if (auth.id) {
|
|
29
|
+
setUser(auth);
|
|
30
|
+
setIsAuthenticated(true);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
setIsAuthenticated(false);
|
|
34
|
+
}
|
|
35
|
+
}, []);
|
|
36
|
+
const login = async (username, password) => {
|
|
37
|
+
setIsLoading(true);
|
|
38
|
+
const token = await getToken(username, password);
|
|
39
|
+
if (token.accessToken) {
|
|
40
|
+
const { id, name, aditionalData } = await getUserData(token.accessToken);
|
|
41
|
+
const userData = {
|
|
42
|
+
id,
|
|
43
|
+
name,
|
|
44
|
+
aditionalData,
|
|
45
|
+
token,
|
|
46
|
+
};
|
|
47
|
+
setUser(userData);
|
|
48
|
+
storeAuth(userData);
|
|
49
|
+
setIsAuthenticated(true);
|
|
50
|
+
}
|
|
51
|
+
setIsLoading(false);
|
|
52
|
+
};
|
|
53
|
+
const logout = async () => {
|
|
54
|
+
removeStoredAuth();
|
|
55
|
+
setUser(null);
|
|
56
|
+
if (removeToken && user?.token?.accessToken) {
|
|
57
|
+
await removeToken(user.token.accessToken);
|
|
58
|
+
}
|
|
59
|
+
setIsAuthenticated(false);
|
|
60
|
+
};
|
|
61
|
+
return (_jsx(AuthContext.Provider, { value: { user, isAuthenticated, isLoading, login, logout }, children: children }));
|
|
62
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeContext.d.ts","sourceRoot":"","sources":["../../src/contexts/ThemeContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"ThemeContext.d.ts","sourceRoot":"","sources":["../../src/contexts/ThemeContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAOZ,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AA2CvD,UAAU,kBAAkB;IAC1B,QAAQ,EAAE,SAAS,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAgKtD,CAAC;AAIF,eAAO,MAAM,QAAQ,QAAO,gBAM3B,CAAC;AAIF,eAAO,MAAM,eAAe,eAG3B,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import React, { createContext, useContext, useEffect,
|
|
2
|
+
import React, { createContext, useContext, useEffect, useMemo, useState, } from "react";
|
|
3
3
|
import { themes, defaultTheme } from "./presets";
|
|
4
4
|
const ThemeContext = createContext(undefined);
|
|
5
5
|
const toKebabCase = (value) => value.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
@@ -67,55 +67,40 @@ export const ThemeProvider = ({ children, initialTheme = "light", storageKey = "
|
|
|
67
67
|
return getInitialTheme();
|
|
68
68
|
});
|
|
69
69
|
const [currentThemeName, setCurrentThemeName] = useState(currentTheme.name);
|
|
70
|
-
const containerRef = useRef(null);
|
|
71
70
|
// Function to apply theme to CSS variables
|
|
72
|
-
const applyThemeToCSS = (theme
|
|
71
|
+
const applyThemeToCSS = (theme) => {
|
|
73
72
|
if (typeof document === "undefined")
|
|
74
73
|
return;
|
|
75
|
-
|
|
76
|
-
const target = container || document.documentElement;
|
|
74
|
+
const root = document.documentElement;
|
|
77
75
|
// Apply color variables
|
|
78
76
|
Object.entries(theme.colors).forEach(([key, value]) => {
|
|
79
77
|
const cssVarName = `--flysoft-${key
|
|
80
78
|
.replace(/([A-Z])/g, "-$1")
|
|
81
79
|
.toLowerCase()}`;
|
|
82
|
-
|
|
83
|
-
// También sobrescribir variables genéricas que FontAwesome pueda usar
|
|
84
|
-
// Esto asegura que nuestras variables tengan prioridad
|
|
85
|
-
if (key.startsWith("gray")) {
|
|
86
|
-
const genericVarName = `--color-${key
|
|
87
|
-
.replace(/([A-Z])/g, "-$1")
|
|
88
|
-
.toLowerCase()}`;
|
|
89
|
-
target.style.setProperty(genericVarName, value);
|
|
90
|
-
}
|
|
80
|
+
root.style.setProperty(cssVarName, value);
|
|
91
81
|
});
|
|
92
82
|
// Apply shadow variables
|
|
93
83
|
Object.entries(theme.shadows).forEach(([key, value]) => {
|
|
94
84
|
const cssVarName = `--flysoft-shadow-${key}`;
|
|
95
|
-
|
|
85
|
+
root.style.setProperty(cssVarName, value);
|
|
96
86
|
});
|
|
97
87
|
// Apply radius variables
|
|
98
88
|
Object.entries(theme.radius).forEach(([key, value]) => {
|
|
99
89
|
const cssVarName = `--flysoft-radius-${key}`;
|
|
100
|
-
|
|
90
|
+
root.style.setProperty(cssVarName, value);
|
|
101
91
|
});
|
|
102
92
|
// Apply spacing variables
|
|
103
93
|
Object.entries(theme.spacing).forEach(([key, value]) => {
|
|
104
94
|
const cssVarName = `--flysoft-spacing-${key}`;
|
|
105
|
-
|
|
95
|
+
root.style.setProperty(cssVarName, value);
|
|
106
96
|
});
|
|
107
97
|
// Apply font variables
|
|
108
98
|
Object.entries(theme.fonts).forEach(([key, value]) => {
|
|
109
99
|
const cssVarName = `--flysoft-font-${key}`;
|
|
110
|
-
|
|
100
|
+
root.style.setProperty(cssVarName, value);
|
|
111
101
|
});
|
|
112
102
|
// Set theme name as data attribute for CSS targeting
|
|
113
|
-
|
|
114
|
-
container.setAttribute("data-theme", theme.name);
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
document.documentElement.setAttribute("data-theme", theme.name);
|
|
118
|
-
}
|
|
103
|
+
root.setAttribute("data-theme", theme.name);
|
|
119
104
|
// Apply background and text colors to body for better integration
|
|
120
105
|
const body = document.body;
|
|
121
106
|
if (body) {
|
|
@@ -145,29 +130,16 @@ export const ThemeProvider = ({ children, initialTheme = "light", storageKey = "
|
|
|
145
130
|
if (typeof window !== "undefined") {
|
|
146
131
|
localStorage.setItem(storageKey, JSON.stringify(newTheme));
|
|
147
132
|
}
|
|
148
|
-
// Apply to CSS
|
|
149
|
-
applyThemeToCSS(newTheme
|
|
133
|
+
// Apply to CSS
|
|
134
|
+
applyThemeToCSS(newTheme);
|
|
150
135
|
};
|
|
151
136
|
// Function to reset to initial theme (the one passed as initialTheme prop)
|
|
152
137
|
const resetToDefault = () => {
|
|
153
138
|
setTheme(getInitialTheme());
|
|
154
139
|
};
|
|
155
|
-
// Apply theme on mount and when theme changes
|
|
156
|
-
// para asegurar que se aplique antes del paint y con mayor prioridad
|
|
157
|
-
useLayoutEffect(() => {
|
|
158
|
-
if (containerRef.current) {
|
|
159
|
-
applyThemeToCSS(currentTheme, containerRef.current);
|
|
160
|
-
}
|
|
161
|
-
else {
|
|
162
|
-
// Fallback a :root si el contenedor aún no está montado
|
|
163
|
-
applyThemeToCSS(currentTheme);
|
|
164
|
-
}
|
|
165
|
-
}, [currentTheme]);
|
|
166
|
-
// También aplicar después del mount para asegurar que se actualice
|
|
140
|
+
// Apply theme on mount and when theme changes
|
|
167
141
|
useEffect(() => {
|
|
168
|
-
|
|
169
|
-
applyThemeToCSS(currentTheme, containerRef.current);
|
|
170
|
-
}
|
|
142
|
+
applyThemeToCSS(currentTheme);
|
|
171
143
|
}, [currentTheme]);
|
|
172
144
|
// Check if current theme is dark
|
|
173
145
|
const isDark = currentTheme.name === "dark";
|
|
@@ -180,7 +152,7 @@ export const ThemeProvider = ({ children, initialTheme = "light", storageKey = "
|
|
|
180
152
|
resetToDefault,
|
|
181
153
|
isDark,
|
|
182
154
|
};
|
|
183
|
-
return (_jsx(ThemeContext.Provider, { value: value, children: _jsx("div", {
|
|
155
|
+
return (_jsx(ThemeContext.Provider, { value: value, children: _jsx("div", { className: "flysoft-theme-reset", style: themeResetStyles, "data-theme": currentTheme.name, children: children }) }));
|
|
184
156
|
};
|
|
185
157
|
// Hook to use theme context
|
|
186
158
|
// eslint-disable-next-line react-refresh/only-export-components
|
package/dist/contexts/index.d.ts
CHANGED
|
@@ -2,4 +2,6 @@ export { ThemeProvider, useTheme, useThemeContext } from "./ThemeContext";
|
|
|
2
2
|
export { useThemeOverride, useTemporaryOverride, } from "../hooks/useThemeOverride";
|
|
3
3
|
export type { Theme, ThemeContextType, ThemeOverride } from "./types";
|
|
4
4
|
export { lightTheme, darkTheme, blueTheme, greenTheme, defaultTheme, themes, } from "./presets";
|
|
5
|
+
export { AuthProvider, AuthContext } from "./AuthContext";
|
|
6
|
+
export type { AuthContextType, AuthContextUserInterface, AuthTokenInterface, } from "./AuthContext";
|
|
5
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contexts/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EACL,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,2BAA2B,CAAC;AAGnC,YAAY,EAAE,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGtE,OAAO,EACL,UAAU,EACV,SAAS,EACT,SAAS,EACT,UAAU,EACV,YAAY,EACZ,MAAM,GACP,MAAM,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contexts/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EACL,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,2BAA2B,CAAC;AAGnC,YAAY,EAAE,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGtE,OAAO,EACL,UAAU,EACV,SAAS,EACT,SAAS,EACT,UAAU,EACV,YAAY,EACZ,MAAM,GACP,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC1D,YAAY,EACV,eAAe,EACf,wBAAwB,EACxB,kBAAkB,GACnB,MAAM,eAAe,CAAC"}
|
package/dist/contexts/index.js
CHANGED
|
@@ -3,3 +3,5 @@ export { ThemeProvider, useTheme, useThemeContext } from "./ThemeContext";
|
|
|
3
3
|
export { useThemeOverride, useTemporaryOverride, } from "../hooks/useThemeOverride";
|
|
4
4
|
// Preset themes
|
|
5
5
|
export { lightTheme, darkTheme, blueTheme, greenTheme, defaultTheme, themes, } from "./presets";
|
|
6
|
+
// Auth system exports
|
|
7
|
+
export { AuthProvider, AuthContext } from "./AuthContext";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthDocs.d.ts","sourceRoot":"","sources":["../../../src/docs/AuthDocs.tsx/AuthDocs.tsx"],"names":[],"mappings":"AAkDA,eAAO,MAAM,QAAQ,+CAMpB,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { AuthProvider, } from "../../contexts/AuthContext";
|
|
3
|
+
import { apiClient } from "../../services/apiClient";
|
|
4
|
+
import { AuthDocsContent } from "./AuthDocsContent";
|
|
5
|
+
const getToken = async (username, password) => {
|
|
6
|
+
const { access_token, expires, token_type, refresh_token, } = await apiClient.post({
|
|
7
|
+
url: "https://devmanager.osocna.com.ar/backend/api/users/login",
|
|
8
|
+
body: {
|
|
9
|
+
username,
|
|
10
|
+
password,
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
return {
|
|
14
|
+
accessToken: access_token,
|
|
15
|
+
tokenType: token_type,
|
|
16
|
+
expires,
|
|
17
|
+
refreshToken: refresh_token,
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
const getUserData = async (token) => {
|
|
21
|
+
const { id, name } = await apiClient.get({
|
|
22
|
+
url: "https://devmanager.osocna.com.ar/backend/api/users/userdata",
|
|
23
|
+
headers: {
|
|
24
|
+
Authorization: `Bearer ${token}`,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
id,
|
|
29
|
+
name,
|
|
30
|
+
aditionalData: {
|
|
31
|
+
role: "admin",
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
export const AuthDocs = () => {
|
|
36
|
+
return (_jsx(AuthProvider, { getToken: getToken, getUserData: getUserData, children: _jsx(AuthDocsContent, {}) }));
|
|
37
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthDocsContent.d.ts","sourceRoot":"","sources":["../../../src/docs/AuthDocs.tsx/AuthDocsContent.tsx"],"names":[],"mappings":"AAIA,eAAO,MAAM,eAAe,+CA2B3B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useContext } from "react";
|
|
3
|
+
import { AuthContext } from "../../contexts/AuthContext";
|
|
4
|
+
import { Button } from "../../components";
|
|
5
|
+
export const AuthDocsContent = () => {
|
|
6
|
+
const { login, isAuthenticated, isLoading, user, logout } = useContext(AuthContext);
|
|
7
|
+
const handleLogin = async () => {
|
|
8
|
+
await login("wursten.alexis@gmail.com", "Oscn1138");
|
|
9
|
+
};
|
|
10
|
+
const handleLogout = () => {
|
|
11
|
+
logout();
|
|
12
|
+
};
|
|
13
|
+
return isAuthenticated ? (_jsxs("div", { children: [_jsx("h1", { children: "Bienvenido" }), JSON.stringify(user), _jsx("div", { children: _jsx(Button, { onClick: handleLogout, children: "Logout" }) })] })) : isLoading ? (_jsx("div", { children: "Cargando..." })) : (_jsx("div", { children: _jsx(Button, { onClick: handleLogin, children: "Login" }) }));
|
|
14
|
+
};
|