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

package.dist.components.carousel.use-carousel.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 carousel from '@zag-js/carousel';
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 useCarousel = (props = {}) => {
  const { getRootNode } = useEnvironmentContext();
  const { dir } = useLocaleContext();
  const initialContext = {
    id: useId(),
    dir,
    getRootNode,
    index: props.defaultIndex,
    ...props
  };
  const context = {
    ...initialContext,
    index: props.index,
    onIndexChange: useEvent(props.onIndexChange, { sync: true })
  };
  const [state, send] = useMachine(carousel.machine(initialContext), { context });
  return carousel.connect(state, send, normalizeProps);
};

export { useCarousel };




© 2015 - 2025 Weber Informatics LLC | Privacy Policy