Skip to content

Commit

Permalink
test/check f7Swiper
Browse files Browse the repository at this point in the history
  • Loading branch information
DivadNojnarg committed Mar 24, 2024
1 parent f07841c commit 62e11e7
Show file tree
Hide file tree
Showing 25 changed files with 226 additions and 298 deletions.
144 changes: 22 additions & 122 deletions R/f7Swiper.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,152 +9,52 @@
#'
#' @rdname swiper
#'
#' @examples
#' if(interactive()){
#' library(shiny)
#' library(shinyMobile)
#'
#' timeline <- f7Timeline(
#' sides = TRUE,
#' f7TimelineItem(
#' "Another text",
#' date = "01 Dec",
#' card = FALSE,
#' time = "12:30",
#' title = "Title",
#' subtitle = "Subtitle",
#' side = "left"
#' ),
#' f7TimelineItem(
#' "Another text",
#' date = "02 Dec",
#' card = TRUE,
#' time = "13:00",
#' title = "Title",
#' subtitle = "Subtitle"
#' ),
#' f7TimelineItem(
#' "Another text",
#' date = "03 Dec",
#' card = FALSE,
#' time = "14:45",
#' title = "Title",
#' subtitle = "Subtitle"
#' )
#' )
#'
#' shiny::shinyApp(
#' ui = f7Page(
#' title = "Swiper",
#' f7SingleLayout(
#' navbar = f7Navbar(title = "f7Swiper"),
#' f7Swiper(
#' id = "my-swiper",
#' f7Slide(
#' timeline
#' ),
#' f7Slide(
#' f7Toggle(
#' inputId = "toggle",
#' label = "My toggle",
#' color = "pink",
#' checked = TRUE
#' ),
#' verbatimTextOutput("test")
#' ),
#' f7Slide(
#' f7Slider(
#' inputId = "obs",
#' label = "Number of observations",
#' max = 1000,
#' min = 0,
#' value = 100,
#' scaleSteps = 5,
#' scaleSubSteps = 3,
#' scale = TRUE,
#' color = "orange",
#' labels = tagList(
#' f7Icon("circle"),
#' f7Icon("circle_fill")
#' )
#' ),
#' plotOutput("distPlot")
#' )
#' )
#' )
#' ),
#' server = function(input, output) {
#' output$test <- renderPrint(input$toggle)
#' output$distPlot <- renderPlot({
#' hist(rnorm(input$obs))
#' })
#' }
#' )
#' }
#'
#' @example inst/examples/swiper/app.R
#' @author David Granjon, \email{dgranjon@@ymail.com}
#'
#' @export
f7Swiper <- function(
...,
id,
options = list(
speed = 400,
loop = FALSE,
spaceBetween = 50,
slidesPerView = "auto",
centeredSlides = TRUE,
navigation = list(
nextEl = ".swiper-button-next",
prevEl = ".swiper-button-prev"
),
pagination = list(el = ".swiper-pagination", clickable = TRUE),
scrollbar = list(el = ".swiper-scrollbar", draggable = TRUE)
)
) {
# swiper class
swiperCl <- "swiper swiper-container"

swiper_config <- shiny::tags$script(
type = "application/json",
`data-for` = id,
jsonlite::toJSON(
x = options,
auto_unbox = TRUE,
json_verbatim = TRUE
)
)

...,
id,
options = list(
speed = 400,
loop = FALSE,
spaceBetween = 50,
slidesPerView = "auto",
centeredSlides = TRUE,
navigation = list(
nextEl = ".swiper-button-next",
prevEl = ".swiper-button-prev"
),
pagination = list(el = ".swiper-pagination", clickable = TRUE),
scrollbar = list(el = ".swiper-scrollbar", draggable = TRUE)
)) {
# swiper tag
shiny::tags$div(
class = swiperCl,
class = "swiper",
id = id,
shiny::tags$div(
class = "swiper-wrapper",
...
),
if (!is.null(options$pagination)) shiny::tags$div(class = "swiper-pagination"),
if (!is.null(options$navigation)) {
list(
shiny::tags$div(class ="swiper-button-prev"),
shiny::tags$div(class ="swiper-button-next")
shiny::tagList(
shiny::tags$div(class = "swiper-button-prev"),
shiny::tags$div(class = "swiper-button-next")
)
},
if (!is.null(options$scrollbar)) shiny::tags$div(class = "swiper-scrollbar"),
swiper_config
buildConfig(id, options)
)
}





#' Framework7 slide
#'
#' \code{f7Slide} is an \link{f7Swiper} element.
#'
#' @param ... Slide content. Any element.
#'
#' @rdname swiper
#' @export
f7Slide <- function(...) {
shiny::tags$div(class = "swiper-slide", ...)
Expand Down
48 changes: 48 additions & 0 deletions inst/examples/swiper/app.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
library(shiny)
library(shinyMobile)

app <- shiny::shinyApp(
ui = f7Page(
title = "Swiper",
f7SingleLayout(
navbar = f7Navbar(title = "f7Swiper"),
f7Swiper(
id = "swiper",
f7Slide(
f7Toggle(
inputId = "toggle",
label = "My toggle",
color = "pink",
checked = TRUE
),
verbatimTextOutput("test")
),
f7Slide(
f7Slider(
inputId = "slider",
label = "Number of observations",
max = 1000,
min = 0,
value = 100,
scaleSteps = 5,
scaleSubSteps = 3,
scale = TRUE,
color = "orange",
labels = tagList(
f7Icon("circle"),
f7Icon("circle_fill")
)
),
textOutput("test2")
)
)
)
),
server = function(input, output) {
output$test <- renderPrint(input$toggle)
output$test2 <- renderText(input$slider)
}
)

app
# if (interactive() || identical(Sys.getenv("TESTTHAT"), "true")) app
11 changes: 6 additions & 5 deletions man/datepicker.Rd

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

14 changes: 0 additions & 14 deletions man/f7Slide.Rd

This file was deleted.

114 changes: 34 additions & 80 deletions man/smartselect.Rd

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

Loading

0 comments on commit 62e11e7

Please sign in to comment.