feat: integrate tooltip component with sidebar

This commit is contained in:
Dhoni77
2023-10-08 11:16:14 +05:30
parent 88f5ba1d11
commit 5599571ce2
3 changed files with 81 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,48 +10,70 @@ const ActionItem: FC<IActionItem> = ({
active = false,
onClick = () => {},
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 (
<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-tip={tooltip}
data-for={id}
return tooltip ? (
<ToolTip
arrowOffset={5}
arrowSize={6}
arrowPosition="side"
label={tooltip}
postition="top"
withArrow={true}
>
{!!icon ? (
icon
) : (
<UserCircle2
/*title="Account"
size={24}*/
tabIndex={-1}
data-tip={tooltip}
data-for={id}
/>
)}
{/* @ts-ignore
<ReactTooltip
data-delay-hide='10000'
<Item
active={active}
className={className}
id={id}
className="bg-app-foreground-inactive"
place="right"
effect="float" /> */}
</div>
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[];
}