Skip to content

Commit 0ef03c9

Browse files
Merge pull request #40 from Appsilon/tippy
Tippy
2 parents f99abe1 + d5695ee commit 0ef03c9

12 files changed

Lines changed: 92 additions & 4 deletions

File tree

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export(reactable_extras_dependency)
88
export(reactable_extras_server)
99
export(reactable_extras_ui)
1010
export(text_extra)
11+
export(tooltip_extra)

R/dependencies.R

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,18 @@ reactable_extras_dependency <- function() {
1010
version = "0.0.1",
1111
src = list(file = "assets"),
1212
package = "reactable.extras",
13-
script = c("js/reactable-extras.js", "js/reactable-server.js"),
14-
stylesheet = "css/reactable-server.css"
13+
script = c(
14+
"js/reactable-extras.js",
15+
"js/reactable-server.js",
16+
"js/popper.js",
17+
"js/tippy.js"
18+
),
19+
stylesheet = c(
20+
"css/reactable-server.css",
21+
"css/tippy-light.css",
22+
"css/tippy-light-border.css",
23+
"css/tippy-material.css",
24+
"css/tippy-translucent.css"
25+
)
1526
)
1627
}

R/tooltip.R

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#' Tool-tip for table headers
2+
#'
3+
#' @param content The content to be displayed in the tool-tip
4+
#' @param theme The theme of the tool-tip, either "light", "light-border", "material" or
5+
#' "translucent"
6+
#'
7+
#' @examples
8+
#' reactable::colDef(header = tooltip_extra("This is my tool-tip", theme = "material"))
9+
#'
10+
#' @export
11+
tooltip_extra <- function(content, theme = "light") {
12+
reactable::JS(
13+
htmltools::doRenderTags(
14+
htmltools::htmlTemplate(
15+
text_ = "function(columnInfo) {
16+
return React.createElement(TooltipExtras,
17+
{column: columnInfo.name, tooltip: '{{content}}',
18+
theme: '{{theme}}'})
19+
}",
20+
content = content,
21+
theme = theme
22+
)
23+
)
24+
)
25+
}

inst/assets/css/tippy-light-border.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/assets/css/tippy-light.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/assets/css/tippy-material.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/assets/css/tippy-translucent.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/assets/js/popper.js

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/assets/js/reactable-extras.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,24 @@ function updateMemory (id, uuid, column, value) {
99
memory[[id, uuid, column]] = value;
1010
}
1111

12+
let ReRenderCount = 0;
13+
14+
function GenerateTooltipId () {
15+
return "tooltip-" + ReRenderCount++;
16+
}
17+
18+
function TooltipExtras ({ column, tooltip, theme }) {
19+
const tooltip_id = GenerateTooltipId();
20+
React.useEffect(() => {
21+
tippy("#" + tooltip_id, { content: tooltip, theme: theme });
22+
}, []);
23+
return React.createElement(
24+
'span',
25+
{ id: tooltip_id },
26+
column
27+
)
28+
}
29+
1230
function ButtonExtras ({ id, label, uuid, column, className, children }) {
1331
const onClick = event => {
1432
Shiny.setInputValue(id, { row: uuid, column: column}, { priority: 'event' })

inst/assets/js/tippy.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)