@bitrise/bitkit 10.2.2 → 10.2.3-alpha-chakra.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": "10.2.2",
4
+ "version": "10.2.3-alpha-chakra.1",
5
5
  "repository": "git@github.com:bitrise-io/bitkit.git",
6
6
  "main": "src/index.ts",
7
7
  "license": "UNLICENSED",
@@ -1,14 +1,12 @@
1
1
  import * as React from 'react';
2
- import Placement from '../Placement/Placement';
3
- import PlacementManager from '../Placement/PlacementManager';
4
- import PlacementReference from '../Placement/PlacementReference';
5
2
  import Text from '../../Components/Text/Text';
6
- import DropdownButton, { Props as DropdownButtonProps } from './DropdownButton';
7
- import DropdownMenu from './DropdownMenu';
8
- import DropdownMenuItem from './DropdownMenuItem';
3
+ import Popover from '../../Components/Popover/Popover';
4
+ import PopoverTrigger from '../../Components/Popover/PopoverTrigger';
5
+ import PopoverContent from '../../Components/Popover/PopoverContent';
6
+ import Button, { ButtonProps } from '../../Components/Button/Button';
9
7
  import DropdownMenuItemGroup from './DropdownMenuItemGroup';
10
-
11
- const { useState } = React;
8
+ import DropdownMenuItem from './DropdownMenuItem';
9
+ import DropdownMenu from './DropdownMenu';
12
10
 
13
11
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
12
  type DropdownValue = any;
@@ -22,7 +20,7 @@ interface OptionGroup {
22
20
  options: DropdownValue[];
23
21
  }
24
22
 
25
- export interface Props extends DropdownButtonProps {
23
+ export interface Props extends ButtonProps {
26
24
  /** Handler for the value that is selected */
27
25
  onChange?: (value: DropdownValue) => void;
28
26
  /** Array of options that can be selected */
@@ -40,56 +38,64 @@ export interface Props extends DropdownButtonProps {
40
38
  */
41
39
  const Dropdown: React.FunctionComponent<Props> = (props: Props) => {
42
40
  const { children, options, onChange, selected, maxHeight, menuClassName, ...rest } = props;
43
- const [visible, setVisible] = useState(false);
44
41
 
45
42
  const handleChange = (value: DropdownValue) => {
46
43
  if (onChange) {
47
44
  onChange(value);
48
45
  }
49
- setVisible(false);
50
46
  };
51
47
 
52
- const renderOption = ({ text, value }: Option) => (
53
- <DropdownMenuItem onClick={() => handleChange(value)} selected={selected === value} width="100%">
48
+ const renderOption = ({ text, value }: Option, onClose: () => void) => (
49
+ <DropdownMenuItem
50
+ onClick={() => {
51
+ handleChange(value);
52
+ onClose();
53
+ }}
54
+ selected={selected === value}
55
+ width="100%"
56
+ >
54
57
  {text}
55
58
  </DropdownMenuItem>
56
59
  );
57
60
 
58
61
  return (
59
- <PlacementManager>
60
- <PlacementReference>
61
- {() => (
62
- <DropdownButton
63
- {...rest}
64
- onClick={() => {
65
- setVisible(!visible);
66
- }}
67
- >
68
- <Text hasEllipsis>{children}</Text>
69
- </DropdownButton>
70
- )}
71
- </PlacementReference>
72
-
73
- <Placement onClose={() => setVisible(false)} sameWidth visible={visible}>
74
- {() => (
75
- <DropdownMenu className={menuClassName} maxHeight={maxHeight} width="100%">
76
- {options.map((option) => (
77
- <React.Fragment key={option.text}>
78
- {'options' in option ? (
79
- <DropdownMenuItemGroup text={option.text}>
80
- {option.options.map((groupOption) => (
81
- <React.Fragment key={groupOption.value}>{renderOption(groupOption)}</React.Fragment>
82
- ))}
83
- </DropdownMenuItemGroup>
84
- ) : (
85
- renderOption(option)
86
- )}
87
- </React.Fragment>
88
- ))}
89
- </DropdownMenu>
90
- )}
91
- </Placement>
92
- </PlacementManager>
62
+ <Popover matchWidth>
63
+ {({ onClose }) => (
64
+ <>
65
+ {' '}
66
+ <PopoverTrigger>
67
+ <Button
68
+ width="100%"
69
+ variant="secondary"
70
+ rightIconName="ChevronDown"
71
+ justifyContent="space-between"
72
+ {...rest}
73
+ >
74
+ <Text as="span" hasEllipsis>
75
+ {children}
76
+ </Text>
77
+ </Button>
78
+ </PopoverTrigger>
79
+ <PopoverContent>
80
+ <DropdownMenu className={menuClassName} maxHeight={maxHeight} width="100%">
81
+ {options.map((option) => (
82
+ <React.Fragment key={option.text}>
83
+ {'options' in option ? (
84
+ <DropdownMenuItemGroup text={option.text}>
85
+ {option.options.map((groupOption) => (
86
+ <React.Fragment key={groupOption.value}>{renderOption(groupOption, onClose)}</React.Fragment>
87
+ ))}
88
+ </DropdownMenuItemGroup>
89
+ ) : (
90
+ renderOption(option, onClose)
91
+ )}
92
+ </React.Fragment>
93
+ ))}
94
+ </DropdownMenu>
95
+ </PopoverContent>
96
+ </>
97
+ )}
98
+ </Popover>
93
99
  );
94
100
  };
95
101
 
package/src/old.ts CHANGED
@@ -18,12 +18,6 @@ export { default as DatePicker } from './Old/DatePicker/DatePicker';
18
18
  export type { Props as DropdownProps } from './Old/Dropdown/Dropdown';
19
19
  export { default as Dropdown } from './Old/Dropdown/Dropdown';
20
20
 
21
- export type { Props as DropdownButtonProps } from './Old/Dropdown/DropdownButton';
22
- export { default as DropdownButton } from './Old/Dropdown/DropdownButton';
23
-
24
- export type { Props as DropdownMenusProps } from './Old/Dropdown/DropdownMenus';
25
- export { default as DropdownMenus } from './Old/Dropdown/DropdownMenus';
26
-
27
21
  export type { Props as DropdownMenuProps } from './Old/Dropdown/DropdownMenu';
28
22
  export { default as DropdownMenu } from './Old/Dropdown/DropdownMenu';
29
23