Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Ajout du composant header_dsfr #41

Merged
merged 2 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export(add_dsfr_deps)
export(column_dsfr)
export(fluidPage_dsfr)
export(fluidRow_dsfr)
export(header_dsfr)
export(parse_html)
export(radioButtons_dsfr)
export(run_app)
Expand Down
5 changes: 2 additions & 3 deletions R/app_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
app_server <- function(input, output, session) {
# Your application server logic

observeEvent(input$go,{
observeEvent(input$go, {
message("je clique ", input$go)
})

observeEvent(input$espece,{
observeEvent(input$espece, {
message("je change d'esepce ", input$espece)
})

}
45 changes: 27 additions & 18 deletions R/app_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,36 @@ app_ui <- function(request) {
golem_add_external_resources(),
# Your application UI logic
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 shiny dsfr",
h1("Exemple d'utilisation de {shinygouv}"),
fluidRow_dsfr(
column_dsfr(0, #Calcul automatique de la largeur
p("Premi\\u00E8re Colonne"),
actionButton_dsfr("go", label = "Sample!"),
plotOutput(
"plot_sample"
)
),
column_dsfr(0,#Calcul automatique de la largeur
p("Deuxi\\u00E8me Colonne"),
radioButtons_dsfr(
inputId = "espece",
label = "Especes",
choices = c("Setosa" = "setosa","Versicolor" = "versicolor"),
class = NULL
),
plotOutput(
"plot_espece"
)
column_dsfr(
0, # Calcul automatique de la largeur
p("Premi\\u00E8re Colonne"),
actionButton_dsfr("go", label = "Sample!"),
plotOutput(
"plot_sample"
)
),
column_dsfr(
0, # Calcul automatique de la largeur
p("Deuxi\\u00E8me Colonne"),
radioButtons_dsfr(
inputId = "espece",
label = "Especes",
choices = c("Setosa" = "setosa", "Versicolor" = "versicolor"),
class = NULL
),
plotOutput(
"plot_espece"
)
)
)
)
Expand Down
67 changes: 33 additions & 34 deletions R/column_dsfr.R
Original file line number Diff line number Diff line change
@@ -1,52 +1,51 @@
# WARNING - Generated by {fusen} from /dev/v1.7.2/composant/flat_fluidpage.Rmd: do not edit by hand

#' column_dsfr
#'
#'
#'
#'
#' @param width width par défaut est NULL, cela signifie que la taille de la colonne depend des autres colonnes. Vous pouvez aussi utiliser 0
#' @param ... differents tag pour construire la page
#'
#' @return shiny.tag.list
#'
#'
#' @importFrom htmltools tagList
#'
#'
#' @export
#' @examples
#'
#' if(interactive()){
#' shiny::shinyApp(
#' ui = fluidPage_dsfr(
#' title = "exemple",
#' fluidRow_dsfr(
#' column_dsfr(0, "test"),
#' column_dsfr(0, "test"),
#' column_dsfr(0, "test"),
#' column_dsfr(0, "test")
#' )
#' ),
#' server = function(input, output){}
#'
#' if (interactive()) {
#' shiny::shinyApp(
#' ui = fluidPage_dsfr(
#' title = "exemple",
#' fluidRow_dsfr(
#' column_dsfr(0, "test"),
#' column_dsfr(0, "test"),
#' column_dsfr(0, "test"),
#' column_dsfr(0, "test")
#' )
#' ),
#' server = function(input, output) {}
#' )
#' }
#'
column_dsfr <- function(width = NULL, ...){

if(is.null(width)) {
#'
column_dsfr <- function(width = NULL, ...) {
if (is.null(width)) {
add_width <- ""
}else{
if(width != 0){
add_width <- paste0("-", width)
}else{
add_width <- ""
}
} else {
if (width != 0) {
add_width <- paste0("-", width)
} else {
add_width <- ""
}
}

class <- paste0("fr-col", add_width)

layout_dsfr_template(
html = tagList(
...
),
class = class,
other_class = NULL
)
html = tagList(
...
),
class = class,
other_class = NULL
)
}
38 changes: 22 additions & 16 deletions R/fluidpage_dsfr.R
Original file line number Diff line number Diff line change
@@ -1,46 +1,52 @@
# WARNING - Generated by {fusen} from /dev/v1.7.2/composant/flat_fluidpage.Rmd: do not edit by hand

#' fluidPage_dsfr
#'
#'
#' @param ... element a inclure dans la page
#' @param header l entete de la page
#' @param theme pas implemente
#' @param lang pas implemente
#' @param title titre de la page
#'
#' @return html
#'
#'
#' @importFrom htmltools tagList
#'
#'
#' @export
#'
#' @examples
#' my_page <- fluidPage_dsfr(
#' header = header_dsfr(
#' intitule = "Prefet de",
#' officiel = "Bretagne",
#' ),
#' title = "Gouv",
#' htmltools::div("test")
#' )
#' if(interactive()){
#' shiny::shinyApp(
#' my_page,
#' server = function(input, output){}
#' if (interactive()) {
#' shiny::shinyApp(
#' my_page,
#' server = function(input, output) {}
#' )
#' }
fluidPage_dsfr <- function(
...,
title = NULL,
theme = NULL,
lang = NULL
...,
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()
parse_html(zone = "/html") %>%
add_dsfr_deps()
ui

}
16 changes: 8 additions & 8 deletions R/fluidpage_dsfr_template.R
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
# WARNING - Generated by {fusen} from /dev/v1.7.2/composant/flat_fluidpage.Rmd: do not edit by hand

#' fluidPage_dsfr_template
#'
#' @param header entete de la page
#' @param title titre de la page
#' @param body body
#' @param body body
#'
#' @importFrom htmltools htmlTemplate
#' @return html
#' @noRd
fluidPage_dsfr_template <- function(
title,
body
){
header,
title,
body
) {
htmltools::htmlTemplate(
filename = system.file(
"v1.7.2",
"composant",
"composant",
"fluidpage.html",
package = "shinygouv"
),
header = header,
title = title,
body = body
)
}

44 changes: 22 additions & 22 deletions R/fluidrow_dsfr.R
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
# WARNING - Generated by {fusen} from /dev/v1.7.2/composant/flat_fluidpage.Rmd: do not edit by hand

#' fluidRow_dsfr
#'
#'
#'
#'
#' @param ... differents tag pour construire la page
#' @param class ajout de class pour la fluidRow_dsfr (voir la page officiel du CSS)
#'
#' @return shiny.tag.list
#' @importFrom htmltools tagList
#'
#'
#' @export
#' @examples
#'
#' if(interactive()){
#' shiny::shinyApp(
#' ui = fluidPage_dsfr(
#' title = "exemple",
#' fluidRow_dsfr(
#' shiny::p("Voici un exemple")
#' )
#' ),
#' server = function(input, output){}
#'
#' if (interactive()) {
#' shiny::shinyApp(
#' ui = fluidPage_dsfr(
#' title = "exemple",
#' fluidRow_dsfr(
#' shiny::p("Voici un exemple")
#' )
#' ),
#' server = function(input, output) {}
#' )
#' }
#'
fluidRow_dsfr <- function(..., class = NULL){
layout_dsfr_template(
html = tagList(
...
),
class = "fr-grid-row",
other_class = class
)
#'
fluidRow_dsfr <- function(..., class = NULL) {
layout_dsfr_template(
html = tagList(
...
),
class = "fr-grid-row",
other_class = class
)
}
46 changes: 46 additions & 0 deletions R/header_dsfr.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# WARNING - Generated by {fusen} from /dev/v1.7.2/composant/flat_header.Rmd: do not edit by hand

#' header_dsfr
#'
#' @param intitule la partie "intitule" du bloc marque
#' @param officiel la partie "officiel" du bloc marque
#' @param url l url de redirection - optionnel
#' @param titre le texte de description de l url - optionnel
#' @param nom_site_service le nom du site ou du service - optionnel
#' @param baseline le texte sous le nom de site/service - optionnel
#' @param class un classe a ajouter si necessaire ("fr-m-1w" correspond a une margin de 1w sur tous les cotés) - optionnel, par defaut "fr-container" (centré) (voir le Systeme de design de l'Etat "fondamentaux-techniques/espacements")
#' @return html
#' @export
#'
#' @examples
#'
#' header_dsfr(
#' intitule = "Prefet de",
#' officiel = "Bretagne",
#' )
header_dsfr <- function(
intitule,
officiel,
url = "/",
titre = NULL,
nom_site_service = NULL,
baseline = NULL,
class = "fr-container"
) {

# check les params
assertthat::assert_that(is.character(intitule))
assertthat::assert_that(is.character(officiel))
# TODO verifier que l url est valide

header_dsfr_template(
class = class,
intitule = intitule,
officiel = officiel,
url = url,
titre = titre,
nom_site_service = nom_site_service,
baseline = baseline
) %>%
parse_html()
}
Loading