Skip to content

Commit

Permalink
feat: enhance popover functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
georgi4444 committed Dec 21, 2024
1 parent d25365b commit 2ce7975
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 41 deletions.
23 changes: 2 additions & 21 deletions src/components/Accordions/AccordionBoxItems.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
'use client';

import { Accordion, AccordionItem } from '@nextui-org/accordion';
import { Button } from '@nextui-org/button';
import { Popover, PopoverContent, PopoverTrigger } from '@nextui-org/popover';
import { Spinner } from '@nextui-org/spinner';
import { useEffect, useState } from 'react';
import Highlighter from 'react-highlight-words';

import { AccordionContainerProps } from '@/domain/props/AccordionContainerProps';
import AccordionOperations from '@/operations/accordions/AccordionOperations';

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

/**
Expand Down Expand Up @@ -68,24 +66,7 @@ export default function AccordionBoxItems({
{item.infoIcon && <span className="w-[37px] h-[37px] p-[5.5px]">{item.infoIcon}</span>}
</Tooltip>
)}
{item.popoverInfo && (
<Popover>
<PopoverTrigger>
{item.infoIcon && (
<Button isIconOnly className="w-[37px] h-[37px] p-[5.5px]" variant="light">
{item.infoIcon}
</Button>
)}
</PopoverTrigger>
<PopoverContent>
<div className="p-2 max-w-[400px] prose prose-sm dark:prose-invert prose-headings:text-medium">
<ReadMore maxHeight={100} maxExpandedHeight={500}>
{item.popoverInfo}
</ReadMore>
</div>
</PopoverContent>
</Popover>
)}
{item.popoverInfo && <InfoPopover infoIcon={item.infoIcon} popoverInfo={item.popoverInfo} />}
{!item.tooltipInfo && !item.popoverInfo && item.infoIcon && (
<span className="w-[37px] h-[37px] p-[5.5px]">{item.infoIcon}</span>
)}
Expand Down
18 changes: 2 additions & 16 deletions src/components/Accordions/AccordionListItems.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
'use client';

import { Accordion, AccordionItem } from '@nextui-org/accordion';
import { Button } from '@nextui-org/button';
import { Popover, PopoverContent, PopoverTrigger } from '@nextui-org/popover';
import { Spinner } from '@nextui-org/spinner';
import { useEffect, useState } from 'react';
import Highlighter from 'react-highlight-words';

import { AccordionContainerProps } from '@/domain/props/AccordionContainerProps';
import AccordionOperations from '@/operations/accordions/AccordionOperations';

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

/**
Expand Down Expand Up @@ -62,20 +61,7 @@ export default function AccordionListItems({
{item.infoIcon && <span className="w-[37px] h-[37px] p-[5.5px]">{item.infoIcon}</span>}
</Tooltip>
)}
{item.popoverInfo && (
<Popover>
<PopoverTrigger>
{item.infoIcon && (
<Button isIconOnly className="w-[37px] h-[37px] p-[5.5px]" variant="light">
{item.infoIcon}
</Button>
)}
</PopoverTrigger>
<PopoverContent>
<div className="p-2 max-w-[400px] content">{item.popoverInfo}</div>
</PopoverContent>
</Popover>
)}
{item.popoverInfo && <InfoPopover infoIcon={item.infoIcon} popoverInfo={item.popoverInfo} />}
</div>
}
>
Expand Down
31 changes: 31 additions & 0 deletions src/components/InfoPopover/InfoPopover.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Button } from '@nextui-org/button';
import { Popover, PopoverContent, PopoverTrigger } from '@nextui-org/popover';
import React from 'react';

import CustomInfoCircle from '../CustomInfoCircle/CustomInfoCircle';
import { ReadMore } from '../ReadMore/ReadMore';

export function InfoPopover({
infoIcon = <CustomInfoCircle />,
popoverInfo,
}: {
infoIcon?: React.ReactNode;
popoverInfo: React.ReactNode;
}) {
return (
<Popover className="m-2">
<PopoverTrigger>
<Button isIconOnly radius="full" className="w-[37px] h-[37px]" variant="light">
{infoIcon}
</Button>
</PopoverTrigger>
<PopoverContent>
<div className="p-2 max-w-[250px] prose prose-sm dark:prose-invert prose-headings:text-medium">
<ReadMore maxHeight={100} maxExpandedHeight={200}>
{popoverInfo}
</ReadMore>
</div>
</PopoverContent>
</Popover>
);
}
12 changes: 8 additions & 4 deletions src/components/Legend/LegendContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useMediaQuery } from '@/utils/resolution';

import AccordionContainer from '../Accordions/AccordionContainer';
import CustomInfoCircle from '../CustomInfoCircle/CustomInfoCircle';
import { InfoPopover } from '../InfoPopover/InfoPopover';
import PopupModal from '../PopupModal/PopupModal';
import { Tooltip } from '../Tooltip/Tooltip';
import GradientLegend from './GradientLegend';
Expand Down Expand Up @@ -61,15 +62,18 @@ export default function LegendContainer({ items, loading = false }: LegendContai
{items.map((item) =>
LegendOperations.isGradientLegendContainerItem(item) ? (
<>
<div key={item.title} className="font-bold">
{item.title}
<div key={item.title} className="flex justify-between w-full">
<div className="font-bold">{item.title}</div>
<InfoPopover popoverInfo={item.popoverInfo} />
</div>

<GradientLegend key={item.title} {...item} />
</>
) : (
<>
<div key={item.title} className="font-bold">
{item.title}
<div key={item.title} className="flex justify-between w-full">
<div className="font-bold">{item.title}</div>
<InfoPopover popoverInfo={item.popoverInfo} />
</div>
<PointLegend key={item.title} {...item}>
{item.renderItem ? (props) => item.renderItem?.(props) : undefined}
Expand Down

0 comments on commit 2ce7975

Please sign in to comment.