@lemonadejs/tabs 2.0.4 → 2.1.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 +41 -0
- package/dist/index.js +82 -18
- package/dist/react.d.ts +4 -1
- package/dist/style.css +5 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -54,6 +54,47 @@ export default function App() {
|
|
|
54
54
|
}
|
|
55
55
|
```
|
|
56
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
|
+
|
|
57
98
|
[You can find more examples here in the official documentation.](https://lemonadejs.net/components/tabs)
|
|
58
99
|
|
|
59
100
|
### Configuration
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
if (!lemonade && typeof (require) === 'function') {
|
|
1
|
+
if (! lemonade && typeof (require) === 'function') {
|
|
2
2
|
var lemonade = require('lemonadejs');
|
|
3
3
|
}
|
|
4
4
|
|
|
@@ -10,29 +10,47 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
10
10
|
|
|
11
11
|
const Tabs = function (html) {
|
|
12
12
|
let self = this
|
|
13
|
+
let elements = [];
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
if (this.tagName) {
|
|
16
|
+
// Remove elements from the DOM
|
|
17
|
+
elements = removeElements(this);
|
|
18
|
+
}
|
|
15
19
|
|
|
16
20
|
if (self.data) {
|
|
17
21
|
for (let i = 0; i < self.data.length; i++) {
|
|
18
|
-
|
|
22
|
+
let d = document.createElement('div');
|
|
23
|
+
d.title = self.data[i].title;
|
|
24
|
+
d.innerHTML = self.data[i].content;
|
|
25
|
+
elements.push(d);
|
|
19
26
|
}
|
|
20
27
|
}
|
|
21
28
|
|
|
29
|
+
if (! html) {
|
|
30
|
+
html = '';
|
|
31
|
+
}
|
|
32
|
+
|
|
22
33
|
self.tabs = [];
|
|
23
34
|
|
|
24
35
|
const select = function (index) {
|
|
25
36
|
index = parseInt(index);
|
|
26
37
|
|
|
27
|
-
|
|
28
|
-
self.
|
|
29
|
-
|
|
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;
|
|
30
47
|
}
|
|
31
|
-
self.headers.children[index].classList.add('selected');
|
|
32
|
-
self.content.children[index].classList.add('selected');
|
|
33
48
|
}
|
|
34
49
|
|
|
35
50
|
self.onload = function () {
|
|
51
|
+
// Append elements to the container
|
|
52
|
+
appendElements(self.el.children[1], elements);
|
|
53
|
+
|
|
36
54
|
for (let i = 0; i < self.content.children.length; i++) {
|
|
37
55
|
self.tabs.push({ title: self.content.children[i].title });
|
|
38
56
|
}
|
|
@@ -43,8 +61,29 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
43
61
|
index = parseInt(self.selected);
|
|
44
62
|
}
|
|
45
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
|
+
});
|
|
46
84
|
}
|
|
47
85
|
|
|
86
|
+
|
|
48
87
|
self.onchange = function (property) {
|
|
49
88
|
if (property === 'selected') {
|
|
50
89
|
select(self.selected);
|
|
@@ -62,24 +101,49 @@ if (!lemonade && typeof (require) === 'function') {
|
|
|
62
101
|
}
|
|
63
102
|
|
|
64
103
|
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">${
|
|
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>
|
|
67
106
|
</div>`
|
|
68
107
|
}
|
|
69
108
|
|
|
70
|
-
|
|
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
|
+
}
|
|
71
120
|
|
|
72
|
-
|
|
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) {
|
|
73
130
|
if (typeof (root) === 'object') {
|
|
74
|
-
//
|
|
75
|
-
|
|
76
|
-
|
|
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);
|
|
77
137
|
|
|
78
|
-
// Send Template as a parameter for the Lemonade component
|
|
79
|
-
lemonade.render(Tabs, root, options, template)
|
|
80
138
|
return options;
|
|
81
139
|
} else {
|
|
82
|
-
return Tabs.call(this
|
|
140
|
+
return Tabs.call(this);
|
|
83
141
|
}
|
|
84
142
|
}
|
|
143
|
+
|
|
144
|
+
lemonade.setComponents({ Tabs: Tabs });
|
|
145
|
+
|
|
146
|
+
lemonade.createWebComponent('tabs', Tabs);
|
|
147
|
+
|
|
148
|
+
return Component;
|
|
85
149
|
})));
|
package/dist/react.d.ts
CHANGED
|
@@ -6,10 +6,13 @@
|
|
|
6
6
|
import Component from './index';
|
|
7
7
|
|
|
8
8
|
interface Tabs {
|
|
9
|
+
ref?: MutableRefObject<undefined>;
|
|
9
10
|
(): any
|
|
10
11
|
[key: string]: any
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
type Props = IntrinsicAttributes & Component.Options & Tabs;
|
|
15
|
+
|
|
16
|
+
declare function Tabs<Tabs>(props: Props): any;
|
|
14
17
|
|
|
15
18
|
export default Tabs;
|
package/dist/style.css
CHANGED