@bitrise/bitkit 13.162.1-alpha.0 → 13.162.1-alpha.2
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 +1 -1
- package/src/Components/CloseButton/CloseButton.tsx +1 -1
- package/src/Components/Dialog/Dialog.tsx +1 -1
- package/src/Components/Drawer/Drawer.tsx +1 -1
- package/src/Components/Filter/Filter.tsx +1 -1
- package/src/Components/Filter/FilterAdd/FilterAdd.tsx +1 -1
- package/src/Components/Filter/FilterItem/FilterItem.tsx +1 -1
- package/src/Components/Filter/FilterSearch/FilterSearch.tsx +1 -1
- package/src/Components/Form/Checkbox/Checkbox.tsx +1 -1
- package/src/Components/Form/FileInput/FileInput.tsx +1 -1
- package/src/Components/Icons/16x16/{CloseSmall.tsx → Cross.tsx} +2 -2
- package/src/Components/Icons/16x16/{MinusClose.tsx → Minus.tsx} +2 -2
- package/src/Components/Icons/16x16/{MinusRemove.tsx → MinusCircle.tsx} +2 -2
- package/src/Components/Icons/16x16/{PlusOpen.tsx → Plus.tsx} +2 -2
- package/src/Components/Icons/16x16/{PlusAdd.tsx → PlusCircle.tsx} +2 -2
- package/src/Components/Icons/16x16/index.ts +5 -5
- package/src/Components/Icons/24x24/{CloseSmall.tsx → Cross.tsx} +2 -2
- package/src/Components/Icons/24x24/{MinusClose.tsx → Minus.tsx} +2 -2
- package/src/Components/Icons/24x24/{MinusRemove.tsx → MinusCircle.tsx} +2 -2
- package/src/Components/Icons/24x24/{PlusOpen.tsx → Plus.tsx} +2 -2
- package/src/Components/Icons/24x24/{PlusAdd.tsx → PlusCircle.tsx} +2 -2
- package/src/Components/Icons/24x24/index.ts +5 -5
- package/src/Components/LabeledData/LabeledData.tsx +1 -1
- package/src/Components/SearchInput/SearchInput.tsx +1 -1
- package/src/Components/Tabs/ContainedTab.tsx +1 -0
- package/src/Components/Tabs/Tab.tsx +1 -0
- package/src/Components/Tabs/Tabs.tsx +76 -2
- package/src/Components/Tag/Tag.tsx +1 -1
- package/src/index.ts +0 -2
- package/src/Components/Tabs/useTabs.ts +0 -46
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@ export interface CloseButtonProps extends ChakraCloseButtonProps {
|
|
|
14
14
|
|
|
15
15
|
const CloseButton = forwardRef<CloseButtonProps, 'button'>((props, ref) => (
|
|
16
16
|
<ChakraCloseButton ref={ref} {...CloseButtonTheme.defaultProps} {...props}>
|
|
17
|
-
<Icon name="
|
|
17
|
+
<Icon name="Cross" />
|
|
18
18
|
</ChakraCloseButton>
|
|
19
19
|
));
|
|
20
20
|
|
|
@@ -52,7 +52,7 @@ const Drawer = ({ overlayProps, contentProps, headerProps, bodyProps, footerProp
|
|
|
52
52
|
<DrawerOverlay {...overlayProps} />
|
|
53
53
|
<DrawerContent maxWidth={maxWidth} padding={padding} margin={margin} {...contentProps}>
|
|
54
54
|
<DrawerCloseButton size="md">
|
|
55
|
-
<Icon name="
|
|
55
|
+
<Icon name="Cross" />
|
|
56
56
|
</DrawerCloseButton>
|
|
57
57
|
<DrawerHeader as="h3" padding={headerPadding} {...headerProps}>
|
|
58
58
|
{title}
|
|
@@ -61,7 +61,7 @@ const FilterSearch = (props: FilterSearchProps) => {
|
|
|
61
61
|
</Tooltip>
|
|
62
62
|
{!!searchValue && (
|
|
63
63
|
<InputRightElement>
|
|
64
|
-
<IconButton aria-label="Clear" iconName="
|
|
64
|
+
<IconButton aria-label="Clear" iconName="Cross" onClick={onClearClick} size="sm" variant="tertiary" />
|
|
65
65
|
</InputRightElement>
|
|
66
66
|
)}
|
|
67
67
|
</InputGroup>
|
|
@@ -34,7 +34,7 @@ const CustomIcon = (props: CheckboxIconProps) => {
|
|
|
34
34
|
if (!isChecked) {
|
|
35
35
|
return null;
|
|
36
36
|
}
|
|
37
|
-
return <Icon __css={__css} name={isIndeterminate ? '
|
|
37
|
+
return <Icon __css={__css} name={isIndeterminate ? 'Minus' : 'Check'} />;
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
/**
|
|
@@ -104,7 +104,7 @@ const FileInput = forwardRef<FileInputProps, 'div'>((props, ref) => {
|
|
|
104
104
|
</Text>
|
|
105
105
|
<Text as="span">{selectedFileNames[0]}</Text>
|
|
106
106
|
</Box>
|
|
107
|
-
<Button flexShrink={0} leftIconName="
|
|
107
|
+
<Button flexShrink={0} leftIconName="MinusCircle" onClick={onRemoveClick} size="sm" variant="secondary">
|
|
108
108
|
Remove
|
|
109
109
|
</Button>
|
|
110
110
|
</>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { forwardRef, Icon, IconProps } from '@chakra-ui/react';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const Cross = forwardRef<IconProps, 'svg'>((props, ref) => (
|
|
4
4
|
<Icon ref={ref} viewBox="0 0 16 16" {...props}>
|
|
5
5
|
<path
|
|
6
6
|
d="M7.99996 6.93954L4.99474 3.93433L3.93408 4.99499L6.9393 8.0002L3.9341 11.0054L4.99476 12.0661L7.99996 9.06086L11.0051 12.0661L12.0658 11.0054L9.06062 8.0002L12.0658 4.99499L11.0052 3.93433L7.99996 6.93954Z"
|
|
@@ -9,4 +9,4 @@ const CloseSmall = forwardRef<IconProps, 'svg'>((props, ref) => (
|
|
|
9
9
|
</Icon>
|
|
10
10
|
));
|
|
11
11
|
|
|
12
|
-
export default
|
|
12
|
+
export default Cross;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { forwardRef, Icon, IconProps } from '@chakra-ui/react';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const Minus = forwardRef<IconProps, 'svg'>((props, ref) => (
|
|
4
4
|
<Icon ref={ref} viewBox="0 0 16 16" {...props}>
|
|
5
5
|
<path clipRule="evenodd" d="M3 7.25L13 7.25L13 8.75L3 8.75L3 7.25Z" fill="currentColor" fillRule="evenodd" />
|
|
6
6
|
</Icon>
|
|
7
7
|
));
|
|
8
8
|
|
|
9
|
-
export default
|
|
9
|
+
export default Minus;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { forwardRef, Icon, IconProps } from '@chakra-ui/react';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const MinusCircle = forwardRef<IconProps, 'svg'>((props, ref) => (
|
|
4
4
|
<Icon ref={ref} viewBox="0 0 16 16" {...props}>
|
|
5
5
|
<path d="M11.5 7.25H4.5V8.75H11.5V7.25Z" fill="currentColor" />
|
|
6
6
|
<path
|
|
@@ -12,4 +12,4 @@ const MinusRemove = forwardRef<IconProps, 'svg'>((props, ref) => (
|
|
|
12
12
|
</Icon>
|
|
13
13
|
));
|
|
14
14
|
|
|
15
|
-
export default
|
|
15
|
+
export default MinusCircle;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { forwardRef, Icon, IconProps } from '@chakra-ui/react';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const Plus = forwardRef<IconProps, 'svg'>((props, ref) => (
|
|
4
4
|
<Icon ref={ref} viewBox="0 0 16 16" {...props}>
|
|
5
5
|
<path d="M8.75 7.25L8.75 3H7.25L7.25 7.25H3V8.75H7.25L7.25 13H8.75L8.75 8.75H13V7.25H8.75Z" fill="currentColor" />
|
|
6
6
|
</Icon>
|
|
7
7
|
));
|
|
8
8
|
|
|
9
|
-
export default
|
|
9
|
+
export default Plus;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { forwardRef, Icon, IconProps } from '@chakra-ui/react';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const PlusCircle = forwardRef<IconProps, 'svg'>((props, ref) => (
|
|
4
4
|
<Icon ref={ref} viewBox="0 0 16 16" {...props}>
|
|
5
5
|
<path d="M8.75 7.25H11.5V8.75H8.75V11.5H7.25V8.75H4.5V7.25H7.25V4.5H8.75V7.25Z" fill="currentColor" />
|
|
6
6
|
<path
|
|
@@ -12,4 +12,4 @@ const PlusAdd = forwardRef<IconProps, 'svg'>((props, ref) => (
|
|
|
12
12
|
</Icon>
|
|
13
13
|
));
|
|
14
14
|
|
|
15
|
-
export default
|
|
15
|
+
export default PlusCircle;
|
|
@@ -66,7 +66,7 @@ export { default as ChevronLeft } from './ChevronLeft';
|
|
|
66
66
|
export { default as ChevronRight } from './ChevronRight';
|
|
67
67
|
export { default as ChevronUp } from './ChevronUp';
|
|
68
68
|
export { default as Clock } from './Clock';
|
|
69
|
-
export { default as
|
|
69
|
+
export { default as Cross } from './Cross';
|
|
70
70
|
export { default as Code } from './Code';
|
|
71
71
|
export { default as CodeSigning } from './CodeSigning';
|
|
72
72
|
export { default as Coffee } from './Coffee';
|
|
@@ -151,8 +151,8 @@ export { default as MenuHamburger } from './MenuHamburger';
|
|
|
151
151
|
export { default as Message } from './Message';
|
|
152
152
|
export { default as MessageQuestion } from './MessageQuestion';
|
|
153
153
|
export { default as MinusCircleFilled } from './MinusCircleFilled';
|
|
154
|
-
export { default as
|
|
155
|
-
export { default as
|
|
154
|
+
export { default as Minus } from './Minus';
|
|
155
|
+
export { default as MinusCircle } from './MinusCircle';
|
|
156
156
|
export { default as Mobile } from './Mobile';
|
|
157
157
|
export { default as MonitorChart } from './MonitorChart';
|
|
158
158
|
export { default as MoreHorizontal } from './MoreHorizontal';
|
|
@@ -172,9 +172,9 @@ export { default as Pencil } from './Pencil';
|
|
|
172
172
|
export { default as Percent } from './Percent';
|
|
173
173
|
export { default as Person } from './Person';
|
|
174
174
|
export { default as Play } from './Play';
|
|
175
|
-
export { default as
|
|
175
|
+
export { default as PlusCircle } from './PlusCircle';
|
|
176
176
|
export { default as PlusCircleFilled } from './PlusCircleFilled';
|
|
177
|
-
export { default as
|
|
177
|
+
export { default as Plus } from './Plus';
|
|
178
178
|
export { default as Podcast } from './Podcast';
|
|
179
179
|
export { default as Power } from './Power';
|
|
180
180
|
export { default as Pull } from './Pull';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { forwardRef, Icon, IconProps } from '@chakra-ui/react';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const Cross = forwardRef<IconProps, 'svg'>((props, ref) => (
|
|
4
4
|
<Icon ref={ref} viewBox="0 0 24 24" {...props}>
|
|
5
5
|
<path
|
|
6
6
|
d="M12 13.4143L16.5426 17.9569C16.5426 17.9569 16.5428 17.9572 17.25 17.2501C17.9571 16.543 17.957 16.5429 17.957 16.5429L13.4142 12.0001L17.9571 7.45718L16.5428 6.04297L12 10.5859L7.45706 6.04297L6.04285 7.45718L10.5857 12.0001L6.04285 16.543L7.45706 17.9572L12 13.4143Z"
|
|
@@ -9,4 +9,4 @@ const CloseSmall = forwardRef<IconProps, 'svg'>((props, ref) => (
|
|
|
9
9
|
</Icon>
|
|
10
10
|
));
|
|
11
11
|
|
|
12
|
-
export default
|
|
12
|
+
export default Cross;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { forwardRef, Icon, IconProps } from '@chakra-ui/react';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const Minus = forwardRef<IconProps, 'svg'>((props, ref) => (
|
|
4
4
|
<Icon ref={ref} viewBox="0 0 24 24" {...props}>
|
|
5
5
|
<path clipRule="evenodd" d="M18 13H6V11H18V13Z" fill="currentColor" fillRule="evenodd" />
|
|
6
6
|
</Icon>
|
|
7
7
|
));
|
|
8
8
|
|
|
9
|
-
export default
|
|
9
|
+
export default Minus;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { forwardRef, Icon, IconProps } from '@chakra-ui/react';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const MinusCircle = forwardRef<IconProps, 'svg'>((props, ref) => (
|
|
4
4
|
<Icon ref={ref} viewBox="0 0 24 24" {...props}>
|
|
5
5
|
<path d="M7 13H17V11H7V13Z" fill="currentColor" />
|
|
6
6
|
<path
|
|
@@ -12,4 +12,4 @@ const MinusRemove = forwardRef<IconProps, 'svg'>((props, ref) => (
|
|
|
12
12
|
</Icon>
|
|
13
13
|
));
|
|
14
14
|
|
|
15
|
-
export default
|
|
15
|
+
export default MinusCircle;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { forwardRef, Icon, IconProps } from '@chakra-ui/react';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const Plus = forwardRef<IconProps, 'svg'>((props, ref) => (
|
|
4
4
|
<Icon ref={ref} viewBox="0 0 24 24" {...props}>
|
|
5
5
|
<path d="M11 13V18H13V13H18V11H13V6H11V11H6V13H11Z" fill="currentColor" />
|
|
6
6
|
</Icon>
|
|
7
7
|
));
|
|
8
8
|
|
|
9
|
-
export default
|
|
9
|
+
export default Plus;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { forwardRef, Icon, IconProps } from '@chakra-ui/react';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const PlusCircle = forwardRef<IconProps, 'svg'>((props, ref) => (
|
|
4
4
|
<Icon ref={ref} viewBox="0 0 24 24" {...props}>
|
|
5
5
|
<path d="M11 13H7V11H11V7H13V11H17V13H13V17H11V13Z" fill="currentColor" />
|
|
6
6
|
<path
|
|
@@ -12,4 +12,4 @@ const PlusAdd = forwardRef<IconProps, 'svg'>((props, ref) => (
|
|
|
12
12
|
</Icon>
|
|
13
13
|
));
|
|
14
14
|
|
|
15
|
-
export default
|
|
15
|
+
export default PlusCircle;
|
|
@@ -63,7 +63,7 @@ export { default as ChevronLeft } from './ChevronLeft';
|
|
|
63
63
|
export { default as ChevronRight } from './ChevronRight';
|
|
64
64
|
export { default as ChevronUp } from './ChevronUp';
|
|
65
65
|
export { default as Clock } from './Clock';
|
|
66
|
-
export { default as
|
|
66
|
+
export { default as Cross } from './Cross';
|
|
67
67
|
export { default as Code } from './Code';
|
|
68
68
|
export { default as CodeSigning } from './CodeSigning';
|
|
69
69
|
export { default as Coffee } from './Coffee';
|
|
@@ -149,8 +149,8 @@ export { default as MenuHamburger } from './MenuHamburger';
|
|
|
149
149
|
export { default as Message } from './Message';
|
|
150
150
|
export { default as MessageQuestion } from './MessageQuestion';
|
|
151
151
|
export { default as MinusCircleFilled } from './MinusCircleFilled';
|
|
152
|
-
export { default as
|
|
153
|
-
export { default as
|
|
152
|
+
export { default as Minus } from './Minus';
|
|
153
|
+
export { default as MinusCircle } from './MinusCircle';
|
|
154
154
|
export { default as Mobile } from './Mobile';
|
|
155
155
|
export { default as MonitorChart } from './MonitorChart';
|
|
156
156
|
export { default as MoreHorizontal } from './MoreHorizontal';
|
|
@@ -170,9 +170,9 @@ export { default as Pencil } from './Pencil';
|
|
|
170
170
|
export { default as Percent } from './Percent';
|
|
171
171
|
export { default as Person } from './Person';
|
|
172
172
|
export { default as Play } from './Play';
|
|
173
|
-
export { default as
|
|
173
|
+
export { default as PlusCircle } from './PlusCircle';
|
|
174
174
|
export { default as PlusCircleFilled } from './PlusCircleFilled';
|
|
175
|
-
export { default as
|
|
175
|
+
export { default as Plus } from './Plus';
|
|
176
176
|
export { default as Podcast } from './Podcast';
|
|
177
177
|
export { default as Power } from './Power';
|
|
178
178
|
export { default as Pull } from './Pull';
|
|
@@ -1,18 +1,92 @@
|
|
|
1
|
+
import React, { isValidElement, ReactElement, useEffect, useState } from 'react';
|
|
1
2
|
import { forwardRef, Tabs as ChakraTabs, TabsProps as ChakraTabsProps } from '@chakra-ui/react';
|
|
3
|
+
import { useHistory } from '../../hooks';
|
|
4
|
+
import { TabProps } from './Tab';
|
|
2
5
|
|
|
3
6
|
export interface TabsProps extends ChakraTabsProps {
|
|
4
7
|
defaultTab?: string;
|
|
5
8
|
onChange?: (index: number, tabId?: string) => void;
|
|
6
9
|
tabId?: string;
|
|
7
10
|
variant?: 'contained' | 'line';
|
|
11
|
+
withHistory?: boolean;
|
|
8
12
|
}
|
|
9
13
|
|
|
14
|
+
const getTabIds = (props: TabsProps): string[] => {
|
|
15
|
+
const tabList = React.Children.toArray(props.children)[0] as ReactElement;
|
|
16
|
+
const tabs = React.Children.toArray(tabList.props.children) as ReactElement[];
|
|
17
|
+
|
|
18
|
+
return tabs.filter((item) => isValidElement(item)).map((item) => (item.props as TabProps).id || '');
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const getTabIndexFromSearchParams = (tabIds: string[], tabIndex?: number) => {
|
|
22
|
+
if (typeof window === 'undefined') {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
27
|
+
const tabName = searchParams.get('tab');
|
|
28
|
+
if (!tabName) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const index = tabIds.indexOf(tabName);
|
|
33
|
+
if (index === -1) {
|
|
34
|
+
return tabIndex;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return index;
|
|
38
|
+
};
|
|
39
|
+
|
|
10
40
|
/**
|
|
11
41
|
* An accessible tabs component that provides keyboard interactions and ARIA attributes described in the WAI-ARIA Tabs Design Pattern.
|
|
12
42
|
*/
|
|
13
43
|
const Tabs = forwardRef<TabsProps, 'div'>((props, ref) => {
|
|
14
|
-
const { variant = 'line', ...rest } = props;
|
|
15
|
-
|
|
44
|
+
const { defaultTab = '', onChange, tabId, variant = 'line', withHistory, ...rest } = props;
|
|
45
|
+
const { replace } = useHistory();
|
|
46
|
+
|
|
47
|
+
const tabIds = getTabIds(props);
|
|
48
|
+
|
|
49
|
+
let tabIndex = 0;
|
|
50
|
+
|
|
51
|
+
if (defaultTab) {
|
|
52
|
+
tabIndex = tabIds.includes(defaultTab) ? tabIds.indexOf(defaultTab) : 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (tabId) {
|
|
56
|
+
tabIndex = tabIds.includes(tabId) ? tabIds.indexOf(tabId) : 0;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const [actualIndex, setActualIndex] = useState(
|
|
60
|
+
withHistory ? getTabIndexFromSearchParams(tabIds, tabIndex) : tabIndex,
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const onTabChange = (index: number) => {
|
|
64
|
+
const newTabId = tabIds[index];
|
|
65
|
+
|
|
66
|
+
if (withHistory) {
|
|
67
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
68
|
+
if (newTabId) {
|
|
69
|
+
searchParams.set('tab', newTabId);
|
|
70
|
+
} else {
|
|
71
|
+
searchParams.delete('tab');
|
|
72
|
+
}
|
|
73
|
+
replace(`?${searchParams.toString()}`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (onChange) {
|
|
77
|
+
onChange(index, newTabId);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
setActualIndex(index);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
if (tabId) {
|
|
85
|
+
setActualIndex(tabIds.includes(tabId) ? tabIds.indexOf(tabId) : 0);
|
|
86
|
+
}
|
|
87
|
+
}, [tabId]);
|
|
88
|
+
|
|
89
|
+
return <ChakraTabs {...rest} ref={ref} index={actualIndex} onChange={onTabChange} variant={variant} />;
|
|
16
90
|
});
|
|
17
91
|
|
|
18
92
|
export default Tabs;
|
|
@@ -67,7 +67,7 @@ const Tag = forwardRef<TagProps, 'span'>((props, ref) => {
|
|
|
67
67
|
{!!onClose && (
|
|
68
68
|
<Tooltip isDisabled={!closeButtonTooltip} label={closeButtonTooltip}>
|
|
69
69
|
<TagCloseButton isDisabled={isDisabled || isLoading} onClick={onClose}>
|
|
70
|
-
<Icon name="
|
|
70
|
+
<Icon name="Cross" size="16" />
|
|
71
71
|
</TagCloseButton>
|
|
72
72
|
</Tooltip>
|
|
73
73
|
)}
|
package/src/index.ts
CHANGED
|
@@ -58,8 +58,6 @@ export { default as TabPanels } from './Components/Tabs/TabPanels';
|
|
|
58
58
|
export type { TabPanelProps } from './Components/Tabs/TabPanel';
|
|
59
59
|
export { default as TabPanel } from './Components/Tabs/TabPanel';
|
|
60
60
|
|
|
61
|
-
export { default as useTabs } from './Components/Tabs/useTabs';
|
|
62
|
-
|
|
63
61
|
export type { BadgeProps } from './Components/Badge/Badge';
|
|
64
62
|
export { default as Badge } from './Components/Badge/Badge';
|
|
65
63
|
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
|
-
|
|
3
|
-
type UseTabsProps<T> = {
|
|
4
|
-
defaultId?: T;
|
|
5
|
-
queryKey?: string;
|
|
6
|
-
tabIds: T[];
|
|
7
|
-
withHistory?: boolean;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
const useTabs = <T extends string>(props: UseTabsProps<T>) => {
|
|
11
|
-
const { defaultId, queryKey = 'tab', tabIds, withHistory } = props;
|
|
12
|
-
|
|
13
|
-
const searchParams = new URLSearchParams(window.location.search);
|
|
14
|
-
|
|
15
|
-
const defaultIndex = useMemo(() => {
|
|
16
|
-
if (withHistory && searchParams.get(queryKey)) {
|
|
17
|
-
return tabIds.indexOf(searchParams.get(queryKey) as T);
|
|
18
|
-
}
|
|
19
|
-
if (defaultId) {
|
|
20
|
-
return tabIds.indexOf(defaultId);
|
|
21
|
-
}
|
|
22
|
-
return 0;
|
|
23
|
-
}, []);
|
|
24
|
-
|
|
25
|
-
const [tabIndex, setTabIndex] = useState(defaultIndex);
|
|
26
|
-
|
|
27
|
-
const setTabId = useCallback((id: T) => {
|
|
28
|
-
setTabIndex(tabIds.indexOf(id));
|
|
29
|
-
}, []);
|
|
30
|
-
|
|
31
|
-
useEffect(() => {
|
|
32
|
-
if (withHistory) {
|
|
33
|
-
searchParams.set(queryKey, tabIds[tabIndex]);
|
|
34
|
-
window.parent.history.replaceState(null, '', `?${decodeURIComponent(searchParams.toString())}`);
|
|
35
|
-
}
|
|
36
|
-
}, [tabIndex]);
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
setTabId,
|
|
40
|
-
setTabIndex,
|
|
41
|
-
tabId: tabIds[tabIndex],
|
|
42
|
-
tabIndex,
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export default useTabs;
|