-
Notifications
You must be signed in to change notification settings - Fork 3.2k
docs(tabs): add playground for basic usage #3824
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
Changes from 3 commits
1d63cef
c203487
4781f9d
7d41c81
3fe3f93
ce6783c
bd732de
109e036
cfb3567
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,17 +24,23 @@ The `ion-tabs` component does not have any styling and works as a router outlet | |
|
||
Both `ion-tabs` and `ion-tab-bar` can be used as standalone elements. They don’t depend on each other to work, but they are usually used together in order to implement a tab-based navigation that behaves like a native app. | ||
|
||
:::warning | ||
Using `IonTabs` within React requires the `IonTabBar` component as a direct child of `IonTabs`. | ||
::: | ||
|
||
|
||
The `ion-tab-bar` needs a slot defined in order to be projected to the right place in an `ion-tabs` component. | ||
|
||
:::note Framework Support | ||
## Basic Usage | ||
|
||
Using `ion-tabs` within Angular, React or Vue requires the use of the `ion-router-outlet` or `ion-nav` components. | ||
Tabs can be used to display different content without the need to change the URL. This is useful when the tabs are not used for navigation, but rather to display different content. | ||
|
||
::: | ||
import Basic from '@site/static/usage/v8/tabs/basic/index.md'; | ||
|
||
<Basic /> | ||
|
||
## Usage with Router | ||
|
||
Tabs can be used with the Ionic router to implement tab-based navigation. The tab bar and active tab will automatically resolve based on the url. This is the most common pattern for tabs navigation. | ||
Tabs can be used with the Ionic router to implement tab-based navigation. The tab bar and active tab will automatically resolve based on the URL. This is the most common pattern for tabs navigation. | ||
|
||
import Router from '@site/static/usage/v8/tabs/router/index.md'; | ||
brandyscarney marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
```css | ||
/* This style is for demonstration purposes only. */ | ||
/* It's not required for the tabs to function. */ | ||
.example-content { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
height: 100%; | ||
} | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
```html | ||
<ion-tabs> | ||
<ion-tab tab="home"> | ||
<div id="home-page"> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>Listen now</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content> | ||
<div class="example-content">Listen now content</div> | ||
</ion-content> | ||
</div> | ||
</ion-tab> | ||
<ion-tab tab="radio"> | ||
<div id="radio-page"> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>Radio</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content> | ||
<div class="example-content">Radio content</div> | ||
</ion-content> | ||
</div> | ||
</ion-tab> | ||
<ion-tab tab="library"> | ||
<div id="library-page"> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>Library</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content> | ||
<div class="example-content">Library content</div> | ||
</ion-content> | ||
</div> | ||
</ion-tab> | ||
<ion-tab tab="search"> | ||
<div id="search-page"> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>Search</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content> | ||
<div class="example-content">Search content</div> | ||
</ion-content> | ||
</div> | ||
</ion-tab> | ||
|
||
<ion-tab-bar slot="bottom"> | ||
<ion-tab-button tab="home"> | ||
<ion-icon name="play-circle"></ion-icon> | ||
Listen Now | ||
</ion-tab-button> | ||
<ion-tab-button tab="radio"> | ||
<ion-icon name="radio"></ion-icon> | ||
Radio | ||
</ion-tab-button> | ||
<ion-tab-button tab="library"> | ||
<ion-icon name="library"></ion-icon> | ||
Library | ||
</ion-tab-button> | ||
<ion-tab-button tab="search"> | ||
<ion-icon name="search"></ion-icon> | ||
Search | ||
</ion-tab-button> | ||
</ion-tab-bar> | ||
</ion-tabs> | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
```ts | ||
import { Component } from '@angular/core'; | ||
|
||
import { addIcons } from 'ionicons'; | ||
import { library, playCircle, radio, search } from 'ionicons/icons'; | ||
|
||
@Component({ | ||
selector: 'app-example', | ||
templateUrl: 'example.component.html', | ||
styleUrls: ['example.component.css'], | ||
}) | ||
export class ExampleComponent { | ||
constructor() { | ||
/** | ||
* Any icons you want to use in your application | ||
* can be registered in app.component.ts and then | ||
* referenced by name anywhere in your application. | ||
*/ | ||
addIcons({ library, playCircle, radio, search }); | ||
} | ||
} | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Tabs</title> | ||
<link rel="stylesheet" href="../../common.css" /> | ||
<script src="../../common.js"></script> | ||
<script type="module" src="https://cdn.jsdelivr.net/npm/@ionic/core@8/dist/ionic/ionic.esm.js"></script> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@ionic/core@8/css/ionic.bundle.css" /> | ||
<style> | ||
.example-content { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
height: 100%; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<ion-app> | ||
<ion-tabs> | ||
<ion-tab tab="home"> | ||
<div id="home-page"> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>Listen now</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content> | ||
<div class="example-content">Listen now content</div> | ||
</ion-content> | ||
</div> | ||
</ion-tab> | ||
<ion-tab tab="radio"> | ||
<div id="radio-page"> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>Radio</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content> | ||
<div class="example-content">Radio content</div> | ||
</ion-content> | ||
</div> | ||
</ion-tab> | ||
<ion-tab tab="library"> | ||
<div id="library-page"> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>Library</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content> | ||
<div class="example-content">Library content</div> | ||
</ion-content> | ||
</div> | ||
</ion-tab> | ||
<ion-tab tab="search"> | ||
<div id="search-page"> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>Search</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content> | ||
<div class="example-content">Search content</div> | ||
</ion-content> | ||
</div> | ||
</ion-tab> | ||
|
||
<ion-tab-bar slot="bottom"> | ||
<ion-tab-button tab="home"> | ||
<ion-icon name="play-circle"></ion-icon> | ||
Listen Now | ||
</ion-tab-button> | ||
<ion-tab-button tab="radio"> | ||
<ion-icon name="radio"></ion-icon> | ||
Radio | ||
</ion-tab-button> | ||
<ion-tab-button tab="library"> | ||
<ion-icon name="library"></ion-icon> | ||
Library | ||
</ion-tab-button> | ||
<ion-tab-button tab="search"> | ||
<ion-icon name="search"></ion-icon> | ||
Search | ||
</ion-tab-button> | ||
</ion-tab-bar> | ||
</ion-tabs> | ||
</ion-app> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import Playground from '@site/src/components/global/Playground'; | ||
|
||
import javascript_index_html from './javascript/index_html.md'; | ||
import javascript_index_ts from './javascript/index_ts.md'; | ||
|
||
import react_main_tsx from './react/main_tsx.md'; | ||
import react_main_css from './react/main_css.md'; | ||
|
||
import vue from './vue.md'; | ||
|
||
import angular_example_component_html from './angular/example_component_html.md'; | ||
import angular_example_component_ts from './angular/example_component_ts.md'; | ||
import angular_example_component_css from './angular/example_component_css.md'; | ||
|
||
<Playground | ||
version="8" | ||
code={{ | ||
javascript: { | ||
files: { | ||
'index.html': javascript_index_html, | ||
'index.ts': javascript_index_ts, | ||
}, | ||
}, | ||
react: { | ||
files: { | ||
'src/main.tsx': react_main_tsx, | ||
'src/main.css': react_main_css, | ||
}, | ||
}, | ||
vue, | ||
angular: { | ||
files: { | ||
'src/app/example.component.html': angular_example_component_html, | ||
'src/app/example.component.ts': angular_example_component_ts, | ||
'src/app/example.component.css': angular_example_component_css, | ||
}, | ||
}, | ||
}} | ||
src="usage/v8/tabs/basic/demo.html" | ||
devicePreview | ||
/> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
```html | ||
<ion-tabs> | ||
<ion-tab tab="home"> | ||
<div id="home-page"> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>Listen now</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content> | ||
<div class="example-content">Listen now content</div> | ||
</ion-content> | ||
</div> | ||
</ion-tab> | ||
<ion-tab tab="radio"> | ||
<div id="radio-page"> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>Radio</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content> | ||
<div class="example-content">Radio content</div> | ||
</ion-content> | ||
</div> | ||
</ion-tab> | ||
<ion-tab tab="library"> | ||
<div id="library-page"> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>Library</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content> | ||
<div class="example-content">Library content</div> | ||
</ion-content> | ||
</div> | ||
</ion-tab> | ||
<ion-tab tab="search"> | ||
<div id="search-page"> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-title>Search</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content> | ||
<div class="example-content">Search content</div> | ||
</ion-content> | ||
</div> | ||
</ion-tab> | ||
|
||
<ion-tab-bar slot="bottom"> | ||
<ion-tab-button tab="home"> | ||
<ion-icon name="play-circle"></ion-icon> | ||
Listen Now | ||
</ion-tab-button> | ||
<ion-tab-button tab="radio"> | ||
<ion-icon name="radio"></ion-icon> | ||
Radio | ||
</ion-tab-button> | ||
<ion-tab-button tab="library"> | ||
<ion-icon name="library"></ion-icon> | ||
Library | ||
</ion-tab-button> | ||
<ion-tab-button tab="search"> | ||
<ion-icon name="search"></ion-icon> | ||
Search | ||
</ion-tab-button> | ||
</ion-tab-bar> | ||
</ion-tabs> | ||
|
||
<style> | ||
/* This style is for demonstration purposes only. */ | ||
/* It's not required for the tabs to function. */ | ||
.example-content { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
height: 100%; | ||
} | ||
</style> | ||
``` |
Uh oh!
There was an error while loading. Please reload this page.