2024-12-05 15:46:23 +03:00
|
|
|
import React, { Suspense } from 'react';
|
|
|
|
|
|
2025-03-12 12:04:50 +03:00
|
|
|
import { type PlacesType, Tooltip } from '@/components/container';
|
|
|
|
|
import { TextURL } from '@/components/control';
|
|
|
|
|
import { IconHelp } from '@/components/icons';
|
|
|
|
|
import { Loader } from '@/components/loader';
|
2025-02-21 21:15:05 +03:00
|
|
|
import { type Styling } from '@/components/props';
|
2025-04-12 21:44:13 +03:00
|
|
|
import { cn } from '@/components/utils';
|
2025-01-14 21:58:16 +03:00
|
|
|
import { usePreferencesStore } from '@/stores/preferences';
|
2023-12-13 14:32:57 +03:00
|
|
|
|
2025-03-12 11:55:43 +03:00
|
|
|
import { type HelpTopic } from '../models/help-topic';
|
2025-02-12 13:42:21 +03:00
|
|
|
|
2025-02-19 23:30:35 +03:00
|
|
|
const TopicPage = React.lazy(() =>
|
2025-03-12 11:55:43 +03:00
|
|
|
import('@/features/help/pages/manuals-page/topic-page').then(module => ({ default: module.TopicPage }))
|
2025-02-19 23:30:35 +03:00
|
|
|
);
|
2023-12-05 01:22:44 +03:00
|
|
|
|
2025-02-21 21:15:05 +03:00
|
|
|
interface BadgeHelpProps extends Styling {
|
2024-11-21 15:09:51 +03:00
|
|
|
/** Topic to display in a tooltip. */
|
2023-12-28 14:04:44 +03:00
|
|
|
topic: HelpTopic;
|
2024-11-21 15:09:51 +03:00
|
|
|
|
|
|
|
|
/** Offset from the cursor to the tooltip. */
|
2023-12-28 14:04:44 +03:00
|
|
|
offset?: number;
|
2024-11-21 15:09:51 +03:00
|
|
|
|
|
|
|
|
/** Classname for padding. */
|
2024-06-02 23:41:46 +03:00
|
|
|
padding?: string;
|
2024-11-21 15:09:51 +03:00
|
|
|
|
|
|
|
|
/** Place of the tooltip in relation to the cursor. */
|
2024-01-06 03:15:02 +03:00
|
|
|
place?: PlacesType;
|
2025-03-07 22:05:12 +03:00
|
|
|
|
|
|
|
|
/** Classname for content wrapper. */
|
|
|
|
|
contentClass?: string;
|
2023-12-05 01:22:44 +03:00
|
|
|
}
|
|
|
|
|
|
2024-11-21 15:09:51 +03:00
|
|
|
/**
|
|
|
|
|
* Display help icon with a manual page tooltip.
|
|
|
|
|
*/
|
2025-03-07 22:05:12 +03:00
|
|
|
export function BadgeHelp({ topic, padding = 'p-1', className, contentClass, style, ...restProps }: BadgeHelpProps) {
|
2025-01-14 21:58:16 +03:00
|
|
|
const showHelp = usePreferencesStore(state => state.showHelp);
|
2024-04-01 19:07:20 +03:00
|
|
|
|
|
|
|
|
if (!showHelp) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2023-12-05 01:22:44 +03:00
|
|
|
return (
|
2025-04-12 21:44:13 +03:00
|
|
|
<div tabIndex={-1} id={`help-${topic}`} className={cn(padding, className)} style={style}>
|
2025-06-19 12:44:58 +03:00
|
|
|
<IconHelp size='1.25rem' className='text-muted-foreground hover:text-primary cc-animate-color' />
|
2025-03-07 22:05:12 +03:00
|
|
|
<Tooltip
|
|
|
|
|
clickable
|
|
|
|
|
anchorSelect={`#help-${topic}`}
|
|
|
|
|
layer='z-topmost'
|
2025-04-12 21:44:13 +03:00
|
|
|
className={cn('max-w-120', contentClass)}
|
2025-03-07 22:05:12 +03:00
|
|
|
{...restProps}
|
|
|
|
|
>
|
2024-12-05 15:46:23 +03:00
|
|
|
<Suspense fallback={<Loader />}>
|
2025-04-16 15:22:31 +03:00
|
|
|
<div className='absolute right-1 text-sm top-2 bg-' onClick={event => event.stopPropagation()}>
|
2025-03-07 20:38:40 +03:00
|
|
|
<TextURL text='Справка...' href={`/manuals?topic=${topic}`} />
|
2023-12-28 14:04:44 +03:00
|
|
|
</div>
|
2024-12-05 15:46:23 +03:00
|
|
|
<TopicPage topic={topic} />
|
|
|
|
|
</Suspense>
|
2024-01-04 19:30:10 +03:00
|
|
|
</Tooltip>
|
2023-12-28 14:04:44 +03:00
|
|
|
</div>
|
|
|
|
|
);
|
2023-12-05 01:22:44 +03:00
|
|
|
}
|