-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathdashboardNavbar.R
189 lines (168 loc) · 4.51 KB
/
dashboardNavbar.R
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#' Create a Boostrap 4 dashboard navbar
#'
#' Build a tabler dashboard page
#'
#' @param id Navbar id.
#' @param ... Navbar content.
#' @param src Brand image url or path.
#' @param navMenu Slot for \link{tablerNavMenu}
#'
#' @author David Granjon, \email{dgranjon@@ymail.com}
#'
#' @export
tablerDashNav <- function(id, ..., src = NULL, navMenu = NULL) {
headerTag <- shiny::tags$div(
class = "header py-4",
shiny::tags$div(
class = "container",
shiny::tags$div(
class = "d-flex",
# header brand
shiny::tags$a(
class = "header-brand",
href = "#",
shiny::img(src = src, class = "header-brand-img")
),
# navbar content
shiny::tags$div(
class = "d-flex order-lg-2 ml-auto",
lapply(list(...), shiny::tagAppendAttributes, class = "mx-2")
),
# header toggle
if (!is.null(navMenu)) {
shiny::tags$a(
href = "#",
class = "header-toggler d-lg-none ml-3 ml-lg-0",
`data-toggle` = "collapse",
`data-target` = paste0("#", id),
shiny::tags$span(class="header-toggler-icon")
)
}
)
)
)
navTag <- if (!is.null(navMenu)) {
shiny::tags$div(
class = "header collapse d-lg-flex p-0",
id = id,
shiny::tags$div(
class = "container",
shiny::tags$div(
class = "row align-items-center",
# navigation
shiny::tags$div(
class = "col-lg order-lg-first",
navMenu
)
)
)
)
}
shiny::tagList(headerTag, navTag)
}
#' Create a Boostrap 4 dashboard navbar menu
#'
#' Build a tabler dashboard main navbar menu
#'
#' @param ... Slot for \link{tablerNavMenuItem}.
#'
#' @author David Granjon, \email{dgranjon@@ymail.com}
#'
#' @export
tablerNavMenu <- function(...){
shiny::tags$ul(
class = "nav nav-tabs border-0 flex-column flex-lg-row",
...
)
}
#' Create a Boostrap 4 dashboard navbar menu item
#'
#' Build a tabler dashboard navbar menu item
#'
#' @param ... Item name.
#' @param tabName Should correspond exactly to the tabName given in \code{\link{tablerTabItem}}.
#' @param icon Item icon.
#'
#' @author David Granjon, \email{dgranjon@@ymail.com}
#'
#' @export
tablerNavMenuItem <- function(..., tabName = NULL, icon = NULL) {
shiny::tags$li(
class = "nav-item",
shiny::tags$a(
class = "nav-link",
id = paste0("tab-", tabName),
href = paste0("#shiny-tab-", tabName),
`data-toggle` = "tab",
`data-value` = tabName,
tablerIcon(name = icon, lib = "feather"),
...
)
)
}
#' Create a Boostrap 4 dashboard dropdown container
#'
#' Build a tabler dashboard dropdown container
#'
#' @param ... Slot for \link{tablerDropdownItem}.
#' @param icon Dropdown icon.
#' @param collapsed Whether to collapse the dropdown. TRUE by default.
#'
#' @author David Granjon, \email{dgranjon@@ymail.com}
#'
#' @export
tablerDropdown <- function(..., icon = "bell", collapsed = TRUE) {
shiny::tags$div(
class = "dropdown d-none d-md-flex",
# link and icon
shiny::tags$a(
class = "nav-link icon",
`data-toggle` = "dropdown",
`aria-expanded` = if (collapsed) "false" else "true",
tablerIcon(name = icon, lib = "feather"),
shiny::span(class = "nav-unread")
),
# dropdown content
shiny::tags$div(
class = "dropdown-menu dropdown-menu-right dropdown-menu-arrow",
`x-placement` = "bottom-end",
style = "position: absolute;
transform: translate3d(39px, 32px, 0px);
top: 0px; left: 0px; will-change: transform;",
...
)
)
}
#' Create a Boostrap 4 dashboard dropdown container
#'
#' Build a tabler dashboard dropdown container
#'
#' @param ... Item content.
#' @param title Item title.
#' @param href External link.
#' @param url Author image.
#' @param status Item status. Only if url is not NULL.
#' @param date Item date.
#'
#' @author David Granjon, \email{dgranjon@@ymail.com}
#'
#' @export
tablerDropdownItem <- function(..., title = NULL, href = NULL,
url = NULL, status = NULL, date = NULL) {
shiny::tags$a(
href = href,
target = "_blank",
class = "dropdown-item d-flex",
if (!is.null(url)) {
shiny::tagAppendAttributes(
tablerAvatar(url = url, status = status),
class = "mr-3"
)
},
shiny::tags$div(
if (!is.null(title)) shiny::strong(paste0(title, ": ")),
...,
shiny::tags$div(class = "small text-muted", date)
)
)
}