@bitrise/bitkit 13.204.0 → 13.206.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.204.0",
4
+ "version": "13.206.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'];
@@ -20,6 +20,7 @@ import {
20
20
  import Icon, { TypeIconName } from '../../Icon/Icon';
21
21
  import { TooltipProps } from '../../Tooltip/Tooltip';
22
22
  import FormLabel, { FormLabelProps } from '../FormLabel';
23
+ import { getDataAttributes } from '../../../utils/utils';
23
24
 
24
25
  type UsedFormControlProps = Omit<FormControlProps, 'label' | 'onBlur' | 'onChange'>;
25
26
  type UsedChakraInputProps = Pick<
@@ -42,7 +43,6 @@ type UsedChakraInputProps = Pick<
42
43
  >;
43
44
  export interface InputProps extends UsedFormControlProps, UsedChakraInputProps {
44
45
  badge?: FormLabelProps['badge'];
45
- 'data-testid'?: string;
46
46
  errorText?: ReactNode;
47
47
  infoTooltipLabel?: string;
48
48
  infoTooltipProps?: TooltipProps;
@@ -74,7 +74,6 @@ const Input = forwardRef<InputProps, 'div'>((props, ref) => {
74
74
  autoComplete,
75
75
  autoFocus,
76
76
  badge,
77
- 'data-testid': dataTestid,
78
77
  defaultValue,
79
78
  errorText,
80
79
  helperText,
@@ -124,7 +123,6 @@ const Input = forwardRef<InputProps, 'div'>((props, ref) => {
124
123
  const inputProps = {
125
124
  autoComplete,
126
125
  autoFocus,
127
- 'data-testid': dataTestid,
128
126
  defaultValue,
129
127
  max,
130
128
  maxLength,
@@ -142,6 +140,8 @@ const Input = forwardRef<InputProps, 'div'>((props, ref) => {
142
140
  value,
143
141
  };
144
142
 
143
+ const dataAttributes = getDataAttributes(rest);
144
+
145
145
  const inputInlinePadding = size === 'lg' ? '15' : '11';
146
146
 
147
147
  const RightContentWrapper = rightAddonPlacement === 'inside' ? InputRightElement : InputRightAddon;
@@ -193,6 +193,7 @@ const Input = forwardRef<InputProps, 'div'>((props, ref) => {
193
193
  paddingLeft={inputLeftPadding}
194
194
  paddingRight={inputRightPadding}
195
195
  {...inputProps}
196
+ {...dataAttributes}
196
197
  onChange={onInputChange}
197
198
  />
198
199
  {rightAddon && <RightContentWrapper>{rightAddon}</RightContentWrapper>}
@@ -10,6 +10,7 @@ import {
10
10
  } from '@chakra-ui/react';
11
11
  import { TooltipProps } from '../../Tooltip/Tooltip';
12
12
  import FormLabel, { FormLabelProps } from '../FormLabel';
13
+ import { getDataAttributes } from '../../../utils/utils';
13
14
 
14
15
  type UsedFormControlProps = Omit<FormControlProps, 'label' | 'onBlur' | 'onChange'>;
15
16
  type UsedChakraTextProps = Pick<
@@ -28,7 +29,6 @@ type UsedChakraTextProps = Pick<
28
29
 
29
30
  export interface TextareaProps extends UsedFormControlProps, UsedChakraTextProps {
30
31
  badge?: FormLabelProps['badge'];
31
- 'data-testid'?: string;
32
32
  errorText?: string;
33
33
  infoTooltipLabel?: string;
34
34
  infoTooltipProps?: TooltipProps;
@@ -50,7 +50,6 @@ const Textarea = forwardRef<TextareaProps, 'div'>((props, ref) => {
50
50
  autoComplete,
51
51
  autoFocus,
52
52
  badge,
53
- 'data-testid': dataTestid,
54
53
  errorText,
55
54
  helperText,
56
55
  infoTooltipLabel,
@@ -80,7 +79,6 @@ const Textarea = forwardRef<TextareaProps, 'div'>((props, ref) => {
80
79
  const textareaProps = {
81
80
  autoComplete,
82
81
  autoFocus,
83
- 'data-testid': dataTestid,
84
82
  maxLength,
85
83
  minLength,
86
84
  name,
@@ -101,6 +99,8 @@ const Textarea = forwardRef<TextareaProps, 'div'>((props, ref) => {
101
99
  }
102
100
  };
103
101
 
102
+ const dataAttributes = getDataAttributes(props);
103
+
104
104
  return (
105
105
  <FormControl {...formControlProps}>
106
106
  <FormLabel
@@ -114,7 +114,7 @@ const Textarea = forwardRef<TextareaProps, 'div'>((props, ref) => {
114
114
  {label}
115
115
  </FormLabel>
116
116
 
117
- <ChakraTextarea {...textareaProps} onChange={onTextareaChange} />
117
+ <ChakraTextarea {...textareaProps} {...dataAttributes} onChange={onTextareaChange} />
118
118
  {errorText && <FormErrorMessage as="p">{errorText}</FormErrorMessage>}
119
119
  {helperText && <FormHelperText as="p">{helperText}</FormHelperText>}
120
120
  </FormControl>
@@ -14,10 +14,10 @@ import Icon from '../Icon/Icon';
14
14
  import ProgressSpinner from '../ProgressSpinner/ProgressSpinner';
15
15
  import FormLabel, { FormLabelProps } from '../Form/FormLabel';
16
16
  import { TooltipProps } from '../Tooltip/Tooltip';
17
+ import { getDataAttributes } from '../../utils/utils';
17
18
 
18
19
  export interface SelectProps extends Omit<FormControlProps, 'label' | 'onBlur' | 'onChange'> {
19
20
  badge?: FormLabelProps['badge'];
20
- 'data-testid'?: string;
21
21
  errorText?: string;
22
22
  helperText?: ReactNode;
23
23
  infoTooltipLabel?: string;
@@ -37,7 +37,6 @@ const Select = forwardRef<SelectProps, 'div'>((props, ref) => {
37
37
  const {
38
38
  badge,
39
39
  children,
40
- 'data-testid': dataTestid,
41
40
  defaultValue,
42
41
  errorText,
43
42
  helperText,
@@ -74,6 +73,9 @@ const Select = forwardRef<SelectProps, 'div'>((props, ref) => {
74
73
  size,
75
74
  value,
76
75
  };
76
+
77
+ const dataAttributes = getDataAttributes(props);
78
+
77
79
  if (placeholder) {
78
80
  if ('value' in props) {
79
81
  selectProperties.value = selectProperties.value ?? '';
@@ -94,7 +96,7 @@ const Select = forwardRef<SelectProps, 'div'>((props, ref) => {
94
96
  {label}
95
97
  </FormLabel>
96
98
  <Box sx={style.selectContainer}>
97
- <ChakraSelect ref={ref} data-testid={dataTestid} {...selectProperties} sx={style.field}>
99
+ <ChakraSelect ref={ref} {...selectProperties} {...dataAttributes} sx={style.field}>
98
100
  {placeholder && (
99
101
  <option disabled value="">
100
102
  {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;