Skip to content

Commit

Permalink
fixed bug knob return value + added fontsize arg
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed May 3, 2020
1 parent f1c5e2e commit a9c43f1
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 9 deletions.
10 changes: 5 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: shinyWidgets
Title: Custom Inputs Widgets for Shiny
Version: 0.5.1.900
Version: 0.5.1.920
Authors@R: c(
person("Victor", "Perrier", email = "victor.perrier@dreamrs.fr", role = c("aut", "cre")),
person("Fanny", "Meyer", email = "fanny.meyer@dreamrs.fr", role = "aut"),
Expand Down Expand Up @@ -32,6 +32,10 @@ Description: Collection of custom input controls and user interface components f
Give your applications a unique and colorful style !
URL: https://github.com/dreamRs/shinyWidgets
BugReports: https://github.com/dreamRs/shinyWidgets/issues
License: GPL-3 | file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.0
Depends:
R (>= 3.1.0)
Imports:
Expand All @@ -40,10 +44,6 @@ Imports:
jsonlite,
grDevices,
scales
License: GPL-3 | file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.0
Suggests: shinydashboard,
testthat,
covr,
Expand Down
8 changes: 8 additions & 0 deletions R/input-knob.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#' @param bgColor Background color.
#' @param pre A prefix string to put in front of the value.
#' @param post A suffix string to put after the value.
#' @param fontSize Font size, must be a valid CSS unit.
#' @param readOnly Disable knob (\code{TRUE} or \code{FALSE}).
#' @param skin Change Knob skin, only one option available : 'tron'.
#' @param width,height The width and height of the input, e.g. \code{400px}, or \code{100\%}.
Expand Down Expand Up @@ -78,6 +79,7 @@ knobInput <- function(inputId, label, value,
inputColor = NULL,
bgColor = NULL,
pre = NULL, post = NULL,
fontSize = NULL,
readOnly = FALSE,
skin = NULL,
width = NULL,
Expand Down Expand Up @@ -113,6 +115,12 @@ knobInput <- function(inputId, label, value,
knobInputTag <- tags$div(
class = "form-group shiny-input-container",
style = if (!is.null(width)) paste0("width: ", validateCssUnit(width), ";"),
if (!is.null(fontSize)) {
tags$style(sprintf(
"#%s {font-size: %s !important;}",
inputId, validateCssUnit(fontSize)
))
},
if (!is.null(label)) tags$label(`for` = inputId, label),
if (!is.null(label)) tags$br(),
inputTag
Expand Down
13 changes: 12 additions & 1 deletion inst/assets/jquery-knob/knob-bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,18 @@ $.extend(knobInputBinding, {

// Given the DOM element for the input, return the value
getValue: function(el) {
return parseFloat(el.value.replace(/\D/g, ""));
var value = el.value;
var pre = $(el).data("pre");
if (typeof pre !== "undefined") {
var regexPre = new RegExp("^" + pre);
value = value.replace(regexPre, "");
}
var post = $(el).data("post");
if (typeof post !== "undefined") {
var regexPost = new RegExp(post + "$");
value = value.replace(regexPost, "");
}
return parseFloat(value);
},

// Set up the event listeners so that interactions with the
Expand Down
2 changes: 1 addition & 1 deletion inst/assets/shinyWidgets-bindings.min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions man/knobInput.Rd

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

4 changes: 2 additions & 2 deletions tests/testthat/test-knob.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ test_that("default", {
expect_is(tagkb, "shiny.tag")
expect_length(htmltools::findDependencies(tagkb), 2)
expect_identical(htmltools::findDependencies(tagkb)[[2]]$script, c("jquery.knob.min.js"))
expect_true(htmltools::tagHasAttribute(tagkb$children[[3]], "id"))
expect_identical(htmltools::tagGetAttribute(tagkb$children[[3]], "id"), "myKnob")
expect_true(htmltools::tagHasAttribute(tagkb$children[[length(tagkb$children)]], "id"))
expect_identical(htmltools::tagGetAttribute(tagkb$children[[length(tagkb$children)]], "id"), "myKnob")
})


Expand Down

0 comments on commit a9c43f1

Please sign in to comment.