ol-list-group-item.tsx 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { forwardRef, useId } from 'react'
  2. import { ListGroupItem, ListGroupItemProps } from 'react-bootstrap'
  3. import OLTooltip from '@/shared/components/ol/ol-tooltip'
  4. type OLListGroupItemProps = ListGroupItemProps & {
  5. disabledReason?: string
  6. }
  7. const OLListGroupItem = forwardRef<HTMLElement, OLListGroupItemProps>(
  8. function OLListGroupItem({ disabledReason, ...props }, ref) {
  9. const as = props.as ?? 'button'
  10. const tooltipId = useId()
  11. const showDisabledTooltip = Boolean(props.disabled && disabledReason)
  12. const item = (
  13. <ListGroupItem
  14. {...props}
  15. ref={ref}
  16. as={as}
  17. type={as === 'button' ? 'button' : undefined}
  18. />
  19. )
  20. if (showDisabledTooltip) {
  21. return (
  22. <OLTooltip
  23. id={tooltipId}
  24. description={disabledReason}
  25. overlayProps={{ placement: 'right' }}
  26. >
  27. <span className="d-block">{item}</span>
  28. </OLTooltip>
  29. )
  30. }
  31. return item
  32. }
  33. )
  34. OLListGroupItem.displayName = 'OLListGroupItem'
  35. export default OLListGroupItem