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 (
<HStack {...rest} alignItems='center' justifyContent='between' className='h-16 rounded-t-xl px-4 py-3'>
2022-08-10 05:38:49 -07:00
<ButtonComp
2023-02-01 14:13:42 -08:00
className='flex h-16 grow flex-row items-center space-x-1'
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>
2023-02-01 14:13:42 -08:00
<div className='h-2.5 w-2.5 rounded-full bg-accent-300' />
2022-08-10 05:38:49 -07:00
</HStack>
)}
</ButtonComp>
2022-08-16 13:35:06 -07:00
<HStack space={2} alignItems='center'>
{secondaryAction ? (
<IconButton
onClick={secondaryAction}
src={secondaryActionIcon as string}
iconClassName='h-5 w-5 text-gray-600'
2022-08-16 13:35:06 -07:00
/>
) : null}
<IconButton
onClick={onToggle}
src={isOpen ? require('@tabler/icons/chevron-down.svg') : require('@tabler/icons/chevron-up.svg')}
iconClassName='h-5 w-5 text-gray-600'
2022-08-16 13:35:06 -07:00
/>
</HStack>
2022-08-10 05:38:49 -07:00
</HStack>
);
};
export default ChatPaneHeader;