Scaffold: cache children with memo

This commit is contained in:
thislight 2024-11-25 15:24:13 +08:00
parent b1812392cb
commit 62a80ddce2
No known key found for this signature in database
GPG key ID: FCFE5192241CCD4E

View file

@ -2,6 +2,7 @@ import { createElementSize } from "@solid-primitives/resize-observer";
import {
JSX,
Show,
children,
createRenderEffect,
createSignal,
splitProps,
@ -21,8 +22,8 @@ type ScaffoldProps = ParentProps<
/**
* The passthrough props are passed to the content container.
*/
const Scaffold: Component<ScaffoldProps> = (props) => {
const [managed, rest] = splitProps(props, [
const Scaffold: Component<ScaffoldProps> = (oprops) => {
const [props, rest] = splitProps(oprops, [
"topbar",
"fab",
"bottom",
@ -34,9 +35,13 @@ const Scaffold: Component<ScaffoldProps> = (props) => {
const topbarSize = createElementSize(topbarElement);
const topbar = children(() => props.topbar)
const fab = children(() => props.fab)
const bottom = children(() => props.bottom)
return (
<div
class={`Scaffold ${managed.class || ""}`}
class={`Scaffold ${props.class || ""}`}
ref={(e) => {
createRenderEffect(() => {
e.style.setProperty(
@ -45,28 +50,28 @@ const Scaffold: Component<ScaffoldProps> = (props) => {
);
});
if (managed.ref) {
(managed.ref as (val: typeof e) => void)(e);
if (props.ref) {
(props.ref as (val: typeof e) => void)(e);
}
}}
{...rest}
>
<Show when={props.topbar}>
<Show when={topbar()}>
<div class="topbar" ref={setTopbarElement} role="presentation">
{props.topbar}
{topbar()}
</div>
</Show>
<Show when={props.fab}>
<Show when={fab()}>
<div class="fab-dock" role="presentation">
{props.fab}
{fab()}
</div>
</Show>
{managed.children}
{props.children}
<Show when={props.bottom}>
<Show when={bottom()}>
<div class="bottom-dock" role="presentation">
{props.bottom}
{bottom()}
</div>
</Show>
</div>