bs_modal: Modal window

View source: R/modal.R

bs_modalR Documentation

Modal window

Description

Modal windows are useful to make detailed explanations, and are typically attached to buttons or links. Thus, there are two parts to this system:

Usage

bs_modal(
  id,
  title,
  body,
  footer = bs_modal_closebutton(label = "Close"),
  size = c("medium", "large", "small")
)

bs_modal_closebutton(label = "Close", title)

bs_attach_modal(tag, id_modal)

Arguments

id

character, unique id for the modal window

title

character, title for the modal window (this argument is deprecated for bs_modal_closebutton, use label instead)

body

character (HTML) or htmltools::[tagList][htmltools::tagList], content for the body of the modal window

footer

character (HTML) or htmltools::[tagList][htmltools::tagList], content for the footer of the modal window

size

character, size of the modal window

label

character (HTML), label for the close-button

tag

htmltools::[tag][htmltools::tag], button or link to which to attach the modal window

id_modal

character, unique id of modal window to attach

Details

  1. A modal window, created using bs_modal()

  2. At least one button or link to which the id of the modal window is attached, using bs_attach_modal()

The verb attach is used to signify that we are attaching the id of our modal window to the tag in question (generally a button or a link). This implies that you can attach the id of a modal window to more than one button or link.

It is your responsibility to ensure that id is unique among HTML elements in your page. If you have non-unique id's, strange things may happen to your page.

Your code may be cleaner if you can import the content for the modal body from an external source. Here, the function shiny::[includeMarkdown][shiny::includeMarkdown] be useful.

If you want to compose your own footer for the modal window, the function bs_modal_closebutton() can be useful.

Value

bs_modal()

htmltools::[tag][htmltools::tag], <div/>

bs_attach_modal()

htmltools::[tag][htmltools::tag], modified copy of tag

bs_modal_closebutton()

htmltools::[tag][htmltools::tag], <button/>

See Also

shiny::[includeMarkdown][shiny::includeMarkdown]

Examples

library("htmltools") # also needs `markdown` package
library("shiny")

bs_modal(id = "modal", title = "I'm a modal", body = "Yes, I am.")
bs_button("Click for modal") %>%
  bs_attach_modal(id_modal = "modal")

bs_modal(
  id = "modal_large",
  title = "I'm a modal",
  size = "large",
  body = includeMarkdown(system.file("markdown", "modal.md", package = "bsplus"))
)
bs_button("Click for modal") %>%
  bs_attach_modal(id_modal = "modal_large")


bsplus documentation built on Nov. 16, 2022, 1:11 a.m.