withStates: Chakra component with states or hooks

Description Usage Arguments Value Examples

View source: R/chakra.R

Description

Create a Chakra component with React states and/or hooks.

Usage

1
withStates(component, states)

Arguments

component

a React component

states

named list of states; a state value can be an R object serializable to JSON, a React component (Tag$Component(...)), a Shiny widget, some HTML code defined by the HTML function, a JSX element defined by the jsx function, a JavaScript value defined by the jseval function, or a hook such as useDisclosure() (see useDisclosure).

Value

A component to use in chakraComponent.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
library(shiny)
library(shinyChakraUI)

ui <- chakraPage(

  br(),

  chakraComponent(
    "mycomponent",

    withStates(

      Tag$Fragment(

        Tag$Container(
          maxW = "xl",
          centerContent = TRUE,
          bg = "orange.50",
          Tag$Heading(
            getState("heading")
          ),
          Tag$Text(
            "I'm just some text."
          )
        ),

        br(),
        Tag$Divider(),
        br(),

        Tag$Button(
          colorScheme = "twitter",
          display = "block",
          onClick = jseval(
            "() => setState('heading', 'I am the new heading.')"
          ),
          "Click me to change the heading"
        )

      ),

      states = list(heading = "I am the heading.")

    )

  )

)

server <- function(input, output, session){}

if(interactive()){
  shinyApp(ui, server)
}

shinyChakraUI documentation built on Jan. 5, 2022, 5:08 p.m.