react-unified-auth 1.0.2 → 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/dist/index.esm.js CHANGED
@@ -4062,19 +4062,14 @@ function useDynamicForm(formId) {
4062
4062
  }
4063
4063
 
4064
4064
  function Button({ variant = 'primary', size = 'md', loading = false, fullWidth = false, children, disabled, className = '', ...props }) {
4065
- const baseStyles = 'inline-flex items-center justify-center font-medium rounded-lg transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed';
4066
- const variantStyles = {
4067
- primary: 'bg-blue-600 text-white hover:bg-blue-700 focus:ring-blue-500',
4068
- secondary: 'bg-gray-600 text-white hover:bg-gray-700 focus:ring-gray-500',
4069
- outline: 'border-2 border-blue-600 text-blue-600 hover:bg-blue-50 focus:ring-blue-500',
4070
- };
4071
- const sizeStyles = {
4072
- sm: 'px-3 py-1.5 text-sm',
4073
- md: 'px-4 py-2 text-base',
4074
- lg: 'px-6 py-3 text-lg',
4075
- };
4076
- const widthStyles = fullWidth ? 'w-full' : '';
4077
- return (jsxs("button", { className: `${baseStyles} ${variantStyles[variant]} ${sizeStyles[size]} ${widthStyles} ${className}`, disabled: disabled || loading, ...props, children: [loading && (jsxs("svg", { className: "animate-spin -ml-1 mr-2 h-4 w-4", xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [jsx("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }), jsx("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" })] })), children] }));
4065
+ const buttonClasses = [
4066
+ 'usa-button',
4067
+ `usa-button--${variant}`,
4068
+ `usa-button--${size}`,
4069
+ fullWidth ? 'usa-button--full-width' : '',
4070
+ className
4071
+ ].filter(Boolean).join(' ');
4072
+ return (jsxs("button", { className: buttonClasses, disabled: disabled || loading, ...props, children: [loading && (jsxs("svg", { className: "usa-loading-spinner", xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [jsx("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }), jsx("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" })] })), children] }));
4078
4073
  }
4079
4074
 
4080
4075
  function validateField(field, value) {
@@ -4163,8 +4158,8 @@ function DynamicForm({ fields, onSubmit, submitText = 'Submit', submitVariant =
4163
4158
  const renderField = (field) => {
4164
4159
  const error = touched[field.name] ? errors[field.name] : '';
4165
4160
  const hasError = !!error;
4166
- const baseInputStyles = 'w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 transition-colors';
4167
- const errorStyles = hasError ? 'border-red-500 focus:ring-red-500' : 'border-gray-300 focus:ring-blue-500';
4161
+ const baseInputStyles = 'usa-form__input';
4162
+ const errorStyles = hasError ? 'usa-form__input--error' : '';
4168
4163
  switch (field.type) {
4169
4164
  case 'text':
4170
4165
  case 'email':
@@ -4172,18 +4167,18 @@ function DynamicForm({ fields, onSubmit, submitText = 'Submit', submitVariant =
4172
4167
  case 'number':
4173
4168
  return (jsx("input", { type: field.type, name: field.name, value: values[field.name] || '', onChange: (e) => handleChange(field.name, e.target.value), onBlur: () => handleBlur(field.name), placeholder: field.placeholder, className: `${baseInputStyles} ${errorStyles}`, disabled: loading }));
4174
4169
  case 'textarea':
4175
- return (jsx("textarea", { name: field.name, value: values[field.name] || '', onChange: (e) => handleChange(field.name, e.target.value), onBlur: () => handleBlur(field.name), placeholder: field.placeholder, rows: 4, className: `${baseInputStyles} ${errorStyles}`, disabled: loading }));
4170
+ return (jsx("textarea", { name: field.name, value: values[field.name] || '', onChange: (e) => handleChange(field.name, e.target.value), onBlur: () => handleBlur(field.name), placeholder: field.placeholder, rows: 4, className: "usa-form__textarea", disabled: loading }));
4176
4171
  case 'select':
4177
- return (jsxs("select", { name: field.name, value: values[field.name] || '', onChange: (e) => handleChange(field.name, e.target.value), onBlur: () => handleBlur(field.name), className: `${baseInputStyles} ${errorStyles}`, disabled: loading, children: [jsx("option", { value: "", children: "Select an option" }), field.options?.map((option) => (jsx("option", { value: option.value, children: option.label }, option.value)))] }));
4172
+ return (jsxs("select", { name: field.name, value: values[field.name] || '', onChange: (e) => handleChange(field.name, e.target.value), onBlur: () => handleBlur(field.name), className: "usa-form__select", disabled: loading, children: [jsx("option", { value: "", children: "Select an option" }), field.options?.map((option) => (jsx("option", { value: option.value, children: option.label }, option.value)))] }));
4178
4173
  case 'checkbox':
4179
- return (jsx("input", { type: "checkbox", name: field.name, checked: values[field.name] || false, onChange: (e) => handleChange(field.name, e.target.checked), onBlur: () => handleBlur(field.name), className: "w-4 h-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500", disabled: loading }));
4174
+ return (jsx("input", { type: "checkbox", name: field.name, checked: values[field.name] || false, onChange: (e) => handleChange(field.name, e.target.checked), onBlur: () => handleBlur(field.name), className: "usa-form__checkbox", disabled: loading }));
4180
4175
  case 'radio':
4181
- return (jsx("div", { className: "space-y-2", children: field.options?.map((option) => (jsxs("label", { className: "flex items-center space-x-2", children: [jsx("input", { type: "radio", name: field.name, value: option.value, checked: values[field.name] === option.value, onChange: (e) => handleChange(field.name, e.target.value), onBlur: () => handleBlur(field.name), className: "w-4 h-4 text-blue-600 border-gray-300 focus:ring-blue-500", disabled: loading }), jsx("span", { children: option.label })] }, option.value))) }));
4176
+ return (jsx("div", { className: "usa-form__radio-group", children: field.options?.map((option) => (jsxs("label", { className: "usa-form__radio-label", children: [jsx("input", { type: "radio", name: field.name, value: option.value, checked: values[field.name] === option.value, onChange: (e) => handleChange(field.name, e.target.value), onBlur: () => handleBlur(field.name), className: "usa-form__radio", disabled: loading }), jsx("span", { children: option.label })] }, option.value))) }));
4182
4177
  default:
4183
4178
  return null;
4184
4179
  }
4185
4180
  };
4186
- return (jsxs("form", { onSubmit: handleSubmit, className: "space-y-4", children: [fields.map((field) => (jsxs("div", { children: [jsxs("label", { className: "block text-sm font-medium text-gray-700 mb-1", children: [field.label, field.required && jsx("span", { className: "text-red-500 ml-1", children: "*" })] }), renderField(field), touched[field.name] && errors[field.name] && (jsx("p", { className: "mt-1 text-sm text-red-600", children: errors[field.name] }))] }, field.name))), jsx(Button, { type: "submit", variant: submitVariant, loading: loading, fullWidth: true, children: submitText })] }));
4181
+ return (jsxs("form", { onSubmit: handleSubmit, className: "usa-form", children: [fields.map((field) => (jsxs("div", { className: "usa-form__field-group", children: [jsx("label", { className: `usa-form__label ${field.required ? 'usa-form__label--required' : ''}`, children: field.label }), renderField(field), touched[field.name] && errors[field.name] && (jsx("p", { className: "usa-form__error", children: errors[field.name] }))] }, field.name))), jsx(Button, { type: "submit", variant: submitVariant, loading: loading, fullWidth: true, children: submitText })] }));
4187
4182
  }
4188
4183
 
4189
4184
  function LoginForm({ formId, onSuccess, onError }) {
@@ -4216,32 +4211,32 @@ function LoginForm({ formId, onSuccess, onError }) {
4216
4211
  }
4217
4212
  };
4218
4213
  if (formLoading) {
4219
- return (jsx("div", { className: "flex items-center justify-center p-8", children: jsx("div", { className: "animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600" }) }));
4214
+ return (jsx("div", { className: "usa-login-form__loading", children: jsx("div", { className: "animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600" }) }));
4220
4215
  }
4221
4216
  if (formError) {
4222
- return (jsx("div", { className: "p-4 bg-red-50 border border-red-200 rounded-lg", children: jsx("p", { className: "text-red-600", children: formError }) }));
4217
+ return (jsx("div", { className: "usa-login-form__error", children: jsx("p", { className: "text-red-600", children: formError }) }));
4223
4218
  }
4224
4219
  if (!formConfig) {
4225
4220
  return null;
4226
4221
  }
4227
- return (jsx("div", { className: "w-full", children: jsx(DynamicForm, { fields: formConfig.fields, onSubmit: handleSubmit, submitText: formConfig.submitButton?.text || 'Login', submitVariant: formConfig.submitButton?.variant || 'primary', loading: submitting }) }));
4222
+ return (jsx("div", { className: "usa-login-form", children: jsx(DynamicForm, { fields: formConfig.fields, onSubmit: handleSubmit, submitText: formConfig.submitButton?.text || 'Login', submitVariant: formConfig.submitButton?.variant || 'primary', loading: submitting }) }));
4228
4223
  }
4229
4224
 
4230
4225
  function UserInfoBox({ user, onLogout, loading = false, className = '' }) {
4231
- return (jsxs("div", { className: `bg-white rounded-lg shadow-md p-6 ${className}`, children: [jsxs("div", { className: "flex items-center space-x-4", children: [user.avatar && (jsx("img", { src: user.avatar, alt: user.name, className: "w-16 h-16 rounded-full object-cover" })), jsxs("div", { className: "flex-1", children: [jsx("h3", { className: "text-lg font-semibold text-gray-900", children: user.name }), user.email && (jsx("p", { className: "text-sm text-gray-600", children: user.email }))] })] }), onLogout && (jsx("div", { className: "mt-4", children: jsx(Button, { variant: "outline", size: "sm", onClick: onLogout, loading: loading, fullWidth: true, children: "Logout" }) }))] }));
4226
+ return (jsxs("div", { className: `usa-user-info-box ${className}`, children: [jsxs("div", { className: "usa-user-info-box__header", children: [user.avatar && (jsx("img", { src: user.avatar, alt: user.name, className: "usa-user-info-box__avatar" })), jsxs("div", { className: "usa-user-info-box__details", children: [jsx("h3", { className: "usa-user-info-box__name", children: user.name }), user.email && (jsx("p", { className: "usa-user-info-box__email", children: user.email }))] })] }), onLogout && (jsx("div", { className: "mt-4", children: jsx(Button, { variant: "outline", size: "sm", onClick: onLogout, loading: loading, fullWidth: true, children: "Logout" }) }))] }));
4232
4227
  }
4233
4228
 
4234
4229
  function SocialLoginButton({ provider, onClick, loading = false, className = '' }) {
4235
4230
  const handleClick = () => {
4236
4231
  onClick(provider);
4237
4232
  };
4238
- return (jsxs(Button, { variant: "outline", onClick: handleClick, loading: loading, fullWidth: true, className: `flex items-center justify-center space-x-2 ${className}`, children: [provider.icon && (jsx("img", { src: provider.icon, alt: provider.name, className: "w-5 h-5" })), jsxs("span", { children: ["Continue with ", provider.name] })] }));
4233
+ return (jsxs(Button, { variant: "outline", onClick: handleClick, loading: loading, fullWidth: true, className: `usa-social-login-button ${className}`, children: [provider.icon && (jsx("img", { src: provider.icon, alt: provider.name, className: "usa-social-login-button__icon" })), jsxs("span", { children: ["Continue with ", provider.name] })] }));
4239
4234
  }
4240
4235
  function SocialLogin({ providers, onLogin, loading = false, className = '' }) {
4241
4236
  if (providers.length === 0) {
4242
4237
  return null;
4243
4238
  }
4244
- return (jsx("div", { className: `space-y-3 ${className}`, children: providers.map((provider) => (jsx(SocialLoginButton, { provider: provider, onClick: onLogin, loading: loading }, provider.id))) }));
4239
+ return (jsx("div", { className: `usa-social-login ${className}`, children: providers.map((provider) => (jsx(SocialLoginButton, { provider: provider, onClick: onLogin, loading: loading }, provider.id))) }));
4245
4240
  }
4246
4241
 
4247
4242
  export { ApiClient, AuthProvider, Button, DynamicForm, LoginForm, SocialLogin, SocialLoginButton, UserInfoBox, useAuth, useAuthConfig, useDynamicForm, validateField, validateForm };