@bitrise/bitkit 13.210.0 → 13.210.1-alpha.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bitrise/bitkit",
3
3
  "description": "Bitrise React component library",
4
- "version": "13.210.0",
4
+ "version": "13.210.1-alpha.1",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+ssh://git@github.com/bitrise-io/bitkit.git"
@@ -2,23 +2,16 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
2
2
 
3
3
  type UseTabsProps<T> = {
4
4
  defaultId?: T;
5
- queryKey?: string;
5
+ onChange?: (id: T, index: number) => void;
6
6
  tabIds: T[];
7
+ queryKey?: string;
7
8
  withHistory?: boolean;
8
9
  };
9
10
 
10
11
  const useTabs = <T extends string>(props: UseTabsProps<T>) => {
11
- const { defaultId, queryKey = 'tab', tabIds, withHistory } = props;
12
-
13
- let searchParams = new URLSearchParams(window.location.search);
12
+ const { defaultId, onChange, tabIds } = props;
14
13
 
15
14
  const defaultIndex = useMemo(() => {
16
- if (withHistory && searchParams.get(queryKey)) {
17
- const tabIndex = tabIds.indexOf(searchParams.get(queryKey) as T);
18
- if (tabIndex !== -1) {
19
- return tabIndex;
20
- }
21
- }
22
15
  if (defaultId) {
23
16
  const tabIndex = tabIds.indexOf(defaultId);
24
17
  if (tabIndex !== -1) {
@@ -35,11 +28,9 @@ const useTabs = <T extends string>(props: UseTabsProps<T>) => {
35
28
  }, []);
36
29
 
37
30
  useEffect(() => {
38
- const queryValue = tabIds[tabIndex];
39
- if (withHistory && queryValue) {
40
- searchParams = new URLSearchParams(window.location.search);
41
- searchParams.set(queryKey, queryValue);
42
- window.parent.history.replaceState(null, '', `?${decodeURIComponent(searchParams.toString())}`);
31
+ if (onChange) {
32
+ const id = tabIds[tabIndex];
33
+ onChange(id, tabIndex);
43
34
  }
44
35
  }, [tabIndex]);
45
36