Skip to content
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

Tab Component #4

Merged
merged 8 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
75 changes: 75 additions & 0 deletions src/tabs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Tabs

<table width="100%">
<tr>
<td align="left" width="70%">
<p>Built by the super talented team at <strong><a href="https://www.travelopia.com/work-with-us/">Travelopia</a></strong>.</p>
</td>
<td align="center" width="30%">
<img src="https://www.travelopia.com/wp-content/themes/travelopia/assets/svg/logo-travelopia-circle.svg" width="50" />
</td>
</tr>
</table>

## Sample Usage

Example:

```js
// Import the component as needed:
import '@travelopia/web-components/dist/tabs';
import '@travelopia/web-components/dist/tabs/style.css';

// TypeScript usage:
import { TPTabs } from '@travelopia/web-components';

...

const tabs: TPTabs = document.querySelector( 'tp-tabs' );
tabs.triggerTabSelection( '#overview' );
```

```html
<tp-tabs>
<tp-tabs-nav overflow="scroll">
<nav>
<tp-tab-nav active="true">
<a href="#tab-1">Tab 1</a>
</tp-tab-nav>
<tp-tab-nav>
<a href="#tab-2">Tab 2</a>
</tp-tab-nav>
<tp-tab-nav>
<a href="#tab-3">Tab 3</a>
</tp-tab-nav>
<tp-tab-nav>
<a href="#tab-4">Tab 4</a>
</tp-tab-nav>
</nav>
</tp-tabs-nav>
<tp-tab id="#tab-1" open="yes">
<p>Tab 1: Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</tp-tab>
<tp-tab id="#tab-2">
<p>Tab 2: Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</tp-tab>
<tp-tab id="#tab-3">
<p>Tab 3: Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</tp-tab>
<tp-tab id="#tab-4">
<p>Tab 4: Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</tp-tab>
</tp-tabs>
```

## Events

| Event | Notes |
|----------------|-----------------------------------------------------------------------------------------------------|
| tp-tab-clicked | When a tab is clicked. You can access the tab id using activeTabId.activeTabId e.g. value #overview |

## Methods

### `triggerTabSelection`

Move to the tab with the given id.
61 changes: 61 additions & 0 deletions src/tabs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Web Component: Tabs</title>

<link rel="stylesheet" href="../../dist/tabs/style.css" media="all">
<script type="module" src="../../dist/tabs/index.js"></script>

<style>
tp-tab-nav a {
text-decoration: none;
padding: 10px 20px;
border: 1px solid #f1f1f1;
display: inline-block;
color: #000;
}

tp-tab-nav[active] a {
background-color: #ccc;
}
</style>

</head>
<body>
<main>
<tp-tabs>
junaidbhura marked this conversation as resolved.
Show resolved Hide resolved
<tp-tabs-nav overflow="scroll">
<nav>
junaidbhura marked this conversation as resolved.
Show resolved Hide resolved
<tp-tab-nav active="true">
junaidbhura marked this conversation as resolved.
Show resolved Hide resolved
<a href="#tab-1">Tab 1</a>
</tp-tab-nav>
<tp-tab-nav>
<a href="#tab-2">Tab 2</a>
</tp-tab-nav>
<tp-tab-nav>
<a href="#tab-3">Tab 3</a>
</tp-tab-nav>
<tp-tab-nav>
<a href="#tab-4">Tab 4</a>
</tp-tab-nav>
</nav>
</tp-tabs-nav>
<tp-tab id="#tab-1" open="yes">
junaidbhura marked this conversation as resolved.
Show resolved Hide resolved
<p>Tab 1: Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</tp-tab>
<tp-tab id="#tab-2">
<p>Tab 2: Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</tp-tab>
<tp-tab id="#tab-3">
<p>Tab 3: Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</tp-tab>
<tp-tab id="#tab-4">
<p>Tab 4: Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</tp-tab>
</tp-tabs>
</main>
</body>
</html>
20 changes: 20 additions & 0 deletions src/tabs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Styles.
*/
import './style.scss';

/**
* Components.
*/
import { TPTabElement } from './tp-tab';
import { TPTabs } from './tp-tabs';
junaidbhura marked this conversation as resolved.
Show resolved Hide resolved
import { TPTabNavElement } from './tp-tab-nav';
import { TPTabsNavElement } from './tp-tabs-nav';

/**
* Register Components.
*/
customElements.define( 'tp-tabs', TPTabs );
customElements.define( 'tp-tab', TPTabElement );
junaidbhura marked this conversation as resolved.
Show resolved Hide resolved
customElements.define( 'tp-tab-nav', TPTabNavElement );
customElements.define( 'tp-tabs-nav', TPTabsNavElement );
7 changes: 7 additions & 0 deletions src/tabs/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
tp-tab {
display: none;

&[open="yes"] {
display: block;
}
}
5 changes: 5 additions & 0 deletions src/tabs/tp-tab-nav.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* TP Tab Nav Element.
*/
export class TPTabNavElement extends HTMLElement {
}
5 changes: 5 additions & 0 deletions src/tabs/tp-tab.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* TP Tab Element.
*/
export class TPTabElement extends HTMLElement {
}
5 changes: 5 additions & 0 deletions src/tabs/tp-tabs-nav.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* TP Tabs Nav Element.
*/
export class TPTabsNavElement extends HTMLElement {
}
Loading