scrollbar.mdx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. ---
  2. title: ScrollBar
  3. description: Standalone scrollbar with arrows and keyboard control
  4. order: 8
  5. ---
  6. # ScrollBar
  7. A standalone scrollbar component with optional arrows, keyboard navigation, and a draggable thumb.
  8. ## Basic usage
  9. ### Renderable API
  10. ```typescript
  11. import { ScrollBarRenderable, createCliRenderer } from "@opentui/core"
  12. const renderer = await createCliRenderer()
  13. const scrollbar = new ScrollBarRenderable(renderer, {
  14. id: "scrollbar",
  15. orientation: "vertical",
  16. height: 10,
  17. showArrows: true,
  18. trackOptions: {
  19. backgroundColor: "#222222",
  20. foregroundColor: "#888888",
  21. },
  22. onChange: (position) => {
  23. console.log("Scroll position:", position)
  24. },
  25. })
  26. // Connect the scrollbar to your content
  27. scrollbar.scrollSize = 200
  28. scrollbar.viewportSize = 20
  29. scrollbar.scrollPosition = 0
  30. renderer.root.add(scrollbar)
  31. scrollbar.focus()
  32. ```
  33. ## Keyboard controls
  34. When focused, the scrollbar responds to:
  35. - `Up`/`Down` or `k`/`j` for vertical bars
  36. - `Left`/`Right` or `h`/`l` for horizontal bars
  37. - `PageUp`/`PageDown` for larger jumps
  38. - `Home`/`End` to jump to start/end
  39. ## Construct API
  40. > Not available yet. Use `ScrollBarRenderable` for now.
  41. ## Properties
  42. | Property | Type | Default | Description |
  43. | ---------------- | ------------------------------ | ------- | -------------------------------------- |
  44. | `orientation` | `"vertical"` or `"horizontal"` | - | Scrollbar direction |
  45. | `showArrows` | `boolean` | `false` | Show arrow buttons |
  46. | `arrowOptions` | `ArrowOptions` | - | Styling for arrow buttons |
  47. | `trackOptions` | `Partial<SliderOptions>` | - | Styling for the track and thumb |
  48. | `scrollSize` | `number` | `0` | Total scrollable size |
  49. | `viewportSize` | `number` | `0` | Visible size of the viewport |
  50. | `scrollPosition` | `number` | `0` | Current scroll position |
  51. | `scrollStep` | `number` | - | Step size when `scrollBy(..., "step")` |
  52. | `onChange` | `(position: number) => void` | - | Fired when scroll position changes |