From da148ad47ba5e1f34f0cc6b94638918934ce3343 Mon Sep 17 00:00:00 2001
From: DivadNojnarg <dgranjon@ymail.com>
Date: Sun, 23 Jun 2024 10:31:13 +0200
Subject: [PATCH] fix tabs, remove maggritr dep, R CMD clean

---
 DESCRIPTION             |  5 ++--
 NAMESPACE               |  2 --
 R/deps.R                | 44 +++++++++++++++----------------
 R/layout.R              | 57 +++++++++++++++++++----------------------
 R/user-feedback.R       |  2 +-
 R/utils-pipe.R          | 11 --------
 R/utils-shiny.R         |  5 ++--
 man/pipe.Rd             | 12 ---------
 man/tabset_panel_386.Rd |  2 ++
 9 files changed, 56 insertions(+), 84 deletions(-)
 delete mode 100644 R/utils-pipe.R
 delete mode 100644 man/pipe.Rd

diff --git a/DESCRIPTION b/DESCRIPTION
index acc5ba8..79f2ff8 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -12,7 +12,6 @@ Description: This template is made for people having nostalgic feelings about fl
     Less distraction for more productivity!
 License: MIT + file LICENSE
 Encoding: UTF-8
-LazyData: true
 Roxygen: list(markdown = TRUE)
 RoxygenNote: 7.3.1
 URL: https://github.com/RinteRface/shiny386
@@ -20,5 +19,5 @@ BugReports: https://github.com/RinteRface/shiny386/issues
 Imports: 
     htmltools (>= 0.5.2),
     shiny,
-    magrittr,
-    httpuv
+    httpuv,
+    bslib
diff --git a/NAMESPACE b/NAMESPACE
index dd76473..cbba489 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -1,6 +1,5 @@
 # Generated by roxygen2: do not edit by hand
 
-export("%>%")
 export(badge_386)
 export(button_386)
 export(card_386)
@@ -47,4 +46,3 @@ export(validate_progress_value)
 export(validate_status)
 import(htmltools)
 import(shiny)
-importFrom(magrittr,"%>%")
diff --git a/R/deps.R b/R/deps.R
index 8c062dc..973a790 100644
--- a/R/deps.R
+++ b/R/deps.R
@@ -1,24 +1,3 @@
-bs4_deps <- htmltools::htmlDependency(
-  name = "Bootstrap",
-  version = "4.4.1",
-  src = c(file = "bootstrap-4.4.1"),
-  package = "shiny386",
-  script = c(
-    "js/bootstrap.bundle.js",
-    "js/custom.js",
-    "js/progress_handler.js",
-    "js/toast_handler.js",
-    "js/radioButtonsBinding.js",
-    "js/tabsetPanelBinding.js",
-    "js/dropdownInputBinding.js"
-  ),
-  stylesheet = c(
-    "css/bootstrap.min.css",
-    "css/custom.css"
-  )
-)
-
-
 #' Create shiny386 dependencies
 #'
 #' Add all necessary dependencies so that shiny386 renders well
@@ -27,5 +6,26 @@ bs4_deps <- htmltools::htmlDependency(
 #' @export
 #' @seealso \link{page_386}.
 use_bs4_deps <- function(tag) {
-  tagList(tag, bs4_deps)
+  tagList(
+    tag,
+    htmltools::htmlDependency(
+      name = "Bootstrap",
+      version = "4.4.1",
+      src = c(file = "bootstrap-4.4.1"),
+      package = "shiny386",
+      script = c(
+        "js/bootstrap.bundle.js",
+        "js/custom.js",
+        "js/progress_handler.js",
+        "js/toast_handler.js",
+        "js/radioButtonsBinding.js",
+        "js/tabsetPanelBinding.js",
+        "js/dropdownInputBinding.js"
+      ),
+      stylesheet = c(
+        "css/bootstrap.min.css",
+        "css/custom.css"
+      )
+    )
+  )
 }
diff --git a/R/layout.R b/R/layout.R
index 9f61fc1..a71beef 100644
--- a/R/layout.R
+++ b/R/layout.R
@@ -21,12 +21,14 @@ page_386 <- function(..., title = NULL) {
       tags$meta(`http-equiv` = "X-UA-Compatible", content = "IE=edge")
     ),
     # body
-    tags$body(
-      div(
-        class = "container",
-        ...
+    use_bs4_deps(
+      tags$body(
+        div(
+          class = "container",
+          ...
+        )
       )
-    ) %>% use_bs4_deps()
+    )
   )
 }
 
