BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/retab-ui/segment-interaction

Segment Interaction

retab-ui/segment-interaction
FreeUtility

React-free hover, focus, selection, and current-page helpers for Segment[] surfaces.

Install it

npx shadcn@latest add https://ui.retab.com/r/segment-interaction.json

Source

registry/new-york-v4/lib/segment-interaction.tsui.retab.com/r/segment-interaction.json
1import { type Segment } from "@/lib/segments";
2
3export interface SegmentInteraction {
4 previewSegmentId: string | null;
5 previewSegment: (segmentId: string) => void;
6 clearPreview: () => void;
7}
8
9export interface SegmentInteractionState {
10 currentPage: number | null;
11 currentSegmentId: string | null;
12 currentSegmentIds: readonly string[];
13 previewSegmentId: string | null;
14 highlightedSegmentId: string | null;
15 highlightedSegmentIds: readonly string[];
16}
17
18export interface SegmentViewState {
19 isPreviewed: boolean;
20 isCurrent: boolean;
21 isHighlighted: boolean;
22 isDimmed: boolean;
23}
24
25export interface SegmentSurfaceProps {
26 state: SegmentViewState;
27 eventHandlers: {
28 onPointerEnter: () => void;
29 onPointerLeave: () => void;
30 onClick: () => void;
31 };
32 dataProps: {
33 "data-previewed": boolean;
34 "data-current": boolean;
35 "data-highlighted": boolean;
36 };
37}
38
39export function resolvePreviewedSegmentId(
40 interaction?: Partial<Pick<SegmentInteraction, "previewSegmentId">> | null,
41): string | null {
42 return interaction?.previewSegmentId ?? null;
43}
44
45export function getSegmentInteractionState({
46 segments,
47 currentPage,
48 interaction,
49}: {
50 segments: Segment[];
51 currentPage?: number | null;
52 interaction?: SegmentInteraction | null;
53}): SegmentInteractionState {
54 const segmentIds = new Set(segments.map((segment) => segment.id));
55 const previewSegmentId = knownSegmentId(
56 resolvePreviewedSegmentId(interaction),
57 segmentIds,
58 );
59 const resolvedCurrentPage = normalizeCurrentPage(currentPage);
60 const currentSegmentIds =
61 resolvedCurrentPage == null
62 ? []
63 : resolveCurrentSegmentIds(segments, resolvedCurrentPage);
64 const highlightedSegmentIds =
65 previewSegmentId != null ? [previewSegmentId] : currentSegmentIds;
66
67 return {
68 currentPage: resolvedCurrentPage,
69 currentSegmentId: currentSegmentIds[0] ?? null,
70 currentSegmentIds,
71 previewSegmentId,
72 highlightedSegmentId: highlightedSegmentIds[0] ?? null,
73 highlightedSegmentIds,
74 };
75}
76
77export function scopeSegmentInteraction(
78 interaction: SegmentInteraction | null | undefined,
79 segmentIds: Iterable<string>,
80): SegmentInteraction | null | undefined {
81 if (!interaction) return interaction;
82
83 const knownIds = new Set(segmentIds);
84 const previewSegmentId = knownSegmentId(
85 interaction.previewSegmentId,
86 knownIds,
87 );
88
89 if (previewSegmentId === interaction.previewSegmentId) {
90 return interaction;
91 }
92
93 return {
94 ...interaction,
95// … truncated

What it pulls in

Other registry items

  • @retab/segments

Files it writes

  • registry/new-york-v4/lib/segment-interaction.ts

Facts

Registry
retab-ui
Type
registry:lib
Access
Free
Files written
1
Licence
NOASSERTION
First indexed
2026-08-04
Last confirmed
today

Go to the source

ui.retab.com retab-dev/retab-ui on GitHub Raw registry item This item as JSON

More from retab-ui

All 130 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
CSV parsercsvretab-uiUtilitiesFreeno deps · 4 files
Document source modeldocument-sourceretab-uiUtilitiesFreeno deps
DOCX Document Resourcedocx-document-resourceretab-uiUtilitiesFreeno deps · 5 files
Effect Keyeffect-keyretab-uiUtilitiesFreeno deps
PDF Document Resourcepdf-document-resourceretab-uiUtilitiesFree1 dep · 6 files
Segments modelsegmentsretab-uiUtilitiesFreeno deps
Utilsutilsretab-uiUtilitiesFree2 deps
XLSX SheetJS flattenerxlsx-sheetjs-flattenerretab-uiUtilitiesFree1 dep
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex