Files
ui/src/lib/internal/Child.svelte
T
Brandon WeesandJason Rasmussen 7f756355f5 chore: formatter use 2 spaces instead of tabs (#273)
* chore: formatter use 2 spaces instead of tabs

* chore: format

* chore: use defaults

* chore: 120 width

---------

Co-authored-by: Jason Rasmussen <jason@rasm.me>
2025-09-18 15:26:01 -04:00

29 lines
748 B
Svelte

<script lang="ts">
import { ChildKey } from '$lib/constants.js';
import type { ChildData } from '$lib/types.js';
import { withPrefix } from '$lib/utils.js';
import { getContext, type Snippet } from 'svelte';
type ContextType = {
register: (key: ChildKey, data: () => ChildData) => void;
};
type Props = {
for: ChildKey;
as: ChildKey;
class?: string;
children: Snippet;
};
const { for: key, as, children, class: className }: Props = $props();
const context = getContext<ContextType>(withPrefix(key));
const data = $derived({ snippet: children, class: className });
if (context) {
context.register(as, () => data);
} else {
console.log('Unable to find context for key:', key);
}
</script>