{"version":3,"file":"combobox-types.mjs","names":[],"sources":["../../../src/combobox/combobox-types.ts"],"sourcesContent":["/*!\n *\n *  Copyright (c) \"Neo4j\"\n *  Neo4j Sweden AB [http://neo4j.com]\n *\n *  This file is part of Neo4j.\n *\n *  Neo4j is free software: you can redistribute it and/or modify\n *  it under the terms of the GNU General Public License as published by\n *  the Free Software Foundation, either version 3 of the License, or\n *  (at your option) any later version.\n *\n *  This program is distributed in the hope that it will be useful,\n *  but WITHOUT ANY WARRANTY; without even the implied warranty of\n *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n *  GNU General Public License for more details.\n *\n *  You should have received a copy of the GNU General Public License\n *  along with this program.  If not, see <http://www.gnu.org/licenses/>.\n */\n\ntype ComboboxOption = {\n  label: string;\n  value: string;\n  /** If the option is disabled */\n  isDisabled?: boolean;\n  /** A visual element to display before the label. Incompatible with multi select. */\n  leadingVisual?: React.ReactNode;\n  /** A description to display below the label. */\n  description?: string;\n};\n\ntype ComboboxOptionGroup<TOption extends ComboboxOption = ComboboxOption> = {\n  label: string;\n  options: TOption[];\n};\n\ntype ComboboxFilterOption<TOption extends ComboboxOption = ComboboxOption> =\n  | ((option: TOption, searchValue: string) => boolean)\n  | false;\n\ntype ComboboxSize = 'small' | 'medium' | 'large';\n\n/**\n * A row at the end of the panel that acts instead of selecting.\n *\n * @remarks\n * Deliberately not a `ComboboxOption`, since an action never becomes part of\n * the value. Use it for something that leads out of the selection, such as a\n * link into a create flow.\n */\ntype ComboboxAction = {\n  /** Text of the row. */\n  label: string;\n  /**\n   * Called when the row is activated, with the current search value so the\n   * action can carry the query with it. The selection is left untouched.\n   */\n  onSelect: (context: { searchValue: string }) => void;\n  /** A description to display below the label. */\n  description?: string;\n  /** A visual element to display before the label. */\n  leadingVisual?: React.ReactNode;\n  /** If the action is disabled. */\n  isDisabled?: boolean;\n  /**\n   * Whether a divider is rendered above the action, separating it from the\n   * action before it. Ignored on the first action, which already sits below\n   * the divider that separates actions from options.\n   */\n  hasDivider?: boolean;\n};\n\ntype ComboboxBaseProps<TOption extends ComboboxOption = ComboboxOption> = {\n  /** Accessible label for the combobox. Rendered above the control. */\n  label: string;\n  /**\n   * Name used to submit the selected option value through a native form.\n   * Above 300 options, only the selection is mirrored to the form, so browser\n   * autofill no longer offers the option list.\n   */\n  name?: string;\n  /** Id of the form the combobox belongs to when it is outside that form. */\n  formId?: string;\n  /** Hint for browser autofill on the native form control. */\n  autoComplete?: string;\n  /** Ref to the focusable combobox trigger. */\n  triggerRef?: React.Ref<HTMLElement>;\n  /** Whether the label is clipped out of the layout, leaving it to screen readers only. */\n  hasVisuallyHiddenLabel?: boolean;\n  /** Assistive text below the control. Replaced by `errorText` while there is an error. */\n  helpText?: React.ReactNode;\n  /** Error message below the control. Puts the control in its error state. */\n  errorText?: React.ReactNode;\n  /**\n   * Whether a selection is required. Sets `aria-required` and, when `name` is\n   * provided, enables native form validation.\n   */\n  isRequired?: boolean;\n  /** Whether Required or Optional is shown at the end of the label row, based on the `isRequired` prop */\n  hasRequiredIndicator?: boolean;\n  /** The options to display in the combobox. Either an array of options or an array of option groups. */\n  options: TOption[] | ComboboxOptionGroup<TOption>[];\n  /**\n   * Whether a search input is rendered inside the panel. On by default; turn\n   * it off for a short list (roughly 10 options or fewer) where filtering\n   * adds nothing.\n   */\n  isSearchable?: boolean;\n  /** The search value in controlled mode. */\n  searchValue?: string;\n  /** The initial search value in uncontrolled mode. */\n  defaultSearchValue?: string;\n  /** Called when the search value changes. */\n  onSearchChange?: (searchValue: string) => void;\n  /**\n   * How options are matched against the search value. Defaults to a\n   * case-insensitive match on the option label. Pass `false` to skip internal\n   * filtering when the options are already filtered, such as when searching\n   * server side.\n   */\n  filterOption?: ComboboxFilterOption<TOption>;\n  /** Placeholder for the search input, which also names it. */\n  searchPlaceholder?: string;\n  /**\n   * Whether the panel is waiting for options. Replaces the empty message while\n   * there are no options.\n   */\n  isLoading?: boolean;\n  /** Text of the loading status. Defaults to `Loading...`. */\n  loadingMessage?: React.ReactNode;\n  /**\n   * Whether the search value can be turned into a new option, shown as an extra\n   * row at the end of the list. Requires `isSearchable`.\n   */\n  isCreatable?: boolean;\n  /**\n   * Called after a created option has been selected, so it can be persisted\n   * into `options`. Created options are not added to `options` by the combobox.\n   */\n  onCreateOption?: (option: TOption) => void;\n  /**\n   * Builds the option to create from the search value. Defaults to using the\n   * search value as both label and value, which is only enough when the options\n   * carry no fields of their own beyond `ComboboxOption`.\n   */\n  createOption?: (searchValue: string) => TOption;\n  /** Text of the create row. Defaults to `Create \"<search value>\"`. */\n  formatCreateLabel?: (searchValue: string) => React.ReactNode;\n  /**\n   * Whether the search value can become a new option. Defaults to requiring a\n   * non-blank value that does not exactly match an existing option or a\n   * currently selected one.\n   */\n  isValidNewOption?: (searchValue: string, options: TOption[]) => boolean;\n  /**\n   * Rows that act instead of selecting, pinned below the scrolling options\n   * after a divider so they stay visible however long the list is. They are\n   * always shown, never filtered by the search value, and never part of the\n   * selection.\n   */\n  actions?: ComboboxAction[];\n  /** Whether the panel is controlled open. */\n  isOpen?: boolean;\n  /** Called when the panel opens or closes. */\n  onOpenChange?: (isOpen: boolean) => void;\n  /** Whether a button for clearing the selection is rendered in the trigger. */\n  isClearable?: boolean;\n  /** Text shown in the trigger while nothing is selected. */\n  placeholder?: string;\n  /** Whether the combobox is disabled. */\n  isDisabled?: boolean;\n  /** Size of the combobox control. */\n  size?: ComboboxSize;\n  /** Whether the combobox fills the available width. */\n  isFluid?: boolean;\n  /** Whether the control hugs its content without a background or resting outline. */\n  isClean?: boolean;\n  /** Whether the panel is wrapped in a floating portal. Defaults to true outside a dialog. */\n  isPortaled?: boolean;\n  /** Portal target element. Defaults to `document.body`. */\n  portalTarget?: HTMLElement | null;\n  /** Positioning strategy used by Floating UI. */\n  floatingStrategy?: 'absolute' | 'fixed';\n  /**\n   * Replaces the built-in trigger. Spread `triggerProps` onto the focusable\n   * element that should open the panel; the panel is anchored to it. No root\n   * element is rendered, so the trigger is a direct child of whatever contains\n   * the combobox. `isFluid`, `isClean`, `size`, `className`, `style`,\n   * `htmlAttributes` and `ref` are ignored; use `triggerRef` to reach the\n   * trigger element.\n   */\n  renderTrigger?: (\n    triggerProps: ComboboxTriggerProps,\n    state: ComboboxTriggerState<TOption>,\n  ) => React.ReactNode;\n  /**\n   * Replaces how selected values and option labels are presented, keeping the\n   * behavior and the ARIA of the combobox.\n   */\n  components?: ComboboxComponents<TOption>;\n};\n\n/**\n * Presentation overrides for the parts of the combobox that show an option.\n *\n * @remarks\n * Each override is handed the option itself, so widening the option type is\n * what gives them typed access to fields of your own, such as a color. Only\n * presentation is replaced; selection, filtering, keyboard interaction and the\n * ARIA of the surrounding elements stay with the combobox. Use `renderTrigger`\n * instead to replace the control as a whole.\n */\ntype ComboboxComponents<TOption extends ComboboxOption = ComboboxOption> = {\n  /** Replaces the tag rendered per selected option in multi select. */\n  MultiValue?: React.ComponentType<ComboboxMultiValueProps<TOption>>;\n  /** Replaces the value shown in the trigger in single select. Must be non-interactive. */\n  SingleValue?: React.ComponentType<ComboboxSingleValueProps<TOption>>;\n  /** Replaces the label of an option. The selection and description chrome stays. */\n  OptionLabel?: React.ComponentType<ComboboxOptionLabelProps<TOption>>;\n};\n\n/** Props of a `MultiValue` override, rendered once per selected option. */\ntype ComboboxMultiValueProps<TOption extends ComboboxOption = ComboboxOption> =\n  {\n    option: TOption;\n    /** Position of the option in the selection. */\n    index: number;\n    isDisabled: boolean;\n    size: ComboboxSize;\n    /**\n     * Deselects this option. Nothing calls it unless the override renders an\n     * affordance for it, which also makes focus after the removal its own\n     * responsibility.\n     */\n    remove: () => void;\n  };\n\n/** Props of a `SingleValue` override, rendered inside the trigger. */\ntype ComboboxSingleValueProps<TOption extends ComboboxOption = ComboboxOption> =\n  {\n    option: TOption;\n    isDisabled: boolean;\n    size: ComboboxSize;\n  };\n\n/** Props of an `OptionLabel` override, rendered inside each option. */\ntype ComboboxOptionLabelProps<TOption extends ComboboxOption = ComboboxOption> =\n  {\n    option: TOption;\n    isSelected: boolean;\n    isDisabled: boolean;\n    /** Whether the option currently holds virtual focus. */\n    isFocused: boolean;\n    isMulti: boolean;\n    size: ComboboxSize;\n  };\n\n/**\n * Props that must be spread onto a custom trigger element. Includes the\n * Floating UI reference props, so the element it lands on becomes the anchor\n * the panel is positioned against.\n */\ntype ComboboxTriggerProps = React.HTMLAttributes<HTMLElement> & {\n  ref: React.Ref<HTMLElement>;\n  role: 'combobox';\n  'aria-haspopup': 'dialog' | 'listbox';\n  // These are DOM attribute names, so the boolean naming convention cannot apply.\n  /* eslint-disable @typescript-eslint/naming-convention */\n  'aria-expanded': boolean;\n  'aria-disabled': boolean | undefined;\n  'aria-invalid': boolean | undefined;\n  'aria-required': boolean | undefined;\n  /* eslint-enable @typescript-eslint/naming-convention */\n  'aria-controls': string | undefined;\n  'aria-activedescendant': string | undefined;\n  'aria-describedby': string | undefined;\n  'aria-label'?: string;\n  'aria-labelledby'?: string;\n};\n\n/**\n * The label, help text, and error text of the combobox, for rendering them from\n * a custom trigger.\n *\n * @remarks\n * A custom trigger is named through `aria-label` and carries the\n * `aria-describedby` of whichever message is currently shown, so it has to\n * render that message with the id it is handed here.\n */\ntype ComboboxFieldState = {\n  label: string;\n  hasVisuallyHiddenLabel: boolean;\n  helpText?: React.ReactNode;\n  errorText?: React.ReactNode;\n  hasError: boolean;\n  isRequired: boolean;\n  hasRequiredIndicator: boolean;\n  /** Id the trigger's `aria-labelledby` points at when the label is rendered. */\n  labelId: string;\n  /** Id of the trigger, so a rendered `<label>` can point at it with `htmlFor`. */\n  triggerId: string;\n  /** Ids the trigger's `aria-describedby` points at. Only one is used at a time. */\n  helpTextId: string;\n  errorTextId: string;\n};\n\n/** Current combobox state, for rendering a custom trigger. */\ntype ComboboxTriggerState<TOption extends ComboboxOption = ComboboxOption> = {\n  isOpen: boolean;\n  isMulti: boolean;\n  isDisabled: boolean;\n  /** The selected options, as a list in both single and multi select. */\n  selectedOptions: TOption[];\n  /** Clears the whole selection. */\n  clear: () => void;\n  /** Deselects a single option. */\n  remove: (option: TOption) => void;\n  /** The label and messages of the combobox, so a custom trigger can present them. */\n  field: ComboboxFieldState;\n};\n\ntype ComboboxSingleProps<TOption extends ComboboxOption = ComboboxOption> = {\n  /** The selected option in controlled mode. */\n  value?: TOption | null;\n  /** The initially selected option in uncontrolled mode. */\n  defaultValue?: TOption | null;\n  /** Called when the selected option changes. `null` when the selection is cleared. */\n  onChange?: (value: TOption | null) => void;\n  /** Whether multiple options can be selected. */\n  isMulti?: false;\n  maxRows?: never;\n};\n\ntype ComboboxMultiProps<TOption extends ComboboxOption = ComboboxOption> = {\n  /** The selected options in controlled mode. */\n  value?: TOption[];\n  /** The initially selected options in uncontrolled mode. */\n  defaultValue?: TOption[];\n  /** Called when the selected options change. */\n  onChange?: (value: TOption[]) => void;\n  /** Whether multiple options can be selected. */\n  isMulti: true;\n  /**\n   * Maximum number of rows the selected tags may wrap into, a single row by\n   * default. Tags that do not fit are collapsed into a read-only counter tag,\n   * such as `+4`, at the end of the last row. Pass `null` to let the control\n   * grow with the selection.\n   */\n  maxRows?: number | null;\n};\n\ntype ComboboxProps<TOption extends ComboboxOption = ComboboxOption> =\n  ComboboxBaseProps<TOption> &\n    (ComboboxSingleProps<TOption> | ComboboxMultiProps<TOption>);\n\ntype ComboboxPanelProps = {\n  children?: React.ReactNode;\n  ref?: React.Ref<HTMLDivElement>;\n  id?: string;\n  className?: string;\n  style?: React.CSSProperties;\n  /**\n   * Set when the panel is a dialog popup, which is the case while the search\n   * input inside it holds DOM focus.\n   */\n  ariaLabel?: string;\n  isDialog?: boolean;\n} & Record<string, unknown>;\n\ntype ComboboxControlProps<TOption extends ComboboxOption = ComboboxOption> = {\n  triggerProps: ComboboxTriggerProps;\n  state: ComboboxTriggerState<TOption>;\n  field: ComboboxFieldState;\n  placeholder: string;\n  isClearable: boolean;\n  isClean: boolean;\n  size: ComboboxSize;\n  /** Maximum number of rows the selected tags may wrap into in multi select. `null` is unlimited. */\n  maxRows?: number | null;\n  components: ComboboxComponents<TOption>;\n  /** Floating UI reference props, so clicking anywhere in the control opens the panel. */\n  referenceProps: React.HTMLAttributes<HTMLDivElement>;\n  referenceRef: React.Ref<HTMLDivElement>;\n};\n\ntype ComboboxEmptyStateProps = {\n  children?: React.ReactNode;\n};\n\ntype ComboboxInputProps = {\n  ref?: React.Ref<HTMLInputElement>;\n  ariaLabel: string;\n  value: string;\n  onValueChange: (searchValue: string) => void;\n  placeholder?: string;\n  /** Id of the listbox the input controls, when the listbox is rendered. */\n  listboxId?: string;\n  /** Id of the virtually focused option, when one is active. */\n  activeOptionId?: string;\n  onKeyDown?: (event: React.KeyboardEvent<HTMLInputElement>) => void;\n};\n\ntype ComboboxListBoxProps = {\n  ariaLabel: string;\n  children?: React.ReactNode;\n  isMulti?: boolean;\n  id?: string;\n  /** Ids of the pinned action rows the listbox owns without containing. */\n  ownsIds?: string;\n};\n\ntype ComboboxGroupProps = {\n  children?: React.ReactNode;\n  label: string;\n};\n\ntype ComboboxOptionProps = {\n  children?: React.ReactNode;\n  /** Left out on rows that cannot be selected, which drops `aria-selected`. */\n  isSelected?: boolean;\n  isDisabled?: boolean;\n  isFocused?: boolean;\n  /** Whether the option is the row that creates a new option from the search value. */\n  isCreate?: boolean;\n  /** Whether the option is an action row, which acts instead of selecting. */\n  isAction?: boolean;\n  id?: string;\n  onClick?: () => void;\n  /** Called when the pointer moves over the option, so hover can drive virtual focus. */\n  onHover?: () => void;\n  /**\n   * One-based position in the full list. Only set while the listbox is\n   * virtualized, where the DOM no longer holds every option.\n   */\n  posInSet?: number;\n  /** Total options in the full list. Only set while the listbox is virtualized. */\n  setSize?: number;\n};\n\ntype ComboboxOptionContentProps = {\n  label: string;\n  /**\n   * Replaces the label text. Rendered in place of the label typography rather\n   * than inside it, so it can be any element rather than inline text.\n   */\n  customLabel?: React.ReactNode;\n  description?: string;\n  leadingVisual?: React.ReactNode;\n  isDisabled?: boolean;\n  isSelected?: boolean;\n  isMulti?: boolean;\n};\n\nexport type {\n  ComboboxProps,\n  ComboboxAction,\n  ComboboxComponents,\n  ComboboxControlProps,\n  ComboboxFieldState,\n  ComboboxMultiValueProps,\n  ComboboxOptionLabelProps,\n  ComboboxSingleValueProps,\n  ComboboxTriggerProps,\n  ComboboxTriggerState,\n  ComboboxPanelProps,\n  ComboboxEmptyStateProps,\n  ComboboxFilterOption,\n  ComboboxInputProps,\n  ComboboxListBoxProps,\n  ComboboxGroupProps,\n  ComboboxOptionProps,\n  ComboboxOptionContentProps,\n  ComboboxOption,\n  ComboboxOptionGroup,\n  ComboboxSize,\n};\n"],"mappings":""}