import React, { ReactElement } from 'react'; import { DOMAttributes, FocusableElement } from '@react-types/shared'; import { useOverlayTrigger } from 'react-aria'; import { OverlayTriggerState } from 'react-stately'; import { ModalOpeningButton } from '../Modal/ModalOpeningButton'; import { Icon, IconOptions, ResourceSources } from '../Icons/Icon'; import { uuid, transformSnakeCase } from '../Utils/utils'; interface ResourceItem { item: T; selected?: boolean; label: string; type: string; childCount?: number; previewModalState: OverlayTriggerState; onSelect: (node: T, overlayProps: DOMAttributes) => void; onDrillDown?: (node: T) => void; className: string; allowedTypes?: string[] | undefined; componentIcon?: ReactElement | undefined; iconSource?: ResourceSources; showChevron?: boolean; id?: string; } const ResourceItem = ({ item, selected, label, type, childCount, previewModalState, onSelect, onDrillDown, className, allowedTypes, componentIcon, iconSource = 'matrix', showChevron = false, id, }: ResourceItem) => { const { triggerProps, overlayProps } = useOverlayTrigger({ type: 'dialog' }, previewModalState); const isDisabled = allowedTypes !== undefined && !allowedTypes.includes(transformSnakeCase(type)); const title = isDisabled ? "You can't select this item" : label; return (
  • onSelect(item, overlayProps)} aria-label={childCount === undefined ? `Drill down to ${label} children` : ''} className={` relative grow flex items-center px-4 py-2 rounded outline-0 ${selected ? 'bg-blue-100 text-blue-400' : ''} ${ childCount !== undefined && childCount > 0 ? 'mr-2' : '' } ${isDisabled ? 'font-normal text-gray-600 cursor-not-allowed' : 'hover:bg-gray-50 focus:bg-gray-50'} `} title={title} data-id={id} > {label} {selected && } {childCount === undefined && showChevron && ( )} {childCount !== undefined && childCount > 0 && onDrillDown && ( )}
  • ); }; export { ResourceItem };