11use convert_case:: { Case , Casing } ;
22use floating_ui_leptos:: {
3- FallbackStrategy , Flip , FlipOptions , MiddlewareVec , Placement , Shift , ShiftOptions ,
4- UseFloatingOptions , UseFloatingReturn , use_floating,
3+ Alignment , CrossAxis , FallbackStrategy , Flip , FlipOptions , MiddlewareVec , Placement , Shift ,
4+ ShiftOptions , UseFloatingOptions , UseFloatingReturn , use_floating,
55} ;
66use leptos:: prelude:: * ;
77use leptos_node_ref:: AnyNodeRef ;
@@ -26,11 +26,13 @@ pub fn Flip() -> impl IntoView {
2626
2727 let ( placement, set_placement) = signal ( Placement :: Bottom ) ;
2828 let ( main_axis, set_main_axis) = signal ( true ) ;
29- let ( cross_axis, set_cross_axis) = signal ( true ) ;
29+ let ( cross_axis, set_cross_axis) = signal ( CrossAxis :: True ) ;
3030 let ( fallback_placements, set_fallback_placements) = signal ( FallbackPlacements :: None ) ;
3131 let ( fallback_strategy, set_fallback_strategy) = signal ( FallbackStrategy :: BestFit ) ;
3232 let ( flip_alignment, set_flip_alignment) = signal ( true ) ;
3333 let ( add_shift, set_add_shift) = signal ( false ) ;
34+ let ( fallback_axis_side_direction, set_fallback_axis_side_direction) =
35+ signal ( None :: < Alignment > ) ;
3436
3537 let UseFloatingReturn {
3638 x,
@@ -49,9 +51,10 @@ pub fn Flip() -> impl IntoView {
4951 . main_axis ( main_axis. get ( ) )
5052 . cross_axis ( cross_axis. get ( ) )
5153 . fallback_strategy ( fallback_strategy. get ( ) )
52- . flip_alignment ( flip_alignment. get ( ) ) ;
54+ . flip_alignment ( flip_alignment. get ( ) )
55+ . fallback_axis_side_direction ( Alignment :: End ) ;
5356
54- options = if add_shift. get ( ) {
57+ options = if add_shift. get ( ) && fallback_axis_side_direction . get ( ) . is_none ( ) {
5558 options. fallback_placements ( vec ! [ Placement :: Bottom ] )
5659 } else {
5760 match fallback_placements. get ( ) {
@@ -100,7 +103,8 @@ pub fn Flip() -> impl IntoView {
100103 style: position=move || format!( "{:?}" , strategy. get( ) ) . to_lowercase( )
101104 style: top=move || format!( "{}px" , y. get( ) )
102105 style: left=move || format!( "{}px" , x. get( ) )
103- style: width=move || if add_shift. get( ) { "400px" } else { Default :: default ( ) }
106+ style: width=move || if add_shift. get( ) { if fallback_axis_side_direction. get( ) . is_none( ) { "400px" } else { "200px" } } else { Default :: default ( ) }
107+ style: height=move || if add_shift. get( ) { if fallback_axis_side_direction. get( ) . is_none( ) { Default :: default ( ) } else { "50px" } } else { Default :: default ( ) }
104108 >
105109 Floating
106110 </div>
@@ -152,19 +156,19 @@ pub fn Flip() -> impl IntoView {
152156 <h2>crossAxis</h2>
153157 <div class="controls" >
154158 <For
155- each=|| [ true , false ]
156- key=|value| format!( "{value}" )
159+ each=|| [ CrossAxis :: True , CrossAxis :: False , CrossAxis :: Alignment ]
160+ key=|value| format!( "{value:? }" )
157161 children=move |value| view! {
158162 <button
159- data-testid=format!( "crossAxis-{}" , value)
163+ data-testid=format!( "crossAxis-{}" , format! ( "{ value:?}" ) . to_case ( Case :: Camel ) )
160164 style: background-color=move || if cross_axis. get( ) == value {
161165 "black"
162166 } else {
163167 ""
164168 }
165169 on: click=move |_| set_cross_axis. set( value)
166170 >
167- { format!( "{value}" ) }
171+ { format!( "{value:?}" ) . to_case ( Case :: Camel ) }
168172 </button>
169173 }
170174 />
@@ -261,5 +265,34 @@ pub fn Flip() -> impl IntoView {
261265 }
262266 />
263267 </div>
268+
269+ <h2>fallbackAxisSideDirection</h2>
270+ <div class="controls" >
271+ <For
272+ each=|| [ Some ( Alignment :: Start ) , Some ( Alignment :: End ) , None ]
273+ key=|value| format!( "{value:?}" )
274+ children=move |value| view! {
275+ <button
276+ data-testid=format!( "fallbackAxisSideDirection-{}" , match value {
277+ Some ( Alignment :: Start ) => "start" ,
278+ Some ( Alignment :: End ) => "end" ,
279+ None => "none"
280+ } )
281+ style: background-color=move || if fallback_axis_side_direction. get( ) == value {
282+ "black"
283+ } else {
284+ ""
285+ }
286+ on: click=move |_| set_fallback_axis_side_direction. set( value)
287+ >
288+ { match value {
289+ Some ( Alignment :: Start ) => "start" ,
290+ Some ( Alignment :: End ) => "end" ,
291+ None => "none"
292+ } }
293+ </button>
294+ }
295+ />
296+ </div>
264297 }
265298}
0 commit comments