@@ -34,6 +36,7 @@ page_386 <- function(..., title = NULL) {
 
 #' Create a Bootstrap 386 tabset panel
 #' @inheritParams shiny::tabsetPanel
+#' @param position Tabs position.
 #' @export
 #' @examples
 #' if (interactive()) {
@@ -70,30 +73,22 @@ tabset_panel_386 <- function(..., id = NULL, selected = NULL,
   )
 
   # Some edit below since Bootstrap 4 significantly changed the layout
-  nav_items <- temp_tabset$children[[1]]$children[[1]]
-  found_active <- FALSE
-  bs4_nav_items <- lapply(nav_items, function(x) {
-    if (!is.null(x$attribs$class)) {
-      if (grep(x = x$attribs$class, pattern = "active")) {
-        x$attribs$class <- NULL
-        found_active <- TRUE
+  htmltools::tagQuery(temp_tabset)$
+    find("li")$
+    each(
+      function(x, i) {
+        # replace text
+        current_tab <- x$children[[1]]$attribs$`data-value`
+        x$attribs$class <- "nav-item"
+        x$children[[1]]$attribs$class <- if (selected == current_tab) {
+          "nav-link active"
+        } else {
+          "nav-link"
+        }
+        x
       }
-    }
-    x$attribs$class <- if (is.null(x$attribs$class)) {
-      "nav-item"
-    } else {
-      paste("nav-item",  x$attribs$class)
-    }
-    x$children[[1]]$attribs$class <- if (found_active) {
-      "nav-link active"
-    } else {
-      "nav-link"
-    }
-    x
-  })
-
-  temp_tabset$children[[1]]$children[[1]] <- bs4_nav_items
-  temp_tabset
+    )$
+    allTags()
 }
 
 
@@ -205,9 +200,9 @@ update_tabset_panel_386 <- shiny::updateTabsetPanel
 #'  shinyApp(ui, server)
 #' }
 navbar_page_386 <- function (title, ..., id = NULL, selected = NULL,
-                        position = c("static-top", "fixed-top", "fixed-bottom"),
-                        header = NULL, footer = NULL, inverse = FALSE,
-                        windowTitle = title) {
+                             position = c("static-top", "fixed-top", "fixed-bottom"),
+                             header = NULL, footer = NULL, inverse = FALSE,
+                             windowTitle = title) {
   pageTitle <- title
   navbarClass <- "navbar navbar-expand-lg navbar-dark bg-primary"
   position <- match.arg(position)
diff --git a/R/user-feedback.R b/R/user-feedback.R
index 012cd02..bdd10ac 100644
--- a/R/user-feedback.R
+++ b/R/user-feedback.R
@@ -37,7 +37,7 @@ toast_386 <- function(id, title = NULL, subtitle = NULL, ..., img = NULL) {
     `data-toggle` = "toast"
   )
 
-  toast_wrapper %>% tagAppendChildren(toast_header, toast_body)
+  tagAppendChildren(toast_wrapper, toast_header, toast_body)
 }
 
 
diff --git a/R/utils-pipe.R b/R/utils-pipe.R
deleted file mode 100644
index e79f3d8..0000000
--- a/R/utils-pipe.R
+++ /dev/null
@@ -1,11 +0,0 @@
-#' Pipe operator
-#'
-#' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details.
-#'
-#' @name %>%
-#' @rdname pipe
-#' @keywords internal
-#' @export
-#' @importFrom magrittr %>%
-#' @usage lhs \%>\% rhs
-NULL
diff --git a/R/utils-shiny.R b/R/utils-shiny.R
index 0ff6f9d..c39133d 100644
--- a/R/utils-shiny.R
+++ b/R/utils-shiny.R
@@ -27,7 +27,7 @@ create_checkbox_tag <- function(inputId, label, value = FALSE, width = NULL,
   )
 
   if (!is.null(value) && value) {
-    input_tag <- input_tag %>% tagAppendAttributes(checked = "checked")
+    input_tag <- tagAppendAttributes(input_tag, checked = "checked")
   }
 
   input_wrapper <- tags$div(
@@ -37,7 +37,8 @@ create_checkbox_tag <- function(inputId, label, value = FALSE, width = NULL,
     }
   )
 
-  input_wrapper %>% tagAppendChildren(
+  tagAppendChildren(
+    input_wrapper,
     input_tag,
     tags$label(class = "custom-control-label", `for` = inputId, label)
   )
diff --git a/man/pipe.Rd b/man/pipe.Rd
deleted file mode 100644
index 0eec752..0000000
--- a/man/pipe.Rd
+++ /dev/null
@@ -1,12 +0,0 @@
-% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/utils-pipe.R
-\name{\%>\%}
-\alias{\%>\%}
-\title{Pipe operator}
-\usage{
-lhs \%>\% rhs
-}
-\description{
-See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details.
-}
-\keyword{internal}
diff --git a/man/tabset_panel_386.Rd b/man/tabset_panel_386.Rd
index 3ed05e7..be46ef7 100644
--- a/man/tabset_panel_386.Rd
+++ b/man/tabset_panel_386.Rd
@@ -31,6 +31,8 @@ tab will be selected.}
 conjunction with \code{\link[shiny:tabPanelBody]{tabPanelBody()}} and \code{\link[shiny:updateTabsetPanel]{updateTabsetPanel()}} to control the
 active tab via other input controls. (See example below)}
 }}
+
+\item{position}{Tabs position.}
 }
 \description{
 Create a Bootstrap 386 tabset panel