|
| 1 | +# 🧬 Skeleton RS Dioxus Usage |
| 2 | + |
| 3 | +Adding Skeleton 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 **skeleton-rs** library to your dependencies by including it in your `Cargo.toml` file: |
| 8 | + |
| 9 | + ```sh |
| 10 | + cargo add skeleton-rs --features=dio |
| 11 | + ``` |
| 12 | + |
| 13 | +1. Import the `Skeleton` component into your Dioxus application. |
| 14 | + |
| 15 | +## 🛠️ Usage |
| 16 | + |
| 17 | +Incorporating Skeleton RS into your **Dioxus** application is straightforward. Follow these steps: |
| 18 | + |
| 19 | +1. Import the `Skeleton` component into your Dioxus project: |
| 20 | + |
| 21 | + ```rust |
| 22 | + use dioxus::prelude::*; |
| 23 | + use skeleton_rs::dioxus::Skeleton; |
| 24 | + use skeleton_rs::{Variant, Animation, Direction, Theme}; |
| 25 | + ``` |
| 26 | + |
| 27 | +1. Use the `Skeleton` component within your Dioxus application: |
| 28 | + |
| 29 | + ```rust |
| 30 | + use dioxus::prelude::*; |
| 31 | + use skeleton_rs::dioxus::Skeleton; |
| 32 | + use skeleton_rs::Variant; |
| 33 | + |
| 34 | + #[component] |
| 35 | + fn App() -> Element { |
| 36 | + rsx! { |
| 37 | + Skeleton { |
| 38 | + variant: Variant::Text, |
| 39 | + width: "100%", |
| 40 | + height: "1.2em", |
| 41 | + } |
| 42 | + } |
| 43 | + } |
| 44 | + ``` |
| 45 | + |
| 46 | +## 🔧 Props |
| 47 | + |
| 48 | +| Property | Type | Description | Default | |
| 49 | +| ------------ | ----------- | ---------------------------------------------------------------------- | ------------- | |
| 50 | +| `variant` | `Variant` | Visual variant: `Text`, `Circle`, `Rect`, etc. | `Text` | |
| 51 | +| `animation` | `Animation` | Animation style: `Pulse`, `Wave`, `None`. | `Pulse` | |
| 52 | +| `direction` | `Direction` | Animation direction: `LeftToRight`, `RightToLeft`, `TopToBottom`, etc. | `LeftToRight` | |
| 53 | +| `theme` | `Theme` | Theme for light/dark variants. | `Light` | |
| 54 | +| `show` | `bool` | Manually control visibility of the skeleton. | `false` | |
| 55 | +| `delay_ms` | `u32` | Delay before showing the skeleton in milliseconds. | `0` | |
| 56 | +| `infer_size` | `bool` | Infers width/height from child content if true. | `false` | |
| 57 | +| `responsive` | `bool` | Enables scaling for responsive layouts. | `false` | |
| 58 | +| `children` | `Element` | Content to wrap in skeleton loading. | `None` | |
| 59 | + |
| 60 | +### 🎨 Styling Props |
| 61 | + |
| 62 | +| Property | Type | Description | Default | |
| 63 | +| --------------- | -------------- | ---------------------------------- | -------- | |
| 64 | +| `width` | `&'static str` | Width of the skeleton block. | `"100%"` | |
| 65 | +| `height` | `&'static str` | Height of the skeleton block. | `"1em"` | |
| 66 | +| `font_size` | `Option<&str>` | Font size used for text variant. | `None` | |
| 67 | +| `border_radius` | `&'static str` | Border radius for rounded shapes. | `"4px"` | |
| 68 | +| `line_height` | `&'static str` | Line height of the skeleton block. | `"1"` | |
| 69 | +| `margin` | `&'static str` | External margin styling. | `""` | |
| 70 | +| `custom_style` | `&'static str` | Inline custom styles. | `""` | |
| 71 | + |
| 72 | +### ⚙️ Visibility Behavior |
| 73 | + |
| 74 | +| Property | Type | Description | Default | |
| 75 | +| -------------------- | ------ | ------------------------------------------------------------ | ------- | |
| 76 | +| `animate_on_hover` | `bool` | Starts animation on hover. | `false` | |
| 77 | +| `animate_on_focus` | `bool` | Starts animation on focus. | `false` | |
| 78 | +| `animate_on_active` | `bool` | Starts animation on active interaction (e.g., click). | `false` | |
| 79 | +| `animate_on_visible` | `bool` | Uses IntersectionObserver to trigger animation when in view. | `false` | |
| 80 | + |
| 81 | +### 📏 Layout Constraints |
| 82 | + |
| 83 | +| Property | Type | Description | Default | |
| 84 | +| ------------ | -------------- | --------------------------- | ------- | |
| 85 | +| `max_width` | `Option<&str>` | Max width of the skeleton. | `None` | |
| 86 | +| `min_width` | `Option<&str>` | Min width of the skeleton. | `None` | |
| 87 | +| `max_height` | `Option<&str>` | Max height of the skeleton. | `None` | |
| 88 | +| `min_height` | `Option<&str>` | Min height of the skeleton. | `None` | |
| 89 | + |
| 90 | +## 💡 Notes |
| 91 | + |
| 92 | +- The `Skeleton` component is ideal for loading states and placeholder UIs. |
| 93 | +- When `animate_on_visible` is enabled, `IntersectionObserver` is used to optimize performance. |
| 94 | +- Use the `show` prop to manually toggle visibility or let the component manage it. |
| 95 | +- Enable `infer_size` to make the skeleton size itself based on wrapped children. |
| 96 | +- For improved UX, use `delay_ms` to avoid flashing placeholders for fast-loading content. |
| 97 | +- Customize styles with `custom_style` and regular class/style props. |
0 commit comments