@bitrise/bitkit 13.203.0 → 13.205.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": "13.203.0",
4
+ "version": "13.205.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+ssh://git@github.com/bitrise-io/bitkit.git"
@@ -21,6 +21,7 @@ import { FloatingFocusManager } from '@floating-ui/react-dom-interactions';
21
21
  import SearchInput from '../SearchInput/SearchInput';
22
22
  import FormLabel from '../Form/FormLabel';
23
23
  import { AvatarProps } from '../Avatar/Avatar';
24
+ import { getDataAttributes } from '../../utils/utils';
24
25
  import { DropdownEventArgs, DropdownProvider, useDropdownContext, useDropdownStyles } from './Dropdown.context';
25
26
  import { DropdownDetailedOption, DropdownGroup, DropdownOption, DropdownOptionProps } from './DropdownOption';
26
27
  import DropdownButton from './DropdownButton';
@@ -261,7 +262,6 @@ const Dropdown = forwardRef<Element, DropdownProps<string | null>>(
261
262
  'aria-label': ariaLabel,
262
263
  badge,
263
264
  buttonProps = {},
264
- 'data-testid': dataTestid,
265
265
  defaultValue,
266
266
  disabled,
267
267
  dropdownMaxHeight,
@@ -291,6 +291,8 @@ const Dropdown = forwardRef<Element, DropdownProps<string | null>>(
291
291
  },
292
292
  ref,
293
293
  ) => {
294
+ const dataAttributes = getDataAttributes(props);
295
+
294
296
  const optionsRef = useRef(null);
295
297
  const {
296
298
  avatar,
@@ -352,7 +354,7 @@ const Dropdown = forwardRef<Element, DropdownProps<string | null>>(
352
354
  <>
353
355
  {name && formValue && <input name={name} type="hidden" value={formValue} />}
354
356
  <DropdownProvider context={dropdownCtx} styles={dropdownStyles}>
355
- <FormControl {...props} isDisabled={disabled} isInvalid={isError} isRequired={required}>
357
+ <FormControl {...props} {...dataAttributes} isDisabled={disabled} isInvalid={isError} isRequired={required}>
356
358
  <FormLabel
357
359
  badge={badge}
358
360
  infoTooltipLabel={infoTooltipLabel}
@@ -366,7 +368,6 @@ const Dropdown = forwardRef<Element, DropdownProps<string | null>>(
366
368
  {...buttonProps}
367
369
  aria-label={ariaLabel}
368
370
  avatar={avatar}
369
- data-testid={dataTestid}
370
371
  id={buttonId}
371
372
  iconName={iconName}
372
373
  blurHandler={blurHandler}
@@ -388,7 +389,7 @@ const Dropdown = forwardRef<Element, DropdownProps<string | null>>(
388
389
  </FormControl>
389
390
  {isOpen && (
390
391
  <FloatingFocusManager context={floatingContext} initialFocus={searchRef} returnFocus={returnFocus}>
391
- <chakra.div {...floatingProps} sx={listStyles}>
392
+ <chakra.div {...floatingProps} {...dataAttributes} sx={listStyles}>
392
393
  {searchElement}
393
394
  <chakra.div ref={optionsRef} __css={dropdownStyles.options} tabIndex={-1}>
394
395
  {children}
@@ -14,7 +14,6 @@ export interface DropdownProps<T> extends ChakraProps {
14
14
  badge?: FormLabelProps['badge'];
15
15
  buttonProps?: ChakraProps;
16
16
  children?: ReactNode;
17
- 'data-testid'?: string;
18
17
  defaultValue?: T;
19
18
  disabled?: boolean;
20
19
  dropdownMinHeight?: ChakraProps['minH'];
@@ -13,7 +13,7 @@ import RadioGroup from '../../Form/Radio/RadioGroup';
13
13
  import SearchInput from '../../SearchInput/SearchInput';
14
14
  import Text from '../../Text/Text';
15
15
  import { FilterStyle } from '../Filter.theme';
16
- import { FilterOptions, FilterValue } from '../Filter.types';
16
+ import { FilterOptions, FilterOptionsMap, FilterValue } from '../Filter.types';
17
17
  import { isEqual, useDebounce } from '../../../utils/utils';
18
18
  import { getOptionLabel } from '../Filter.utils';
19
19
  import { useFilterContext } from '../Filter.context';
@@ -50,6 +50,7 @@ const FilterForm = (props: FilterFormProps) => {
50
50
 
51
51
  const [isLoading, setLoading] = useState(Boolean(isInitialLoading));
52
52
  const [foundOptions, setFoundOptions] = useState<FilterOptions>([]);
53
+ const [foundOptionsMap, setFoundOptionsMap] = useState<FilterOptionsMap>();
53
54
 
54
55
  const isAsync = !!onAsyncSearch;
55
56
  const withSearch = (options && options.length > 5) || isAsync;
@@ -105,6 +106,7 @@ const FilterForm = (props: FilterFormProps) => {
105
106
  const response = await onAsyncSearch(category, searchValue);
106
107
  setLoading(false);
107
108
  setFoundOptions(response.options);
109
+ setFoundOptionsMap(response.optionsMap || optionsMap);
108
110
  }
109
111
  };
110
112
 
@@ -122,10 +124,13 @@ const FilterForm = (props: FilterFormProps) => {
122
124
 
123
125
  const isEditMode = value.length !== 0;
124
126
 
125
- const items =
126
- isAsync && !!searchValue
127
- ? Array.from(new Set(preserveOptionOrder ? [...foundOptions] : [...value, ...foundOptions]))
128
- : Array.from(new Set(preserveOptionOrder ? [...filteredOptions] : [...value, ...filteredOptions]));
127
+ const isAsyncSearch = isAsync && !!searchValue;
128
+
129
+ const items = isAsyncSearch
130
+ ? Array.from(new Set(preserveOptionOrder ? [...foundOptions] : [...value, ...foundOptions]))
131
+ : Array.from(new Set(preserveOptionOrder ? [...filteredOptions] : [...value, ...filteredOptions]));
132
+
133
+ const currentOptionMap = isAsyncSearch ? foundOptionsMap : optionsMap;
129
134
 
130
135
  return (
131
136
  <FocusLock>
@@ -156,7 +161,7 @@ const FilterForm = (props: FilterFormProps) => {
156
161
  ? items.map((opt) => (
157
162
  <Checkbox key={opt} value={opt}>
158
163
  {iconsMap && iconsMap[opt] && <Icon name={iconsMap[opt]} />}
159
- {getOptionLabel(opt, optionsMap)}
164
+ {getOptionLabel(opt, currentOptionMap)}
160
165
  </Checkbox>
161
166
  ))
162
167
  : getEmptyText()}
@@ -174,7 +179,7 @@ const FilterForm = (props: FilterFormProps) => {
174
179
  {items.length
175
180
  ? items.map((opt) => {
176
181
  const hasIcon = iconsMap && iconsMap[opt];
177
- const label = getOptionLabel(opt, optionsMap);
182
+ const label = getOptionLabel(opt, currentOptionMap);
178
183
  return (
179
184
  <Radio key={opt} value={opt}>
180
185
  {hasIcon ? (
@@ -17,7 +17,6 @@ import { TooltipProps } from '../Tooltip/Tooltip';
17
17
 
18
18
  export interface SelectProps extends Omit<FormControlProps, 'label' | 'onBlur' | 'onChange'> {
19
19
  badge?: FormLabelProps['badge'];
20
- 'data-testid'?: string;
21
20
  errorText?: string;
22
21
  helperText?: ReactNode;
23
22
  infoTooltipLabel?: string;
@@ -37,7 +36,6 @@ const Select = forwardRef<SelectProps, 'div'>((props, ref) => {
37
36
  const {
38
37
  badge,
39
38
  children,
40
- 'data-testid': dataTestid,
41
39
  defaultValue,
42
40
  errorText,
43
41
  helperText,
@@ -94,7 +92,7 @@ const Select = forwardRef<SelectProps, 'div'>((props, ref) => {
94
92
  {label}
95
93
  </FormLabel>
96
94
  <Box sx={style.selectContainer}>
97
- <ChakraSelect ref={ref} data-testid={dataTestid} {...selectProperties} sx={style.field}>
95
+ <ChakraSelect ref={ref} {...selectProperties} sx={style.field}>
98
96
  {placeholder && (
99
97
  <option disabled value="">
100
98
  {placeholder}
@@ -2,8 +2,9 @@ import { AlertDescription, AlertTitle, useToast as useChakraToast, UseToastOptio
2
2
  import { DateTime } from 'luxon';
3
3
  import Box from '../Box/Box';
4
4
  import Notification, { ActionProps, NotificationAction, NotificationProps } from '../Notification/Notification';
5
+ import { DataAttributes } from '../../types/bitkit';
5
6
 
6
- export interface ToastOptions {
7
+ export interface ToastOptions extends DataAttributes {
7
8
  title?: string;
8
9
  description: React.ReactNode;
9
10
  status: NotificationProps['status'];
@@ -16,27 +17,38 @@ export interface ToastOptions {
16
17
 
17
18
  const useToast = () => {
18
19
  const toast = useChakraToast();
19
- return (opts: ToastOptions) => {
20
+ return ({
21
+ action,
22
+ description,
23
+ duration,
24
+ isClosable,
25
+ position,
26
+ showTimestamp,
27
+ status,
28
+ title,
29
+ ...rest
30
+ }: ToastOptions) => {
20
31
  let timestamp: string | undefined;
21
- if (opts.showTimestamp) {
32
+ if (showTimestamp) {
22
33
  timestamp = DateTime.now().toFormat('hh:mm:ssa');
23
34
  }
24
35
  toast({
25
- duration: opts.duration,
26
- isClosable: opts.isClosable,
27
- position: opts.position || 'top-right',
36
+ duration,
37
+ isClosable,
38
+ position: position || 'top-right',
28
39
  render: ({ onClose }) => (
29
40
  <Notification
30
41
  boxShadow="large"
31
42
  maxW="437px"
32
- onClose={opts.isClosable ? onClose : undefined}
33
- status={opts.status || 'info'}
43
+ onClose={isClosable ? onClose : undefined}
44
+ status={status || 'info'}
45
+ {...rest}
34
46
  >
35
47
  <Box display="flex" flexDirection="column">
36
- {opts.title && <AlertTitle>{opts.title}</AlertTitle>}
37
- {opts.description && <AlertDescription>{opts.description}</AlertDescription>}
38
- {!opts.action && timestamp && <AlertDescription marginTop="8">{timestamp}</AlertDescription>}
39
- {opts.action && <NotificationAction alignSelf="start" marginBottom="4" marginTop="8" {...opts.action} />}
48
+ {title && <AlertTitle>{title}</AlertTitle>}
49
+ {description && <AlertDescription>{description}</AlertDescription>}
50
+ {!action && timestamp && <AlertDescription marginTop="8">{timestamp}</AlertDescription>}
51
+ {action && <NotificationAction alignSelf="start" marginBottom="4" marginTop="8" {...action} />}
40
52
  </Box>
41
53
  </Notification>
42
54
  ),
@@ -26,3 +26,7 @@ export type Shadows = keyof typeof tokens.shadows;
26
26
  export type TextSizes = '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8';
27
27
 
28
28
  export type TypeSizes = keyof typeof tokens.sizes;
29
+
30
+ export type DataAttributes = {
31
+ [key: `data-${string}`]: string;
32
+ };
@@ -50,3 +50,16 @@ export function useDebounce<T>(value: T, delay?: number): T {
50
50
 
51
51
  return debouncedValue;
52
52
  }
53
+
54
+ export function getDataAttributes(attributes: Record<string, any>) {
55
+ return Object.keys(attributes).reduce(
56
+ (acc, key) => {
57
+ if (key.startsWith('data-')) {
58
+ acc[key] = attributes[key as any];
59
+ }
60
+
61
+ return acc;
62
+ },
63
+ {} as { [key: string]: string | boolean },
64
+ );
65
+ }
@@ -1,37 +0,0 @@
1
- import { ElementType, ReactNode, useState } from 'react';
2
- import { MergeWithAs } from '@chakra-ui/react';
3
- import Dialog, { DialogProps } from '../Dialog/Dialog';
4
-
5
- type ValueDialogProps<T> = { value?: T; children: (value: T) => ReactNode } & Omit<
6
- DialogProps,
7
- 'isOpen' | 'onCloseComplete' | 'children'
8
- >;
9
-
10
- type ComponentWithAs<Component extends ElementType = 'section'> = {
11
- <T, AsComponent extends ElementType = Component>(
12
- props: MergeWithAs<
13
- React.ComponentProps<Component>,
14
- React.ComponentProps<AsComponent>,
15
- ValueDialogProps<T>,
16
- AsComponent
17
- >,
18
- ): JSX.Element;
19
- };
20
- const ValueDialog: ComponentWithAs = ({ value, onClose, children, ...rest }) => {
21
- const [closing, setClosing] = useState(false);
22
- return (
23
- <Dialog
24
- isOpen={Boolean(value) || !closing}
25
- onClose={() => setClosing(true)}
26
- onCloseComplete={() => {
27
- onClose();
28
- setClosing(false);
29
- }}
30
- {...rest}
31
- >
32
- {value && children(value)}
33
- </Dialog>
34
- );
35
- };
36
-
37
- export default ValueDialog;