Skip to content

Commit a589deb

Browse files
committed
refactor(tab-bar): add expand prop for ionic theme
1 parent bde1d09 commit a589deb

File tree

7 files changed

+97
-4
lines changed

7 files changed

+97
-4
lines changed

core/api.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2177,6 +2177,7 @@ ion-tab,method,setActive,setActive() => Promise<void>
21772177

21782178
ion-tab-bar,shadow
21792179
ion-tab-bar,prop,color,"danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string & Record<never, never> | undefined,undefined,false,true
2180+
ion-tab-bar,prop,expand,"compact" | "full",'full',false,false
21802181
ion-tab-bar,prop,mode,"ios" | "md",undefined,false,false
21812182
ion-tab-bar,prop,selectedTab,string | undefined,undefined,false,false
21822183
ion-tab-bar,prop,theme,"ios" | "md" | "ionic",undefined,false,false

core/src/components.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3411,6 +3411,10 @@ export namespace Components {
34113411
* The color to use from your application's color palette. Default options are: `"primary"`, `"secondary"`, `"tertiary"`, `"success"`, `"warning"`, `"danger"`, `"light"`, `"medium"`, and `"dark"`. For more information on colors, see [theming](/docs/theming/basics).
34123412
*/
34133413
"color"?: Color;
3414+
/**
3415+
* Set to `"compact"` to display a width based on the items inside the tab bar. This value will only work for the `ionic` theme. Set to `"full"` to display a full width tab bar. Defaults to `"full"`.
3416+
*/
3417+
"expand": 'compact' | 'full';
34143418
/**
34153419
* The mode determines the platform behaviors of the component.
34163420
*/
@@ -8765,6 +8769,10 @@ declare namespace LocalJSX {
87658769
* The color to use from your application's color palette. Default options are: `"primary"`, `"secondary"`, `"tertiary"`, `"success"`, `"warning"`, `"danger"`, `"light"`, `"medium"`, and `"dark"`. For more information on colors, see [theming](/docs/theming/basics).
87668770
*/
87678771
"color"?: Color;
8772+
/**
8773+
* Set to `"compact"` to display a width based on the items inside the tab bar. This value will only work for the `ionic` theme. Set to `"full"` to display a full width tab bar. Defaults to `"full"`.
8774+
*/
8775+
"expand"?: 'compact' | 'full';
87688776
/**
87698777
* The mode determines the platform behaviors of the component.
87708778
*/

core/src/components/segment/test/basic/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
</ion-toolbar>
3737

3838
<ion-toolbar>
39-
<ion-segment value="2" scrollable="true">
39+
<ion-segment value="2" scrollable="true" mode="md">
4040
<ion-segment-button value="1">
4141
<ion-label>Button 1</ion-label>
4242
</ion-segment-button>

core/src/components/tab-bar/tab-bar.common.scss

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
align-items: center;
1010
justify-content: center;
1111

12-
width: auto;
13-
1412
/* stylelint-disable */
1513
padding-right: var(--ion-safe-area-right);
1614
padding-bottom: var(--ion-safe-area-bottom, 0);
@@ -24,7 +22,6 @@
2422

2523
text-align: center;
2624

27-
contain: strict;
2825
user-select: none;
2926

3027
/* stylelint-disable-next-line declaration-no-important */
@@ -52,3 +49,11 @@
5249
/* stylelint-disable-next-line declaration-no-important */
5350
display: none !important;
5451
}
52+
53+
// Expand: Full
54+
// --------------------------------------------------
55+
:host(.tab-bar-full) {
56+
width: auto;
57+
58+
contain: strict;
59+
}

core/src/components/tab-bar/tab-bar.ionic.scss

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,25 @@
3232
// TODO(ROU-10853): replace this value with a layer token
3333
z-index: 10;
3434
}
35+
36+
// Expand: Compact
37+
// --------------------------------------------------
38+
:host(.tab-bar-compact) {
39+
position: absolute;
40+
41+
align-self: center;
42+
43+
width: fit-content;
44+
45+
box-shadow: #{globals.$ionic-elevation-200};
46+
47+
contain: content;
48+
}
49+
50+
:host([slot="top"].tab-bar-expand-compact) {
51+
top: globals.$ionic-space-400;
52+
}
53+
54+
:host([slot="bottom"].tab-bar-expand-compact) {
55+
bottom: globals.$ionic-space-400;
56+
}

core/src/components/tab-bar/tab-bar.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ export class TabBar implements ComponentInterface {
4949
}
5050
}
5151

52+
/**
53+
* Set to `"compact"` to display a width based on the items
54+
* inside the tab bar. This value will only work for the
55+
* `ionic` theme.
56+
*
57+
* Set to `"full"` to display a full width tab bar.
58+
*
59+
* Defaults to `"full"`.
60+
*/
61+
@Prop() expand: 'compact' | 'full' = 'full';
62+
5263
/**
5364
* If `true`, the tab bar will be translucent.
5465
* Only applies when the theme is `"ios"` and the device supports
@@ -109,6 +120,7 @@ export class TabBar implements ComponentInterface {
109120
[theme]: true,
110121
'tab-bar-translucent': translucent,
111122
'tab-bar-hidden': shouldHide,
123+
[`tab-bar-${this.expand}`]: true,
112124
})}
113125
>
114126
<slot></slot>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!DOCTYPE html>
2+
<html lang="en" dir="ltr">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>Tab Bar - Preview</title>
6+
<meta
7+
name="viewport"
8+
content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"
9+
/>
10+
<script src="../../../../../scripts/testing/scripts.js"></script>
11+
<script nomodule src="../../../../../dist/ionic/ionic.js"></script>
12+
<script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script>
13+
<link rel="stylesheet" href="../../../../../css/ionic.bundle.css" />
14+
<link rel="stylesheet" href="../../../../../scripts/testing/styles.css" />
15+
</head>
16+
17+
<body>
18+
<ion-app>
19+
<ion-content>
20+
<ion-tab-bar selected-tab="1" expand="compact">
21+
<ion-tab-button tab="1">
22+
<ion-icon name="triangle-outline"></ion-icon>
23+
<ion-label>Label</ion-label>
24+
</ion-tab-button>
25+
26+
<ion-tab-button tab="2">
27+
<ion-icon name="triangle-outline"></ion-icon>
28+
<ion-label>Label</ion-label>
29+
</ion-tab-button>
30+
31+
<ion-tab-button tab="3" class="ion-focused">
32+
<ion-icon name="triangle-outline"></ion-icon>
33+
<ion-label>Label</ion-label>
34+
</ion-tab-button>
35+
</ion-tab-bar>
36+
</ion-content>
37+
</ion-app>
38+
39+
<style>
40+
ion-content {
41+
--background: #f6f6f6;
42+
}
43+
</style>
44+
</body>
45+
</html>

0 commit comments

Comments
 (0)