@lemonadejs/tabs 1.0.4 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -75
- package/dist/index.d.ts +25 -24
- package/dist/index.js +84 -78
- package/dist/style.css +61 -45
- package/package.json +20 -20
- package/src/index.html +15 -15
package/README.md
CHANGED
|
@@ -1,75 +1,80 @@
|
|
|
1
|
-
# LemonadeJS Tabs
|
|
2
|
-
|
|
3
|
-
[Official website and documentation is here](https://lemonadejs.net/components/tabs)
|
|
4
|
-
|
|
5
|
-
Compatible with Vanilla JavaScript, LemonadeJS, React, Vue or Angular.
|
|
6
|
-
|
|
7
|
-
The LemonadeJS JavaScript Tabs is a responsive and reactive component that creates selected tabs.
|
|
8
|
-
|
|
9
|
-
## Features
|
|
10
|
-
|
|
11
|
-
- Lightweight: The JavaScript Tabs is only about 2 KBytes;
|
|
12
|
-
- Integration: It can be used as a standalone library or integrated with any modern framework;
|
|
13
|
-
|
|
14
|
-
## Getting Started
|
|
15
|
-
|
|
16
|
-
You can install using NPM or using directly from a CDN.
|
|
17
|
-
|
|
18
|
-
### npm Installation
|
|
19
|
-
|
|
20
|
-
To install it in your project using npm, run the following command:
|
|
21
|
-
|
|
22
|
-
```bash
|
|
23
|
-
$ npm install @lemonadejs/tabs
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
### CDN
|
|
27
|
-
|
|
28
|
-
To use tabs via a CDN, include the following script tags in your HTML file:
|
|
29
|
-
|
|
30
|
-
```html
|
|
31
|
-
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/lemonadejs/dist/lemonade.min.js"></script>
|
|
32
|
-
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@lemonadejs/tabs/dist/index.min.js"></script>
|
|
33
|
-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@lemonadejs/tabs/dist/style.min.css" />
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
### Usage
|
|
37
|
-
|
|
38
|
-
Quick example with Lemonade
|
|
39
|
-
|
|
40
|
-
```javascript
|
|
41
|
-
import Tabs from "@lemonadejs/tabs";
|
|
42
|
-
import "@lemonadejs/tabs/dist/style.css"
|
|
43
|
-
|
|
44
|
-
export default function Component() {
|
|
45
|
-
const self = this;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
You can
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
The
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
1
|
+
# LemonadeJS Tabs
|
|
2
|
+
|
|
3
|
+
[Official website and documentation is here](https://lemonadejs.net/components/tabs)
|
|
4
|
+
|
|
5
|
+
Compatible with Vanilla JavaScript, LemonadeJS, React, Vue or Angular.
|
|
6
|
+
|
|
7
|
+
The LemonadeJS JavaScript Tabs is a responsive and reactive component that creates selected tabs.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- Lightweight: The JavaScript Tabs is only about 2 KBytes;
|
|
12
|
+
- Integration: It can be used as a standalone library or integrated with any modern framework;
|
|
13
|
+
|
|
14
|
+
## Getting Started
|
|
15
|
+
|
|
16
|
+
You can install using NPM or using directly from a CDN.
|
|
17
|
+
|
|
18
|
+
### npm Installation
|
|
19
|
+
|
|
20
|
+
To install it in your project using npm, run the following command:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
$ npm install @lemonadejs/tabs
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### CDN
|
|
27
|
+
|
|
28
|
+
To use tabs via a CDN, include the following script tags in your HTML file:
|
|
29
|
+
|
|
30
|
+
```html
|
|
31
|
+
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/lemonadejs/dist/lemonade.min.js"></script>
|
|
32
|
+
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@lemonadejs/tabs/dist/index.min.js"></script>
|
|
33
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@lemonadejs/tabs/dist/style.min.css" />
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Usage
|
|
37
|
+
|
|
38
|
+
Quick example with Lemonade
|
|
39
|
+
|
|
40
|
+
```javascript
|
|
41
|
+
import Tabs from "@lemonadejs/tabs";
|
|
42
|
+
import "@lemonadejs/tabs/dist/style.css"
|
|
43
|
+
|
|
44
|
+
export default function Component() {
|
|
45
|
+
const self = this;
|
|
46
|
+
|
|
47
|
+
self.open = (index) => {
|
|
48
|
+
console.log(index)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return `<Tabs :onopen="self.open">
|
|
52
|
+
<div title="Tab 1">Content of the first tab</div>
|
|
53
|
+
<div title="Tab 2">Content of the second tab</div>
|
|
54
|
+
</Tabs>`;
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
[You can find more examples here in the official documentation.](https://lemonadejs.net/components/tabs)
|
|
59
|
+
|
|
60
|
+
### Configuration
|
|
61
|
+
|
|
62
|
+
You can configure things such as tabs titles, tabs contents and selected tab.
|
|
63
|
+
|
|
64
|
+
#### Tabs Properties
|
|
65
|
+
|
|
66
|
+
| Property | Type | Description |
|
|
67
|
+
|-----------|----------|----------------------------------------------------------------------------------------------------------------------|
|
|
68
|
+
| data? | array | An optional alternative method to provide the title and content that will serve as the basis for rendering the tabs. |
|
|
69
|
+
| selected? | number | The index of the initially selected tab. Starts from 0. |
|
|
70
|
+
| position? | string | The position of the tabs bar within the parent element. Use 'center' to center-align the tabs. |
|
|
71
|
+
| onopen? | function | When a new tabs is opened. |
|
|
72
|
+
|
|
73
|
+
## License
|
|
74
|
+
|
|
75
|
+
The [LemonadeJS](https://lemonadejs.net) Tabs is released under the MIT.
|
|
76
|
+
|
|
77
|
+
## Other Tools
|
|
78
|
+
|
|
79
|
+
- [jSuites](https://jsuites.net/v4/)
|
|
80
|
+
- [Jspreadsheet Data Grid](https://jspreadsheet.com)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Official Type definitions for LemonadeJS plugins
|
|
3
|
-
* https://lemonadejs.net
|
|
4
|
-
* Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
interface Tabs {
|
|
8
|
-
(): any
|
|
9
|
-
[key: string]: any
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
interface options {
|
|
13
|
-
data?: object[];
|
|
14
|
-
selected?: number;
|
|
15
|
-
position?: number;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Official Type definitions for LemonadeJS plugins
|
|
3
|
+
* https://lemonadejs.net
|
|
4
|
+
* Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
interface Tabs {
|
|
8
|
+
(): any
|
|
9
|
+
[key: string]: any
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface options {
|
|
13
|
+
data?: object[];
|
|
14
|
+
selected?: number;
|
|
15
|
+
position?: number;
|
|
16
|
+
onopen?: (index: number) => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface instance {
|
|
20
|
+
data: object[];
|
|
21
|
+
selected: number;
|
|
22
|
+
position: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export declare function Tabs(el: HTMLElement, options?: options): instance;
|
package/dist/index.js
CHANGED
|
@@ -1,79 +1,85 @@
|
|
|
1
|
-
if (!lemonade && typeof (require) === 'function') {
|
|
2
|
-
var lemonade = require('lemonadejs');
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
; (function (global, factory) {
|
|
6
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
7
|
-
typeof define === 'function' && define.amd ? define(factory) :
|
|
8
|
-
global.Tabs = factory();
|
|
9
|
-
}(this, (function () {
|
|
10
|
-
|
|
11
|
-
const Tabs = function (html) {
|
|
12
|
-
let self = this
|
|
13
|
-
|
|
14
|
-
let content = html;
|
|
15
|
-
|
|
16
|
-
if (self.data) {
|
|
17
|
-
for (let i = 0; i < self.data.length; i++) {
|
|
18
|
-
content += `<div title="${self.data[i].title}">${self.data[i].content}</div>`;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
self.tabs = [];
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
self.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
1
|
+
if (!lemonade && typeof (require) === 'function') {
|
|
2
|
+
var lemonade = require('lemonadejs');
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
; (function (global, factory) {
|
|
6
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
7
|
+
typeof define === 'function' && define.amd ? define(factory) :
|
|
8
|
+
global.Tabs = factory();
|
|
9
|
+
}(this, (function () {
|
|
10
|
+
|
|
11
|
+
const Tabs = function (html) {
|
|
12
|
+
let self = this
|
|
13
|
+
|
|
14
|
+
let content = html;
|
|
15
|
+
|
|
16
|
+
if (self.data) {
|
|
17
|
+
for (let i = 0; i < self.data.length; i++) {
|
|
18
|
+
content += `<div title="${self.data[i].title}">${self.data[i].content}</div>`;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
self.tabs = [];
|
|
23
|
+
|
|
24
|
+
const select = function (index) {
|
|
25
|
+
index = parseInt(index);
|
|
26
|
+
|
|
27
|
+
for (let i = 0; i < self.content.children.length; i++) {
|
|
28
|
+
self.headers.children[i].classList.remove('selected');
|
|
29
|
+
self.content.children[i].classList.remove('selected');
|
|
30
|
+
}
|
|
31
|
+
self.headers.children[index].classList.add('selected');
|
|
32
|
+
self.content.children[index].classList.add('selected');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
self.onload = function () {
|
|
36
|
+
for (let i = 0; i < self.content.children.length; i++) {
|
|
37
|
+
self.tabs.push({ title: self.content.children[i].title });
|
|
38
|
+
}
|
|
39
|
+
self.refresh('tabs');
|
|
40
|
+
|
|
41
|
+
let index = 0;
|
|
42
|
+
if (! isNaN(parseInt(self.selected))) {
|
|
43
|
+
index = parseInt(self.selected);
|
|
44
|
+
}
|
|
45
|
+
select(index);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
self.onchange = function (property) {
|
|
49
|
+
if (property === 'selected') {
|
|
50
|
+
select(self.selected);
|
|
51
|
+
|
|
52
|
+
if (typeof(self.onopen) === 'function') {
|
|
53
|
+
self.onopen.call(self, self.selected);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
self.click = function (e) {
|
|
59
|
+
if (e.target.tagName === 'LI') {
|
|
60
|
+
self.selected = Array.prototype.indexOf.call(e.target.parentNode.children, e.target);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return `<div class="lm-tabs" :position="self.position" data-round="{{self.round}}">
|
|
65
|
+
<ul :ref="self.headers" :loop="self.tabs" :selected="self.selected" onclick="self.click"><li class="lm-tab-list-item">{{self.title}}</li></ul>
|
|
66
|
+
<div :ref="self.content" class="lm-tabs-content">${content}</div>
|
|
67
|
+
</div>`
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
lemonade.setComponents({ Tabs: Tabs });
|
|
71
|
+
|
|
72
|
+
return function (root, options) {
|
|
73
|
+
if (typeof (root) === 'object') {
|
|
74
|
+
// Get HTML inside the wrapper element then empty it
|
|
75
|
+
const template = root.innerHTML
|
|
76
|
+
root.innerHTML = ''
|
|
77
|
+
|
|
78
|
+
// Send Template as a parameter for the Lemonade component
|
|
79
|
+
lemonade.render(Tabs, root, options, template)
|
|
80
|
+
return options;
|
|
81
|
+
} else {
|
|
82
|
+
return Tabs.call(this, root)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
79
85
|
})));
|
package/dist/style.css
CHANGED
|
@@ -1,46 +1,62 @@
|
|
|
1
|
-
.lm-tabs {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
.lm-tabs > ul > li:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
1
|
+
.lm-tabs .lm-tabs-content > div {
|
|
2
|
+
padding: 10px;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.lm-tabs > ul {
|
|
6
|
+
list-style-type: none;
|
|
7
|
+
display: flex;
|
|
8
|
+
margin: 0;
|
|
9
|
+
padding: 0;
|
|
10
|
+
width: fit-content;
|
|
11
|
+
align-self: center;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.lm-tabs > ul > li {
|
|
15
|
+
cursor: pointer;
|
|
16
|
+
user-select: none;
|
|
17
|
+
padding: 4px 12px 4px 12px;
|
|
18
|
+
border: 1px solid #ccc;
|
|
19
|
+
background-position: center;
|
|
20
|
+
transition: background 0.8s;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.lm-tabs > ul > li.selected {
|
|
24
|
+
background-color: #eee;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.lm-tabs[data-round="true"] > ul > li:first-child {
|
|
28
|
+
border-top-left-radius: 3px;
|
|
29
|
+
border-bottom-left-radius: 3px;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.lm-tabs[data-round="true"] > ul > li:last-child {
|
|
33
|
+
border-top-right-radius: 3px;
|
|
34
|
+
border-bottom-right-radius: 3px;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
.lm-tabs > ul > li:not(:first-child) {
|
|
39
|
+
border-left: 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.lm-tabs > ul > li:hover {
|
|
43
|
+
background: #eee radial-gradient(circle, transparent 1%, #eee 1%) center/15000%;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.lm-tabs > ul > li:active {
|
|
47
|
+
background-color: #ddd;
|
|
48
|
+
background-size: 100%;
|
|
49
|
+
transition: background 0s;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.lm-tabs .lm-tabs-content > div {
|
|
53
|
+
display: none;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.lm-tabs .lm-tabs-content > div.selected {
|
|
57
|
+
display: block;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.lm-tabs[position="center"] > ul {
|
|
61
|
+
margin: 0 auto;
|
|
46
62
|
}
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@lemonadejs/tabs",
|
|
3
|
-
"title": "JavaScript Tabs",
|
|
4
|
-
"description": "LemonadeJS tabs is a JavaScript component to create tabs.",
|
|
5
|
-
"author": {
|
|
6
|
-
"name": "Contact <contact@lemonadejs.net>",
|
|
7
|
-
"url": "https://lemonadejs.net"
|
|
8
|
-
},
|
|
9
|
-
"keywords": [
|
|
10
|
-
"javascript tabs",
|
|
11
|
-
"lemonadejs tabs",
|
|
12
|
-
"js tabs",
|
|
13
|
-
"tabs js"
|
|
14
|
-
],
|
|
15
|
-
"dependencies": {
|
|
16
|
-
"lemonadejs": "^3.
|
|
17
|
-
},
|
|
18
|
-
"main": "dist/index.js",
|
|
19
|
-
"version": "1.
|
|
20
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@lemonadejs/tabs",
|
|
3
|
+
"title": "JavaScript Tabs",
|
|
4
|
+
"description": "LemonadeJS tabs is a JavaScript component to create tabs.",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Contact <contact@lemonadejs.net>",
|
|
7
|
+
"url": "https://lemonadejs.net"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"javascript tabs",
|
|
11
|
+
"lemonadejs tabs",
|
|
12
|
+
"js tabs",
|
|
13
|
+
"tabs js"
|
|
14
|
+
],
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"lemonadejs": "^3.4.0"
|
|
17
|
+
},
|
|
18
|
+
"main": "dist/index.js",
|
|
19
|
+
"version": "1.1.2"
|
|
20
|
+
}
|
package/src/index.html
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
<script src="https://cdn.jsdelivr.net/npm/lemonadejs@3.3.1/dist/lemonade.min.js"></script>
|
|
2
|
-
<script src="../dist/index.js"></script>
|
|
3
|
-
<link rel="stylesheet" href="../dist/style.css" />
|
|
4
|
-
|
|
5
|
-
<div id="tabs">
|
|
6
|
-
<div title="Tab 1">Content of the first tab</div>
|
|
7
|
-
<div title="Tab 2">Content of the second tab</div>
|
|
8
|
-
</div>
|
|
9
|
-
|
|
10
|
-
<script>
|
|
11
|
-
const root = document.getElementById("tabs");
|
|
12
|
-
|
|
13
|
-
Tabs(root, {
|
|
14
|
-
selected: 0
|
|
15
|
-
});
|
|
1
|
+
<script src="https://cdn.jsdelivr.net/npm/lemonadejs@3.3.1/dist/lemonade.min.js"></script>
|
|
2
|
+
<script src="../dist/index.js"></script>
|
|
3
|
+
<link rel="stylesheet" href="../dist/style.css" />
|
|
4
|
+
|
|
5
|
+
<div id="tabs">
|
|
6
|
+
<div title="Tab 1">Content of the first tab</div>
|
|
7
|
+
<div title="Tab 2">Content of the second tab</div>
|
|
8
|
+
</div>
|
|
9
|
+
|
|
10
|
+
<script>
|
|
11
|
+
const root = document.getElementById("tabs");
|
|
12
|
+
|
|
13
|
+
Tabs(root, {
|
|
14
|
+
selected: 0
|
|
15
|
+
});
|
|
16
16
|
</script>
|