2022-08-02 00:17:22 +00:00
|
|
|
import { PropsWithChildren } from 'react';
|
2022-11-28 02:00:28 +00:00
|
|
|
import { AlertCircle } from 'lucide-react';
|
2023-02-22 20:13:33 +00:00
|
|
|
import clsx from 'clsx';
|
2021-11-30 02:31:16 +00:00
|
|
|
|
2023-01-24 06:50:55 +00:00
|
|
|
import { Icon, IconMode } from '@@/Icon';
|
2022-07-27 13:47:38 +00:00
|
|
|
|
2023-05-30 18:33:22 +00:00
|
|
|
type Color = 'orange' | 'blue' | 'red' | 'green';
|
2022-01-23 19:48:04 +00:00
|
|
|
|
|
|
|
export interface Props {
|
2023-01-24 06:50:55 +00:00
|
|
|
icon?: React.ReactNode;
|
2022-01-23 19:48:04 +00:00
|
|
|
color?: Color;
|
2023-02-22 20:13:33 +00:00
|
|
|
className?: string;
|
2023-05-17 22:19:44 +00:00
|
|
|
childrenWrapperClassName?: string;
|
2023-05-31 03:08:41 +00:00
|
|
|
inline?: boolean;
|
2022-01-23 19:48:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function TextTip({
|
|
|
|
color = 'orange',
|
2023-01-24 06:50:55 +00:00
|
|
|
icon = AlertCircle,
|
2023-05-31 03:08:41 +00:00
|
|
|
inline = true,
|
2023-02-22 20:13:33 +00:00
|
|
|
className,
|
2022-01-23 19:48:04 +00:00
|
|
|
children,
|
2023-05-17 22:19:44 +00:00
|
|
|
childrenWrapperClassName = 'text-muted',
|
2022-01-23 19:48:04 +00:00
|
|
|
}: PropsWithChildren<Props>) {
|
2023-01-24 06:50:55 +00:00
|
|
|
return (
|
2023-05-31 03:08:41 +00:00
|
|
|
<div
|
|
|
|
className={clsx(
|
|
|
|
className,
|
2023-06-01 20:35:15 +00:00
|
|
|
'small gap-1 align-top text-xs',
|
2023-05-31 03:08:41 +00:00
|
|
|
inline ? 'inline-flex' : 'flex'
|
|
|
|
)}
|
|
|
|
>
|
2023-06-11 23:50:13 +00:00
|
|
|
<Icon icon={icon} mode={getMode(color)} className="!mt-0.5 flex-none" />
|
2023-05-14 02:26:11 +00:00
|
|
|
|
2023-05-17 22:19:44 +00:00
|
|
|
<span className={childrenWrapperClassName}>{children}</span>
|
2023-03-07 16:45:39 +00:00
|
|
|
</div>
|
2023-01-24 06:50:55 +00:00
|
|
|
);
|
|
|
|
}
|
2022-07-27 13:47:38 +00:00
|
|
|
|
2023-01-24 06:50:55 +00:00
|
|
|
function getMode(color: Color): IconMode {
|
2022-07-27 13:47:38 +00:00
|
|
|
switch (color) {
|
|
|
|
case 'blue':
|
2023-01-24 06:50:55 +00:00
|
|
|
return 'primary';
|
2023-05-30 18:33:22 +00:00
|
|
|
case 'red':
|
|
|
|
return 'danger';
|
|
|
|
case 'green':
|
|
|
|
return 'success';
|
2022-07-27 13:47:38 +00:00
|
|
|
case 'orange':
|
|
|
|
default:
|
2023-01-24 06:50:55 +00:00
|
|
|
return 'warning';
|
2022-07-27 13:47:38 +00:00
|
|
|
}
|
2021-11-30 02:31:16 +00:00
|
|
|
}
|