A comprehensive React UI library with authentication, form handling, and API integration.
- π Authentication with JWT
- π Form handling with validation
- π API integration with caching
- π TypeScript support
- π± Responsive design
- π¨ Material UI components
- π Data visualization
- π Date and time pickers
- π Data grids
- π³ Tree views
npm install @khuniverse/sso-coreui
# or
yarn add @khuniverse/sso-coreui
import { useAuth, AlertProvider } from '@khuniverse/sso-coreui';
function App() {
return (
<AlertProvider>
<YourApp />
</AlertProvider>
);
}
function LoginForm() {
const { login, isAuthenticated } = useAuth();
const { showError } = useAlert();
const handleLogin = async (credentials) => {
try {
await login(credentials);
} catch (error) {
showError('Login failed');
}
};
return (
// Your login form
);
}
import { useForm } from '@khuniverse/sso-coreui';
function UserForm() {
const { values, errors, handleChange, validateForm } = useForm({
name: '',
email: '',
}, {
name: {
required: true,
minLength: 3,
},
email: {
required: true,
pattern: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
},
});
const handleSubmit = async (e) => {
e.preventDefault();
if (await validateForm()) {
// Submit form
}
};
return (
<form onSubmit={handleSubmit}>
<input
name="name"
value={values.name}
onChange={handleChange}
/>
{errors.name && <div>{errors.name}</div>}
<input
name="email"
value={values.email}
onChange={handleChange}
/>
{errors.email && <div>{errors.email}</div>}
<button type="submit">Submit</button>
</form>
);
}
import { useFetch } from '@khuniverse/sso-coreui';
function UserList() {
const { data, loading, error, fetchData } = useFetch<User[]>();
useEffect(() => {
fetchData('/users', { cacheTime: 300000 }); // Cache for 5 minutes
}, [fetchData]);
if (loading) return <div>Loading...</div>;
if (error) return <div>Error: {error.message}</div>;
return (
<ul>
{data?.map(user => (
<li key={user.id}>{user.name}</li>
))}
</ul>
);
}
const {
user,
isAuthenticated,
login,
logout,
refreshToken,
hasRole,
hasAnyRole,
hasPermission,
hasAnyPermission,
} = useAuth();
const {
values,
errors,
touched,
handleChange,
handleBlur,
setFieldValue,
setFieldError,
resetForm,
validateForm,
setValues,
setErrors,
setTouched,
} = useForm(initialValues, validationRules);
const { data, loading, error, fetchData, reset, refetch } = useFetch<T>();
const { showSuccess, showError, showWarning, showInfo } = useAlert();
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
MIT Β© KH Universe