Skip to content

Repository files navigation

📜 ink-scroll-bar

A customizable, high-precision vertical scroll bar component for Ink CLI applications.

LicenseVersion

✨ Features

  • Two Rendering Modes:

    • Border Mode: Seamlessly integrates with container borders (replaces one side).

      Border Mode Demo

    • Inset Mode: Renders inside the content area, perfect for floating scroll bars.

      Inset Mode Demo

      • Supports autoHide: Completely hide the scroll bar when content fits the viewport.
      • If autoHide is false (default) and content fits, only the track is shown.

      Auto Hide Demo

  • Rich Styling:

    • Supports all standard Ink border styles (single, double, round, bold, etc.).
    • Special inset styles (block, line, thick, dots).
    • Customizable colors and dimming.
  • Flexible Integration:

    • Standalone ScrollBar component for custom layouts.
    • ScrollBarBox wrapper for instant bordered containers with scroll bars.
  • Auto-hide: Option to hide the scroll bar when content fits the viewport (inset mode).

📦 Installation

npm install @byteland/ink-scroll-bar

🚀 Usage

Basic Usage with ScrollBarBox

The easiest way to use ink-scroll-bar is with the ScrollBarBox component. It wraps your content in a bordered box and handles the scroll bar positioning for you.

importReact,{useState}from"react";import{Text}from"ink";import{ScrollBarBox}from"ink-scroll-bar";constMyComponent=()=>{const[offset,setOffset]=useState(0);consttotalItems=50;constviewportHeight=10;return(<ScrollBarBoxheight={viewportHeight+2}// +2 for borderswidth={40}borderStyle="single"scrollBarPosition="right"contentHeight={totalItems}viewportHeight={viewportHeight}scrollOffset={offset}>{/* Your scrollable content here */}<Text>Item 1...</Text></ScrollBarBox>);};

Advanced Usage with ScrollBar

For more control over layout, use the standalone ScrollBar component.

Border Mode

In border mode, the scroll bar renders corner characters to connect with adjacent borders.

import{Box}from"ink";import{ScrollBar}from"ink-scroll-bar";<BoxflexDirection="row">{/* Content Box with right border removed */}<BoxborderStyle="single"borderRight={false}><Content/></Box>{/* ScrollBar completes the border */}<ScrollBarplacement="right"style="single"contentHeight={100}viewportHeight={20}scrollOffset={offset}/></Box>;

Inset Mode

Inset mode renders without corners, suitable for placing inside a container.

<BoxborderStyle="round"padding={1}><BoxflexDirection="row"><Content/><ScrollBarplacement="inset"style="block"// 'block', 'line', 'thick', 'dots'color="cyan"contentHeight={100}viewportHeight={20}scrollOffset={offset}autoHide// Hide if content fits/></Box></Box>

📚 API

ScrollBar Props

PropTypeDefaultDescription
contentHeightnumberRequired📏 Total height of the scrollable content.
viewportHeightnumberRequired👁️ Height of the visible area.
scrollOffsetnumberRequired⬇️ Current scroll position (0 to max).
placement'left' | 'right' | 'inset''right'📍 Rendering mode/position.
styleScrollBarStyle'single'/'block'🎨 Visual style (see below).
colorstringundefined🌈 Color of the scroll bar characters.
dimColorbooleanfalse🌑 Whether to dim the scroll bar.
autoHidebooleanfalse👻 Hide when content fits (Inset mode only). If false, shows track when content fits.
thumbCharstring-👍 Custom thumb character.
trackCharstring-🛤️ Custom track character (Inset mode only).

ScrollBarBox Props

Inherits all Ink Box Props, plus:

PropTypeDefaultDescription
contentHeightnumberRequired📏 Total height of the content.
viewportHeightnumberRequired👁️ Height of the viewport.
scrollOffsetnumberRequired⬇️ Current scroll position.
scrollBarPosition'left' | 'right''right'📍 Which border to replace with scroll bar.
scrollBarAutoHidebooleanfalse👻 Hide thumb if content fits.
thumbCharstring-👍 Custom thumb character.

🎨 Styles

Border Mode Styles (matches Ink borders):

  • single, double, round, bold, singleDouble, doubleSingle, classic, arrow

Inset Mode Styles:

  • block: █ thumb, ░ track
  • line: │ thumb, (blank) track
  • thick: ┃ thumb, ╏ track
  • dots: ● thumb, · track

📄 License

MIT

About

A customizable, high-precision vertical scroll bar component for Ink CLI applications.

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages