### Checkbox Group Setup in Svelte Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/components/checkbox.md Provides an example of creating a checkbox group using `Checkbox.Group` and `Checkbox.Root` components. It includes basic setup with script and template. ```svelte Notifications ``` -------------------------------- ### Usage Example Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/type-helpers/with-element-ref.md An example demonstrating how to use the `WithElementRef` type helper in a Svelte component. ```APIDOC ## Usage Example ### Description This example shows how to integrate the `WithElementRef` type helper into a custom Svelte component to manage the `ref` prop. ### Component: CustomButton.svelte ```svelte ``` ### Explanation - The `Props` type is defined by extending `WithElementRef` with specific component props (`yourPropA`, `yourPropB`) and the desired HTML element type (`HTMLButtonElement`). - The `ref` prop is then destructured from `Props` and initialized using `$bindable(null)`. - The `bind:this={ref}` directive on the ` ``` ```svelte ``` -------------------------------- ### Apply Svelte Transitions to Menubar Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/components/menubar.md Demonstrates using the forceMount prop and the child snippet to apply Svelte transitions like fly to Menubar content. ```svelte {#snippet child({ wrapperProps, props, open })} {#if open}
Item 1 Item 2
{/if} {/snippet}
``` -------------------------------- ### TimeRange Type Definition Source: https://github.com/huntabyte/bits-ui/blob/main/docs/src/lib/content/api-reference/extended-types/shared/time-range-prop.md Defines the structure for a time range object containing optional start and end time values. ```APIDOC ## Type Definition: TimeRange ### Description The `TimeRange` type represents a temporal range consisting of an optional start time and an optional end time, utilizing the `TimeValue` type from the Bits UI package. ### Structure - **start** (TimeValue | undefined) - The beginning of the time range. - **end** (TimeValue | undefined) - The conclusion of the time range. ### Usage Example ```typescript import type { TimeRange } from "bits-ui"; const myRange: TimeRange = { start: new Time(9, 0), end: new Time(17, 0) }; ``` ``` -------------------------------- ### Using Custom Switch Component (Svelte) Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/components/switch.md Illustrates how to integrate and use the custom 'MySwitch' component within an application. It demonstrates binding the 'checked' state to a local variable and setting a descriptive label. ```svelte ``` -------------------------------- ### Manage Rating State Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/components/rating-group.md Provides examples for managing component state using two-way binding or fully controlled function bindings. ```svelte {#snippet children({ items })} {#each items as item (item.index)} {#if item.state === "active"}⭐{:else}☆{/if} {/each} {/snippet} ``` ```svelte {#snippet children({ items })} {#each items as item (item.index)} {#if item.state === "active"}⭐{:else}☆{/if} {/each} {/snippet} ``` -------------------------------- ### Creating a Reusable Progress Component Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/components/progress.md An example of wrapping the Progress primitive to create a custom, reusable component with labels and accessibility attributes. ```svelte
{label} {valueLabel}
``` -------------------------------- ### Implement Basic Date Picker Structure Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/components/date-picker.md Demonstrates the standard composition of a Date Picker using Bits UI sub-components. It includes the input field, calendar grid, and navigation controls. ```svelte {#snippet children({ segments })} {#each segments as { part, value }} {value} {/each} {/snippet} {#snippet children({ months, weekdays })} {#each months as month} {#each weekdays as day} {day} {/each} {#each month.weeks as weekDates} {#each weekDates as date} {/each} {/each} {/each} {/snippet} ``` -------------------------------- ### Toolbar Structure Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/components/toolbar.md Demonstrates the basic HTML structure for implementing the Toolbar component using bits-ui. ```APIDOC ## Toolbar Structure ### Description This section shows the fundamental HTML structure for the Toolbar component. ### Method N/A (Component Structure) ### Endpoint N/A (Component Structure) ### Parameters N/A (Component Structure) ### Request Example ```svelte ``` ### Response N/A (Component Structure) ### Response Example N/A (Component Structure) ``` -------------------------------- ### Use Custom Context Menu with Inline Snippet Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/components/context-menu.md Example of using the reusable CustomContextMenu component with the trigger snippet defined inline. ```svelte {#snippet triggerArea()}
Right-click me
{/snippet}
``` -------------------------------- ### Applying Svelte Transitions with forceMount Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/transitions.md Demonstrates how to use the forceMount prop and the child snippet to conditionally render a Dialog component and apply a Svelte fly transition. ```svelte {#snippet child({ props, open })} {#if open}
{/if} {/snippet}
``` -------------------------------- ### Basic PIN Input Structure (Svelte) Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/components/pin-input.md Demonstrates the fundamental structure of the PIN Input component using Svelte. It sets up the root element and iterates through cells to render individual input fields. ```svelte {#snippet children({ cells })} {#each cells as cell} {/each} {/snippet} ``` -------------------------------- ### Manage Placeholder State Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/components/time-range-field.md Examples of managing the placeholder state using standard two-way binding or a fully controlled approach with function bindings. ```svelte ``` -------------------------------- ### Basic Toolbar Structure Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/components/toolbar.md Demonstrates the fundamental composition of a Toolbar using the Root, Group, GroupItem, Link, and Button sub-components. ```svelte ``` -------------------------------- ### Meter Component - Basic Usage Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/components/meter.md Demonstrates the basic structure of using the Meter component. ```APIDOC ## Meter Component - Basic Usage ### Description This snippet shows the fundamental way to include and use the Meter component. ### Method N/A (Component Usage) ### Endpoint N/A (Component Usage) ### Parameters N/A (Component Usage) ### Request Example ```svelte ``` ### Response N/A (Component Usage) ``` -------------------------------- ### Custom Accordion Content Component Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/components/accordion.md A guide on how to create a reusable Accordion Content component that encapsulates Svelte transition logic for better maintainability. ```APIDOC ## Custom Accordion Content Component ### Description Encapsulates the Accordion.Content primitive with custom transition logic using Svelte's `fade` transition. ### Parameters #### Props - **duration** (number) - Optional - The duration of the fade transition in milliseconds. - **ref** (HTMLElement) - Optional - Bindable reference to the underlying element. ### Implementation Example ```svelte {#snippet child({ props, open })} {#if open}
{@render children?.()}
{/if} {/snippet}
``` ``` -------------------------------- ### Create Svelte Project Source: https://github.com/huntabyte/bits-ui/blob/main/tests/README.md Commands to create a new Svelte project either in the current directory or a specified directory. This is the initial step for any Svelte application. ```bash npm create svelte@latest npm create svelte@latest my-app ``` -------------------------------- ### Configure TimeField Placeholder Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/components/time-field.md Examples of setting the initial placeholder time for the TimeField component using standard Time objects or ZonedDateTime for timezone support. ```svelte ``` -------------------------------- ### Basic Dialog Structure Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/components/dialog.md Demonstrates the fundamental composition of the Dialog component using its sub-components like Root, Trigger, Portal, Overlay, and Content. ```svelte ``` -------------------------------- ### Configure Accordion Selection Modes Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/components/accordion.md Examples of setting the Accordion type to either single or multiple selection modes to control user interaction behavior. ```svelte ``` -------------------------------- ### Use Custom Context Menu with Separate Snippet Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/components/context-menu.md Example of using the reusable CustomContextMenu component with the trigger snippet defined separately and passed as a prop. ```svelte {#snippet triggerArea()}
Right-click me
{/snippet} ``` -------------------------------- ### Use Svelte Transitions with Tooltip Content Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/components/tooltip.md Use the `forceMount` prop on `Tooltip.Content` to enable Svelte Transitions or other animation libraries. This requires manually managing the open state within a child snippet. ```svelte {#snippet child({ wrapperProps, props, open })} {#if open}
{/if} {/snippet}
``` -------------------------------- ### Use Command LinkItem for Navigation Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/components/command.md Explains how to use Command.LinkItem to render an anchor tag, providing standard link behavior like prefetching. ```svelte ``` -------------------------------- ### Creating Reusable Menubar Components Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/components/menubar.md Shows how to wrap Menubar parts into a custom component to simplify implementation when using the Menubar in multiple locations. ```svelte {triggerText} {#each items as item} {item.label} {/each} ``` -------------------------------- ### Customizing Accessibility with aria-valuetext Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/components/rating-group.md Provides an example of how to use the `aria-valuetext` prop to supply custom descriptive text for rating values, enhancing screen reader announcements. ```APIDOC ## Customizing Accessibility You can enhance the accessibility experience with custom `aria-valuetext`: ```svelte { if (value === 0) return "No rating selected"; return `${value} out of ${max} stars. ${value >= 4 ? "Excellent" : value >= 3 ? "Good" : "Fair"} rating.`; }} > ``` ``` -------------------------------- ### Configure Scroll Area Behavior and Delay Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/components/scroll-area.md Examples showing how to toggle scrollbar visibility types and customize the hide delay using the custom component wrapper. ```svelte ``` -------------------------------- ### Basic Aspect Ratio Implementation (Svelte) Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/components/aspect-ratio.md Demonstrates the fundamental usage of the AspectRatio.Root component from bits-ui in a Svelte application. This snippet shows how to import and render the root component. ```svelte ``` -------------------------------- ### Define TimeRange Type Source: https://github.com/huntabyte/bits-ui/blob/main/docs/src/lib/content/api-reference/extended-types/shared/time-range-prop.md Defines a TypeScript type for representing a range of time. It relies on the TimeValue type from bits-ui and allows both start and end properties to be undefined. ```typescript import type { TimeValue } from "bits-ui"; type TimeRange = { start: TimeValue | undefined; end: TimeValue | undefined; }; ``` -------------------------------- ### Apply Svelte Transitions to Link Preview Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/components/link-preview.md Use the forceMount prop and child snippet to enable Svelte transitions for the Link Preview content. ```svelte {#snippet child({ wrapperProps, props, open })} {#if open}
{/if} {/snippet}
``` -------------------------------- ### Control Tooltip Active Trigger Programmatically Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/components/tooltip.md In controlled mode, bind both `open` and `triggerId` to manage tooltip visibility programmatically. This is useful for guided onboarding flows. ```svelte ``` -------------------------------- ### Using MyAspectRatio Component (Svelte) Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/components/aspect-ratio.md Shows how to integrate the custom 'MyAspectRatio' reusable component within a Svelte page. It demonstrates passing the 'src', 'alt', and 'ratio' props to render an image with a specific aspect ratio. ```svelte ``` -------------------------------- ### Configure AlertDialog Focus Management Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/components/alert-dialog.md Provides examples for disabling focus traps, overriding auto-focus on open, and overriding auto-focus on close to improve accessibility and user flow. ```svelte { e.preventDefault(); nameInput?.focus(); }} > { e.preventDefault(); nameInput?.focus(); }} > ``` -------------------------------- ### Implement Basic Link Preview Structure Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/components/link-preview.md The fundamental structure of the Link Preview component using Root, Trigger, and Content sub-components. ```svelte ``` -------------------------------- ### Use Svelte Transitions with ContextMenu.Content Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/components/context-menu.md Force mount ContextMenu.Content using the 'forceMount' prop and the 'child' snippet to integrate Svelte Transitions or other animation libraries. This requires manual handling of the content's visibility and wrapper props. ```svelte {#snippet child({ wrapperProps, props, open })} {#if open}
Item 1 Item 2
{/if} {/snippet}
``` -------------------------------- ### Implement Time Range Field Structure Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/components/time-range-field.md Basic implementation of the TimeRangeField component using Svelte. It demonstrates how to structure the root, label, and input segments for both start and end times. ```svelte Working Hours {#each ["start", "end"] as const as type} {#snippet children({ segments })} {#each segments as { part, value }} {value} {/each} {/snippet} {/each} ``` -------------------------------- ### Theme-specific Portal Targets Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/utilities/bits-config.md Demonstrates configuring different portal targets for distinct UI regions like headers, sidebars, and main content areas using separate BitsConfig instances. ```svelte
``` -------------------------------- ### Custom Anchor for Select Content Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/components/select.md Anchor the Select.Content to a different element by providing a selector string or an HTMLElement to the `customAnchor` prop. This example demonstrates binding the `customAnchor` prop to a div element. ```svelte
``` -------------------------------- ### Using Custom Checkbox Component (Svelte) Source: https://github.com/huntabyte/bits-ui/blob/main/docs/content/components/checkbox.md Shows a practical example of how to import and use the custom `MyCheckbox` component within a Svelte page, passing necessary props like `labelText`. ```svelte ```