import { Button } from '@cloud-ru/ds-button'; import { KebabSVG } from '@cloud-ru/ds-icons/interface/system'; import { Droplist } from '@cloud-ru/ds-list'; import { Tooltip } from '@cloud-ru/ds-tooltip'; import { useDynamicList } from '@cloud-ru/ds-utils'; import { RefObject, useRef, useState } from 'react'; import { toolbarLocale } from '../../../../locale'; import { TEST_IDS } from '../../../../testIds'; import { BulkAction } from '../../types'; import { getBulkActionIndex, getBulkActionKey, mapBulkActionToDroplistItem } from '../../utils'; import { BulkActionsCheckbox } from '../BulkActionsCheckbox'; import { SelectionLabel } from '../SelectionLabel'; import styles from './styles.module.scss'; type BulkActionsControlsVariant = 'toolbar' | 'sheet'; type BulkActionsControlsProps = { actions: BulkAction[]; variant: BulkActionsControlsVariant; checked?: boolean; indeterminate?: boolean; onCheck?(): void; showCheckbox?: boolean; resizingContainerRef?: RefObject; selectedCount?: number; totalCount?: number; hasSelection?: boolean; }; export function BulkActionsControls({ actions, variant, checked, indeterminate, onCheck, showCheckbox = false, resizingContainerRef, selectedCount = 0, totalCount, hasSelection = false, }: BulkActionsControlsProps) { const { t } = toolbarLocale.useTranslations(); const [isMoreOpen, setIsMoreOpen] = useState(false); const actionsAreaRef = useRef(null); const triggerRef = useRef(null); const isSheet = variant === 'sheet'; const { visibleItems, hiddenItems } = useDynamicList({ items: actions, resizingContainerRef: isSheet ? undefined : resizingContainerRef, parentContainerRef: actionsAreaRef, }); const droplistActions = isSheet ? actions : hiddenItems; return (
{showCheckbox && }
{visibleItems.map((action, visibleIndex) => { const { label, icon: Icon, onClick, disabled, tooltip, 'data-test-id': testId } = action; const actionIndex = getBulkActionIndex(actions, action, visibleIndex); return (
{hiddenItems.length > 0 && ( ) : undefined } open={isMoreOpen} onOpenChange={setIsMoreOpen} trigger='clickAndFocusVisible' triggerElemRef={triggerRef} triggerClassName={styles.triggerClassName} closeDroplistOnItemClick placement='bottom-end' scroll size='s' items={droplistActions.map((action, index) => mapBulkActionToDroplistItem(action, getBulkActionIndex(actions, action, index)), )} > {({ onKeyDown }) => (
); }