mirror of https://github.com/msgbyte/tailchat
refactor: 抽象出部分公共代码
parent
83da09fba5
commit
3b447b459d
@ -0,0 +1,42 @@
|
||||
import { Badge, Typography } from 'antd';
|
||||
import clsx from 'clsx';
|
||||
import React from 'react';
|
||||
import { useLocation } from 'react-router';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
export const GroupPanelItem: React.FC<{
|
||||
name: string;
|
||||
icon: React.ReactNode;
|
||||
to: string;
|
||||
badge?: boolean;
|
||||
}> = React.memo((props) => {
|
||||
const { icon, name, to, badge } = props;
|
||||
const location = useLocation();
|
||||
const isActive = location.pathname.startsWith(to);
|
||||
|
||||
return (
|
||||
<Link to={to}>
|
||||
<div
|
||||
className={clsx(
|
||||
'w-full hover:bg-white hover:bg-opacity-20 cursor-pointer text-white rounded px-1 h-8 flex items-center text-base group',
|
||||
{
|
||||
'bg-white bg-opacity-20': isActive,
|
||||
}
|
||||
)}
|
||||
>
|
||||
<div className="flex items-center justify-center px-1 mr-1">{icon}</div>
|
||||
|
||||
<Typography.Text className="flex-1 text-white" ellipsis={true}>
|
||||
{name}
|
||||
</Typography.Text>
|
||||
|
||||
{badge === true ? (
|
||||
<Badge status="error" />
|
||||
) : (
|
||||
<Badge count={Number(badge) || 0} />
|
||||
)}
|
||||
</div>
|
||||
</Link>
|
||||
);
|
||||
});
|
||||
GroupPanelItem.displayName = 'GroupPanelItem';
|
@ -0,0 +1,37 @@
|
||||
import { Icon } from '@iconify/react';
|
||||
import React from 'react';
|
||||
import { useReducer } from 'react';
|
||||
|
||||
export const GroupSection: React.FC<{
|
||||
header: string;
|
||||
}> = React.memo((props) => {
|
||||
const [isShow, switchShow] = useReducer((v) => !v, true);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div
|
||||
className="flex items-center cursor-pointer py-1"
|
||||
onClick={switchShow}
|
||||
>
|
||||
<Icon
|
||||
className="mr-1"
|
||||
icon="mdi-chevron-right"
|
||||
rotate={isShow ? 45 : 0}
|
||||
/>
|
||||
<div>{props.header}</div>
|
||||
</div>
|
||||
<div
|
||||
className="transition-all overflow-hidden"
|
||||
style={{
|
||||
maxHeight: isShow ? 'var(--max-height)' : 0,
|
||||
}}
|
||||
ref={(ref) =>
|
||||
ref?.style.setProperty('--max-height', `${ref.scrollHeight}px`)
|
||||
}
|
||||
>
|
||||
{props.children}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
GroupSection.displayName = 'GroupSection';
|
Loading…
Reference in New Issue