2024-12-05 15:45:53 +03:00
|
|
|
import React, { Suspense } from 'react';
|
2025-03-07 22:04:56 +03:00
|
|
|
import clsx from 'clsx';
|
2024-12-05 15:45:53 +03:00
|
|
|
|
2025-02-20 20:22:05 +03:00
|
|
|
import { type PlacesType, Tooltip } from '@/components/Container';
|
2025-02-10 01:32:16 +03:00
|
|
|
import { TextURL } from '@/components/Control';
|
2025-01-28 23:23:03 +03:00
|
|
|
import { IconHelp } from '@/components/Icons';
|
2025-02-10 01:32:16 +03:00
|
|
|
import { Loader } from '@/components/Loader';
|
2025-02-20 20:22:05 +03:00
|
|
|
import { type Styling } from '@/components/props';
|
2025-01-14 21:57:32 +03:00
|
|
|
import { usePreferencesStore } from '@/stores/preferences';
|
2025-03-07 22:04:56 +03:00
|
|
|
import { PARAMETER } from '@/utils/constants';
|
2024-06-07 20:17:03 +03:00
|
|
|
|
2025-02-22 14:03:13 +03:00
|
|
|
import { type HelpTopic } from '../models/helpTopic';
|
2025-02-12 13:41:58 +03:00
|
|
|
|
2025-02-19 23:29:45 +03:00
|
|
|
const TopicPage = React.lazy(() =>
|
|
|
|
import('@/features/help/pages/ManualsPage/TopicPage').then(module => ({ default: module.TopicPage }))
|
|
|
|
);
|
2024-06-07 20:17:03 +03:00
|
|
|
|
2025-02-20 20:22:05 +03:00
|
|
|
interface BadgeHelpProps extends Styling {
|
2024-11-21 15:09:31 +03:00
|
|
|
/** Topic to display in a tooltip. */
|
2024-06-07 20:17:03 +03:00
|
|
|
topic: HelpTopic;
|
2024-11-21 15:09:31 +03:00
|
|
|
|
|
|
|
/** Offset from the cursor to the tooltip. */
|
2024-06-07 20:17:03 +03:00
|
|
|
offset?: number;
|
2024-11-21 15:09:31 +03:00
|
|
|
|
|
|
|
/** Classname for padding. */
|
2024-06-07 20:17:03 +03:00
|
|
|
padding?: string;
|
2024-11-21 15:09:31 +03:00
|
|
|
|
|
|
|
/** Place of the tooltip in relation to the cursor. */
|
2024-06-07 20:17:03 +03:00
|
|
|
place?: PlacesType;
|
2025-03-07 22:04:56 +03:00
|
|
|
|
|
|
|
/** Classname for content wrapper. */
|
|
|
|
contentClass?: string;
|
2024-06-07 20:17:03 +03:00
|
|
|
}
|
|
|
|
|
2024-11-21 15:09:31 +03:00
|
|
|
/**
|
|
|
|
* Display help icon with a manual page tooltip.
|
|
|
|
*/
|
2025-03-07 22:04:56 +03:00
|
|
|
export function BadgeHelp({ topic, padding = 'p-1', className, contentClass, style, ...restProps }: BadgeHelpProps) {
|
2025-01-14 21:57:32 +03:00
|
|
|
const showHelp = usePreferencesStore(state => state.showHelp);
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
if (!showHelp) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return (
|
2025-03-07 22:04:56 +03:00
|
|
|
<div tabIndex={-1} id={`help-${topic}`} className={clsx(padding, className)} style={style}>
|
2024-06-07 20:17:03 +03:00
|
|
|
<IconHelp size='1.25rem' className='icon-primary' />
|
2025-03-07 22:04:56 +03:00
|
|
|
<Tooltip
|
|
|
|
clickable
|
|
|
|
anchorSelect={`#help-${topic}`}
|
|
|
|
layer='z-topmost'
|
|
|
|
className={clsx(PARAMETER.TOOLTIP_WIDTH, contentClass)}
|
|
|
|
{...restProps}
|
|
|
|
>
|
2024-12-05 15:45:53 +03:00
|
|
|
<Suspense fallback={<Loader />}>
|
2025-03-07 16:21:18 +03:00
|
|
|
<div className='absolute right-1 text-sm top-[0.4rem] clr-input' onClick={event => event.stopPropagation()}>
|
|
|
|
<TextURL text='Справка...' href={`/manuals?topic=${topic}`} />
|
2024-06-07 20:17:03 +03:00
|
|
|
</div>
|
2024-12-05 15:45:53 +03:00
|
|
|
<TopicPage topic={topic} />
|
|
|
|
</Suspense>
|
2024-06-07 20:17:03 +03:00
|
|
|
</Tooltip>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|