1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use InnerPopper;
use crate*;
use *;
/// A component showing the popper content in a portal.
///
/// ## Usage
///
/// When visible, the component will show its children in a portal attached to the body of the
/// document. The user has the responsibility to apply the styles and attributes. In order to apply
/// them, it is necessary to capture the state and apply it to the child components. It is also
/// necessary to provide a [`NodeRef`], which references the popper content, so that the calculation
/// works correctly.
///
/// ## Example
///
/// ```rust
/// use yew::prelude::*;
/// use popper_rs::prelude::*;
/// use popper_rs::yew::component::PortalPopper;
///
/// #[function_component(Example)]
/// fn example() -> Html {
/// /// The references
/// let button_ref = use_node_ref();
/// let tooltip_ref = use_node_ref();
///
/// // For activating the popper
/// let active = use_state_eq(|| false);
/// let onclick = use_callback(active.clone(), move |_, active| active.set(!**active));
///
/// // For passing the state
/// let state = use_state_eq(State::default);
/// let onstatechange = use_callback(state.clone(), |new_state, state| state.set(new_state));
///
/// html!(
/// <div>
/// <button
/// ref={button_ref.clone()}
/// class="button"
/// {onclick}
/// > { "Click me" } </button>
///
/// <PortalPopper
/// target={button_ref}
/// content={tooltip_ref.clone()}
/// visible={*active}
/// {onstatechange}
/// >
/// <div
/// ref={tooltip_ref}
/// data-show="true"
/// style={&state.styles.popper}
/// >
/// { "Tooltip content" }
/// <div style={&state.styles.arrow}></div>
/// </div>
/// </PortalPopper>
/// </div>
/// )
/// }
/// ```
///
/// For a complete example, see the `yew` example `component`.