Skip to content

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

Merged
merged 9 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/api/tab.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import EncapsulationPill from '@components/page/api/EncapsulationPill';
The tab component is a child component of [tabs](tabs.md). Each tab can contain a top level navigation stack for an app or a single view. An app can have many tabs, all with their own independent navigation.

:::note
Note: This component should only be used with vanilla JavaScript projects. For Angular, React, and Vue apps you do not need to use `ion-tab` to declare your tab components.
Angular, React, and Vue can only use this component when the `ion-tabs` component is configured for [basic usage](./tabs.md#basic-usage). When setting up tabs with routing, the `ion-tab` component cannot be used.

In JavaScript, this component can be used with the `ion-tabs` component configured for either [basic usage](./tabs.md#basic-usage) or [usage with router](./tabs.md#usage-with-router).
:::


Expand Down
10 changes: 6 additions & 4 deletions docs/api/tabs.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ Both `ion-tabs` and `ion-tab-bar` can be used as standalone elements. They don

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';

Expand Down
10 changes: 10 additions & 0 deletions static/usage/v8/tabs/basic/angular/example_component_css.md
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%;
}
```
71 changes: 71 additions & 0 deletions static/usage/v8/tabs/basic/angular/example_component_html.md
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>
```
22 changes: 22 additions & 0 deletions static/usage/v8/tabs/basic/angular/example_component_ts.md
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 });
}
}
```
94 changes: 94 additions & 0 deletions static/usage/v8/tabs/basic/demo.html
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>
42 changes: 42 additions & 0 deletions static/usage/v8/tabs/basic/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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
includeIonContent={false}
/>
82 changes: 82 additions & 0 deletions static/usage/v8/tabs/basic/javascript/index_html.md
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>
```
Loading