# Layout — SvelteKit UI

Package: sveltekit-ui 1.1.94

Page: https://www.sveltekit-ui.com/components/layout

Category: Foundations

manages a high-level app layout with nav bar, optional full navigation panel, confetti effects, dark theme toggling, and more

Public component import: `Layout`

Public manager import: `create_layout_manager`

## Usage

```svelte
<script>
  // Import the shared stylesheet once in your application's root layout.
  import "sveltekit-ui/style.css"
  import { Layout, create_layout_manager, Button, create_button_manager } from "sveltekit-ui"

  const manager = create_layout_manager({
    is_dark_theme: false,
    is_show_hamburger: true,
  })

  const projects_button = create_button_manager({ text: "Projects", href: "#projects", type: "plain" })
  const all_projects_button = create_button_manager({
    text: "All projects",
    href: "#projects",
    type: "plain",
    on_click: () => manager.set_is_full_nav_toggled_on(false),
  })
</script>

<Layout {manager}>
  {#snippet nav_bar_logo()}<strong>Example site</strong>{/snippet}
  {#snippet nav_bar_extra()}<Button manager={projects_button} />{/snippet}
  {#snippet full_nav()}
    <Button manager={all_projects_button} />
  {/snippet}
  {#snippet content()}
    <section id="projects" style="padding: 2rem;">
      <h1>Projects</h1><p>Your page content goes here.</p>
    </section>
  {/snippet}
</Layout>
```

## Configuration

### `is_dark_theme`

- type: boolean
- default: true
- description: sets the initial dark/light theme mode

### `full_nav_links`

- type: array
- default:
- description: an array of link objects for the full navigation panel

### `nav_bar_links`

- type: array
- default:
- description: an array of link objects for a simplified or top nav bar

### `is_show_hamburger`

- type: boolean
- default: true
- description: if true, displays a hamburger menu icon for toggling full nav

### `is_all_nav_bar_hidden`

- type: boolean
- default: false
- description: completely hides the nav bar if true

### `is_nav_bar_hidable_from_scroll`

- type: boolean
- default: false
- description: if true, allows the nav bar to hide on downward scrolling

### `is_nav_bar_hidden_from_scroll`

- type: boolean
- default: false
- description: indicates whether the nav bar is currently hidden from scroll

### `is_full_nav_prevented`

- type: boolean
- default: false
- description: prevents the user from opening the full nav if true

### `is_full_nav_toggled_on`

- type: boolean
- default: false
- description: if true, the full nav panel is open

### `border_radius`

- type: number
- default: 0
- description: border radius for certain nav bar styling, in rem

### `nav_margin_x`

- type: number
- default: 0
- description: horizontal margin for the nav bar

### `nav_margin_top`

- type: number
- default: 0
- description: top margin for the nav bar

### `nav_margin_bottom`

- type: number
- default: 0
- description: bottom margin for the nav bar

### `nav_main_padding_y`

- type: number
- default: 0.5
- description: vertical padding inside the nav bar

### `nav_main_padding_x`

- type: number
- default: 1
- description: horizontal padding inside the nav bar

### `breakpoint_splits`

- type: object
- default:
  - sm: 480
  - md: 768
  - lg: 1024
  - xl: 1200
- description: defines screen width breakpoints for layout adjustments

### `favicons`

- type: object
- default: null
- description: optionally contains { favicon, favicon_inactive }, updated on document visibility change

## Methods

### `handle_scroll()`

- description: marks that user is scrolling; sets is_at_top=false, is_at_bottom=false, etc.
- parameters:
- returns: void

### `handle_scrollend()`

- description: detects if scrolled to top/bottom at scroll end, updates manager states
- parameters:
- returns: void

### `set_base_theme()`

- description: checks document.dataset.theme or system preference, sets is_dark_theme accordingly
- parameters:
- returns: void

### `set_is_at_top()`

- description: manually sets is_at_top to given boolean
- parameters:
  - input: boolean
- returns: void

### `set_is_at_bottom()`

- description: manually sets is_at_bottom to given boolean
- parameters:
  - input: boolean
- returns: void

### `set_theme()`

- description: updates is_dark_theme and sets the theme data attribute/cookie
- parameters:
  - is_dark_theme_input: boolean
- returns: void

### `set_full_nav_height()`

