diff --git a/DESCRIPTION b/DESCRIPTION index 240131f6..7fa03266 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: shinygouv Title: Implement the DSFR for your shiny applications -Version: 1.0.0 +Version: 1.0.2 Authors@R: c( person("Juliette", "ENGELARE-LEFEBVRE", , "juliette.engelaere-lefebvre@developpement-durable.gouv.fr", role = c("aut", "cre")), person("Sébastien", "Rochette", , "sebastien@thinkr.fr", role = "aut", @@ -18,7 +18,7 @@ Authors@R: c( Description: Components and tools to build or transform shiny applications with the Design System of France. License: EUPL (>= 1.2) | file LICENSE -Imports: +Imports: assertthat (>= 0.2.1), attempt (>= 0.3.1), config (>= 0.3.1), @@ -27,7 +27,7 @@ Imports: golem (>= 0.3.2), htmltools (>= 0.5.2), janitor (>= 2.2.0), - lifecycle, + lifecycle (>= 1.0.3), magrittr (>= 2.0.3), purrr (>= 0.3.4), shiny (>= 1.7.1), @@ -35,7 +35,7 @@ Imports: tools, utils, XML (>= 3.99.0.10) -Suggests: +Suggests: desc (>= 1.4.1), DT (>= 0.23), knitr (>= 1.39), @@ -43,10 +43,10 @@ Suggests: rmarkdown (>= 2.14), testthat (>= 3.0.0), tibble (>= 3.1.7), - withr -VignetteBuilder: + withr (>= 2.5.0) +VignetteBuilder: knitr -Config/fusen/version: 0.5.0.9008 +Config/fusen/version: 0.5.0.9001 Config/testthat/edition: 3 Encoding: UTF-8 LazyData: true diff --git a/NAMESPACE b/NAMESPACE index d3caf1e9..4043b4ec 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -8,6 +8,7 @@ export(checkboxInput_dsfr) export(column_dsfr) export(convert_to_dsfr) export(fileInput_dsfr) +export(dateRangeInput_dsfr) export(fluidPage_dsfr) export(fluidRow_dsfr) export(get_dsfr_version) @@ -30,6 +31,7 @@ export(tabsetPanel_dsfr) export(toggleSwitch_dsfr) export(updateCheckboxGroupInput_dsfr) export(updateCheckboxInput_dsfr) +export(updateDateRangeInput_dsfr) export(updateNumericInput_dsfr) export(updateRadioButtons_dsfr) export(updateRadioGroupButtons_dsfr) diff --git a/NEWS.md b/NEWS.md index ebb5b047..c701b5bd 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# shinygouv 1.0.2 + +## fix + +* Correction de la classe du `fluidPage_dsfr()` + # shinygouv 1.0.0 ## chore @@ -8,6 +14,7 @@ ## feat +* Ajout de `dateRangeInput_dsfr()` et `updateDateRangeInput_dsfr()` * Ajout de `numericInput_dsfr()` et `updateNumericInput_dsfr()` * Ajout de `navbarPage_dsfr()` et `navbarPanel_dsfr()` * Ajout de `radioButtons_dsfr()` et `updateRadioButtons_dsfr()` diff --git a/R/daterangeinput_dsfr.R b/R/daterangeinput_dsfr.R new file mode 100644 index 00000000..b5f87f7c --- /dev/null +++ b/R/daterangeinput_dsfr.R @@ -0,0 +1,84 @@ +# WARNING - Generated by {fusen} from /dev/flat_composants/flat_dateRangeInput.Rmd: do not edit by hand + +#' dateRangeInput_dsfr +#' +#' @param inputId inputId +#' @param label label +#' @param start character La date de début au format aaaa-mm-jj. Si NULL (valeur par défaut), la date utilisée est la date du jour. +#' @param end character La date de fin au format aaaa-mm-jj. Si NULL (valeur par défaut), la date utilisée est la date du jour. +#' @param separator character Chaîne à afficher entre les zones de saisie de début et de fin de dates. +#' +#' @importFrom assertthat assert_that +#' @importFrom purrr map +#' @return html +#' +#' @export +#' +#' @examples +#' ## Only run examples in interactive R sessions +#' if (interactive()) { +#' library(shiny) +#' library(shinygouv) +#' +#' ui <- fluidPage_dsfr( +#' header = header_dsfr( +#' intitule = "Intitule", +#' officiel = "Officiel", +#' nom_site_service = "Nom du site / service", +#' baseline = "baseline - precisions sur l organisation", +#' class = "fr-m-1w" +#' ), +#' title = "Exemple", +#' fluidRow_dsfr( +#' # sans vecteur nommé +#' dateRangeInput_dsfr(inputId = "daterange1", +#' label = "Date range:", start = "2001-01-01",separator = "à") +#' ) +#' ) +#' server <- function(input, output, session) { +#' +#' observeEvent(input$daterange1, { +#' print(input$daterange1) +#' }) +#' +#' } +#' +#' +#' shinyApp(ui, server) +#' } +dateRangeInput_dsfr <- function( + inputId, + label, + start = NULL, + end = NULL, + separator = "to" + ) { + # check les params + assertthat::assert_that(is.character(inputId)) + assertthat::assert_that(is.character(separator)) + assertthat::assert_that(is.character(label)) + + + if (isTRUE(is.null(start))) { + start <- Sys.Date() + } else { + assertthat::assert_that(is.character(start)) + } + + if (isTRUE(is.null(end))) { + end <- Sys.Date() + } else { + assertthat::assert_that(is.character(end)) + } + + dateRangeInput_dsfr_template( + inputId = inputId, + label = label, + start = start, + end = end, + separator = separator + ) #%>% + #parse_html() + + +} diff --git a/R/daterangeinput_dsfr_template.R b/R/daterangeinput_dsfr_template.R new file mode 100644 index 00000000..e63df5a8 --- /dev/null +++ b/R/daterangeinput_dsfr_template.R @@ -0,0 +1,38 @@ +# WARNING - Generated by {fusen} from /dev/flat_composants/flat_dateRangeInput.Rmd: do not edit by hand + +#' dateRangeInput_dsfr_template +#' +#' @param inputId inputId +#' @param start character La date de début au format aaaa-mm-jj. Si NULL (valeur par défaut), la date utilisée est la date du jour. +#' @param end character La date de fin au format aaaa-mm-jj. Si NULL (valeur par défaut), la date utilisée est la date du jour. +#' @param label label +#' @param separator character Chaîne à afficher entre les zones de saisie de début et de fin de dates. +#' +#' @importFrom htmltools htmlTemplate +#' @importFrom purrr pmap +#' @return html +#' @noRd +dateRangeInput_dsfr_template <- function( + inputId, + label, + start, + end, + separator + ) { + + + htmltools::htmlTemplate( + filename = system.file( + get_dsfr_version(with_v = TRUE), + "composant", + "dateRangeInput.html", + package = "shinygouv" + ), + inputId = inputId, + label = label, + start = start, + end = end, + separator = separator + ) + + } diff --git a/R/fluidpage_dsfr.R b/R/fluidpage_dsfr.R index 228a0fcd..e67446df 100644 --- a/R/fluidpage_dsfr.R +++ b/R/fluidpage_dsfr.R @@ -4,6 +4,7 @@ #' #' @param ... element a inclure dans la page #' @param header l entete de la page (voir `header_dsfr()`) +#' @param footer contenu du pied de page #' @param theme pas implemente #' @param lang pas implemente #' @param title titre de la page @@ -16,7 +17,7 @@ #' #' @examples #' if (interactive()) { -#' +#' #' library(shiny) #' my_page <- fluidPage_dsfr( #' header = header_dsfr( @@ -25,7 +26,7 @@ #' title = "Gouv", #' htmltools::div("test") #' ) -#' +#' #' shiny::shinyApp( #' my_page, #' server = function(input, output) {} @@ -35,6 +36,7 @@ fluidPage_dsfr <- function( ..., header = NULL, title = NULL, + footer = NULL, theme = NULL, lang = NULL ) { @@ -45,7 +47,8 @@ fluidPage_dsfr <- function( title = tagList(title), body = tagList( ... - ) + ), + footer = footer ) %>% # parse_html(zone = "/html") %>% add_dsfr_deps() diff --git a/R/fluidpage_dsfr_template.R b/R/fluidpage_dsfr_template.R index 1062ba65..ebd378c1 100644 --- a/R/fluidpage_dsfr_template.R +++ b/R/fluidpage_dsfr_template.R @@ -4,6 +4,8 @@ #' @param header entete de la page #' @param title titre de la page #' @param body body +#' @param footer footer de la page +#' @param class class du container principal #' #' @importFrom htmltools htmlTemplate #' @return html @@ -11,7 +13,9 @@ fluidPage_dsfr_template <- function( header, title, - body + body, + footer = NULL, + class = "fr-container" ) { htmltools::htmlTemplate( filename = system.file( @@ -22,6 +26,10 @@ fluidPage_dsfr_template <- function( ), header = header, title = title, - body = body + body = tags$div( + class = class, + body + ), + footer = footer ) } diff --git a/R/mod_input_limited_choices.R b/R/mod_input_limited_choices.R index d6269cef..c5966ebd 100644 --- a/R/mod_input_limited_choices.R +++ b/R/mod_input_limited_choices.R @@ -350,6 +350,59 @@ mod_input_limited_choices_ui <- function(id){ ) ) + ) + ), + tabPanel_dsfr( + id = ns("tab7"), + title = "dateRangeInput_dsfr()", + content = tagList( + fluidRow_dsfr( + column_dsfr( + 12, + h3("Demo dateRangeInput_dsfr()"), + # Adding space to the column + # https://www.systeme-de-design.gouv.fr/elements-d-interface/fondamentaux-techniques/espacement + extra_class = "fr-my-6w" + ), + column_dsfr( + 3, + dateRangeInput_dsfr(inputId = ns("dateRangeInput"), + label = "Date range:", + start = "2001-01-01", + end = "2023-07-07", + separator = "\u00e0"), + verbatimTextOutput( + outputId = ns("dateRangeInputvalue") + ) + ) + ), + fluidRow_dsfr( + column_dsfr( + 4, + extra_class = "fr-my-6w", + actionButton_dsfr( + inputId = ns("updatedateRangeInput"), + label = "Mettre \u00e0 jour le label" + ) + ), + column_dsfr( + 4, + extra_class = "fr-my-6w", + actionButton_dsfr( + inputId = ns("updatedateRangeInput2"), + label = "Mettre \u00e0 jour le start" + ) + ), + column_dsfr( + 4, + extra_class = "fr-my-6w", + actionButton_dsfr( + inputId = ns("updatedateRangeInput3"), + label = "Mettre \u00e0 jour le end" + ) + ) + ) + ) ) ) @@ -370,7 +423,7 @@ mod_input_limited_choices_server <- function(id){ choices = LETTERS[1:10] ) - ## checkboxinput + ## checkboxinput ---- output$outputcheckbox <- renderText({ paste("Valeur du checkbox :", input$mycheckboxInput) }) @@ -391,7 +444,7 @@ mod_input_limited_choices_server <- function(id){ ) }) - ## checkboxgroupinput + ## checkboxgroupinput ---- output$outputcheckboxgroup <- renderText({ paste("Valeur du checkboxgroup :", paste0(input$mycheckboxgroupInput, collapse = " ")) }) @@ -414,7 +467,7 @@ mod_input_limited_choices_server <- function(id){ ) }) - ## radioButtons + ## radioButtons ---- output$outputespece <- renderText({ paste("Esp\u00e8ce :", input$espece) }) @@ -437,7 +490,7 @@ mod_input_limited_choices_server <- function(id){ ) }) - ## radioGroupButtons + ## radioGroupButtons ---- output$outputespece_radiogroupbutton <- renderText({ paste("Esp\u00e8ce radiogroupbutton :", input$espece_radiogroupbutton) }) @@ -475,7 +528,7 @@ mod_input_limited_choices_server <- function(id){ }) - ## toggle switch + ## toggle switch ---- output$toggleswitchvalue <- renderText({ paste0("La valeur du toggleSwitch est ", input$toggleswitch) }) @@ -495,7 +548,7 @@ mod_input_limited_choices_server <- function(id){ ) }) - ## selectinput + ## selectinput ---- observeEvent(input$updateselectinput, { updateSelectInput_dsfr( inputId = "selectinput", @@ -518,6 +571,38 @@ mod_input_limited_choices_server <- function(id){ ) }) + ## dateRangeInput ---- + + output$dateRangeInputvalue <- renderText({ + paste0("La valeur du dateRangeInput est ", paste0(input$dateRangeInput, collapse = "/")) + }) + + observeEvent(input$updatedateRangeInput, { + updateDateRangeInput_dsfr( + session = session, + inputId = "dateRangeInput", + label = paste(sample(letters, 10), collapse = "") + ) + + }) + + observeEvent(input$updatedateRangeInput2, { + new_start = sample(seq(as.Date('2000/01/01'), Sys.Date(), by="day"), 1) + updateDateRangeInput_dsfr( + session = session, + inputId = "dateRangeInput", + start = new_start + ) + }) + + observeEvent(input$updatedateRangeInput3, { + new_end = sample(seq(as.Date('2000/01/01'), Sys.Date(), by="day"), 1) + updateDateRangeInput_dsfr( + session = session, + inputId = "dateRangeInput", + end = new_end + ) + }) }) } diff --git a/R/navbarpage_dsfr.R b/R/navbarpage_dsfr.R index df1044f2..70f52cf8 100644 --- a/R/navbarpage_dsfr.R +++ b/R/navbarpage_dsfr.R @@ -9,6 +9,7 @@ #' @param title Titre de l'application (Attention, différent de shiny::navbarPage) #' @param id Id de la navbar #' @param header header_dsfr() +#' @param footer pied de page #' #' @examples #' library(shiny) @@ -49,7 +50,7 @@ #' ) #' ) #' , -#' +#' #' # Second tab #' navbarPanel_dsfr( #' title = "radioButtons_dsfr()", @@ -85,13 +86,13 @@ #' output$output1 <- renderText({ #' paste("You clicked", input$go, "times") #' }) -#' +#' #' output$output2 <- renderText({ #' paste("You've selected", input$espece) #' }) -#' +#' #' } -#' +#' #' if (interactive()) { #' # Run the application #' shinyApp(ui = ui, server = server) @@ -100,7 +101,8 @@ navbarPage_dsfr <- function( title, ..., header = NULL, - id = NULL + id = NULL, + footer = NULL ) { all_navs <- list(...) # Making the first tab the current one @@ -165,7 +167,8 @@ navbarPage_dsfr <- function( ) } ) - ) + ), + footer = footer ) %>% add_dsfr_deps() } @@ -174,19 +177,22 @@ navbarPage_dsfr <- function( #' Panel pour la navbar #' #' @param title Titre du panel -#' @param ... UI du panel +#' @param class Classe CSS du panel +#' @param ... Contenu du panel #' #' @export navbarPanel_dsfr <- function( - title, - ... - ) { - + title, + ..., + class = "fr-container" +) { list( title = title, id = janitor::make_clean_names(title), - ui = tagList( + ui = tags$div( + class = class, ... ) ) } + diff --git a/R/shinygouv-dependencies.R b/R/shinygouv-dependencies.R index e9b6b0aa..632b85cc 100644 --- a/R/shinygouv-dependencies.R +++ b/R/shinygouv-dependencies.R @@ -51,6 +51,17 @@ add_dsfr_deps <- function(tag, version = get_dsfr_version()) { package = "shinygouv", all_files = TRUE ), + daterangeinput_deps = htmlDependency( + name = "daterangeinput", + version = version, + src = c(file = "external_deps"), + script = list( + list(type = "text/javascript", src = "daterange.js"), + list(type = "text/javascript", src = "daterangeinputShinyCustomMessage.js") + ), + package = "shinygouv", + all_files = TRUE + ), radiogroupbutton_deps = htmlDependency( name = "radiogroupbuttons", version = version, diff --git a/R/updatedaterangeinput_dsfr.R b/R/updatedaterangeinput_dsfr.R new file mode 100644 index 00000000..2be892d0 --- /dev/null +++ b/R/updatedaterangeinput_dsfr.R @@ -0,0 +1,90 @@ +# WARNING - Generated by {fusen} from /dev/flat_composants/flat_dateRangeInput.Rmd: do not edit by hand + +#' updateDateRangeInput_dsfr +#' +#' @param inputId inputId +#' @param label label +#' @param start character La date de début au format aaaa-mm-jj. Si NULL (valeur par défaut), la date utilisée est la date du jour. +#' @param end character La date de fin au format aaaa-mm-jj. Si NULL (valeur par défaut), la date utilisée est la date du jour. +#' @param session la session, la valeur par défaut est getDefaultReactiveDomain(). +#' @importFrom shiny updateCheckboxInput +#' @return html +#' +#' @export +#' @examples +#' ## Only run examples in interactive R sessions +#' if (interactive()) { +#' +#' library(shiny) +#' +#' ui <- fluidPage_dsfr( +#' dateRangeInput_dsfr(inputId = "daterange1", +#' label = "Date range:", start = "2001-01-01",separator = "à"), +#' actionButton_dsfr("go", "Change label"), +#' actionButton_dsfr("go2", "Change start"), +#' actionButton_dsfr("go3", "Change end") +#' ) +#' +#' server <- function(input, output, session) { +#' observeEvent(input$daterange1, { +#' print(input$daterange1) +#' }) +#' +#' +#' observeEvent(input$go, { +#' updateDateRangeInput_dsfr( +#' session = session, +#' inputId = "daterange1", +#' label = "new label" +#' ) +#' +#' }) +#' +#' +#' observeEvent(input$go2, { +#' updateDateRangeInput_dsfr( +#' session = session, +#' inputId = "daterange1", +#' start = "2000-01-01" +#' ) +#' +#' }) +#' +#' observeEvent(input$go3, { +#' updateDateRangeInput_dsfr( +#' session = session, +#' inputId = "daterange1", +#' end = "2020-01-01" +#' ) +#' +#' }) +#' } +#' shinyApp(ui, server) +#' } +updateDateRangeInput_dsfr <- function(inputId, + label = NULL, + start = NULL, + end = NULL, + session = shiny::getDefaultReactiveDomain()) { + + + ns <- session$ns + + if (!is.null(label)) { + session$sendCustomMessage("updateDateRangeInputLabel", + list(inputId = ns(inputId), + label = label)) + } + + if (!is.null(start)) { + session$sendCustomMessage("updateDateRangeInputStart", + list(inputId = ns(inputId), + start = start)) + } + + if (!is.null(end)) { + session$sendCustomMessage("updateDateRangeInputEnd", + list(inputId = ns(inputId), + end = end)) + } +} diff --git a/README.Rmd b/README.Rmd index 799c6bff..3c310281 100644 --- a/README.Rmd +++ b/README.Rmd @@ -24,30 +24,33 @@ Le package s'utilise comme {shiny}. Voici un exemple minimaliste pour la partie ```{r, eval=FALSE} library(shiny) library(shinygouv) - app_ui <- fluidPage_dsfr( header = header_dsfr( - intitule = "Intitule", - officiel = "Officiel", - nom_site_service = "Nom du site / service", - baseline = "baseline - precisions sur l organisation", - class = "fr-m-1w" - ), + intitule = span("D\u00e9mo", br(), "de", br(), "{shinygouv}"), + nom_site_service = "Bienvenue sur l\'application de d\u00e9monstration de {shinygouv}", + baseline = "https://github.com/spyrales/shinygouv" + ), title = "Exemple", fluidRow_dsfr( column_dsfr( 0, - shiny::p("Exemple colonne") + fileInput("file1", "Ajouter des fichiers", accept = ".csv") ) ) ) +shinyApp( + ui = app_ui, + server = function(input, output) { + } +) ``` + # Visualiser un application de démonstration comprenant les composants déjà implémentés: [shinygouv-demo](https://ssm-ecologie.shinyapps.io/shinygouv-demo/) -# Contribuer au développement du package +# Contribuer au développement du package Voir le README du dossier [documentation](dev/documentation) diff --git a/dev/config_fusen.yaml b/dev/config_fusen.yaml index efe75934..7465a8d7 100644 --- a/dev/config_fusen.yaml +++ b/dev/config_fusen.yaml @@ -11,9 +11,9 @@ flat_actionButton.Rmd: inflate: flat_file: dev/flat_composants/flat_actionButton.Rmd vignette_name: actionButton_dsfr - open_vignette: true - check: false - document: true + open_vignette: yes + check: no + document: yes overwrite: ask flat_checkBoxInput.Rmd: path: dev/flat_composants/flat_checkBoxInput.Rmd @@ -38,9 +38,9 @@ flat_checkBoxInput.Rmd: inflate: flat_file: dev/flat_composants/flat_checkBoxInput.Rmd vignette_name: .na - open_vignette: true - check: false - document: true + open_vignette: yes + check: no + document: yes overwrite: ask flat_convert_to_dsfr.Rmd: path: dev/flat_convert_to_dsfr.Rmd @@ -57,9 +57,9 @@ flat_convert_to_dsfr.Rmd: inflate: flat_file: dev/flat_convert_to_dsfr.Rmd vignette_name: Convertir une app shiny en app shiny dsfr - open_vignette: true - check: true - document: true + open_vignette: yes + check: yes + document: yes overwrite: ask flat_fluidpage.Rmd: path: dev/flat_composants/flat_fluidpage.Rmd @@ -78,11 +78,12 @@ flat_fluidpage.Rmd: - tests/testthat/test-column_dsfr.R vignettes: [] inflate: + pkg: shinygouv flat_file: dev/flat_composants/flat_fluidpage.Rmd vignette_name: .na - open_vignette: true - check: false - document: true + open_vignette: yes + check: no + document: yes overwrite: ask flat_header.Rmd: path: dev/flat_composants/flat_header.Rmd @@ -97,9 +98,9 @@ flat_header.Rmd: inflate: flat_file: dev/flat_composants/flat_header.Rmd vignette_name: .na - open_vignette: false - check: false - document: true + open_vignette: no + check: no + document: yes overwrite: ask flat_modal.Rmd: path: dev/flat_composants/flat_modal.Rmd @@ -114,9 +115,9 @@ flat_modal.Rmd: inflate: flat_file: dev/flat_composants/flat_modal.Rmd vignette_name: .na - open_vignette: true - check: false - document: true + open_vignette: yes + check: no + document: yes overwrite: ask flat_navbarPage.Rmd: path: dev/flat_composants/flat_navbarPage.Rmd @@ -125,11 +126,12 @@ flat_navbarPage.Rmd: tests: tests/testthat/test-navbarpage_dsfr.R vignettes: [] inflate: + pkg: shinygouv flat_file: dev/flat_composants/flat_navbarPage.Rmd vignette_name: .na - open_vignette: true - check: false - document: true + open_vignette: yes + check: no + document: yes overwrite: ask flat_numericInput.Rmd: path: dev/flat_composants/flat_numericInput.Rmd @@ -146,9 +148,9 @@ flat_numericInput.Rmd: inflate: flat_file: dev/flat_composants/flat_numericInput.Rmd vignette_name: .na - open_vignette: true - check: false - document: true + open_vignette: yes + check: no + document: yes overwrite: ask flat_panels.Rmd: path: dev/flat_composants/flat_panels.Rmd @@ -165,9 +167,9 @@ flat_panels.Rmd: inflate: flat_file: dev/flat_composants/flat_panels.Rmd vignette_name: .na - open_vignette: true - check: false - document: true + open_vignette: yes + check: no + document: yes overwrite: ask flat_radioButtons.Rmd: path: dev/flat_composants/flat_radioButtons.Rmd @@ -186,9 +188,9 @@ flat_radioButtons.Rmd: inflate: flat_file: dev/flat_composants/flat_radioButtons.Rmd vignette_name: .na - open_vignette: false - check: false - document: true + open_vignette: no + check: no + document: yes overwrite: 'yes' flat_radioGroupButtons.Rmd: path: dev/flat_composants/flat_radioGroupButtons.Rmd @@ -207,9 +209,9 @@ flat_radioGroupButtons.Rmd: inflate: flat_file: dev/flat_composants/flat_radioGroupButtons.Rmd vignette_name: .na - open_vignette: false - check: false - document: true + open_vignette: no + check: no + document: yes overwrite: 'yes' flat_selectInput.Rmd: path: dev/flat_composants/flat_selectInput.Rmd @@ -228,9 +230,9 @@ flat_selectInput.Rmd: inflate: flat_file: dev/flat_composants/flat_selectInput.Rmd vignette_name: .na - open_vignette: true - check: false - document: true + open_vignette: yes + check: no + document: yes overwrite: ask flat_slider.Rmd: path: dev/flat_composants/flat_slider.Rmd @@ -242,9 +244,9 @@ flat_slider.Rmd: pkg: shinygouv flat_file: dev/flat_composants/flat_slider.Rmd vignette_name: .na - open_vignette: true - check: true - document: true + open_vignette: yes + check: yes + document: yes overwrite: ask flat_toggleswitch.Rmd: path: dev/flat_composants/flat_toggleswitch.Rmd @@ -260,9 +262,9 @@ flat_toggleswitch.Rmd: inflate: flat_file: dev/flat_composants/flat_toggleswitch.Rmd vignette_name: .na - open_vignette: true - check: false - document: true + open_vignette: yes + check: no + document: yes overwrite: ask flat_tools.Rmd: path: dev/tools/flat_tools.Rmd @@ -280,9 +282,9 @@ flat_tools.Rmd: inflate: flat_file: dev/tools/flat_tools.Rmd vignette_name: .na - open_vignette: true - check: false - document: true + open_vignette: yes + check: no + document: yes overwrite: 'yes' flat_withSpinner.Rmd: path: dev/flat_composants/flat_withSpinner.Rmd @@ -293,7 +295,7 @@ flat_withSpinner.Rmd: inflate: flat_file: dev/flat_composants/flat_withSpinner.Rmd vignette_name: withSpinner_dsfr - open_vignette: false - check: false - document: true + open_vignette: no + check: no + document: yes overwrite: 'yes' diff --git a/dev/flat_composants/flat_dateRangeInput.Rmd b/dev/flat_composants/flat_dateRangeInput.Rmd new file mode 100644 index 00000000..7052c020 --- /dev/null +++ b/dev/flat_composants/flat_dateRangeInput.Rmd @@ -0,0 +1,455 @@ +--- +title: "flat_new_one.Rmd empty" +output: html_document +editor_options: + chunk_output_type: console +--- + + +```{r development, include=FALSE} +library(testthat) +``` + +```{r development-load} +# Load already included functions if relevant +pkgload::load_all(export_all = TRUE) +``` + + + +# dateRangeInput_dsfr_template + +```{r function-dateRangeInput_dsfr_template} +#' dateRangeInput_dsfr_template +#' +#' @param inputId inputId +#' @param start character La date de début au format aaaa-mm-jj. Si NULL (valeur par défaut), la date utilisée est la date du jour. +#' @param end character La date de fin au format aaaa-mm-jj. Si NULL (valeur par défaut), la date utilisée est la date du jour. +#' @param label label +#' @param separator character Chaîne à afficher entre les zones de saisie de début et de fin de dates. +#' +#' @importFrom htmltools htmlTemplate +#' @importFrom purrr pmap +#' @return html +#' @noRd +dateRangeInput_dsfr_template <- function( + inputId, + label, + start, + end, + separator + ) { + + + htmltools::htmlTemplate( + filename = system.file( + get_dsfr_version(with_v = TRUE), + "composant", + "dateRangeInput.html", + package = "shinygouv" + ), + inputId = inputId, + label = label, + start = start, + end = end, + separator = separator + ) + + } +``` + + +```{r tests-dateRangeInput_dsfr_template} +test_that("dateRangeInput_dsfr_template works", { + expect_true(inherits(dateRangeInput_dsfr_template, "function")) + + htmlfile <- readLines( + system.file( + get_dsfr_version(with_v = TRUE), + "composant", + "dateRangeInput.html", + package = "shinygouv" + ) + ) + + #' @description Comparer les parametres par rapport a ceux de la version precedente + + + purrr::walk( + c( + "inputId", + "label", + "start", + "end", + "separator" + ), + function(param) { + with_moustache <- paste0("\\{\\{", param, "\\}\\}") + expect_true( + any(grepl(pattern = with_moustache, htmlfile)), + label = paste0("sans moustache '", param, "'") + ) + } + ) + + + test_html <- dateRangeInput_dsfr_template( + inputId = "toto", + label = "titi", + start = "2001-01-01", + end = "2010-12-31", + separator = "to" + ) + + + #' @description tester si tous les params sont remplaces + expect_false(grepl(pattern = "\\{\\{", test_html)) + + + #' @description Verifie que les parametres ont bien ete remplace par leurs valeurs + + purrr::walk( + c( + inputId = "toto", + label = "titi", + start = "2001-01-01", + end = "2010-12-31", + separator = "to" + ), + function(param) { + expect_true( + any(grepl(pattern = param, test_html)), + label = paste0("remplacement de '", param, "'") + ) + } + ) + + ## lecture snapshot + snapshot_html <- readRDS( + file = file.path( + "snapshot", # pour passer les tests en production (apres le inflate), + # "tests/testthat/snapshot", # pour passer les tests en developpement (avant le inflate), + "dateRangeInput_dsfr_template.Rda" + ) + ) + + #' @description Verifie le HTML créé + # Retire tous les espaces et saut de ligne pour la comparaison + # Pour eviter les problèmes inter-OS + expect_equal( + gsub("\\s|\\n", "", test_html), + gsub("\\s|\\n", "", snapshot_html) + ) + + + # Si erreur au précedent test deux cas possibles : + # + # - nouveau composant: Lancer le saveRDS, relancer le test et recommenter le saveRDS + # + # - composant a mettre a jour: si le test ne passe plus avant de changer le snapshot, + # assurez vous d'avoir bien pris en compte la nouvelle personnalisation + # dans la fonction radioButtons_unique_dsfr_template puis lancer le saveRDS, relancer le test et recommenter le saveRDS + # + # saveRDS(test_html, + # file = file.path("tests/testthat/snapshot", + # "dateRangeInput_dsfr_template.Rda" + # ) + # ) + # +}) +``` + + +# dateRangeInput_dsfr + +```{r function-dateRangeInput_dsfr} +#' dateRangeInput_dsfr +#' +#' @param inputId inputId +#' @param label label +#' @param start character La date de début au format aaaa-mm-jj. Si NULL (valeur par défaut), la date utilisée est la date du jour. +#' @param end character La date de fin au format aaaa-mm-jj. Si NULL (valeur par défaut), la date utilisée est la date du jour. +#' @param separator character Chaîne à afficher entre les zones de saisie de début et de fin de dates. +#' +#' @importFrom assertthat assert_that +#' @importFrom purrr map +#' @return html +#' +#' @export +#' +#' @examples +dateRangeInput_dsfr <- function( + inputId, + label, + start = NULL, + end = NULL, + separator = "to" + ) { + # check les params + assertthat::assert_that(is.character(inputId)) + assertthat::assert_that(is.character(separator)) + assertthat::assert_that(is.character(label)) + + + if (isTRUE(is.null(start))) { + start <- Sys.Date() + } else { + assertthat::assert_that(is.character(start)) + } + + if (isTRUE(is.null(end))) { + end <- Sys.Date() + } else { + assertthat::assert_that(is.character(end)) + } + + dateRangeInput_dsfr_template( + inputId = inputId, + label = label, + start = start, + end = end, + separator = separator + ) #%>% + #parse_html() + + +} +``` + + +```{r examples-dateRangeInput_dsfr} +## Only run examples in interactive R sessions +if (interactive()) { + library(shiny) + library(shinygouv) + + ui <- fluidPage_dsfr( + header = header_dsfr( + intitule = "Intitule", + officiel = "Officiel", + nom_site_service = "Nom du site / service", + baseline = "baseline - precisions sur l organisation", + class = "fr-m-1w" + ), + title = "Exemple", + fluidRow_dsfr( + # sans vecteur nommé + dateRangeInput_dsfr(inputId = "daterange1", + label = "Date range:", start = "2001-01-01",separator = "à") + ) + ) + server <- function(input, output, session) { + + observeEvent(input$daterange1, { + print(input$daterange1) + }) + + } + + + shinyApp(ui, server) +} +``` + +```{r tests-dateRangeInput_dsfr} +test_that("dateRangeInput_dsfr works", { + expect_true(inherits(dateRangeInput_dsfr, "function")) + + test_html <- dateRangeInput_dsfr(inputId = "daterange1", + label = "Date range:", start = "2001-01-01", + end = "2003-01-01", separator = "à") + + + expect_error( + dateRangeInput_dsfr( + inputId = 123, + label = "Date range:", + start = "2001-01-01", + end = "2003-01-01" + ) + ) + + expect_error( + dateRangeInput_dsfr( + inputId = "daterange1", + label = 123, + start = "2001-01-01", + end = "2003-01-01" + ) + ) + + expect_error( + dateRangeInput_dsfr( + inputId = "daterange1", + label = "Date range:", + start = 123, + end = "2003-01-01" + ) + ) + + expect_error( + dateRangeInput_dsfr( + inputId = "daterange1", + label = "Date range:", + end = 123, + start = "2003-01-01" + ) + ) + + expect_error( + dateRangeInput_dsfr( + inputId = "daterange1", + label = "Date range:", + end = "2003-02-01", + start = "2003-01-01", + separator = 456 + ) + ) + + expect_error( + dateRangeInput_dsfr( + inputId = "daterange1", + label = "Date range:" + ), + regexp = NA + ) + + snapshot_html <- readRDS( + file = file.path( + "snapshot", # pour passer les tests en production (apres le inflate), + # "tests/testthat/snapshot", # pour passer les tests en developpement (avant le inflate), + "dateRangeInput_dsfr.Rda" + ) + ) + #' @description Verifie le parametre selected dans le HTML + expect_equal( + gsub("\\s|\\n", "", test_html), + gsub("\\s|\\n", "", snapshot_html) + ) + + + # Si erreur au précedent test deux cas possible : + # + # - nouveau composant: Lancer le saveRDS, relancer le test et recommenter le saveRDS + # + # - composant a mettre a jour: si le test ne passe plus avant de changer le snapshot, + # assurez vous d'avoir bien pris en compte la nouvelle personnalisation + # dans la fonction radioButtons_dsfr_template puis lancer le saveRDS, relancer le test et recommenter le saveRDS + + # saveRDS(test_html, + # file = file.path("tests/testthat/snapshot", + # "dateRangeInput_dsfr.Rda" + # ) + # ) + +}) +``` + + + +# updateDateRangeInput_dsfr + + +```{r function-updateCheckboxInput_dsfr} +#' updateDateRangeInput_dsfr +#' +#' @param inputId inputId +#' @param label label +#' @param start character La date de début au format aaaa-mm-jj. Si NULL (valeur par défaut), la date utilisée est la date du jour. +#' @param end character La date de fin au format aaaa-mm-jj. Si NULL (valeur par défaut), la date utilisée est la date du jour. +#' @param session la session, la valeur par défaut est getDefaultReactiveDomain(). +#' @importFrom shiny updateCheckboxInput +#' @return html +#' +#' @export +updateDateRangeInput_dsfr <- function(inputId, + label = NULL, + start = NULL, + end = NULL, + session = shiny::getDefaultReactiveDomain()) { + + + ns <- session$ns + + if (!is.null(label)) { + session$sendCustomMessage("updateDateRangeInputLabel", + list(inputId = ns(inputId), + label = label)) + } + + if (!is.null(start)) { + session$sendCustomMessage("updateDateRangeInputStart", + list(inputId = ns(inputId), + start = start)) + } + + if (!is.null(end)) { + session$sendCustomMessage("updateDateRangeInputEnd", + list(inputId = ns(inputId), + end = end)) + } +} +``` + +```{r examples-updateDateRangeInput_dsfr} +## Only run examples in interactive R sessions +if (interactive()) { + + library(shiny) + + ui <- fluidPage_dsfr( + dateRangeInput_dsfr(inputId = "daterange1", + label = "Date range:", start = "2001-01-01",separator = "à"), + actionButton_dsfr("go", "Change label"), + actionButton_dsfr("go2", "Change start"), + actionButton_dsfr("go3", "Change end") + ) + + server <- function(input, output, session) { + observeEvent(input$daterange1, { + print(input$daterange1) + }) + + + observeEvent(input$go, { + updateDateRangeInput_dsfr( + session = session, + inputId = "daterange1", + label = "new label" + ) + + }) + + + observeEvent(input$go2, { + updateDateRangeInput_dsfr( + session = session, + inputId = "daterange1", + start = "2000-01-01" + ) + + }) + + observeEvent(input$go3, { + updateDateRangeInput_dsfr( + session = session, + inputId = "daterange1", + end = "2020-01-01" + ) + + }) + } + shinyApp(ui, server) +} +``` + + +```{r development-inflate, eval=FALSE} +# Run but keep eval=FALSE to avoid infinite loop +# Execute in the console directly +fusen::inflate( + flat_file = "dev/flat_composants/flat_dateRangeInput.Rmd", + vignette_name = NA, + check = FALSE +) +``` diff --git a/dev/flat_composants/flat_fluidpage.Rmd b/dev/flat_composants/flat_fluidpage.Rmd index 285a7eff..9d8c8e2c 100644 --- a/dev/flat_composants/flat_fluidpage.Rmd +++ b/dev/flat_composants/flat_fluidpage.Rmd @@ -29,13 +29,17 @@ Ensuite, vient la traduction avec `htmlTemplate` : #' @param header entete de la page #' @param title titre de la page #' @param body body +#' @param footer footer de la page +#' @param class class du container principal #' #' @importFrom htmltools htmlTemplate #' @return html fluidPage_dsfr_template <- function( header, title, - body + body, + footer = NULL, + class = "fr-container" ) { htmltools::htmlTemplate( filename = system.file( @@ -46,30 +50,34 @@ fluidPage_dsfr_template <- function( ), header = header, title = title, - body = body + body = tags$div( + class = class, + body + ), + footer = footer ) } ``` ```{r, eval=FALSE, echo=TRUE} -fluidPage_dsfr_template <- function( - header, - title, - body - ) { - - htmltools::htmlTemplate( - filename = system.file( - get_dsfr_version(with_v = TRUE), - "composant", - "fluidpage.html", - package = "shinygouv" - ), - header = NULL, - title = title, - body = body - ) -} +# fluidPage_dsfr_template <- function( +# header, +# title, +# body +# ) { + +# htmltools::htmlTemplate( +# filename = system.file( +# get_dsfr_version(with_v = TRUE), +# "composant", +# "fluidpage.html", +# package = "shinygouv" +# ), +# header = NULL, +# title = title, +# body = body +# ) +# } ``` Les paramètres `header`, `title` et `body` sont repris dans le html pour pouvoir le créer. @@ -93,7 +101,8 @@ test_that("fluidPage_dsfr_template works", { c( "header", "title", - "body" + "body", + "footer" ), function(param) { with_moustache <- paste0("\\{\\{", param, "\\}\\}") @@ -105,7 +114,8 @@ test_that("fluidPage_dsfr_template works", { test_html <- fluidPage_dsfr_template( header = "header", title = "titre", - body = "body" + body = "body", + footer = "footer" ) #' @description tester si tous les params sont remplaces @@ -117,7 +127,8 @@ test_that("fluidPage_dsfr_template works", { c( header = "header", title = "titre", - body = "body" + body = "body", + footer = "footer" ), function(param) { expect_true(any(grepl(pattern = param, test_html)), @@ -128,13 +139,13 @@ test_that("fluidPage_dsfr_template works", { snapshot_html <- readRDS( file = file.path( "snapshot", # pour passer les tests en production (apres le inflate), - # "tests/testthat/snapshot", # pour passer les tests en developpement (avant le inflate), + #"tests/testthat/snapshot", # pour passer les tests en developpement (avant le inflate), "fluidPage_dsfr_template.Rda") ) #' @description Verifie la presence du parametre class - # expect_equal(gsub("\\s|\\n", "", test_html), - # gsub("\\s|\\n", "", snapshot_html)) + expect_equal(gsub("\\s|\\n", "", test_html), + gsub("\\s|\\n", "", snapshot_html)) # Si erreur au précedent test deux cas possible : # @@ -168,6 +179,7 @@ Il est donc à noter qu'il ne sera pas possible de faire des tags Attributes sur #' #' @param ... element a inclure dans la page #' @param header l entete de la page (voir `header_dsfr()`) +#' @param footer contenu du pied de page #' @param theme pas implemente #' @param lang pas implemente #' @param title titre de la page @@ -183,6 +195,7 @@ fluidPage_dsfr <- function( ..., header = NULL, title = NULL, + footer = NULL, theme = NULL, lang = NULL ) { @@ -193,7 +206,8 @@ fluidPage_dsfr <- function( title = tagList(title), body = tagList( ... - ) + ), + footer = footer ) %>% # parse_html(zone = "/html") %>% add_dsfr_deps() @@ -203,28 +217,28 @@ fluidPage_dsfr <- function( ``` ```{r, eval=FALSE, echo=TRUE} -fluidPage_dsfr <- function( - ..., - header = NULL, - title = NULL, - theme = NULL, - lang = NULL - ) { - - # TODO theme et lang - # check les params - ui <- fluidPage_dsfr_template( - header = tagList(header), - title = tagList(title), - body = tagList( - ... - ) - ) %>% - parse_html(zone = "/html") %>% - add_dsfr_deps() - ui - -} +# fluidPage_dsfr <- function( +# ..., +# header = NULL, +# title = NULL, +# theme = NULL, +# lang = NULL +# ) { + +# # TODO theme et lang +# # check les params +# ui <- fluidPage_dsfr_template( +# header = tagList(header), +# title = tagList(title), +# body = tagList( +# ... +# ) +# ) %>% +# parse_html(zone = "/html") %>% +# add_dsfr_deps() +# ui + +# } ``` @@ -263,7 +277,7 @@ test_that("fluidPage_dsfr works", { snapshot_html <- readRDS( file = file.path( "snapshot", # pour passer les tests en production (apres le inflate), - # "tests/testthat/snapshot", # pour passer les tests en developpement (avant le inflate), + #"tests/testthat/snapshot", # pour passer les tests en developpement (avant le inflate), "fluidPage_dsfr.Rda") ) @@ -487,7 +501,7 @@ fluidRow_dsfr <- function(..., class = NULL) { ) } ``` - + ```{r example-fluidRow_dsfr} if (interactive()) { shiny::shinyApp( @@ -610,8 +624,8 @@ column_dsfr <- function(width = NULL, ...) { other_class = NULL ) } -``` - +``` + ```{r example-column_dsfr} if (interactive()) { shiny::shinyApp( diff --git a/dev/flat_composants/flat_navbarPage.Rmd b/dev/flat_composants/flat_navbarPage.Rmd index a6020be0..259ff1ba 100644 --- a/dev/flat_composants/flat_navbarPage.Rmd +++ b/dev/flat_composants/flat_navbarPage.Rmd @@ -33,13 +33,15 @@ La `navbarPage_dsfr()` se compose de : #' @param title Titre de l'application (Attention, différent de shiny::navbarPage) #' @param id Id de la navbar #' @param header header_dsfr() +#' @param footer pied de page #' #' @examples navbarPage_dsfr <- function( title, ..., header = NULL, - id = NULL + id = NULL, + footer = NULL ) { all_navs <- list(...) # Making the first tab the current one @@ -104,7 +106,8 @@ navbarPage_dsfr <- function( ) } ) - ) + ), + footer = footer ) %>% add_dsfr_deps() } @@ -113,22 +116,25 @@ navbarPage_dsfr <- function( #' Panel pour la navbar #' #' @param title Titre du panel -#' @param ... UI du panel +#' @param class Classe CSS du panel +#' @param ... Contenu du panel #' #' @export navbarPanel_dsfr <- function( - title, - ... - ) { - + title, + ..., + class = "fr-container" +) { list( title = title, id = janitor::make_clean_names(title), - ui = tagList( + ui = tags$div( + class = class, ... ) ) } + ``` ```{r examples-navbarPage_dsfr} diff --git a/inst/external_deps/daterange.js b/inst/external_deps/daterange.js new file mode 100644 index 00000000..9515ab75 --- /dev/null +++ b/inst/external_deps/daterange.js @@ -0,0 +1,12 @@ +const inputdate = function (inputId) { + + + var start = $("#"+inputId+"-start").val(); + var end = $("#"+inputId+"-end").val(); + + +console.log(start) +console.log(end) + + Shiny.setInputValue(inputId, {start: start, end: end}) + } diff --git a/inst/external_deps/daterangeinputShinyCustomMessage.js b/inst/external_deps/daterangeinputShinyCustomMessage.js new file mode 100644 index 00000000..7c31438c --- /dev/null +++ b/inst/external_deps/daterangeinputShinyCustomMessage.js @@ -0,0 +1,18 @@ +$(document).ready(function () { + Shiny.addCustomMessageHandler('updateDateRangeInputLabel', function (args) { + document.getElementById(args.inputId + "-label").innerHTML + = args.label; + }); + + Shiny.addCustomMessageHandler('updateDateRangeInputStart', function (args) { + document.getElementById(args.inputId + "-start").value = args.start; + Shiny.setInputValue(args.inputId, {start: args.start, end: document.getElementById(args.inputId + "-end").value}); + }); + + Shiny.addCustomMessageHandler('updateDateRangeInputEnd', function (args) { + document.getElementById(args.inputId + "-end").value = args.end; + Shiny.setInputValue(args.inputId, {start: document.getElementById(args.inputId + "-start").value, end: args.end}); + + }); +}); + diff --git a/inst/external_deps/radiogroupbuttons.js b/inst/external_deps/radiogroupbuttons.js index a07887b0..55ce3579 100644 --- a/inst/external_deps/radiogroupbuttons.js +++ b/inst/external_deps/radiogroupbuttons.js @@ -10,4 +10,3 @@ $(current_name).parent().removeClass('fr-btn--secondary'); $(current_name).parent().parent().parent().find("button").not(current_button).addClass("fr-btn--secondary"); }; - diff --git a/inst/v1.9.3/composant/dateRangeInput.html b/inst/v1.9.3/composant/dateRangeInput.html new file mode 100644 index 00000000..eb8a14ad --- /dev/null +++ b/inst/v1.9.3/composant/dateRangeInput.html @@ -0,0 +1,24 @@ +
+ + + +