pleroma/app/soapbox/features/chats/components/chat-widget/chat-pane-header.tsx

75 lines
1.9 KiB
TypeScript
Raw Normal View History

2022-08-10 05:38:49 -07:00
import React, { HTMLAttributes } from 'react';
import { HStack, IconButton, Text } from 'soapbox/components/ui';
interface IChatPaneHeader {
isOpen: boolean
isToggleable?: boolean
onToggle(): void
title: string | React.ReactNode
unreadCount?: number
2022-08-16 13:35:06 -07:00
secondaryAction?(): void
secondaryActionIcon?: string
2022-08-10 05:38:49 -07:00
}
const ChatPaneHeader = (props: IChatPaneHeader) => {
2022-09-09 07:24:25 -07:00
const {
isOpen,
isToggleable = true,
onToggle,
secondaryAction,
secondaryActionIcon,
title,
unreadCount,
2022-09-12 11:42:15 -07:00
...rest
2022-09-09 07:24:25 -07:00
} = props;
2022-08-10 05:38:49 -07:00
const ButtonComp = isToggleable ? 'button' : 'div';
const buttonProps: HTMLAttributes<HTMLButtonElement | HTMLDivElement> = {};
if (isToggleable) {
buttonProps.onClick = onToggle;
}
return (
2022-09-12 11:42:15 -07:00
<HStack {...rest} alignItems='center' justifyContent='between' className='rounded-t-xl h-16 py-3 px-4'>
2022-08-10 05:38:49 -07:00
<ButtonComp
className='flex-grow flex items-center flex-row space-x-1 h-16'
2022-09-12 11:42:15 -07:00
data-testid='title'
2022-08-10 05:38:49 -07:00
{...buttonProps}
>
<Text weight='semibold' tag='div'>
{title}
</Text>
2022-08-10 05:38:49 -07:00
{(typeof unreadCount !== 'undefined' && unreadCount > 0) && (
<HStack alignItems='center' space={2}>
2022-09-12 11:42:15 -07:00
<Text weight='semibold' data-testid='unread-count'>
2022-08-10 05:38:49 -07:00
({unreadCount})
</Text>
<div className='bg-accent-300 w-2.5 h-2.5 rounded-full' />
</HStack>
)}
</ButtonComp>
2022-08-16 13:35:06 -07:00
<HStack space={2} alignItems='center'>
{secondaryAction ? (
<IconButton
onClick={secondaryAction}
src={secondaryActionIcon as string}
iconClassName='w-5 h-5 text-gray-600'
/>
) : null}
<IconButton
onClick={onToggle}
src={isOpen ? require('@tabler/icons/chevron-down.svg') : require('@tabler/icons/chevron-up.svg')}
iconClassName='w-5 h-5 text-gray-600'
/>
</HStack>
2022-08-10 05:38:49 -07:00
</HStack>
);
};
export default ChatPaneHeader;