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

package.dist.components.date-picker.use-date-picker.js 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';
import * as datePicker from '@zag-js/date-picker';
import { useMachine, normalizeProps } from '@zag-js/react';
import { useId } from 'react';
import { useEnvironmentContext } from '../../providers/environment/use-environment-context.js';
import { useLocaleContext } from '../../providers/locale/use-locale-context.js';
import { useEvent } from '../../utils/use-event.js';

const useDatePicker = (props = {}) => {
  const { getRootNode } = useEnvironmentContext();
  const { dir } = useLocaleContext();
  const initialContext = {
    id: useId(),
    dir,
    getRootNode,
    open: props.defaultOpen,
    "open.controlled": props.open !== void 0,
    value: props.defaultValue,
    ...props
  };
  const context = {
    ...initialContext,
    value: props.value,
    onValueChange: useEvent(props.onValueChange, { sync: true }),
    onFocusChange: useEvent(props.onFocusChange),
    onViewChange: useEvent(props.onViewChange),
    onOpenChange: useEvent(props.onOpenChange)
  };
  const [state, send] = useMachine(datePicker.machine(initialContext), { context });
  return datePicker.connect(state, send, normalizeProps);
};

export { useDatePicker };




© 2015 - 2025 Weber Informatics LLC | Privacy Policy