-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: menu collapse global css (#278)
# Motivation Prefer usage of global CSS instead of JS to define the "collapsed" state of the menu, this to avoid glitch when deployed on mainnet.
- Loading branch information
1 parent
e5a968e
commit 969b784
Showing
10 changed files
with
185 additions
and
73 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { Menu } from "$lib/types/menu"; | ||
import { applyMenu, initMenu } from "$lib/utils/menu.utils"; | ||
import { writable } from "svelte/store"; | ||
|
||
const initialMenu: Menu | undefined = initMenu(); | ||
|
||
export const initMenuStore = () => { | ||
const { subscribe, set } = writable<Menu | undefined>(initialMenu); | ||
|
||
return { | ||
subscribe, | ||
|
||
select: (menu: Menu) => { | ||
applyMenu({ menu, preserve: true }); | ||
set(menu); | ||
}, | ||
}; | ||
}; | ||
|
||
export const menuStore = initMenuStore(); |
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,87 @@ | ||
@use "../mixins/media"; | ||
|
||
:root { | ||
div.split-pane, | ||
div.stretch-pane { | ||
div[role="menu"]:first-child { | ||
--menu-width: var(--menu-expanded-width); | ||
|
||
button { | ||
&.menu-expand, | ||
&.menu-collapse { | ||
opacity: 0; | ||
visibility: hidden; | ||
transition: opacity var(--animation-time-long); | ||
|
||
padding: var(--padding-1_5x); | ||
} | ||
|
||
&.menu-collapse { | ||
position: absolute; | ||
right: 0; | ||
bottom: 64px; | ||
transform: rotate(-180deg); | ||
} | ||
} | ||
|
||
[role="menuitem"] { | ||
span, | ||
div { | ||
opacity: 1; | ||
transition: opacity var(--animation-time-normal); | ||
} | ||
} | ||
|
||
.menu-background { | ||
visibility: visible; | ||
opacity: 1; | ||
transition: opacity var(--animation-time-normal); | ||
} | ||
} | ||
} | ||
|
||
&[menu="collapsed"] { | ||
div.split-pane, | ||
div.stretch-pane { | ||
div[role="menu"]:first-child:not(.open) { | ||
--menu-width: var(--menu-collapsed-width); | ||
|
||
.inner { | ||
overflow-x: hidden; | ||
} | ||
|
||
@include media.min-width(large) { | ||
button.menu-expand { | ||
opacity: 1; | ||
visibility: visible; | ||
} | ||
} | ||
|
||
[role="menuitem"] { | ||
span, | ||
div { | ||
opacity: 0; | ||
} | ||
} | ||
|
||
.menu-background *:not(.background) { | ||
opacity: 0; | ||
} | ||
} | ||
} | ||
} | ||
|
||
&:not([menu="collapsed"]) { | ||
div.split-pane, | ||
div.stretch-pane { | ||
div[role="menu"]:first-child { | ||
@include media.min-width(large) { | ||
button.menu-collapse { | ||
opacity: 1; | ||
visibility: visible; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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,4 @@ | ||
export enum Menu { | ||
COLLAPSED = "collapsed", | ||
EXPANDED = "expanded", | ||
} |
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,43 @@ | ||
import { Menu } from "$lib/types/menu"; | ||
import { isNode } from "$lib/utils/env.utils"; | ||
import { enumFromStringExists } from "./enum.utils"; | ||
|
||
export const MENU_ATTRIBUTE = "menu"; | ||
export const LOCALSTORAGE_MENU_KEY = "nnsMenu"; | ||
|
||
export const initMenu = (): Menu | undefined => { | ||
// No DOM therefore cannot guess the menu | ||
if (isNode()) { | ||
return undefined; | ||
} | ||
|
||
const menu: string | null = | ||
document.documentElement.getAttribute(MENU_ATTRIBUTE); | ||
|
||
const initialMenu: Menu = enumFromStringExists({ | ||
obj: Menu, | ||
value: menu, | ||
}) | ||
? (menu as Menu) | ||
: Menu.EXPANDED; | ||
|
||
applyMenu({ menu: initialMenu, preserve: false }); | ||
|
||
return initialMenu; | ||
}; | ||
|
||
export const applyMenu = ({ | ||
menu, | ||
preserve = true, | ||
}: { | ||
menu: Menu; | ||
preserve?: boolean; | ||
}) => { | ||
const { documentElement } = document; | ||
|
||
documentElement.setAttribute(MENU_ATTRIBUTE, menu); | ||
|
||
if (preserve) { | ||
localStorage.setItem(LOCALSTORAGE_MENU_KEY, JSON.stringify(menu)); | ||
} | ||
}; |