@bitrise/bitkit 11.3.1-alpha-chakra.2 → 11.4.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": "11.3.1-alpha-chakra.2",
4
+ "version": "11.4.1",
5
5
  "repository": "git@github.com:bitrise-io/bitkit.git",
6
6
  "main": "src/index.ts",
7
7
  "license": "UNLICENSED",
@@ -0,0 +1,33 @@
1
+ import {
2
+ Accordion as ChakraAccordion,
3
+ AccordionProps as ChakraAccordionProps,
4
+ usePrefersReducedMotion,
5
+ } from '@chakra-ui/react';
6
+
7
+ export type AccordionProps = Omit<ChakraAccordionProps, 'onChange' | 'defaultIndex'> & {
8
+ defaultIndex: number[];
9
+ };
10
+
11
+ /**
12
+ * Accordions display a list of high-level options that can expand/collapse to reveal more information.
13
+ */
14
+ const Accordion = (props: AccordionProps) => {
15
+ const prefersReducedMotion = usePrefersReducedMotion({ ssr: false });
16
+ const { children, colorScheme, defaultIndex, variant, ...rest } = props;
17
+
18
+ return (
19
+ <ChakraAccordion
20
+ allowMultiple
21
+ allowToggle
22
+ colorScheme={colorScheme}
23
+ variant={variant}
24
+ reduceMotion={prefersReducedMotion}
25
+ defaultIndex={defaultIndex}
26
+ {...rest}
27
+ >
28
+ {children}
29
+ </ChakraAccordion>
30
+ );
31
+ };
32
+
33
+ export default Accordion;
@@ -0,0 +1,38 @@
1
+ import { ReactNode } from 'react';
2
+ import {
3
+ AccordionItem as ChakraAccordionItem,
4
+ AccordionItemProps as ChakraAccordionItemProps,
5
+ AccordionButton,
6
+ AccordionPanel,
7
+ AccordionIcon,
8
+ useAccordionStyles,
9
+ } from '@chakra-ui/react';
10
+
11
+ export interface AccordionItemProps {
12
+ buttonContent: ReactNode | ((props: { isExpanded: boolean; isDisabled: boolean }) => ReactNode);
13
+ children?: ReactNode | ((props: { isExpanded: boolean; isDisabled: boolean }) => ReactNode);
14
+ id?: ChakraAccordionItemProps['id'];
15
+ }
16
+
17
+ const AccordionItem = (props: AccordionItemProps) => {
18
+ const { buttonContent, children, id } = props;
19
+ const styles = useAccordionStyles();
20
+
21
+ return (
22
+ <ChakraAccordionItem sx={styles.item} id={id}>
23
+ {(renderProps) => (
24
+ <>
25
+ <AccordionButton sx={styles.button}>
26
+ {typeof buttonContent === 'function' ? buttonContent(renderProps) : buttonContent}
27
+ <AccordionIcon sx={styles.icon} />
28
+ </AccordionButton>
29
+ {!!children && (
30
+ <AccordionPanel>{typeof children === 'function' ? children(renderProps) : children}</AccordionPanel>
31
+ )}
32
+ </>
33
+ )}
34
+ </ChakraAccordionItem>
35
+ );
36
+ };
37
+
38
+ export default AccordionItem;
@@ -1,4 +1,6 @@
1
+ import { StyleFunctionProps } from '@chakra-ui/styled-system';
1
2
  import type { ComponentStyleConfig } from '@chakra-ui/theme';
3
+ import { CSSObject } from '@emotion/react';
2
4
 
