浏览代码

Add initial functions for bulma level layout

master
父节点
当前提交
4fa36ef1ab
共有 6 个文件被更改,包括 81 次插入1 次删除
  1. +2
    -1
      DESCRIPTION
  2. +3
    -0
      NAMESPACE
  3. +3
    -0
      R/bulma-package.R
  4. +62
    -0
      R/layout_level.R
  5. +7
    -0
      R/utils.R
  6. +4
    -0
      tests/manual/example/bulma-test.Rmd

+ 2
- 1
DESCRIPTION 查看文件

@@ -11,5 +11,6 @@ License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Imports:
rmarkdown
rmarkdown,
htmltools
RoxygenNote: 6.1.1

+ 3
- 0
NAMESPACE 查看文件

@@ -1,3 +1,6 @@
# Generated by roxygen2: do not edit by hand

export(bulma_document)
export(bulma_level)
importFrom(htmltools,tag)
importFrom(htmltools,tagList)

+ 3
- 0
R/bulma-package.R 查看文件

@@ -0,0 +1,3 @@
#' @keywords internal
#' @importFrom htmltools tag tagList
"_PACKAGE"

+ 62
- 0
R/layout_level.R 查看文件

@@ -0,0 +1,62 @@
#' @title Bulma Level
#' @examples
#' bulma_level("Home", "Menu", "Bulma", "Reservations", "Contact")
#' bulma_level("Tweets" = 3456, Following = 123, Followers = "456K", Likes = 789, style = "header")
#' @export
bulma_level <- function(
...,
left = NULL,
right = NULL,
is_mobile = TRUE,
style = "item"
) {
level_item_f <- switch(
match.arg(style, c("item", "header")),
item = level_item,
header = level_item_header
)
htmltools::tags$div(
class = paste("level", if (is_mobile) "is-mobile"),
level_side(left),
level_item_f(...),
level_side(right)
)
}

level_item <- function(...) {
x <- apply_tag(..., tag = "div", class = "level-item")
tagList(x)
}

level_side <- function(x, side = "left") {
if (is.null(x)) return(NULL)
match.arg(side, c("left", "right"))
lapply(x, function(item) {
htmltools::tags$div(
class = paste0("level-", side),
level_item(x)
)
})
}

#' @title Bulma Level Items With Headers
level_item_header <- function(..., item_class = "has-text-centered", heading_class = NULL, title_class = NULL) {
items <- list(...)
x <- mapply(level_item_header_, names(items), items,
MoreArgs = list(item_class = item_class,
heading_class = heading_class,
title_class = title_class),
SIMPLIFY = FALSE)
tagList(x)
}

#' @importFrom htmltools tag
level_item_header_ <- function(item_name, item_body, item_class = NULL, heading_class = NULL, title_class = NULL) {
tag("div", list(
class = paste("level-item", item_class),
list(tag("div", list(
tag("p", list(class = paste("heading", heading_class), item_name)),
tag("p", list(class = paste("title", title_class), item_body))
)))
))
}

+ 7
- 0
R/utils.R 查看文件

@@ -0,0 +1,7 @@
div_with_class <- function(..., class = "") {
htmltools::tags$div(..., class = class)
}

apply_tag <- function(..., tag, class = NULL, extra_attributes = NULL) {
lapply(list(...), function(x) htmltools::tag(tag, c(x, class = class, extra_attributes)))
}

+ 4
- 0
tests/manual/example/bulma-test.Rmd 查看文件

@@ -64,6 +64,10 @@ Things could change dramatically.
:::::
::::::

`r bulma::bulma_level("Home", "Menu", "Bulma", "Reservations", "Contact")`

`r bulma::bulma_level("Tweets" = 3456, Following = 123, Followers = "456K", Likes = 789, style = "header")`

A bit of an _introduction_ here. We no longer need to start an article by writing this:

```latex

正在加载...
取消
保存