@neovici/cosmoz-tabs 5.1.0 → 5.2.1
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/cosmoz-tab-card.js +1 -1
- package/cosmoz-tabs.js +3 -2
- package/lib/render.js +17 -12
- package/lib/use-tabs.js +16 -12
- package/package.json +2 -1
package/cosmoz-tab-card.js
CHANGED
|
@@ -60,7 +60,7 @@ const CosmozTabCard = ({ heading }) => html`
|
|
|
60
60
|
</style>
|
|
61
61
|
|
|
62
62
|
<div id="header" part="header">
|
|
63
|
-
<h1 class="heading">${ heading }<slot name="after-title"></slot></h1>
|
|
63
|
+
<h1 class="heading" part="heading">${ heading }<slot name="after-title"></slot></h1>
|
|
64
64
|
<slot name="card-actions"></slot>
|
|
65
65
|
</div>
|
|
66
66
|
|
package/cosmoz-tabs.js
CHANGED
|
@@ -17,8 +17,8 @@ using tabs.
|
|
|
17
17
|
|
|
18
18
|
The following custom properties and mixins are available for styling:
|
|
19
19
|
|
|
20
|
-
Custom property
|
|
21
|
-
|
|
20
|
+
Custom property | Description | Default
|
|
21
|
+
------------------------------------|-----------------------------|----------
|
|
22
22
|
`--cosmoz-tabs-selection-bar-color` | Color for the selection bar | `#00b4db`
|
|
23
23
|
|
|
24
24
|
*/
|
|
@@ -28,6 +28,7 @@ const Tabs = host => {
|
|
|
28
28
|
return html`
|
|
29
29
|
<style>${ style }</style>
|
|
30
30
|
<div class="tabs" part="tabs" role="tablist">
|
|
31
|
+
<slot name="tabs"></slot>
|
|
31
32
|
${ tabs.map(renderTab(opts)) }
|
|
32
33
|
</div>
|
|
33
34
|
|
package/lib/render.js
CHANGED
|
@@ -12,17 +12,20 @@ const style = `
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
.tabs {
|
|
15
|
-
background-color: #fff;
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
background-color: var(--cosmoz-tabs-bg-color, #fff);
|
|
16
|
+
color: var(--cosmoz-tabs-text-color, #606c7e);
|
|
17
|
+
font-family: var(--cosmoz-tabs-font-family, inherit);
|
|
18
|
+
font-size: var(--cosmoz-tabs-font-size, 13px);
|
|
19
|
+
line-height: var(--cosmoz-tabs-line-height, 19px);
|
|
20
|
+
box-shadow: var(--cosmoz-tabs-shadow, inset 0 -1px 0 0 #e5e6eb);
|
|
18
21
|
flex: none;
|
|
19
22
|
display: flex;
|
|
20
23
|
align-items: center;
|
|
21
24
|
overflow-x: auto;
|
|
22
25
|
-webkit-overflow-scrolling: auto;
|
|
23
26
|
scrollbar-width: none;
|
|
27
|
+
padding-bottom: 1px;
|
|
24
28
|
}
|
|
25
|
-
|
|
26
29
|
.tabs::-webkit-scrollbar {
|
|
27
30
|
display: none;
|
|
28
31
|
}
|
|
@@ -30,16 +33,15 @@ const style = `
|
|
|
30
33
|
.tab {
|
|
31
34
|
position: relative;
|
|
32
35
|
display: flex;
|
|
36
|
+
box-sizing: border-box;
|
|
33
37
|
align-items: center;
|
|
34
38
|
justify-content: center;
|
|
35
39
|
flex: 1;
|
|
36
|
-
padding:
|
|
40
|
+
padding: 11px 24px;
|
|
37
41
|
color: inherit;
|
|
38
42
|
text-decoration: none;
|
|
39
43
|
text-align: center;
|
|
40
|
-
|
|
41
|
-
line-height: 1.27;
|
|
42
|
-
font-weight: 300;
|
|
44
|
+
letter-spacing: 0.3px;
|
|
43
45
|
text-overflow: ellipsis;
|
|
44
46
|
white-space: nowrap;
|
|
45
47
|
cursor: pointer;
|
|
@@ -48,12 +50,14 @@ const style = `
|
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
.tab[aria-selected] {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
color: var(--cosmoz-tabs-accent-color, #508aef);
|
|
54
|
+
box-shadow: inset 0 -3px 0px 0px var(--cosmoz-tabs-accent-color, #508aef);
|
|
55
|
+
font-weight: 700;
|
|
56
|
+
letter-spacing: 0;
|
|
53
57
|
}
|
|
54
58
|
|
|
55
59
|
.tab[disabled] {
|
|
56
|
-
opacity: 0.
|
|
60
|
+
opacity: 0.4;
|
|
57
61
|
pointer-events: none;
|
|
58
62
|
}
|
|
59
63
|
|
|
@@ -101,10 +105,11 @@ const style = `
|
|
|
101
105
|
selectedTab,
|
|
102
106
|
onSelect,
|
|
103
107
|
href
|
|
104
|
-
}) => tab => {
|
|
108
|
+
}) => (tab, i, tabs) => {
|
|
105
109
|
const isSelected = selectedTab === tab,
|
|
106
110
|
icon = getIcon(tab, isSelected);
|
|
107
111
|
return html`<a class="tab" tabindex="-1" role="tab"
|
|
112
|
+
part=${ ['tab', i === 0 && 'first-tab', i === tabs.length - 1 && 'last-tab', isSelected && 'selected-tab'].filter(Boolean).join(' ') }
|
|
108
113
|
?hidden=${ tab.hidden } ?disabled=${ tab.disabled }
|
|
109
114
|
?aria-selected=${ isSelected }
|
|
110
115
|
@click=${ onSelect }
|
package/lib/use-tabs.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useState, useEffect, useMemo, useCallback
|
|
3
|
-
} from 'haunted';
|
|
1
|
+
import { useState, useEffect, useMemo, useCallback } from 'haunted';
|
|
4
2
|
import { notifyProperty } from '@neovici/cosmoz-utils/lib/hooks/use-notify-property';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
choose, collect, getName, isValid
|
|
10
|
-
} from './utils';
|
|
3
|
+
import { useHashParam, link } from './use-hash-param';
|
|
4
|
+
import { choose, collect, getName, isValid } from './utils';
|
|
5
|
+
import computeScroll from 'compute-scroll-into-view';
|
|
11
6
|
|
|
12
7
|
const useTabSelectedEffect = (host, selectedTab) => {
|
|
13
8
|
useEffect(() => {
|
|
@@ -37,6 +32,17 @@ const useTabSelectedEffect = (host, selectedTab) => {
|
|
|
37
32
|
}, [selectedTab]);
|
|
38
33
|
},
|
|
39
34
|
|
|
35
|
+
useAutoScroll = (host, selectedTab) => {
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
const el = host.shadowRoot.querySelector('a[aria-selected]');
|
|
38
|
+
if (!el) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
computeScroll(el, { block: 'nearest', inline: 'center', boundary: el.parentElement })
|
|
42
|
+
.forEach(({ el, top, left }) => el.scroll({ top, left, behavior: 'smooth' }));
|
|
43
|
+
}, [selectedTab]);
|
|
44
|
+
},
|
|
45
|
+
|
|
40
46
|
useTabs = host => {
|
|
41
47
|
const {
|
|
42
48
|
selected, hashParam
|
|
@@ -62,9 +68,7 @@ const useTabSelectedEffect = (host, selectedTab) => {
|
|
|
62
68
|
return () => host.removeEventListener('cosmoz-tab-alter', onTabAlter);
|
|
63
69
|
}, [selectedTab]);
|
|
64
70
|
|
|
65
|
-
|
|
66
|
-
host.shadowRoot.querySelector('a[aria-selected]')?.scrollIntoView?.({ inline: 'center', behavior: 'smooth' });
|
|
67
|
-
}, [selectedTab]);
|
|
71
|
+
useAutoScroll(host, selectedTab);
|
|
68
72
|
|
|
69
73
|
const href = useCallback(tab => isValid(tab) ? link(hashParam, getName(tab)) : undefined, [hashParam]);
|
|
70
74
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neovici/cosmoz-tabs",
|
|
3
|
-
"version": "5.1
|
|
3
|
+
"version": "5.2.1",
|
|
4
4
|
"description": "A multi views container element that allow navigation between the views using tabs or an accordion.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"web-components"
|
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
"@neovici/cosmoz-utils": "^3.21.0",
|
|
58
58
|
"@polymer/iron-icon": "^3.0.0",
|
|
59
59
|
"@polymer/iron-icons": "^3.0.0",
|
|
60
|
+
"compute-scroll-into-view": "^1.0.17",
|
|
60
61
|
"haunted": "^4.8.0",
|
|
61
62
|
"lit-html": "^1.4.0"
|
|
62
63
|
},
|