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} tabIndex={-1}
/> />
), ),
// text: `Collections (${scPrefix} ⇧ C)`,
item: EActivityBarItems.Explorer, item: EActivityBarItems.Explorer,
tooltip: `Collections (${scPrefix} ⇧ C)`,
}, },
{ {
id: EActivityBarItems.Environment, id: EActivityBarItems.Environment,
@@ -52,8 +52,8 @@ const compositeBarItems = [
tabIndex={-1} tabIndex={-1}
/> />
), ),
// text: `Environment (${scPrefix} ⇧ E)`,
item: EActivityBarItems.Environment, item: EActivityBarItems.Environment,
tooltip: `Environment (${scPrefix} ⇧ E)`,
}, },
{ {
id: EActivityBarItems.History, id: EActivityBarItems.History,
@@ -66,8 +66,8 @@ const compositeBarItems = [
tabIndex={-1} tabIndex={-1}
/> />
), ),
// text: `History (${scPrefix} ⇧ H)`,
item: EActivityBarItems.History, item: EActivityBarItems.History,
tooltip: `History (${scPrefix} ⇧ H)`,
}, },
]; ];
@@ -106,8 +106,8 @@ const actionBarItems = [
tabIndex={-1} tabIndex={-1}
/> />
), ),
text: `User (${scPrefix} ⇧ U)`,
item: EActivityBarItems.User, item: EActivityBarItems.User,
tooltip: `User (${scPrefix} ⇧ U)`,
}, },
{ {
id: EActivityBarItems.Settings, id: EActivityBarItems.Settings,
@@ -118,8 +118,8 @@ const actionBarItems = [
tabIndex={-1} tabIndex={-1}
/> />
), ),
text: `Settings (${scPrefix} ⇧ /)`,
item: EActivityBarItems.Settings, 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 cx from 'classnames';
import { UserCircle2 } from 'lucide-react'; import { UserCircle2 } from 'lucide-react';
// import ReactTooltip from 'react-tooltip'; import Tooltip from '../tooltip/Tooltip';
const ActionItem: FC<IActionItem> = ({ const ActionItem: FC<IActionItem> = ({
id = '', id = '',
@@ -10,48 +10,70 @@ const ActionItem: FC<IActionItem> = ({
active = false, active = false,
onClick = () => {}, onClick = () => {},
icon = '', icon = '',
tooltip = '', tooltip,
}) => { }) => {
const Item = forwardRef<HTMLDivElement, IActionItem>(
(
{
active = false,
className = '',
style = {},
onClick = () => {},
icon = '',
},
ref
) => (
<div
tabIndex={1}
className={cx(
'h-12 flex justify-center items-center cursor-pointer relative text-2xl action-item',
{
'text-activityBar-foreground-inactive hover:text-activityBar-foreground':
active == false,
},
{
'before:block before:z-0 before:content-[""] before:absolute before:top-0 before:bottom-0 before:left-0 before:w-0.5 before:bg-activityBar-border-active text-activityBar-foreground bg-activityBar-background-active':
active == true,
},
className
)}
style={style}
onClick={onClick}
data-for={id}
ref={ref}
>
{!!icon ? icon : <UserCircle2 tabIndex={-1} data-for={id} />}
</div>
)
);
return ( return tooltip ? (
<div <Tooltip
tabIndex={1} arrowOffset={5}
className={cx( arrowSize={6}
'h-12 flex justify-center items-center cursor-pointer relative text-2xl action-item', arrowPosition="side"
{ label={tooltip}
'text-activityBar-foreground-inactive hover:text-activityBar-foreground': position="right"
active == false, withArrow={true}
},
{
'before:block before:z-0 before:content-[""] before:absolute before:top-0 before:bottom-0 before:left-0 before:w-0.5 before:bg-activityBar-border-active text-activityBar-foreground bg-activityBar-background-active':
active == true,
},
className
)}
style={style}
onClick={onClick}
data-tip={tooltip}
data-for={id}
> >
{!!icon ? ( <Item
icon active={active}
) : ( className={className}
<UserCircle2
/*title="Account"
size={24}*/
tabIndex={-1}
data-tip={tooltip}
data-for={id}
/>
)}
{/* @ts-ignore
<ReactTooltip
data-delay-hide='10000'
id={id} id={id}
className="bg-app-foreground-inactive" onClick={onClick}
place="right" style={style}
effect="float" /> */} icon={icon}
</div> />
</Tooltip>
) : (
<Item
active={active}
className={className}
id={id}
icon={icon}
onClick={onClick}
style={style}
/>
); );
}; };
@@ -89,7 +111,7 @@ export interface IActionItem {
/** /**
* Add a tooltip * Add a tooltip
*/ */
tooltip: string; tooltip?: string;
onClick: () => void; onClick: () => void;
} }

View File

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