Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions inst/emptystate.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ function hideEmptyState(message) {
resizeObserver.unobserve(elementToReplace);
}

function shiny_emptystate_updatePosition(id){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change the name of the function to follow camel case, instead of a weird hybrid. updateElementPosition should work here.

const elementWithEmptyState = findElementById(id);
const emptyStateContainer = elementWithEmptyState.querySelector(".empty-state-container");

const parentElement = emptyStateContainer.parentElement;
emptyStateContainer.style.height = parentElement.offsetHeight + "px";
emptyStateContainer.style.width = parentElement.offsetWidth + "px";
emptyStateContainer.style.left = parentElement.offsetLeft + "px";
emptyStateContainer.style.top = parentElement.offsetTop + "px";
}


$(function() {
Shiny.addCustomMessageHandler("showEmptyState", showEmptyState)
Shiny.addCustomMessageHandler("hideEmptyState", hideEmptyState)
Expand Down
39 changes: 26 additions & 13 deletions pkgdown/_pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,38 @@ url: https://appsilon.github.io/shiny.emptystate/

navbar:
bg: primary
left:
- icon: fa-home
href: index.html
structure:
left: [home, tutorials, reference, changelog]
right: [search, github, twitter, mastodon]
components:
home:
icon: fa-home
text: "Start"
- icon: fa-university
href: articles/use-undraw-drawkit-image.html
text: "Tutorial"
- icon: fa-file-code-o
href: index.html
tutorials:
text: Tutorials
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new article is not a tutorial, but a small guide. Change this to "Articles".

icon: fa-university
menu:
- text: How to Use unDraw/Drawkit Illustrations
href: articles/use-undraw-drawkit-image.html
- text: How to use triggered animations
href: articles/use-toggle-animations.html
reference:
icon: fa-file-code-o
text: "Reference"
href: reference/index.html
- icon: fa-newspaper-o
text: Changelog
changelog:
icon: fa-newspaper-o
text: "Changelog"
href: news/index.html
right:
- icon: fa-github fa-lg
github:
icon: fa-github fa-lg
href: https://github.com/Appsilon/shiny.emptystate
- icon: fa-twitter fa-lg
twitter:
icon: fa-twitter fa-lg
href: https://twitter.com/Appsilon
- icon: fab fa-mastodon fa-lg
mastodon:
icon: fab fa-mastodon fa-lg
href: https://fosstodon.org/@appsilon

home:
Expand Down
43 changes: 43 additions & 0 deletions tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,46 @@ test_app <- function() {
}
)
}

test_slider_app <- function() {
shiny::shinyApp(
ui = shiny::fillPage(
use_empty_state(),
shiny::actionButton(
"toggle_pannel",
"Toggle panel",
class = "btn btn-primary",
onClick = "$('#container1').toggle(0,
function(){shiny_emptystate_updatePosition('container2')});"
),
shiny::div(
style = "width: 300px",
class = "d-flex flex-column gap-5",
shiny::div(
id = "container1",
shiny::div(
shiny::h1("Card 1"),
"Card content"
)
),
shiny::div(
id = "container2",
shiny::div(
shiny::h1("Card 2"),
"Card content"
)
)
)
),
server = function(input, output) {
empty_state_content <- shiny::div(
"This is example empty state content"
)
empty_state_manager <- EmptyStateManager$new(
id = "container2",
html_content = empty_state_content
)
empty_state_manager$show()
}
)
}
9 changes: 9 additions & 0 deletions tests/testthat/test-empty_state.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ describe("EmptyStateManager", {
expect_null(app$get_html(selector = ".empty-state-content"))
app$stop()
})

it("checks the empty state component follows slider from id", {
app <- shinytest2::AppDriver$new(test_slider_app(), name = "slide_tag")
position_1 <- app$get_html(selector = "#container2")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a position, but a full HTML. The variable name is misleading.

app$click("toggle_pannel")
position_2 <- app$get_html(selector = "#container2")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a position, but a full HTML. The variable name is misleading.

expect_false(position_1 == position_2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you compare the whole HTML, this may be a false positive (some other parts of HTML will change).

app$stop()
})
})

describe("use_empty_state()", {
Expand Down
Binary file added vignettes/files/dynamic_emptystate.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 69 additions & 0 deletions vignettes/use-toggle-animations.rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
title: "How to use triggered animations"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{How to use triggered animations}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---

# Introduction

`shiny.emptystate` is capable of being used for dynamic positioning trigger animations. This is specially interesting when we have UIs that change position and we want to keep the `emptystate` in the appropriate tag
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`shiny.emptystate` is capable of being used for dynamic positioning trigger animations. This is specially interesting when we have UIs that change position and we want to keep the `emptystate` in the appropriate tag
`shiny.emptystate` is capable of being used for dynamic positioning trigger animations. This is specially useful when we have UIs that change position and we want to keep the `emptystate` in the appropriate tag


**Note:** This solution is only available for instant positioning animation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please include the solution for the animations, provided in the issue comments.


# Animation example

The example below showcases the example of using a dynamic trigger slider that changes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please explain this in more detail. Also, inform the reader what would happen without the updatePosition function.


The function `shiny_emptystate_updatePosition` updates the position of the #container1 after being re-positioned
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make it clear that this function is 1. JS 2. comes withshiny.emptystate.


``` r
library(shiny)
library(shiny.emptystate)

ui <- shiny::fillPage(
use_empty_state(),
shiny::actionButton(
"toggle_pannel",
"Toggle panel",
class = "btn btn-primary",
onClick = "$('#container1').toggle(0,
function(){shiny_emptystate_updatePosition('container2')});"
),
shiny::div(
style = "width: 300px",
class = "d-flex flex-column gap-5",
shiny::div(
id = "container1",
shiny::div(
shiny::h1("Card 1"),
"Card content"
)
),
shiny::div(
id = "container2",
shiny::div(
shiny::h1("Card 2"),
"Card content"
)
)
)
)

server = function(input, output) {
empty_state_content <- shiny::div(
"This is example empty state content"
)
empty_state_manager <- EmptyStateManager$new(
id = "container2",
html_content = empty_state_content
)
empty_state_manager$show()
}

shinyApp(ui, server)
```

![](files/dynamic_emptystate.gif)