@lemonadejs/tabs 2.1.0 → 2.3.0

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,129 +1,129 @@
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
- Quick example with React
58
-
59
- ```jsx
60
- import React, { useRef } from "react";
61
- import Tabs from "@lemonadejs/tabs/dist/react";
62
- import '@lemonadejs/tabs/dist/style.css';
63
-
64
- const data = [{ title: 'Tab 1', content: 'Content of first tab' }, { title: 'Tab 2', content: 'Content of second tab' }]
65
- export default function App() {
66
- const tabs = useRef();
67
- return (
68
- <>
69
- <Tabs selected={0} ref={tabs} data={data}/>
70
- </>
71
- );
72
- }
73
- ```
74
-
75
- Quick example with React
76
-
77
- ```vue
78
- <template>
79
- <Tabs :selected="0">
80
- <div title="Tab 1">Content of the first tab</div>
81
- <div title="Tab 2">Content of the second tab</div>
82
- </Tabs>
83
- </template>
84
-
85
- <script>
86
- import Tabs from '@lemonadejs/tabs/dist/vue';
87
- import '@lemonadejs/tabs/dist/style.css';
88
-
89
- export default {
90
- name: 'App',
91
- components: {
92
- Tabs,
93
- },
94
- };
95
- </script>
96
- ```
97
-
98
- [You can find more examples here in the official documentation.](https://lemonadejs.net/components/tabs)
99
-
100
- ### Configuration
101
-
102
- You can configure things such as tabs titles, tabs contents and selected tab.
103
-
104
- #### Settings
105
-
106
- | Property | Type | Description |
107
- | -------- | ---- | ----------- |
108
- | selected? | number | The index of the initially selected tab. Starts from 0. |
109
- | position? | string | The position of the tabs bar within the parent element. Use 'center' to center-align the tabs. |
110
- | 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. |
111
- | round? | boolean | Dictates whether the tab style will feature rounded corners. |
112
- | onopen? | function | When a new tabs is opened. |
113
-
114
- #### Tab Item
115
-
116
- | Property | Description |
117
- | -------- | ----------- |
118
- | title | The title of the tab, serving as the label displayed on the tab options. |
119
- | content | The HTML content intended for this specific tab. |
120
-
121
-
122
- ## License
123
-
124
- The [LemonadeJS](https://lemonadejs.net) Tabs is released under the MIT.
125
-
126
- ## Other Tools
127
-
128
- - [jSuites](https://jsuites.net)
129
- - [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
+ Quick example with React
58
+
59
+ ```jsx
60
+ import React, { useRef } from "react";
61
+ import Tabs from "@lemonadejs/tabs/dist/react";
62
+ import '@lemonadejs/tabs/dist/style.css';
63
+
64
+ const data = [{ title: 'Tab 1', content: 'Content of first tab' }, { title: 'Tab 2', content: 'Content of second tab' }]
65
+ export default function App() {
66
+ const tabs = useRef();
67
+ return (
68
+ <>
69
+ <Tabs selected={0} ref={tabs} data={data}/>
70
+ </>
71
+ );
72
+ }
73
+ ```
74
+
75
+ Quick example with React
76
+
77
+ ```vue
78
+ <template>
79
+ <Tabs :selected="0">
80
+ <div title="Tab 1">Content of the first tab</div>
81
+ <div title="Tab 2">Content of the second tab</div>
82
+ </Tabs>
83
+ </template>
84
+
85
+ <script>
86
+ import Tabs from '@lemonadejs/tabs/dist/vue';
87
+ import '@lemonadejs/tabs/dist/style.css';
88
+
89
+ export default {
90
+ name: 'App',
91
+ components: {
92
+ Tabs,
93
+ },
94
+ };
95
+ </script>
96
+ ```
97
+
98
+ [You can find more examples here in the official documentation.](https://lemonadejs.net/components/tabs)
99
+
100
+ ### Configuration
101
+
102
+ You can configure things such as tabs titles, tabs contents and selected tab.
103
+
104
+ #### Settings
105
+
106
+ | Property | Type | Description |
107
+ | -------- | ---- | ----------- |
108
+ | selected? | number | The index of the initially selected tab. Starts from 0. |
109
+ | position? | string | The position of the tabs bar within the parent element. Use 'center' to center-align the tabs. |
110
+ | 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. |
111
+ | round? | boolean | Dictates whether the tab style will feature rounded corners. |
112
+ | onopen? | function | When a new tabs is opened. |
113
+
114
+ #### Tab Item
115
+
116
+ | Property | Description |
117
+ | -------- | ----------- |
118
+ | title | The title of the tab, serving as the label displayed on the tab options. |
119
+ | content | The HTML content intended for this specific tab. |
120
+
121
+
122
+ ## License
123
+
124
+ The [LemonadeJS](https://lemonadejs.net) Tabs is released under the MIT.
125
+
126
+ ## Other Tools
127
+
128
+ - [jSuites](https://jsuites.net)
129
+ - [Jspreadsheet Data Grid](https://jspreadsheet.com)
package/dist/index.d.ts CHANGED
@@ -1,42 +1,50 @@
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
-
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 Item {
11
+ // Reference to an external DOM
12
+ el: HTMLElement,
13
+ // Tab header
14
+ title: string,
15
+ // HTML template
16
+ content: string,
17
+ }
18
+
19
+ interface Options {
20
+ /** Programmatically content */
21
+ data?: Item[];
22
+ /** Selected tab */
23
+ selected?: number;
24
+ /** Tabs position */
25
+ position?: 'center' | undefined;
26
+ /** Activate round borders */
27
+ round?: boolean;
28
+ /** On open event */
29
+ onopen?: (instance: object, index: number) => void;
30
+ /** Allow to create new tab button */
31
+ allowCreate?: boolean;
32
+ }
33
+
34
+ interface Instance {
35
+ /** Create a new option */
36
+ create: (item: Item, position?: number, select?: boolean) => void;
37
+ /** Programmatically content */
38
+ data: Item[];
39
+ /** Selected tab */
40
+ selected: number;
41
+ /** Tabs position */
42
+ position?: 'center' | undefined;
43
+ /** Activate round borders */
44
+ round?: boolean;
45
+ /** On open event */
46
+ onopen?: (instance: object, index: number) => void;
47
+ }
48
+ }
49
+
42
50
  export default Tabs;
package/dist/index.js CHANGED
@@ -1,149 +1,237 @@
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
- let elements = [];
14
-
15
- if (this.tagName) {
16
- // Remove elements from the DOM
17
- elements = removeElements(this);
18
- }
19
-
20
- if (self.data) {
21
- for (let i = 0; i < self.data.length; i++) {
22
- let d = document.createElement('div');
23
- d.title = self.data[i].title;
24
- d.innerHTML = self.data[i].content;
25
- elements.push(d);
26
- }
27
- }
28
-
29
- if (! html) {
30
- html = '';
31
- }
32
-
33
- self.tabs = [];
34
-
35
- const select = function (index) {
36
- index = parseInt(index);
37
-
38
- if (index >= 0 && index < self.tabs.length) {
39
- for (let i = 0; i < self.content.children.length; i++) {
40
- self.headers.children[i].classList.remove('selected');
41
- self.content.children[i].classList.remove('selected');
42
- }
43
- self.headers.children[index].classList.add('selected');
44
- self.content.children[index].classList.add('selected');
45
-
46
- self.position = index;
47
- }
48
- }
49
-
50
- self.onload = function () {
51
- // Append elements to the container
52
- appendElements(self.el.children[1], elements);
53
-
54
- for (let i = 0; i < self.content.children.length; i++) {
55
- self.tabs.push({ title: self.content.children[i].title });
56
- }
57
- self.refresh('tabs');
58
-
59
- let index = 0;
60
- if (! isNaN(parseInt(self.selected))) {
61
- index = parseInt(self.selected);
62
- }
63
- select(index);
64
-
65
- /**
66
- * Handler keyboard
67
- * @param {object} e - event
68
- */
69
- self.headers.addEventListener('keydown', function(e){
70
- let prevent = false;
71
- if (e.key === 'ArrowUp' || e.key === 'ArrowLeft') {
72
- select(self.position - 1);
73
- prevent = true;
74
- } else if (e.key === 'ArrowDown' || e.key === 'ArrowRight') {
75
- select(self.position + 1);
76
- prevent = true;
77
- }
78
-
79
- if (prevent) {
80
- e.preventDefault();
81
- e.stopImmediatePropagation();
82
- }
83
- });
84
- }
85
-
86
-
87
- self.onchange = function (property) {
88
- if (property === 'selected') {
89
- select(self.selected);
90
-
91
- if (typeof(self.onopen) === 'function') {
92
- self.onopen.call(self, self.selected);
93
- }
94
- }
95
- }
96
-
97
- self.click = function (e) {
98
- if (e.target.tagName === 'LI') {
99
- self.selected = Array.prototype.indexOf.call(e.target.parentNode.children, e.target);
100
- }
101
- }
102
-
103
- return `<div class="lm-tabs" data-position="{{self.position}}" data-round="{{self.round}}">
104
- <ul :ref="self.headers" :loop="self.tabs" :selected="self.selected" onclick="self.click" tabindex="0"><li class="lm-tab-list-item">{{self.title}}</li></ul>
105
- <div :ref="self.content" class="lm-tabs-content">${html}</div>
106
- </div>`
107
- }
108
-
109
- const removeElements = function(root) {
110
- // Keep the DOM elements
111
- let elements = [];
112
- if (root) {
113
- while (root.firstChild) {
114
- elements.push(root.firstChild);
115
- root.firstChild.remove();
116
- }
117
- }
118
- return elements;
119
- }
120
-
121
- const appendElements = function(root, elements) {
122
- if (elements && elements.length) {
123
- while (elements[0]) {
124
- root.appendChild(elements.shift());
125
- }
126
- }
127
- }
128
-
129
- const Component = function (root, options) {
130
- if (typeof (root) === 'object') {
131
- // Remove elements from the DOM
132
- let elements = removeElements(root);
133
- // Create the modal
134
- let e = lemonade.render(Tabs, root, options);
135
- // Add elements to the container
136
- appendElements(e.children[1], elements);
137
-
138
- return options;
139
- } else {
140
- return Tabs.call(this);
141
- }
142
- }
143
-
144
- lemonade.setComponents({ Tabs: Tabs });
145
-
146
- lemonade.createWebComponent('tabs', Tabs);
147
-
148
- return Component;
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
+ // Dispatcher
12
+ const Dispatch = function(type){
13
+ if (typeof this[type] === 'function') {
14
+ let args = Array.from(arguments);
15
+ args.shift();
16
+ this[type](...args)
17
+ }
18
+ }
19
+
20
+ const extract = function(root, self) {
21
+ if (! Array.isArray(self.data)) {
22
+ self.data = [];
23
+ }
24
+
25
+ if (root.tagName) {
26
+ for (let i = 0; i < root.children.length; i++) {
27
+ self.data.push({
28
+ el: root.children[i],
29
+ })
30
+ }
31
+ } else {
32
+ root.forEach((child) => {
33
+ self.data.push({
34
+ el: child.element,
35
+ })
36
+ });
37
+ }
38
+ }
39
+
40
+ const Tabs = function(children) {
41
+ let self = this
42
+
43
+ // Add new tab
44
+ let createButton;
45
+
46
+ // Get the references from the root web component
47
+ let root;
48
+ if (this.tagName) {
49
+ root = this;
50
+ } else {
51
+ // References from LemonadeJS
52
+ if (typeof(children) === 'string') {
53
+ // Version 4
54
+ root = document.createElement('div');
55
+ root.innerHTML = children;
56
+ } else if (children && children.length) {
57
+ // Version 5
58
+ root = children;
59
+ }
60
+ }
61
+
62
+ if (root) {
63
+ extract(root, self);
64
+ }
65
+
66
+ // Process the data
67
+ if (self.data) {
68
+ for (let i = 0; i < self.data.length; i++) {
69
+ if (self.data[i].el) {
70
+ if (! self.data[i].title) {
71
+ self.data[i].title = self.data[i].el.getAttribute('title');
72
+ }
73
+ if (! self.data[i].selected) {
74
+ self.data[i].selected = self.data[i].el.getAttribute('selected');
75
+ }
76
+ } else {
77
+ // Create element
78
+ self.data[i].el = document.createElement('div');
79
+ // Create from content
80
+ if (self.data[i].content) {
81
+ self.data[i].el.innerHTML = self.data[i].content;
82
+ }
83
+ }
84
+ }
85
+ }
86
+
87
+ const select = function (index) {
88
+ // Make sure the index is a number
89
+ index = parseInt(index);
90
+ // Do not select tabs that does not exist
91
+ if (index >= 0 && index < self.data.length) {
92
+ for (let i = 0; i < self.root.children.length; i++) {
93
+ self.headers.children[i].classList.remove('selected');
94
+ self.root.children[i].classList.remove('selected');
95
+ }
96
+ self.headers.children[index].classList.add('selected');
97
+ self.root.children[index].classList.add('selected');
98
+ }
99
+ }
100
+
101
+ const init = function(selected) {
102
+ let tabs = [];
103
+ for (let i = 0; i < self.data.length; i++) {
104
+ // Create tabs object
105
+ tabs[i] = {
106
+ title: self.data[i].title,
107
+ }
108
+ // Which one is selected by default
109
+ if (self.data[i].selected) {
110
+ selected = i;
111
+ }
112
+
113
+ self.root.appendChild(self.data[i].el)
114
+ }
115
+ // Create headers
116
+ self.tabs = tabs;
117
+ // Default selected
118
+ if (typeof(selected) !== 'undefined') {
119
+ self.selected = selected;
120
+ }
121
+ // Add create new tab button
122
+ if (createButton) {
123
+ self.headers.appendChild(createButton);
124
+ }
125
+ }
126
+
127
+ self.onload = function () {
128
+ init(self.selected || 0);
129
+ }
130
+
131
+ self.keydown = function(e, s) {
132
+ let index = null;
133
+ if (e.key === 'Enter') {
134
+ self.click(e, s);
135
+ } else if (e.key === 'ArrowUp' || e.key === 'ArrowLeft') {
136
+ index = self.selected - 1;
137
+ if (index < 0) {
138
+ index = 0;
139
+ }
140
+ } else if (e.key === 'ArrowDown' || e.key === 'ArrowRight') {
141
+ index = self.selected + 1;
142
+ if (index > self.tabs.length-1) {
143
+ index = self.tabs.length-1;
144
+ }
145
+ }
146
+
147
+ // Make selection
148
+ if (index !== null) {
149
+ self.tabs[index].el.focus();
150
+ }
151
+ }
152
+
153
+ self.open = function (e) {
154
+ if (e.target.tagName === 'LI') {
155
+ // Avoid select something already selected
156
+ let index = Array.prototype.indexOf.call(e.target.parentNode.children, e.target);
157
+ if (index !== self.selected) {
158
+ self.selected = index;
159
+ }
160
+ }
161
+ }
162
+
163
+ self.create = function(item, position, select) {
164
+ // Create element
165
+ if (typeof(item) !== 'object') {
166
+ console.error('Item must be an object');
167
+ } else {
168
+ // Create DOM
169
+ item.el = document.createElement('div');
170
+ // Create from content
171
+ if (item.content) {
172
+ item.el.innerHTML = item.content;
173
+ }
174
+
175
+ // Add the new item in the end
176
+ if (typeof(position) === 'undefined' || position === null) {
177
+ // Mew item
178
+ position = self.data.length;
179
+ // Add in the end
180
+ self.data.push(item);
181
+ } else {
182
+ self.data.splice(position, 0, item);
183
+ }
184
+ // New position
185
+ if (select) {
186
+ // Refresh
187
+ init(self.data.indexOf(item));
188
+ } else {
189
+ init(self.selected);
190
+ }
191
+ }
192
+ }
193
+
194
+ self.click = function() {
195
+ // Create a new item
196
+ self.create({ title: 'Untitled' }, null, true);
197
+ }
198
+
199
+ self.onchange = function (property) {
200
+ if (property === 'selected') {
201
+ select(self.selected);
202
+
203
+ Dispatch.call(self, 'onopen', self, self.selected);
204
+ }
205
+ }
206
+
207
+ self.allowCreate = !! self.allowCreate;
208
+
209
+ return `<div class="lm-tabs" data-position="{{self.position}}" data-round="{{self.round}}">
210
+ <div role="tabs" class="lm-tabs-headers">
211
+ <ul :ref="self.headers" :loop="self.tabs" :selected="self.selected" onclick="self.open" onkeydown="self.keydown" onfocusin="self.open"><li class="lm-tab" tabindex="0" role="tab">{{self.title}}</li></ul>
212
+ <div data-visible="{{self.allowCreate}}" class="lm-tabs-insert-tab material-icons" role="insert-tab" onclick="self.click">add</div>
213
+ </div>
214
+ <div :ref="self.root" class="lm-tabs-content"></div>
215
+ </div>`
216
+ }
217
+
218
+ lemonade.setComponents({ Tabs: Tabs });
219
+
220
+ lemonade.createWebComponent('tabs', Tabs);
221
+
222
+ return function (root, options) {
223
+ if (typeof (root) === 'object') {
224
+ if (typeof(options) !== 'object') {
225
+ options = {};
226
+ }
227
+ // Extract DOM references
228
+ extract(root, options);
229
+ // Create the modal
230
+ lemonade.render(Tabs, root, options);
231
+ // Return self
232
+ return options;
233
+ } else {
234
+ return Tabs.call(this);
235
+ }
236
+ };
149
237
  })));
package/dist/react.d.ts CHANGED
@@ -1,18 +1,18 @@
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
- ref?: MutableRefObject<undefined>;
10
- (): any
11
- [key: string]: any
12
- }
13
-
14
- type Props = IntrinsicAttributes & Component.Options & Tabs;
15
-
16
- declare function Tabs<Tabs>(props: Props): any;
17
-
18
- export default Tabs;
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
+ ref?: MutableRefObject<undefined>;
10
+ (): any
11
+ [key: string]: any
12
+ }
13
+
14
+ type Props = IntrinsicAttributes & Component.Options & Tabs;
15
+
16
+ declare function Tabs<Tabs>(props: Props): any;
17
+
18
+ export default Tabs;
package/dist/react.js CHANGED
@@ -1,37 +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);
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
37
  })
