### Usage Example Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/api-reference/container-components.md Example demonstrating how to use the Menu and MenuItem components with a Button trigger. ```APIDOC ## Usage ```svelte {}} /> {}} /> ``` ``` -------------------------------- ### Basic M3 Svelte Button Setup Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/README.md Demonstrates basic setup and usage of an M3 Svelte Button component. Includes importing necessary styles and defining custom primary colors. ```svelte ``` -------------------------------- ### Install Theming Dependencies Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/configuration.md Install the material-color-utilities-nightly package for dynamic theming and vite-plugin-functions-mixins for density customization. ```bash npm install @ktibow/material-color-utilities-nightly npm install --save-dev vite-plugin-functions-mixins ``` -------------------------------- ### Install M3 Svelte Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/README.md Install the m3-svelte package using npm. ```bash npm install m3-svelte ``` -------------------------------- ### Configure SvelteKit Adapter Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/configuration.md Example svelte.config.js configuration for SvelteKit projects. Ensures compatibility with the build process. ```javascript import adapter from '@sveltejs/adapter-auto' export default { kit: { adapter: adapter(), }, } ``` -------------------------------- ### Minimal M3 Svelte List Demo Source: https://github.com/ktibow/m3-svelte/blob/main/src/demos.md A basic example demonstrating how to use the ListItem component with just a headline. ```svelte
``` -------------------------------- ### Snackbar Usage Example Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/api-reference/container-components.md Demonstrates how to integrate the Snackbar component into an application and trigger notifications. It shows adding the Snackbar to the app root and using the `snackbar` function with and without actions. ```svelte ``` -------------------------------- ### Install vite-plugin-token-shaker Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/configuration.md Install the vite-plugin-token-shaker package to optimize CSS variables by removing unused ones. This plugin helps in reducing the final CSS bundle size. ```bash npm install --save-dev vite-plugin-token-shaker ``` -------------------------------- ### TabsLink Usage Example Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/api-reference/navigation-components.md Demonstrates how to implement TabsLink for URL-based navigation within a Svelte application. Ensure to import necessary components and stores. ```svelte ``` -------------------------------- ### Install M3 Svelte with npm, pnpm, or yarn Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/configuration.md Install the m3-svelte package using your preferred package manager. This is the first step to using M3 Svelte components. ```bash npm install m3-svelte # or pnpm add m3-svelte # or yarn add m3-svelte ``` -------------------------------- ### NavigationRail Usage Example Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/api-reference/navigation-components.md Shows how to set up a vertical NavigationRail with NavigationRailItems. Icons must be imported from a compatible icon set. State management is required for selected items. ```svelte currentNav = 'home'} /> currentNav = 'settings'} /> currentNav = 'profile'} /> ``` -------------------------------- ### Tree-shaking Example Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/configuration.md Demonstrates how unused components are automatically removed by modern bundlers when only specific components are imported. Ensure only necessary components are imported to leverage tree-shaking. ```javascript // Only imported components are bundled import { Button } from 'm3-svelte' import TextField from 'm3-svelte' ``` -------------------------------- ### Code Splitting Example Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/configuration.md Shows how to manually control code splitting in SvelteKit by dynamically importing components. This is useful for optimizing load times by splitting code per route or component. ```javascript import { browser } from '$app/environment' let Dialog if (browser) { Dialog = (await import('m3-svelte')).Dialog } ``` -------------------------------- ### SplitButton Usage Example Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/api-reference/button-components.md Demonstrates how to use the SplitButton component with a main action and menu items. Ensure the SplitButton component is imported from 'm3-svelte'. ```svelte doMainAction()} menuItems={[ { label: 'Option 1', onclick: () => opt1() }, { label: 'Option 2', onclick: () => opt2() }, ]}> Save ``` -------------------------------- ### Minimal Button Demo Source: https://github.com/ktibow/m3-svelte/blob/main/src/demos.md A basic example of using the Button component with an elevated variant and a simple click handler. ```svelte ``` -------------------------------- ### FAB Usage Example (Icon-only) Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/api-reference/button-components.md Shows how to implement an icon-only Floating Action Button (FAB). This is typically used for a primary action on the screen. Ensure FAB and Icon components are imported. ```svelte ``` -------------------------------- ### Full FAB Configuration Source: https://github.com/ktibow/m3-svelte/blob/main/src/demos.md Demonstrates a configurable Floating Action Button with options for color, size, and content (icon, text, or both). Requires setup for state variables and component imports. ```typescript let color: | "primary-container" | "secondary-container" | "tertiary-container" | "primary" | "secondary" | "tertiary" = $state("primary-container"); const sizes = ["normal", "medium", "large"] as const; let sizeIndex = $state(0); let iconTextSetup: "icon" | "both" | "text" = $state("icon"); ``` ```svelte sizes[n][0].toUpperCase() + sizes[n].slice(1)} /> {#snippet demo()} {@const size = sizes[sizeIndex]}
{}} />
{/snippet} ``` -------------------------------- ### Peer Dependencies for Theming Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/configuration.md Includes essential peer dependencies for dynamic theming and density customization. Install these for advanced theming features. ```json { "peerDependencies": { "@ktibow/material-color-utilities-nightly": "^0.4.1768930731000", "vite-plugin-functions-mixins": "^0.4.1" } } ``` -------------------------------- ### Switch Usage Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/api-reference/form-components.md Illustrates the use of the Switch component for on/off states. The example shows how to bind the toggle state to a variable. ```svelte ``` -------------------------------- ### Full ConnectedButtons Demo Configuration Source: https://github.com/ktibow/m3-svelte/blob/main/src/demos.md Configures variant, multiselect, and size for ConnectedButtons. Use this for dynamic button group setups. ```use ConnectedButtons Button ``` ```ts let variant: "filled" | "tonal" = $state("filled"); let multiselect = $state(true); const sizes = ["xs", "s", "m", "l", "xl"] as const; const sizeLabels = ["Extra small", "Small", "Medium", "Large", "Extra large"] as const; let sizeIndex = $state(1); ``` ```svelte sizeLabels[n]} /> {#snippet demo()} {@const size = sizes[sizeIndex]} {/snippet} ``` -------------------------------- ### Show StandardSideSheet Example Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/api-reference/container-components.md Illustrates the use of the StandardSideSheet component for displaying navigation. The sheet's visibility and content are managed via bound variables and child components. ```svelte ``` -------------------------------- ### Minimal Shapes Component Demo Source: https://github.com/ktibow/m3-svelte/blob/main/src/demos.md Shows the minimal setup for using shape paths, intended for use within an SVG element. ```svelte ``` -------------------------------- ### Menu and MenuItem Usage Example Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/api-reference/container-components.md This snippet shows how to use the Menu and MenuItem components to create a context menu triggered by a button. It demonstrates binding menu visibility and anchoring the menu to a specific element. Ensure necessary icons are imported. ```svelte {}} /> {}} /> ``` -------------------------------- ### Show BottomSheet Example Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/api-reference/container-components.md Demonstrates how to use the BottomSheet component to display filter options. The sheet's visibility is controlled by a bound boolean variable. ```svelte ``` -------------------------------- ### Tabs and VariableTabs Usage Example Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/api-reference/navigation-components.md Demonstrates how to implement both primary Tabs and secondary VariableTabs components, including binding the active tab and conditionally rendering content based on the selected tab. ```svelte {#if activeTab === 'home'}
Home content
{:else if activeTab === 'activity'}
Activity content
{:else}
Settings content
{/if} ``` -------------------------------- ### Vertical Navigation with Badges Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/api-reference/navigation-components.md Demonstrates a vertical navigation layout using NavCMLX and NavCMLXItem. Includes examples of displaying numerical badges and boolean dot indicators, along with managing the active state. ```svelte activeNav = 'inbox'} /> activeNav = 'sent'} /> activeNav = 'drafts'} /> ``` -------------------------------- ### Svelte Snippet Prop Example Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/API-OVERVIEW.md Demonstrates the use of the `Snippet` prop for flexible content rendering in container components like Dialog. It shows how to define buttons with a render function. ```svelte {...}}> Confirm deletion? ``` -------------------------------- ### Change Theme Dynamically at Runtime Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/configuration.md Update CSS variables on-the-fly to change color schemes dynamically. This example demonstrates changing the theme based on a color input. ```svelte changeTheme(parseInt(e.target.value.slice(1), 16) + 0xFF000000)} /> ``` -------------------------------- ### FAB Usage Example (Extended) Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/api-reference/button-components.md Demonstrates an extended Floating Action Button (FAB) which includes both an icon and text. This variant is suitable for actions that benefit from a descriptive label. Ensure FAB and Icon components are imported. ```svelte Edit Profile ``` -------------------------------- ### Importing Components and Utilities from m3-svelte Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/COMPONENT-INVENTORY.md Demonstrates how to import all components and specific utilities from the main 'm3-svelte' entry point, or how to import individual components and utilities. ```typescript // From 'm3-svelte' import Button, { ConnectedButtons, FAB, SplitButton, TextField, // ... all others Snackbar, { snackbar } } from 'm3-svelte' // Or individual imports import Button from 'm3-svelte' import { Snackbar, snackbar } from 'm3-svelte' ``` -------------------------------- ### Full Dialog Demo with Open Button Source: https://github.com/ktibow/m3-svelte/blob/main/src/demos.md Demonstrates opening a Dialog using a button. The dialog includes an icon, headline, extensive content, and action buttons. Requires 'Button' and 'Dialog' imports. ```ts let open = $state(false); ``` ```svelte {#snippet demo()} Anything is possible at ZomboCom! You can do anything at ZomboCom! The infinite is possible at ZomboCom! The unattainable is unknown at ZomboCom! {#snippet buttons()} {/snippet} {/snippet} ``` -------------------------------- ### Basic Icon Usage Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/api-reference/navigation-components.md Demonstrates how to import and use the Icon component with default sizing. ```svelte ``` -------------------------------- ### Minimal Radio Animation Demo Source: https://github.com/ktibow/m3-svelte/blob/main/src/demos.md Basic example of a radio button with the RadioAnim1 component. ```svelte ``` -------------------------------- ### Minimal ConnectedButtons Demo Source: https://github.com/ktibow/m3-svelte/blob/main/src/demos.md A basic example of using the ConnectedButtons component with two checkbox inputs. ```svelte ``` -------------------------------- ### TextField with Trailing Button Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/api-reference/form-components.md Illustrates using a trailing button within the TextField, for example, to clear the input. ```svelte email = '' }} /> ``` -------------------------------- ### Full Progress Demo Configuration Source: https://github.com/ktibow/m3-svelte/blob/main/src/demos.md Sets up state variables for controlling the type, estimation, thickness, and percentage of progress indicators. This allows for dynamic configuration of the progress display. ```typescript let type: "linear" | "linear-wavy" | "circular" = $state("linear"); let estimate = $state(false); let thick = $state(false); let percent = $state(10); ``` -------------------------------- ### TypeScript Configuration Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/configuration.md Basic tsconfig.json setup for M3 Svelte projects, specifying target, libraries, and module resolution. ```json { "compilerOptions": { "target": "ES2020", "lib": ["ES2020", "DOM"], "moduleResolution": "bundler" } } ``` -------------------------------- ### Full NavCMLX Demo with State Source: https://github.com/ktibow/m3-svelte/blob/main/src/demos.md A comprehensive demo of the NavCMLX component demonstrating dynamic variant and item selection using Svelte state management. ```typescript let variant: "compact" | "medium" | "large" | "extra-large" | "auto" = $state("auto"); let item = $state("a"); ``` ```svelte {#snippet demo()} {/snippet} ``` -------------------------------- ### SnackbarItem Usage Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/api-reference/container-components.md Example of using the SnackbarItem component to display a notification message with an action button. Import the component from 'm3-svelte'. ```svelte

