Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Friessn committed Sep 24, 2024
2 parents e4597b6 + a428e22 commit dc3e1ed
Show file tree
Hide file tree
Showing 7 changed files with 283 additions and 0 deletions.
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export(redo)
export(renderTabulator)
export(set_calculation)
export(set_column_defaults)
export(set_column_editor_input)
export(set_column_editor_numeric)
export(set_column_editor_text_area)
export(set_editor)
export(set_formatter_color)
export(set_formatter_datetime)
Expand Down
103 changes: 103 additions & 0 deletions R/editors.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#' The \strong{input} editor allows entering of a single line of plain text
#'
#' @param widget A [tabulator()] HTML widget.
#' @param column The name of the column the formatter is applied to.
#' @param search Use search type input element with clear button
#' @param mask Apply a mask to the input to allow characters to be entered only in a certain order
#' @param select_contents When the editor is loaded select its text content
#' @param elementAttributes Set attributes directly on the input element
#'
#' @return The updated [tabulator()] HTML widget
#' @export
#'
#' @examples examples/editors/editor_input
set_column_editor_input <- function(widget,
columns,
search = TRUE,
mask = "",
select_contents = TRUE,
elementAttributes = list(
maxlength = 10
)){
editor = "input"
editorParams = list(
search = search,
mask = mask,
selectContents = select_contents,
elementAttributes = elementAttributes
)

set_column_editor(widget, columns, editor, editorParams)
}

#' The \strong{textarea} editor allows entering of multiple lines of plain text
#' @inherit set_column_editor_input params return
#' @param elementAttributes Set attributes directly on the textarea element
#' @param mask Apply a mask to the input to allow characters to be entered only in a certain order
#' @param select_contents When the editor is loaded select its text content
#' @param vertical_navigation Determine how use of the up/down arrow keys will affect the editor,
#' this can take three different types of value: *hybrid*, *editor* and *table*
#' @param shift_enter_submit Submit the cell value when the shift and enter keys are pressed
#'
#' @export
#'
set_column_editor_text_area <- function(widget,
columns,
elementAttributes = list(
maxlength = 10
),
mask = "",
select_contents = TRUE,
vertical_navigation = "editor",
shift_enter_submit = TRUE
){
editor = "textarea"
editorParams = list(
elementAttributes = elementAttributes,
mask = mask,
selectContents = select_contents,
verticalNavigation = vertical_navigation,
shiftEnterSubmit = shift_enter_submit
)

set_column_editor(widget, columns, editor, editorParams)
}

#' The \strong{numeric} editor allows for numeric entry with a number type input element with increment and decrement buttons.
#' @inherit set_column_editor_input params return
#' @param min the maximum allowed value
#' @param max the minimum allowed value
#' @param step the step size when incrementing/decrementing the value (default 1)
#' @param elementAttributes Set attributes directly on the element
#' @param mask Apply a mask to the input to allow characters to be entered only in a certain order
#' @param select_contents When the editor is loaded select its text content
#' @param vertical_navigation determine how use of the up/down arrow keys will affect the editor,
#' this can take two different types of value: : *editor* and *table*
#' @export
#'
set_column_editor_numeric <- function(widget,
columns,
min = 0,
max = 100,
step = 1,
elementAttributes = list(
maxlength = 10
),
mask = "",
select_contents = TRUE,
vertical_navigation = "table"
){
editor = "number"
editorParams = list(
min = min,
max = max,
elementAttributes = elementAttributes,
mask = mask,
selectContents = select_contents,
verticalNavigation = vertical_navigation
)

set_column_editor(widget, columns, editor, editorParams)
}


37 changes: 37 additions & 0 deletions man/set_column_editor_input.Rd

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

42 changes: 42 additions & 0 deletions man/set_column_editor_numeric.Rd

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

36 changes: 36 additions & 0 deletions man/set_column_editor_text_area.Rd

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

62 changes: 62 additions & 0 deletions tests/testthat/test-editor.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
test_that("set editor input", {
# Prepare
col = "input_var"
df <- data.frame(input_var = c("a","b","c"))


# Act
t <- tabulator(df) |>
set_column_editor_input(col)

# Assert
expected_column_def <- list(
title = "input_var",
field = "input_var",
hozAlign = "left",
editor = "input",
editorParams = list(
search = TRUE,
mask = "",
selectContents = TRUE,
elementAttributes = list(
maxlength = 10
)
)
)
expect_mapequal(t$x$options$columns[[1]], expected_column_def)
expect_s3_class(t, "rtabulator")
expect_s3_class(t, "htmlwidget")
})

test_that("set editor area input", {
# Prepare
col = "input_var"
df <- data.frame(input_var = c("a","b","c"))


# Act
t <- tabulator(df) |>
set_column_editor_text_area(col)

# Assert
expected_column_def <- list(
title = "input_var",
field = "input_var",
hozAlign = "left",
editor = "textarea",
editorParams = list(
elementAttributes = list(
maxlength = 10
),
mask = "",
selectContents = TRUE,
verticalNavigation = "editor",
shiftEnterSubmit = TRUE
)
)
expect_mapequal(t$x$options$columns[[1]], expected_column_def)
expect_s3_class(t, "rtabulator")
expect_s3_class(t, "htmlwidget")
})


File renamed without changes.

0 comments on commit dc3e1ed

Please sign in to comment.