Skip to content

Commit 86ca69f

Browse files
fix(card header): Make card header flex by default (#1253) (#1254)
Fixes card headers so they are flex by default, ensures nav_spacer also works in card headers. -------------------------------- Co-authored-by: Garrick Aden-Buie <[email protected]> Co-authored-by: elnelson575 <[email protected]>
1 parent 7ba82cb commit 86ca69f

File tree

7 files changed

+35
-5
lines changed

7 files changed

+35
-5
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
## Improvements and bug fixes
88

9+
* `card_header()` is now flex by default and gains a `gap` argument to better support complex header layouts. (#1253)
10+
911
* `bs_theme_dependencies()` now avoids unnecessarily copying internal package files to R's temporary directory more than once when preparing precompiled theme dependencies (e.g. for a standard `bs_theme()` theme). (#1184)
1012

1113
* Fixed an issue where the `<main>` areas of `page_sidebar()` and `page_navbar()` (with a `sidebar`) were made to be a fillable containers even when `fillable = FALSE`. (#1188)

R/card.R

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,19 @@ card_title <- function(..., container = htmltools::h5) {
244244
#' @describeIn card_body A header (with border and background color) for the `card()`. Typically appears before a `card_body()`.
245245
#' @param container a function that generates an [htmltools tag][htmltools::tags].
246246
#' @export
247-
card_header <- function(..., class = NULL, container = htmltools::div) {
247+
card_header <- function(
248+
...,
249+
gap = NULL,
250+
class = NULL,
251+
container = htmltools::div
252+
) {
248253
as.card_item(
249-
container(class = "card-header", class = class, ...)
254+
container(
255+
class = "card-header bslib-gap-spacing",
256+
class = class,
257+
style = css(gap = validateCssUnit(gap)),
258+
...
259+
)
250260
)
251261
}
252262

R/sysdata.rda

-259 KB
Binary file not shown.

inst/components/dist/components.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/components/scss/card.scss

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,24 @@
2727
}
2828

2929
.card-header {
30+
display: flex;
31+
flex-direction: row;
32+
align-items: center;
33+
align-self: stretch;
34+
gap: 0.25rem;
35+
36+
// Give the nav flex: 1 so that if the card header contains a nav, it will take all the available space
37+
// and correctly push items to the right if `nav_spacer` is used
38+
> .nav {
39+
flex: 1;
40+
min-width: 0; // Prevent flex item from overflowing
41+
}
42+
43+
// Ensures that nav_spacer() correctly pushes subsequent items to the right in card headers
44+
> .bslib-nav-spacer {
45+
margin-left: auto;
46+
}
47+
3048
.form-group {
3149
margin-bottom: 0;
3250
}

man/card_body.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/_snaps/card.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"https://example.com/image.jpg"), card_body("image not a cap")))
3030
Output
3131
<div class="card bslib-card bslib-mb-spacing html-fill-item html-fill-container" data-bslib-card-init data-require-bs-caller="card()" data-require-bs-version="5">
32-
<div class="card-header">header</div>
32+
<div class="card-header bslib-gap-spacing">header</div>
3333
<img src="https://example.com/image.jpg" alt="" class="img-fluid"/>
3434
<div class="card-body bslib-gap-spacing html-fill-item html-fill-container" style="margin-top:auto;margin-bottom:auto;flex:1 1 auto;">image not a cap</div>
3535
<script data-bslib-card-init>bslib.Card.initializeAllCards();</script>

0 commit comments

Comments
 (0)