@goobits/forms v1.0.1
@goobits/forms
ā ļø EXPERIMENTAL PACKAGE - v0.0.1-alpha
A configurable, accessible form library for SvelteKit with contact forms, validation, optional reCAPTCHA support, and file uploads.
š Security Notice
This package handles user input. Always validate and sanitize data server-side. Never trust client-side validation alone. The included sanitization is basic and should be supplemented with server-side security measures.
⨠Features
- šØ Multiple form types (general, support, feedback, booking, business)
- ā Built-in validation with Zod
- š Optional reCAPTCHA v3 integration
- š File upload support with preview
- š¾ Form state persistence
- āæ Accessibility features
- šÆ JSDoc type annotations
- š§ Highly configurable
- š Easy to integrate
- š Internationalization (i18n) support
š¦ Installation
npm install @goobits/forms
# Required peer dependencies
npm install @sveltejs/kit svelte formsnap lucide-svelte sveltekit-superforms zod
š Quick Start
// src/lib/contact-config.js
export const contactConfig = {
appName: 'My App',
categories: {
'general': {
label: 'General Inquiry',
fields: ['name', 'email', 'message', 'coppa']
}
}
}
// src/app.js
import { initContactFormConfig } from '@goobits/forms/config'
import { contactConfig } from '$lib/contact-config.js'
initContactFormConfig(contactConfig)
<!-- src/routes/contact/+page.svelte -->
<script>
import { ContactForm } from '@goobits/forms'
export let data
</script>
<h1>Contact Us</h1>
<ContactForm
apiEndpoint="/api/contact"
/>
š§ Configuration
const contactConfig = {
appName: 'My App',
// Form UI settings
ui: {
submitButtonText: 'Send Message',
submittingButtonText: 'Sending...',
resetAfterSubmit: true
},
// reCAPTCHA settings
recaptcha: {
enabled: false,
provider: 'google-v3',
siteKey: 'YOUR_SITE_KEY'
}
}
š Internationalization (i18n)
The contactform package supports full internationalization through multiple integration methods:
1. Component-level Translation
All components accept a messages
prop for direct translation override:
<script>
import { ContactForm } from '@goobits/forms'
// Custom translations
const messages = {
howCanWeHelp: 'How can we help you?',
sendMessage: 'Send Message',
sending: 'Sending...'
}
</script>
<ContactForm {messages} />
2. Server Integration
For full i18n with automatic language detection and routing:
// hooks.server.js
import { handleFormI18n } from '@goobits/forms/i18n'
export async function handle({ event, resolve }) {
// Add language info to event.locals
await handleFormI18n(event)
// Continue with request handling
return await resolve(event)
}
3. Page Integration
Enhance contact form pages with i18n data:
// contact/+page.server.js
import { loadWithFormI18n } from '@goobits/forms/i18n'
export const load = async (event) => {
return await loadWithFormI18n(event, async () => {
// Your original contact form data loading
return { formData, categories }
})
}
4. Paraglide Integration
For seamless integration with Paraglide (recommended):
import { createMessageGetter } from '@goobits/forms/i18n'
import * as m from '$paraglide/messages'
// Map form messages to Paraglide translations
const getMessage = createMessageGetter({
howCanWeHelp: m.howCanWeHelp,
sendMessage: m.sendMessage,
sending: m.sending
})
š§© Components
ContactForm
- Main form component with validationContactFormPage
- Complete page with form and layoutFormField
- Reusable form field with validationFormErrors
- Form error display componentFeedbackForm
- Quick feedback form widgetThankYou
- Success message componentUploadImage
- File upload component
šØ Styling
// Import SCSS directly
import '@goobits/forms/ui/ContactForm.scss'
// Or customize with CSS variables
:root {
--contact-form-primary: #007bff;
--contact-form-error: #dc3545;
--contact-form-success: #28a745;
}
āæ Accessibility
The component follows WCAG 2.1 guidelines:
- Semantic HTML structure
- ARIA labels and descriptions
- Keyboard navigation support
- Focus management
- Error announcements
- Color contrast compliance
š License
MIT