@bitrise/bitkit 12.99.0 → 12.101.0

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": "12.99.0",
4
+ "version": "12.101.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+ssh://git@github.com/bitrise-io/bitkit.git"
@@ -13,6 +13,7 @@ import {
13
13
  import { BREAKPOINTS } from '../../Foundations/Breakpoints/Breakpoints';
14
14
  import Icon from '../Icon/Icon';
15
15
  import Text from '../Text/Text';
16
+ import Tooltip from '../Tooltip/Tooltip';
16
17
 
17
18
  export interface DialogProps extends Omit<HTMLChakraProps<'section'>, 'scrollBehavior'> {
18
19
  isClosable?: boolean;
@@ -23,10 +24,12 @@ export interface DialogProps extends Omit<HTMLChakraProps<'section'>, 'scrollBeh
23
24
  title: string;
24
25
  trapFocus?: boolean;
25
26
  variant?: 'default' | 'empty';
27
+ closeNotice?: string;
26
28
  }
27
29
 
28
30
  const Dialog: ComponentWithAs<'section', DialogProps> = ({
29
31
  children,
32
+ closeNotice,
30
33
  isClosable,
31
34
  isOpen,
32
35
  onClose,
@@ -41,6 +44,12 @@ const Dialog: ComponentWithAs<'section', DialogProps> = ({
41
44
  const prefersReducedMotion = usePrefersReducedMotion({ ssr: false });
42
45
  const headerId = useId();
43
46
 
47
+ const closeBtn = (
48
+ <ModalCloseButton isDisabled={!isClosable} size="large">
49
+ <Icon name="CloseSmall" />
50
+ </ModalCloseButton>
51
+ );
52
+
44
53
  return (
45
54
  <Modal
46
55
  closeOnEsc={isClosable}
@@ -61,9 +70,13 @@ const Dialog: ComponentWithAs<'section', DialogProps> = ({
61
70
  {title}
62
71
  </Text>
63
72
  </ModalHeader>
64
- <ModalCloseButton isDisabled={!isClosable} size="large">
65
- <Icon name="CloseSmall" />
66
- </ModalCloseButton>
73
+ {closeNotice ? (
74
+ <Tooltip label={closeNotice} placement="top">
75
+ {closeBtn}
76
+ </Tooltip>
77
+ ) : (
78
+ closeBtn
79
+ )}
67
80
  </>
68
81
  )}
69
82
  {children}
@@ -1,29 +1,41 @@
1
1
  import { createMultiStyleConfigHelpers } from '@chakra-ui/styled-system';
2
2
 
3
- const itemHelpers = createMultiStyleConfigHelpers(['container', 'stage', 'iconWithLine', 'line', 'label']);
3
+ const itemHelpers = createMultiStyleConfigHelpers([
4
+ 'container',
5
+ 'stage',
6
+ 'iconWithLine',
7
+ 'line',
8
+ 'label',
9
+ 'labelContainer',
10
+ ]);
4
11
 
5
12
  const ProgressIndicatorTheme = itemHelpers.defineMultiStyleConfig({
6
13
  baseStyle: {
7
14
  container: {
8
15
  display: 'flex',
16
+ width: '100%',
9
17
  },
10
18
  iconWithLine: {
11
- display: 'flex',
19
+ display: 'grid',
12
20
  },
13
21
  label: {
14
- alignSelf: 'flex-start',
15
22
  lineHeight: '1.5rem',
16
- maxWidth: 'max(8rem, calc(100% - 1rem))',
23
+ maxWidth: '8rem',
17
24
  overflow: 'hidden',
25
+ textAlign: 'center',
18
26
  textOverflow: 'ellipsis',
19
27
  whiteSpace: 'nowrap',
20
28
  },
29
+ labelContainer: {
30
+ display: 'flex',
31
+ justifyContent: 'center',
32
+ },
21
33
  line: {
22
34
  flexGrow: '1',
23
35
  },
24
36
  stage: {
25
37
  display: 'flex',
26
- gap: '1rem',
38
+ gap: '8',
27
39
  },
28
40
  },
29
41
  variants: {
@@ -32,6 +44,9 @@ const ProgressIndicatorTheme = itemHelpers.defineMultiStyleConfig({
32
44
  flexDir: 'row',
33
45
  },
34
46
  iconWithLine: {
47
+ gridTemplateColumns: '1fr 24px 1fr',
48
+ },
49
+ labelContainer: {
35
50
  flexDir: 'row',
36
51
  },
37
52
  line: {
@@ -46,11 +61,16 @@ const ProgressIndicatorTheme = itemHelpers.defineMultiStyleConfig({
46
61
  flexDir: 'column',
47
62
  },
48
63
  iconWithLine: {
64
+ gridTemplateRows: '24px 1fr',
65
+ minHeight: '62px',
66
+ },
67
+ labelContainer: {
49
68
  flexDir: 'column',
69
+ justifyContent: 'start',
50
70
  },
51
71
  line: {
52
- height: '1.5rem',
53
- marginX: 'calc(.75rem - 1px)',
72
+ height: '100%',
73
+ justifySelf: 'center',
54
74
  },
55
75
  stage: {
56
76
  flexDir: 'row',
@@ -1,99 +1,205 @@
1
+ import { useMemo } from 'react';
1
2
  import { useMultiStyleConfig } from '@chakra-ui/react';
2
3
  import Box from '../Box/Box';
3
4
  import Icon, { IconProps } from '../Icon/Icon';
4
- import Text from '../Text/Text';
5
+ import Text, { TextProps } from '../Text/Text';
5
6
  import Divider, { DividerProps } from '../Divider/Divider';
6
7
  import Link, { LinkProps } from '../Link/Link';
7
8
 
9
+ type ProgressStage = {
10
+ label: string;
11
+ isInvalid?: boolean;
12
+ isDisabled?: boolean;
13
+ helperText?: string;
14
+ action?: {
15
+ onClick?: () => void;
16
+ href?: LinkProps['href'];
17
+ isExternal?: LinkProps['isExternal'];
18
+ };
19
+ };
8
20
  export type ProgressIndicatorProps = {
9
- stages: {
10
- label: string;
11
- isInvalid?: boolean;
12
- isDisabled?: boolean;
13
- action?: {
14
- label: string;
15
- onClick?: () => void;
16
- href?: LinkProps['href'];
17
- isExternal?: LinkProps['isExternal'];
18
- };
19
- }[];
21
+ stages: ProgressStage[];
20
22
  activeStageIndex: number;
23
+ } & (
24
+ | {
25
+ variant: 'horizontal';
26
+ extendLines?: boolean;
27
+ }
28
+ | {
29
+ variant: 'vertical';
30
+ }
31
+ );
32
+
33
+ type RenderStage = (ProgressStage & { spacer?: never }) | { spacer: true };
34
+
35
+ const SegmentLine = ({
36
+ activeSegmentIndex,
37
+ segmentIndex,
38
+ spacer,
39
+ variant,
40
+ }: {
41
+ segmentIndex: number;
42
+ activeSegmentIndex: number;
21
43
  variant: 'horizontal' | 'vertical';
44
+ spacer?: true;
45
+ }) => {
46
+ const style = useMultiStyleConfig('ProgressIndicator', { variant });
47
+ let props: {
48
+ color: DividerProps['color'];
49
+ variant?: DividerProps['variant'];
50
+ } = { color: 'border.minimal' };
51
+
52
+ if (segmentIndex < activeSegmentIndex) {
53
+ props = { ...props, color: 'border.selected' };
54
+ } else if (segmentIndex === activeSegmentIndex) {
55
+ props = {
56
+ ...props,
57
+ color: 'border.selected',
58
+ variant: 'dashed',
59
+ };
60
+ }
61
+ return (
62
+ <Divider
63
+ gridColumn={spacer ? '1/4' : undefined}
64
+ orientation={variant === 'horizontal' ? 'horizontal' : 'vertical'}
65
+ size="2"
66
+ sx={style.line}
67
+ {...props}
68
+ />
69
+ );
22
70
  };
23
71
 
24
- const ProgressIndicator = ({ activeStageIndex, stages, variant }: ProgressIndicatorProps): JSX.Element => {
72
+ const RealStage = ({
73
+ activeSegmentIndex,
74
+ extendLines,
75
+ lastBlock,
76
+ segmentIndex,
77
+ stage: { action, helperText, isDisabled, isInvalid, label },
78
+ variant,
79
+ }: Pick<ProgressIndicatorProps, 'variant'> & {
80
+ segmentIndex: number;
81
+ activeSegmentIndex: number;
82
+ stage: ProgressStage;
83
+ lastBlock: boolean;
84
+ extendLines: boolean;
85
+ }) => {
86
+ let iconName: IconProps['name'];
87
+ let iconColor: IconProps['color'] = 'icon.interactive';
88
+ let textColor: TextProps['color'] = 'text.secondary';
89
+ let iconTransform: IconProps['transform'];
90
+
91
+ if (segmentIndex < activeSegmentIndex) {
92
+ iconName = 'BuildstatusSuccessfulSolid';
93
+ } else if (segmentIndex === activeSegmentIndex) {
94
+ iconName = 'StageCurrent';
95
+ if (variant === 'vertical') iconTransform = 'rotate(90deg)';
96
+ textColor = 'text.primary';
97
+ } else {
98
+ iconName = 'StageIncomplete';
99
+ iconColor = 'icon.tertiary';
100
+ }
101
+ if (isInvalid) {
102
+ iconName = 'StepstatusWarning';
103
+ iconColor = 'icon.negative';
104
+ }
105
+ if (isDisabled) {
106
+ iconColor = 'icon.disabled';
107
+ textColor = 'text.disabled';
108
+ }
25
109
  const style = useMultiStyleConfig('ProgressIndicator', { variant });
26
110
 
27
111
  return (
28
- <Box sx={style.container}>
29
- {stages.map(({ action, isDisabled, isInvalid, label }, index, array) => {
30
- let iconName: IconProps['name'];
31
- let iconColor: IconProps['color'] = 'purple.50';
32
-
33
- let dividerProps: {
34
- color: DividerProps['color'];
35
- variant?: DividerProps['variant'];
36
- } = { color: 'neutral.93' };
112
+ <>
113
+ <Box sx={style.iconWithLine}>
114
+ {variant === 'horizontal' &&
115
+ (segmentIndex > 0 ? (
116
+ <SegmentLine
117
+ activeSegmentIndex={activeSegmentIndex}
118
+ segmentIndex={segmentIndex - (extendLines ? 2 : 1)}
119
+ variant={variant}
120
+ />
121
+ ) : (
122
+ <div />
123
+ ))}
124
+ <Icon color={iconColor} name={iconName} transform={iconTransform} />
125
+ {lastBlock ? (
126
+ <div />
127
+ ) : (
128
+ <SegmentLine activeSegmentIndex={activeSegmentIndex} segmentIndex={segmentIndex} variant={variant} />
129
+ )}
130
+ </Box>
131
+ <Box sx={style.labelContainer}>
132
+ {action && !isDisabled ? (
133
+ <Link
134
+ as={action.href ? 'a' : 'button'}
135
+ colorScheme="purple"
136
+ href={action.href}
137
+ isExternal={action.isExternal}
138
+ onClick={action.onClick}
139
+ size="2"
140
+ sx={style.label}
141
+ >
142
+ {label}
143
+ </Link>
144
+ ) : (
145
+ <Text color={textColor} size="2" sx={style.label}>
146
+ {label}
147
+ </Text>
148
+ )}
149
+ {variant === 'vertical' && helperText && (
150
+ <Text color="text.secondary" fontSize="1" lineHeight="1rem">
151
+ {helperText}
152
+ </Text>
153
+ )}
154
+ </Box>
155
+ </>
156
+ );
157
+ };
37
158
 
38
- if (index < activeStageIndex) {
39
- iconName = 'BuildstatusSuccessful';
40
- dividerProps = { ...dividerProps, color: 'purple.50' };
41
- } else if (index === activeStageIndex) {
42
- iconName = 'StageCurrent';
43
- dividerProps = {
44
- ...dividerProps,
45
- color: 'purple.50',
46
- variant: 'dashed',
47
- };
48
- } else {
49
- iconName = 'StageIncomplete';
50
- iconColor = 'neutral.60';
51
- }
52
- if (isInvalid) {
53
- iconName = 'StepstatusWarning';
54
- iconColor = 'red.50';
55
- }
56
- if (isDisabled) {
57
- iconColor = 'neutral.80';
58
- }
159
+ const ProgressIndicator = ({ activeStageIndex, stages, ...rest }: ProgressIndicatorProps): JSX.Element => {
160
+ const style = useMultiStyleConfig('ProgressIndicator', { variant: rest.variant });
161
+ const extendLines = Boolean(rest.variant === 'horizontal' && rest.extendLines);
162
+ const activeSegmentIndex = extendLines ? activeStageIndex * 2 : activeStageIndex;
59
163
 
60
- const lastBlock = index === array.length - 1;
164
+ const renderStages = useMemo((): RenderStage[] => {
165
+ if (!extendLines) return stages;
166
+ const extendedStages: RenderStage[] = stages.map((stage) => ({ ...stage, type: 'real' }));
167
+ for (let i = 1; i < stages.length * 2 - 1; i += 2) {
168
+ extendedStages.splice(i, 0, { spacer: true });
169
+ }
170
+ return extendedStages;
171
+ }, [extendLines, stages]);
172
+ return (
173
+ <Box sx={style.container}>
174
+ {renderStages.map((stage, segmentIndex, array) => {
175
+ const lastBlock = segmentIndex === array.length - 1;
61
176
 
62
177
  return (
63
178
  <Box
64
179
  // eslint-disable-next-line react/no-array-index-key
65
- key={index}
66
- flexBasis={lastBlock ? undefined : `${100 / array.length}%`}
67
- flexGrow={lastBlock ? undefined : '1'}
180
+ key={segmentIndex}
181
+ flex="1"
68
182
  sx={style.stage}
69
183
  >
70
- <Box sx={style.iconWithLine}>
71
- <Icon color={iconColor} name={iconName} />
72
- {!lastBlock && (
73
- <Divider
74
- orientation={variant === 'horizontal' ? 'horizontal' : 'vertical'}
75
- size="2"
76
- sx={style.line}
77
- {...dividerProps}
184
+ {!stage.spacer && (
185
+ <RealStage
186
+ activeSegmentIndex={activeSegmentIndex}
187
+ extendLines={Boolean(extendLines)}
188
+ lastBlock={lastBlock}
189
+ segmentIndex={segmentIndex}
190
+ stage={stage}
191
+ variant={rest.variant}
192
+ />
193
+ )}
194
+ {stage.spacer && (
195
+ <Box sx={style.iconWithLine}>
196
+ <SegmentLine
197
+ activeSegmentIndex={activeSegmentIndex}
198
+ segmentIndex={segmentIndex - 1}
199
+ spacer
200
+ variant="horizontal"
78
201
  />
79
- )}
80
- </Box>
81
- {action && !isDisabled ? (
82
- <Link
83
- as={action.href ? 'a' : 'button'}
84
- colorScheme="purple"
85
- href={action.href}
86
- isExternal={action.isExternal}
87
- onClick={action.onClick}
88
- size="2"
89
- sx={style.label}
90
- >
91
- {label}
92
- </Link>
93
- ) : (
94
- <Text color={isDisabled ? 'neutral.80' : 'neutral.10'} size="2" sx={style.label}>
95
- {label}
96
- </Text>
202
+ </Box>
97
203
  )}
98
204
  </Box>
99
205
  );