- description: stores the measured height of the full nav panel (used for responsiveness checks)
- parameters:
  - input: number
- returns: void

### `set_is_full_nav_toggled_on()`

- description: sets whether the full navigation panel is open
- parameters:
  - input: boolean
- returns: void

### `set_screen_height()`

- description: updates the overall screen height in the manager
- parameters:
  - input: number
- returns: void

### `set_screen_width()`

- description: updates the overall screen width in the manager
- parameters:
  - input: number
- returns: void

### `set_nav_bar_height()`

- description: updates the nav bar’s current pixel height
- parameters:
  - input: number
- returns: void

### `set_is_navigating()`

- description: indicates a route transition is in progress (shows a loading overlay, etc.)
- parameters:
  - input: boolean
- returns: void

### `to_home()`

- description: convenience method to navigate user to '/' using svelte's goto
- parameters:
- returns: void

### `goto_path()`

- description: navigates user to a given route, closes full nav if open
- parameters:
  - slashed_path: string (ex: '/about')
- returns: void

### `init()`

- description: constructs the layout manager, setting initial states, creating sub-managers for alerts, confetti, dark theme switch, etc.
- parameters:
  - config: object
- returns: void

## Returned state

### `is_dark_theme`

- type: boolean
- description: true if the current theme is dark

### `favicons`

- type: object
- description: contains { favicon, favicon_inactive } for dynamic updates

### `breakpoints`

- type: object
- description: derived state with booleans for sm, md, lg, xl, xxl

### `full_nav_links`

- type: array
- description: an array of link objects for a full nav panel

### `nav_bar_links`

- type: array
- description: link objects for a top nav bar

### `is_show_hamburger`

- type: boolean
- description: if true, shows a hamburger icon to toggle full nav

### `screen_width`

- type: number
- description: the current window width

### `screen_height`

- type: number
- description: the current window height

### `is_all_nav_bar_hidden`

- type: boolean
- description: true if the entire nav bar is forcibly hidden

### `shown_nav_bar_height`

- type: number or null
- description: the current nav bar height if visible, else null

### `is_nav_bar_hidable_from_scroll`

- type: boolean
- description: allows nav bar to hide on scroll down

### `is_nav_bar_hidden_from_scroll`

- type: boolean
- description: the current scroll state: nav is hidden or not

### `is_nav_bar_shown`

- type: boolean
- description: true if the nav bar is currently displayed

### `is_full_nav_prevented`

- type: boolean
- description: disables opening the full nav

### `is_full_nav_toggled_on`

- type: boolean
- description: state of the full nav toggle

### `is_full_nav_shown`

- type: boolean
- description: true if the full nav is actually displayed

### `nav_bar_height`

- type: number or null
- description: the measured nav bar height in px

### `border_radius`

- type: number
- description: general border radius for nav styling

### `nav_margin_x`

- type: number
- description: horizontal margin for the nav

### `nav_margin_top`

- type: number
- description: top margin for the nav

### `nav_margin_bottom`

- type: number
- description: bottom margin for the nav

### `nav_main_padding_y`

- type: number
- description: vertical padding inside the nav bar

### `nav_main_padding_x`

- type: number
- description: horizontal padding inside the nav bar

### `is_navigating`

- type: boolean
- description: true if the app is in the middle of a page navigation

### `client_interface`

- type: object or null
- description: data from get_user_interface if screen size is known

### `breakpoint_splits`

- type: object
- description: holds the numeric widths for sm, md, lg, xl

### `nav_link_clicks`

- type: number
- description: count of how many nav links have been clicked

### `is_at_top`

- type: boolean
- description: true if user has scrolled to the top of the page

### `is_at_bottom`

- type: boolean
- description: true if user has scrolled to the bottom of the page

### `hovered_route_name`

- type: string or null
- description: the route name over which the user is currently hovering

### `available_content_height`

- type: number
- description: calculated screen height minus shown nav bar height

### `full_nav_height`

- type: number or null
- description: the measured height of the full nav

### `is_full_nav_large`

- type: boolean
- description: true if the full nav is over half the available screen content height

### `confetti_manager`

- type: object
- description: manages confetti display with a full screen overlay

### `alert_manager`

- type: object
- description: manages global alerts

### `dark_theme_manager`

- type: object
- description: a dark_theme checkbox manager controlling is_dark_theme
