Skip to content

Commit

Permalink
steps: add arg "showOn", that works with JS and R code, #1
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennebacher committed Apr 10, 2022
1 parent 15bb301 commit d3638a9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion R/conductor.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Conductor <- R6::R6Class(
step = function(el = NULL, title = NULL, text = NULL, position = NULL,
arrow = TRUE, is_id = TRUE, canClickTarget = TRUE,
advanceOn = NULL, scrollTo = TRUE, cancelIcon = NULL,
when = NULL) {
when = NULL, showOn = NULL) {

if (is.null(el)) {
if(!is.null(position)) {
Expand Down Expand Up @@ -130,6 +130,7 @@ Conductor <- R6::R6Class(
popover$canClickTarget <- canClickTarget
popover$arrow <- arrow
popover$scrollTo <- scrollTo
popover$showOn <- showOn
if (!is.null(cancelIcon)) {
popover$cancelIcon <- list(
enabled = cancelIcon[[1]],
Expand Down
2 changes: 1 addition & 1 deletion inst/packer/conductor.js

Large diffs are not rendered by default.

14 changes: 11 additions & 3 deletions srcjs/exts/conductor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import 'shepherd.js/dist/css/shepherd.css';
import './custom.css';

let tour = [];
let events = ["complete", "cancel", "start", "hide", "show", "active", "inactive"];
let tourEvents = ["complete", "cancel", "start", "hide", "show", "active", "inactive"];
let stepEvents = ["before-show", "show", "before-hide", "hide", "complete", "cancel", "destroy"];

// https://stackoverflow.com/a/196991/11598948
function toTitleCase(str) {
Expand Down Expand Up @@ -46,7 +47,7 @@ Shiny.addCustomMessageHandler('conductor-init', (opts) => {
tour[opts.id] = new Shepherd.Tour(opts.globals);

// Run code when tour is complete, cancelled, etc.
events.forEach(event => tour[opts.id].on(event, () => {
tourEvents.forEach(event => tour[opts.id].on(event, () => {
if (opts.globals["on" + toTitleCase(event)]) {
new Function("return " + opts.globals["on" + toTitleCase(event)])()
}
Expand All @@ -61,9 +62,16 @@ Shiny.addCustomMessageHandler('conductor-init', (opts) => {
}
}
}
tour[opts.id].addStep(step)

if (typeof opts.steps[index].showOn != undefined) {
if (typeof opts.steps[index].showOn == "boolean") {
opts.steps[index].showOn = "() => {return " + opts.steps[index].showOn.toString() + "}"
}
opts.steps[index].showOn = new Function("return " + opts.steps[index].showOn)()
}
});

tour[opts.id].addSteps(opts.steps)

})

Expand Down

0 comments on commit d3638a9

Please sign in to comment.