|
| 1 | +# 🧬 Browser RS Dioxus Usage |
| 2 | + |
| 3 | +Adding Browser RS to your project is simple: |
| 4 | + |
| 5 | +1. Make sure your project is set up with **Dioxus**. Refer to the [Dioxus Getting Started Guide](https://dioxuslabs.com/learn/0.6/getting_started) for setup instructions. |
| 6 | + |
| 7 | +1. Add the **browser-rs** library to your dependencies by including it in your `Cargo.toml` file: |
| 8 | + |
| 9 | + ```sh |
| 10 | + cargo add browser-rs --features=dio |
| 11 | + ``` |
| 12 | + |
| 13 | +1. Import the `BrowserFrame` component into your Dioxus application to simulate a browser window with rich customization. |
| 14 | + |
| 15 | +## 🛠️ Usage |
| 16 | + |
| 17 | +Follow these steps to integrate the `BrowserFrame` into your Dioxus application: |
| 18 | + |
| 19 | +### Step 1: Import the Required Components |
| 20 | + |
| 21 | +Import the `BrowserFrame` component and any required Dioxus types: |
| 22 | + |
| 23 | +```rust |
| 24 | +use dioxus::prelude::*; |
| 25 | +use browser_rs::dioxus::BrowserFrame; |
| 26 | +``` |
| 27 | + |
| 28 | +### Step 2: Basic Implementation |
| 29 | + |
| 30 | +Use the `BrowserFrame` in your app to render content inside a simulated browser window: |
| 31 | + |
| 32 | +```rust |
| 33 | +use dioxus::prelude::*; |
| 34 | +use browser_rs::dioxus::BrowserFrame; |
| 35 | + |
| 36 | + |
| 37 | +fn app() -> Element { |
| 38 | + let on_close = Callback::new(|_| log::info!("Browser closed")); |
| 39 | + |
| 40 | + rsx! { |
| 41 | + BrowserFrame { |
| 42 | + url: "https://opensass.org", |
| 43 | + on_close: on_close, |
| 44 | + children: rsx! { |
| 45 | + p { "Your embedded content here." } |
| 46 | + } |
| 47 | + } |
| 48 | + } |
| 49 | +} |
| 50 | +``` |
| 51 | + |
| 52 | +### Step 3: Customize the BrowserFrame |
| 53 | + |
| 54 | +You can customize the appearance and behavior of the browser frame using various props: |
| 55 | + |
| 56 | +```rust |
| 57 | +use dioxus::prelude::*; |
| 58 | +use browser_rs::dioxus::BrowserFrame; |
| 59 | + |
| 60 | + |
| 61 | +fn app() -> Element { |
| 62 | + let custom_button = rsx! { |
| 63 | + button { "Custom Button" } |
| 64 | + }; |
| 65 | + |
| 66 | + rsx! { |
| 67 | + BrowserFrame { |
| 68 | + url: "https://opensass.org", |
| 69 | + class: "rounded-xl shadow-xl", |
| 70 | + input_class: "bg-gray-200 text-gray-900", |
| 71 | + container_class: "flex-1 mx-4", |
| 72 | + custom_buttons: vec![custom_button], |
| 73 | + on_close: Callback::new(|_| log::info!("Closed")), |
| 74 | + children: rsx! { |
| 75 | + p { "Customized browser frame!" } |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | +} |
| 80 | +``` |
| 81 | + |
| 82 | +### Step 4: Handling Events and Interactions |
| 83 | + |
| 84 | +Use event handlers to manage user interactions, such as closing or minimizing the browser window: |
| 85 | + |
| 86 | +```rust |
| 87 | +use dioxus::prelude::*; |
| 88 | +use browser_rs::dioxus::BrowserFrame; |
| 89 | + |
| 90 | + |
| 91 | +fn app() -> Element { |
| 92 | + rsx! { |
| 93 | + BrowserFrame { |
| 94 | + url: "https://opensass.org", |
| 95 | + on_close: Callback::new(|_| log::info!("Closed")), |
| 96 | + on_minimize: Callback::new(|_| log::info!("Minimized")), |
| 97 | + on_maximize: Callback::new(|_| log::info!("Maximized")), |
| 98 | + children: rsx! { |
| 99 | + p { "Interactive browser frame." } |
| 100 | + } |
| 101 | + } |
| 102 | + } |
| 103 | +} |
| 104 | +``` |
| 105 | + |
| 106 | +## 🔧 Props |
| 107 | + |
| 108 | +### `BrowserFrameProps` Props |
| 109 | + |
| 110 | +#### Main Props |
| 111 | + |
| 112 | +| Property | Type | Description | Default | |
| 113 | +| ------------------ | --------------------------------- | ------------------------------------------------------------ | ------------------------------ | |
| 114 | +| `children` | `Element` | Child elements rendered inside the browser frame. | `{}` | |
| 115 | +| `url` | `String` | The URL displayed in the address bar and used in the iframe. | `""` | |
| 116 | +| `placeholder` | `&'static str` | Placeholder text shown in the address bar. | `""` | |
| 117 | +| `on_url_change` | `Option<EventHandler<FormEvent>>` | Event handler for when the address bar URL changes. | `None` | |
| 118 | +| `on_close` | `EventHandler<()>` | Event handler for when the close button is clicked. | No-op | |
| 119 | +| `on_minimize` | `EventHandler<()>` | Event handler for when the minimize button is clicked. | No-op | |
| 120 | +| `on_maximize` | `EventHandler<()>` | Event handler for when the maximize button is clicked. | No-op | |
| 121 | +| `show_controls` | `bool` | Whether to show control buttons (close, minimize, maximize). | `true` | |
| 122 | +| `show_address_bar` | `bool` | Whether to show the address bar. | `true` | |
| 123 | +| `read_only` | `bool` | Whether the address bar is read-only. | `false` | |
| 124 | +| `size` | `Size` | Size of the browser frame container. | `Size::default()` | |
| 125 | +| `variant` | `Variant` | Display variant for the frame (e.g., Tabs, Plain). | `Variant::default()` | |
| 126 | +| `custom_buttons` | `Vec<Element>` | Custom buttons displayed in the top bar. | `[]` | |
| 127 | +| `class` | `&'static str` | CSS class for the outermost container. | `"rounded-lg..."` | |
| 128 | +| `frame_class` | `&'static str` | CSS class for the browser frame. | `""` | |
| 129 | +| `style` | `&'static str` | Inline styles for the outer container. | `""` | |
| 130 | +| `id` | `&'static str` | HTML id attribute for the browser container. | `""` | |
| 131 | +| `aria_label` | `&'static str` | ARIA label for accessibility. | `"Browser window"` | |
| 132 | +| `aria_describedby` | `&'static str` | ARIA description for additional accessibility context. | `""` | |
| 133 | +| `container_class` | `&'static str` | Additional CSS class for the address bar container. | `""` | |
| 134 | +| `input_class` | `&'static str` | CSS class for the address bar input element. | `"text-black dark:text-white"` | |
| 135 | + |
| 136 | +#### Behavioral & Style Props |
| 137 | + |
| 138 | +| Property | Type | Description | Default | |
| 139 | +| ---------------------------- | -------------- | ----------------------------------------------------------------- | ---------------------------- | |
| 140 | +| `refresh_button_style` | `&'static str` | Inline style for the refresh button. | `"position: absolute; ...;"` | |
| 141 | +| `refresh_button_aria_label` | `&'static str` | ARIA label for the refresh button. | `"Refresh"` | |
| 142 | +| `icon_button_style` | `&'static str` | Shared inline style for icon buttons (close, minimize, maximize). | `"padding: 4px; ...;"` | |
| 143 | +| `address_wrapper_base_style` | `&'static str` | Inline style for the wrapper around the address bar. | `"flex: 1; ...;"` | |
| 144 | +| `header_base_style` | `&'static str` | Inline style for the header container (controls and address bar). | `"display: flex; ...;"` | |
| 145 | + |
| 146 | +#### Control Button Props |
| 147 | + |
| 148 | +Each control button (close, minimize, maximize) has customizable events and styles: |
| 149 | + |
| 150 | +| Property | Type | Description | Default | |
| 151 | +| --------------------- | -------------------------- | -------------------------------------------------------- | ------- | |
| 152 | +| `on_close_mouse_over` | `EventHandler<()>` | Mouse over event for close button. | No-op | |
| 153 | +| `on_close_mouse_out` | `EventHandler<()>` | Mouse out event for close button. | No-op | |
| 154 | +| `on_close_focus` | `EventHandler<FocusEvent>` | Focus event for close button. | No-op | |
| 155 | +| `on_close_blur` | `EventHandler<FocusEvent>` | Blur event for close button. | No-op | |
| 156 | +| `close_class` | `&'static str` | CSS class for the close button. | `""` | |
| 157 | +| ... | ... | _Similar props exist for minimize and maximize buttons._ | | |
| 158 | + |
| 159 | +#### Additional Custom Button Props |
| 160 | + |
| 161 | +Props are also available for share, tabs, and more buttons: |
| 162 | + |
| 163 | +| Property | Type | Description | Default | |
| 164 | +| -------------------- | ------------------ | ------------------------------------------------ | ------- | |
| 165 | +| `share_button_style` | `&'static str` | Inline style for the share button. | `""` | |
| 166 | +| `share_onclick` | `EventHandler<()>` | Click event for the share button. | No-op | |
| 167 | +| ... | ... | _Similar props exist for tabs and more buttons._ | | |
| 168 | + |
| 169 | +## 💡 Notes |
| 170 | + |
| 171 | +1. **Accessible**: All elements support ARIA labels, roles, and keyboard navigation (`Escape` triggers close). |
| 172 | + |
| 173 | +1. **Dark Mode Ready**: Default styles are compatible with Tailwind's dark theme classes. |
| 174 | + |
| 175 | +1. **Customizable Controls**: All button elements (close, minimize, maximize, refresh, tabs, share, more) support individual style, label, and event customization. |
| 176 | + |
| 177 | +1. **Component Structure**: Internally splits into header and content subcomponents (`BrowserHeader`, `BrowserContent`) for modular control. |
| 178 | + |
| 179 | +1. **Use Anywhere**: Can be used to wrap iframes, widgets, editors, or any arbitrary HTML/RSX content. |
0 commit comments