/* eslint-disable @typescript-eslint/no-use-before-define */ import * as React from "react"; import type { AriaListBoxOptions } from "@react-aria/listbox"; import type { ListState } from "react-stately"; import type { Node } from "@react-types/shared"; import { useListBox, useListBoxSection, useOption } from "react-aria"; // import { CheckIcon } from "@heroicons/react/solid"; import Checkmark from '@spectrum-icons/workflow/Checkmark' interface ListBoxProps extends AriaListBoxOptions { listBoxRef?: React.RefObject; state: ListState; } interface SectionProps { section: Node; state: ListState; } interface OptionProps { item: Node; state: ListState; } export function ListBox(props: ListBoxProps) { let ref = React.useRef(null); let { listBoxRef = ref, state } = props; let { listBoxProps } = useListBox(props, state, listBoxRef); return (
    {[...state.collection].map((item) => item.type === "section" ? ( ) : (
); } function ListBoxSection({ section, state }: SectionProps) { let { itemProps, headingProps, groupProps } = useListBoxSection({ heading: section.rendered, "aria-label": section["aria-label"] }); return ( <>
  • {section.rendered && ( {section.rendered} )}
      {[...section.childNodes].map((node) => (
  • ); } function Option({ item, state }: OptionProps) { let ref = React.useRef(null); let { optionProps, isDisabled, isSelected, isFocused } = useOption( { key: item.key }, state, ref ); let text = "text-black"; if (isFocused || isSelected) { text = "text-black"; } else if (isDisabled) { text = "text-gray-200"; } return (
  • {item.rendered} {isSelected && (
  • ); }