diff --git a/.Rbuildignore b/.Rbuildignore index 719ce81..45d59c2 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,30 +1,17 @@ -dev -rheroicons.code-workspace -package.json -README.md -.gitignore -node_modules -inst/rheroicons-gallery -inst/gallery-assets/src -.cache -.postcssrc -.babelrc -^\.travis\.yml$ -^\.github$ -yarn.lock -yarn-error.log -^\.pkgbump\.json$ ^node_modules$ ^inst/rheroicons-gallery/rsconnect$ ^yarn-error\.log$ +^\.github$ ^config$ ^dev$ ^inst/rheroicons-gallery$ ^\.babelrc$ ^\.gitignore$ +^cran-comments\.md$ ^package\.json$ +^pkgbump\.config\.json$ ^postcss\.config\.js$ ^rheroicons\.code-workspace$ ^webpack\.config\.js$ ^yarn\.lock$ -^pkgbump\.config\.json$ +^LICENSE\.md$ diff --git a/DESCRIPTION b/DESCRIPTION index 34912a5..ec3aa74 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,13 +1,28 @@ Package: rheroicons -Title: The Heroicons library for use in R-based web projects -Version: 0.2.4 -Authors@R: - person(given = "David", - family = "Ruvolo", - role = c("aut", "cre"), - email = "dcruvolo@gmail.com", - comment = c(ORCID = "0000-0002-5745-5298")) -Description: The rheroicons provides access to the fantastic SVG icon collection heroicons, developed by @adamwathan and @sschoger, as R functions for use in your R-based web projects (i.e., shiny, Rmarkdown, etc.). This package requires no HTML, CSS, or JavaScript dependencies as all icons are rendered inline as SVG elements. +Title: A Zero Dependency SVG Icon Library for Use in R Web-Based Projects +Version: 0.3.0 +Authors@R: c( + person( + given = "David", + family = "Ruvolo", + role = c("aut", "cre"), + email = "dcruvolo@gmail.com", + comment = c(ORCID = "0000-0002-5745-5298")), + person( + given = "Adam", + family = "Wathan", + role = c("ctb", "cph"), + comment = "Author of heroicons library"), + person( + given = "Steve", + family = "Schoger", + role = c("ctb", "cph"), + comment = "Author of heroicons library") + ) +Description: The rheroicons package brings the Heroicons icon library + to Shiny and other web-based projects. All icons are rendered as + inline SVG elements. Therefore, no CSS or JavaScript dependencies + are required! License: MIT + file LICENSE Encoding: UTF-8 LazyData: true @@ -16,9 +31,10 @@ RoxygenNote: 7.1.1 Imports: htmltools (>= 0.5.0), shiny (>= 1.5.0), - cli, stringr -Suggests: +Suggests: + spelling, testthat Depends: R (>= 2.10) +Language: en-US diff --git a/LICENSE b/LICENSE index fffdf12..ae3e4ea 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,2 @@ -MIT License - -Copyright (c) 2020 dcruvolo - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +YEAR: 2021 +COPYRIGHT HOLDER: David Ruvolo diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..e0fe5dd --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,53 @@ +# MIT License + +The rheroicons package as a whole is distributed under MIT License. + +Copyright (c) 2021 rheroicons authors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +The rheroicons package includes other open source software components. The following +is a list of these components (full copies of the license agreements used by +these components are included below): + +- heroicons, [https://github.com/tailwindlabs/heroicons](https://github.com/tailwindlabs/heroicons) + +## Heriocons License + +MIT License + +Copyright (c) 2020 Refactoring UI Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/NEWS.md b/NEWS.md index 891c8b4..2814d13 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,8 +1,27 @@ +# rheroicons 0.3.0 + +* Prepared package for CRAN submission +* Removed `cli` package as a dependency +* Added tests for `find_icon` +* Revised documentation + +# rheroicons 0.2.4 + +* Upgraded to latest version of Heroicons ([v0.4.2](https://github.com/tailwindlabs/heroicons/releases/tag/v0.4.2)) + +# rheroicons 0.2.3 + +This is a minor package update. The main issue was the handling of error messages via the `cli` package. These changes are listed below. + +* Updated error message for `rheroicon` function. It now uses {.val {value}} +* Removed error message for find_icons as the default query is "". +* Reset `pkgbump` configuration file + # rheroicons 0.2.21 -* Switched to webpack as the bundler of choice :tada: -* Tested assets in dev and prod environments using the `dev-app` -* Rebuilt assets +* The development side of this package now uses Webpack! +* Tested assets in `dev` and `prod` environments using the `dev-app` +* Rebuilt assets * Updated R package configuration and ignore files # rheroicons 0.2.2 @@ -16,13 +35,13 @@ # rheroicons 0.2.0 -* New package structure :rocket: icons are now generated using the function `rheroicon`. Select an icon using the argument `name`. Icons can be found in the gallery via `launch_gallery()` function. Use the argument `type` to return define the icon style as `outline` or `solid`. Icons can be further customized by passing additional css classes using the `classnames` argument. -* Restructured rheroicons gallery as icons are available using an internal dataset. The gallery's ui, server, and modules are now located in `R/launch_gallery.R`. Static assets are still located in `inst/rheroicons-demo`. +* New package structure! Icons are now generated using the function `rheroicon`. Select an icon using the argument `name`. Icons can be found in the gallery via `launch_gallery()` function. Use the argument `type` to return define the icon style as `outline` or `solid`. Icons can be further customized by passing additional CSS classes using the `classnames` argument. +* Restructured rheroicons gallery as icons are available using an internal dataset. The gallery's client, server, and modules are now located in `R/launch_gallery.R`. Static assets are still located in `inst/rheroicons-demo`. * Rewrote unit tests ## rheroicons 0.1.6 -* Updated to heroicons `v0.4.0` +* Updated to Heroicons `v0.4.0` * Redesigned icon gallery ## rheroicons 0.1.5 @@ -36,4 +55,4 @@ ## rheroicons 0.1.4 * Added a `NEWS.md` file to track changes to the package. -* Added Package management dir `dev`. Convert Icons using `dev/dev.R` \ No newline at end of file +* Added Package management directory `dev`. Convert Icons using `dev/dev.R` \ No newline at end of file diff --git a/R/find_icon.R b/R/find_icon.R index 99a6142..10ce929 100644 --- a/R/find_icon.R +++ b/R/find_icon.R @@ -1,16 +1,19 @@ -#' Find Icons +#' Find available icons #' -#' Find an icon using a search term -#' -#' @param query a search term passed down to \code{stringr::str_subset} +#' @param query a search term passed down to \code{stringr::str_subset}. +#' Alternatively, leave blank to view all icon names. #' #' @examples #' find_icons(query = "chevron") #' find_icons(query = "chevron|arrow") #' find_icons(query = "down|up|left|right") #' -#' @return Find an icon using a search term +#' @return An array of icon names #' +#' @references +#' \url{https://heroicons.com} +#' \url{https://github.com/tailwindlabs/heroicons} +#' #' @export find_icons <- function(query = "") { stringr::str_subset(string = names(rheroicons), pattern = query) diff --git a/R/launch_gallery.R b/R/launch_gallery.R index c6edf7d..a99793d 100644 --- a/R/launch_gallery.R +++ b/R/launch_gallery.R @@ -3,7 +3,7 @@ #' Run the rheroicons gallery and search for icons. Click on an icon #' name to copy the function to the clipboard. #' -#' @param ... additional options passed down to runApp +#' @param ... additional options passed down to \code{shiny::runApp} #' #' @examples #' \dontrun{ @@ -28,7 +28,7 @@ launch_gallery <- function(...) { ns <- shiny::NS(id) shiny::tags$li( id = ns("icon"), - class = "icon-item", + class = paste0("icon-item set-", set), shiny::tags$button( id = ns("icon-copy"), class = "icon-name icon-button", @@ -58,7 +58,10 @@ launch_gallery <- function(...) { ns <- shiny::NS(id) # define elements - parent <- shiny::tags$ul(id = ns("icon-set"), class = "icon-list") + parent <- shiny::tags$ul( + id = ns("icon-set"), + class = paste0("icon-list set-", set) + ) children <- list() # outline icons diff --git a/R/rheroicon.R b/R/rheroicon.R index 06ba9b0..075ced9 100644 --- a/R/rheroicon.R +++ b/R/rheroicon.R @@ -1,25 +1,32 @@ -#' rheroicon +#' An inline SVG icon from Heroicons #' -#' Render an rheroicon icon by name. Use `launch_gallery` to view the icons -#' available in this package or visit the gallery on shinyapps.io (see link -#' below). All icons are rendered with three CSS classes: global ("rheroicons"), -#' icon style ("rheroicons_outline" or "rheroicons_solid"), and icon name ( -#' "rheroicons_academic_cap"). Use any of these classes to customize the style -#' of the icon or define your own classes using the argument `class`. +#' Render an icon by name. Use `launch_gallery` to view the icons +#' available in this package or visit the Heroicons icon gallery +#' (see referenced urls). #' #' @param name an icon name -#' @param type choose icon style "solid" or "outline" (default: "outline") -#' @param classnames a string containing one or more CSS classes +#' @param type render a "solid" or "outline" icon (default: "outline") +#' @param classnames a string containing one or more CSS classes (optional) +#' +#' @section Styling Icons with CSS class names: +#' +#' Icons are rendered from SVG strings. All icons have three CSS classes +#' defined: global ("rheroicons"), icon style ("rheroicons_outline" or +#' "rheroicons_solid"), and icon name ("rheroicons_academic_cap"). +#' Use any of combination of these classes to style icons via CSS. +#' Alternatively, you can pass your own classes using the \code{classnames} +#' argument. #' #' @examples #' rheroicon(name = "academic_cap") #' rheroicon(name = "academic_cap", type = "solid") #' rheroicon(name = "academic_cap", classnames = "education-icons") #' +#' @return Returns an SVG string #' #' @references +#' \url{https://heroicons.com} #' \url{https://github.com/tailwindlabs/heroicons} -#' \url{https://davidruvolo.shinyapps.io/rheroicons-demo/} #' #' @export rheroicon <- function(name, type = "outline", classnames = NULL) { @@ -28,16 +35,17 @@ rheroicon <- function(name, type = "outline", classnames = NULL) { # warn if icon does not exist if (is.null(icon)) { - cli::cli_alert_danger("Icon {.val {name}} cannot be found.") + warning("Icon does not exist") } # throw error if input value for "type" is invalid - if (!type %in% c("outline", "solid")) { - cli::cli_alert_danger("Icon type {.val {type}} is invalid. Use {.val outline} or {.val solid}") + valid_types <- c("outline", "solid") + if (!type %in% valid_types) { + warning("Icon type is invalid. Use 'outline' or 'solid'") } # process only if icon exists - if (length(icon) && type %in% c("outline", "solid")) { + if (length(icon) && (type %in% valid_types)) { svg <- icon$icons[[type]] # append class attribute if applicable diff --git a/R/utils.R b/R/utils.R index f2948c2..fa24184 100644 --- a/R/utils.R +++ b/R/utils.R @@ -5,6 +5,7 @@ #' customizing the appearance of icons. #' #' @param svg a string containing the SVG markup of an icon +#' @param class a string containing one or more CSS classes #' #' @noRd .set__classnames <- function(svg, class) { diff --git a/README.md b/README.md index 9968670..e58138f 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,9 @@ # rheroicons -The `rheroicons` provides access to the fantastic SVG icon collection [heroicons](https://github.com/refactoringui/heroicons), developed by [adamwathan](https://github.com/adamwathan) and [sschoger](https://github.com/sschoger), as R functions for use in your R-based web projects (i.e., shiny, Rmarkdown, etc.). This package requires no HTML, CSS, or JavaScript dependencies as all SVG icons are rendered inline. +The `rheroicons` packages brings to the [Heroicons](https://github.com/tailwindlabs/heroicons) icon library, developed by [Adam Wathan](https://github.com/adamwathan) and [Steve Schoger](https://github.com/sschoger), as R functions for use in your R-based web projects. + +All icons are rendered as inline SVG icons. Therefore, no CSS or JavaScript dependencies are loaded into your Shiny application or other web document at runtime! ## Install @@ -15,31 +17,56 @@ Use `devtools` or `remotes` to install the `rheroicons`. devtools::install_github("davidruvolo51/rheroicons") ``` +## Getting Started -## Use +### Finding Icons -There are well over a 200 icons in the collection and each icon has two styles (outline and solid). Icons can be found via the icon gallery. Click an icon name to copy the R code used to generate that icon. +There are over 200 icons in the collection. Each icon has two styles: outline and solid. Icons can be found using the icon gallery. ```r rheroicons::launch_gallery() ``` -Icons are created using the `rheroicon` function. +Click an icon name to copy the R code used to generate the icon. You can paste the R code directly into your Shiny app or other web-based document. + +Alternatively, you can use the `find_icon` function to search for icons. + +```r +# returns all icon names +rheroicons::find_icon() + +# find icons with `chevron` in the name +rheroicons::find_icons(query = "chevron") + +# find icons with `chevron` OR `arrow` in the name +rheroicons::find_icons(query = "chevron|arrow") + +# find icons with `down`, `up`, `left`, OR `right` in the name +rheroicons::find_icons(query = "down|up|left|right") +``` + +### Rendering Icons + +When you have found the icon that you would like to use, you can render them into your app or web document using the `rheroicon` function. ```r # rheroicons version of `document-add` rheroicons::rheroicon(name = "document_add") ``` -\***NOTE**: You can use the [heroicons](https://heroicons.com) site to find icons. All icons that have a dash (`-`) in the original name were renamed using underscores (`_`). +You can use the [Heroicons](https://heroicons.com) site to find icons. All icons that have a dash (`-`) in the original name were renamed using underscores (`_`). -### Arguments +#### Arguments All functions take the following arguments. -- `name`: an icon name -- `type`: select the icon style (either `outline` or `solid`; default `outline`) -- `classnames`: a CSS class to be applied to the SVG icon +| Argument | Description | Options | Default | +|--------------|------------------------|-------------------------------------|-----------| +| `name` | icon name | use `find_icon` or `launch_gallery` | --- | +| `type` | icon style | `outline` or `solid` | `outline` | +| `classnames` | add custom CSS classes | --- | `NULL` | + +Example use: ```r library(shiny) @@ -47,27 +74,27 @@ tags$button( id = "copy", class = "btn", tags$span("Add to clipboard"), - rheroicons::rheroicon( - name = "clipboard_copy", - type = "solid", - classnames = "btn__icons" - ) + rheroicons::rheroicon(name = "clipboard_copy") ) ``` -\***NOTE**: the default icon type is `outline` - - ### Customizing the appearance of icons -Use the argument `class` to define a custom css classes that can be used to select icons via CSS or JavaScript. +Use the argument `classnames` to add custom CSS classes to your icons. ```r -# clipboard_copy icon -rheroicons::rheroicon( - name = "clipboard_copy", - type = "outline", - class = "my__ui__icons" +library(shiny) + +# create a button with the `clipboard_copy` icon +tags$button( + id = "copy", + class = "btn", + tags$span("Add to clipboard"), + rheroicons::rheroicon( + name = "clipboard_copy", + type = "outline", + class = "my__ui__icons" + ) ) ``` @@ -75,16 +102,16 @@ However, you may find it easier to use the predefined classes generated by this - global: `rheroicons` - set: `rheroicons_solid` or `rheroicons_outline` -- icon: `rhericons_*`, where `*` is the name of the icon. In `rheroicons`, this is same as the function name. +- icon: `rhericons_*`, where `*` is the name of the icon. (This is same as the icon name.) -The following table displays the CSS clases by set for the `arrow_circle_down` icon. +The following table displays the CSS classes by set for the `arrow_circle_down` icon. -set | rheroicons function | rheroicons css classes -:------ | :------------------ | :--------- -outline | `rheroicon(name ="arrow_circle_down", type = "outline")` | `rheroicons rheroicons_outline rheroicons_arrow_circle_down` -solid | `rheroicon(name ="arrow_circle_down", type = "solid")` | `rheroicons rheroicons_solid rheroicons_arrow_circle_down` +| Icon Set | Function | CSS classes | +|----------|----------------------------------------------------------|--------------------------------------------------------------| +| outline | `rheroicon(name ="arrow_circle_down", type = "outline")` | `rheroicons rheroicons_outline rheroicons_arrow_circle_down` | +| solid | `rheroicon(name ="arrow_circle_down", type = "solid")` | `rheroicons rheroicons_solid rheroicons_arrow_circle_down` | -In the Shiny UI, you can select items and style icons through CSS. Create a new `tags$style` element and define your styles (or use an external CSS file). +You can select and style icons through CSS using these classes. Create a new `tags$style` element and define your styles (or use an external CSS file). ```r library(shiny) @@ -129,12 +156,11 @@ ui <- tagList( ### Example -The following code demonstrates how to generate icons in Shiny, render solid and outlined icons, and style icons using CSS. +The following code demonstrates how to generate icons in Shiny, render solid and outlined icons, and style icons using CSS. ```r # pkgs library(shiny) -library(rheroicons) # ui ui <- tagList( @@ -156,18 +182,18 @@ ui <- tagList( tags$main( tags$h2("rheroicons"), tags$div( - rheroicon(name = "arrow_circle_down"), - rheroicon(name = "arrow_circle_up"), - rheroicon(name = "arrow_circle_left"), - rheroicon(name = "arrow_circle_right") + rheroicons::rheroicon(name = "arrow_circle_down"), + rheroicons::rheroicon(name = "arrow_circle_up"), + rheroicons::rheroicon(name = "arrow_circle_left"), + rheroicons::rheroicon(name = "arrow_circle_right") ), tags$div( - rheroicon(name = "chart_bar", type = "solid"), - rheroicon(name = "chart_bar") + rheroicons::rheroicon(name = "chart_bar", type = "solid"), + rheroicons::rheroicon(name = "chart_bar") ), tags$div( - rheroicon(name = "home", type = "solid"), - rheroicon(name = "home") + rheroicons::rheroicon(name = "home", type = "solid"), + rheroicons::rheroicon(name = "home") ) ) ) @@ -178,5 +204,3 @@ server <- function(input, output) { } # app shinyApp(ui, server) ``` - - diff --git a/cran-comments.md b/cran-comments.md new file mode 100644 index 0000000..c200561 --- /dev/null +++ b/cran-comments.md @@ -0,0 +1,20 @@ +# CRAN Comments + +## Test environments + +* local OS X install, R 4.0.3 +* windows-latest release (on GitHub Actions), R 4.0.3 +* macOS-latest release (on GitHub Actions), R 4.0.3 +* ubuntu-20.04 release (on GitHub Actions), R 4.0.3 +* ubuntu-20.04 devel (on GitHub Actions), R 4.0.3 +* win-builder (devel and release) + +## R CMD check results + +0 errors | 0 warnings | 1 note + +There was one note: + +* Possibly mis-spelled words in DESCRIPTION: Heroicons (24:16) rheroicons (23:18) + +Heroicons is the name of the original library and rheroicons is the name of the current library. \ No newline at end of file diff --git a/dev/dev.R b/dev/dev.R index f39afa9..6f1e977 100644 --- a/dev/dev.R +++ b/dev/dev.R @@ -2,51 +2,75 @@ #' FILE: dev.R #' AUTHOR: David Ruvolo #' CREATED: 2020-08-07 -#' MODIFIED: 2020-10-10 +#' MODIFIED: 2021-01-30 #' PURPOSE: package management #' STATUS: ongoing #' PACKAGES: usethis; pkgbump #' COMMENTS: NA #'//////////////////////////////////////////////////////////////////////////// -# init primary files -usethis::use_namespace() -usethis::use_description() -usethis::use_travis() -usethis::use_github_action_check_standard() -usethis::use_news_md() -usethis::use_testthat() +#' install dev packages +#' install.packages("devtools") +#' install.packages("usethis") +#' remotes::install_github("r-lib/revdepcheck") -# pkgs -usethis::use_package(package = "htmltools", min_version = TRUE) -usethis::use_package(package = "shiny") -usethis::use_package(package = "stringr") -usethis::use_package(package = "cli") +#' init primary files +#' usethis::use_namespace() +#' usethis::use_description() +#' usethis::use_travis() +#' usethis::use_github_action_check_standard() +#' usethis::use_news_md() +#' usethis::use_testthat() +#' usethis::use_mit_license("David Ruvolo") + +#'////////////////////////////////////// + +#' ~ 1 ~ +#' SVG Processing -# convert icons +#' load conversion tools source("dev/convert.R") -# use dataset +#' update internal data object usethis::use_data(rheroicons, internal = TRUE, overwrite = TRUE) -# checks +#'////////////////////////////////////// + +#' ~ 2 ~ +#' Package Management + +#' ~ 2a ~ +#' pkgs +usethis::use_package(package = "htmltools", min_version = TRUE) +usethis::use_package(package = "shiny") +usethis::use_package(package = "stringr") + +#' ~ 2b ~ +#' pkg checks devtools::check_man() devtools::load_all() devtools::test() devtools::check() -# init pkgbump -pkgbump::set_pkgbump( - files = c( - "package.json", - "DESCRIPTION" - ) -) - -pkgbump::pkgbump(version = "0.2.4") +#' ~ 2c ~ +#' cran checks +covr::package_coverage() +covr::report() +devtools::check() +devtools::spell_check() +devtools::run_examples() +devtools::test() +devtools::check_win_release() +devtools::check_win_devel() +#' ~ 2c ~ +#' pkgbump configuration +#' remotes::install_github("davidruvolo51/pkgbump") +pkgbump::set_pkgbump(files = c("package.json", "DESCRIPTION")) +pkgbump::pkgbump(version = "0.3.0") -# ignore +#' ~ 2d ~ +# ignore files ignore <- c( "node_modules", "inst/rheroicons-gallery/rsconnect", @@ -63,7 +87,8 @@ usethis::use_build_ignore( "inst/rheroicons-gallery", ".babelrc", ".gitignore", - ".travis.yml", + "cran-comments.md", + "LICENSE.md", "package.json", "pkgbump.config.json", "postcss.config.js", diff --git a/man/find_icons.Rd b/man/find_icons.Rd index 79118c0..4e777b0 100644 --- a/man/find_icons.Rd +++ b/man/find_icons.Rd @@ -2,18 +2,19 @@ % Please edit documentation in R/find_icon.R \name{find_icons} \alias{find_icons} -\title{Find Icons} +\title{Find available icons} \usage{ find_icons(query = "") } \arguments{ -\item{query}{a search term passed down to \code{stringr::str_subset}} +\item{query}{a search term passed down to \code{stringr::str_subset}. +Alternatively, leave blank to view all icon names.} } \value{ -Find an icon using a search term +An array of icon names } \description{ -Find an icon using a search term +Find available icons } \examples{ find_icons(query = "chevron") @@ -21,3 +22,7 @@ find_icons(query = "chevron|arrow") find_icons(query = "down|up|left|right") } +\references{ +\url{https://heroicons.com} +\url{https://github.com/tailwindlabs/heroicons} +} diff --git a/man/launch_gallery.Rd b/man/launch_gallery.Rd index 882fed0..92d77d7 100644 --- a/man/launch_gallery.Rd +++ b/man/launch_gallery.Rd @@ -7,7 +7,7 @@ launch_gallery(...) } \arguments{ -\item{...}{additional options passed down to runApp} +\item{...}{additional options passed down to \code{shiny::runApp}} } \description{ Run the rheroicons gallery and search for icons. Click on an icon diff --git a/man/rheroicon.Rd b/man/rheroicon.Rd index 3c77e96..31926b7 100644 --- a/man/rheroicon.Rd +++ b/man/rheroicon.Rd @@ -2,33 +2,43 @@ % Please edit documentation in R/rheroicon.R \name{rheroicon} \alias{rheroicon} -\title{rheroicon} +\title{An inline SVG icon from Heroicons} \usage{ rheroicon(name, type = "outline", classnames = NULL) } \arguments{ \item{name}{an icon name} -\item{type}{choose icon style "solid" or "outline" (default: "outline")} +\item{type}{render a "solid" or "outline" icon (default: "outline")} -\item{classnames}{a string containing one or more CSS classes} +\item{classnames}{a string containing one or more CSS classes (optional)} +} +\value{ +Returns an SVG string } \description{ -Render an rheroicon icon by name. Use \code{launch_gallery} to view the icons -available in this package or visit the gallery on shinyapps.io (see link -below). All icons are rendered with three CSS classes: global ("rheroicons"), -icon style ("rheroicons_outline" or "rheroicons_solid"), and icon name ( -"rheroicons_academic_cap"). Use any of these classes to customize the style -of the icon or define your own classes using the argument \code{class}. +Render an icon by name. Use \code{launch_gallery} to view the icons +available in this package or visit the Heroicons icon gallery +(see referenced urls). +} +\section{Styling Icons with CSS class names}{ + + +Icons are rendered from SVG strings. All icons have three CSS classes +defined: global ("rheroicons"), icon style ("rheroicons_outline" or +"rheroicons_solid"), and icon name ("rheroicons_academic_cap"). +Use any of combination of these classes to style icons via CSS. +Alternatively, you can pass your own classes using the \code{classnames} +argument. } + \examples{ rheroicon(name = "academic_cap") rheroicon(name = "academic_cap", type = "solid") rheroicon(name = "academic_cap", classnames = "education-icons") - } \references{ +\url{https://heroicons.com} \url{https://github.com/tailwindlabs/heroicons} -\url{https://davidruvolo.shinyapps.io/rheroicons-demo/} } diff --git a/package.json b/package.json index 0efbb9c..1fa43b6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rheroicons", - "version": "0.2.4", + "version": "0.3.0", "author": "dcruvolo", "description": "Heroicons for R", "license": "MIT", diff --git a/tests/testthat/test-find-icon.R b/tests/testthat/test-find-icon.R new file mode 100644 index 0000000..6bd0df7 --- /dev/null +++ b/tests/testthat/test-find-icon.R @@ -0,0 +1,35 @@ +#' //////////////////////////////////////////////////////////////////////////// +#' FILE: test-find-icon.R +#' AUTHOR: David Ruvolo +#' CREATED: 2021-01-27 +#' MODIFIED: 2021-01-27 +#' PURPOSE: `find_icon` tests +#' STATUS: working +#' PACKAGES: testthat +#' COMMENTS: NA +#' //////////////////////////////////////////////////////////////////////////// + + +#' ~ 1 ~ +#' Function returns entire list of icons if no query is provided +test_that("entire icon list prints correctly", { + expect_equal( + object = length(find_icons()), + expected = length(rheroicons), + label = "Returned array does not match the length of the icon set" + ) +}) + +#' ~ 2 ~ +#' Query returns expected icons +test_that("query returns expected icons", { + expect_equal( + object = find_icons(query = "chevron_double"), + expected = c( + "chevron_double_down", + "chevron_double_left", + "chevron_double_right", + "chevron_double_up" + ) + ) +}) \ No newline at end of file diff --git a/tests/testthat/test-launch-gallery.R b/tests/testthat/test-launch-gallery.R new file mode 100644 index 0000000..b0ae15e --- /dev/null +++ b/tests/testthat/test-launch-gallery.R @@ -0,0 +1,109 @@ +#'//////////////////////////////////////////////////////////////////////////// +#' FILE: test-launch-gallery.R +#' AUTHOR: David Ruvolo +#' CREATED: 2021-01-30 +#' MODIFIED: 2021-01-30 +#' PURPOSE: unit tests for launch gallery +#' STATUS: in.progress +#' PACKAGES: usethis; rheroicons; shiny +#' COMMENTS: NA +#'//////////////////////////////////////////////////////////////////////////// + +#' .gallery__list__element() +#' Make sure icons are returned as li element +test_that("Markup of gallery element is expected", { + + # choose a random outline icon + res <- .gallery__list__element( + id = "test", + set = "outline", + icon = rheroicons[["zoom_out"]][["icons"]][["solid"]] + ) + + expect_equal( + object = c( + res$name, + res$attribs$class, + res$children[[1]]$name, + names(attributes(res$children[[1]]$children[[1]]))[1], + res$children[[1]]$children[[2]]$name + ), + expected = c( + "li", + "icon-item set-outline", + "button", + "html", # grab attribute instead + "span" + ), + label = "Gallery element does not have expected markup" + ) +}) + + +#' gallery_list() +#' Test both sets +test_that("Icon sets render properly", { + + set_sol <- .gallery__list(id = "test", set = "solid") + set_out <- .gallery__list(id = "test", set = "outline") + + expect_equal( + object = c( + set_sol$attribs$class, + set_out$attribs$class + ), + expected = c( + "icon-list set-solid", + "icon-list set-outline" + ), + label = "Solid and Outline icons are marked up properly" + ) +}) + +#' I'm not sure if these tests are helpful, but I guess I have to +#' please the coverage overlords! + +#' launch_gallery() +test_that("start gallery returns a shiny object", { + expect_equal( + object = class(launch_gallery(options = c(port = 1234))), + expected = "shiny.appobj", + label = "Start gallery does not return a shiny object" + ) +}) + +#' .ui() +#' This isn't a great unit test, but return and eval the primary +#' html elements +test_that("UI function returns expected markup", { + + res <- .ui() + expect_equal( + object = c( + class(res), + res[[2]]$name, + res[[3]]$name, + res[[4]]$name, + res[[5]]$name, + res[[6]]$name + ), + expected = c( + "shiny.tag.list", "list", + "nav", + "main", + "div", + "div", + "script" + ) + ) +}) + +#' .server() +#' This isn't really a test, but it maybe check to see the +#' server function returns something +test_that("Server returns R6 Shiny Observer", { + expect_equal( + object = class(.server()), + expected = c("Observer", "R6") + ) +}) \ No newline at end of file diff --git a/tests/testthat/test-rheroicon.R b/tests/testthat/test-rheroicon.R index f1814bb..80ee0ea 100644 --- a/tests/testthat/test-rheroicon.R +++ b/tests/testthat/test-rheroicon.R @@ -9,6 +9,27 @@ #' COMMENTS: NA #' //////////////////////////////////////////////////////////////////////////// +#' Icon is Null +#' +#' Function fails correctly if no name is provided +test_that("function properly errors out", { + expect_warning( + object = rheroicon() + ) +}) + +#' IconType fails +#' +#' If an invalid icon type is provided, function should +#' fail as expected. Pass a value other than `solid` or `outline` +test_that("invalid type properly returns error", { + expect_warning( + object = rheroicon( + name = "academic_cap", + type = "circle" + ) + ) +}) #' Class evaluation #'