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

Modify icon() function to call fontawesome::fa_i() for equivalent functionality #3302

Merged
merged 40 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
d90e80e
Use `fontawesome::fa_i()` for FA <i> tags
rich-iannone Feb 12, 2021
ac034be
Remove fontawesome vendor files
rich-iannone Feb 12, 2021
589e66a
Add fontawesome pkg to Imports & Remotes
rich-iannone Feb 12, 2021
bdd9696
Remove FontAwesome `person()` entry
rich-iannone Feb 16, 2021
47c097f
Remove Font Awesome license info
rich-iannone Feb 16, 2021
397aa8b
Delete font-awesome.R
rich-iannone Feb 16, 2021
05cbb72
Update 'Collate' field (removes 'font-awesome.R')
rich-iannone Feb 16, 2021
f03b4fd
Delete updateFontAwesome.R
rich-iannone Feb 16, 2021
5866048
Prefer use of `fontawesome::fa()`
rich-iannone Feb 16, 2021
272371a
Improve function documentation
rich-iannone Feb 16, 2021
ddefe74
Update help file using roxygen
rich-iannone Feb 16, 2021
c0827a3
Modify icon name
rich-iannone Feb 17, 2021
d540bf2
Update icon name in example
rich-iannone Feb 17, 2021
f66005c
Modify icon name in example
rich-iannone Feb 17, 2021
4097ecf
Update help files
rich-iannone Feb 17, 2021
7878f72
Update bootstrap.R
rich-iannone Feb 18, 2021
d1fcdef
Update icon.Rd
rich-iannone Feb 18, 2021
0624754
Update bootstrap.R
rich-iannone Feb 18, 2021
053be3b
Revert `showcaseCodeTabs()` to use FA v4 name
rich-iannone Feb 18, 2021
edd7812
Revert icon name in example (back to FA v4)
rich-iannone Feb 18, 2021
b196e81
Remove `call. = FALSE` in `stop()`
rich-iannone Feb 19, 2021
75f40b0
Remove `fontawesome` from Remotes
rich-iannone Feb 19, 2021
ae68586
Add min version req for the fontawesome pkg
rich-iannone Feb 19, 2021
16ba498
Merge branch 'master' into icon-function
cpsievert May 5, 2021
8e6b25c
Increase minimum version requirement for fontawesome
rich-iannone May 6, 2021
9297050
Update roxygen docs for `icon()`
rich-iannone May 6, 2021
3d69265
Merge branch 'master' into icon-function
rich-iannone May 6, 2021
43b4822
Document (GitHub Actions)
rich-iannone May 6, 2021
704396b
Update icon.Rd
rich-iannone May 6, 2021
347a91e
Merge branch 'icon-function' of https://github.com/rstudio/shiny into…
rich-iannone May 6, 2021
803080b
Generate early return <i> tag for tabsetPanel logic
rich-iannone May 6, 2021
e241b11
Close #3384 and #3383: simplify and correct icon() logic
cpsievert May 6, 2021
7505989
Install htmltools PR for now
cpsievert May 6, 2021
715f8b2
Document (GitHub Actions)
cpsievert May 6, 2021
dec997b
Avoid using tag attribs to hold non-attribute values
cpsievert May 10, 2021
1995d0e
Better legacy support
cpsievert May 11, 2021
9af847c
No need to call prepTabIcon() twice
cpsievert May 11, 2021
6caf44a
code review
cpsievert May 11, 2021
14393bc
Fix glyphicon class creation
cpsievert May 12, 2021
b263c68
update news
cpsievert May 12, 2021
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
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ Authors@R: c(
comment = "Bootstrap-datepicker library"),
person("Andrew", "Rowls", role = c("ctb", "cph"),
comment = "Bootstrap-datepicker library"),
person("Dave", "Gandy", role = c("ctb", "cph"),
comment = "Font-Awesome font"),
person("Brian", "Reavis", role = c("ctb", "cph"),
comment = "selectize.js library"),
person("Salmen", "Bejaoui", role = c("ctb", "cph"),
Expand Down Expand Up @@ -80,6 +78,7 @@ Imports:
mime (>= 0.3),
jsonlite (>= 0.9.16),
xtable,
fontawesome,
rich-iannone marked this conversation as resolved.
Show resolved Hide resolved
htmltools (>= 0.5.0.9001),
R6 (>= 2.0),
sourcetools,
Expand Down Expand Up @@ -113,6 +112,8 @@ Suggests:
ragg,
showtext,
sass
Remotes:
rstudio/fontawesome
rich-iannone marked this conversation as resolved.
Show resolved Hide resolved
URL: https://shiny.rstudio.com/
BugReports: https://github.com/rstudio/shiny/issues
Collate:
Expand All @@ -134,7 +135,6 @@ Collate:
'devmode.R'
'diagnose.R'
'fileupload.R'
'font-awesome.R'
'graph.R'
'reactives.R'
'reactive-domains.R'
Expand Down
444 changes: 0 additions & 444 deletions LICENSE

Large diffs are not rendered by default.

73 changes: 37 additions & 36 deletions R/bootstrap.R
Original file line number Diff line number Diff line change
Expand Up @@ -1492,78 +1492,79 @@ downloadLink <- function(outputId, label="Download", class=NULL, ...) {
#' Create an icon
#'
#' Create an icon for use within a page. Icons can appear on their own, inside
#' of a button, or as an icon for a [tabPanel()] within a
#' [navbarPage()].
#'
#' @param name Name of icon. Icons are drawn from the
#' [Font Awesome Free](https://fontawesome.com/) (currently icons from
#' the v5.13.0 set are supported with the v4 naming convention) and
#' [Glyphicons](https://getbootstrap.com/components/#glyphicons)
#' libraries. Note that the "fa-" and "glyphicon-" prefixes should not be used
#' in icon names (i.e. the "fa-calendar" icon should be referred to as
#' "calendar")
#' @param class Additional classes to customize the style of the icon (see the
#' of a button, or as an icon for a [tabPanel()] within a [navbarPage()].
#'
#' @param name The name of the icon. Icons are drawn from the [Font Awesome
#' Free](https://fontawesome.com/) (currently icons from the v5.13.0 set are
rich-iannone marked this conversation as resolved.
Show resolved Hide resolved
#' supported with the v4 naming convention) and
#' [Glyphicons](https://getbootstrap.com/docs/3.3/components/#glyphicons)
#' libraries. Note that the `"fa-"` and `"glyphicon-"` prefixes should not be
#' used in icon names (i.e. the `"fa-calendar"` icon should be referred to as
#' `"calendar"`).
#' @param class Additional classes to customize the style of an icon (see the
#' [usage examples](https://fontawesome.com/how-to-use) for details on
#' supported styles).
#' @param lib Icon library to use ("font-awesome" or "glyphicon")
#' @param ... Arguments passed to the `<i>` tag of [htmltools::tags]
#' @param lib The icon library to use. If drawing from the Font Awesome library
#' of icons, this should be `"font-awesome"`. The other option is or
#' `"glyphicon"` to use icons from the Glyphicons library.
#' @param ... Arguments passed to the `<i>` tag of [htmltools::tags].
#'
#' @return An icon element
#' @return An icon element.
#'
#' @seealso For lists of available icons, see
#' [https://fontawesome.com/icons](https://fontawesome.com/icons) and
#' [https://getbootstrap.com/components/#glyphicons](https://getbootstrap.com/components/#glyphicons).
#'
#' [https://getbootstrap.com/docs/3.3/components/#glyphicons](https://getbootstrap.com/docs/3.3/components/#glyphicons).
#'
#' @examples
#' # add an icon to a submit button
#' submitButton("Update View", icon = icon("refresh"))
#' submitButton("Update View", icon = icon("redo"))
#'
#' navbarPage("App Title",
#' tabPanel("Plot", icon = icon("bar-chart-o")),
#' tabPanel("Summary", icon = icon("list-alt")),
#' tabPanel("Table", icon = icon("table"))
#' )
#' @export
icon <- function(name, class = NULL, lib = "font-awesome", ...) {
icon <- function(name,
class = NULL,
lib = "font-awesome",
...) {

prefixes <- list(
"font-awesome" = "fa",
"glyphicon" = "glyphicon"
)
prefix <- prefixes[[lib]]

# determine stylesheet
# Stop function if `lib` value is not allowed
if (is.null(prefix)) {
stop("Unknown font library '", lib, "' specified. Must be one of ",
paste0('"', names(prefixes), '"', collapse = ", "))
stop(
"Unknown font library '", lib, "' specified. Must be one of ",
paste0('"', names(prefixes), '"', collapse = ", "),
call. = FALSE
rich-iannone marked this conversation as resolved.
Show resolved Hide resolved
)
}

# Use the `fontawesome::fa_i()` function for FontAwesome icons
# with font-awesome
if (lib == "font-awesome") {
return(fontawesome::fa_i(name = name, class = class, ...))
}

# build the icon class (allow name to be null so that other functions
# e.g. buildTabset can pass an explicit class value)
iconClass <- ""
if (!is.null(name)) {
prefix_class <- prefix
if (prefix_class == "fa" && name %in% font_awesome_brands) {
prefix_class <- "fab"
}
iconClass <- paste0(prefix_class, " ", prefix, "-", name)
}
if (!is.null(class))

if (!is.null(class)) {
iconClass <- paste(iconClass, class)
}

iconTag <- tags$i(class = iconClass, role = "presentation", `aria-label` = paste(name, "icon"), ...)

# font-awesome needs an additional dependency (glyphicon is in bootstrap)
if (lib == "font-awesome") {
htmlDependencies(iconTag) <- htmlDependency(
"font-awesome", "5.13.0", "www/shared/fontawesome", package = "shiny",
stylesheet = c(
"css/all.min.css",
"css/v4-shims.min.css"
)
)
}

htmltools::browsable(iconTag)
}

Expand Down
Loading