add image support to sidebar header

This commit is contained in:
Justin Edmund 2025-12-03 20:51:10 -08:00
parent 399480db9f
commit ee2e51affd
4 changed files with 29 additions and 3 deletions

View file

@ -84,7 +84,7 @@
class:scrollable={pane.scrollable !== false} class:scrollable={pane.scrollable !== false}
style:--pane-depth={depth} style:--pane-depth={depth}
> >
<SidebarHeader title={pane.title}> <SidebarHeader title={pane.title} image={pane.image}>
{#snippet leftAccessory()} {#snippet leftAccessory()}
{#if showBackButton} {#if showBackButton}
<Button <Button

View file

@ -6,13 +6,15 @@
interface Props { interface Props {
/** Title for the sidebar header */ /** Title for the sidebar header */
title: string title: string
/** Optional image URL to display next to the title */
image?: string
/** Left accessory content (e.g., close/back button) */ /** Left accessory content (e.g., close/back button) */
leftAccessory?: Snippet leftAccessory?: Snippet
/** Right accessory content (e.g., save/edit button) */ /** Right accessory content (e.g., save/edit button) */
rightAccessory?: Snippet rightAccessory?: Snippet
} }
const { title, leftAccessory, rightAccessory }: Props = $props() const { title, image, leftAccessory, rightAccessory }: Props = $props()
</script> </script>
<div class="sidebar-header"> <div class="sidebar-header">
@ -22,7 +24,12 @@
{/if} {/if}
</div> </div>
<h2 class="sidebar-title">{title}</h2> <div class="sidebar-title-container">
{#if image}
<img src={image} alt="" class="title-image" />
{/if}
<h2 class="sidebar-title">{title}</h2>
</div>
<div class="header-right"> <div class="header-right">
{#if rightAccessory} {#if rightAccessory}
@ -76,6 +83,21 @@
gap: $unit-half; gap: $unit-half;
} }
.sidebar-title-container {
display: flex;
align-items: center;
justify-content: center;
gap: $unit-half;
}
.title-image {
width: calc($unit * 3);
height: calc($unit * 3);
object-fit: contain;
border-radius: $item-corner-small;
flex-shrink: 0;
}
.sidebar-title { .sidebar-title {
margin: 0; margin: 0;
font-size: $font-regular; font-size: $font-regular;

View file

@ -31,6 +31,8 @@ export interface PaneConfig {
id: string id: string
/** Title displayed in the pane header */ /** Title displayed in the pane header */
title: string title: string
/** Optional image URL to display next to the title */
image?: string
/** Component to render in the pane */ /** Component to render in the pane */
component: Component<any, any, any> component: Component<any, any, any>
/** Props to pass to the component */ /** Props to pass to the component */

View file

@ -15,6 +15,7 @@ interface OpenWithComponentOptions {
saveLabel?: string saveLabel?: string
element?: ElementType element?: ElementType
onback?: () => void onback?: () => void
image?: string
} }
interface SidebarState { interface SidebarState {
@ -66,6 +67,7 @@ class SidebarStore {
const paneConfig: PaneConfig = { const paneConfig: PaneConfig = {
id: crypto.randomUUID(), id: crypto.randomUUID(),
title, title,
image: opts.image,
component, component,
props, props,
onback: opts.onback, onback: opts.onback,