1- use leptos:: { prelude:: * , html} ;
1+ use leptos:: { prelude:: * , html, attribute_interceptor :: AttributeInterceptor } ;
22use radix_leptos_primitive:: Primitive ;
33use leptos_node_ref:: AnyNodeRef ;
44
@@ -15,19 +15,19 @@ const NAME: &'static str = "AspectRatio";
1515pub fn AspectRatio (
1616 /// Children passed to the AspectRatio component
1717 children : TypedChildrenFn < impl IntoView + ' static > ,
18-
1918 /// Change the default rendered element for the one passed as a child
2019 #[ prop( into, optional, default = false . into( ) ) ]
2120 as_child : MaybeProp < bool > ,
22-
2321 /// The desired ratio when rendering the content (e.g., 16/9). Defaults to 1.0 if not specified.
2422 #[ prop( into, optional, default = DEFAULT_RATIO . into( ) ) ]
2523 ratio : MaybeProp < f64 > ,
26-
2724 /// Reference to the underlying DOM node
2825 #[ prop( into, optional) ]
2926 node_ref : AnyNodeRef ,
3027) -> impl IntoView {
28+ // attribute interceptor incurs this requirement
29+ let children = StoredValue :: new ( children. into_inner ( ) ) ;
30+
3131 // calculates the percent-based padding for the aspect ratio
3232 let padding_bottom = Signal :: derive ( move || {
3333 100.0
@@ -42,38 +42,39 @@ pub fn AspectRatio(
4242 leptos:: logging:: log!( "[{NAME}] ratio: {:?}" , ratio. get( ) ) ;
4343 leptos:: logging:: log!( "[{NAME}] as_child: {:?}" , as_child. get( ) ) ;
4444 leptos:: logging:: log!( "[{NAME}] node_ref: {:?}" , node_ref. get( ) ) ;
45+ leptos:: logging:: log!( "[{NAME}] padding_bottom: {:?}" , padding_bottom. get( ) ) ;
4546 } ) ;
4647
4748 view ! {
48- // ensures inner element is contained
49- <div
50- style: position="relative"
51- // ensures padding bottom trick works
52- style: width="100%"
53- style: padding-bottom=move || format!( "{}%" , padding_bottom. get( ) )
54- data-radix-aspect-ratio-wrapper=""
55- >
56- <Primitive
57- // ensures children expand to fill the ratio
58- element=html:: div
59- as_child=as_child
60- node_ref=node_ref
61- children=children
62- style: position="absolute"
63- style: top="0"
64- style: right="0"
65- style: bottom="0"
66- style: left="0"
67- />
68- </div>
49+ // replicate the radix react spread props
50+ <AttributeInterceptor let : attrs>
51+ // ensures inner element is contained
52+ <div
53+ style: position="relative"
54+ // ensures padding bottom trick works
55+ style: width="100%"
56+ style: padding-bottom=move || format!( "{}%" , padding_bottom. get( ) )
57+ data-radix-aspect-ratio-wrapper=""
58+ >
59+ <Primitive
60+ // ensures children expand to fill the ratio
61+ element={ html:: div}
62+ as_child={ as_child}
63+ node_ref={ node_ref}
64+ { ..attrs}
65+ style: position="absolute"
66+ style: top="0"
67+ style: right="0"
68+ style: bottom="0"
69+ style: left="0"
70+ >
71+ { children. with_value( |children| children( ) ) }
72+ </Primitive >
73+ </div>
74+ </AttributeInterceptor >
6975 }
7076}
7177
72- /* -------------------------------------------------------------------------------------------------
73- * Primitive re-exports
74- * -----------------------------------------------------------------------------------------------*/
78+ /* -----------------------------------------------------------------------------------------------*/
7579
76- pub mod primitive {
77- pub use super :: * ;
78- pub use AspectRatio as Root ;
79- }
80+ pub use AspectRatio as Root ;
0 commit comments