Skip to content

Commit

Permalink
replace up with top and down with bottom, more user friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
daattali committed Jul 23, 2023
1 parent 17c56c0 commit c374074
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 21 deletions.
14 changes: 8 additions & 6 deletions R/tip.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#' is not a supported interaction.
#' @param tag A Shiny tag, tagList, or plain text to add a tooltip to.
#' @param content The text in the tooltip. Can include emojis, but cannot contain HTML.
#' @param position The position of the tooltip in relation to the tag. One of: `"up"`, `"down"`,
#' `"left"`, `"right"`, `"up-left"`, `"up-right"`, `"down-left"`, `"down-right"`.
#' @param position The position of the tooltip in relation to the tag. One of: `"top"`, `"bottom"`,
#' `"left"`, `"right"`, `"top-left"`, `"top-right"`, `"bottom-left"`, `"bottom-right"`.
#' @param length How wide should the tooltip be? One of: `"line"` (place the entire tooltip in one
#' line), `"fit"` (the tooltip should have the same width as the tag), `"s"` (small), `"m"` (medium),
#' `"l"` (large), `"xl"` (extra large).
Expand Down Expand Up @@ -58,7 +58,7 @@
tip <- function(
tag,
content,
position = getOption("shinytip.position", "up"),
position = getOption("shinytip.position", "top"),
length = getOption("shinytip.length", "line"),
bg = getOption("shinytip.bg", "black"),
fg = getOption("shinytip.fg", "white"),
Expand All @@ -68,10 +68,12 @@ tip <- function(
pointer = getOption("shinytip.pointer", TRUE),
...) {

allowed_position <- c("up", "down", "left", "right", "up-left", "up-right", "down-left", "down-right")
allowed_position <- c("top", "bottom", "left", "right", "top-left", "top-right", "bottom-left", "bottom-right")
if (!position %in% allowed_position) {
stop("tip: `position` must be one of: [", toString(allowed_position), "]", call. = FALSE)
}
position <- sub("top", "up", position)
position <- sub("bottom", "down", position)

allowed_length <- c("line", "fit", "s", "m", "l", "xl")
if (!length %in% allowed_length) {
Expand Down Expand Up @@ -184,7 +186,7 @@ tip <- function(
#' @export
tip_icon <- function(
content,
position = getOption("shinytip.position", "up"),
position = getOption("shinytip.position", "top"),
length = getOption("shinytip.length", "line"),
bg = getOption("shinytip.bg", "black"),
fg = getOption("shinytip.fg", "white"),
Expand All @@ -211,7 +213,7 @@ tip_icon <- function(
tip_input <- function(
tag,
content,
position = getOption("shinytip.position", "up"),
position = getOption("shinytip.position", "top"),
length = getOption("shinytip.length", "line"),
bg = getOption("shinytip.bg", "black"),
fg = getOption("shinytip.fg", "white"),
Expand Down
6 changes: 3 additions & 3 deletions man/tip.Rd

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

6 changes: 3 additions & 3 deletions man/tip_icon.Rd

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

6 changes: 3 additions & 3 deletions man/tip_input.Rd

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

2 changes: 1 addition & 1 deletion tests/manual/advanced.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ui <- fluidPage(fluidRow(
column(
offset = 2,
width = 3,
shinytip::tip_icon("This is the explanation", position = "down"), br(),
shinytip::tip_icon("This is the explanation", position = "bottom"), br(),
"This one requires a click",
shinytip::tip_icon("Red background", position = "right", bg = "red", click = TRUE),
shinytip::tip_input(
Expand Down
2 changes: 1 addition & 1 deletion tests/manual/options.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ui <- fluidPage(
tip(
"blue tip on bottom",
sample_text,
position = "down",
position = "bottom",
fg = "blue",
click = FALSE
)
Expand Down
6 changes: 3 additions & 3 deletions tests/manual/simple.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ ui <- fluidPage(fluidRow(
tip(
"tip on the bottom right, small",
sample_text,
position = "down-right",
position = "bottom-right",
length = "s"
), br(),
tip(
"tip on the top left, extra large",
sample_text,
position = "up-left",
position = "top-left",
length = "xl"
), br(),
tip(
div("tip on a div; bottom, red background, yellow colour, fit within the dimensions of the parent"),
sample_text,
position = "down",
position = "bottom",
length = "fit",
bg = "red",
fg = "yellow"
Expand Down
2 changes: 1 addition & 1 deletion tests/manual/simple.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ runtime: shiny
---

```{r}
shinytip::tip("hover over me", "this is a tooltip", position = "down")
shinytip::tip("hover over me", "this is a tooltip", position = "bottom")
```

0 comments on commit c374074

Please sign in to comment.