@bitrise/bitkit 10.11.0-alpha-chakra.2 → 10.11.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bitrise/bitkit",
3
3
  "description": "Bitrise React component library",
4
- "version": "10.11.0-alpha-chakra.2",
4
+ "version": "10.11.2",
5
5
  "repository": "git@github.com:bitrise-io/bitkit.git",
6
6
  "main": "src/index.ts",
7
7
  "license": "UNLICENSED",
@@ -25,18 +25,18 @@ const onButtonClick = (e: MouseEvent<HTMLButtonElement>) => {
25
25
  e.stopPropagation();
26
26
  };
27
27
 
28
- const ButtonContentElement = () => {
28
+ const ButtonContentElement = ({ title }: { title: string }) => {
29
29
  return (
30
30
  <Box display="flex" alignItems="center" flexGrow={1}>
31
31
  <Icon name="Doc" />
32
32
  <Text as="p" align="left" size="3" margin="0 auto 0 1rem">
33
- The buttonContent is a React element
33
+ {title}
34
34
  <br />
35
35
  <Text as="span" size="2" textColor="neutral.40">
36
36
  Generated by clone-build workflow
37
37
  </Text>
38
38
  </Text>
39
- <Button as="a" size="small" onClick={onButtonClick} leftIconName="Download">
39
+ <Button as="a" href="#" size="small" onClick={onButtonClick} leftIconName="Download">
40
40
  Download
41
41
  </Button>
42
42
  </Box>
@@ -48,9 +48,13 @@ export const DefaultVariant: ComponentStory<typeof Accordion> = (props) => (
48
48
  <AccordionItem buttonContent="The buttonContent is a string" fontSize="2" id="first">
49
49
  Content - you can use any style prop on AccordionItem
50
50
  </AccordionItem>
51
- <AccordionItem buttonContent={<ButtonContentElement />} fontSize="2" id="second">
51
+ <AccordionItem
52
+ buttonContent={<ButtonContentElement title="The buttonContent is a React element" />}
53
+ fontSize="2"
54
+ id="second"
55
+ >
52
56
  Content - you can use any style prop on AccordionItem
53
57
  </AccordionItem>
54
- <AccordionItem buttonContent="Without children the button is disabled" id="third" />
58
+ <AccordionItem buttonContent={<ButtonContentElement title="Without children" />} id="third" />
55
59
  </Accordion>
56
60
  );
@@ -0,0 +1,34 @@
1
+ import { render, screen } from '@testing-library/react';
2
+ import userEvent from '@testing-library/user-event';
3
+ import Accordion from './Accordion';
4
+ import AccordionItem from './AccordionItem';
5
+
6
+ describe('Accordion', () => {
7
+ it('calls the onChange handler with the proper id if Accordion has a conditionally not rendered item', async () => {
8
+ const thirdId = 'third-item';
9
+ const thirdTitle = 'Third item';
10
+
11
+ const handleChange = jest.fn();
12
+
13
+ render(
14
+ <Accordion onChange={handleChange}>
15
+ <AccordionItem id="first" buttonContent="First item">
16
+ First content
17
+ </AccordionItem>
18
+ {false && (
19
+ <AccordionItem id="second" buttonContent="Second item">
20
+ Second content
21
+ </AccordionItem>
22
+ )}
23
+ <AccordionItem id={thirdId} buttonContent={thirdTitle}>
24
+ Third content
25
+ </AccordionItem>
26
+ </Accordion>,
27
+ );
28
+
29
+ const thirdTab = await screen.findByText(thirdTitle);
30
+ await userEvent.click(thirdTab);
31
+
32
+ expect(handleChange).toHaveBeenCalledWith(['third-item'], [1]);
33
+ });
34
+ });
@@ -7,25 +7,24 @@ const AccordionTheme: ComponentStyleConfig = {
7
7
  borderColor: 'neutral.93',
8
8
  borderRadius: '8',
9
9
  boxShadow: 'small',
10
- overflow: 'hidden',
11
10
  marginBottom: '16',
12
11
  },
13
12
  button: {
13
+ display: 'flex',
14
+ alignItems: 'center',
15
+ justifyContent: 'space-between',
14
16
  width: '100%',
15
17
  padding: '16',
16
18
  background: colorScheme === 'gray' ? 'neutral.95' : 'neutral.100',
17
19
  borderBottom: '1px solid',
18
20
  borderColor: 'neutral.93',
19
- justifyContent: 'space-between',
20
- _hover: {
21
+ borderRadius: '8',
22
+ '&[type="button"]:hover': {
21
23
  background: 'purple.95',
22
24
  },
23
- _disabled: {
24
- pointerEvents: 'none',
25
- },
26
- _focusVisible: {
27
- background: 'purple.95',
28
- boxShadow: 'none',
25
+ '&[aria-expanded="true"]': {
26
+ borderBottomLeftRadius: '0',
27
+ borderBottomRightRadius: '0',
29
28
  },
30
29
  },
31
30
  icon: {
@@ -20,6 +20,9 @@ const getItemIds = (props: AccordionProps) => {
20
20
  return ids;
21
21
  };
22
22
 
23
+ /**
24
+ * Accordions display a list of high-level options that can expand/collapse to reveal more information.
25
+ */
23
26
  const Accordion = (props: AccordionProps) => {
24
27
  const prefersReducedMotion = usePrefersReducedMotion();
25
28
  const { children, colorScheme, onChange, ...rest } = props;
@@ -8,6 +8,7 @@ import {
8
8
  AccordionIcon,
9
9
  useMultiStyleConfig,
10
10
  } from '@chakra-ui/react';
11
+ import Box from '../Box/Box';
11
12
  import Text from '../Text/Text';
12
13
 
13
14
  export interface AccordionItemProps extends AccordionPanelProps {
@@ -20,12 +21,14 @@ const AccordionItem = (props: AccordionItemProps) => {
20
21
  const { buttonContent, children, id, ...rest } = props;
21
22
  const styles = useMultiStyleConfig('Accordion');
22
23
 
24
+ const ButtonComponent = children ? AccordionButton : Box;
25
+
23
26
  return (
24
- <ChakraAccordionItem sx={styles.item} id={id} isDisabled={!children}>
25
- <AccordionButton>
27
+ <ChakraAccordionItem sx={styles.item} id={id}>
28
+ <ButtonComponent sx={styles.button}>
26
29
  {isValidElement(buttonContent) ? buttonContent : <Text as="span">{buttonContent}</Text>}
27
- <AccordionIcon />
28
- </AccordionButton>
30
+ <AccordionIcon opacity={children ? 1 : 0.4} />
31
+ </ButtonComponent>
29
32
  {!!children && <AccordionPanel {...rest}>{children}</AccordionPanel>}
30
33
  </ChakraAccordionItem>
31
34
  );
@@ -0,0 +1,36 @@
1
+ import { render, screen } from '@testing-library/react';
2
+ import userEvent from '@testing-library/user-event';
3
+ import Tabs from './Tabs';
4
+ import TabList from './TabList';
5
+ import Tab from './Tab';
6
+ import TabPanels from './TabPanels';
7
+ import TabPanel from './TabPanel';
8
+
9
+ describe('Tabs', () => {
10
+ it('calls the onChange handler with the proper id if TabList has a conditionally not rendered item', async () => {
11
+ const thirdTabId = 'third-tab';
12
+ const thirdTabTitle = 'Third tab';
13
+
14
+ const handleChange = jest.fn();
15
+
16
+ render(
17
+ <Tabs onChange={handleChange}>
18
+ <TabList>
19
+ <Tab id="first-tab">First tab</Tab>
20
+ {false && <Tab id="second-tab">Second tab</Tab>}
21
+ <Tab id={thirdTabId}>{thirdTabTitle}</Tab>
22
+ </TabList>
23
+ <TabPanels>
24
+ <TabPanel>First content</TabPanel>
25
+ {false && <TabPanel>Second content</TabPanel>}
26
+ <TabPanel>Third content</TabPanel>
27
+ </TabPanels>
28
+ </Tabs>,
29
+ );
30
+
31
+ const thirdTab = await screen.findByText(thirdTabTitle);
32
+ await userEvent.click(thirdTab);
33
+
34
+ expect(handleChange).toHaveBeenCalledWith(1, thirdTabId);
35
+ });
36
+ });
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useState } from 'react';
1
+ import React, { isValidElement, ReactElement, useEffect, useState } from 'react';
2
2
  import { Tabs as ChakraTabs, TabsProps as ChakraTabsProps, forwardRef } from '@chakra-ui/react';
3
3
  import { useHistory } from '../../hooks';
4
4
 
@@ -8,13 +8,11 @@ export interface TabsProps extends ChakraTabsProps {
8
8
  withHistory?: boolean;
9
9
  }
10
10
 
11
- const getTabIds = (props: TabsProps) => {
12
- const ids: string[] = [];
13
- const tabs = React.Children.toArray(props.children)[0] as any;
14
- React.Children.forEach(tabs.props.children, (c, index) => {
15
- ids[index] = c?.props?.id;
16
- });
17
- return ids;
11
+ const getTabIds = (props: TabsProps): string[] => {
12
+ const tabList = React.Children.toArray(props.children)[0] as ReactElement;
13
+ const tabs = React.Children.toArray(tabList.props.children) as ReactElement[];
14
+
15
+ return tabs.filter((item) => isValidElement(item)).map((item) => item.props.id);
18
16
  };
19
17
 
20
18
  /**