Skip to content

Commit 26fd632

Browse files
feat(dioxus): add floating-ui-dioxus (#151)
1 parent 2efd362 commit 26fd632

28 files changed

+1856
-27
lines changed

Cargo.lock

Lines changed: 927 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ version = "0.4.1"
1919
cfg-if = "1.0.0"
2020
console_error_panic_hook = "0.1.7"
2121
console_log = "1.0.0"
22+
dioxus = "0.6.3"
2223
dyn_derive = "0.3.4"
2324
dyn_std = "0.3.3"
2425
floating-ui-core = { path = "./packages/core", version = "0.4.0" }
26+
floating-ui-dioxus = { path = "./packages/dioxus", version = "0.4.0" }
2527
floating-ui-dom = { path = "./packages/dom", version = "0.4.0" }
2628
floating-ui-leptos = { path = "./packages/leptos", version = "0.4.0" }
2729
floating-ui-utils = { path = "./packages/utils", version = "0.4.0" }

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,24 @@ Rust port of [Floating UI](https://floating-ui.com).
1515
Rust Floating UI is available for these Rust frameworks:
1616

1717
- [DOM](./packages/dom) ([`web-sys`](https://rustwasm.github.io/wasm-bindgen/web-sys/index.html))
18+
- [Dioxus](https://dioxuslabs.com/)
1819
- [Leptos](./packages/leptos)
1920
- [Yew](https://yew.rs/)
2021

21-
The following frameworks are under consideration:
22-
23-
- [Dioxus](https://dioxuslabs.com/)
24-
2522
## Examples
2623

2724
See [the Rust Floating UI book](https://floating-ui.rustforweb.org/) for examples.
2825

2926
Each framework has an implementations of the [Floating UI tutorial](https://floating-ui.com/docs/tutorial) as an example:
3027

3128
- [DOM](./packages/dom/example)
29+
- [Dioxus](./packages/dioxus/example)
3230
- [Leptos](./packages/leptos/example)
3331
- [Yew](./packages/yew/example)
3432

3533
Additionally, implementations of [Floating UI tests](https://github.com/floating-ui/floating-ui/tree/master/packages/dom/test) are more complex examples:
3634

35+
- [Dioxus](./packages/dioxus/tests)
3736
- [Leptos](./packages/leptos/tests)
3837
- [Yew](./packages/yew/tests)
3938

@@ -44,6 +43,7 @@ See [the Rust Floating UI book](https://floating-ui.rustforweb.org/) for documen
4443
Documentation for the crates is available on [Docs.rs](https://docs.rs/):
4544

4645
- [`floating-ui-core`](https://docs.rs/floating-ui-core/latest/floating_ui_core/)
46+
- [`floating-ui-dioxus`](https://docs.rs/floating-ui-dioxus/latest/floating_ui_dioxus/)
4747
- [`floating-ui-dom`](https://docs.rs/floating-ui-dom/latest/floating_ui_dom/)
4848
- [`floating-ui-leptos`](https://docs.rs/floating-ui-leptos/latest/floating_ui_leptos/)
4949
- [`floating-ui-utils`](https://docs.rs/floating-ui-utils/latest/floating_ui_utils/)

book/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- [Platform](./platform.md)
2020
- [Frameworks](./frameworks/README.md)
2121
- [DOM](./frameworks/dom.md)
22+
- [Dioxus](./frameworks/dioxus.md)
2223
- [Leptos](./frameworks/leptos.md)
2324
- [Yew](./frameworks/yew.md)
2425
- [Contributing]()

book/src/auto-update.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,27 @@ floating_el.remove();
6666
cleanup();
6767
```
6868

69+
{{#endtab }}
70+
{{#tab name="Dioxus" }}
71+
72+
If you're conditionally rendering the floating element (recommended), use the `while_elements_mounted` option:
73+
74+
```rust,ignore
75+
use floating_ui_dioxus::{use_auto_update, use_floating, UseFloatingOptions};
76+
77+
let auto_update = use_auto_update();
78+
79+
use_floating(
80+
reference_el,
81+
floating_el,
82+
UseFloatingOptions::default().while_elements_mounted((*(auto_update())).clone()),
83+
);
84+
```
85+
86+
`while_elements_mounted` automatically handles calling and cleaning up `auto_update` based on the presence of the reference and floating element.
87+
88+
See the documentation on [docs.rs](https://docs.rs/floating-ui-dioxus/latest/floating_ui_dioxus/#functions) for all alternatives of the `use_auto_update` hook.
89+
6990
{{#endtab }}
7091
{{#tab name="Leptos" }}
7192

book/src/compute-position.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ use floating_ui_dom::compute_position;
2424
- [View on docs.rs](https://docs.rs/floating-ui-dom/latest/floating_ui_dom/)
2525
- [View source](https://github.com/RustForWeb/floating-ui/tree/main/packages/dom)
2626

27+
{{#endtab }}
28+
{{#tab name="Dioxus" }}
29+
30+
<div class="warning">
31+
32+
**Non-framework API**
33+
34+
[`use_floating()`](./frameworks/dioxus.md) should be used instead with a framework. If you are using a base package, change the package with the package switcher above.
35+
36+
</div>
37+
2738
{{#endtab }}
2839
{{#tab name="Leptos" }}
2940

@@ -193,6 +204,17 @@ let cleanup = auto_update(reference_el, floating_el, Rc::new(|| {
193204
cleanup();
194205
```
195206

207+
{{#endtab }}
208+
{{#tab name="Dioxus" }}
209+
210+
<div class="warning">
211+
212+
**Non-framework API**
213+
214+
[`use_floating()`](./frameworks/leptos.md) should be used instead with a framework. If you are using a base package, change the package with the package switcher above.
215+
216+
</div>
217+
196218
{{#endtab }}
197219
{{#tab name="Leptos" }}
198220

book/src/frameworks/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
Rust Floating UI is available for the following frameworks:
44

55
- [DOM (`web-sys`)](./dom.md)
6+
- [Dioxus](./dioxus.md)
67
- [Leptos](./leptos.md)
78
- [Yew](./yew.md)

book/src/frameworks/dioxus.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Dioxus
2+
3+
This package provides [Dioxus](https://dioxuslabs.com/) bindings for `floating-ui-dom` - a library that provides anchor positioning for a floating element to position it next to a given reference element.
4+
5+
## Installation
6+
7+
```shell
8+
cargo add floating-ui-dioxus
9+
```
10+
11+
- [View on crates.io](https://crates.io/crates/floating-ui-dioxus)
12+
- [View on docs.rs](https://docs.rs/floating-ui-dioxus/latest/floating_ui_dioxus/)
13+
- [View source](https://github.com/RustForWeb/floating-ui/tree/main/packages/dioxus)
14+
15+
## Usage
16+
17+
TODO

book/src/introduction.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@ It also provides features to avoid collisions with the viewport, as absolute pos
1717
Rust Floating UI is available for the following frameworks:
1818

1919
- [DOM (`web-sys`)](https://rustwasm.github.io/wasm-bindgen/web-sys/index.html)
20+
- [Dioxus](https://dioxuslabs.com/)
2021
- [Leptos](https://leptos.dev/)
2122
- [Yew](https://yew.rs/)
2223

23-
The following frameworks are under consideration:
24-
25-
- [Dioxus](https://dioxuslabs.com/)
26-
2724
See [Frameworks](./frameworks/index.md) for documentation for each framework.
2825

2926
## Examples

book/src/middleware/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ compute_position(
3434
);
3535
```
3636

37+
{{#endtab }}
38+
{{#tab name="Dioxus" }}
39+
40+
```rust,ignore
41+
use_floating(
42+
reference_el,
43+
floating_el,
44+
UseFloatingOptions::default()
45+
.position(Placement::Right)
46+
.middleware(vec![]),
47+
);
48+
```
49+
3750
{{#endtab }}
3851
{{#tab name="Leptos" }}
3952

@@ -129,6 +142,21 @@ compute_position(
129142
);
130143
```
131144

145+
{{#endtab }}
146+
{{#tab name="Dioxus" }}
147+
148+
```rust,ignore
149+
use_floating(
150+
reference_el,
151+
floating_el,
152+
UseFloatingOptions::default()
153+
.position(Placement::Right)
154+
.middleware(vec![
155+
Box::new(ShiftByOnePixel::new())
156+
]),
157+
);
158+
```
159+
132160
{{#endtab }}
133161
{{#tab name="Leptos" }}
134162

@@ -261,6 +289,28 @@ if let Some(data) = middleware_data.get_as::<ShiftByOnePixelData>(SHIFT_BY_ONE_P
261289
}
262290
```
263291

292+
{{#endtab }}
293+
{{#tab name="Dioxus" }}
294+
295+
```rust,ignore
296+
let UseFloatingReturn {
297+
middleware_data,
298+
..
299+
} = use_floating(
300+
reference_el,
301+
floating_el,
302+
UseFloatingOptions::default()
303+
.position(Placement::Right)
304+
.middleware(vec![
305+
Box::new(ShiftByOnePixel::new())
306+
]),
307+
);
308+
309+
if let Some(data) = middleware_data.get_as::<ShiftByOnePixelData>(SHIFT_BY_ONE_PIXEL_NAME) {
310+
log::info!("{:#?}", data);
311+
}
312+
```
313+
264314
{{#endtab }}
265315
{{#tab name="Leptos" }}
266316

0 commit comments

Comments
 (0)