πŸ“„ File detail

components/CustomSelect/option-map.ts

🧩 .tsπŸ“ 51 linesπŸ’Ύ 1,189 bytesπŸ“ text
← Back to All Files

🎯 Use case

This file lives under β€œcomponents/”, which covers shared React UI pieces. On the API surface it exposes OptionMap β€” mainly functions, hooks, or classes. Dependencies touch React UI. It composes internal code from select (relative imports).

Generated from folder role, exports, dependency roots, and inline comments β€” not hand-reviewed for every path.

🧠 Inline summary

import type { ReactNode } from 'react' import type { OptionWithDescription } from './select.js' type OptionMapItem<T> = { label: ReactNode

πŸ“€ Exports (heuristic)

  • OptionMap
  • default

πŸ“š External import roots

Package roots from from "…" (relative paths omitted).

  • react

πŸ–₯️ Source preview

import type { ReactNode } from 'react'
import type { OptionWithDescription } from './select.js'

type OptionMapItem<T> = {
  label: ReactNode
  value: T
  description?: string
  previous: OptionMapItem<T> | undefined
  next: OptionMapItem<T> | undefined
  index: number
}

export default class OptionMap<T> extends Map<T, OptionMapItem<T>> {
  readonly first: OptionMapItem<T> | undefined
  readonly last: OptionMapItem<T> | undefined

  constructor(options: OptionWithDescription<T>[]) {
    const items: Array<[T, OptionMapItem<T>]> = []
    let firstItem: OptionMapItem<T> | undefined
    let lastItem: OptionMapItem<T> | undefined
    let previous: OptionMapItem<T> | undefined
    let index = 0

    for (const option of options) {
      const item = {
        label: option.label,
        value: option.value,
        description: option.description,
        previous,
        next: undefined,
        index,
      }

      if (previous) {
        previous.next = item
      }

      firstItem ||= item
      lastItem = item

      items.push([option.value, item])
      index++
      previous = item
    }

    super(items)
    this.first = firstItem
    this.last = lastItem
  }
}