Skip to content

Commit 99b9c72

Browse files
author
geoffreygarrett
committed
Update Aspect Ratio to Leptos 0.7
1 parent fc8f7cd commit 99b9c72

File tree

2 files changed

+72
-49
lines changed

2 files changed

+72
-49
lines changed

Cargo.toml

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ members = [
1010
# -- Leptos Primitives (commented until they're upgraded) --
1111
# "packages/primitives/leptos/accessible-icon",
1212
# "packages/primitives/leptos/arrow",
13-
# "packages/primitives/leptos/aspect-ratio",
13+
"packages/primitives/leptos/aspect-ratio",
1414
# "packages/primitives/leptos/avatar",
1515
# "packages/primitives/leptos/checkbox",
1616
# "packages/primitives/leptos/collection",
@@ -82,13 +82,12 @@ yew = "0.21.0"
8282
yew-router = "0.18.0"
8383
yew-struct-component = "0.1.4"
8484
yew-style = "0.1.4"
85-
radix-leptos-primitive.version = "0.0.2"
8685

8786
# Subcrate packages (paths remain the same; you can comment out any subcrate not yet upgraded).
8887
# We centralize shared dependencies in [workspace.dependencies] for a single source of truth,
8988
# reducing duplication, preventing version drift, and keeping the Cargo.lock consistent.
9089
#radix-leptos-arrow.path = "./packages/primitives/leptos/arrow"
91-
#radix-leptos-aspect-ratio.path = "./packages/primitives/leptos/aspect-ratio"
90+
radix-leptos-aspect-ratio.path = "./packages/primitives/leptos/aspect-ratio"
9291
#radix-leptos-accessible-icon.path = "./packages/primitives/leptos/accessible-icon"
9392
#radix-leptos-avatar.path = "./packages/primitives/leptos/avatar"
9493
#radix-leptos-checkbox.path = "./packages/primitives/leptos/checkbox"
@@ -124,4 +123,3 @@ radix-leptos-primitive.path = "./packages/primitives/leptos/primitive"
124123
yew = { git = "https://github.com/RustForWeb/yew.git", branch = "feature/use-composed-ref" }
125124
yew-router = { git = "https://github.com/RustForWeb/yew.git", branch = "feature/use-composed-ref" }
126125
leptos-node-ref = { git = "https://github.com/geoffreygarrett/leptos-utils", branch = "feature/any-node-ref" }
127-
radix-leptos-primitive = { git = "https://github.com/geoffreygarrett/radix", branch = "update/leptos-0.7-primitive" }

book/src/primitives/components/aspect-ratio.md

+70-45
Original file line numberDiff line numberDiff line change
@@ -2,121 +2,146 @@
22

33
Displays content within a desired ratio.
44

5-
{{#tabs global="framework" }}
6-
{{#tab name="Leptos" }}
5+
{{#tabs global="framework"}}
6+
{{#tab name="Leptos"}}
77

88
```toml,trunk
99
package = "radix-leptos-book-primitives"
1010
features = ["aspect-ratio"]
1111
files = ["src/aspect_ratio.rs"]
1212
```
1313

14-
{{#endtab }}
15-
{{#tab name="Yew" }}
14+
{{#endtab}}
15+
{{#tab name="Yew"}}
1616

1717
```toml,trunk
1818
package = "radix-yew-book-primitives"
1919
features = ["aspect-ratio"]
2020
files = ["src/aspect_ratio.rs"]
2121
```
2222

23-
{{#endtab }}
24-
{{#endtabs }}
23+
{{#endtab}}
24+
{{#endtabs}}
2525

2626
## Features
2727

28-
- Accepts any custom ratio.
28+
- Accepts any custom ratio.
2929

3030
## Installation
3131

3232
Install the component from your command line.
3333

34-
{{#tabs global="framework" }}
35-
{{#tab name="Leptos" }}
34+
{{#tabs global="framework"}}
35+
{{#tab name="Leptos"}}
3636

3737
```shell
3838
cargo add radix-leptos-aspect-ratio
3939
```
4040

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)
4444

45-
{{#endtab }}
46-
{{#tab name="Yew" }}
45+
{{#endtab}}
46+
{{#tab name="Yew"}}
4747

4848
```shell
4949
cargo add radix-yew-aspect-ratio
5050
```
5151

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)
5555

56-
{{#endtab }}
57-
{{#endtabs }}
56+
{{#endtab}}
57+
{{#endtabs}}
5858

5959
## Anatomy
6060

61-
Import the component.
62-
63-
{{#tabs global="framework" }}
64-
{{#tab name="Leptos" }}
61+
{{#tabs global="framework"}}
62+
{{#tab name="Leptos"}}
6563

6664
```rust,ignore
6765
use leptos::*;
68-
use radix_leptos_aspect_ratio::*;
66+
use radix_leptos_aspect_ratio as AspectRatio;
6967
7068
#[component]
7169
fn Anatomy() -> impl IntoView {
7270
view! {
73-
<AspectRatio />
71+
<AspectRatio::Root ratio=16.0/9.0>
72+
<div>"Constrained within the 16:9 ratio!"</div>
73+
</AspectRatio::Root>
7474
}
7575
}
7676
```
7777

78-
{{#endtab }}
79-
{{#tab name="Yew" }}
78+
{{#endtab}}
79+
{{#tab name="Yew"}}
8080

8181
```rust,ignore
8282
use radix_yew_aspect_ratio::*;
83-
use yew::prelude::::*;
83+
use yew::prelude::*;
8484
8585
#[function_component]
8686
fn Anatomy() -> Html {
8787
html! {
88-
<AspectRatio />
88+
<AspectRatio>
89+
{"Constrained within the desired ratio!"}
90+
</AspectRatio>
8991
}
9092
}
9193
```
9294

93-
{{#endtab }}
94-
{{#endtabs }}
95+
{{#endtab}}
96+
{{#endtabs}}
9597

9698
## API Reference
9799

98100
### Root
99101

100102
Contains the content you want to constrain to a given ratio.
101103

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+
```
104130

105-
| Prop | Type | Default |
106-
| ------- | ---------------- | ------- |
107-
| `ratio` | `MaybeProp<f64>` | `1.0` |
131+
{{#endtab}}
132+
{{#tab name="Yew"}}
108133

109-
{{#endtab }}
110-
{{#tab name="Yew" }}
134+
<!-- TODO: Add or update Yew-specific props if needed -->
111135

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` |
116139

117-
{{#endtab }}
118-
{{#endtabs }}
140+
{{#endtab}}
141+
{{#endtabs}}
119142

120143
## See Also
121144

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

Comments
 (0)