rail-panel-header.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { useTranslation } from 'react-i18next'
  2. import { useRailContext } from '@/features/ide-react/context/rail-context'
  3. import OLIconButton from '@/shared/components/ol/ol-icon-button'
  4. import React, { useCallback } from 'react'
  5. import OLTooltip from '@/shared/components/ol/ol-tooltip'
  6. export default function RailPanelHeader({
  7. title,
  8. actions,
  9. onClose,
  10. }: {
  11. title: React.ReactNode
  12. actions?: React.ReactElement
  13. onClose?: () => void
  14. }) {
  15. const { t } = useTranslation()
  16. const { handlePaneCollapse } = useRailContext()
  17. const handleClose = useCallback(() => {
  18. handlePaneCollapse()
  19. if (onClose) {
  20. onClose()
  21. }
  22. }, [handlePaneCollapse, onClose])
  23. return (
  24. <div className="rail-panel-header">
  25. <h4 className="rail-panel-title">{title}</h4>
  26. <div className="rail-panel-header-actions">
  27. {actions}
  28. <OLTooltip
  29. id="close-rail-panel"
  30. description={t('close')}
  31. overlayProps={{ placement: 'bottom' }}
  32. >
  33. <OLIconButton
  34. onClick={handleClose}
  35. className="rail-panel-header-button-subdued"
  36. icon="close"
  37. accessibilityLabel={t('close')}
  38. size="sm"
  39. />
  40. </OLTooltip>
  41. </div>
  42. </div>
  43. )
  44. }