@bitrise/bitkit 9.14.0-alpha-chakra.5 → 9.14.0-alpha-chakra.8

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": "9.14.0-alpha-chakra.5",
4
+ "version": "9.14.0-alpha-chakra.8",
5
5
  "repository": "git@github.com:bitrise-io/bitkit.git",
6
6
  "main": "src/index.ts",
7
7
  "license": "UNLICENSED",
@@ -5,6 +5,10 @@ import Dropdown from './Dropdown';
5
5
  export default {
6
6
  title: 'Components/Dropdown',
7
7
  component: Dropdown,
8
+ args: {
9
+ isDisabled: false,
10
+ isLoading: false,
11
+ },
8
12
  argTypes: {
9
13
  onChange: {
10
14
  action: 'onChange event',
@@ -1,4 +1,5 @@
1
1
  import { ChakraStylesConfig } from 'chakra-react-select';
2
+ import type { SystemStyleObject } from '@chakra-ui/theme-tools';
2
3
  import SelectTheme from '../Select/Select.theme';
3
4
 
4
5
  const controlTextStyle = {
@@ -12,22 +13,19 @@ const controlTextStyle = {
12
13
  whiteSpace: 'nowrap',
13
14
  };
14
15
 
15
- const getDropdownStyles = (size: 'small' | 'medium'): ChakraStylesConfig => ({
16
+ const getDropdownStyles = (size: 'small' | 'medium', additionalStyle?: SystemStyleObject): ChakraStylesConfig => ({
16
17
  container: (_provided, state) => ({
17
18
  borderRadius: '4',
18
19
  boxShadow: state.isFocused ? 'outline' : 'none',
19
20
  position: 'relative',
21
+ zIndex: state.isFocused ? '1' : '0',
22
+ ...additionalStyle,
20
23
  }),
21
24
  control: () => ({
22
25
  display: 'flex',
23
26
  ...SelectTheme.baseStyle.field,
24
27
  ...SelectTheme.sizes[size].field,
25
- }),
26
- dropdownIndicator: () => ({
27
- position: 'absolute',
28
- right: '7px',
29
- top: '50%',
30
- transform: 'translateY(-50%)',
28
+ paddingRight: '8',
31
29
  }),
32
30
  groupHeading: () => ({
33
31
  display: 'flex',
@@ -46,6 +44,18 @@ const getDropdownStyles = (size: 'small' | 'medium'): ChakraStylesConfig => ({
46
44
  bg: 'neutral.90',
47
45
  },
48
46
  }),
47
+ indicatorsContainer: (provided) => ({
48
+ ...provided,
49
+ width: '100%',
50
+ alignItems: 'center',
51
+ justifyContent: 'flex-end',
52
+ }),
53
+ loadingIndicator: () => ({
54
+ color: 'neutral.70',
55
+ width: '16',
56
+ height: '16',
57
+ marginRight: '8',
58
+ }),
49
59
  menu: () => ({
50
60
  position: 'absolute',
51
61
  transform: 'translateY(8px)',
@@ -60,7 +70,6 @@ const getDropdownStyles = (size: 'small' | 'medium'): ChakraStylesConfig => ({
60
70
  padding: '12',
61
71
  }),
62
72
  placeholder: () => ({
63
- color: 'text.secondary',
64
73
  ...controlTextStyle,
65
74
  }),
66
75
  singleValue: () => controlTextStyle,
@@ -1,11 +1,15 @@
1
1
  import React from 'react';
2
- import { chakraComponents, ChakraStylesConfig, Props, DropdownIndicatorProps, Select } from 'chakra-react-select';
2
+ import { chakraComponents, ChakraStylesConfig, DropdownIndicatorProps, Props, Select } from 'chakra-react-select';
3
+ import type { SystemStyleObject } from '@chakra-ui/theme-tools';
3
4
  import Icon from '../../Old/Icon/Icon';
4
5
  import getDropdownStyles from './Dropdown.styles';
5
6
 
6
- export type DropdownProps = {
7
+ export type DropdownProps = Omit<Props, 'defaultValue' | 'onChange'> & {
8
+ defaultValue?: any;
9
+ onChange?: ((newValue: any) => void) | undefined;
7
10
  size?: 'small' | 'medium';
8
- } & Props;
11
+ style?: SystemStyleObject;
12
+ };
9
13
 
10
14
  const components = {
11
15
  DropdownIndicator: (props: DropdownIndicatorProps) => {
@@ -18,21 +22,39 @@ const components = {
18
22
  };
19
23
 
20
24
  const Dropdown = (props: DropdownProps) => {
21
- const { defaultValue, onChange, options, placeholder, size = 'medium' } = props;
22
- const chakraStyles: ChakraStylesConfig = getDropdownStyles(size);
23
-
24
- return (
25
- <Select
26
- chakraStyles={chakraStyles}
27
- components={components}
28
- defaultValue={defaultValue}
29
- isSearchable={false}
30
- onChange={onChange}
31
- options={options}
32
- placeholder={placeholder}
33
- selectedOptionStyle="check"
34
- />
35
- );
25
+ const { defaultValue, isDisabled, isLoading, onChange, options, placeholder, size = 'medium', style } = props;
26
+ const chakraStyles: ChakraStylesConfig = getDropdownStyles(size, style);
27
+
28
+ const defaultValueWithLabel = defaultValue;
29
+
30
+ if (!defaultValue?.label && defaultValue?.text) {
31
+ defaultValueWithLabel.label = defaultValue.text;
32
+ }
33
+
34
+ const mappedOptions = options?.map((opt: any) => {
35
+ if (!opt.label && opt.text) {
36
+ return {
37
+ ...opt,
38
+ label: opt.text,
39
+ };
40
+ }
41
+ return opt;
42
+ });
43
+
44
+ const properties: Props = {
45
+ chakraStyles,
46
+ components,
47
+ defaultValue,
48
+ isDisabled: isDisabled || isLoading,
49
+ isLoading,
50
+ isSearchable: false,
51
+ onChange,
52
+ options: mappedOptions,
53
+ placeholder,
54
+ selectedOptionStyle: 'check',
55
+ };
56
+
57
+ return <Select {...properties} />;
36
58
  };
37
59
 
38
60
  Dropdown.defaultProps = {
package/src/old.ts CHANGED
@@ -61,6 +61,8 @@ export { default as DatePicker } from './Old/DatePicker/DatePicker';
61
61
  export type { Props as DotProps } from './Old/Dot/Dot';
62
62
  export { default as Dot } from './Old/Dot/Dot';
63
63
 
64
+ export type { Props as OldDropdownProps } from './Old/Dropdown/Dropdown';
65
+
64
66
  export type { Props as DropdownButtonProps } from './Old/Dropdown/DropdownButton';
65
67
  export { default as DropdownButton } from './Old/Dropdown/DropdownButton';
66
68