Notification message

``` -------------------------------- ### Minimal Switch Demo Source: https://github.com/ktibow/m3-svelte/blob/main/src/demos.md A basic implementation of the Switch component. ```svelte ``` -------------------------------- ### Full Menu Demo with Icons Toggle Source: https://github.com/ktibow/m3-svelte/blob/main/src/demos.md Demonstrates the Menu and MenuItem components with an option to toggle icons on and off. Requires 'Menu' and 'MenuItem' imports. ```ts let icons = $state(false); ``` ```svelte {#snippet demo()} {}}>Alpha {}}>Beta {}}>Charlie {/snippet} ``` -------------------------------- ### Full Icon Component Demo Source: https://github.com/ktibow/m3-svelte/blob/main/src/demos.md A full demonstration of the Icon component, allowing dynamic size adjustment via a Slider. ```ts let size = $state(24); ``` ```svelte n.toFixed(0) + "px"} /> {#snippet demo()}
{/snippet} ``` -------------------------------- ### ConnectedButtons Usage Example Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/api-reference/button-components.md Demonstrates how to group multiple buttons together using the ConnectedButtons component. Ensure Button components are imported alongside ConnectedButtons. ```svelte ``` -------------------------------- ### Minimal Icon Component Demo Source: https://github.com/ktibow/m3-svelte/blob/main/src/demos.md Demonstrates the minimal usage of the Icon component with a specific icon import. ```svelte ``` -------------------------------- ### Minimal Menu Demo Source: https://github.com/ktibow/m3-svelte/blob/main/src/demos.md A basic implementation of the Menu component with three menu items. ```svelte Alpha Beta Charlie ``` -------------------------------- ### Full Select Demo Source: https://github.com/ktibow/m3-svelte/blob/main/src/demos.md Demonstrates the Select and SelectOutlined components with options for variant, icons, and enabled state. Requires Select, SelectOutlined, and icon definitions to be imported. ```svelte {#snippet demo()} {#if variant === "filled"} {/if} {#if iconType == "none"} Hello {:else if iconType == "left"} Hello {:else} {/if} {/snippet} ``` -------------------------------- ### Dialog Component Usage Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/api-reference/container-components.md Example of how to use the Dialog component to create a confirmation dialog for deleting an item. Includes import statements and state management for dialog visibility. ```svelte ( <> )}> This action cannot be undone. ``` -------------------------------- ### Basic TextField Usage Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/api-reference/form-components.md Demonstrates the basic usage of the TextField component for capturing user input. ```svelte ``` -------------------------------- ### Minimal Tabs Demo Source: https://github.com/ktibow/m3-svelte/blob/main/src/demos.md Demonstrates the basic usage of the Tabs component with predefined items. ```svelte ``` -------------------------------- ### Radio Button Animation Styles Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/api-reference/form-components.md Shows how to implement radio buttons using different animation styles (Fill, Bounce, Scale) provided by m3-svelte. This example uses RadioAnim1. ```svelte
``` -------------------------------- ### Animatable SVG Shape Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/api-reference/utility-functions.md Provides an example of using an SVG with an animate element to transition between different path values, creating an animatable shape. This is typically used for advanced animations. ```svelte ``` -------------------------------- ### Full Switch Demo Configuration Source: https://github.com/ktibow/m3-svelte/blob/main/src/demos.md Configures the Switch component with different icon states and enables/disables it. ```ts let icons: "checked" | "both" | "none" = $state("checked"); let enabled = $state(true); ``` ```svelte {#snippet demo()} {/snippet} ``` -------------------------------- ### Svelte Usage of addBadge Function Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/api-reference/utility-functions.md Example of using the addBadge function in a Svelte component to add a notification badge to an icon. The 'icon' parameter is the base icon, and 'n' is the optional count. ```svelte ``` -------------------------------- ### Use Key Blocks for List Animations Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/QUICK-REFERENCE.md Employ key blocks within `#each` statements to enable efficient list animations and updates. Assign a unique key to each item for proper tracking. ```svelte {#each items as item (item.id)}
{item.name}
{/each} ``` -------------------------------- ### Minimal NavCMLX Demo Source: https://github.com/ktibow/m3-svelte/blob/main/src/demos.md A basic implementation of the NavCMLX component with two items. It uses the 'auto' variant for adaptive behavior. ```svelte ``` -------------------------------- ### Full M3 Svelte List Demo Configuration Source: https://github.com/ktibow/m3-svelte/blob/main/src/demos.md Defines state variables for headline, lines, and type, which control the appearance and behavior of the ListItem. Use this for complex list item setups. ```ts const headline = "Hello"; let lines: "1" | "2" | "3" = $state("1"); let type: "div" | "button" | "label" | "a" = $state("div"); let supporting = $derived( lines == "1" ? undefined : lines == "2" ? "Welcome to ZomboCom!" : "Welcome to ZomboCom! Anything is possible at ZomboCom! You can do anything at ZomboCom!", ); ``` -------------------------------- ### Minimal Select Demo Source: https://github.com/ktibow/m3-svelte/blob/main/src/demos.md A basic implementation of the Select component with two options. ```svelte {:else} {/if} {/snippet} {} } : type == "a" ? { href: "https://example.com" } : {}} /> {} } : type == "a" ? { href: "https://example.com" } : {}} /> {/snippet} ``` -------------------------------- ### Import Recommended M3 Svelte Styles Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/configuration.md Import the recommended M3 Svelte styles, which include base tokens. This is the preferred method for comprehensive styling. ```svelte ``` -------------------------------- ### Minimal TextField Demo Source: https://github.com/ktibow/m3-svelte/blob/main/src/demos.md A basic implementation of the TextField component. ```svelte ``` -------------------------------- ### ListItem Component Usage Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/api-reference/container-components.md Shows how to implement the ListItem component with headline, supporting text, leading and trailing icons, and click handling. Requires importing icons. ```svelte { selectedContact = 'john' }} /> ``` -------------------------------- ### Bindable Values for Svelte State Management Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/types.md Demonstrates the use of Svelte's `$bindable()` directive for creating two-way bound properties in components. Examples cover string, boolean, number, and string types for various UI elements. ```typescript // TextField value: string = $bindable() // Checkbox, Switch checked: boolean = $bindable() // Slider value: number = $bindable() // Tabs tab: string = $bindable() // Select value: string = $bindable() ``` -------------------------------- ### Basic Slider with Icons Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/api-reference/form-components.md Implement a basic volume slider with leading and trailing icons to indicate the range. Ensure icons are imported from a compatible icon set. ```svelte ``` -------------------------------- ### Basic Chip with Icon and Click Handler Source: https://github.com/ktibow/m3-svelte/blob/main/src/demos.md Demonstrates a basic Chip component with an icon and an onclick event handler. The 'iconCircle' variable is assumed to be defined elsewhere. ```svelte alert("!")}>Hello ``` -------------------------------- ### Full Tabs Demo Configuration Source: https://github.com/ktibow/m3-svelte/blob/main/src/demos.md Configures tab type, icon visibility, and variable tab behavior. ```ts let type: "primary" | "secondary" = $state("primary"); let icons = $state(false); let variable = $state(false); let tab = $state("hello"); let items = $derived( icons ? [ { icon: iconCircle, name: "Hello", value: "hello" }, { icon: iconSquare, name: "World", value: "world" }, { icon: iconTriangle, name: "The longest item", value: "long" }, ] : [ { name: "Hello", value: "hello" }, { name: "World", value: "world" }, { name: "The longest item", value: "long" }, ], ); ``` -------------------------------- ### Import m3-svelte Utilities Source: https://github.com/ktibow/m3-svelte/blob/main/_autodocs/QUICK-REFERENCE.md Import utility functions and constants for animations, color manipulation, and helper functions from the 'm3-svelte' package. These are used for enhancing UI behavior and customization. ```svelte ``` -------------------------------- ### Full Slider Demo with Options Source: https://github.com/ktibow/m3-svelte/blob/main/src/demos.md Demonstrates a fully configurable Slider component with options for precision, size, icons, and orientation. Requires state management for various properties. ```typescript let precision = $state<"continuous" | "discrete" | "discrete-stops">("continuous"); const sizes = ["xs", "s", "m", "l", "xl"] as const; const sizeLabels = ["Extra small", "Small", "Medium", "Large", "Extra large"] as const; let sizeIndex = $state(0); let trailingIcon = $state(false); let leadingIcon = $state(false); let endStops = $state(true); let enabled = $state(true); let vertical = $state(false); ``` ```svelte sizeLabels[n]} /> {#if sizeIndex > 1} {/if} {#if precision != "discrete-stops" && !trailingIcon} {/if} {#snippet demo()} {/snippet} ```