-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
71 lines (58 loc) · 2.16 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import streamlit as st
import base64
from streamlit.components.v1 import html
from PATHS import NAVBAR_PATHS
def inject_custom_css():
with open('assets/styles.css') as f:
st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True)
def get_current_route():
try:
return st.experimental_get_query_params()['nav'][0]
except:
return None
def navbar_component():
navbar_items = ''
for key, value in NAVBAR_PATHS.items():
navbar_items += (f'<a class="navitem" href="/?nav={value}">{key}</a>')
component = rf'''
<nav class="container navbar" id="navbar">
<ul class="navlist">
{navbar_items}
</ul>
<div class="dropdown" id="settingsDropDown">
<div id="myDropdown" class="dropdown-content">
</div>
</div>
</nav>
'''
st.markdown(component, unsafe_allow_html=True)
js = '''
<script>
// navbar elements
var navigationTabs = window.parent.document.getElementsByClassName("navitem");
var cleanNavbar = function(navigation_element) {
navigation_element.removeAttribute('target')
}
for (var i = 0; i < navigationTabs.length; i++) {
cleanNavbar(navigationTabs[i]);
}
// Dropdown hide / show
var dropdown = window.parent.document.getElementById("settingsDropDown");
dropdown.onclick = function() {
var dropWindow = window.parent.document.getElementById("myDropdown");
if (dropWindow.style.visibility == "hidden"){
dropWindow.style.visibility = "visible";
}else{
dropWindow.style.visibility = "hidden";
}
};
var settingsNavs = window.parent.document.getElementsByClassName("settingsNav");
var cleanSettings = function(navigation_element) {
navigation_element.removeAttribute('target')
}
for (var i = 0; i < settingsNavs.length; i++) {
cleanSettings(settingsNavs[i]);
}
</script>
'''
html(js)