2023-05-22 10:52:06 +08:00
|
|
|
import { FC, ReactElement } from 'react';
|
|
|
|
import { Label, Tooltip } from '@fluentui/react-components';
|
2023-05-19 14:22:37 +08:00
|
|
|
import classnames from 'classnames';
|
2023-05-05 23:23:34 +08:00
|
|
|
|
2023-05-17 23:27:52 +08:00
|
|
|
export const Labeled: FC<{
|
2023-05-24 21:27:23 +08:00
|
|
|
label: string;
|
|
|
|
desc?: string | null,
|
2023-06-03 20:18:57 +08:00
|
|
|
descComponent?: ReactElement,
|
2023-05-24 21:27:23 +08:00
|
|
|
content: ReactElement,
|
|
|
|
flex?: boolean,
|
|
|
|
spaceBetween?: boolean,
|
2023-06-03 20:18:57 +08:00
|
|
|
breakline?: boolean,
|
|
|
|
onMouseEnter?: () => void
|
|
|
|
onMouseLeave?: () => void
|
2023-05-17 23:27:52 +08:00
|
|
|
}> = ({
|
2023-05-22 10:52:06 +08:00
|
|
|
label,
|
|
|
|
desc,
|
2023-06-03 20:18:57 +08:00
|
|
|
descComponent,
|
2023-05-22 10:52:06 +08:00
|
|
|
content,
|
|
|
|
flex,
|
2023-05-24 21:27:23 +08:00
|
|
|
spaceBetween,
|
2023-06-03 20:18:57 +08:00
|
|
|
breakline,
|
|
|
|
onMouseEnter,
|
|
|
|
onMouseLeave
|
2023-05-22 10:52:06 +08:00
|
|
|
}) => {
|
2023-05-05 23:23:34 +08:00
|
|
|
return (
|
2023-05-19 14:22:37 +08:00
|
|
|
<div className={classnames(
|
2023-05-24 21:27:23 +08:00
|
|
|
!breakline ? 'items-center' : '',
|
2023-05-19 14:22:37 +08:00
|
|
|
flex ? 'flex' : 'grid grid-cols-2',
|
2023-05-24 21:27:23 +08:00
|
|
|
breakline ? 'flex-col' : '',
|
2023-05-19 14:22:37 +08:00
|
|
|
spaceBetween && 'justify-between')
|
2023-05-17 23:27:52 +08:00
|
|
|
}>
|
2023-06-03 20:18:57 +08:00
|
|
|
{(desc || descComponent) ?
|
|
|
|
<Tooltip content={descComponent ? descComponent : desc!} showDelay={0} hideDelay={0} relationship="description">
|
|
|
|
<Label onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave}>{label}</Label>
|
2023-05-05 23:23:34 +08:00
|
|
|
</Tooltip> :
|
2023-06-03 20:18:57 +08:00
|
|
|
<Label onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave}>{label}</Label>
|
2023-05-05 23:23:34 +08:00
|
|
|
}
|
|
|
|
{content}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|