@neovici/cosmoz-tabs 7.5.0 → 8.0.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/package.json +12 -14
- package/src/cosmoz-tab-card.js +52 -47
- package/src/cosmoz-tab.js +1 -1
- package/src/cosmoz-tabs.js +1 -1
- package/src/next/cosmoz-tab.js +1 -1
- package/src/next/cosmoz-tabs.js +1 -1
- package/src/next/use-tabs.d.ts +2 -1
- package/src/next/use-tabs.js +13 -13
- package/src/render.js +39 -26
- package/src/use-tab.js +1 -1
- package/src/use-tabs.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neovici/cosmoz-tabs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
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"
|
|
@@ -68,29 +68,27 @@
|
|
|
68
68
|
"./next/*": "./src/next/*"
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@neovici/cosmoz-router": "^
|
|
72
|
-
"@neovici/cosmoz-utils": "^
|
|
71
|
+
"@neovici/cosmoz-router": "^11.0.0",
|
|
72
|
+
"@neovici/cosmoz-utils": "^6.0.0",
|
|
73
|
+
"@pionjs/pion": "^2.0.0",
|
|
73
74
|
"@polymer/iron-icon": "^3.0.0",
|
|
74
75
|
"@polymer/iron-icons": "^3.0.0",
|
|
75
76
|
"compute-scroll-into-view": "^1.0.17",
|
|
76
|
-
"
|
|
77
|
-
"lit-html": "^2.0.0"
|
|
77
|
+
"lit-html": "^2.0.0 || ^3.0.0"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
|
-
"@commitlint/cli": "^
|
|
81
|
-
"@commitlint/config-conventional": "^
|
|
80
|
+
"@commitlint/cli": "^18.0.0",
|
|
81
|
+
"@commitlint/config-conventional": "^18.0.0",
|
|
82
82
|
"@neovici/cfg": "^1.11.0",
|
|
83
|
-
"@open-wc/testing": "^
|
|
83
|
+
"@open-wc/testing": "^4.0.0",
|
|
84
84
|
"@polymer/iron-list": "^3.1.0",
|
|
85
85
|
"@semantic-release/changelog": "^6.0.0",
|
|
86
86
|
"@semantic-release/git": "^10.0.0",
|
|
87
87
|
"@storybook/storybook-deployer": "^2.8.0",
|
|
88
|
-
"@web/dev-server-storybook": "^0.
|
|
89
|
-
"@web/test-runner": "^0.15.0",
|
|
90
|
-
"eslint-import-resolver-typescript": "^3.2.7",
|
|
88
|
+
"@web/dev-server-storybook": "^2.0.0",
|
|
91
89
|
"husky": "^8.0.0",
|
|
92
|
-
"semantic-release": "^
|
|
93
|
-
"sinon": "^
|
|
94
|
-
"typescript": "^
|
|
90
|
+
"semantic-release": "^22.0.0",
|
|
91
|
+
"sinon": "^17.0.0",
|
|
92
|
+
"typescript": "^5.0.0"
|
|
95
93
|
}
|
|
96
94
|
}
|
package/src/cosmoz-tab-card.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
// @license Copyright (C) 2015 Neovici AB - Apache 2 License
|
|
2
|
-
import {
|
|
3
|
-
html,
|
|
4
|
-
component
|
|
5
|
-
} from 'haunted';
|
|
2
|
+
import { html, component } from '@pionjs/pion';
|
|
6
3
|
|
|
7
4
|
/**
|
|
8
5
|
|
|
@@ -22,52 +19,60 @@ Custom property | Description | Default
|
|
|
22
19
|
`--cosmoz-tab-card-content-line-height` | Card content line height | `initial`
|
|
23
20
|
`--cosmoz-tab-card-content-padding` | Card content padding | `initial`
|
|
24
21
|
*/
|
|
25
|
-
const CosmozTabCard = ({ heading }) =>
|
|
26
|
-
<style>
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
22
|
+
const CosmozTabCard = ({ heading }) =>
|
|
23
|
+
html` <style>
|
|
24
|
+
:host {
|
|
25
|
+
display: block;
|
|
26
|
+
position: relative;
|
|
27
|
+
box-sizing: border-box;
|
|
28
|
+
background-color: #fff;
|
|
29
|
+
border-radius: 3px;
|
|
30
|
+
margin: 15px;
|
|
31
|
+
align-self: flex-start;
|
|
32
|
+
padding: var(--cosmoz-tab-card-padding, 0);
|
|
33
|
+
width: var(--cosmoz-tab-card-width, 300px);
|
|
34
|
+
box-shadow: var(
|
|
35
|
+
--cosmoz-shadow-2dp,
|
|
36
|
+
var(--shadow-elevation-2dp_-_box-shadow, 0 2px 4px 0 #e5e5e5)
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
#content {
|
|
41
|
+
line-height: var(--cosmoz-tab-card-content-line-height, initial);
|
|
42
|
+
padding: var(--cosmoz-tab-card-content-padding, initial);
|
|
43
|
+
}
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
45
|
+
#header {
|
|
46
|
+
display: flex;
|
|
47
|
+
align-items: center;
|
|
48
|
+
background-color: #fff;
|
|
49
|
+
cursor: default;
|
|
50
|
+
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
|
|
51
|
+
}
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
</style>
|
|
53
|
+
.heading {
|
|
54
|
+
font-family: inherit;
|
|
55
|
+
font-size: 17px;
|
|
56
|
+
font-weight: 400;
|
|
57
|
+
flex: 1;
|
|
58
|
+
margin: 0.67em 0 0;
|
|
59
|
+
}
|
|
60
|
+
</style>
|
|
61
61
|
|
|
62
|
-
<div id="header" part="header">
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
</
|
|
62
|
+
<div id="header" part="header">
|
|
63
|
+
<h1 class="heading" part="heading">
|
|
64
|
+
${heading}<slot name="after-title"></slot>
|
|
65
|
+
</h1>
|
|
66
|
+
<slot name="card-actions"></slot>
|
|
67
|
+
</div>
|
|
66
68
|
|
|
67
|
-
<div id="content" part="content">
|
|
68
|
-
|
|
69
|
-
</div>`;
|
|
69
|
+
<div id="content" part="content">
|
|
70
|
+
<slot></slot>
|
|
71
|
+
</div>`;
|
|
70
72
|
|
|
71
|
-
customElements.define(
|
|
72
|
-
|
|
73
|
-
|
|
73
|
+
customElements.define(
|
|
74
|
+
'cosmoz-tab-card',
|
|
75
|
+
component(CosmozTabCard, {
|
|
76
|
+
observedAttributes: ['heading'],
|
|
77
|
+
}),
|
|
78
|
+
);
|
package/src/cosmoz-tab.js
CHANGED
package/src/cosmoz-tabs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @license Copyright (C) 2015 Neovici AB - Apache 2 License
|
|
2
|
-
import { html, component } from '
|
|
2
|
+
import { html, component } from '@pionjs/pion';
|
|
3
3
|
import { useTabs } from './use-tabs';
|
|
4
4
|
import { style, renderTab } from './render';
|
|
5
5
|
import './cosmoz-tab.js';
|
package/src/next/cosmoz-tab.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { component, useEffect, useLayoutEffect } from '
|
|
1
|
+
import { component, useEffect, useLayoutEffect } from '@pionjs/pion';
|
|
2
2
|
import { html, nothing } from 'lit-html';
|
|
3
3
|
import { ifDefined } from 'lit-html/directives/if-defined.js';
|
|
4
4
|
import computeScroll from 'compute-scroll-into-view';
|
package/src/next/cosmoz-tabs.js
CHANGED
package/src/next/use-tabs.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export interface RenderTab extends Tab {
|
|
|
11
11
|
|
|
12
12
|
export interface Options {
|
|
13
13
|
hashParam?: string;
|
|
14
|
+
onActivate?: (name: string) => void;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
type Unpacked<T> = T extends (infer U)[] ? U : T;
|
|
@@ -30,7 +31,7 @@ export type RenderTabs<T extends Tab> = Pick<
|
|
|
30
31
|
|
|
31
32
|
export declare const useTabs: <T extends Tab, P extends Options>(
|
|
32
33
|
tabs: T[],
|
|
33
|
-
opts
|
|
34
|
+
opts?: P
|
|
34
35
|
) => Result<T>;
|
|
35
36
|
|
|
36
37
|
export interface RenderOptions<T extends RenderTab> {
|
package/src/next/use-tabs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable import/group-exports */
|
|
2
|
-
import { html, useMemo, useCallback, useRef } from '
|
|
2
|
+
import { html, useMemo, useCallback, useRef } from '@pionjs/pion';
|
|
3
3
|
import { ifDefined } from 'lit-html/directives/if-defined.js';
|
|
4
4
|
/* eslint-disable-next-line import/no-unresolved */
|
|
5
5
|
import { useHashParam } from '@neovici/cosmoz-router/use-hash-param';
|
|
@@ -16,15 +16,21 @@ const isValid = (tab) => !tab.hidden && !tab.disabled,
|
|
|
16
16
|
return tab && isValid(tab) ? tab : valid(tabs);
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
export const useTabs = (tabs, { hashParam }) => {
|
|
19
|
+
export const useTabs = (tabs, { hashParam, onActivate }) => {
|
|
20
20
|
const [name, activate] = useHashParam(hashParam),
|
|
21
21
|
ref = useRef([]),
|
|
22
22
|
active = useMemo(() => choose(tabs, name), [tabs, name]),
|
|
23
23
|
activated = useMemo(() => {
|
|
24
24
|
const name = active.name;
|
|
25
25
|
return (ref.current = [...ref.current.filter((i) => i !== name), name]);
|
|
26
|
-
}, [active])
|
|
27
|
-
|
|
26
|
+
}, [active]);
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
tabs,
|
|
30
|
+
active,
|
|
31
|
+
activated,
|
|
32
|
+
activate,
|
|
33
|
+
onActivate: useCallback(
|
|
28
34
|
(e) => {
|
|
29
35
|
if (e.button !== 0 || e.metaKey || e.ctrlKey) {
|
|
30
36
|
return;
|
|
@@ -33,17 +39,11 @@ export const useTabs = (tabs, { hashParam }) => {
|
|
|
33
39
|
if (!name) {
|
|
34
40
|
return;
|
|
35
41
|
}
|
|
42
|
+
onActivate?.(name);
|
|
36
43
|
activate(name);
|
|
37
44
|
},
|
|
38
|
-
[activate]
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
tabs,
|
|
43
|
-
active,
|
|
44
|
-
activated,
|
|
45
|
-
activate,
|
|
46
|
-
onActivate,
|
|
45
|
+
[activate, onActivate]
|
|
46
|
+
),
|
|
47
47
|
};
|
|
48
48
|
};
|
|
49
49
|
|
package/src/render.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { html } from '
|
|
1
|
+
import { html } from 'lit-html';
|
|
2
2
|
import { ifDefined } from 'lit-html/directives/if-defined.js';
|
|
3
3
|
import { getIcon, getIconStyle } from './utils';
|
|
4
4
|
|
|
@@ -100,29 +100,42 @@ const style = `
|
|
|
100
100
|
color: #ffffff;
|
|
101
101
|
text-align: center;
|
|
102
102
|
}`,
|
|
103
|
+
renderTab =
|
|
104
|
+
({ selectedTab, onSelect, href }) =>
|
|
105
|
+
(tab, i, tabs) => {
|
|
106
|
+
const isSelected = selectedTab === tab,
|
|
107
|
+
icon = getIcon(tab, isSelected);
|
|
108
|
+
return html`<a
|
|
109
|
+
class="tab"
|
|
110
|
+
tabindex="-1"
|
|
111
|
+
role="tab"
|
|
112
|
+
part=${[
|
|
113
|
+
'tab',
|
|
114
|
+
i === 0 && 'first-tab',
|
|
115
|
+
i === tabs.length - 1 && 'last-tab',
|
|
116
|
+
isSelected && 'selected-tab',
|
|
117
|
+
]
|
|
118
|
+
.filter(Boolean)
|
|
119
|
+
.join(' ')}
|
|
120
|
+
?hidden=${tab.hidden}
|
|
121
|
+
?disabled=${tab.disabled}
|
|
122
|
+
?aria-selected=${isSelected}
|
|
123
|
+
@click=${onSelect}
|
|
124
|
+
.tab=${tab}
|
|
125
|
+
href=${ifDefined(href(tab))}
|
|
126
|
+
>
|
|
127
|
+
${icon
|
|
128
|
+
? html`<iron-icon
|
|
129
|
+
class="icon"
|
|
130
|
+
icon=${icon}
|
|
131
|
+
style=${getIconStyle(tab)}
|
|
132
|
+
></iron-icon>`
|
|
133
|
+
: ''}
|
|
134
|
+
<span>${tab.heading}</span>
|
|
135
|
+
${tab.badge
|
|
136
|
+
? html`<div class="badge" title=${tab.badge}>${tab.badge}</div>`
|
|
137
|
+
: ''}
|
|
138
|
+
</a>`;
|
|
139
|
+
};
|
|
103
140
|
|
|
104
|
-
|
|
105
|
-
selectedTab,
|
|
106
|
-
onSelect,
|
|
107
|
-
href
|
|
108
|
-
}) => (tab, i, tabs) => {
|
|
109
|
-
const isSelected = selectedTab === tab,
|
|
110
|
-
icon = getIcon(tab, isSelected);
|
|
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(' ') }
|
|
113
|
-
?hidden=${ tab.hidden } ?disabled=${ tab.disabled }
|
|
114
|
-
?aria-selected=${ isSelected }
|
|
115
|
-
@click=${ onSelect }
|
|
116
|
-
.tab=${ tab }
|
|
117
|
-
href=${ ifDefined(href(tab)) }
|
|
118
|
-
>
|
|
119
|
-
${ icon ? html `<iron-icon class="icon" icon=${ icon } style=${ getIconStyle(tab) }></iron-icon>` : '' }
|
|
120
|
-
<span>${ tab.heading }</span>
|
|
121
|
-
${ tab.badge ? html`<div class="badge" title=${ tab.badge }>${ tab.badge }</div>` : '' }
|
|
122
|
-
</a>`;
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
export {
|
|
126
|
-
style,
|
|
127
|
-
renderTab
|
|
128
|
-
};
|
|
141
|
+
export { style, renderTab };
|
package/src/use-tab.js
CHANGED
package/src/use-tabs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState, useEffect, useMemo, useCallback } from '
|
|
1
|
+
import { useState, useEffect, useMemo, useCallback } from '@pionjs/pion';
|
|
2
2
|
import { notifyProperty } from '@neovici/cosmoz-utils/hooks/use-notify-property';
|
|
3
3
|
/* eslint-disable-next-line import/no-unresolved */
|
|
4
4
|
import { useHashParam, link } from '@neovici/cosmoz-router/use-hash-param';
|