ConceptPortal-public/rsconcept/frontend/src/features/help/components/badge-help.tsx

63 lines
1.9 KiB
TypeScript
Raw Normal View History

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';
import { type Styling } from '@/components/props';
import { cn } from '@/components/utils';
import { usePreferencesStore } from '@/stores/preferences';
2025-03-12 11:55:43 +03:00
import { type HelpTopic } from '../models/help-topic';
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
);
interface BadgeHelpProps extends Styling {
/** Topic to display in a tooltip. */
2023-12-28 14:04:44 +03:00
topic: HelpTopic;
/** Offset from the cursor to the tooltip. */
2023-12-28 14:04:44 +03:00
offset?: number;
/** Classname for padding. */
padding?: string;
/** Place of the tooltip in relation to the cursor. */
place?: PlacesType;
2025-03-07 22:05:12 +03:00
/** Classname for content wrapper. */
contentClass?: string;
}
/**
* 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) {
const showHelp = usePreferencesStore(state => state.showHelp);
2024-04-01 19:07:20 +03:00
if (!showHelp) {
return null;
}
return (
<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'
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>
</Tooltip>
2023-12-28 14:04:44 +03:00
</div>
);
}