Examples

Chapter 1

Introduction to the library.

Chapter 2

Getting started with components.

Chapter 3

Advanced patterns and recipes.


Documentation

A page-flip presentation component that displays content in a book-like format with page navigation. Pages are provided as an array of BookPage objects. Supports previous/next arrow navigation, clickable page indicator dots, keyboard navigation (ArrowLeft/ArrowRight), and optional swipe/drag gestures. The currentPage prop is bindable for two-way page tracking. Transitions between pages can be "slide" (default), "fade", or "none". Built for a reading or onboarding flow — pages turn only on user action, never automatically (as opposed to Carousel, which auto-plays and is aimed at rotating promotional content rather than something someone reads through).

Usage

<script>
  import { Book } from '@juspay/svelte-ui-components';
</script>

<Book
  ariaLabel="Onboarding guide"
  pages={[
    { content: myPageSnippet1, title: 'Introduction' },
    { content: myPageSnippet2, title: 'Details' }
  ]}
/>

Props

Prop Type Required Default Description
pages BookPage[] Yes - Array of BookPage objects. Each contains a Snippet for the page content and an optional title string.
currentPage number No 0 The 0-indexed page currently displayed. Bindable for two-way sync with parent.
transition BookTransition No 'slide' Animation style when changing pages. "slide" translates horizontally, "fade" cross-fades, "none" switches instantly.
showNavigation boolean No true When true, shows previous/next arrow buttons on the left and right sides of the book.
showPageIndicator boolean No true When true, shows clickable dot indicators below the book for direct page navigation.
enableSwipe boolean No false When true, enables touch swipe and mouse drag gestures (20px threshold) to navigate between pages.
ariaLabel string No 'Book' Accessible name for the keyboard-operated book region.
testId string No - Test identifier applied as data-pw on the root element.
classes string No - CSS class string applied to the component's top-level element. Useful for theming — define classes with CSS variable overrides (e.g., .btn-primary { --button-color: #0070f3; }) and pass them to create variant styles.

The keyboard-operated book region is named "Book" by default. Set ariaLabel to describe the content or provide a localized name, especially when a page has several books.

Snippets

Svelte 5 Snippet props — pass content blocks to the component.

Snippet Type Description
previousIcon Snippet Custom icon rendered inside the previous-page navigation button. Defaults to a built-in SVG.
nextIcon Snippet Custom icon rendered inside the next-page navigation button. Defaults to a built-in SVG.

Events

Event Type Description
onpagechange (page: number) => void Fires after the current page changes. Receives the new 0-indexed page number.

CSS Variables

Override these custom properties to theme the component.

Variable Default CSS Property Description
--book-width 100% width Width of the book container.
--book-height 400px height Height of the page content area.
--book-background #ffffff background-color Background color of the book container.
--book-border-radius 8px border-radius Corner rounding of the book container.
--book-border 1px solid #e0e0e0 border Border of the book container.
--book-overflow hidden overflow Overflow behavior of the page content area.
--book-transition-duration 0.3s transition-duration Duration of the page transition animation.
--book-nav-size 36px width/height Size of the navigation arrow buttons.
--book-nav-background rgba(0, 0, 0, 0.05) --button-background Background of navigation buttons. Maps to --button-background which may have no effect in the current Button implementation.
--book-nav-hover-background rgba(0, 0, 0, 0.1) --button-hover-background Hover background of navigation buttons. Maps to --button-hover-background which may have no effect — Button uses --button-hover-color instead.
--book-nav-color #333333 --button-color Maps to Button's --button-color, which controls background-color of navigation buttons.
--book-nav-border-radius 50% border-radius Corner rounding of the navigation arrow buttons.
--book-nav-disabled-opacity 0.3 opacity Opacity of navigation arrows when at the first/last page.
--book-dot-size 8px width/height Size of each page indicator dot.
--book-dot-gap 8px gap Gap between page indicator dots.
--book-dot-color #cccccc background-color Color of inactive page indicator dots.
--book-dot-active-color #333333 background-color Color of the active page indicator dot.
--book-dot-border-radius 50% border-radius Corner rounding of page indicator dots.
--book-indicator-padding 12px 0 padding Padding around the page indicator dots container.
--book-dot-transition-duration 0.2s transition Duration of a page dot's active-state transition. Falls back through --motion-duration.
--book-dot-transition-easing ease transition Easing curve of a page dot's active-state transition. Falls back through --motion-easing.

Type Reference

Custom types used by this component's props and events:

BookPage

type BookPage = { content: Snippet; title?: string };

BookTransition

type BookTransition = 'slide' | 'fade' | 'none';

Internal Dependencies

This component uses the following library components internally:

  • Button (for navigation controls)

Web Component

Tag: <sui-book>

The aria-label attribute names the inner book region. Its JavaScript adapter property is bookAriaLabel, which avoids replacing the native HTMLElement.ariaLabel accessor. Both attribute updates and property assignment update the region name.

<sui-book show-navigation show-page-indicator></sui-book>

Web Component Events

onpagechange is available as a JS property, and also dispatches a same-named DOM custom event (bubbles, composed) for a consumer who only calls addEventListener — the detail is the new page number, unchanged from the callback's own argument:

const book = document.querySelector('sui-book');
book.addEventListener('pagechange', (e) => console.log(e.detail));

Slots

Slot Name Maps to Snippet Description
previous-icon previousIcon Custom icon for the previous page button; defaults to the built-in chevron.
next-icon nextIcon Custom icon for the next page button; defaults to the built-in chevron.

Note: The pages prop is an array of objects with Snippet content — set it via JavaScript property, not HTML attribute.