New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refresh and refactor value boxes #758
Conversation
.bslib-value-box .value-box-title .bslib-value-box .value-box.value
Also consolidates container query for all showcase layouts
…ore grid width options
We only need the `class` in the calling functions, since all the layout logic now lives in the CSS and is based on the class
da9919b
to
0bb3192
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM once the remaining comments are addressed! 🚀
Co-authored-by: Carson Sievert <cpsievert1@gmail.com>
Yeah, I think these values tend to make better gradients that are interesting but not overpowering. Here it is with essentially I do think it'd be completely reasonable to put CSS variables in front of those values though so they can be customized easily. |
Okay, I added CSS variables that make each of the orientation, start and end positions pick up on CSS variables, which could be used like this (or set globally on value_box(
title = "Customer lifetime value",
value = "$5,000",
showcase = bsicons::bs_icon("bank2"),
theme = "bg-gradient-teal-indigo",
style = css(
"--bg-gradient-deg" = "210deg",
"--bg-gradient-start" = "10%",
"--bg-gradient-end" = "90%"
)
) I initially adjusted the fallback and contrast-driving color to be an even mix of the two colors, since that's our best guess, but this degraded the appearance of the default case. Users can rely on the |
c2ce815
to
d639a3b
Compare
For #625
New features
Many new themes, powered by utility classes added to the Bootstrap bundle. We already have
bg-{name}
andtext-{name}
classes from$theme-colors
(the semantic color names, likeprimary
), to which we're addingbg-{color}
andtext-{color}
(the main colors from the$colors
map), as well as gradient background classes withbg-gradient-{from}-{to}
where from and to are drawn from the main colors map as well. Both can be user-customized via the$bslib-gradient-colors
map.The
theme_color
argument is replaced withtheme
. For nowtheme_color
is passed totheme
if only one is provided, with a deprecation warning thanks to lifecycle. As a result, I'm also adding lifecycle as a new dependency so that we can start using it in more places.Themes are now fully customizable via
value_box_theme()
, which takesname
,bg
, andfg
. I've also added a helper functionpair_colors_bg_fg()
that we can use to perform our typical foreground color picking based on contrast with the background color. Thevalue_box_theme()
creates a newbslib_value_box_theme
classed list that contains the theme class and styles to be applied inline to the value box card.Similarly we now have a
bslib_showcase_layout
class to organize the user options for the showcase layout. Theshowcase_layout
argument ofvalue_box()
now accepts primarily character strings, to use the default settings of the named showcase layout, or the result from theshowcase_layout_{layout}()
functions where the user can customize the layout settings.I added a new showcase layout, called
showcase_bottom()
featuring a full-bleed plot along the bottom edge of the value box. There are now three layouts,"left center"
,"top right"
, and"bottom"
.The
layout_showcase()
function now creates consistentvalue_box()
markup that carries the user preference forward. All of the layout logic was moved into the value box CSS, so we only do basic validation of units on the R side. As a part of this, I also removed the internal use oflayout_column_wrap()
, opting instead for a custom grid implementation. The lets us simplify the value box markup considerably, in particular to be able to coordinate the.value-box-showcase
and.value-box-area
(contents) entirely around those classes.The CSS was refactored considerably. In particular, we now use named grid areas and assign the showcase and contents to those areas based on the
.showcase-{layout}
classes.I moved the
.showcase-{layout}
class to the top level of the value box. This lets us approach the showcase layout styles more holistically. Also, all of the custom CSS properties used to communicate the user's preferences from R are now consolidated on the.value-box-grid
item. They also start with---bslib-
(rather than--bslib
) to indicate they are private CSS properties. (In the future, we'd rather--_bslib
but can't currently due to limitations with `htmltools::css().)When no specific theme is requested by the user, we add a
.default
class to the.bslib-value-box
container. This class can be used to style the default value box appearance. It defaults to the colors used by cards in the current theme, but can also be customized via CSS variables from anywhere higher up in the DOM tree (likely on:root
). These variables are--bslib-value-box-color
,--bslib-value-box-bg
,--bslib-value-box-border-color
, and--bslib-value-box-border-width
.Box shadows can be turned on for value boxes via the
$enable-shadows
flag, or specifically through$bslib-value-box-enable-shadow
.We also added
$bslib-value-box-enable-border
that can be one of"auto"
,"always"
or"never"
. When"never"
, we remove all borders from value boxes."always"
is an implicit state, and technically means that we follow the.card
styles. When"auto"
, the default, borders are enabled for cards that 1) don't set a background color and 2) that don't have shadows.There are also a few shiny preset style changes in here. In particular, we're adding a gradient to icons used in the default-themed value boxes. To get the gradient on the SVG icons, we have to get an
<svg>
element onto the page, so we're doing a bit of an unusual round trip by adding a script to the value box dependency that contains the full svg (it's small) and writes it into the document so we can use it.Preview
Kitchen Sink App