Setup
pnpm add @cailabs/components.layout <script>
import {
TFLayoutWrapper,
TFSidebar,
TFHeader,
TFContentWrapper
} from '@cailabs/components.layout';
import '@cailabs/components.layout/tf-layout.css';
</script> See Installation for peers and other segments.
Features
Responsive Sidebar: Collapsible navigation sidebar with menu items User Header: Contains user profile information, notifications, and sidebar toggle Notification System: Dropdown notification list with read/unread status Flexible Content Area: Main section that adapts to your application content Usage
The TF Layout is built using several interconnected components:
TFLayoutWrapper: The main container that structures the overall layout TFSidebar: Navigation sidebar with app branding and menu items TFContentWrapper: Container for the main content area TFHeader: Top header bar with user controls and notifications NotificationList: Component for displaying user notifications
Example Implementation
<script lang="ts">
import {
NotificationList,
TFContentWrapper,
TFHeader,
TFLayoutWrapper,
TFSidebar,
type NotificationItem
} from '$lib/index.js';
let { children } = $props();
let hideSidebar = $state(false);
export function fetchNotifications(): Promise<NotificationItem[]> {
return new Promise((resolve) => {
// Simulate API delay
setTimeout(() => {
resolve([
{
id: 1,
icon: 'basil:document-solid',
isRead: false,
time: '2 mins ago',
content: 'Your document has been approved',
sender: 'System'
},
{
id: 2,
icon: 'entypo:chat',
isRead: true,
time: '1 hour ago',
content: 'New message from support team',
sender: 'Support'
},
{
id: 3,
icon: 'basil:document-solid',
isRead: false,
time: '3 hours ago',
content: 'Invoice #1234 is ready',
sender: 'Billing'
},
{
id: 4,
icon: 'entypo:chat',
isRead: true,
time: 'Yesterday',
content: 'Your subscription will renew soon',
sender: 'Account'
},
{
id: 5,
icon: 'basil:document-solid',
isRead: false,
time: '2 days ago',
content: 'New policy update available',
sender: 'Admin'
}
]);
}, 800); // Simulate network delay
});
}
</script>
<TFLayoutWrapper>
{#snippet sidebar()}
<TFSidebar
appName="Teachers' Fund MIS"
appShortName="TF MIS"
logoUrl="https://mis.teachersfund.org.gh/_app/immutable/assets/logo.C3bie209.png"
homeUrl=""
menuItems={[
{ title: 'Home', icon: 'solar:home-bold-duotone', path: '/docs/layouts/tf/home' },
{ title: 'Users', icon: 'mage:users-fill', path: '/docs/layouts/tf/users' }
]}
{hideSidebar}
/>
{/snippet}
{#snippet content()}
<TFContentWrapper>
{#snippet topBar()}
<TFHeader
notificationCount={3}
bind:hideSidebar
title="Dummy App"
user={{
firstName: 'Theophilus',
lastName: 'Adusei',
initials: 'TA',
fullName: 'Theophilus Adusei',
role: 'Super Admin',
username: 'tkadusei@bitblueconsult.com'
}}
>
{#snippet notificationList()}
<NotificationList read={fetchNotifications} />
{/snippet}
</TFHeader>
{/snippet}
{@render children()}
</TFContentWrapper>
{/snippet}
</TFLayoutWrapper>