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