The bs_accordion()
family is an extension of the bs_collapse()
family. An accordion is a set of collapsible panels constructed such that one panel, at most, is open at a time.
There are three functions in this family:
bs_accordion()
, used to establish the accordion frameworkbs_append()
, used to add a panel (title
and content
) to the accordionbs_set_opts()
, used to set options for the panels to followThe bs_accordion()
function takes a single argument, a unique id
for the accordion frameowrk.
To add a panel to an accordion, use the bs_append()
function. Its arguments are the tag
of the accordion, the title
of the panel, which will generally be text, and the content
of the panel, which can be HTML.
The appearance of panels can be modified using the bs_set_opts()
function. Its first argument is the accordion tag
, its other arguments are panel_type
, which controls the appearance of following panels, and use_heading_link
, which, if TRUE
, makes the entire headings of following panels of into links, rather than just the title.
The default panel_type
is "default"
, the default for use_heading_link
is FALSE
.
All of these functions return an accordion tag; thus, you can build an accordion using a pipe.
bs_accordion(id = "beatles") %>%
bs_set_opts(panel_type = "success", use_heading_link = TRUE) %>%
bs_append(title = "John Lennon", content = "Rhythm guitar, vocals") %>%
bs_append(title = "Paul McCartney", content = "Bass guitar, vocals") %>%
bs_append(title = "George Harrison", content = "Lead guitar, vocals") %>%
bs_set_opts(panel_type = "info") %>%
bs_append(title = "Ringo Starr", content = "Drums, vocals")
The panel_type
has to be one of the standard Bootstrap types: c("default", "primary", "success", "info", "warning", "danger")
.
bs_accordion(id = "bootstrap_types") %>%
bs_set_opts(panel_type = "default") %>%
bs_append(title = "Default", content = NULL) %>%
bs_set_opts(panel_type = "primary") %>%
bs_append(title = "Primary", content = NULL) %>%
bs_set_opts(panel_type = "success") %>%
bs_append(title = "Success", content = NULL) %>%
bs_set_opts(panel_type = "info") %>%
bs_append(title = "Info", content = NULL) %>%
bs_set_opts(panel_type = "warning") %>%
bs_append(title = "Warning", content = NULL) %>%
bs_set_opts(panel_type = "danger") %>%
bs_append(title = "Danger", content = NULL)
For more information, please see the Bootstrap JavaScript page.