Created
June 12, 2021 17:54
-
-
Save kylebutts/ae998e067a26a2e5bd8772c20ed1397c to your computer and use it in GitHub Desktop.
Shiny Components
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| responsive_col <- function(xs, ..., sm = xs, md = sm, lg = md, xl = lg, xs_offset = 0, sm_offset = 0, md_offset = 0, lg_offset = 0, xl_offset = 0){ | |
| if (!is.numeric(xs) || (xs < 1) || (xs > 12)) | |
| stop("column width must be between 1 and 12") | |
| if (!is.numeric(sm) || (sm < 1) || (sm > 12)) | |
| stop("column width must be between 1 and 12") | |
| if (!is.numeric(md) || (md < 1) || (md > 12)) | |
| stop("column width must be between 1 and 12") | |
| if (!is.numeric(lg) || (lg < 1) || (lg > 12)) | |
| stop("column width must be between 1 and 12") | |
| if (!is.numeric(xl) || (xl < 1) || (xl > 12)) | |
| stop("column width must be between 1 and 12") | |
| # Only add class if option is different from one smaller viewport | |
| colClass <- paste0("col-", xs) | |
| if(sm != xs) colClass <- paste0(colClass, " col-sm-", sm) | |
| if(md != sm) colClass <- paste0(colClass, " col-md-", md) | |
| if(lg != md) colClass <- paste0(colClass, " col-lg-", lg) | |
| if(xl != lg) colClass <- paste0(colClass, " col-xl-", xl) | |
| # Add offset | |
| if(xs_offset > 0) colClass <- paste0(colClass, " offset-", xs_offset) | |
| if(sm_offset > 0) colClass <- paste0(colClass, " offset-sm-", sm_offset) | |
| if(md_offset > 0) colClass <- paste0(colClass, " offset-md-", md_offset) | |
| if(lg_offset > 0) colClass <- paste0(colClass, " offset-lg-", lg_offset) | |
| if(xl_offset > 0) colClass <- paste0(colClass, " offset-xl-", xl_offset) | |
| div(class = colClass, ...) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment