@bitrise/bitkit 10.19.0 → 10.21.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.
Files changed (36) hide show
  1. package/package.json +1 -1
  2. package/src/Components/Collapse/Collapse.tsx +5 -0
  3. package/src/Components/Dropdown/Dropdown.stories.tsx +2 -2
  4. package/src/Components/Dropdown/Dropdown.test.tsx +7 -0
  5. package/src/Components/Dropdown/Dropdown.tsx +16 -20
  6. package/src/Components/Dropdown/hooks/useFloatingDropdown.ts +28 -6
  7. package/src/Old/DatePicker/DatePickerGrid.tsx +5 -3
  8. package/src/Old/DatePicker/DatePickerMonth.tsx +2 -2
  9. package/src/Old/Placement/Placement.tsx +3 -8
  10. package/src/Old/Progress/ProgressBitbot.tsx +3 -3
  11. package/src/index.ts +3 -0
  12. package/src/old.ts +0 -34
  13. package/src/tsconfig.tsbuildinfo +1 -1
  14. package/src/Old/Expand/Expand.css +0 -26
  15. package/src/Old/Expand/Expand.test.tsx +0 -52
  16. package/src/Old/Expand/Expand.tsx +0 -133
  17. package/src/Old/Expand/__snapshots__/Expand.test.tsx.snap +0 -211
  18. package/src/Old/Grid/Grid.css +0 -40
  19. package/src/Old/Grid/Grid.test.tsx +0 -49
  20. package/src/Old/Grid/Grid.tsx +0 -76
  21. package/src/Old/Grid/__snapshots__/Grid.test.tsx.snap +0 -127
  22. package/src/Old/Logo/Logo.css +0 -3
  23. package/src/Old/Logo/Logo.tsx +0 -50
  24. package/src/Old/Modal/ModalContext.ts +0 -6
  25. package/src/Old/Status/Status500.tsx +0 -40
  26. package/src/Old/Table/Table.css +0 -77
  27. package/src/Old/Table/Table.tsx +0 -28
  28. package/src/Old/Table/TableBody.tsx +0 -14
  29. package/src/Old/Table/TableCell.tsx +0 -23
  30. package/src/Old/Table/TableHeader.tsx +0 -14
  31. package/src/Old/Table/TableHeaderCell.tsx +0 -62
  32. package/src/Old/Table/TableHeaderRow.tsx +0 -14
  33. package/src/Old/Table/TableRow.tsx +0 -23
  34. package/src/Old/Text/Text.css +0 -33
  35. package/src/Old/Text/Text.tsx +0 -87
  36. package/src/Old/Text/TextSizes.css +0 -0
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.19.0",
4
+ "version": "10.21.0",
5
5
  "repository": "git@github.com:bitrise-io/bitkit.git",
6
6
  "main": "src/index.ts",
7
7
  "license": "UNLICENSED",
@@ -0,0 +1,5 @@
1
+ import { Collapse, CollapseProps } from '@chakra-ui/react';
2
+
3
+ export type { CollapseProps };
4
+
5
+ export default Collapse;
@@ -114,8 +114,8 @@ export const Default: ComponentStoryFn<typeof Dropdown> = (args) => {
114
114
  export const InsideDialog = () => {
115
115
  return (
116
116
  <Provider>
117
- <Dialog isOpen isClosable>
118
- <DialogBody>
117
+ <Dialog isOpen isClosable title="Dropdown inside Dialog">
118
+ <DialogBody paddingBottom="24">
119
119
  <Dropdown search={false}>
120
120
  <DropdownOption value="x">Test Opt1</DropdownOption>
121
121
  </Dropdown>
@@ -31,6 +31,13 @@ const TestComponent = forwardRef<
31
31
  });
32
32
 
33
33
  describe('Dropdown', () => {
34
+ it('sets ref to the button', async () => {
35
+ const handler = jest.fn();
36
+ render(<Dropdown ref={handler} />);
37
+ const button = await screen.findByRole('combobox');
38
+ expect(handler).toHaveBeenCalledWith(button);
39
+ });
40
+
34
41
  it('shows option on button', async () => {
35
42
  render(<TestComponent submit={() => {}} />);
36
43
  const button = await screen.findByRole('combobox', { name: 'Test' });
@@ -1,14 +1,4 @@
1
- import React, {
2
- cloneElement,
3
- forwardRef,
4
- ReactNode,
5
- useCallback,
6
- useEffect,
7
- useImperativeHandle,
8
- useMemo,
9
- useRef,
10
- useState,
11
- } from 'react';
1
+ import React, { cloneElement, forwardRef, ReactNode, useCallback, useEffect, useMemo, useRef, useState } from 'react';
12
2
  import {
13
3
  chakra,
14
4
  ChakraProps,
@@ -18,7 +8,7 @@ import {
18
8
  useControllableState,
19
9
  useMultiStyleConfig,
20
10
  } from '@chakra-ui/react';
21
- import { FloatingFocusManager } from '@floating-ui/react-dom-interactions';
11
+ import { FloatingFocusManager, UseFloatingProps } from '@floating-ui/react-dom-interactions';
22
12
  import Icon, { TypeIconName } from '../Icon/Icon';
23
13
  import { DropdownEventArgs, DropdownProvider, useDropdownContext, useDropdownStyles } from './Dropdown.context';
24
14
  import { DropdownOption, DropdownGroup, DropdownDetailedOption, DropdownOptionProps } from './DropdownOption';
@@ -95,6 +85,8 @@ export interface DropdownProps<T> extends ChakraProps {
95
85
  size?: 'small' | 'medium';
96
86
  dropdownMaxHeight?: ChakraProps['maxH'];
97
87
  dropdownMinHeight?: ChakraProps['minH'];
88
+ dropdownWidth?: ChakraProps['width'] | 'match';
89
+ placement?: UseFloatingProps['placement'];
98
90
  readOnly?: boolean;
99
91
  disabled?: boolean;
100
92
  placeholder?: string;
@@ -102,7 +94,7 @@ export interface DropdownProps<T> extends ChakraProps {
102
94
  search?: ReactNode;
103
95
  children?: ReactNode;
104
96
  iconName?: TypeIconName;
105
- formLabel?: string;
97
+ formLabel?: ReactNode;
106
98
  }
107
99
 
108
100
  function useOptionListWithIndexes({ children }: { children: ReactNode }) {
@@ -132,8 +124,8 @@ function useOptionListWithIndexes({ children }: { children: ReactNode }) {
132
124
  }, [children]);
133
125
  }
134
126
 
135
- type UseDropdownProps<T> = {
136
- ref: React.Ref<DropdownInstance<T>>;
127
+ type UseDropdownProps = {
128
+ ref: React.Ref<Element>;
137
129
  optionsRef: React.RefObject<HTMLDivElement>;
138
130
  };
139
131
 
@@ -162,11 +154,13 @@ function useDropdown<T>({
162
154
  value,
163
155
  optionsRef,
164
156
  defaultValue,
157
+ dropdownWidth = 'match',
158
+ placement,
165
159
  ref,
166
160
  children,
167
161
  readOnly,
168
162
  ...rest
169
- }: DropdownProps<T> & UseDropdownProps<T>) {
163
+ }: DropdownProps<T> & UseDropdownProps) {
170
164
  const searchRef = useRef(null);
171
165
  const {
172
166
  close,
@@ -179,7 +173,7 @@ function useDropdown<T>({
179
173
  setActiveIndex,
180
174
  getItemProps,
181
175
  listRef,
182
- } = useFloatingDropdown({ enabled: !readOnly, optionsRef });
176
+ } = useFloatingDropdown({ enabled: !readOnly, optionsRef, dropdownWidth, placement });
183
177
  const [formValue, setFormValue] = useControllableState<T>({
184
178
  onChange: (newValue) => onChange?.({ target: { value: newValue, name } }),
185
179
  defaultValue,
@@ -187,7 +181,6 @@ function useDropdown<T>({
187
181
  });
188
182
 
189
183
  const [formLabel, setFormLabel] = useState<ReactNode>();
190
- useImperativeHandle(ref, () => ({ value: formValue, name }), [formValue, name]);
191
184
  const refdChildren = useOptionListWithIndexes({ children });
192
185
 
193
186
  const searchOnSubmit = useCallback(() => {
@@ -251,6 +244,7 @@ function useDropdown<T>({
251
244
  return {
252
245
  isOpen,
253
246
  referenceProps: getReferenceProps({
247
+ ref,
254
248
  onKeyDown: referenceKeyDown,
255
249
  }),
256
250
  floatingProps,
@@ -265,11 +259,12 @@ function useDropdown<T>({
265
259
  };
266
260
  }
267
261
 
268
- const Dropdown = forwardRef<DropdownInstance<string | null>, DropdownProps<string | null>>(
262
+ const Dropdown = forwardRef<Element, DropdownProps<string | null>>(
269
263
  (
270
264
  {
271
265
  dropdownMaxHeight,
272
266
  dropdownMinHeight,
267
+ dropdownWidth,
273
268
  readOnly,
274
269
  onBlur,
275
270
  placeholder,
@@ -297,6 +292,7 @@ const Dropdown = forwardRef<DropdownInstance<string | null>, DropdownProps<strin
297
292
  name,
298
293
  readOnly,
299
294
  optionsRef,
295
+ dropdownWidth,
300
296
  ref,
301
297
  ...props,
302
298
  });
@@ -350,7 +346,7 @@ const Dropdown = forwardRef<DropdownInstance<string | null>, DropdownProps<strin
350
346
 
351
347
  export function typedDropdown<T>() {
352
348
  return {
353
- Dropdown: Dropdown as React.ForwardRefExoticComponent<DropdownProps<T> & React.RefAttributes<DropdownInstance<T>>>,
349
+ Dropdown: Dropdown as React.ForwardRefExoticComponent<DropdownProps<T> & React.RefAttributes<Element>>,
354
350
  DropdownOption: DropdownOption as (p: DropdownOptionProps<T>) => JSX.Element,
355
351
  };
356
352
  }
@@ -9,10 +9,28 @@ import {
9
9
  useRole,
10
10
  useDismiss,
11
11
  flip,
12
+ UseFloatingProps,
13
+ MiddlewareArguments,
12
14
  } from '@floating-ui/react-dom-interactions';
15
+ import { ChakraProps } from '@chakra-ui/react';
16
+ import { mergeRefs } from '@chakra-ui/react-utils';
13
17
  import useAutoScroll from './useAutoScroll';
14
18
 
15
- const useFloatingDropdown = ({ enabled, optionsRef }: { enabled: boolean; optionsRef: RefObject<HTMLDivElement> }) => {
19
+ type ApplyFnArgs = MiddlewareArguments & {
20
+ availableWidth: number;
21
+ availableHeight: number;
22
+ };
23
+ const useFloatingDropdown = ({
24
+ enabled,
25
+ optionsRef,
26
+ dropdownWidth,
27
+ placement,
28
+ }: {
29
+ enabled: boolean;
30
+ optionsRef: RefObject<HTMLDivElement>;
31
+ dropdownWidth: ChakraProps['width'] | 'match';
32
+ placement: UseFloatingProps['placement'] | undefined;
33
+ }) => {
16
34
  const listRef = useRef<HTMLElement[]>([]);
17
35
  const [isOpen, setOpen] = useState(false);
18
36
  const [activeIndex, setActiveIndex] = useState<number | null>(null);
@@ -22,18 +40,21 @@ const useFloatingDropdown = ({ enabled, optionsRef }: { enabled: boolean; option
22
40
  setKeyboardControlled(true);
23
41
  }, [isOpen]);
24
42
 
25
- const { context, reference, floating, strategy, x, y } = useFloating({
43
+ const widthRef = useRef(dropdownWidth);
44
+ widthRef.current = dropdownWidth;
45
+ const { context, reference, floating, strategy, x, y } = useFloating<Element>({
26
46
  open: enabled && isOpen,
27
47
  onOpenChange: setOpen,
48
+ placement,
28
49
  whileElementsMounted(aRef, aFloat, update) {
29
50
  return autoUpdate(aRef, aFloat, update, { elementResize: false });
30
51
  },
31
52
  middleware: [
32
53
  size({
33
54
  padding: 5,
34
- apply({ elements, availableHeight, rects }) {
55
+ apply: ({ elements, availableHeight, rects }: ApplyFnArgs) => {
35
56
  Object.assign(elements.floating.style, {
36
- width: `${rects.reference.width}px`,
57
+ width: widthRef.current === 'match' ? `${rects.reference.width}px` : widthRef.current,
37
58
  });
38
59
  elements.floating.style.setProperty('--floating-available-height', `${availableHeight}px`);
39
60
  },
@@ -91,8 +112,9 @@ const useFloatingDropdown = ({ enabled, optionsRef }: { enabled: boolean; option
91
112
  activeIndex,
92
113
  setActiveIndex,
93
114
  setSelectedIndex,
94
- getReferenceProps(props: React.HTMLProps<Element>) {
95
- return getReferenceProps({ ...props, ref: reference });
115
+ getReferenceProps({ ref, ...props }: React.HTMLProps<Element>) {
116
+ const merged = mergeRefs(ref as any, reference);
117
+ return getReferenceProps({ ...props, ref: merged });
96
118
  },
97
119
  floatingProps: getFloatingProps({
98
120
  ref: floating,
@@ -1,10 +1,12 @@
1
1
  import * as React from 'react';
2
- import Grid, { Props as GridProps } from '../Grid/Grid';
2
+ import Box, { BoxProps } from '../../Components/Box/Box';
3
3
 
4
- type Props = GridProps;
4
+ type Props = BoxProps;
5
5
 
6
6
  const DatePickerGrid: React.FunctionComponent<Props> = (props: Props) => {
7
- return <Grid {...props} className="DatePicker__grid" gapVertical="x1" repeat="7" repeatWidth="3rem" />;
7
+ return (
8
+ <Box display="grid" {...props} gridTemplateColumns="repeat(7, 3rem)" gridAutoRows="max-content" gridRowGap="4" />
9
+ );
8
10
  };
9
11
 
10
12
  export default DatePickerGrid;
@@ -57,7 +57,7 @@ const DatePickerMonth: React.FunctionComponent<Props> = (props: Props) => {
57
57
  </Flex>
58
58
  </Flex>
59
59
 
60
- <DatePickerGrid margin="x1">
60
+ <DatePickerGrid marginY="4">
61
61
  {daysOfTheWeek.map((day) => (
62
62
  <Text textAlign="center" key={day} paddingY="16" size="2" color="neutral.70" textTransform="uppercase">
63
63
  {day}
@@ -65,7 +65,7 @@ const DatePickerMonth: React.FunctionComponent<Props> = (props: Props) => {
65
65
  ))}
66
66
  </DatePickerGrid>
67
67
 
68
- <DatePickerGrid paddingVertical="x2">
68
+ <DatePickerGrid borderTop="1px solid" borderTopColor="neutral.93" paddingY="8">
69
69
  {Array.from({ length: daysCount }).map((_, i) => (
70
70
  <DatePickerDay
71
71
  dateSelectableFrom={dateSelectableFrom}
@@ -1,7 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { Placement as TypePlacement } from '@popperjs/core';
3
3
  import { Props as BaseProps } from '../Base/Base';
4
- import { ModalContext } from '../Modal/ModalContext';
5
4
  import PlacementPopper from './PlacementPopper';
6
5
  import './Placement.css';
7
6
 
@@ -63,13 +62,9 @@ export interface Props extends BaseProps {
63
62
  * and PlacementReference. If the target is an existing reference element
64
63
  * it can be used by iteself by using the referenceElement prop.
65
64
  */
66
- const Placement: React.FunctionComponent<Props> = (props: Props) => {
67
- return (
68
- <ModalContext.Consumer>
69
- {({ modalElement }) => <PlacementPopper {...props} closeElement={modalElement} isInsideModal={!!modalElement} />}
70
- </ModalContext.Consumer>
71
- );
72
- };
65
+ const Placement: React.FunctionComponent<Props> = (props: Props) => (
66
+ <PlacementPopper {...props} closeElement={null} isInsideModal={false} />
67
+ );
73
68
 
74
69
  Placement.defaultProps = {
75
70
  flip: true,
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { Props as BaseProps } from '../Base/Base';
3
- import Text from '../Text/Text';
3
+ import Text from '../../Components/Text/Text';
4
4
 
5
5
  export interface Props extends BaseProps {
6
6
  /**
@@ -62,7 +62,7 @@ const ProgressBitbot: React.FunctionComponent<Props> = (props: Props) => {
62
62
  const { content, size, ...rest } = props;
63
63
 
64
64
  return (
65
- <Text {...rest} align="middle">
65
+ <Text {...rest} textAlign="center">
66
66
  <svg fill="currentColor" height={size} viewBox="0 0 24 24" width={size}>
67
67
  <g fill="currentColor" fillRule="evenodd" stroke="none" strokeWidth="1">
68
68
  <path d={dot0}>
@@ -159,7 +159,7 @@ const ProgressBitbot: React.FunctionComponent<Props> = (props: Props) => {
159
159
  </svg>
160
160
 
161
161
  {content && (
162
- <Text align="middle" letterSpacing="x5" size="1" uppercase>
162
+ <Text textAlign="center" size="1" textTransform="uppercase">
163
163
  {content}
164
164
  </Text>
165
165
  )}
package/src/index.ts CHANGED
@@ -196,5 +196,8 @@ export { default as Tr } from './Components/Table/Tr';
196
196
  export type { ToggleProps } from './Components/Toggle/Toggle';
197
197
  export { default as Toggle } from './Components/Toggle/Toggle';
198
198
 
199
+ export type { CollapseProps } from './Components/Collapse/Collapse';
200
+ export { default as Collapse } from './Components/Collapse/Collapse';
201
+
199
202
  export type { TextareaProps } from './Components/Form/Textarea/Textarea';
200
203
  export { default as Textarea } from './Components/Form/Textarea/Textarea';
package/src/old.ts CHANGED
@@ -24,15 +24,9 @@ export { default as DropdownMenuItem } from './Old/Dropdown/DropdownMenuItem';
24
24
  export type { Props as DropdownMenuItemGroupProps } from './Old/Dropdown/DropdownMenuItemGroup';
25
25
  export { default as DropdownMenuItemGroup } from './Old/Dropdown/DropdownMenuItemGroup';
26
26
 
27
- export type { Props as ExpandProps } from './Old/Expand/Expand';
28
- export { default as Expand } from './Old/Expand/Expand';
29
-
30
27
  export type { Props as FlexProps } from './Old/Flex/Flex';
31
28
  export { default as Flex } from './Old/Flex/Flex';
32
29
 
33
- export type { Props as GridProps } from './Old/Grid/Grid';
34
- export { default as Grid } from './Old/Grid/Grid';
35
-
36
30
  export type { Props as InputProps } from './Old/Input/Input';
37
31
  export { default as Input } from './Old/Input/Input';
38
32
 
@@ -48,9 +42,6 @@ export { default as InputInlineHelp } from './Old/Input/InputInlineHelp';
48
42
  export type { Props as InputLabelProps } from './Old/Input/InputLabel';
49
43
  export { default as InputLabel } from './Old/Input/InputLabel';
50
44
 
51
- export type { Props as LogoProps } from './Old/Logo/Logo';
52
- export { default as Logo } from './Old/Logo/Logo';
53
-
54
45
  export type { Props as ProgressBarProps } from './Old/Progress/ProgressBar';
55
46
  export { default as ProgressBar } from './Old/Progress/ProgressBar';
56
47
 
@@ -66,31 +57,6 @@ export { default as Skeleton } from './Old/Skeleton/Skeleton';
66
57
  export type { Props as SkeletonBoxProps } from './Old/Skeleton/SkeletonBox';
67
58
  export { default as SkeletonBox } from './Old/Skeleton/SkeletonBox';
68
59
 
69
- export type { Props as Status500Props } from './Old/Status/Status500';
70
- export { default as Status500 } from './Old/Status/Status500';
71
-
72
- export type { Props as OldTableProps } from './Old/Table/Table';
73
- export { default as OldTable } from './Old/Table/Table';
74
-
75
- export type { Props as OldTableBodyProps } from './Old/Table/TableBody';
76
- export { default as OldTableBody } from './Old/Table/TableBody';
77
-
78
- export type { Props as OldTableCellProps } from './Old/Table/TableCell';
79
- export { default as OldTableCell } from './Old/Table/TableCell';
80
-
81
- export type { Props as OldTableHeaderProps } from './Old/Table/TableHeader';
82
- export { default as OldTableHeader } from './Old/Table/TableHeader';
83
-
84
- export type { Props as OldTableHeaderCellProps } from './Old/Table/TableHeaderCell';
85
- export type { TypeTableSort } from './Old/Table/TableHeaderCell';
86
- export { default as OldTableHeaderCell } from './Old/Table/TableHeaderCell';
87
-
88
- export type { Props as OldTableHeaderRowProps } from './Old/Table/TableHeaderRow';
89
- export { default as OldTableHeaderRow } from './Old/Table/TableHeaderRow';
90
-
91
- export type { Props as OldTableRowProps } from './Old/Table/TableRow';
92
- export { default as OldTableRow } from './Old/Table/TableRow';
93
-
94
60
  export type { Props as VisibilityProps } from './Old/Visibility/Visibility';
95
61
  export { default as Visibility } from './Old/Visibility/Visibility';
96
62