@bitrise/bitkit 9.17.0-alpha-chakra.3 → 9.17.0-alpha-chakra.4

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": "9.17.0-alpha-chakra.3",
4
+ "version": "9.17.0-alpha-chakra.4",
5
5
  "repository": "git@github.com:bitrise-io/bitkit.git",
6
6
  "main": "src/index.ts",
7
7
  "license": "UNLICENSED",
@@ -9,6 +9,11 @@ export default {
9
9
  title: 'Components/Tabs',
10
10
  component: Tabs,
11
11
  subcomponents: { Tab },
12
+ argTypes: {
13
+ onChange: {
14
+ action: 'onChange event',
15
+ },
16
+ },
12
17
  } as ComponentMeta<typeof Tabs>;
13
18
 
14
19
  const badge = {
@@ -17,11 +22,11 @@ const badge = {
17
22
  color: 'neutral.10',
18
23
  };
19
24
 
20
- export const WithDefaults: ComponentStory<typeof Tabs> = () => {
25
+ export const WithDefaults: ComponentStory<typeof Tabs> = (props) => {
21
26
  return (
22
- <Tabs defaultIndex={1} variant="unstyled" withHistory>
27
+ <Tabs defaultIndex={1} variant="unstyled" {...props}>
23
28
  <TabList>
24
- <Tab id="default">Default</Tab>
29
+ <Tab id="basic">Basic</Tab>
25
30
  <Tab id="selected-as-default">Selected as default</Tab>
26
31
  <Tab leftIconName="Bell">With left icon</Tab>
27
32
  <Tab id="with-badge" badge={badge}>
@@ -50,3 +55,7 @@ export const WithDefaults: ComponentStory<typeof Tabs> = () => {
50
55
  </Tabs>
51
56
  );
52
57
  };
58
+
59
+ WithDefaults.args = {
60
+ withHistory: true,
61
+ };
@@ -3,6 +3,7 @@ import { Tabs as ChakraTabs, TabsProps as ChakraTabsProps, forwardRef } from '@c
3
3
  import { useHistory } from '../../hooks';
4
4
 
5
5
  export interface TabsProps extends ChakraTabsProps {
6
+ onChange?: (index: number, tabId?: string) => void;
6
7
  withHistory?: boolean;
7
8
  }
8
9
 
@@ -34,17 +35,18 @@ const Tabs = forwardRef<TabsProps, 'div'>((props, ref) => {
34
35
  }, []);
35
36
 
36
37
  const onTabChange = (index: number) => {
38
+ const tabId = tabIds[index];
37
39
  setActualIndex(index);
38
40
  if (withHistory) {
39
- if (tabIds[index]) {
40
- searchParams.set('tab', tabIds[index]);
41
+ if (tabId) {
42
+ searchParams.set('tab', tabId);
41
43
  } else {
42
44
  searchParams.delete('tab');
43
45
  }
44
46
  replace(`?${searchParams.toString()}`);
45
47
  }
46
48
  if (onChange) {
47
- onChange(index);
49
+ onChange(index, tabId);
48
50
  }
49
51
  };
50
52
  return <ChakraTabs {...rest} ref={ref} onChange={onTabChange} index={actualIndex} />;