package.dist.components.rating-group.use-rating-group.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of react Show documentation
Show all versions of react Show documentation
A collection of unstyled, accessible UI components for React, utilizing state machines for seamless interaction.
The newest version!
'use client';
import * as rating from '@zag-js/rating-group';
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';
import { useFieldContext } from '../field/use-field-context.js';
const useRatingGroup = (props = {}) => {
const { getRootNode } = useEnvironmentContext();
const { dir } = useLocaleContext();
const field = useFieldContext();
const initialContext = {
id: useId(),
ids: {
label: field?.ids.label,
hiddenInput: field?.ids.control
},
dir,
disabled: field?.disabled,
readOnly: field?.readOnly,
required: field?.required,
getRootNode,
value: props.defaultValue,
...props
};
const context = {
...initialContext,
value: props.value,
onValueChange: useEvent(props.onValueChange, { sync: true }),
onHoverChange: useEvent(props.onHoverChange)
};
const [state, send] = useMachine(rating.machine(initialContext), {
context
});
return rating.connect(state, send, normalizeProps);
};
export { useRatingGroup };
© 2015 - 2025 Weber Informatics LLC | Privacy Policy