Module dioxus

Source
Available on crate feature dio only.
Expand description

§🧬 Browser RS Dioxus Usage

Adding Browser RS to your project is simple:

  1. Make sure your project is set up with Dioxus. Refer to the Dioxus Getting Started Guide for setup instructions.

  2. Add the browser-rs library to your dependencies by including it in your Cargo.toml file:

    cargo add browser-rs --features=dio
  3. Import the BrowserFrame component into your Dioxus application to simulate a browser window with rich customization.

§🛠️ Usage

Follow these steps to integrate the BrowserFrame into your Dioxus application:

§Step 1: Import the Required Components

Import the BrowserFrame component and any required Dioxus types:

use dioxus::prelude::*;
use browser_rs::dioxus::BrowserFrame;

§Step 2: Basic Implementation

Use the BrowserFrame in your app to render content inside a simulated browser window:

use dioxus::prelude::*;
use browser_rs::dioxus::BrowserFrame;


fn app() -> Element {
    let on_close = Callback::new(|_| log::info!("Browser closed"));

    rsx! {
        BrowserFrame {
            url: "https://opensass.org",
            on_close: on_close,
            children: rsx! {
                p { "Your embedded content here." }
            }
        }
    }
}

§Step 3: Customize the BrowserFrame

You can customize the appearance and behavior of the browser frame using various props:

use dioxus::prelude::*;
use browser_rs::dioxus::BrowserFrame;


fn app() -> Element {
    let custom_button = rsx! {
        button { "Custom Button" }
    };

    rsx! {
        BrowserFrame {
            url: "https://opensass.org",
            class: "rounded-xl shadow-xl",
            input_class: "bg-gray-200 text-gray-900",
            container_class: "flex-1 mx-4",
            custom_buttons: vec![custom_button],
            on_close: Callback::new(|_| log::info!("Closed")),
            children: rsx! {
                p { "Customized browser frame!" }
            }
        }
    }
}

§Step 4: Handling Events and Interactions

Use event handlers to manage user interactions, such as closing or minimizing the browser window:

use dioxus::prelude::*;
use browser_rs::dioxus::BrowserFrame;


fn app() -> Element {
    rsx! {
        BrowserFrame {
            url: "https://opensass.org",
            on_close: Callback::new(|_| log::info!("Closed")),
            on_minimize: Callback::new(|_| log::info!("Minimized")),
            on_maximize: Callback::new(|_| log::info!("Maximized")),
            children: rsx! {
                p { "Interactive browser frame." }
            }
        }
    }
}

§🔧 Props

§BrowserFrameProps Props

§Main Props
PropertyTypeDescriptionDefault
childrenElementChild elements rendered inside the browser frame.{}
urlStringThe URL displayed in the address bar and used in the iframe.""
placeholder&'static strPlaceholder text shown in the address bar.""
on_url_changeOption<EventHandler<FormEvent>>Event handler for when the address bar URL changes.None
on_closeEventHandler<()>Event handler for when the close button is clicked.No-op
on_minimizeEventHandler<()>Event handler for when the minimize button is clicked.No-op
on_maximizeEventHandler<()>Event handler for when the maximize button is clicked.No-op
show_controlsboolWhether to show control buttons (close, minimize, maximize).true
show_address_barboolWhether to show the address bar.true
read_onlyboolWhether the address bar is read-only.false
sizeSizeSize of the browser frame container.Size::default()
variantVariantDisplay variant for the frame (e.g., Tabs, Plain).Variant::default()
custom_buttonsVec<Element>Custom buttons displayed in the top bar.[]
class&'static strCSS class for the outermost container."rounded-lg..."
frame_class&'static strCSS class for the browser frame.""
style&'static strInline styles for the outer container.""
id&'static strHTML id attribute for the browser container.""
aria_label&'static strARIA label for accessibility."Browser window"
aria_describedby&'static strARIA description for additional accessibility context.""
container_class&'static strAdditional CSS class for the address bar container.""
input_class&'static strCSS class for the address bar input element."text-black dark:text-white"
§Behavioral & Style Props
PropertyTypeDescriptionDefault
refresh_button_style&'static strInline style for the refresh button."position: absolute; ...;"
refresh_button_aria_label&'static strARIA label for the refresh button."Refresh"
icon_button_style&'static strShared inline style for icon buttons (close, minimize, maximize)."padding: 4px; ...;"
address_wrapper_base_style&'static strInline style for the wrapper around the address bar."flex: 1; ...;"
header_base_style&'static strInline style for the header container (controls and address bar)."display: flex; ...;"
§Control Button Props

Each control button (close, minimize, maximize) has customizable events and styles:

PropertyTypeDescriptionDefault
on_close_mouse_overEventHandler<()>Mouse over event for close button.No-op
on_close_mouse_outEventHandler<()>Mouse out event for close button.No-op
on_close_focusEventHandler<FocusEvent>Focus event for close button.No-op
on_close_blurEventHandler<FocusEvent>Blur event for close button.No-op
close_class&'static strCSS class for the close button.""
Similar props exist for minimize and maximize buttons.
§Additional Custom Button Props

Props are also available for share, tabs, and more buttons:

PropertyTypeDescriptionDefault
share_button_style&'static strInline style for the share button.""
share_onclickEventHandler<()>Click event for the share button.No-op
Similar props exist for tabs and more buttons.

§💡 Notes

  1. Accessible: All elements support ARIA labels, roles, and keyboard navigation (Escape triggers close).

  2. Dark Mode Ready: Default styles are compatible with Tailwind’s dark theme classes.

  3. Customizable Controls: All button elements (close, minimize, maximize, refresh, tabs, share, more) support individual style, label, and event customization.

  4. Component Structure: Internally splits into header and content subcomponents (BrowserHeader, BrowserContent) for modular control.

  5. Use Anywhere: Can be used to wrap iframes, widgets, editors, or any arbitrary HTML/RSX content.

Structs§

AddressBarProps
BrowserContentProps
BrowserControlsProps
BrowserFrameProps
Properties for the BrowserFrame component.
BrowserHeaderProps
ControlButtonProps
KeyboardNavigationOptions

Functions§

AddressBar
BrowserContent
BrowserControls
BrowserFrame
BrowserFrame Component
BrowserHeader
ControlButton
use_keyboard