Skip to content

Commit

Permalink
added args to calendarProInput()
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Nov 7, 2024
1 parent ef5d534 commit bd8b2b9
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 29 deletions.
39 changes: 28 additions & 11 deletions R/calendar-pro-input.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ html_dependency_calendar_pro <- function() {
#'
#' @inheritParams shiny::selectInput
#' @param value Initial value.
#' @param min The date.min parameter sets the minimum allowable date that the calendar will consider, which cannot be earlier than this date.
#' @param max The date.max parameter sets the maximum allowable date that the calendar will consider, which cannot be later than this date.
#' @param type Determines the type of calendar displayed: 'default' | 'multiple' | 'month' | 'year'.
#' @param range TRUE or FALSE, in case of multiple type, allow to select a range of dates.
#' @param type Determines the type of calendar displayed and the selection process: 'default' | 'multiple' | 'range' | 'month' | 'year'.
#' @param min This parameter sets the minimum date that the user can choose. Dates earlier than the specified date will be disabled and not available for selection.
#' @param max This parameter sets the maximum date that the user can choose. Dates later than the specified date will be disabled and not available for selection.
#' @param disablePast This parameter disables all past days.
#' @param disableAllDays This parameter disables all days and can be useful when using `enable` is set.
#' @param disableWeekday This parameter allows you to disable specified weekdays. Specify an array with numbers, where each number represents a day of the week. For example, `0` is Sunday.
#' @param disableGaps This parameter disables the selection of days within a range with disabled dates. It only works when `type = "range"`.
#' @param disabled This parameter allows you to disable specific dates regardless of the specified range.
#' @param enabled This parameter allows you to enable specific dates regardless of the range and disabled dates.
#' @param months The months parameter specifies the number of displayed months when the calendar type is set to 'multiple'.
#' @param jumpMonths The jumpMonths parameter controls the number of months to jump.
#' @param jumpToSelectedDate When the option is enabled and 1 or more selected date(s) are provided but without providing
Expand All @@ -48,10 +53,15 @@ html_dependency_calendar_pro <- function() {
calendarProInput <- function(inputId,
label,
value = NULL,
type = c("default", "multiple", "range", "month", "year"),
min = NULL,
max = NULL,
type = c("default", "multiple", "month", "year"),
range = FALSE,
disablePast = FALSE,
disableAllDays = FALSE,
disableWeekday = NULL,
disableGaps = FALSE,
disabled = NULL,
enabled = NULL,
months = 2,
jumpMonths = 1,
jumpToSelectedDate = FALSE,
Expand All @@ -67,8 +77,9 @@ calendarProInput <- function(inputId,
inline = FALSE,
width = NULL) {
# selected <- restoreInput(id = inputId, default = selected)
type <- match.arg(type)
config <- list(
type = match.arg(type),
type = if (type == "range") "multiple" else type,
months = months,
jumpMonths = jumpMonths,
jumpToSelectedDate = jumpToSelectedDate,
Expand All @@ -78,12 +89,18 @@ calendarProInput <- function(inputId,
)
config$input <- input
config$settings$selected$dates <- list1(value)
if (config$type == "multiple")
if (type == "multiple")
config$settings$selection$day <- "multiple"
if (isTRUE(range))
if (type == "range")
config$settings$selection$day <- "multiple-ranged"
config$date$min <- min
config$date$max <- max
config$settings$range$min <- min
config$settings$range$max <- max
config$settings$range$disablePast <- disablePast
config$settings$range$disableAllDays <- disableAllDays
config$settings$range$disableWeekday <- list1(disableWeekday)
config$settings$range$disableGaps <- disableGaps
config$settings$range$disabled <- list1(disabled)
config$settings$range$enabled <- list1(enabled)
config$settings$visibility$theme <- theme
config$settings$visibility$weekNumbers <- weekNumbers
config$settings$visibility$weekend <- weekend
Expand Down
9 changes: 3 additions & 6 deletions examples/calendar-pro.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,14 @@ ui <- fluidPage(
calendarProInput(
inputId = "cal4",
label = "Calendar with range selection:",
type = "multiple",
range = TRUE,
type = "range",
width = "100%"
),
verbatimTextOutput("res4"),
calendarProInput(
inputId = "cal6",
label = "Calendar without input field:",
type = "multiple",
range = TRUE,
type = "range",
months = 3,
input = FALSE,
width = "100%"
Expand All @@ -69,8 +67,7 @@ ui <- fluidPage(
calendarProInput(
inputId = "cal8",
label = "Calendar select week:",
type = "multiple",
range = TRUE,
type = "range",
weekNumbers = TRUE,
weekNumbersSelect = TRUE,
width = "100%"
Expand Down
98 changes: 98 additions & 0 deletions inst/examples/calendar-pro/disable/app.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
theme = bslib::bs_theme(5),
tags$h2("Calendar Pro Input: disable/enable days"),
fluidRow(
column(
width = 6,
calendarProInput(
inputId = "cal1",
label = "Disable past:",
placeholder = "Select a date",
disablePast = TRUE,
width = "100%"
),
verbatimTextOutput("res1"),
calendarProInput(
inputId = "cal3",
label = "Disable week-ends:",
disableWeekday = c(0, 6),
width = "100%"
),
verbatimTextOutput("res3"),
calendarProInput(
inputId = "cal5",
label = "Disable wednesdays:",
disableWeekday = 3,
width = "100%"
),
verbatimTextOutput("res5"),
calendarProInput(
inputId = "cal7",
label = "Set range:",
placeholder = "Select a date",
min = Sys.Date() - 14,
max = Sys.Date() + 7,
width = "100%"
),
verbatimTextOutput("res7")
),
column(
width = 6,
calendarProInput(
inputId = "cal2",
label = "Disable select range with gaps (cannot select range with today included):",
type = "range",
disableGaps = TRUE,
disabled = Sys.Date(),
positionToInput = c("bottom", "left"),
width = "100%"
),
verbatimTextOutput("res2"),
calendarProInput(
inputId = "cal4",
label = "Disable days:",
disabled = c(Sys.Date() + c(-5, -2, 3, 6, 7, 9, 14)),
positionToInput = c("bottom", "left"),
width = "100%"
),
verbatimTextOutput("res4"),
calendarProInput(
inputId = "cal6",
label = "Disable range of days (today -/+ 3):",
disabled = paste(Sys.Date() - 3, Sys.Date() + 3, sep = ":"),
positionToInput = c("bottom", "left"),
width = "100%"
),
verbatimTextOutput("res6"),
calendarProInput(
inputId = "cal8",
label = "Enable specifics days:",
disableAllDays = TRUE,
enabled = c(Sys.Date() + c(-5, -2, 3, 6, 7, 9, 14)),
positionToInput = c("bottom", "left"),
width = "100%"
),
verbatimTextOutput("res8")
)
)
)

server <- function(input, output, session) {

output$res1 <- renderPrint(input$cal1)
output$res2 <- renderPrint(input$cal2)
output$res3 <- renderPrint(input$cal3)
output$res4 <- renderPrint(input$cal4)
output$res5 <- renderPrint(input$cal5)
output$res6 <- renderPrint(input$cal6)
output$res7 <- renderPrint(input$cal7)
output$res8 <- renderPrint(input$cal8)

}

if (interactive())
shinyApp(ui, server)
36 changes: 24 additions & 12 deletions man/calendarProInput.Rd

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

0 comments on commit bd8b2b9

Please sign in to comment.