@@ -4,15 +4,19 @@ library(muiMaterial)
44# ── Source example files into an isolated environment ────────────────────────
55example_files <- list.files(
66 system.file(" examples" , package = " muiMaterial" ),
7- full.names = TRUE , pattern = " \\ .R$"
7+ full.names = TRUE ,
8+ pattern = " \\ .R$"
89)
910example_env <- new.env(parent = globalenv())
10- sapply(X = example_files , FUN = source , local = example_env )
11+ invisible ( sapply(X = example_files , FUN = source , local = example_env ) )
1112
1213# ── Discover components from ui_* objects ────────────────────────────────────
1314# Any new example file that defines ui_Foo will automatically appear in the nav.
1415# Add names here to exclude them from the showcase.
15- exclude_components <- c(" CustomComponentShinyInput" , " CustomComponentShinyInputStyled" )
16+ exclude_components <- c(
17+ " CustomComponentShinyInput" ,
18+ " CustomComponentShinyInputStyled"
19+ )
1620
1721discovered <- sort(ls(pattern = " ^ui_" , envir = example_env ))
1822components <- sub(" ^ui_" , " " , discovered )
@@ -27,7 +31,9 @@ get_code_example <- function(component_name) {
2731 file.path(" examples" , paste0(component_name , " .R" )),
2832 package = " muiMaterial"
2933 )
30- if (file.exists(exact )) return (readChar(exact , file.info(exact )$ size ))
34+ if (file.exists(exact )) {
35+ return (readChar(exact , file.info(exact )$ size ))
36+ }
3137
3238 pattern <- paste0(" ^ui_" , gsub(" \\ ." , " \\\\ ." , component_name ), " \\ s*<-" )
3339 for (f in example_files ) {
@@ -48,27 +54,30 @@ create_tab_list <- function(tablist_id) {
4854 label = name ,
4955 value = name ,
5056 sx = list (
51- alignItems = " flex-start" ,
52- textAlign = " left" ,
53- minHeight = 44 ,
54- pl = 3 ,
57+ alignItems = " flex-start" ,
58+ textAlign = " left" ,
59+ minHeight = 44 ,
60+ pl = 3 ,
5561 textTransform = " none" ,
56- fontSize = " 0.875rem"
62+ fontSize = " 0.875rem"
5763 )
5864 )
5965 }))
60- do.call(TabList.shinyInput , c(
61- list (
62- inputId = tablist_id ,
63- value = initial_tab ,
64- orientation = " vertical" ,
65- sx = list (
66- " & .MuiTabs-indicator" = list (left = 0 , right = " auto" , width = 3 ),
67- " & .Mui-selected" = list (fontWeight = 700 )
68- )
69- ),
70- tab_items
71- ))
66+ do.call(
67+ TabList.shinyInput ,
68+ c(
69+ list (
70+ inputId = tablist_id ,
71+ value = initial_tab ,
72+ orientation = " vertical" ,
73+ sx = list (
74+ " & .MuiTabs-indicator" = list (left = 0 , right = " auto" , width = 3 ),
75+ " & .Mui-selected" = list (fontWeight = 700 )
76+ )
77+ ),
78+ tab_items
79+ )
80+ )
7281}
7382
7483create_nav_content <- function (tablist_id ) {
@@ -77,9 +86,9 @@ create_nav_content <- function(tablist_id) {
7786 Toolbar(
7887 Typography(
7988 " muiMaterial" ,
80- variant = " h6" ,
89+ variant = " h6" ,
8190 component = " div" ,
82- sx = list (fontWeight = 700 , color = " primary.main" )
91+ sx = list (fontWeight = 700 , color = " primary.main" )
8392 )
8493 ),
8594 Divider(),
@@ -93,7 +102,7 @@ create_nav_content <- function(tablist_id) {
93102create_panel <- function (component_name ) {
94103 TabPanel.shinyInput(
95104 inputId = paste0(" tab" , component_name ),
96- value = component_name ,
105+ value = component_name ,
97106 Box(
98107 sx = list (pb = 5 ),
99108 Typography(
@@ -105,16 +114,21 @@ create_panel <- function(component_name) {
105114 Divider(sx = list (mb = 3 )),
106115 Card(
107116 elevation = 0 ,
108- sx = list (border = 1 , borderColor = " divider" , borderRadius = 2 , mb = 3 ),
117+ sx = list (
118+ border = 1 ,
119+ borderColor = " divider" ,
120+ borderRadius = 2 ,
121+ mb = 3
122+ ),
109123 CardContent(
110124 get(paste0(" ui_" , component_name ), envir = example_env )
111125 )
112126 ),
113127 Accordion(
114- elevation = 0 ,
128+ elevation = 0 ,
115129 disableGutters = TRUE ,
116130 sx = list (
117- border = 1 ,
131+ border = 1 ,
118132 borderColor = " divider" ,
119133 borderRadius = 2 ,
120134 " &:before" = list (display = " none" )
@@ -127,11 +141,11 @@ create_panel <- function(component_name) {
127141 sx = list (p = 0 ),
128142 Box(
129143 sx = list (
130- bgcolor = " grey.50" ,
131- borderTop = 1 ,
144+ bgcolor = " grey.50" ,
145+ borderTop = 1 ,
132146 borderColor = " divider" ,
133- overflow = " auto" ,
134- p = 2
147+ overflow = " auto" ,
148+ p = 2
135149 ),
136150 tags $ pre(
137151 style = " margin: 0;" ,
@@ -152,7 +166,7 @@ ui <- muiMaterialPage(
152166 CssBaseline(
153167 TabContext.shinyInput(
154168 inputId = " context" ,
155- value = initial_tab ,
169+ value = initial_tab ,
156170
157171 Box(
158172 sx = list (display = " flex" ),
@@ -163,22 +177,26 @@ ui <- muiMaterialPage(
163177 sx = list (zIndex = 1300 ),
164178 Toolbar(
165179 IconButton(
166- id = " mobile-nav-trigger" ,
180+ id = " mobile-nav-trigger" ,
167181 color = " inherit" ,
168- edge = " start" ,
169- sx = list (mr = 2 , display = list (sm = " none" )),
182+ edge = " start" ,
183+ sx = list (mr = 2 , display = list (sm = " none" )),
170184 shiny :: icon(" bars" )
171185 ),
172186 Typography(
173187 " muiMaterial" ,
174- variant = " h6" ,
188+ variant = " h6" ,
175189 component = " div" ,
176- sx = list (fontWeight = 700 , letterSpacing = " 0.3px" )
190+ sx = list (fontWeight = 700 , letterSpacing = " 0.3px" )
177191 ),
178192 Typography(
179193 " \u 00b7 Showcase" ,
180194 variant = " body1" ,
181- sx = list (ml = 1 , opacity = 0.75 , display = list (xs = " none" , sm = " block" ))
195+ sx = list (
196+ ml = 1 ,
197+ opacity = 0.75 ,
198+ display = list (xs = " none" , sm = " block" )
199+ )
182200 )
183201 )
184202 ),
@@ -191,22 +209,28 @@ ui <- muiMaterialPage(
191209 # Mobile: Drawer.triggerId (no server logic needed)
192210 Drawer.triggerId(
193211 triggerId = " mobile-nav-trigger" ,
194- anchor = " left" ,
195- width = drawer_width ,
212+ anchor = " left" ,
213+ width = drawer_width ,
196214 sx = list (
197215 display = list (xs = " block" , sm = " none" ),
198- " & .MuiDrawer-paper" = list (boxSizing = " border-box" , width = drawer_width )
216+ " & .MuiDrawer-paper" = list (
217+ boxSizing = " border-box" ,
218+ width = drawer_width
219+ )
199220 ),
200221 create_nav_content(" tabListMobile" )
201222 ),
202223
203224 # Desktop: permanent drawer
204225 Drawer(
205226 variant = " permanent" ,
206- open = TRUE ,
227+ open = TRUE ,
207228 sx = list (
208229 display = list (xs = " none" , sm = " block" ),
209- " & .MuiDrawer-paper" = list (boxSizing = " border-box" , width = drawer_width )
230+ " & .MuiDrawer-paper" = list (
231+ boxSizing = " border-box" ,
232+ width = drawer_width
233+ )
210234 ),
211235 create_nav_content(" tabListDesktop" )
212236 )
@@ -216,17 +240,20 @@ ui <- muiMaterialPage(
216240 Box(
217241 component = " main" ,
218242 sx = list (
219- flexGrow = 1 ,
220- p = 3 ,
221- width = list (sm = sprintf(" calc(100%% - %dpx)" , drawer_width )),
243+ flexGrow = 1 ,
244+ p = 3 ,
245+ width = list (sm = sprintf(" calc(100%% - %dpx)" , drawer_width )),
222246 minHeight = " 100vh" ,
223- bgcolor = " background.default"
247+ bgcolor = " background.default"
224248 ),
225249 Toolbar(), # spacer for fixed AppBar
226- do.call(Container , c(
227- list (maxWidth = " md" ),
228- unname(lapply(components , create_panel ))
229- ))
250+ do.call(
251+ Container ,
252+ c(
253+ list (maxWidth = " md" ),
254+ unname(lapply(components , create_panel ))
255+ )
256+ )
230257 )
231258 )
232259 )
@@ -239,29 +266,38 @@ server <- function(input, output, session) {
239266 selected_tab <- reactiveVal(initial_tab )
240267
241268 observeEvent(input $ tabListDesktop , {
242- if (! is.null(input $ tabListDesktop ) && input $ tabListDesktop != selected_tab())
269+ if (
270+ ! is.null(input $ tabListDesktop ) && input $ tabListDesktop != selected_tab()
271+ ) {
243272 selected_tab(input $ tabListDesktop )
273+ }
244274 })
245275
246276 observeEvent(input $ tabListMobile , {
247- if (! is.null(input $ tabListMobile ) && input $ tabListMobile != selected_tab())
277+ if (
278+ ! is.null(input $ tabListMobile ) && input $ tabListMobile != selected_tab()
279+ ) {
248280 selected_tab(input $ tabListMobile )
281+ }
249282 })
250283
251284 observe({
252285 val <- selected_tab()
253- updateTabContext.shinyInput(inputId = " context" , value = val )
254- updateTabList.shinyInput( inputId = " tabListDesktop" , value = val )
255- updateTabList.shinyInput( inputId = " tabListMobile" , value = val )
286+ updateTabContext.shinyInput(inputId = " context" , value = val )
287+ updateTabList.shinyInput(inputId = " tabListDesktop" , value = val )
288+ updateTabList.shinyInput(inputId = " tabListMobile" , value = val )
256289 })
257290
258291 # Delegate server logic to each example's server_* function (if it exists).
259292 # Pass only the arguments the function actually declares (some omit session).
260293 lapply(components , function (comp ) {
261294 fn_name <- paste0(" server_" , comp )
262- if (exists(fn_name , envir = example_env ) && is.function(get(fn_name , envir = example_env ))) {
263- fn <- get(fn_name , envir = example_env )
264- all_args <- list (input = input , output = output , session = session )
295+ if (
296+ exists(fn_name , envir = example_env ) &&
297+ is.function(get(fn_name , envir = example_env ))
298+ ) {
299+ fn <- get(fn_name , envir = example_env )
300+ all_args <- list (input = input , output = output , session = session )
265301 do.call(fn , all_args [names(formals(fn ))])
266302 }
267303 })
0 commit comments