### Install Formwerk Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/getting-started.mdx Installs the Formwerk core library using different package managers. ```bash npm install @formwerk/core ``` ```bash pnpm add @formwerk/core ``` ```bash bun add @formwerk/core ``` ```bash yarn add @formwerk/core ``` -------------------------------- ### Basic OTP Field Setup Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/fields/otp-fields.mdx Demonstrates the basic setup of an OTP field component using Formwerk's `useOtpField` composable and binding it to DOM elements. This example shows how to integrate the OTP field into an application. ```vue ``` -------------------------------- ### App Component Usage Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/getting-started.mdx Shows a simple Vue.js application component that uses the `TextField` component, demonstrating data binding with `v-model`. ```vue ``` -------------------------------- ### Use TextField Composable Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/getting-started.mdx Demonstrates how to import and use the `useTextField` composable from Formwerk in a Vue.js component. It shows how to bind props and handle input, labels, and error messages. ```vue ``` -------------------------------- ### Package JSON Dependencies Source: https://github.com/formwerkjs/formwerk.dev/blob/main/README.md Example of a package.json file, showing the dependencies required for an Astro project, including Starlight and its related packages. ```json { "name": "my-starlight-docs", "version": "0.0.1", "scripts": { "dev": "astro dev", "start": "astro dev", "build": "astro build", "preview": "astro preview", "astro": "astro" }, "dependencies": { "@astrojs/check": "^0.7.0", "@astrojs/starlight": "^0.23.0", "astro": "^4.7.0", "starlight-links-checker": "^0.7.0", "typescript": "^5.0.0", "wrangler": "^7.0.0" } } ``` -------------------------------- ### Slider Component Example with MdxRepl Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/fields/sliders.mdx Provides a complete example of integrating custom Slider and SliderThumb components within an application using MdxRepl. This showcases the practical usage and setup. ```vue ``` -------------------------------- ### Nuxt SSR Integration Example Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/extras/ssr.mdx Demonstrates how to import and use Formwerk composables within a Nuxt application for server-side rendering. This example highlights the out-of-the-box compatibility with Nuxt. ```javascript import { useForm } from '@formwerk/vue'; // In your Nuxt page or component: const { form, submit } = useForm({ // Form configuration }); ``` -------------------------------- ### Starlight Project Commands Source: https://github.com/formwerkjs/formwerk.dev/blob/main/README.md Lists the essential npm commands for managing and running an Astro + Starlight project. These commands cover installation, local development, building for production, and previewing. ```bash npm install npm run dev npm run build npm run preview npm run astro ... npm run astro -- --help ``` -------------------------------- ### Full Form Repeater Example with Fields Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/forms/form-repeater.mdx This example demonstrates a complete form using repeaters, including text fields and checkboxes. It uses the `useForm` composable for form management and integrates a `FormRepeater` component with nested fields. The example also includes a submit button to process the form data. ```vue ``` -------------------------------- ### Dropzone Component Setup Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/fields/file-fields.mdx Illustrates how to create a dropzone component using Formwerk's `useFileField` composable in Vue.js. This example shows the integration of a custom Dropzone component with a label. ```vue ``` -------------------------------- ### Vue ComboBox Component Example Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/fields/comboboxes.mdx Demonstrates the basic structure of a ComboBox component in Vue.js, including importing and using `ComboBox` and `OptionItem` components. This example shows how to pass props like `label` and `placeholder`. ```vue ``` -------------------------------- ### Vue Checkbox Component Setup Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/fields/checkboxes.mdx Demonstrates how to set up a Vue.js checkbox component using the `useCheckbox` composable from Formwerk's core library. It shows importing necessary types and functions, defining props, and utilizing the composable to get label and input binding objects. ```typescript import { CheckboxProps, useCheckbox } from '@formwerk/core'; const props = defineProps(); const { labelProps, inputProps } = useCheckbox(props); ``` ```vue ``` -------------------------------- ### TextField Component Script Setup Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/extras/_partials/_textField.mdx This script setup defines the TextField component using Vue 3's Composition API. It imports necessary types and hooks from '@formwerk/core', defines props, and utilizes the `useTextField` hook to manage input, label, error, and description properties. ```typescript import { type TextFieldProps, useTextField } from '@formwerk/core'; const props = defineProps(); const { inputProps, labelProps, errorMessage, errorMessageProps, descriptionProps, } = useTextField(props); ``` -------------------------------- ### Locale and Calendar Support Example Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/fields/calendars.mdx Shows how to specify a custom calendar and locale for the Calendar component using the `@internationalized/date` library. This example uses the Islamic Umalqura calendar and the Arabic Saudi locale. ```vue ``` -------------------------------- ### Calendar as a Picker Example Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/fields/calendars.mdx Demonstrates using the Calendar component as a date picker, often paired with a date field. It utilizes the `usePicker` composable from `@formwerk/core` and the popover API for UI. ```vue ``` -------------------------------- ### Project Structure Overview Source: https://github.com/formwerkjs/formwerk.dev/blob/main/README.md Illustrates the typical directory and file structure of an Astro project integrated with Starlight. It highlights key directories for content, assets, and configuration. ```bash .\nā”œā”€ā”€ public/\nā”œā”€ā”€ src/\n│ ā”œā”€ā”€ assets/\n│ ā”œā”€ā”€ content/\n│ │ ā”œā”€ā”€ docs/\n│ │ └── config.ts\n│ └── env.d.ts\nā”œā”€ā”€ astro.config.mjs\nā”œā”€ā”€ package.json\n└── tsconfig.json ``` -------------------------------- ### Create Starlight Project Source: https://github.com/formwerkjs/formwerk.dev/blob/main/README.md Command to create a new Astro project using the Starlight template. This is the initial step for setting up a documentation site with Starlight. ```bash npm create astro@latest -- --template starlight ``` -------------------------------- ### Generic Checkbox Component Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/fields/checkboxes.mdx Provides an example of creating a type-safe and flexible Checkbox component by applying generics (`TValue`) to the component's script setup and `CheckboxProps`. ```vue ``` -------------------------------- ### Starlight Content Configuration Source: https://github.com/formwerkjs/formwerk.dev/blob/main/README.md Configuration file for Starlight, defining the structure and behavior of documentation content. This includes setting up navigation, sidebars, and other documentation-specific features. ```typescript import { defineCollection, defineEntry } from 'astro:content'; const docsCollection = defineCollection({ type: 'content', schema: ({ image }) => defineEntry({ type: 'data', schema: { title: String, description: String, editUrl: ({ sourceFile }) => `https://github.com/withastro/starlight/edit/main/examples/basics/${sourceFile.filepath}`, tableOfContents: { maxHeadingLevel: 3, minHeadingLevel: 2, }, hero: { image: { asset: image(), alt: String, }, text: String, }, sidebar: { label: String, order: Number, customProps: { // Example of custom props // You can add any key-value pairs here // that you want to use in your sidebar. // For example, to add an icon: // icon: 'star' }, }, }, }), }); export function collections({ // The `getEntry` function is available when using the `content` collection type. getEntry, }) { return { docs: docsCollection, }; } ``` -------------------------------- ### Astro Configuration Source: https://github.com/formwerkjs/formwerk.dev/blob/main/README.md Configuration file for Astro projects, specifying project settings, integrations, and output formats. This file is crucial for customizing the build process. ```javascript import { defineConfig } from 'astro/config'; import starlight from '@astrojs/starlight'; // https://astro.build/config export default defineConfig({ integrations: [ starlight({ title: 'My Docs', }), ], }); ``` -------------------------------- ### Radio Group with HTML Constraint Validation Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/fields/radios.mdx Shows how to apply HTML5 constraint validation, specifically the `required` attribute, to a `RadioGroup` component. This example demonstrates the setup in `App.vue` with `RadioGroup` and `Radio` components. ```vue ``` -------------------------------- ### Basic Form with useForm Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/forms/index.mdx Demonstrates the most basic form creation using the `useForm` composable from Formwerk. It initializes a form context and provides a `handleSubmit` function for form submission. ```ts import { useForm } from '@formwerk/core'; const { handleSubmit } = useForm(); const onSubmit = handleSubmit((data) => { console.log(data); }); ``` -------------------------------- ### Radio Component with Input Element Base Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/fields/radios.mdx Illustrates building a `RadioItem` component using a native HTML `input` element as the base. This example shows a complete `App.vue` setup with `RadioGroup` and `RadioItem` components. ```vue ``` -------------------------------- ### PreviewCard Component Usage Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/showcase.mdx Demonstrates the usage of the PreviewCard component to display project showcases. Each card includes a title, description, link to a demo, a video source, and an external link flag. ```vue ``` -------------------------------- ### Switch Component without Input Element Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/fields/switches.mdx Illustrates creating a switch component without a native input element, using a custom element like an SVG. This approach also leverages the `useSwitch` composable for binding and functionality. The example includes a Vue application setup with `v-model` binding. ```vue ``` -------------------------------- ### Vue.js Switch Component Implementation Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/fields/_partials/_switch.mdx This snippet shows the Vue 3 script setup for the Switch component. It imports the `useSwitch` composable from `@formwerk/core` and defines props based on `SwitchProps`. It then utilizes the composable to get input, label, and error message props for binding to the template elements. ```vue ``` -------------------------------- ### Option Component API Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/fields/selects.mdx API documentation for the Option component, detailing its props and return values from the `useOption` composable. ```APIDOC Option Component API: Props (useOption): - (Details not provided in source, refer to ) Returns (useOption): - (Details not provided in source, refer to ) ``` -------------------------------- ### Switch Component with HTML Constraint Validation Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/fields/switches.mdx Shows how to implement HTML constraint validation for a switch component, specifically when using an input[type="checkbox"] as the base. It highlights the use of the `required` attribute and its effect on the switch's validation state. The example includes a simple Vue application setup. ```vue ``` -------------------------------- ### Grid Layout for Showcases Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/showcase.mdx A responsive grid layout using Tailwind CSS classes to display project showcase cards. The grid adjusts the number of columns based on screen size. ```html
``` -------------------------------- ### Formwerk Radio Component - Vue Template and Script Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/fields/_partials/_radioItem.mdx This snippet shows the Vue 3 script setup for the Radio component, importing necessary types and hooks from '@formwerk/core'. It defines props and uses the `useRadio` hook to get label and input properties. The template renders a radio button with a circle indicator and a label, applying the props appropriately. ```vue ``` -------------------------------- ### Select Component API Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/fields/selects.mdx API documentation for the Select component, detailing its props and return values from the `useSelect` composable. ```APIDOC Select Component API: Props (useSelect): - (Details not provided in source, refer to ) Returns (useSelect): - (Details not provided in source, refer to ) ``` -------------------------------- ### Disabling Calendar Views Example Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/fields/calendars.mdx Shows how to restrict the available views (e.g., years, months, weeks) in the Calendar component by using the `allowedViews` prop. This example disables the year view. ```vue ``` -------------------------------- ### Building an Option Component with useOption Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/fields/selects.mdx Demonstrates how to create an option component using the `useOption` composable from FormwerkJS. It highlights the use of `OptionProps` for defining component props and accessing the `label` for display. ```vue ``` -------------------------------- ### Step Form Navigation with `useStepFormFlow` Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/forms/stepped-form-flow.mdx Demonstrates how to use the `useStepFormFlow` composable to manage a multi-step form. It includes logic for navigating between steps, highlighting the active step using `isCurrentStep`, and handling form submission with `onDone`. The example utilizes Zod for schema validation. ```vue ``` -------------------------------- ### Creating a Stepped Form Flow with useStepFormFlow Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/forms/stepped-form-flow.mdx Demonstrates how to use the `useStepFormFlow` composable to create a multi-step form. It covers binding form properties, navigation buttons, handling the completion of the form, and structuring form steps. ```vue ``` -------------------------------- ### NumberFlow Date/Time Field Example Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/fields/date-fields.mdx Showcases a date/time field implementation using the `@number-flow/vue` library for animated value transitions. This example demonstrates advanced UI capabilities for date and time inputs. ```vue ``` -------------------------------- ### Console Timing and Time Logging Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/components/Repl/srcdoc.html Enhances console.time, console.timeLog, and console.timeEnd to record elapsed time and send it to the parent window. It uses a Map to store start times for each timer label. ```javascript const timers = new Map(); const original_time = console.time; const original_timelog = console.timeLog; const original_timeend = console.timeEnd; console.time = (label = 'default') => { original_time(label); timers.set(label, performance.now()); }; console.timeLog = (label = 'default') => { original_timelog(label); const now = performance.now(); if (timers.has(label)) { parent.postMessage( { action: 'console', level: 'system-log', args: [`${label}: ${now - timers.get(label)}ms`] }, '\*' ); } else { parent.postMessage( { action: 'console', level: 'system-warn', args: [`Timer '${label}' does not exist`] }, '\*' ); } }; console.timeEnd = (label = 'default') => { original_timeend(label); const now = performance.now(); if (timers.has(label)) { parent.postMessage( { action: 'console', level: 'system-log', args: [`${label}: ${now - timers.get(label)}ms`] }, '\*' ); } else { parent.postMessage( { action: 'console', level: 'system-warn', args: [`Timer '${label}' does not exist`] }, '\*' ); } timers.delete(label); }; ``` -------------------------------- ### Vue Component Implementation Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/fields/_partials/_switchCustom.mdx This snippet shows the Vue 3 ` ``` -------------------------------- ### Speak Field Component Example Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/fields/custom-fields.mdx Demonstrates the usage of a custom 'SpeakField' component within an App.vue file, showcasing how to pass props like 'name', 'label', and 'sentence'. This example illustrates the integration of a custom field into a Formwerk application. ```vue ``` -------------------------------- ### Option Group Component API Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/fields/selects.mdx API documentation for the Option Group component, detailing its props and return values from the `useOptionGroup` composable. ```APIDOC Option Group Component API: Props (useOptionGroup): - (Details not provided in source, refer to ) Returns (useOptionGroup): - (Details not provided in source, refer to ) ``` -------------------------------- ### Disabled DateField Usage Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/fields/date-fields.mdx Provides an example of disabling the DateField component using the `disabled` prop. Disabled fields are not validated or submitted. ```vue ``` -------------------------------- ### TextField Disabled Example Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/fields/text-fields.mdx Demonstrates how to disable a TextField component, making it non-interactive and preventing validation and submission. Disabled fields cannot be modified by the user. ```vue ``` -------------------------------- ### Formwerk ComboBox Component Ecosystem Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/fields/comboboxes.mdx Explains the core components provided by Formwerk for building ComboBox fields, including the main ComboBox component and its supporting Option and OptionGroup components. It also mentions the use of hooks like `useComboBox` for implementation. ```javascript // Formwerk handles these parts and abstracts them into the following component ecosystem: // - ComboBox: Contains the input, button, and listbox parts. You will use `useComboBox` to build it. // - Option: Represents an option in the list. You will use `useOption` to build it. // - OptionGroup: Represents a group of options in the list. You will use `useOptionGroup` to build it. // Notice that the listbox is not a separate component. This is because popups today can be done in different ways, so Formwerk while offers the open state along with some accessability attributes, it does not have a specific popup component implementation. But we offer out of the box support for [Popover API](https://developer.mozilla.org/en-US/docs/Web/API/Popover_API) if you happen to use one for the listbox element. ``` -------------------------------- ### StepResolveContext API Reference Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/forms/stepped-form-flow.mdx Provides details on the `StepResolveContext` object available within the `onBeforeStepResolve` callback. This context object contains information about the current step, form values, navigation direction, and methods to control the flow. ```APIDOC StepResolveContext: currentStep: object - The current form step object. values: object - An object containing the current form values. next: function - A function that resolves to the next step object in the default flow. - Returns: Promise direction: 'next' | 'previous' - The direction of navigation. Example Usage in onBeforeStepResolve: onBeforeStepResolve(async ({ currentStep, values, next, direction }) => { const nextStep = await next(); if (nextStep.name === 'school' && !values.isStudent) { return direction === 'next' ? 'address' : 'info'; } return next(); }); // Related properties in StepResolveContext: // - You can use `currentStep`, `values`, `direction` to make decisions. // - The `next()` function is crucial for proceeding with the default flow or getting the next step's information. // - Refer to the API reference for a complete list of properties and methods available in StepResolveContext. ``` -------------------------------- ### Formatted Number Field with Currency Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/fields/number-fields.mdx Shows how to format the NumberField value using `formatOptions` compatible with Intl.NumberFormat. This example formats the number as currency. ```vue ``` -------------------------------- ### Indeterminate Checkbox Example Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/fields/checkboxes.mdx Demonstrates how to use the `indeterminate` prop on a Checkbox component to create a tri-state checkbox, useful for checkbox groups with mixed states. ```vue ``` -------------------------------- ### Switch Component with Input Element Source: https://github.com/formwerkjs/formwerk.dev/blob/main/src/content/docs/guides/fields/switches.mdx Demonstrates building a switch component using an input[type="checkbox"] as the base element. It shows how to use the `useSwitch` composable and bind its properties to the DOM elements for functionality and accessibility. Includes a basic Vue application setup with `v-model` binding. ```vue ```