3
5
  type ColorObj = {
4
6
  [key: string]: {
@@ -15,6 +17,8 @@ type VariantObj = {
15
17
  [key: string]: {
16
18
  borderRadius: string;
17
19
  boxShadow: string;
20
+ marginBottom: string;
21
+ border?: string;
18
22
  };
19
23
  };
20
24
 
@@ -64,59 +68,103 @@ const variants: VariantObj = {
64
68
  legacy: {
65
69
  borderRadius: '8',
66
70
  boxShadow: 'small',
71
+ marginBottom: '16',
67
72
  },
68
73
  flat: {
69
74
  borderRadius: '0',
70
75
  boxShadow: 'none',
76
+ marginBottom: '16',
71
77
  },
72
78
  };
73
79
 
74
- const AccordionTheme: ComponentStyleConfig = {
75
- baseStyle: ({ colorScheme, variant }) => ({
76
- item: {
77
- border: '1px solid',
78
- borderColor: colors[colorScheme].border,
79
- borderRadius: variants[variant].borderRadius,
80
- boxShadow: variants[variant].boxShadow,
81
- marginBottom: '16',
82
- _last: {
83
- marginBottom: 0,
84
- },
85
- },
86
- enabledButton: {
87
- ...buttonStyle,
88
- borderColor: colors[colorScheme].border,
89
- borderRadius: variants[variant].borderRadius,
90
- background: colors[colorScheme].enabledButton,
91
- _hover: {
92
- background: colors[colorScheme].hover,
93
- },
94
- _expanded: {
95
- borderBottomLeftRadius: '0',
96
- borderBottomRightRadius: '0',
97
- },
80
+ const LegacyBaseStyle: ({ colorScheme, variant }: Pick<StyleFunctionProps, 'colorScheme' | 'variant'>) => CSSObject = ({
81
+ colorScheme,
82
+ variant,
83
+ }) => ({
84
+ item: {
85
+ border: variants[variant].border ?? '1px solid',
86
+ borderColor: colors[colorScheme].border,
87
+ borderRadius: variants[variant].borderRadius,
88
+ boxShadow: variants[variant].boxShadow,
89
+ marginBottom: variants[variant].marginBottom,
90
+ _last: {
91
+ marginBottom: 0,
98
92
  },
99
- disabledButton: {
100
- ...buttonStyle,
101
- borderRadius: variants[variant].borderRadius,
102
- background: colors[colorScheme].disabledButton,
103
- borderColor: colors[colorScheme].border,
104
- cursor: 'default',
93
+ },
94
+ enabledButton: {
95
+ ...buttonStyle,
96
+ borderColor: colors[colorScheme].border,
97
+ borderRadius: variants[variant].borderRadius,
98
+ background: colors[colorScheme].enabledButton,
99
+ _hover: {
100
+ background: colors[colorScheme].hover,
105
101
  },
106
- enabledIcon: {
107
- ...iconStyle,
108
- color: colors[colorScheme].enabledIcon,
102
+ _expanded: {
103
+ borderBottomLeftRadius: '0',
104
+ borderBottomRightRadius: '0',
109
105
  },
110
- disabledIcon: {
111
- ...iconStyle,
112
- opacity: '0.4',
113
- transform: 'none',
114
- color: colors[colorScheme].disabledIcon,
106
+ },
107
+ disabledButton: {
108
+ ...buttonStyle,
109
+ borderRadius: variants[variant].borderRadius,
110
+ background: colors[colorScheme].disabledButton,
111
+ borderColor: colors[colorScheme].border,
112
+ cursor: 'default',
113
+ },
114
+ enabledIcon: {
115
+ ...iconStyle,
116
+ color: colors[colorScheme].enabledIcon,
117
+ },
118
+ disabledIcon: {
119
+ ...iconStyle,
120
+ opacity: '0.4',
121
+ transform: 'none',
122
+ color: colors[colorScheme].disabledIcon,
123
+ },
124
+ panel: {
125
+ padding: '16',
126
+ },
127
+ });
128
+
129
+ const BaseStyle: () => CSSObject = () => ({
130
+ item: {
131
+ borderRadius: 0,
132
+ boxShadow: 'none',
133
+ borderTopStyle: 'solid',
134
+ borderTopWidth: '1px',
135
+ borderTopColor: 'neutral.90',
136
+ },
137
+ button: {
138
+ display: 'flex',
139
+ alignItems: 'center',
140
+ justifyContent: 'space-between',
141
+ width: '100%',
142
+ paddingInline: '16',
143
+ paddingBlock: '20',
144
+ borderColor: 'neutral.93',
145
+ _hover: {
146
+ background: 'neutral.93',
115
147
  },
116
- panel: {
117
- padding: '16',
148
+ _expanded: {
149
+ borderBottomLeftRadius: '0',
150
+ borderBottomRightRadius: '0',
151
+ background: 'neutral.90',
118
152
  },
119
- }),
153
+ },
154
+ icon: {
155
+ width: '24',
156
+ height: '24',
157
+ marginLeft: '16',
158
+ },
159
+ panel: {
160
+ padding: '16',
161
+ },
162
+ });
163
+
164
+ const AccordionTheme: ComponentStyleConfig = {
165
+ baseStyle: ({ colorScheme, variant }) => {
166
+ return variant === 'legacy' || variant === 'flat' ? LegacyBaseStyle({ colorScheme, variant }) : BaseStyle();
167
+ },
120
168
  };
121
169
 
122
170
  export default AccordionTheme;
package/src/index.ts CHANGED
@@ -159,6 +159,12 @@ export { default as Notification } from './Components/Notification/Notification'
159
159
 
160
160
  export { BREAKPOINTS } from './Foundations/Breakpoints/Breakpoints';
161
161
 
162
+ export type { AccordionProps } from './Components/Accordion/Accordion';
163
+ export { default as Accordion } from './Components/Accordion/Accordion';
164
+
165
+ export type { AccordionItemProps } from './Components/Accordion/AccordionItem';
166
+ export { default as AccordionItem } from './Components/Accordion/AccordionItem';
167
+
162
168
  export type { LegacyAccordionProps } from './Components/AccordionLegacy/LegacyAccordion';
163
169
  export { default as LegacyAccordion } from './Components/AccordionLegacy/LegacyAccordion';
164
170