INIT
This commit is contained in:
+38
@@ -0,0 +1,38 @@
|
||||
<script lang="ts">
|
||||
import { boxWith, mergeProps } from "svelte-toolbelt";
|
||||
import type { AspectRatioRootProps } from "../types.js";
|
||||
import { AspectRatioRootState } from "../aspect-ratio.svelte.js";
|
||||
import { createId } from "../../../internal/create-id.js";
|
||||
|
||||
const uid = $props.id();
|
||||
|
||||
let {
|
||||
ref = $bindable(null),
|
||||
id = createId(uid),
|
||||
ratio = 1,
|
||||
children,
|
||||
child,
|
||||
...restProps
|
||||
}: AspectRatioRootProps = $props();
|
||||
|
||||
const rootState = AspectRatioRootState.create({
|
||||
id: boxWith(() => id),
|
||||
ref: boxWith(
|
||||
() => ref,
|
||||
(v) => (ref = v)
|
||||
),
|
||||
ratio: boxWith(() => ratio),
|
||||
});
|
||||
|
||||
const mergedProps = $derived(mergeProps(restProps, rootState.props));
|
||||
</script>
|
||||
|
||||
<div style:position="relative" style:width="100%" style:padding-bottom="{ratio ? 100 / ratio : 0}%">
|
||||
{#if child}
|
||||
{@render child({ props: mergedProps })}
|
||||
{:else}
|
||||
<div {...mergedProps}>
|
||||
{@render children?.()}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import type { AspectRatioRootProps } from "../types.js";
|
||||
declare const AspectRatio: import("svelte").Component<AspectRatioRootProps, {}, "ref">;
|
||||
type AspectRatio = ReturnType<typeof AspectRatio>;
|
||||
export default AspectRatio;
|
||||
Reference in New Issue
Block a user