forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adds overflow menu * moves settings from navigation bar to the overflow menu * pressing escape closes menu note: There is a warning from react router which I think we can safely ignore, because we are using a different source for the location of the menu router from it's parent one.
- Loading branch information
1 parent
3c65b52
commit ddd7538
Showing
17 changed files
with
256 additions
and
10 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
wallet/src/ui/app/components/menu/button/MenuButton.module.scss
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,55 @@ | ||
@use '_variables' as v; | ||
|
||
$btn-width: 20px; | ||
$btn-height: 14px; | ||
$line-height: 2px; | ||
|
||
.button { | ||
background: none; | ||
outline: none; | ||
border: none; | ||
width: $btn-width; | ||
height: $btn-height; | ||
position: relative; | ||
cursor: pointer; | ||
padding: 0; | ||
} | ||
|
||
.line { | ||
width: $btn-width; | ||
height: $line-height; | ||
background-color: v.use(v.$colors-menu-btn-color); | ||
transition-property: opacity, transform, top; | ||
transition-duration: 0.2s; | ||
transition-timing-function: ease-in-out; | ||
display: block; | ||
position: absolute; | ||
border-radius: 10px; | ||
|
||
&.line-1 { | ||
top: 0; | ||
} | ||
|
||
&.line-2 { | ||
top: calc(50% - ($line-height / 2)); | ||
} | ||
|
||
&.line-3 { | ||
bottom: 0; | ||
} | ||
} | ||
|
||
.open { | ||
> .line-1 { | ||
top: calc(50% - ($line-height / 2)); | ||
transform: rotate(45deg); | ||
} | ||
|
||
> .line-2 { | ||
transform: rotate(-45deg); | ||
} | ||
|
||
> .line-3 { | ||
opacity: 0; | ||
} | ||
} |
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,31 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import cl from 'classnames'; | ||
import { memo } from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
import { useMenuIsOpen, useNextMenuUrl } from '_components/menu/hooks'; | ||
|
||
import st from './MenuButton.module.scss'; | ||
|
||
export type MenuButtonProps = { | ||
className?: string; | ||
}; | ||
|
||
function MenuButton({ className }: MenuButtonProps) { | ||
const isOpen = useMenuIsOpen(); | ||
const menuUrl = useNextMenuUrl(!isOpen, '/'); | ||
return ( | ||
<Link | ||
className={cl(st.button, { [st.open]: isOpen }, className)} | ||
to={menuUrl} | ||
> | ||
<span className={cl(st.line, st.line1)} /> | ||
<span className={cl(st.line, st.line2)} /> | ||
<span className={cl(st.line, st.line3)} /> | ||
</Link> | ||
); | ||
} | ||
|
||
export default memo(MenuButton); |
25 changes: 25 additions & 0 deletions
25
wallet/src/ui/app/components/menu/content/MenuContent.module.scss
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,25 @@ | ||
@use '_values/colors'; | ||
@use '_variables' as v; | ||
|
||
.container { | ||
position: absolute; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
|
||
.backdrop { | ||
position: absolute; | ||
width: 100%; | ||
height: 100%; | ||
background-color: colors.$gray-100; | ||
opacity: 0.8; | ||
} | ||
|
||
.content { | ||
position: relative; | ||
padding: 20px 25px 25px; | ||
background-color: v.use(v.$colors-main-content-background); | ||
border-radius: 20px; | ||
max-height: 100%; | ||
overflow-y: auto; | ||
} |
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,56 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { useCallback } from 'react'; | ||
import { Navigate, Route, Routes, useNavigate } from 'react-router-dom'; | ||
|
||
import Settings from './settings'; | ||
import { | ||
useMenuIsOpen, | ||
useMenuUrl, | ||
useNextMenuUrl, | ||
} from '_components/menu/hooks'; | ||
import { useOnKeyboardEvent } from '_hooks'; | ||
|
||
import type { MouseEvent } from 'react'; | ||
|
||
import st from './MenuContent.module.scss'; | ||
|
||
const CLOSE_KEY_CODES: string[] = ['Escape']; | ||
|
||
function MenuContent() { | ||
const isOpen = useMenuIsOpen(); | ||
const menuUrl = useMenuUrl(); | ||
const menuHomeUrl = useNextMenuUrl(true, '/settings'); | ||
const closeMenuUrl = useNextMenuUrl(false); | ||
const navigate = useNavigate(); | ||
const handleOnCloseMenu = useCallback( | ||
(e: KeyboardEvent | MouseEvent<HTMLDivElement>) => { | ||
if (isOpen) { | ||
e.preventDefault(); | ||
navigate(closeMenuUrl); | ||
} | ||
}, | ||
[isOpen, navigate, closeMenuUrl] | ||
); | ||
useOnKeyboardEvent('keydown', CLOSE_KEY_CODES, handleOnCloseMenu, isOpen); | ||
if (!isOpen) { | ||
return null; | ||
} | ||
return ( | ||
<div className={st.container}> | ||
<div className={st.backdrop} onClick={handleOnCloseMenu} /> | ||
<div className={st.content}> | ||
<Routes location={menuUrl || ''}> | ||
<Route path="settings" element={<Settings />} /> | ||
<Route | ||
path="*" | ||
element={<Navigate to={menuHomeUrl} replace={true} />} | ||
/> | ||
</Routes> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default MenuContent; |
File renamed without changes.
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,40 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { useMemo } from 'react'; | ||
import { useLocation, useSearchParams } from 'react-router-dom'; | ||
|
||
const MENU_PARAM = 'menu'; | ||
|
||
export function useMenuUrl() { | ||
const [searchParams] = useSearchParams(); | ||
if (searchParams.has(MENU_PARAM)) { | ||
return searchParams.get(MENU_PARAM) || '/'; | ||
} | ||
return false; | ||
} | ||
|
||
export function useMenuIsOpen() { | ||
const [searchParams] = useSearchParams(); | ||
return searchParams.has(MENU_PARAM); | ||
} | ||
|
||
/** | ||
* Get the URL that contains the background page and the menu location | ||
* | ||
* @param isOpen Indicates if the menu will be open | ||
* @param nextMenuLocation The location within the menu | ||
*/ | ||
export function useNextMenuUrl(isOpen: boolean, nextMenuLocation = '/') { | ||
const [searchParams] = useSearchParams(); | ||
const { pathname } = useLocation(); | ||
return useMemo(() => { | ||
if (isOpen) { | ||
searchParams.set(MENU_PARAM, nextMenuLocation); | ||
} else { | ||
searchParams.delete(MENU_PARAM); | ||
} | ||
const search = searchParams.toString(); | ||
return `${pathname}${search ? '?' : ''}${search}`; | ||
}, [isOpen, nextMenuLocation, searchParams, pathname]); | ||
} |
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,5 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export { default as MenuButton } from './button'; | ||
export { default as MenuContent } from './content'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { useEffect } from 'react'; | ||
|
||
function useOnKeyboardEvent<K extends 'keydown' | 'keyup' | 'keypress'>( | ||
eventType: K, | ||
keys: string[], | ||
handler: (e: KeyboardEvent) => void, | ||
enabled = true | ||
) { | ||
useEffect(() => { | ||
if (enabled) { | ||
const listener = (e: KeyboardEvent) => { | ||
if (keys.includes(e.key)) { | ||
handler(e); | ||
} | ||
}; | ||
|
||
document.addEventListener(eventType, listener); | ||
|
||
return () => { | ||
document.removeEventListener(eventType, listener); | ||
}; | ||
} | ||
}, [eventType, keys, handler, enabled]); | ||
} | ||
|
||
export default useOnKeyboardEvent; |
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
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