From 52497db76310577332bf3ec928904c8e6ae95cd5 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Wed, 22 May 2024 16:33:32 +0200 Subject: [PATCH] simplify for use in custom modules --- NEWS.md | 1 + R/f7Login.R | 14 +++++++++----- man/authentication.Rd | 14 +++++++++++++- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/NEWS.md b/NEWS.md index ae9ba930..e635cf69 100644 --- a/NEWS.md +++ b/NEWS.md @@ -94,6 +94,7 @@ the new router layout. Items must be wrapped in a `shiny::tagList()`. - `updateF7App` can now also handle changes in app theme (ios or md), dark mode, and color. - `f7Fabs()` has a new argument `global` that can be used to make FABs persistent across different tabs in `f7TabLayout()`. - `f7ExpandableCard()` has a new argument `buttonColor` that can be used to control the color of the close button. +- `f7Login()` has a new argument `module` that can, optionally, be set to `FALSE` for more flexibility. For example, this allows you to use `f7Login()` inside your own modules, or without the provided `f7LoginServer()` module. - Fix various issues in documentation. - Include new vignettes. diff --git a/R/f7Login.R b/R/f7Login.R index 2addf006..fa5cb211 100644 --- a/R/f7Login.R +++ b/R/f7Login.R @@ -20,21 +20,25 @@ #' @param startOpen Whether to open the login page at start. Default to TRUE. There #' are some cases where it is interesting to set up to FALSE, for instance when you want #' to have authentication only in a specific tab of your app (See example 2). +#' @param module Whether or not to use in combination with \link{f7LoginServer}. Can be +#' set to FALSE if you want to develop your own server functionality, or if you want to +#' use \code{f7Login} inside a module yourself. Defaults to TRUE. #' #' @export #' @rdname authentication #' @importFrom jsonlite toJSON #' @example inst/examples/login/app.R f7Login <- function(..., id, title, label = "Sign In", footer = NULL, - startOpen = TRUE) { + startOpen = TRUE, module = TRUE) { + ns <- shiny::NS(id) - submitBttn <- f7Button(inputId = ns("submit"), label = label) + submitBttn <- f7Button(inputId = ifelse(module, ns("submit"), "submit"), label = label) submitBttn[[2]]$attribs$class <- "item-link list-button f7-action-button" submitBttn[[2]]$name <- "a" shiny::tags$div( - id = ns(id), + id = ifelse(module, ns(id), id), `data-start-open` = jsonlite::toJSON(startOpen), class = "login-screen", shiny::tags$div( @@ -49,12 +53,12 @@ f7Login <- function(..., id, title, label = "Sign In", footer = NULL, shiny::tags$form( f7List( f7Text( - inputId = ns("user"), + inputId = ifelse(module, ns("user"), "user"), label = "Username", placeholder = "Your name here" ), f7Password( - inputId = ns("password"), + inputId = ifelse(module, ns("password"), "password"), label = "Password", placeholder = "Your password here" ), diff --git a/man/authentication.Rd b/man/authentication.Rd index dfc71a31..d14a326a 100644 --- a/man/authentication.Rd +++ b/man/authentication.Rd @@ -6,7 +6,15 @@ \alias{updateF7Login} \title{Framework7 login screen} \usage{ -f7Login(..., id, title, label = "Sign In", footer = NULL, startOpen = TRUE) +f7Login( + ..., + id, + title, + label = "Sign In", + footer = NULL, + startOpen = TRUE, + module = TRUE +) f7LoginServer(id, ignoreInit = FALSE, trigger = NULL) @@ -33,6 +41,10 @@ either opened or closed).} are some cases where it is interesting to set up to FALSE, for instance when you want to have authentication only in a specific tab of your app (See example 2).} +\item{module}{Whether or not to use in combination with \link{f7LoginServer}. Can be +set to FALSE if you want to develop your own server functionality, or if you want to +use \code{f7Login} inside a module yourself. Defaults to TRUE.} + \item{ignoreInit}{If TRUE, then, when this observeEvent is first created/initialized, ignore the handlerExpr (the second argument), whether it is otherwise supposed to run or not. The default is FALSE.}