package/dist/style.css CHANGED
@@ -1,66 +1,78 @@
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
- color: #000;
25
- }
26
-
27
- .lm-tabs > ul:focus {
28
- outline: none;
29
- }
30
-
31
- .lm-tabs[data-round="true"] > ul > li:first-child {
32
- border-top-left-radius: 3px;
33
- border-bottom-left-radius: 3px;
34
- }
35
-
36
- .lm-tabs[data-round="true"] > ul > li:last-child {
37
- border-top-right-radius: 3px;
38
- border-bottom-right-radius: 3px;
39
- }
40
-
41
- .lm-tabs > ul > li:not(:first-child) {
42
- border-left: 0;
43
- }
44
-
45
- .lm-tabs > ul > li:hover {
46
- background: #eee radial-gradient(circle, transparent 1%, #eee 1%) center/15000%;
47
- }
48
-
49
- .lm-tabs > ul > li:active {
50
- background-color: #ddd;
51
- background-size: 100%;
52
- transition: background 0s;
53
- }
54
-
55
- .lm-tabs .lm-tabs-content > div {
56
- display: none;
57
- }
58
-
59
- .lm-tabs .lm-tabs-content > div.selected {
60
- display: block;
61
- }
62
-
63
- .lm-tabs[data-position="center"] > ul {
64
- margin: 0 auto;
65
- justify-content: center;
1
+ .lm-tabs .lm-tabs-content > div {
2
+ padding: 6px;
3
+ }
4
+
5
+ .lm-tabs .lm-tabs-headers {
6
+ display: flex;
7
+ align-items: center;
8
+ width: 100%;
9
+ }
10
+
11
+ .lm-tabs[data-position="center"] .lm-tabs-headers {
12
+ margin: 0 auto;
13
+ justify-content: center;
14
+ }
15
+
16
+ .lm-tabs .lm-tabs-headers > ul {
17
+ list-style-type: none;
18
+ display: flex;
19
+ margin: 0;
20
+ padding: 0;
21
+ align-items: center;
22
+ }
23
+
24
+ .lm-tabs .lm-tabs-headers > ul > li {
25
+ cursor: pointer;
26
+ user-select: none;
27
+ padding: 4px 24px;
28
+ border: 1px solid #ccc;
29
+ background-position: center;
30
+ transition: background 0.8s;
31
+ }
32
+
33
+ .lm-tabs .lm-tabs-headers > ul > li.selected {
34
+ background-color: #eee;
35
+ color: #000;
36
+ }
37
+
38
+ .lm-tabs[data-round="true"] .lm-tabs-headers > ul > li:first-of-type {
39
+ border-top-left-radius: 3px;
40
+ border-bottom-left-radius: 3px;
41
+ }
42
+
43
+ .lm-tabs[data-round="true"] .lm-tabs-headers > ul > li:last-of-type {
44
+ border-top-right-radius: 3px;
45
+ border-bottom-right-radius: 3px;
46
+ }
47
+
48
+ .lm-tabs .lm-tabs-headers > ul > li:not(:first-child) {
49
+ border-left: 1px solid transparent;
50
+ }
51
+
52
+ .lm-tabs .lm-tabs-headers > ul > li:hover {
53
+ background: #eee radial-gradient(circle, transparent 1%, #eee 1%) center/15000%;
54
+ }
55
+
56
+ .lm-tabs .lm-tabs-headers > ul > li:active {
57
+ background-color: #ddd;
58
+ background-size: 100%;
59
+ transition: background 0s;
60
+ }
61
+
62
+ .lm-tabs .lm-tabs-content > div {
63
+ display: none;
64
+ }
65
+
66
+ .lm-tabs .lm-tabs-content > div.selected {
67
+ display: block;
68
+ }
69
+
70
+ .lm-tabs-insert-tab {
71
+ margin-left: 5px;
72
+ color: #555;
73
+ cursor: pointer;
74
+ }
75
+
76
+ .lm-tabs div[data-visible='false'] {
77
+ display: none;
66
78
  }
package/dist/vue.d.ts CHANGED
@@ -1,15 +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;
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 CHANGED
@@ -1,54 +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
-
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
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.3.1"
17
- },
18
- "main": "dist/index.js",
19
- "version": "2.1.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.3.3"
17
+ },
18
+ "main": "dist/index.js",
19
+ "version": "2.3.0"
20
+ }