Skip to content

Commit e0b15d0

Browse files
authored
Add an optional wrapper to tabs (#11897)
Adds an optional argument to the `tabs` shortcode that when set to `true`, wraps tabs in a border and slight background color. This allows us to opt specific tabs into being more visually isolated from the surrounding content. To better facilitate this, slightly adjusts the inset (code block) background color to be more distinct from the background of the tab. Resolves #11784 --- Example from [/ui/layout](https://flutter-docs-prod--pr11897-feat-tab-wrapper-aofkivvh.web.app/ui/layout#common-layout-widgets): <img width="420" alt="Light mode version of a wrapped tab" src="https://github.com/user-attachments/assets/b5e8eedd-fd00-4ec3-8369-1992d97e3141" />
1 parent 498a6ac commit e0b15d0

File tree

6 files changed

+76
-25
lines changed

6 files changed

+76
-25
lines changed

src/_11ty/shortcodes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ function _setupTabs(eleventyConfig: UserConfig) {
3535
let currentTabWrapperId = 0;
3636
let currentTabPaneId = 0;
3737

38-
eleventyConfig.addPairedShortcode('tabs', function (content: string, saveKey: string) {
38+
eleventyConfig.addPairedShortcode('tabs', function (content: string, saveKey: string, wrapped: boolean = false) {
3939
const tabWrapperId = currentTabWrapperId++;
40-
let tabMarkup = `<div id="${tabWrapperId}" class="tabs-wrapper" ${saveKey ? `data-tab-save-key="${slugify(saveKey)}"` : ''}><ul class="nav-tabs" role="tablist">`;
40+
let tabMarkup = `<div id="${tabWrapperId}" class="tabs-wrapper${wrapped ? " wrapped" : ""}" ${saveKey ? `data-tab-save-key="${slugify(saveKey)}"` : ''}><ul class="nav-tabs" role="tablist">`;
4141

4242
// Only select child tab panes that don't already have a parent wrapper.
4343
const tabPanes = selectAll('.tab-pane[data-tab-wrapper-id="undefined"]', fromHtml(content));

src/_sass/base/_root.scss

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ body {
4242
--site-base-fgColor-alt: #6a6f71;
4343

4444
--site-raised-bgColor: #e9ecef;
45+
--site-raised-bgColor-translucent: #{color.change(#e9ecef, $alpha: 0.2)};
4546

4647
--site-primary-color: #{$base_primary_color};
4748
--site-accent-color: #833ef2;
@@ -56,8 +57,8 @@ body {
5657
--site-onPrimary-color-lighter: #{color.mix(#fff, #B8EAFE, 50%)};
5758
--site-onPrimary-color-lightest: #{color.mix(#fff, #B8EAFE, 75%)};
5859

59-
--site-inset-bgColor: #F8F9FA;
60-
--site-inset-bgColor-translucent: rgba(248, 249, 250, 0.8);
60+
--site-inset-bgColor: #F6F7F8;
61+
--site-inset-bgColor-translucent: rgba(237, 240, 242, 0.8);
6162
--site-inset-fgColor: var(--site-base-fgColor);
6263
--site-inset-borderColor: #DADCE0;
6364

@@ -109,6 +110,7 @@ body {
109110
--site-base-fgColor-alt: #a8acad;
110111

111112
--site-raised-bgColor: #1c1e27;
113+
--site-raised-bgColor-translucent: #{color.change(#1c1e27, $alpha: 0.4)};
112114

113115
--site-primary-color: #{$base_primary_color};
114116
--site-accent-color: #b07fff;

src/_sass/components/_content.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
min-width: 8rem;
1616
max-width: 960px;
1717
min-height: calc(100vh - var(--site-header-height) - var(--site-subheader-height));
18-
padding: 2rem;
18+
padding: 1.5rem;
19+
20+
@media (min-width: 576px) {
21+
padding: 2rem;
22+
}
1923

2024
img {
2125
object-fit: contain;

src/_sass/components/_sidebar.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
border-right: 0.1rem solid var(--site-outline-variant);
3333
padding: 0.75rem 0.75rem 2.25rem;
3434
position: sticky;
35+
height: calc(100vh - var(--site-header-height));
3536
top: var(--site-header-height);
3637
overscroll-behavior: auto;
3738
width: 16rem;

src/_sass/components/_tabs.scss

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@
88
}
99
}
1010

11+
$wrapper-padding: 0.375rem;
12+
$wrapper-radius: 0.125rem;
13+
1114
ul.nav-tabs {
1215
list-style: none;
1316

1417
display: flex;
1518
flex-direction: row;
1619
align-items: center;
1720

18-
padding: 0.375rem;
19-
border-radius: 0.125rem;
21+
padding: $wrapper-padding;
22+
border-radius: $wrapper-radius;
2023
background-color: var(--site-raised-bgColor);
2124
gap: 0.5rem;
2225
overflow-x: scroll;
@@ -57,3 +60,27 @@ ul.nav-tabs {
5760
}
5861
}
5962
}
63+
64+
.tabs-wrapper.wrapped {
65+
.nav-tabs {
66+
margin-bottom: 0;
67+
}
68+
69+
.tab-content {
70+
padding: 1rem 1rem 0;
71+
background-color: var(--site-raised-bgColor-translucent);
72+
73+
border: $wrapper-padding solid var(--site-raised-bgColor);
74+
border-top: none;
75+
border-bottom-left-radius: $wrapper-radius;
76+
border-bottom-right-radius: $wrapper-radius;
77+
78+
ul {
79+
padding-left: 1rem;
80+
}
81+
82+
.tab-pane > :first-child {
83+
margin-block-start: 0;
84+
}
85+
}
86+
}

src/content/ui/layout/index.md

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ displays the widget.
159159
<a id="material-apps" aria-hidden="true"></a>
160160
<a id="cupertino-apps" aria-hidden="true"></a>
161161

162-
{% tabs "app-type-tabs" %}
162+
{% tabs "app-type-tabs", true %}
163163

164164
{% tab "Standard apps" %}
165165

@@ -772,41 +772,58 @@ only Material apps can use the Material Components library.
772772
<a id="standard-widgets" aria-hidden="true"></a>
773773
<a id="materials-widgets" aria-hidden="true"></a>
774774

775-
{% tabs "os-archive-tabs" %}
775+
{% tabs "widget-types-tabs", true %}
776776

777777
{% tab "Standard widgets" %}
778778

779-
* [`Container`](#container): Adds padding, margins, borders,
779+
[`Container`](#container)
780+
: Adds padding, margins, borders,
780781
background color, or other decorations to a widget.
781-
* [`GridView`](#gridview): Lays widgets out as a scrollable grid.
782-
* [`ListView`](#listview): Lays widgets out as a scrollable list.
783-
* [`Stack`](#stack): Overlaps a widget on top of another.
782+
783+
[`GridView`](#gridview)
784+
: Lays widgets out as a scrollable grid.
785+
786+
[`ListView`](#listview)
787+
: Lays widgets out as a scrollable list.
788+
789+
[`Stack`](#stack)
790+
: Overlaps a widget on top of another.
784791

785792
{% endtab %}
786793

787794
{% tab "Material widgets" %}
788795

789-
* [`Scaffold`][]: Provides a structured layout framework
796+
[`Scaffold`][]
797+
: Provides a structured layout framework
790798
with slots for common Material Design app elements.
791-
* [`AppBar`][]: Creates a horizontal bar that's typically
799+
800+
[`AppBar`][]
801+
: Creates a horizontal bar that's typically
792802
displayed at the top of a screen.
793-
* [`Card`](#card): Organizes related info into a box with
803+
804+
[`Card`](#card)
805+
: Organizes related info into a box with
794806
rounded corners and a drop shadow.
795-
* [`ListTile`](#listtile): Organizes up to 3 lines of text,
807+
808+
[`ListTile`](#listtile)
809+
: Organizes up to 3 lines of text,
796810
and optional leading and trailing icons, into a row.
797811

798812
{% endtab %}
799813

800814
{% tab "Cupertino widgets" %}
801815

802-
* [`CupertinoPageScaffold`][]: Provides the basic layout
803-
structure for an iOS-style page.  
804-
* [`CupertinoNavigationBar`][]: Creates an iOS-style
805-
navigation bar at the top of the screen.  
806-
* [`CupertinoSegmentedControl`][]: Creates a segmented
807-
control for selecting.  
808-
* [`CupertinoTabBar`][] and [`CupertinoTabScaffold`][]:
809-
Creates the characteristic iOS bottom tab bar.
816+
[`CupertinoPageScaffold`][]
817+
: Provides the basic layout structure for an iOS-style page.
818+
819+
[`CupertinoNavigationBar`][]
820+
: Creates an iOS-style navigation bar at the top of the screen.
821+
822+
[`CupertinoSegmentedControl`][]
823+
: Creates a segmented control for selecting.
824+
825+
[`CupertinoTabBar`][] and [`CupertinoTabScaffold`][]
826+
: Creates the characteristic iOS bottom tab bar.
810827

811828
{% endtab %}
812829

0 commit comments

Comments
 (0)