>): JSX.Element => {
+ const Wrapper = asChild ? Slot : 'div';
+ const customStyle: React.CSSProperties = React.useMemo(
() => ({
paddingTop: `calc(100% * (1 / ${ratio}))`,
- ...style,
+ ...props.style,
}),
- [ratio, style]
+ [ratio, props.style]
);
- if (Children.count(children) > 1) {
- throw new Error('AspectRatio component expects exactly one child element.');
- }
return (
-
- {Children.only(children)}
-
+ {React.Children.only(children)}
+
);
-});
-
-AspectRatio.displayName = 'AspectRatio';
+};