Skip to content

Commit

Permalink
[Porting] MultiSlider + example
Browse files Browse the repository at this point in the history
  • Loading branch information
filipakkad committed Jun 24, 2022
1 parent 4874fae commit bd1b679
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export(Label)
export(Menu)
export(MenuDivider)
export(MenuItem)
export(MultiSlider)
export(MultiSliderHandle)
export(Navbar)
export(NavbarDivider)
export(NavbarGroup)
Expand Down
24 changes: 24 additions & 0 deletions R/components.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ component <- function(name) {
}
}

properties <- function(name) {
function(...) {
shiny.react::reactElement(
module = "@/appsilon.blueprint",
name = name,
props = shiny.react::asProps(...),
deps = blueprintDependency()
)
}
}

button <- function(name) {
function(inputId, ...) {
shiny.react::reactElement(
Expand Down Expand Up @@ -445,6 +456,19 @@ RangeSlider <- component("RangeSlider")
#' @export
RangeSlider.shinyInput <- input("RangeSlider", c(0, 0)) # nolint

#' MultiSlider
#'
#' Documentation: <https://blueprintjs.com/docs/#core/components/sliders.multi-slider>
#'
#' @example inst/examples/components/MultiSlider.R
#' @inherit template params
#' @export
MultiSlider <- component("MultiSlider")

#' @rdname MultiSlider
#' @export
MultiSliderHandle <- properties("MultiSliderHandle")

#' Switch
#'
#' Documentation: <https://blueprintjs.com/docs/#core/components/switch>
Expand Down
57 changes: 57 additions & 0 deletions inst/examples/components/MultiSlider.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
library(shiny)
library(appsilon.blueprint)

if (interactive()) shinyApp(
ui = reactOutput("multiSliderOutput"),
server = function(input, output) {

thresholds <- reactiveValues(
dangerStart = 3,
warningStart = 8,
warningEnd = 14,
dangerEnd = 17
)

observeEvent(input$mutliSliderInput, {
sliderValues <- sort(input$mutliSliderInput)
thresholds$dangerStart <- sliderValues[1]
thresholds$warningStart <- sliderValues[2]
thresholds$warningEnd <- sliderValues[3]
thresholds$dangerEnd <- sliderValues[4]
})

output$multiSliderOutput <- renderReact({
MultiSlider(
defaultTrackIntent = "success",
onChange = setInput("mutliSliderInput"),
stepSize = 1,
min = 0,
max = 20,
MultiSliderHandle(
type = "start",
intentBefore = "danger",
value = thresholds$dangerStart,
interactionKind = "push"
),
MultiSliderHandle(
type = "start",
intentBefore = "warning",
value = thresholds$warningStart,
interactionKind = "push"
),
MultiSliderHandle(
type = "end",
intentAfter = "warning",
value = thresholds$warningEnd,
interactionKind = "push"
),
MultiSliderHandle(
type = "end",
intentAfter = "danger",
value = thresholds$dangerEnd,
interactionKind = "push"
)
)
})
}
)
2 changes: 1 addition & 1 deletion inst/www/blueprint.min.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions js/src/inputs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export const RangeSlider = InputAdapter(Blueprint.RangeSlider, (value, setValue)
onChange: setValue,
}));

export const MultiSliderHandle = Blueprint.MultiSlider.Handle;

export const Switch = InputAdapter(Blueprint.Switch, (value, setValue) => ({
checked: value,
onChange: (event) => setValue(event.target.checked),
Expand Down
76 changes: 76 additions & 0 deletions man/MultiSlider.Rd

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

0 comments on commit bd1b679

Please sign in to comment.