### Configure ESLint for Type-Aware Linting in React/TypeScript Source: https://github.com/aranlucas/react-hook-form-mantine/blob/master/example/README.md This configuration snippet shows how to set up ESLint for type-aware linting in a React and TypeScript project. It requires specifying project files and the root directory for TypeScript configuration. Dependencies include `@typescript-eslint/eslint-plugin` and `eslint-plugin-react`. ```javascript parserOptions: { ecmaVersion: 'latest', sourceType: 'module', project: ['./tsconfig.json', './tsconfig.node.json'], tsconfigRootDir: __dirname, } ``` -------------------------------- ### TextInput Component Example using React Hook Form and Mantine Source: https://context7.com/aranlucas/react-hook-form-mantine/llms.txt Demonstrates how to use the TextInput component from react-hook-form-mantine for form input. It includes setup with useForm, schema validation using Zod, and displays errors and values. This example requires react-hook-form, @mantine/core, zod, and @hookform/resolvers/zod. ```tsx import { useForm } from "react-hook-form"; import { TextInput } from "react-hook-form-mantine"; import { Button } from "@mantine/core"; import { z } from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; const schema = z.object({ username: z.string().min(3, "Username must be at least 3 characters"), email: z.string().email("Invalid email address"), }); type FormData = z.infer; function LoginForm() { const { control, handleSubmit } = useForm({ resolver: zodResolver(schema), defaultValues: { username: "", email: "", }, }); const onSubmit = (data: FormData) => { console.log("Form data:", data); // Output: { username: "john_doe", email: "john@example.com" } }; return (
); } ``` -------------------------------- ### Select Component Example using React Hook Form and Mantine Source: https://context7.com/aranlucas/react-hook-form-mantine/llms.txt Illustrates the usage of the Select component from react-hook-form-mantine for dropdown selections. It integrates with useForm and Zod for validation, defining options and handling form submission. Dependencies include react-hook-form, @mantine/core, zod, and @hookform/resolvers/zod. ```tsx import { useForm } from "react-hook-form"; import { Select } from "react-hook-form-mantine"; import { Button } from "@mantine/core"; import { z } from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; const schema = z.object({ framework: z.string().min(1, "Please select a framework"), language: z.string(), }); type FormData = z.infer; function PreferencesForm() { const { control, handleSubmit } = useForm({ resolver: zodResolver(schema), defaultValues: { framework: "", language: "typescript", }, }); const onSubmit = (data: FormData) => { console.log("Selected preferences:", data); // Output: { framework: "react", language: "typescript" } }; return (
); } ``` -------------------------------- ### Switch: Toggle for Preferences - React Hook Form / Mantine Source: https://context7.com/aranlucas/react-hook-form-mantine/llms.txt Enables boolean toggling using the Switch component from react-hook-form-mantine. This example demonstrates managing user preferences like dark mode and notifications. Zod schema validation ensures correct boolean handling. ```tsx import { useForm } from "react-hook-form"; import { Switch } from "react-hook-form-mantine"; import { Button, Stack } from "@mantine/core"; import { z } from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; const schema = z.object({ darkMode: z.boolean(), notifications: z.boolean(), autoSave: z.boolean(), }); type FormData = z.infer; function PreferencesToggleForm() { const { control, handleSubmit } = useForm({ resolver: zodResolver(schema), defaultValues: { darkMode: false, notifications: true, autoSave: true, }, }); const onSubmit = (data: FormData) => { console.log("Preferences:", data); // Output: { darkMode: true, notifications: true, autoSave: false } }; return (
); } ``` -------------------------------- ### Radio Group Component with React Hook Form and Mantine Source: https://context7.com/aranlucas/react-hook-form-mantine/llms.txt Shows how to implement a radio button group using `react-hook-form-mantine`'s `Radio.Group` and `Radio.Item` components. This example includes schema validation with Zod for mutually exclusive selections and integrates with `react-hook-form`. ```tsx import { useForm } from "react-hook-form"; import { Radio } from "react-hook-form-mantine"; import { Button, Group } from "@mantine/core"; import { z } from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; const schema = z.object({ plan: z.enum(["free", "pro", "enterprise"], { required_error: "Please select a plan", }), }); type FormData = z.infer; function SubscriptionForm() { const { control, handleSubmit } = useForm({ resolver: zodResolver(schema), }); const onSubmit = (data: FormData) => { console.log("Selected plan:", data); // Output: { plan: "pro" } }; return (
); } ``` -------------------------------- ### File Upload Input with Type Restrictions (React) Source: https://context7.com/aranlucas/react-hook-form-mantine/llms.txt Demonstrates file uploads using react-hook-form-mantine's FileInput, with support for specifying accepted file types and basic validation for required files. Dependencies include react-hook-form, react-hook-form-mantine, @mantine/core, zod, and @hookform/resolvers. ```tsx import { useForm } from "react-hook-form"; import { FileInput } from "react-hook-form-mantine"; import { Button } from "@mantine/core"; import { z } from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; const schema = z.object({ resume: z.any().refine((file) => file !== null, "Resume is required"), avatar: z.any(), }); type FormData = z.infer; function UploadForm() { const { control, handleSubmit } = useForm({ resolver: zodResolver(schema), defaultValues: { resume: null, avatar: null, }, }); const onSubmit = (data: FormData) => { console.log("Files:", { resume: data.resume?.name, avatar: data.avatar?.name, }); // Output: { resume: "resume.pdf", avatar: "profile.jpg" } }; return (
); } ``` -------------------------------- ### JSON Input with Validation and Formatting (React) Source: https://context7.com/aranlucas/react-hook-form-mantine/llms.txt Implements a JSON input field using react-hook-form-mantine's JsonInput. It includes Zod schema validation for JSON syntax and auto-formatting on blur. Dependencies include react-hook-form, react-hook-form-mantine, @mantine/core, zod, and @hookform/resolvers. ```tsx import { useForm } from "react-hook-form"; import { JsonInput } from "react-hook-form-mantine"; import { Button } from "@mantine/core"; import { z } from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; const schema = z.object({ config: z.string().refine((val) => { try { JSON.parse(val); return true; } catch { return false; } }, "Invalid JSON"), }); type FormData = z.infer; function ConfigForm() { const { control, handleSubmit } = useForm({ resolver: zodResolver(schema), defaultValues: { config: '{"apiUrl": "https://api.example.com", "timeout": 5000}', }, }); const onSubmit = (data: FormData) => { const parsed = JSON.parse(data.config); console.log("Config:", parsed); // Output: { apiUrl: "https://api.example.com", timeout: 5000 } }; return (
); } ``` -------------------------------- ### Number Input Component with React Hook Form and Mantine Source: https://context7.com/aranlucas/react-hook-form-mantine/llms.txt Illustrates the use of the `NumberInput` component from `react-hook-form-mantine` for numeric inputs. Includes features like increment/decrement controls, min/max validation, precision settings, and prefix/step configuration, all managed via `react-hook-form` and Zod. ```tsx import { useForm } from "react-hook-form"; import { NumberInput } from "react-hook-form-mantine"; import { Button } from "@mantine/core"; import { z } from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; const schema = z.object({ age: z.number().min(18, "Must be at least 18").max(120, "Invalid age"), quantity: z.number().min(1).max(100), price: z.number().positive(), }); type FormData = z.infer; function ProductForm() { const { control, handleSubmit } = useForm({ resolver: zodResolver(schema), defaultValues: { age: 25, quantity: 1, price: 0, }, }); const onSubmit = (data: FormData) => { console.log("Form data:", data); // Output: { age: 25, quantity: 5, price: 29.99 } }; return (
); } ``` -------------------------------- ### Slider: Range Input for Settings - React Hook Form / Mantine Source: https://context7.com/aranlucas/react-hook-form-mantine/llms.txt Provides a range slider component for numeric value selection using Slider from react-hook-form-mantine. It includes visual markers and labels for clarity. Zod is used for schema validation, ensuring values are within a specified range. ```tsx import { useForm } from "react-hook-form"; import { Slider } from "react-hook-form-mantine"; import { Button, Text } from "@mantine/core"; import { z } from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; const schema = z.object({ volume: z.number().min(0).max(100), brightness: z.number(), }); type FormData = z.infer; function SettingsSliderForm() { const { control, handleSubmit, watch } = useForm({ resolver: zodResolver(schema), defaultValues: { volume: 50, brightness: 75, }, }); const volumeValue = watch("volume"); const onSubmit = (data: FormData) => { console.log("Settings:", data); // Output: { volume: 75, brightness: 90 } }; return (
Volume: {volumeValue}%
Brightness
); } ``` -------------------------------- ### Checkbox Component with React Hook Form and Mantine Source: https://context7.com/aranlucas/react-hook-form-mantine/llms.txt Demonstrates how to use the `Checkbox` and `Checkbox.Group` components from `react-hook-form-mantine` for single and multi-selection scenarios. It includes form validation using Zod and integrates seamlessly with `react-hook-form`'s `useForm` hook. ```tsx import { useForm } from "react-hook-form"; import { Checkbox } from "react-hook-form-mantine"; import { Button, Stack } from "@mantine/core"; import { z } from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; const schema = z.object({ terms: z.boolean().refine((val) => val === true, { message: "You must accept the terms", }), newsletter: z.boolean(), notifications: z.array(z.string()), }); type FormData = z.infer; function SettingsForm() { const { control, handleSubmit } = useForm({ resolver: zodResolver(schema), defaultValues: { terms: false, newsletter: true, notifications: ["email"], }, }); const onSubmit = (data: FormData) => { console.log("Settings:", data); // Output: { terms: true, newsletter: true, notifications: ["email", "push"] } }; return (
); } ``` -------------------------------- ### Textarea Component with Validation Source: https://context7.com/aranlucas/react-hook-form-mantine/llms.txt Implements a multi-line text input with auto-sizing and character limit support using react-hook-form and Zod for validation. It includes a comment field with min/max length and an optional bio field. ```tsx import { useForm } from "react-hook-form"; import { Textarea } from "react-hook-form-mantine"; import { Button } from "@mantine/core"; import { z } from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; const schema = z.object({ comment: z.string().min(10, "Comment must be at least 10 characters").max(500), bio: z.string().optional(), }); type FormData = z.infer; function CommentForm() { const { control, handleSubmit } = useForm({ resolver: zodResolver(schema), defaultValues: { comment: "", bio: "", }, }); const onSubmit = (data: FormData) => { console.log("Submitted:", data); // Output: { comment: "This is my comment...", bio: "Software developer" } }; return (