feat: menu icon + dropdown in collection item

This commit is contained in:
Anoop M D 2021-12-11 01:58:44 +05:30
parent 6d71393069
commit 1b3d9e5854
4 changed files with 59 additions and 5 deletions

View File

@ -24,6 +24,7 @@
"@fortawesome/fontawesome-svg-core": "^1.2.36", "@fortawesome/fontawesome-svg-core": "^1.2.36",
"@fortawesome/free-solid-svg-icons": "^5.15.4", "@fortawesome/free-solid-svg-icons": "^5.15.4",
"@fortawesome/react-fontawesome": "^0.1.16", "@fortawesome/react-fontawesome": "^0.1.16",
"@tabler/icons": "^1.46.0",
"classnames": "^2.3.1", "classnames": "^2.3.1",
"codemirror": "^5.64.0", "codemirror": "^5.64.0",
"escape-html": "^1.0.3", "escape-html": "^1.0.3",

View File

@ -1,6 +1,12 @@
import styled from 'styled-components'; import styled from 'styled-components';
const Wrapper = styled.div` const Wrapper = styled.div`
.menu-icon {
display: none;
flex-grow: 1;
justify-content: flex-end;
}
.collection-item-name { .collection-item-name {
height: 1.875rem; height: 1.875rem;
cursor: pointer; cursor: pointer;
@ -10,9 +16,21 @@ const Wrapper = styled.div`
transform: rotateZ(90deg); transform: rotateZ(90deg);
} }
&.item-focused-in-tab, &:hover { &.item-focused-in-tab {
background:#ededed; background:#ededed;
} }
&:hover {
background: #f7f7f7;
.menu-icon {
display: flex;
}
}
div.tippy-box {
position: relative;
top: -0.625rem;
}
} }
`; `;

View File

@ -1,11 +1,22 @@
import React from 'react'; import React, { useRef, forwardRef } from 'react';
import range from 'lodash/range'; import range from 'lodash/range';
import { IconChevronRight } from '@tabler/icons'; import get from 'lodash/get';
import { IconChevronRight, IconDots } from '@tabler/icons';
import classnames from 'classnames'; import classnames from 'classnames';
import Dropdown from '../../../../Dropdown';
import StyledWrapper from './StyledWrapper'; import StyledWrapper from './StyledWrapper';
const CollectionItem = ({item, collectionId, actions, dispatch, activeRequestTabId}) => { const CollectionItem = ({item, collectionId, actions, dispatch, activeRequestTabId}) => {
const dropdownTippyRef = useRef();
const MenuIcon = forwardRef((props, ref) => {
return (
<div ref={ref}>
<IconDots size={22} style={{color: 'rgb(110 110 110)'}}/>
</div>
);
});
const iconClassName = classnames({ const iconClassName = classnames({
'rotate-90': item.collapsed 'rotate-90': item.collapsed
@ -15,7 +26,12 @@ const CollectionItem = ({item, collectionId, actions, dispatch, activeRequestTab
'item-focused-in-tab': item.id == activeRequestTabId 'item-focused-in-tab': item.id == activeRequestTabId
}); });
const handleClick = () => { const handleClick = (event) => {
let tippyEl = get(dropdownTippyRef, 'current.reference');
if(tippyEl && tippyEl.contains && tippyEl.contains(event.target)) {
return;
}
dispatch({ dispatch({
type: actions.SIDEBAR_COLLECTION_ITEM_CLICK, type: actions.SIDEBAR_COLLECTION_ITEM_CLICK,
itemId: item.id, itemId: item.id,
@ -25,6 +41,12 @@ const CollectionItem = ({item, collectionId, actions, dispatch, activeRequestTab
let indents = range(item.depth); let indents = range(item.depth);
const onDropdownCreate = (ref) => dropdownTippyRef.current = ref;
const stopEventPropogation = (event) => {
event.stopPropagation();
};
return ( return (
<StyledWrapper className="flex flex-col"> <StyledWrapper className="flex flex-col">
<div <div
@ -60,6 +82,19 @@ const CollectionItem = ({item, collectionId, actions, dispatch, activeRequestTab
<span className="ml-1">{item.name}</span> <span className="ml-1">{item.name}</span>
</div> </div>
<div className="menu-icon pr-2">
<Dropdown onCreate={onDropdownCreate} icon={<MenuIcon />} placement='bottom-start'>
<div>
<div className="dropdown-item" onClick={(e) => {
dropdownTippyRef.current.hide();
stopEventPropogation(e);
console.log('Clicked');
}}>
Add Request
</div>
</div>
</Dropdown>
</div>
</div> </div>
</div> </div>

View File

@ -9,7 +9,7 @@ const Sidebar = ({collections, actions, dispatch, activeRequestTabId}) => {
<Navbar /> <Navbar />
<div className="mt-4 px-2 flex"> <div className="mt-4 px-2 flex">
<IconDatabase size={20} strokeWidth={1.5}/> <IconDatabase size={20} strokeWidth={1.5}/>
<span className="ml-1">No Environment</span> <span className="ml-2">No Environment</span>
</div> </div>
<div className="mt-4 relative collection-filter px-2"> <div className="mt-4 relative collection-filter px-2">