Skip to content

Commit

Permalink
feat: add tooltip to the collapsed sidebar (#179)
Browse files Browse the repository at this point in the history
Co-authored-by: Armanpreet Ghotra <[email protected]>
  • Loading branch information
ArmanpreetGhotra and Armanpreet Ghotra authored Jan 14, 2025
1 parent 9dd2085 commit e5f0c05
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
28 changes: 16 additions & 12 deletions src/components/Sidebar/CollapsedSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { GlobalInsight } from '@/domain/enums/GlobalInsight.ts';
import { CollapsedSidebarProps } from '@/domain/props/CollapsedSidebarProps';
import { SidebarOperations } from '@/operations/sidebar/SidebarOperations';

import { Tooltip } from '../Tooltip/Tooltip';

export function CollapsedSidebar({ mapDataFetching }: CollapsedSidebarProps) {
const { toggleSidebar } = useSidebar();
const { selectedMapType, setSelectedMapType } = useSelectedMap();
Expand All @@ -32,18 +34,20 @@ export function CollapsedSidebar({ mapDataFetching }: CollapsedSidebarProps) {
<CardBody>
<div className="flex flex-col gap-1">
{SidebarOperations.getSidebarMapTypes().map((item) => (
<Button
isIconOnly
key={item.key}
variant={selectedMapType === item.key ? undefined : 'light'}
className={selectedMapType === item.key ? 'bg-primary' : undefined}
onClick={() => onMapTypeSelect(item.key)}
>
<div className="flex items-center justify-center relative">
<NextImage unoptimized loading="eager" src={item.icon} alt={item.label} width={24} height={24} />
{mapDataFetching[item.key] && <Spinner className="absolute" color="white" />}
</div>
</Button>
<Tooltip text={item.label} placement="right">
<Button
isIconOnly
key={item.key}
variant={selectedMapType === item.key ? undefined : 'light'}
className={selectedMapType === item.key ? 'bg-primary' : undefined}
onClick={() => onMapTypeSelect(item.key)}
>
<div className="flex items-center justify-center relative">
<NextImage unoptimized loading="eager" src={item.icon} alt={item.label} width={24} height={24} />
{mapDataFetching[item.key] && <Spinner className="absolute" color="white" />}
</div>
</Button>
</Tooltip>
))}
</div>
</CardBody>
Expand Down
14 changes: 13 additions & 1 deletion src/components/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,20 @@ import TooltipProps from '@/domain/props/TooltipProps';
* @param {string} props.titleStyle tailwind classes to style the title (optional)
* @param {string} props.textStyle tailwind classes to style the text (optional)
* @param {number} props.offset offset of the tooltip, default is set to 10 (optional)
* @param {TooltipPlacement} props.placement placement of the tooltip, default is set to 'top' (optional)
* @constructor
*/
export function Tooltip({ children, title, text, delay, warning, titleStyle, textStyle, offset = 10 }: TooltipProps) {
export function Tooltip({
children,
title,
text,
delay,
warning,
titleStyle,
textStyle,
offset = 10,
placement,
}: TooltipProps) {
const RADIUS = 'sm';
const SHADOW = 'md';
const COLOR = 'default';
Expand All @@ -43,6 +54,7 @@ export function Tooltip({ children, title, text, delay, warning, titleStyle, tex
offset={offset}
radius={RADIUS}
shadow={SHADOW}
placement={placement}
>
{Array.isArray(children) ? <div> {...children} </div> : children}
</NextUITooltip>
Expand Down
2 changes: 2 additions & 0 deletions src/domain/props/TooltipProps.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TooltipPlacement } from '@nextui-org/tooltip';
import { ReactNode } from 'react';

export default interface TooltipProps {
Expand All @@ -9,4 +10,5 @@ export default interface TooltipProps {
titleStyle?: string;
textStyle?: string;
offset?: number;
placement?: TooltipPlacement;
}

0 comments on commit e5f0c05

Please sign in to comment.