/
dashboardSidebar.R
184 lines (168 loc) · 5.48 KB
/
dashboardSidebar.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
#' Create a Boostrap 4 dashboard sidebar
#'
#' Build an argon dashboard sidebar
#'
#' @param ... Any element such as \link{argonDashSidebar}, \link{argonSidebarMenu},
#' \link{argonSidebarItem}, \link{argonSidebarHeader} and \link{argonSidebarDivider}.
#'
#' @param id Unique sidebar id.
#' @param dropdownMenus Slot for dropdown menus. Not displayd on large screens.
#' @param brand_url Sidebar brand url
#' @param brand_logo Sidebar brand logo
#' @param vertical Whether to display the sidebar in vertical mode. TRUE by default.
#' @param side Sidebar side: "right" or "left". "left" by default.
#' @param size Sidebar size: "s", "md", "lg". "md" by default.
#' @param skin Sidebar skin. "light" by default.
#' @param background Sidebar background color. See \url{https://demos.creative-tim.com/argon-design-system/docs/foundation/colors.html}.
#'
#' @author David Granjon, \email{dgranjon@@ymail.com}
#'
#' @export
argonDashSidebar <- function(..., dropdownMenus = NULL, id, brand_url = NULL, brand_logo = NULL,
vertical = TRUE, side = c("left", "right"),
size = c("s", "md", "lg"), skin = c("light", "dark"),
background = "white") {
side <- match.arg(side)
size <- match.arg(size)
skin <- match.arg(skin)
sidebarCl <- "navbar"
if (vertical) {
sidebarCl <- paste0(sidebarCl, " navbar-vertical")
} else {
sidebarCl <- paste0(sidebarCl, " navbar-horizontal")
}
if (!is.null(side)) sidebarCl <- paste0(sidebarCl, " fixed-", side)
if (!is.null(size)) sidebarCl <- paste0(sidebarCl, " navbar-expand-", size)
if (!is.null(skin)) sidebarCl <- paste0(sidebarCl, " navbar-", skin)
if (!is.null(background)) sidebarCl <- paste0(sidebarCl, " bg-", background)
# handle horizontal items
# if vertical is FALSE, we need to modify
# ... class to nav instead of nav flex-column
# so that items are displayed on the same line
items <- list(...)
if (!vertical) {
for (i in seq_along(items)) {
if (items[[i]]$attribs[["class"]] == "nav-wrapper") {
items[[i]]$children[[1]]$attribs$class <- "nav"
items[[i]]$children[[1]]$attribs[["aria-orientation"]] <- "horizontal"
}
}
}
shiny::tags$nav(
class = sidebarCl,
id = id,
shiny::tags$div(
class = "container-fluid",
# sidebar trigger
shiny::tags$button(
`aria-control` = id,
`aria-expanded` = "false",
`aria-label` = "Toggle navigation",
class = "navbar-toggler collapsed",
`data-target` = "#sidenav-collapse-main",
`data-toggle` = "collapse",
type = "button",
shiny::tags$span(class = "navbar-toggler-icon")
),
# Brand
shiny::a(
class = "navbar-brand pt-0 my-0",
href = brand_url,
target = "_blank",
shiny::img(class = "navbar-brand-img", src = brand_logo)
),
# Dropdown Menus
shiny::tags$ul(class = "nav align-items-center d-md-none", dropdownMenus),
# Main content
shiny::tags$div(
class = "collapse navbar-collapse my--4",
id = "sidenav-collapse-main",
# sidebar header when collapsed
shiny::tags$div(
class = "navbar-collapse-header d-md-none",
shiny::fluidRow(
shiny::tags$div(
class = "col-6 collapse-brand",
shiny::a(
href = brand_url,
target = "_blank",
shiny::img(class = "navbar-brand-img", src = brand_logo)
)
),
shiny::tags$div(
class = "col-6 collapse-close",
shiny::tags$button(
`aria-control` = id,
`aria-expanded` = "true",
`aria-label` = "Toggle sidenav",
class = "navbar-toggler",
`data-target` = "#sidenav-collapse-main",
`data-toggle` = "collapse",
type = "button",
shiny::tags$span(),
shiny::tags$span()
)
)
)
),
items
)
)
)
}
#' Create a Boostrap 4 argon sidebar menu
#'
#' Build an argon dashboard main sidebar menu
#'
#' @param ... Slot for \link{argonSidebarItem}.
#'
#' @author David Granjon, \email{dgranjon@@ymail.com}
#'
#' @export
argonSidebarMenu <- function(...) {
shiny::tags$div(
class = "nav-wrapper my--4",
shiny::tags$div(
class = "nav flex-column nav-pills",
`aria-orientation` = "vertical",
id = "sidebar-menu",
...
)
)
}
#' Create a Boostrap 4 argon sidebar menu
#'
#' Build an argon dashboard main sidebar menu
#'
#' @param ... Item name.
#' @param tabName Should correspond exactly to the tabName given in \code{\link{argonTabItem}}.
#' @param icon Item icon. \link{argonIcon} or \link[shiny]{icon}.
#'
#' @author David Granjon, \email{dgranjon@@ymail.com}
#'
#' @export
argonSidebarItem <- function(..., tabName = NULL, icon = NULL) {
shiny::tags$a(
class = "nav-link mt-1 mb-1 mx-2 shadow",
id = paste0("tab-", tabName),
href = paste0("#shiny-tab-", tabName),
`data-toggle` = "tab",
`data-value` = tabName,
icon,
...
)
}
#' A header to put inside \link{argonDashSidebar}
#'
#' @param title Header title
#'
#' @export
argonSidebarHeader <- function(title = NULL) {
shiny::tags$h6(class = "navbar-heading text-muted", title)
}
#' A divider to put inside \link{argonDashSidebar}
#'
#' @export
argonSidebarDivider <- function() {
shiny::tags$hr(class = "my-3")
}