Skip to content

Commit

Permalink
calendarProInput: added some arguments and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Nov 6, 2024
1 parent bcb3934 commit ef5d534
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 12 deletions.
13 changes: 13 additions & 0 deletions R/calendar-pro-input.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ html_dependency_calendar_pro <- function() {
#' selected.month and selected.year, it will make the calendar jump to the first selected date. If set to false,
#' the calendar will always open to the current month and year.
#' @param toggleSelected If toggleSelected parameter is true then clicking on the active cell will remove the selection from it.
#' @param weekNumbers With this parameter, you can decide whether to display week numbers in the calendar.
#' @param weekNumbersSelect If `TRUE` select the week when week number is clicked.
#' @param weekend This parameter allows you to highlight weekends in the calendar.
#' @param ... Other settings passed to Slim Select JAvaScript method.
#' @param positionToInput This parameter specifies the position of the calendar relative to input,
#' if the calendar is initialized with the input parameter. Possible values: 'auto' | 'center' | 'left' | 'right' | c('bottom' | 'top', 'center' | 'left' | 'right')
#' @param theme This parameter determines the theme of the calendar : 'light' or 'dark'.
#' @param placeholder A character string giving the user a hint as to what can be entered into the control.
#' @param input If `TRUE` (default), use an input and render calendar in a dropdown, otherwise calendar is rendered in the page.
Expand All @@ -51,7 +56,11 @@ calendarProInput <- function(inputId,
jumpMonths = 1,
jumpToSelectedDate = FALSE,
toggleSelected = TRUE,
weekNumbers = FALSE,
weekNumbersSelect = FALSE,
weekend = TRUE,
...,
positionToInput = "auto",
theme = "light",
placeholder = NULL,
input = TRUE,
Expand All @@ -64,6 +73,7 @@ calendarProInput <- function(inputId,
jumpMonths = jumpMonths,
jumpToSelectedDate = jumpToSelectedDate,
toggleSelected = toggleSelected,
weekNumbersSelect = weekNumbersSelect,
...
)
config$input <- input
Expand All @@ -75,6 +85,9 @@ calendarProInput <- function(inputId,
config$date$min <- min
config$date$max <- max
config$settings$visibility$theme <- theme
config$settings$visibility$weekNumbers <- weekNumbers
config$settings$visibility$weekend <- weekend
config$settings$visibility$positionToInput <- positionToInput
tag_el <- if (isTRUE(input)) {
tags$input(
type = "text",
Expand Down
24 changes: 22 additions & 2 deletions examples/calendar-pro.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@ ui <- fluidPage(
input = FALSE,
width = "100%"
),
verbatimTextOutput("res5")
verbatimTextOutput("res5"),
calendarProInput(
inputId = "cal7",
label = "Calendar with week numbers:",
placeholder = "Select a date",
weekNumbers = TRUE,
width = "100%"
),
verbatimTextOutput("res7")
),
column(
width = 6,
Expand Down Expand Up @@ -57,7 +65,17 @@ ui <- fluidPage(
input = FALSE,
width = "100%"
),
verbatimTextOutput("res6")
verbatimTextOutput("res6"),
calendarProInput(
inputId = "cal8",
label = "Calendar select week:",
type = "multiple",
range = TRUE,
weekNumbers = TRUE,
weekNumbersSelect = TRUE,
width = "100%"
),
verbatimTextOutput("res8")
)
)
)
Expand All @@ -70,6 +88,8 @@ server <- function(input, output, session) {
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)

}

Expand Down
2 changes: 1 addition & 1 deletion inst/packer/calendar-pro.js

Large diffs are not rendered by default.

37 changes: 35 additions & 2 deletions man/calendarProInput.Rd

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

15 changes: 8 additions & 7 deletions srcjs/inputs/vanilla-calendar-pro.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,14 @@ $.extend(calendarProBinding, {
calendarProBinding.updateValue(el, self.selectedDates);
$(el).trigger("change");
};
config.actions.initCalendar = function(event, self) {
$(el).trigger("change");
};
config.actions.updateCalendar = function(event, self) {
calendarProBinding.updateValue(el, self.selectedDates);
$(el).trigger("change");
};
if (config.weekNumbersSelect) {
config.actions.clickWeekNumber = function(event, number, days, year, self) {
self.settings.selected.dates = days.map((day) => day.dataset.calendarDay);
self.update({ dates: true });
calendarProBinding.updateValue(el, self.selectedDates);
$(el).trigger("change");
};
}
if (config.type == "multiple") {
config.actions.changeToInput = changeToInputMultiple;
} else {
Expand Down

0 comments on commit ef5d534

Please sign in to comment.