Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create gov_list function #142

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export(govTable)
export(govTabs)
export(gov_box)
export(gov_layout)
export(gov_list)
export(gov_main_layout)
export(gov_row)
export(gov_summary)
Expand Down
46 changes: 46 additions & 0 deletions R/govLayouts.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,57 @@ gov_text <- function(...){
)
}

#' @rdname layouts
#' @param list vector of list
#' @param style options: "none", "bullet", "number". defaults to "none".
#' @export
gov_list <- function(list, style = "none") {

# check style argument
if (!style %in% c("none", "bullet", "number")) {
stop(
cat(
'style argument must be one of the following values:
"none"
"bullet"
"number"
'
)
)
}

# create list wrapper
list_wrapper <- function(x) {
# get list style class
if (style == "bullet") {
list_style_class <- "govuk-list--bullet"
} else if (style == "number") {
list_style_class <- "govuk-list--number"
} else {
list_style_class <- ""
}

# get shiny tag to use (ordered list or unordered list)
if (style == "number") {
shiny_tag <- shiny::tags$ol
} else {
shiny_tag <- shiny::tags$ul
}

# put together wrapper
shiny_tag(class = stringr::str_c("govuk-list", list_style_class, sep = " "), x)

}


# apply wrapper over list to get full list
# govList <-
list_wrapper(purrr::map(list, function(x) {
shiny::tags$li(x)
}))



}


17 changes: 15 additions & 2 deletions inst/example_app/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,16 @@ shiny::shinyApp(
"text_area_Input",
"button_Input",
"external_link",
"download_link"
"download_link",
"gov_list"
),
subcontents_id_list = c(
NA,
NA,
NA,
"button_input_text_types",
NA,
NA,
NA
)
),
Expand Down Expand Up @@ -261,7 +263,18 @@ shiny::shinyApp(
file_type = "CSV",
file_size = "1 KB"
)
)
),

heading_text("gov_list", size = "s"),

shinyGovstyle::gov_text("List:"),
gov_list(list = c("a", "b", "c")),

shinyGovstyle::gov_text("Bulleted list:"),
gov_list(list = c("a", "b", "c"), style = "bullet"),

shinyGovstyle::gov_text("Numbered list:"),
gov_list(list = c("one", "two", "three"), style = "number"),
),
),

Expand Down
7 changes: 7 additions & 0 deletions man/layouts.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion shinyGovstyle.Rproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Version: 1.0
ProjectId: ab9c9bc7-4ba5-4288-9748-bfe0e542c4c1

RestoreWorkspace: No
SaveWorkspace: No
Expand Down
51 changes: 51 additions & 0 deletions tests/testthat/test-gov_list.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Check list length
test_that("list length", {
gov_list_check <- gov_list(list = c("a", "b", "c"))

expect_equal(3, length(gov_list(list = c("a", "b", "c"))$children[[1]]))
})

# Check list type
test_that("bulleted list type", {
gov_list_check <- gov_list(list = c("a", "b", "c"))

expect_equal("ul", gov_list_check[[1]])
})

# Check list class
test_that("bulleted list class", {
gov_list_check <- gov_list(list = c("a", "b", "c"))

expect_equal("govuk-list ", gov_list_check$attribs$class[[1]])
})

# Check bullet list type
test_that("bulleted list type", {
gov_list_check <- gov_list(list = c("a", "b", "c"), style = "bullet")

expect_equal("ul", gov_list_check[[1]])
})

# Check bullet list class
test_that("bulleted list class", {
gov_list_check <- gov_list(list = c("a", "b", "c"), style = "bullet")

expect_equal("govuk-list govuk-list--bullet",
gov_list_check$attribs$class[[1]])
})


# Check numbered list type
test_that("numbered list type", {
gov_list_check <- gov_list(list = c("a", "b", "c"), style = "number")

expect_equal("ol", gov_list_check[[1]])
})

# Check numbered list class
test_that("numbered list class", {
gov_list_check <- gov_list(list = c("a", "b", "c"), style = "number")

expect_equal("govuk-list govuk-list--number",
gov_list_check$attribs$class[[1]])
})
Loading