#' @title Hotwire Modifiers
#'
#' @description
#' Modifier functions
#'
#' @param tag (tag) to be modified
#'
#' @family Hotwire
#' @name hotwire_modifiers
NULL
#' @describeIn hotwire_modifiers sets data attributes on a tag
#' @param ... (attr) named attributes to set on the tag; omit the `data-`.
#' @param .list (lst) named list to provide
#' @export
set_data <- function(tag, ..., .list = NULL) {
assert_tags(tag)
attrs <- assert_named(.list %||% list(...))
names(attrs) <- paste0("data-", names(attrs))
tag <- tagQuery(tag)
tag$removeAttrs(names(attrs))
exec(tag$addAttrs, !!!attrs)
return(tag$allTags())
}
#' @describeIn hotwire_modifiers adds data attributes (appends)
#' @param ... (attr) named attributes to add to the tag; omit the `data-`.
#' @export
add_data <- function(tag, ..., .list = NULL) {
assert_tags(tag)
attrs <- assert_named(.list %||% list(...))
names(attrs) <- paste0("data-", names(attrs))
return(exec(tagAppendAttributes, tag = tag, !!!attrs))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.