|
2 | 2 |
|
3 | 3 | Displays content within a desired ratio. |
4 | 4 |
|
5 | | -{{#tabs global="framework" }} |
6 | | -{{#tab name="Leptos" }} |
| 5 | +{{#tabs global="framework"}} |
| 6 | +{{#tab name="Leptos"}} |
7 | 7 |
|
8 | 8 | ```toml,trunk |
9 | 9 | package = "radix-leptos-book-primitives" |
10 | 10 | features = ["aspect-ratio"] |
11 | 11 | files = ["src/aspect_ratio.rs"] |
12 | 12 | ``` |
13 | 13 |
|
14 | | -{{#endtab }} |
15 | | -{{#tab name="Yew" }} |
| 14 | +{{#endtab}} |
| 15 | +{{#tab name="Yew"}} |
16 | 16 |
|
17 | 17 | ```toml,trunk |
18 | 18 | package = "radix-yew-book-primitives" |
19 | 19 | features = ["aspect-ratio"] |
20 | 20 | files = ["src/aspect_ratio.rs"] |
21 | 21 | ``` |
22 | 22 |
|
23 | | -{{#endtab }} |
24 | | -{{#endtabs }} |
| 23 | +{{#endtab}} |
| 24 | +{{#endtabs}} |
25 | 25 |
|
26 | 26 | ## Features |
27 | 27 |
|
28 | | -- Accepts any custom ratio. |
| 28 | +- Accepts any custom ratio. |
29 | 29 |
|
30 | 30 | ## Installation |
31 | 31 |
|
32 | 32 | Install the component from your command line. |
33 | 33 |
|
34 | | -{{#tabs global="framework" }} |
35 | | -{{#tab name="Leptos" }} |
| 34 | +{{#tabs global="framework"}} |
| 35 | +{{#tab name="Leptos"}} |
36 | 36 |
|
37 | 37 | ```shell |
38 | 38 | cargo add radix-leptos-aspect-ratio |
39 | 39 | ``` |
40 | 40 |
|
41 | | -- [View on crates.io](https://crates.io/crates/radix-leptos-aspect-ratio) |
42 | | -- [View on docs.rs](https://docs.rs/radix-leptos-aspect-ratio/latest/radix_leptos_aspect_ratio/) |
43 | | -- [View source](https://github.com/RustForWeb/radix/tree/main/packages/primitives/leptos/aspect-ratio) |
| 41 | +- [View on crates.io](https://crates.io/crates/radix-leptos-aspect-ratio) |
| 42 | +- [View on docs.rs](https://docs.rs/radix-leptos-aspect-ratio/latest/radix_leptos_aspect_ratio/) |
| 43 | +- [View source](https://github.com/RustForWeb/radix/tree/main/packages/primitives/leptos/aspect-ratio) |
44 | 44 |
|
45 | | -{{#endtab }} |
46 | | -{{#tab name="Yew" }} |
| 45 | +{{#endtab}} |
| 46 | +{{#tab name="Yew"}} |
47 | 47 |
|
48 | 48 | ```shell |
49 | 49 | cargo add radix-yew-aspect-ratio |
50 | 50 | ``` |
51 | 51 |
|
52 | | -- [View on crates.io](https://crates.io/crates/radix-yew-aspect-ratio) |
53 | | -- [View on docs.rs](https://docs.rs/radix-yew-aspect-ratio/latest/radix_yew_aspect_ratio/) |
54 | | -- [View source](https://github.com/RustForWeb/radix/tree/main/packages/primitives/yew/aspect-ratio) |
| 52 | +- [View on crates.io](https://crates.io/crates/radix-yew-aspect-ratio) |
| 53 | +- [View on docs.rs](https://docs.rs/radix-yew-aspect-ratio/latest/radix_yew_aspect_ratio/) |
| 54 | +- [View source](https://github.com/RustForWeb/radix/tree/main/packages/primitives/yew/aspect-ratio) |
55 | 55 |
|
56 | | -{{#endtab }} |
57 | | -{{#endtabs }} |
| 56 | +{{#endtab}} |
| 57 | +{{#endtabs}} |
58 | 58 |
|
59 | 59 | ## Anatomy |
60 | 60 |
|
61 | | -Import the component. |
62 | | - |
63 | | -{{#tabs global="framework" }} |
64 | | -{{#tab name="Leptos" }} |
| 61 | +{{#tabs global="framework"}} |
| 62 | +{{#tab name="Leptos"}} |
65 | 63 |
|
66 | 64 | ```rust,ignore |
67 | 65 | use leptos::*; |
68 | | -use radix_leptos_aspect_ratio::*; |
| 66 | +use radix_leptos_aspect_ratio as AspectRatio; |
69 | 67 |
|
70 | 68 | #[component] |
71 | 69 | fn Anatomy() -> impl IntoView { |
72 | 70 | view! { |
73 | | - <AspectRatio /> |
| 71 | + <AspectRatio::Root ratio=16.0/9.0> |
| 72 | + <div>"Constrained within the 16:9 ratio!"</div> |
| 73 | + </AspectRatio::Root> |
74 | 74 | } |
75 | 75 | } |
76 | 76 | ``` |
77 | 77 |
|
78 | | -{{#endtab }} |
79 | | -{{#tab name="Yew" }} |
| 78 | +{{#endtab}} |
| 79 | +{{#tab name="Yew"}} |
80 | 80 |
|
81 | 81 | ```rust,ignore |
82 | 82 | use radix_yew_aspect_ratio::*; |
83 | | -use yew::prelude::::*; |
| 83 | +use yew::prelude::*; |
84 | 84 |
|
85 | 85 | #[function_component] |
86 | 86 | fn Anatomy() -> Html { |
87 | 87 | html! { |
88 | | - <AspectRatio /> |
| 88 | + <AspectRatio> |
| 89 | + {"Constrained within the desired ratio!"} |
| 90 | + </AspectRatio> |
89 | 91 | } |
90 | 92 | } |
91 | 93 | ``` |
92 | 94 |
|
93 | | -{{#endtab }} |
94 | | -{{#endtabs }} |
| 95 | +{{#endtab}} |
| 96 | +{{#endtabs}} |
95 | 97 |
|
96 | 98 | ## API Reference |
97 | 99 |
|
98 | 100 | ### Root |
99 | 101 |
|
100 | 102 | Contains the content you want to constrain to a given ratio. |
101 | 103 |
|
102 | | -{{#tabs global="framework" }} |
103 | | -{{#tab name="Leptos" }} |
| 104 | +{{#tabs global="framework"}} |
| 105 | +{{#tab name="Leptos"}} |
| 106 | + |
| 107 | +| Prop | Type | Default | |
| 108 | +|------------|-------------------|---------| |
| 109 | +| `as_child` | `MaybeProp<bool>` | `false` | |
| 110 | +| `ratio` | `MaybeProp<f64>` | `1.0` | |
| 111 | +| `node_ref` | `AnyNodeRef` | - | |
| 112 | + |
| 113 | +### Usage |
| 114 | + |
| 115 | +To use the `Root` alias for the `AspectRatio` component, import it and use `AspectRatio::Root` in your view. |
| 116 | + |
| 117 | +```rust,ignore |
| 118 | +use leptos::*; |
| 119 | +use radix_leptos_aspect_ratio as AspectRatio; |
| 120 | +
|
| 121 | +#[component] |
| 122 | +fn Example() -> impl IntoView { |
| 123 | + view! { |
| 124 | + <AspectRatio::Root ratio=4.0/3.0> |
| 125 | + <img src="path/to/image.jpg" alt="Example Image" /> |
| 126 | + </AspectRatio::Root> |
| 127 | + } |
| 128 | +} |
| 129 | +``` |
104 | 130 |
|
105 | | -| Prop | Type | Default | |
106 | | -| ------- | ---------------- | ------- | |
107 | | -| `ratio` | `MaybeProp<f64>` | `1.0` | |
| 131 | +{{#endtab}} |
| 132 | +{{#tab name="Yew"}} |
108 | 133 |
|
109 | | -{{#endtab }} |
110 | | -{{#tab name="Yew" }} |
| 134 | +<!-- TODO: Add or update Yew-specific props if needed --> |
111 | 135 |
|
112 | | -| Prop | Type | Default | |
113 | | -| ---------- | ----------------------------------------------- | ------- | |
114 | | -| `as_child` | `Option<Callback<AspectRatioChildProps, Html>>` | - | |
115 | | -| `ratio` | `f64` | `1.0` | |
| 136 | +| Prop | Type | Default | |
| 137 | +|---------|-------|---------| |
| 138 | +| `ratio` | `f64` | `1.0` | |
116 | 139 |
|
117 | | -{{#endtab }} |
118 | | -{{#endtabs }} |
| 140 | +{{#endtab}} |
| 141 | +{{#endtabs}} |
119 | 142 |
|
120 | 143 | ## See Also |
121 | 144 |
|
122 | | -- [Radix documentation](https://www.radix-ui.com/primitives/docs/components/aspect-ratio) |
| 145 | +- [Radix documentation](https://www.radix-ui.com/primitives/docs/components/aspect-ratio) |
| 146 | + |
| 147 | +``` |
0 commit comments