From f2058910ba9397f26c488a12872c67bcd615c895 Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Wed, 3 Jul 2019 10:56:09 -0400 Subject: [PATCH] add bucket_list_tag --- NAMESPACE | 1 + R/bucket_list.R | 40 +++++++++++++++++++++++++++------------- man/bucket_list.Rd | 14 ++++++++++---- 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 84dd9f5..76aedd2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -8,6 +8,7 @@ S3method(question_is_correct,rank) S3method(question_is_valid,rank) export(add_rank_list) export(bucket_list) +export(bucket_list_tag) export(css_bucket_list) export(css_rank_list) export(is_sortable_options) diff --git a/R/bucket_list.R b/R/bucket_list.R index f3c3d6c..cfe54e5 100644 --- a/R/bucket_list.R +++ b/R/bucket_list.R @@ -28,6 +28,7 @@ is.add_rank_list <- function(x)inherits(x, "add_rank_list") #' A bucket list can contain more than one [rank_list] and allows #' drag-and-drop of items between the different lists. #' +#' Use [bucket_list_tag] for finer control over the [sortable_js] objects being used. #' #' @inheritParams rank_list #' @@ -39,9 +40,11 @@ is.add_rank_list <- function(x)inherits(x, "add_rank_list") #' defined by [add_rank_list]. #' #' @param group_name Passed to `sortable.js` as the group name -#' @param group_put_max Not yet implemented +# ' @param group_put_max Not yet implemented +#' @param sortables A list of [sortable_js] objects #' #' @export +#' @rdname bucket_list #' @example inst/examples/example_bucket_list.R #' @examples #' ## Example of a shiny app @@ -53,7 +56,7 @@ bucket_list <- function( header = NULL, ..., group_name, - group_put_max = rep(Inf, length(labels)), + # group_put_max = rep(Inf, length(labels)), selector = NULL, options = sortable_options(), style = css_bucket_list() @@ -85,19 +88,30 @@ bucket_list <- function( # construct list rank_list objects sortables <- lapply(seq_along(mod), function(i) do.call(rank_list, mod[[i]]) ) - z <- tagList( + bucket_list_tag( + header = header, + sortables = sortables, + style = style + ) +} + + +#' @export +#' @rdname bucket_list +bucket_list_tag <- function( + header = NULL, + sortables = list(), + style = css_bucket_list() +) { + ret <- tags$div( + class = "bucket-list", + if(!is.null(header))tags$p(header) else NULL, + tags$style(htmltools::HTML(style)), tags$div( - class = "bucket-list", - if(!is.null(header))tags$p(header) else NULL, - tags$style(htmltools::HTML(style)), - tags$div( - class = "bucket-list-container", - sortables - ) + class = "bucket-list-container", + sortables ) ) - - as.bucket_list(z) + as.bucket_list(ret) } - diff --git a/man/bucket_list.Rd b/man/bucket_list.Rd index 6d5ca1f..57509fb 100644 --- a/man/bucket_list.Rd +++ b/man/bucket_list.Rd @@ -2,10 +2,13 @@ % Please edit documentation in R/bucket_list.R \name{bucket_list} \alias{bucket_list} +\alias{bucket_list_tag} \title{Create a bucket list.} \usage{ -bucket_list(header = NULL, ..., group_name, group_put_max = rep(Inf, - length(labels)), selector = NULL, options = sortable_options(), +bucket_list(header = NULL, ..., group_name, selector = NULL, + options = sortable_options(), style = css_bucket_list()) + +bucket_list_tag(header = NULL, sortables = list(), style = css_bucket_list()) } \arguments{ @@ -17,8 +20,6 @@ defined by \link{add_rank_list}.} \item{group_name}{Passed to \code{sortable.js} as the group name} -\item{group_put_max}{Not yet implemented} - \item{selector}{This is the css id to use, and must be unique in your shiny app. If NULL, the function generates a selector of the form \code{rank_list_id_1}, and will automatically increment for every @@ -27,11 +28,16 @@ app. If NULL, the function generates a selector of the form \item{options}{Options to be supplied to \link{sortable_js} object. See \link{sortable_options} for more details} \item{style}{A css stylesheet, provided as a character string. See also \code{\link[=css_rank_list]{css_rank_list()}}.} + +\item{sortables}{A list of \link{sortable_js} objects} } \description{ A bucket list can contain more than one \link{rank_list} and allows drag-and-drop of items between the different lists. } +\details{ +Use \link{bucket_list_tag} for finer control over the \link{sortable_js} objects being used. +} \examples{ ## Example of a shiny app if (interactive()) {