ConceptPortal-public/rsconcept/frontend/src/components/shared/BadgeHelp.tsx

54 lines
1.7 KiB
TypeScript
Raw Normal View History

2024-12-05 15:46:23 +03:00
import React, { Suspense } from 'react';
import { PlacesType, Tooltip } from '@/components/Container';
import { TextURL } from '@/components/Control';
2025-01-28 23:23:42 +03:00
import { IconHelp } from '@/components/Icons';
import { Loader } from '@/components/Loader';
2025-01-28 23:23:42 +03:00
import { CProps } from '@/components/props';
import { HelpTopic } from '@/features/help/models/helpTopic';
import { usePreferencesStore } from '@/stores/preferences';
const TopicPage = React.lazy(() => import('@/features/help/pages/ManualsPage/TopicPage'));
2024-04-01 19:07:20 +03:00
interface BadgeHelpProps extends CProps.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;
}
/**
* Display help icon with a manual page tooltip.
*/
2024-10-29 12:06:43 +03:00
function BadgeHelp({ topic, padding = 'p-1', ...restProps }: BadgeHelpProps) {
const showHelp = usePreferencesStore(state => state.showHelp);
2024-04-01 19:07:20 +03:00
if (!showHelp) {
return null;
}
return (
2024-10-29 12:06:43 +03:00
<div tabIndex={-1} id={`help-${topic}`} className={padding}>
<IconHelp size='1.25rem' className='icon-primary' />
<Tooltip clickable anchorSelect={`#help-${topic}`} layer='z-modalTooltip' {...restProps}>
2024-12-05 15:46:23 +03:00
<Suspense fallback={<Loader />}>
<div className='relative' onClick={event => event.stopPropagation()}>
<div className='absolute right-0 text-sm top-[0.4rem] clr-input'>
<TextURL text='Справка...' href={`/manuals?topic=${topic}`} />
</div>
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>
);
}
2024-04-01 19:07:20 +03:00
export default BadgeHelp;