### Import and Use Installed Button Component Source: https://context7.com/dioxuslabs/components/llms.txt Example of importing a component (e.g., Button) after it has been installed using the `dx components add` command. ```rust // After installation, import from your own module mod components; use components::button::Button; fn App() -> Element { rsx! { Button { variant: "default", "Click me" } } } ``` -------------------------------- ### Install Dioxus CLI and Components Source: https://context7.com/dioxuslabs/components/llms.txt Commands to install the Dioxus CLI and add individual components to your project. Components are installed into `src/components` and theme CSS into `assets`. ```sh # Install the Dioxus CLI cargo install dioxus-cli # Add individual components dx components add button dx components add accordion dx components add dialog dx components add toast dx components add virtual-list # The CLI creates: # src/components/button/mod.rs # src/components/button/style.css # assets/dx-components-theme.css (on first install) ``` -------------------------------- ### Install Dioxus CLI Source: https://github.com/dioxuslabs/components/blob/main/README.md Install the Dioxus CLI to manage Dioxus projects and components. ```bash cargo install dioxus-cli ``` -------------------------------- ### Install Dioxus Components Source: https://context7.com/dioxuslabs/components/llms.txt Add dioxus-primitives to your Cargo.toml or install the Dioxus CLI to add styled components directly to your project. ```toml # Cargo.toml [dependencies] dioxus-primitives = "0.0.1" dioxus = "0.7.0" ``` ```sh # Or add styled components directly to your project via the Dioxus CLI cargo install dioxus-cli dx components add button dx components add accordion dx components add dialog # ... etc. ``` -------------------------------- ### Show AlertDialog Example Source: https://github.com/dioxuslabs/components/blob/main/preview/src/components/alert_dialog/docs.md Demonstrates how to use the AlertDialog primitive to display a modal dialog for user confirmation. It manages the open state using a signal and provides slots for title, description, and action buttons. ```rust let open = use_signal(|| false); rsx! { button { onclick: move |_| open.set(true), type: "button", "Show Alert Dialog" } AlertDialogRoot { open: Some(open), on_open_change: move |v| open.set(v), AlertDialogContent { // You may pass class/style for custom appearance AlertDialogTitle { "Title" } AlertDialogDescription { "Description" } AlertDialogActions { AlertDialogCancel { "Cancel" } AlertDialogAction { "Confirm" } } } } } ``` -------------------------------- ### Run CSS Linting Source: https://github.com/dioxuslabs/components/blob/main/README.md Check CSS files for style consistency and potential errors within the preview crate. Ensure you are in the preview directory and have installed npm dependencies. ```bash cd preview npm install npx stylelint "src/**/*.css" ``` -------------------------------- ### Basic Badge Structure Source: https://github.com/dioxuslabs/components/blob/main/preview/src/components/badge/docs.md Illustrates the fundamental structure of the Badge component. Use this as a starting point for creating badges. ```rust Badge { {children} } ``` -------------------------------- ### Item Component Structure Example Source: https://github.com/dioxuslabs/components/blob/main/preview/src/components/item/docs.md Demonstrates the basic structure of an Item component within an ItemGroup, including optional header, media, content, actions, and footer. Shows available variants for Item, ItemMedia, and sizes. ```rust ItemGroup { Item { // Available variants: Default, Outline, Muted variant: ItemVariant::Outline, // Available sizes: Default, Sm size: ItemSize::Default, ItemHeader { "Optional header" } ItemMedia { // Media variants: Default, Icon, Image variant: ItemMediaVariant::Image, img { src: "/path/to/image.png", alt: "Description" } } ItemContent { ItemTitle { "Item title" } ItemDescription { "Detailed description that can span multiple lines." } } ItemActions { button { "Primary action" } } ItemFooter { "Optional footer" } } ItemSeparator {} Item { // ... next item in the group } } ``` -------------------------------- ### Basic Select Component Structure Source: https://github.com/dioxuslabs/components/blob/main/preview/src/components/select/docs.md Illustrates the fundamental structure of the Select component, including its trigger, list, groups, and options. This example shows how to define a single selectable option. ```rust Select:: { // The currently selected value(s) in the dropdown. value: "option1", // Callback function triggered when the selected value changes. on_value_change: |value: String| { // Handle the change in selected value. }, // The select trigger is the button that opens the dropdown. SelectTrigger { // The (optional) select value displays the currently selected text value. SelectValue {} } // All groups must be wrapped in the select list. SelectList { // An group within the select dropdown which may contain multiple items. SelectGroup { // The label for the group SelectGroupLabel { "Other" } // Each select option represents an individual option in the dropdown. The type must match the type of the select. SelectOption:: { // The value of the item, which will be passed to the on_value_change callback when selected. value: "option1", // Select item indicator is only rendered if the item is selected. SelectItemIndicator { "✔️" } } } } } ``` -------------------------------- ### Basic Card Structure Source: https://github.com/dioxuslabs/components/blob/main/preview/src/components/card/docs.md Demonstrates the fundamental structure of the Card component, including its header, content, and footer sections. Use this as a starting point for creating cards. ```rust Card { CardHeader { CardTitle { "Card Title" } CardDescription { "Card description goes here." } CardAction { Button { "Action" } } } CardContent { p { "Main content of the card." } } CardFooter { Button { "Submit" } } } ``` -------------------------------- ### Run Playwright End-to-End Tests Source: https://github.com/dioxuslabs/components/blob/main/README.md Execute end-to-end tests using Playwright to verify component behavior in a simulated browser environment. Ensure you are in the playwright directory and have installed npm dependencies. ```bash cd playwright npm install npx playwright test ``` -------------------------------- ### Serve Preview Application (Desktop) Source: https://github.com/dioxuslabs/components/blob/main/README.md Build and serve the preview application for desktop using the Dioxus CLI. ```bash dx serve -p preview --desktop ``` -------------------------------- ### Serve Preview Application (Web) Source: https://github.com/dioxuslabs/components/blob/main/README.md Build and serve the preview application for the web using the Dioxus CLI. ```bash dx serve -p preview --web ``` -------------------------------- ### Run Dioxus Preview Server Source: https://context7.com/dioxuslabs/components/llms.txt Commands to run the interactive component gallery for desktop or web preview. ```sh # Run the interactive component gallery (desktop) dx serve -p preview --desktop # Run the interactive component gallery (web) dx serve -p preview --web ``` -------------------------------- ### Range Slider Component Structure Source: https://github.com/dioxuslabs/components/blob/main/preview/src/components/slider/docs.md This snippet demonstrates a two-thumb range selector using `RangeSlider`. It allows selection of a start and end value within a range. ```rust RangeSlider { default_value: 20.0..80.0, on_value_change: |value: std::ops::Range| { // value.start and value.end give the two endpoints }, SliderTrack { SliderRange {} SliderThumb { index: 0 } SliderThumb { index: 1 } } } ``` -------------------------------- ### Basic Toolbar Structure Source: https://github.com/dioxuslabs/components/blob/main/preview/src/components/toolbar/docs.md Demonstrates the fundamental structure of a Toolbar, including a title, a button, and a separator. Use this as a base for creating custom toolbars. ```rust Toolbar { aria_label: "Toolbar Title", ToolbarButton { index: 0, on_click: |_: ()| { // This callback is triggered when the button is clicked. }, {children} } ToolbarSeparator { horizontal: true, decorative: false, } } ``` -------------------------------- ### ContentSide and ContentAlign Enums for Overlays Source: https://context7.com/dioxuslabs/components/llms.txt Enums used by overlay components like TooltipContent and PopoverContent to declare content position relative to a trigger. Example shows a popover appearing above and aligned to the right edge. ```rust use dioxus_primitives::{ContentAlign, ContentSide}; // ContentSide variants: Top, Right, Bottom, Left // ContentAlign variants: Start, Center, End // Example: popover appearing above, aligned to the right edge of the trigger use dioxus::prelude::*; use dioxus_primitives::popover::{PopoverContent, PopoverRoot, PopoverTrigger}; rsx! { PopoverRoot { open: true, PopoverTrigger { "Help" } PopoverContent { side: ContentSide::Top, align: ContentAlign::End, "Keyboard shortcut: Ctrl+H" } } } ``` -------------------------------- ### Implementing Portals in Dioxus Source: https://github.com/dioxuslabs/components/blob/main/complaints.md Shows how to use `PortalIn` and `PortalOut` to render component content in a different part of the DOM while maintaining its original scope and context. ```rust #[component] pub fn App() -> Element { let portal = use_portal(); rsx! { div { // ... nested stuff PortalIn { portal, // Children of PortalIn becomes children of PortalOut. div { h1 { "Alert Dialog!" } p { "alert!!" } } } } div { // ... other nested stuff PortalOut { portal } } } } ``` -------------------------------- ### Create a User Profile Popover with PopoverRoot Source: https://context7.com/dioxuslabs/components/llms.txt Utilize PopoverRoot, PopoverTrigger, and PopoverContent to display user information in a non-modal floating panel. Configure positioning with `side` and `align`. ```rust use dioxus::prelude::*; use dioxus_primitives::popover::{PopoverContent, PopoverRoot, PopoverTrigger}; use dioxus_primitives::ContentSide; #[component] fn UserCard() -> Element { let mut open = use_signal(|| false); rsx! { PopoverRoot { open: open(), on_open_change: move |v| open.set(v), is_modal: false, PopoverTrigger { "View profile" } PopoverContent { side: ContentSide::Bottom, padding: "1rem", h4 { margin: 0, "Jane Doe" } p { "jane@example.com" } button { onclick: move |_| open.set(false), "Close" } } } } } ``` -------------------------------- ### Run Unit Tests for Dioxus Primitives Source: https://github.com/dioxuslabs/components/blob/main/README.md Execute unit tests for the dioxus-primitives crate to ensure core component logic is sound. ```bash cargo test -p dioxus-primitives ``` -------------------------------- ### Implement a Delete Confirmation Dialog with DialogRoot Source: https://context7.com/dioxuslabs/components/llms.txt Use DialogRoot, DialogContent, DialogTitle, and DialogDescription to create a modal dialog for confirming user actions. The dialog manages its open state and traps focus. ```rust use dioxus::prelude::*; use dioxus_primitives::dialog::{DialogContent, DialogDescription, DialogRoot, DialogTitle}; #[component] fn DeleteConfirmDialog() -> Element { let mut open = use_signal(|| false); rsx! { button { onclick: move |_| open.set(true), "Delete account" } DialogRoot { open: open(), on_open_change: move |v| open.set(v), DialogContent { DialogTitle { "Delete your account?" } DialogDescription { "This action is permanent and cannot be undone." } div { button { onclick: move |_| open.set(false), "Cancel" } button { onclick: move |_| { // perform deletion... open.set(false); }, "Confirm Delete" } } } } } } ``` -------------------------------- ### Basic Color Picker Usage Source: https://github.com/dioxuslabs/components/blob/main/preview/src/components/color_picker/docs.md Demonstrates the basic structure of the ColorPicker component, including its required `color` and `on_color_change` props. The `on_color_change` callback receives the selected color in HSV format. ```rust ColorPicker { // The currently selected color in the color picker. color, on_color_change: move |c: Hsv| { // This callback is triggered when a color is selected in the popover. // The HSV parameter contains the selected color. }, // Optional label on the trigger button. label: "Pick", } ``` -------------------------------- ### Basic VirtualList Usage Source: https://github.com/dioxuslabs/components/blob/main/preview/src/components/virtual_list/docs.md Demonstrates the basic structure of the VirtualList component. Specify the total number of items, the buffer size for rows above and below the viewport, and a render callback function that receives the absolute index of the item to render. ```rust VirtualList { // Total number of items. count: 2000usize, // Render buffer (approximate row count) above and below viewport. buffer: 8usize, // Row renderer callback receives the absolute index. render_item: move |idx: usize| rsx! { article { key: "{idx}", "{rows[idx].title}" } }, } ``` -------------------------------- ### Run Dioxus Tests and Linting Source: https://context7.com/dioxuslabs/components/llms.txt Commands for running unit tests for dioxus-primitives, CSS linting, and Playwright end-to-end tests. ```sh # Run unit tests for dioxus-primitives cargo test -p dioxus-primitives # Run CSS linting cd preview && npm install && npx stylelint "src/**/*.css" # Run Playwright end-to-end tests cd playwright && npm install && npx playwright test ``` -------------------------------- ### Menubar Component Structure Source: https://github.com/dioxuslabs/components/blob/main/preview/src/components/menubar/docs.md Illustrates the basic structure of the Menubar component, including MenubarMenu, MenubarTrigger, MenubarContent, and MenubarItem. Use this to understand how to nest menu elements. ```rust Menubar { // The Menubar component wraps the entire menu bar and contains the individual menus in the order of their index. MenubarMenu { // The MenubarMenu contains the individual menus that can be opened. index: 0, // The menubar trigger is the element that will display the menu when activated. MenubarTrigger { // The content of the trigger button {children} } // The menubar content contains all the items that will be displayed in the menu when it is opened. MenubarContent { // Each menubar item represents an individual items in the menu. MenubarItem { // The value of the item which will be passed to the on_select callback when the item is selected. value: "", on_select: |value: String| { // This callback is triggered when the item is selected. // The value parameter contains the value of the selected item. }, } } } } ``` -------------------------------- ### Add Tooltip for Contextual Help with Tooltip Source: https://context7.com/dioxuslabs/components/llms.txt Implement Tooltip, TooltipTrigger, and TooltipContent to provide contextual help text on hover or focus. The trigger links to the content via `aria-describedby`. ```rust use dioxus::prelude::*; use dioxus_primitives::{ tooltip::{Tooltip, TooltipContent, TooltipTrigger}, ContentSide, }; #[component] fn SaveButton() -> Element { rsx! { Tooltip { TooltipTrigger { button { "💾 Save" } } TooltipContent { side: ContentSide::Top, "Saves your work (Ctrl+S)" } } } } ``` -------------------------------- ### SheetClose with Custom Element (`as` prop) Source: https://github.com/dioxuslabs/components/blob/main/preview/src/components/sheet/docs.md Shows how to use the `as` prop on `SheetClose` to render a custom element while retaining the sheet closing functionality. The default behavior renders a button. ```rust // Default: renders as