Merge pull request #104 from Dhoni77/feat/Tooltip

feat: add a tooltip component and show the tooltip on the action bar item

Closes #103
- Added Tooltip component from mantine library
- Added a tooltip to the sidebar
This commit is contained in:
Nishchit
2023-10-18 17:04:20 +05:30
committed by GitHub
4 changed files with 117 additions and 63 deletions

View File

@@ -38,8 +38,8 @@ const compositeBarItems = [
tabIndex={-1}
/>
),
// text: `Collections (${scPrefix} ⇧ C)`,
item: EActivityBarItems.Explorer,
tooltip: `Collections (${scPrefix} ⇧ C)`,
},
{
id: EActivityBarItems.Environment,
@@ -52,8 +52,8 @@ const compositeBarItems = [
tabIndex={-1}
/>
),
// text: `Environment (${scPrefix} ⇧ E)`,
item: EActivityBarItems.Environment,
tooltip: `Environment (${scPrefix} ⇧ E)`,
},
{
id: EActivityBarItems.History,
@@ -66,8 +66,8 @@ const compositeBarItems = [
tabIndex={-1}
/>
),
// text: `History (${scPrefix} ⇧ H)`,
item: EActivityBarItems.History,
tooltip: `History (${scPrefix} ⇧ H)`,
},
];
@@ -106,8 +106,8 @@ const actionBarItems = [
tabIndex={-1}
/>
),
text: `User (${scPrefix} ⇧ U)`,
item: EActivityBarItems.User,
tooltip: `User (${scPrefix} ⇧ U)`,
},
{
id: EActivityBarItems.Settings,
@@ -118,8 +118,8 @@ const actionBarItems = [
tabIndex={-1}
/>
),
text: `Settings (${scPrefix} ⇧ /)`,
item: EActivityBarItems.Settings,
tooltip: `Settings (${scPrefix} ⇧ /)`,
},
];

View File

@@ -1,7 +1,7 @@
import { FC } from 'react';
import { FC, forwardRef } from 'react';
import cx from 'classnames';
import { UserCircle2 } from 'lucide-react';
// import ReactTooltip from 'react-tooltip';
import Tooltip from '../tooltip/Tooltip';
const ActionItem: FC<IActionItem> = ({
id = '',
@@ -10,10 +10,19 @@ const ActionItem: FC<IActionItem> = ({
active = false,
onClick = () => {},
icon = '',
tooltip = '',
tooltip,
}) => {
return (
const Item = forwardRef<HTMLDivElement, IActionItem>(
(
{
active = false,
className = '',
style = {},
onClick = () => {},
icon = '',
},
ref
) => (
<div
tabIndex={1}
className={cx(
@@ -30,28 +39,41 @@ const ActionItem: FC<IActionItem> = ({
)}
style={style}
onClick={onClick}
data-tip={tooltip}
data-for={id}
ref={ref}
>
{!!icon ? (
icon
) : (
<UserCircle2
/*title="Account"
size={24}*/
tabIndex={-1}
data-tip={tooltip}
data-for={id}
/>
)}
{/* @ts-ignore
<ReactTooltip
data-delay-hide='10000'
id={id}
className="bg-app-foreground-inactive"
place="right"
effect="float" /> */}
{!!icon ? icon : <UserCircle2 tabIndex={-1} data-for={id} />}
</div>
)
);
return tooltip ? (
<Tooltip
arrowOffset={5}
arrowSize={6}
arrowPosition="side"
label={tooltip}
position="right"
withArrow={true}
>
<Item
active={active}
className={className}
id={id}
onClick={onClick}
style={style}
icon={icon}
/>
</Tooltip>
) : (
<Item
active={active}
className={className}
id={id}
icon={icon}
onClick={onClick}
style={style}
/>
);
};
@@ -89,7 +111,7 @@ export interface IActionItem {
/**
* Add a tooltip
*/
tooltip: string;
tooltip?: string;
onClick: () => void;
}

View File

@@ -4,52 +4,48 @@ import ActionItem from './ActionItem';
const ActionItems: FC<IActionItems> = ({
items = [],
activeItem = '',
onClickItem = () => { }
onClickItem = () => {},
}) => {
return (
<Fragment>
{items.map((item: any, i: number) =>
(
{items.map((item: any, i: number) => (
<ActionItem
id={item.id}
icon={item.icon}
tooltip={item.text}
tooltip={item.tooltip}
key={i}
active={activeItem === item.id}
onClick={() => {
onClickItem(item)
onClickItem(item);
}}
/>
)
)}
))}
</Fragment>
);
};
export default ActionItems
export default ActionItems;
ActionItems.defaultProps = {
id: '',
className: '',
items: []
items: [],
};
export interface IActionItems {
activeItem?: string;
activeItem?: string,
onClickItem: (action: any) => void,
onClickItem: (action: any) => void;
/**
* Is this the principal call to action on the page?
*/
id?: string,
id?: string;
/**
* Add class name to show custom styling
*/
className?: string,
className?: string;
/**
* to show list of action items
*/
items?: any[]
items?: any[];
}

View File

@@ -0,0 +1,36 @@
import { FC } from 'react';
import { MantineColor, Tooltip as MantineTooltip } from '@mantine/core';
import { ArrowPosition, FloatingPosition } from '@mantine/core/lib/Floating';
interface ITooltip {
arrowOffset?: number;
arrowPosition?: ArrowPosition;
arrowRadius?: number;
arrowSize?: number;
children: React.ReactNode;
closeDelay?: number;
color?: MantineColor;
disabled?: boolean;
events?: {
hover: boolean;
focus: boolean;
touch: boolean;
};
label: React.ReactNode;
multiline?: boolean;
offset?: number;
openDelay?: number;
position?: FloatingPosition;
withArrow?: boolean;
}
const Tooltip: FC<ITooltip> = ({ label, children, ...props }) => {
return (
<MantineTooltip label={label} {...props}>
{children}
</MantineTooltip>
);
};
export default Tooltip;