@lemonadejs/tabs 2.0.0 → 2.0.4

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 CHANGED
@@ -1,80 +1,88 @@
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)
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 lemonade from 'lemonadejs'
42
+ import Tabs from '@lemonadejs/tabs';
43
+ import '@lemonadejs/tabs/dist/style.css';
44
+
45
+ export default function App() {
46
+ const self = this;
47
+
48
+ return `<div>
49
+ <Tabs :selected="0">
50
+ <div title="Tab 1">Content of the first tab</div>
51
+ <div title="Tab 2">Content of the second tab</div>
52
+ </Tabs>
53
+ </div>`
54
+ }
55
+ ```
56
+
57
+ [You can find more examples here in the official documentation.](https://lemonadejs.net/components/tabs)
58
+
59
+ ### Configuration
60
+
61
+ You can configure things such as tabs titles, tabs contents and selected tab.
62
+
63
+ #### Settings
64
+
65
+ | Property | Type | Description |
66
+ | -------- | ---- | ----------- |
67
+ | selected? | number | The index of the initially selected tab. Starts from 0. |
68
+ | position? | string | The position of the tabs bar within the parent element. Use 'center' to center-align the tabs. |
69
+ | data? | tabItem[] | An optional alternative method to provide the title and content that will serve as the basis for rendering the tabs. See more about the `tabItem` object in the Tab Item section below. |
70
+ | round? | boolean | Dictates whether the tab style will feature rounded corners. |
71
+ | onopen? | function | When a new tabs is opened. |
72
+
73
+ #### Tab Item
74
+
75
+ | Property | Description |
76
+ | -------- | ----------- |
77
+ | title | The title of the tab, serving as the label displayed on the tab options. |
78
+ | content | The HTML content intended for this specific tab. |
79
+
80
+
81
+ ## License
82
+
83
+ The [LemonadeJS](https://lemonadejs.net) Tabs is released under the MIT.
84
+
85
+ ## Other Tools
86
+
87
+ - [jSuites](https://jsuites.net)
88
+ - [Jspreadsheet Data Grid](https://jspreadsheet.com)
package/dist/index.d.ts CHANGED
@@ -1,25 +1,42 @@
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;
1
+ /**
2
+ * Official Type definitions for LemonadeJS plugins
3
+ * https://lemonadejs.net
4
+ * Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
+ */
6
+ declare function Tabs(el: HTMLElement, options?: Tabs.Options): Tabs.Instance;
7
+
8
+ declare namespace Tabs {
9
+
10
+ interface Items {
11
+ title: string,
12
+ content: string,
13
+ }
14
+
15
+ interface Options {
16
+ /** Programmatically content */
17
+ data?: Items[];
18
+ /** Selected tab */
19
+ selected?: number;
20
+ /** Tabs position */
21
+ position?: 'center' | undefined;
22
+ /** Activate round borders */
23
+ round?: boolean;
24
+ /** On open event */
25
+ onopen?: (index: number) => void;
26
+ }
27
+
28
+ interface Instance {
29
+ /** Programmatically content */
30
+ data?: Items[];
31
+ /** Selected tab */
32
+ selected: number;
33
+ /** Tabs position */
34
+ position?: 'center' | undefined;
35
+ /** Activate round borders */
36
+ round?: boolean;
37
+ /** On open event */
38
+ onopen?: (index: number) => void;
39
+ }
40
+ }
41
+
42
+ export default Tabs;
package/dist/index.js CHANGED
@@ -1,85 +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
- 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" data-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
- }
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" data-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
+ }
85
85
  })));
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Official Type definitions for the LemonadeJS plugins
3
+ * https://lemonadejs.net
4
+ * Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
+ */
6
+ import Component from './index';
7
+
8
+ interface Tabs {
9
+ (): any
10
+ [key: string]: any
11
+ }
12
+
13
+ declare function Tabs<Tabs>(props: Component.Options): any;
14
+
15
+ export default Tabs;
package/dist/react.js ADDED
@@ -0,0 +1,37 @@
1
+ import React, { useRef, useEffect } from "react";
2
+ import { renderToStaticMarkup } from 'react-dom/server';
3
+ import Component from './index';
4
+
5
+
6
+ export default React.forwardRef((props, mainReference) => {
7
+ // Dom element
8
+ const Ref = useRef(null);
9
+
10
+ const template = renderToStaticMarkup(props.children)
11
+
12
+ // Get the properties for the spreadsheet
13
+ let options = { ...props };
14
+
15
+ useEffect(() => {
16
+ if (!Ref.current.innerHTML) {
17
+ mainReference.current = Component(Ref.current, options, template);
18
+ }
19
+ }, []);
20
+
21
+ useEffect(() => {
22
+ for (let key in props) {
23
+ if (props.hasOwnProperty(key) && mainReference.current.hasOwnProperty(key)) {
24
+ if (props[key] !== mainReference.current[key]) {
25
+ mainReference.current[key] = props[key];
26
+ }
27
+ }
28
+ }
29
+ }, [props])
30
+
31
+ let prop = {
32
+ ref: Ref,
33
+ style: { height: '100%', width: '100%' }
34
+ };
35
+
36
+ return React.createElement("div", prop);
37
+ })
package/dist/style.css CHANGED
@@ -1,62 +1,61 @@
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[data-position="center"] > ul {
61
- margin: 0 auto;
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: 100%;
11
+ }
12
+
13
+ .lm-tabs > ul > li {
14
+ cursor: pointer;
15
+ user-select: none;
16
+ padding: 4px 12px 4px 12px;
17
+ border: 1px solid #ccc;
18
+ background-position: center;
19
+ transition: background 0.8s;
20
+ }
21
+
22
+ .lm-tabs > ul > li.selected {
23
+ background-color: #eee;
24
+ }
25
+
26
+ .lm-tabs[data-round="true"] > ul > li:first-child {
27
+ border-top-left-radius: 3px;
28
+ border-bottom-left-radius: 3px;
29
+ }
30
+
31
+ .lm-tabs[data-round="true"] > ul > li:last-child {
32
+ border-top-right-radius: 3px;
33
+ border-bottom-right-radius: 3px;
34
+ }
35
+
36
+ .lm-tabs > ul > li:not(:first-child) {
37
+ border-left: 0;
38
+ }
39
+
40
+ .lm-tabs > ul > li:hover {
41
+ background: #eee radial-gradient(circle, transparent 1%, #eee 1%) center/15000%;
42
+ }
43
+
44
+ .lm-tabs > ul > li:active {
45
+ background-color: #ddd;
46
+ background-size: 100%;
47
+ transition: background 0s;
48
+ }
49
+
50
+ .lm-tabs .lm-tabs-content > div {
51
+ display: none;
52
+ }
53
+
54
+ .lm-tabs .lm-tabs-content > div.selected {
55
+ display: block;
56
+ }
57
+
58
+ .lm-tabs[data-position="center"] > ul {
59
+ margin: 0 auto;
60
+ justify-content: center;
62
61
  }
package/dist/vue.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Official Type definitions for the LemonadeJS plugins
3
+ * https://lemonadejs.net
4
+ * Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
+ */
6
+ import Component from './index';
7
+
8
+ interface Tabs {
9
+ (): any
10
+ [key: string]: any
11
+ }
12
+
13
+ declare function Tabs<Tabs>(props: Component.Options): any;
14
+
15
+ export default Tabs;
package/dist/vue.js ADDED
@@ -0,0 +1,54 @@
1
+ import { h } from 'vue';
2
+ import component from "./index.js";
3
+
4
+ export const Tabs = {
5
+ inheritAttrs: false,
6
+ mounted() {
7
+ let options = {
8
+ ...this.$attrs
9
+ };
10
+
11
+ this.el = this.$refs.container;
12
+
13
+ this.current = component(this.el, options);
14
+
15
+ },
16
+ setup(_, context) {
17
+ let containerProps = {
18
+ ref: 'container',
19
+ style: {
20
+ width: '100%',
21
+ height: '100%',
22
+ }
23
+ };
24
+
25
+ let vnode = [];
26
+
27
+ if (context.slots.default && typeof(context.slots.default) === 'function') {
28
+ vnode = context.slots.default()
29
+ }
30
+
31
+ return () => h('div', containerProps, vnode);
32
+ },
33
+ watch: {
34
+ $attrs: {
35
+ deep: true,
36
+ handler() {
37
+ this.updateState();
38
+ }
39
+ }
40
+ },
41
+ methods: {
42
+ updateState() {
43
+ for (let key in this.$attrs) {
44
+ if (this.$attrs.hasOwnProperty(key) && this.current.hasOwnProperty(key)) {
45
+ if (this.$attrs[key] !== this.current[key]) {
46
+ this.current[key] = this.$attrs[key];
47
+ }
48
+ }
49
+ }
50
+ }
51
+ }
52
+ };
53
+
54
+ export default Tabs;
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": "^4.0.7"
17
- },
18
- "main": "dist/index.js",
19
- "version": "2.0.0"
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": "^4.0.7"
17
+ },
18
+ "main": "dist/index.js",
19
+ "version": "2.0.4"
20
+ }
package/src/index.html DELETED
@@ -1,16 +0,0 @@
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
- </script>