All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.dist.components.combobox.use-combobox.cjs Maven / Gradle / Ivy

Go to download

A collection of unstyled, accessible UI components for React, utilizing state machines for seamless interaction.

The newest version!
'use client';
'use strict';

Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });

const combobox = require('@zag-js/combobox');
const react$1 = require('@zag-js/react');
const react = require('react');
const useEnvironmentContext = require('../../providers/environment/use-environment-context.cjs');
const useLocaleContext = require('../../providers/locale/use-locale-context.cjs');
const useEvent = require('../../utils/use-event.cjs');
const useFieldContext = require('../field/use-field-context.cjs');

function _interopNamespaceDefault(e) {
  const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
  if (e) {
    for (const k in e) {
      if (k !== 'default') {
        const d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: () => e[k]
        });
      }
    }
  }
  n.default = e;
  return Object.freeze(n);
}

const combobox__namespace = /*#__PURE__*/_interopNamespaceDefault(combobox);

const useCombobox = (props) => {
  const { collection, ...comboboxProps } = props;
  const { dir } = useLocaleContext.useLocaleContext();
  const { getRootNode } = useEnvironmentContext.useEnvironmentContext();
  const field = useFieldContext.useFieldContext();
  const initialContext = {
    id: react.useId(),
    ids: {
      label: field?.ids.label,
      input: field?.ids.control
    },
    disabled: field?.disabled,
    readOnly: field?.readOnly,
    required: field?.required,
    invalid: field?.invalid,
    dir,
    getRootNode,
    collection,
    open: props.defaultOpen,
    value: props.defaultValue,
    "open.controlled": props.open !== void 0,
    ...comboboxProps
  };
  const context = (() => {
    const { collection: _, ...restProps } = initialContext;
    return {
      ...restProps,
      value: props.value,
      onValueChange: useEvent.useEvent(props.onValueChange),
      onInputValueChange: useEvent.useEvent(props.onInputValueChange, { sync: true }),
      onHighlightChange: useEvent.useEvent(props.onHighlightChange),
      onOpenChange: useEvent.useEvent(props.onOpenChange)
    };
  })();
  const [state, send, service] = react$1.useMachine(combobox__namespace.machine(initialContext), {
    context
  });
  react.useEffect(() => {
    service.setContext({ collection });
  }, [collection]);
  return combobox__namespace.connect(state, send, react$1.normalizeProps);
};

exports.useCombobox = useCombobox;




© 2015 - 2025 Weber Informatics LLC | Privacy Policy