import React from 'react'; import type { AriaButtonOptions } from 'react-aria'; import { mergeProps, useButton, useFocusRing, useHover, useObjectRef } from 'react-aria'; import { useTranslations } from '@shoptet/ui-core-web'; import { forwardRef } from '../../../utils/forwardRef'; import { omit } from '../../../utils/omit'; import { DataList } from '../../DataList/DataList'; import { getDatalistItemProps } from '../../DataList/DataListItem'; import { Text } from '../../Typography/Text/Text'; import { getCheckboxProps } from '../Checkbox/Checkbox'; import type { CommonInputProps } from '../types'; import type { MultiSelectState } from './hooks/useMultiSelectState'; import { dictionary } from './dictionary'; interface MultiSelectToggleAllProps extends Pick, AriaButtonOptions<'button'>, Pick, 'tabIndex'>, React.PropsWithChildren { state: MultiSelectState; mode: 'content' | 'dropdown' | undefined; } export const MultiSelectToggleAll = forwardRef(function MultiSelectToggleAll( { state, warning, error, children, mode, tabIndex, ...props }: MultiSelectToggleAllProps, forwardedRef: React.ForwardedRef ) { const ref = useObjectRef(forwardedRef); const translations = useTranslations(dictionary); const { buttonProps } = useButton({ ...props, preventFocusOnPress: true } as AriaButtonOptions<'button'>, ref); const { hoverProps, isHovered } = useHover({ ...props, isDisabled: mode === 'content' || props.isDisabled }); const { focusProps, isFocused, isFocusVisible } = useFocusRing(props); const checkboxProps = omit( getCheckboxProps({ label: translations.toggleAll, error, warning, checked: state.isFilteredSelectAll, disabled: props.isDisabled, }), 'checked', 'disabled', 'type' ); return ( ); });