@neovici/cosmoz-tabs 7.5.0 → 7.6.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neovici/cosmoz-tabs",
3
- "version": "7.5.0",
3
+ "version": "7.6.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"
@@ -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: P
34
+ opts?: P
34
35
  ) => Result<T>;
35
36
 
36
37
  export interface RenderOptions<T extends RenderTab> {
@@ -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
- onActivate = useCallback(
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