OpenLand IconOpenLand
Back to Open Source

ink-scroll-bar

TypeScript

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

๐Ÿ“œ ink-scroll-bar

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

License Version

โœจ 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 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.

import React, { useState } from "react"; import { Text } from "ink"; import { ScrollBarBox } from "ink-scroll-bar"; const MyComponent = () => { const [offset, setOffset] = useState(0); const totalItems = 50; const viewportHeight = 10; return ( <ScrollBarBox height={viewportHeight + 2} // +2 for borders width={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"; <Box flexDirection="row"> {/* Content Box with right border removed */} <Box borderStyle="single" borderRight={false}> <Content /> </Box> {/* ScrollBar completes the border */} <ScrollBar placement="right" style="single" contentHeight={100} viewportHeight={20} scrollOffset={offset} /> </Box>;

Inset Mode

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

<Box borderStyle="round" padding={1}> <Box flexDirection="row"> <Content /> <ScrollBar placement="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.
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 (Inset mode only).
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.

๐ŸŽจ 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