@bitrise/bitkit 10.10.0-alpha-dropdown-release.4 → 10.11.0-alpha-chakra.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.10.0-alpha-dropdown-release.4",
4
+ "version": "10.11.0-alpha-chakra.2",
5
5
  "repository": "git@github.com:bitrise-io/bitkit.git",
6
6
  "main": "src/index.ts",
7
7
  "license": "UNLICENSED",
@@ -0,0 +1,56 @@
1
+ import { MouseEvent } from 'react';
2
+ import { ComponentStory, ComponentMeta } from '@storybook/react';
3
+ import Box from '../Box/Box';
4
+ import Button from '../Button/Button';
5
+ import Icon from '../Icon/Icon';
6
+ import Text from '../Text/Text';
7
+ import Accordion from './Accordion';
8
+ import AccordionItem from './AccordionItem';
9
+
10
+ export default {
11
+ title: 'Components/Accordion',
12
+ component: Accordion,
13
+ args: {
14
+ colorScheme: 'white',
15
+ },
16
+ argTypes: {
17
+ onChange: {
18
+ action: 'onChange event',
19
+ },
20
+ },
21
+ subcomponents: { AccordionItem },
22
+ } as ComponentMeta<typeof Accordion>;
23
+
24
+ const onButtonClick = (e: MouseEvent<HTMLButtonElement>) => {
25
+ e.stopPropagation();
26
+ };
27
+
28
+ const ButtonContentElement = () => {
29
+ return (
30
+ <Box display="flex" alignItems="center" flexGrow={1}>
31
+ <Icon name="Doc" />
32
+ <Text as="p" align="left" size="3" margin="0 auto 0 1rem">
33
+ The buttonContent is a React element
34
+ <br />
35
+ <Text as="span" size="2" textColor="neutral.40">
36
+ Generated by clone-build workflow
37
+ </Text>
38
+ </Text>
39
+ <Button as="a" size="small" onClick={onButtonClick} leftIconName="Download">
40
+ Download
41
+ </Button>
42
+ </Box>
43
+ );
44
+ };
45
+
46
+ export const DefaultVariant: ComponentStory<typeof Accordion> = (props) => (
47
+ <Accordion {...props} marginLeft="32">
48
+ <AccordionItem buttonContent="The buttonContent is a string" fontSize="2" id="first">
49
+ Content - you can use any style prop on AccordionItem
50
+ </AccordionItem>
51
+ <AccordionItem buttonContent={<ButtonContentElement />} fontSize="2" id="second">
52
+ Content - you can use any style prop on AccordionItem
53
+ </AccordionItem>
54
+ <AccordionItem buttonContent="Without children the button is disabled" id="third" />
55
+ </Accordion>
56
+ );
@@ -0,0 +1,42 @@
1
+ import type { ComponentStyleConfig } from '@chakra-ui/theme';
2
+
3
+ const AccordionTheme: ComponentStyleConfig = {
4
+ baseStyle: ({ colorScheme }) => ({
5
+ item: {
6
+ border: '1px solid',
7
+ borderColor: 'neutral.93',
8
+ borderRadius: '8',
9
+ boxShadow: 'small',
10
+ overflow: 'hidden',
11
+ marginBottom: '16',
12
+ },
13
+ button: {
14
+ width: '100%',
15
+ padding: '16',
16
+ background: colorScheme === 'gray' ? 'neutral.95' : 'neutral.100',
17
+ borderBottom: '1px solid',
18
+ borderColor: 'neutral.93',
19
+ justifyContent: 'space-between',
20
+ _hover: {
21
+ background: 'purple.95',
22
+ },
23
+ _disabled: {
24
+ pointerEvents: 'none',
25
+ },
26
+ _focusVisible: {
27
+ background: 'purple.95',
28
+ boxShadow: 'none',
29
+ },
30
+ },
31
+ icon: {
32
+ width: '24',
33
+ height: '24',
34
+ marginLeft: '16',
35
+ },
36
+ panel: {
37
+ padding: '16',
38
+ },
39
+ }),
40
+ };
41
+
42
+ export default AccordionTheme;
@@ -0,0 +1,55 @@
1
+ import { Children } from 'react';
2
+ import {
3
+ Accordion as ChakraAccordion,
4
+ AccordionProps as ChakraAccordionProps,
5
+ ExpandedIndex,
6
+ usePrefersReducedMotion,
7
+ } from '@chakra-ui/react';
8
+
9
+ export interface AccordionProps extends Omit<ChakraAccordionProps, 'onChange'> {
10
+ colorScheme?: 'white' | 'gray';
11
+ onChange?: (ids: string[], indexes: number[]) => void;
12
+ }
13
+
14
+ const getItemIds = (props: AccordionProps) => {
15
+ const ids: string[] = [];
16
+ const items = Children.toArray(props.children);
17
+ items.forEach((item: any, index: number) => {
18
+ ids[index] = item?.props?.id;
19
+ });
20
+ return ids;
21
+ };
22
+
23
+ const Accordion = (props: AccordionProps) => {
24
+ const prefersReducedMotion = usePrefersReducedMotion();
25
+ const { children, colorScheme, onChange, ...rest } = props;
26
+ const itemIds = getItemIds(props);
27
+
28
+ const onAccordionChange = (indexes: ExpandedIndex) => {
29
+ if (onChange) {
30
+ const indexArray = Object.values(indexes).sort();
31
+ onChange(
32
+ indexArray.map((i: number) => itemIds[i]),
33
+ indexArray,
34
+ );
35
+ }
36
+ };
37
+
38
+ return (
39
+ <ChakraAccordion
40
+ allowMultiple
41
+ allowToggle
42
+ colorScheme={colorScheme}
43
+ reduceMotion={prefersReducedMotion}
44
+ onChange={onAccordionChange}
45
+ {...rest}
46
+ >
47
+ {children}
48
+ </ChakraAccordion>
49
+ );
50
+ };
51
+
52
+ Accordion.defaultProps = {
53
+ colorScheme: 'white',
54
+ };
55
+ export default Accordion;
@@ -0,0 +1,34 @@
1
+ import { ReactNode, isValidElement } from 'react';
2
+ import {
3
+ AccordionItem as ChakraAccordionItem,
4
+ AccordionItemProps as ChakraAccordionItemProps,
5
+ AccordionButton,
6
+ AccordionPanel,
7
+ AccordionPanelProps,
8
+ AccordionIcon,
9
+ useMultiStyleConfig,
10
+ } from '@chakra-ui/react';
11
+ import Text from '../Text/Text';
12
+
13
+ export interface AccordionItemProps extends AccordionPanelProps {
14
+ buttonContent: ReactNode;
15
+ children?: ReactNode;
16
+ id?: ChakraAccordionItemProps['id'];
17
+ }
18
+
19
+ const AccordionItem = (props: AccordionItemProps) => {
20
+ const { buttonContent, children, id, ...rest } = props;
21
+ const styles = useMultiStyleConfig('Accordion');
22
+
23
+ return (
24
+ <ChakraAccordionItem sx={styles.item} id={id} isDisabled={!children}>
25
+ <AccordionButton>
26
+ {isValidElement(buttonContent) ? buttonContent : <Text as="span">{buttonContent}</Text>}
27
+ <AccordionIcon />
28
+ </AccordionButton>
29
+ {!!children && <AccordionPanel {...rest}>{children}</AccordionPanel>}
30
+ </ChakraAccordionItem>
31
+ );
32
+ };
33
+
34
+ export default AccordionItem;
package/src/index.ts CHANGED
@@ -153,3 +153,9 @@ export {
153
153
  } from './Components/Dropdown/Dropdown';
154
154
 
155
155
  export { BREAKPOINTS } from './Foundations/Breakpoints/Breakpoints';
156
+
157
+ export type { AccordionProps } from './Components/Accordion/Accordion';
158
+ export { default as Accordion } from './Components/Accordion/Accordion';
159
+
160
+ export type { AccordionItemProps } from './Components/Accordion/AccordionItem';
161
+ export { default as AccordionItem } from './Components/Accordion/AccordionItem';
package/src/theme.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import Accordion from './Components/Accordion/Accordion.theme';
1
2
  import Avatar from './Components/Avatar/Avatar.theme';
2
3
  import Badge from './Components/Badge/Badge.theme';
3
4
  import Breadcrumb from './Components/Breadcrumb/Breadcrumb.theme';
@@ -66,6 +67,7 @@ const theme = {
66
67
  },
67
68
  },
68
69
  components: {
70
+ Accordion,
69
71
  Avatar,
70
72
  Badge,
71
73
  Breadcrumb,