-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c78645a
commit 951e4de
Showing
7 changed files
with
381 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
import React, {useRef, useState} from 'react'; | ||
import {VscChevronDown} from '@react-icons/all-files/vsc/VscChevronDown'; | ||
import type {configOptions} from '../config'; | ||
import useClickAway from 'react-use/lib/useClickAway'; | ||
|
||
interface Props { | ||
defaultProfile: string; | ||
profiles: configOptions['profiles']; | ||
openNewTab: (name: string) => void; | ||
backgroundColor: string; | ||
borderColor: string; | ||
tabsVisible: boolean; | ||
} | ||
const isMac = /Mac/.test(navigator.userAgent); | ||
|
||
const DropdownButton = ({defaultProfile, profiles, openNewTab, backgroundColor, borderColor, tabsVisible}: Props) => { | ||
const [dropdownOpen, setDropdownOpen] = useState(false); | ||
const ref = useRef(null); | ||
|
||
const toggleDropdown = () => { | ||
setDropdownOpen(!dropdownOpen); | ||
}; | ||
|
||
useClickAway(ref, () => { | ||
setDropdownOpen(false); | ||
}); | ||
|
||
return ( | ||
<div | ||
ref={ref} | ||
title="New Tab" | ||
className={`new_tab ${tabsVisible ? 'tabs_visible' : 'tabs_hidden'}`} | ||
onClick={toggleDropdown} | ||
onDoubleClick={(e) => e.stopPropagation()} | ||
onBlur={() => setDropdownOpen(false)} | ||
> | ||
<VscChevronDown style={{verticalAlign: 'middle'}} /> | ||
|
||
{dropdownOpen && ( | ||
<ul | ||
key="dropdown" | ||
className="profile_dropdown" | ||
style={{ | ||
borderColor, | ||
backgroundColor | ||
}} | ||
> | ||
{profiles.map((profile) => ( | ||
<li | ||
key={profile.name} | ||
onClick={() => { | ||
openNewTab(profile.name); | ||
setDropdownOpen(false); | ||
}} | ||
className={`profile_dropdown_item ${ | ||
profile.name === defaultProfile && profiles.length > 1 ? 'profile_dropdown_item_default' : '' | ||
}`} | ||
> | ||
{profile.name} | ||
</li> | ||
))} | ||
</ul> | ||
)} | ||
|
||
<style jsx>{` | ||
.profile_dropdown { | ||
border-width: 1px; | ||
border-style: solid; | ||
border-bottom-width: 0px; | ||
border-right-width: 0px; | ||
position: absolute; | ||
top: 33px; | ||
right: 0px; | ||
z-index: 1000; | ||
padding: 0px; | ||
margin: 0px; | ||
list-style-type: none; | ||
white-space: nowrap; | ||
min-width: 120px; | ||
} | ||
.profile_dropdown_item { | ||
padding: 0px 20px; | ||
height: 34px; | ||
line-height: 34px; | ||
cursor: pointer; | ||
font-size: 12px; | ||
color: #fff; | ||
background-color: transparent; | ||
border-width: 0px; | ||
border-style: solid; | ||
border-color: transparent; | ||
border-bottom-width: 1px; | ||
border-bottom-style: solid; | ||
border-bottom-color: ${borderColor}; | ||
text-align: start; | ||
text-transform: capitalize; | ||
} | ||
.profile_dropdown_item:hover { | ||
background-color: ${borderColor}; | ||
} | ||
.profile_dropdown_item_default { | ||
font-weight: bold; | ||
} | ||
.new_tab { | ||
background: transparent; | ||
color: #fff; | ||
border-left: 1px; | ||
border-bottom: 1px; | ||
border-left-style: solid; | ||
border-bottom-style: solid; | ||
border-left-width: 1px; | ||
border-bottom-width: 1px; | ||
cursor: pointer; | ||
font-size: 12px; | ||
height: 34px; | ||
line-height: 34px; | ||
padding: 0 16px; | ||
position: relative; | ||
text-align: center; | ||
-webkit-user-select: none; | ||
-webkit-app-region: ${isMac ? 'drag' : ''}; | ||
top: ${isMac ? '0px' : '34px'}; | ||
} | ||
.tabs_visible { | ||
border-color: ${borderColor}; | ||
} | ||
.tabs_hidden { | ||
border-color: transparent; | ||
position: absolute; | ||
right: 0; | ||
} | ||
.tabs_hidden:hover { | ||
border-color: ${borderColor}; | ||
} | ||
`}</style> | ||
</div> | ||
); | ||
}; | ||
|
||
export default DropdownButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.