@bitrise/bitkit 10.22.0 → 10.23.0-alpha-chakra.2

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.22.0",
4
+ "version": "10.23.0-alpha-chakra.2",
5
5
  "repository": "git@github.com:bitrise-io/bitkit.git",
6
6
  "main": "src/index.ts",
7
7
  "license": "UNLICENSED",
@@ -2,7 +2,7 @@ import { Checkbox as ChakraCheckbox, CheckboxProps as ChakraCheckboxProps, forwa
2
2
  import Icon from '../../Icon/Icon';
3
3
 
4
4
  type CheckboxInputProps = ChakraCheckboxProps['inputProps'] & {
5
- 'data-testid': string;
5
+ 'data-testid'?: string;
6
6
  };
7
7
 
8
8
  export interface CheckboxProps extends Omit<ChakraCheckboxProps, 'icon' | 'iconColor' | 'iconSize' | 'inputProps'> {
@@ -24,6 +24,7 @@ const FormTheme = {
24
24
  FormLabel: {
25
25
  baseStyle: {
26
26
  marginBottom: '4',
27
+ fontSize: '2',
27
28
  fontWeight: 'bold',
28
29
  } as ComponentStyleConfig,
29
30
  },
@@ -1,7 +1,7 @@
1
1
  import { Radio as ChakraRadio, RadioProps as ChakraRadioProps, forwardRef } from '@chakra-ui/react';
2
2
 
3
3
  type RadioInputProps = ChakraRadioProps['inputProps'] & {
4
- 'data-testid': string;
4
+ 'data-testid'?: string;
5
5
  };
6
6
 
7
7
  export interface RadioProps extends Omit<ChakraRadioProps, 'inputProps'> {
@@ -8,7 +8,7 @@ export default {
8
8
  export const WithProps = {
9
9
  args: {
10
10
  errorText: '',
11
- helpherText:
11
+ helperText:
12
12
  'Inline help. Maecenas a turpis tortor. Nunc vitae libero tempor, ullamcorper purus quis, mattis tellus.',
13
13
  isDisabled: false,
14
14
  isInvalid: false,
@@ -0,0 +1,35 @@
1
+ import { render, screen } from '@testing-library/react';
2
+ import userEvent from '@testing-library/user-event';
3
+ import { useForm } from 'react-hook-form';
4
+ import Textarea from './Textarea';
5
+
6
+ describe('Textarea', () => {
7
+ it('forwards data-testid', async () => {
8
+ render(<Textarea data-testid="testid" />);
9
+ const elem = await screen.findByTestId('testid');
10
+ expect(elem.tagName).toBe('TEXTAREA');
11
+ expect(elem).toBeInTheDocument();
12
+ });
13
+ describe('react-hook-form support', () => {
14
+ it('sends data when submitted', async () => {
15
+ const handler = jest.fn();
16
+ const TestComponent = () => {
17
+ const { register, handleSubmit } = useForm();
18
+ return (
19
+ <form onSubmit={handleSubmit((data) => handler(data))}>
20
+ <Textarea {...register('textarea')} />
21
+ <button type="submit">Send</button>
22
+ </form>
23
+ );
24
+ };
25
+ render(<TestComponent />);
26
+ const submit = await screen.findByRole('button', { name: 'Send' });
27
+ const textarea = await screen.findByRole('textbox');
28
+ await userEvent.type(textarea, 'test');
29
+ await userEvent.click(submit);
30
+
31
+ expect(handler).toHaveBeenCalledWith({ textarea: 'test' });
32
+ expect(handler).toHaveBeenCalledTimes(1);
33
+ });
34
+ });
35
+ });
@@ -14,12 +14,17 @@ const TextareaTheme: ComponentStyleConfig = {
14
14
  appearance: 'none',
15
15
  lineHeight: 'short',
16
16
  verticalAlign: 'top',
17
+ transition: '200ms',
18
+ _placeholder: {
19
+ fontStyle: 'italic',
20
+ },
17
21
  _disabled: {
18
22
  background: 'neutral.93',
19
23
  cursor: 'not-allowed',
20
24
  },
21
25
  _focusVisible: {
22
- boxShadow: 'outline',
26
+ boxShadow: 'formFocus',
27
+ borderColor: 'purple.50',
23
28
  },
24
29
  _invalid: {
25
30
  color: 'red.50',
@@ -10,13 +10,15 @@ import {
10
10
  forwardRef,
11
11
  } from '@chakra-ui/react';
12
12
 
13
- export interface TextareaProps extends Omit<FormControlProps, 'label' | 'onChange'> {
14
- dataTestid?: string;
13
+ export interface TextareaProps extends Omit<FormControlProps, 'label' | 'onChange' | 'onBlur'> {
14
+ 'data-testid'?: string;
15
15
  errorText?: string;
16
16
  isLoading?: boolean;
17
- helpherText?: string;
17
+ helperText?: string;
18
18
  label?: ReactNode;
19
+ name?: string;
19
20
  onChange?: ChakraTextareaProps['onChange'];
21
+ onBlur?: ChakraTextareaProps['onBlur'];
20
22
  value?: ChakraTextareaProps['value'];
21
23
  }
22
24
 
@@ -25,30 +27,40 @@ export interface TextareaProps extends Omit<FormControlProps, 'label' | 'onChang
25
27
  */
26
28
  const Textarea = forwardRef<TextareaProps, 'div'>((props, ref) => {
27
29
  const {
28
- dataTestid,
30
+ 'data-testid': dataTestid,
29
31
  errorText,
30
- helpherText,
32
+ helperText,
31
33
  isDisabled,
32
34
  isInvalid,
33
35
  isLoading,
34
36
  label,
35
37
  placeholder,
36
38
  onChange,
39
+ onBlur,
40
+ name,
37
41
  value,
38
42
  ...rest
39
43
  } = props;
44
+ const formControlProps = {
45
+ isDisabled: isDisabled || isLoading,
46
+ isInvalid: isInvalid || !!errorText,
47
+ ...rest,
48
+ ref,
49
+ };
40
50
  const textareaProps = {
41
- dataTestid,
51
+ 'data-testid': dataTestid,
42
52
  onChange,
53
+ onBlur,
54
+ name,
43
55
  placeholder,
44
56
  value,
45
57
  };
46
58
  return (
47
- <FormControl isDisabled={isDisabled || isLoading} isInvalid={isInvalid || !!errorText} {...rest} ref={ref}>
59
+ <FormControl {...formControlProps}>
48
60
  {label && <FormLabel>{label}</FormLabel>}
49
61
  <ChakraTextarea {...textareaProps} />
50
62
  {errorText && <FormErrorMessage as="p">{errorText}</FormErrorMessage>}
51
- {helpherText && <FormHelperText as="p">{helpherText}</FormHelperText>}
63
+ {helperText && <FormHelperText as="p">{helperText}</FormHelperText>}
52
64
  </FormControl>
53
65
  );
54
66
  });
@@ -6,6 +6,13 @@ import Select from './Select';
6
6
  export default {
7
7
  title: 'Components/Select',
8
8
  component: Select,
9
+ args: {
10
+ isLoading: false,
11
+ errorText: 'Error text',
12
+ helperText: 'Helpher text',
13
+ label: 'Label',
14
+ name: 'Name',
15
+ },
9
16
  argTypes: {
10
17
  onChange: {
11
18
  action: 'onChange event',
@@ -1,41 +1,86 @@
1
- import { forwardRef, Select as ChakraSelect, SelectProps as ChakraSelectProps, Spinner } from '@chakra-ui/react';
1
+ import { ReactNode } from 'react';
2
+ import {
3
+ FormControl,
4
+ FormControlProps,
5
+ FormErrorMessage,
6
+ FormHelperText,
7
+ FormLabel,
8
+ forwardRef,
9
+ Select as ChakraSelect,
10
+ SelectProps as ChakraSelectProps,
11
+ Spinner,
12
+ } from '@chakra-ui/react';
2
13
  import Icon from '../Icon/Icon';
3
14
 
4
- export interface SelectProps extends ChakraSelectProps {
5
- size?: 'small' | 'medium';
15
+ export interface SelectProps extends Omit<FormControlProps, 'label' | 'onChange'> {
16
+ 'data-testid'?: string;
17
+ errorText?: string;
18
+ helperText?: string;
6
19
  isLoading?: boolean;
20
+ label?: ReactNode;
21
+ name?: string;
22
+ onChange?: ChakraSelectProps['onChange'];
23
+ size?: 'small' | 'medium';
24
+ value?: ChakraSelectProps['value'];
7
25
  }
8
26
 
9
- const Select = forwardRef<SelectProps, 'select'>((props, ref) => {
10
- const { size, placeholder, children, isDisabled, isLoading, ...rest } = props;
27
+ const Select = forwardRef<SelectProps, 'div'>((props, ref) => {
28
+ const {
29
+ children,
30
+ 'data-testid': dataTestid,
31
+ errorText,
32
+ helperText,
33
+ isDisabled,
34
+ isInvalid,
35
+ isLoading,
36
+ label,
37
+ name,
38
+ onChange,
39
+ placeholder,
40
+ size,
41
+ value,
42
+ ...rest
43
+ } = props;
11
44
  const iconSize = size === 'medium' ? '24' : '16';
12
- const properties: ChakraSelectProps = {
45
+ const formControlProps = {
46
+ isDisabled: isDisabled || isLoading,
47
+ isInvalid: isInvalid || !!errorText,
48
+ ...rest,
49
+ ref,
50
+ };
51
+ const selectProperties: ChakraSelectProps = {
13
52
  icon: isLoading ? (
14
53
  <Spinner width={iconSize} height={iconSize} marginEnd="4" />
15
54
  ) : (
16
55
  <Icon name="DropdownArrows" fontSize={iconSize} size={iconSize} />
17
56
  ),
18
- isDisabled: isLoading || isDisabled,
57
+ name,
58
+ onChange,
19
59
  size,
60
+ value,
20
61
  variant: 'select',
21
- ...rest,
22
62
  };
23
63
  if (placeholder) {
24
- if ('value' in properties) {
25
- properties.value = properties.value || '';
64
+ if ('value' in selectProperties) {
65
+ selectProperties.value = selectProperties.value || '';
26
66
  } else {
27
- properties.defaultValue = '';
67
+ selectProperties.defaultValue = '';
28
68
  }
29
69
  }
30
70
  return (
31
- <ChakraSelect ref={ref} {...properties}>
32
- {placeholder && (
33
- <option hidden disabled value="">
34
- {placeholder}
35
- </option>
36
- )}
37
- {children}
38
- </ChakraSelect>
71
+ <FormControl {...formControlProps}>
72
+ {label && <FormLabel>{label}</FormLabel>}
73
+ <ChakraSelect data-testid={dataTestid} ref={ref} {...selectProperties}>
74
+ {placeholder && (
75
+ <option hidden disabled value="">
76
+ {placeholder}
77
+ </option>
78
+ )}
79
+ {children}
80
+ </ChakraSelect>
81
+ {errorText && <FormErrorMessage as="p">{errorText}</FormErrorMessage>}
82
+ {helperText && <FormHelperText as="p">{helperText}</FormHelperText>}
83
+ </FormControl>
39
84
  );
40
85
  });
41
86
 
@@ -9,7 +9,8 @@ export default {
9
9
  export const WithProps = {
10
10
  args: {
11
11
  defaultChecked: false,
12
- helpherText:
12
+ errorText: '',
13
+ helperText:
13
14
  'Inline help. Maecenas a turpis tortor. Nunc vitae libero tempor, ullamcorper purus quis, mattis tellus.',
14
15
  isDisabled: false,
15
16
  isLoading: false,
@@ -2,7 +2,7 @@ import type { ComponentStyleConfig } from '@chakra-ui/theme';
2
2
 
3
3
  const ToggleTheme: ComponentStyleConfig = {
4
4
  baseStyle: {
5
- formControl: {
5
+ labelWrapper: {
6
6
  display: 'flex',
7
7
  gap: '8',
8
8
  },
@@ -61,7 +61,9 @@ const ToggleTheme: ComponentStyleConfig = {
61
61
  },
62
62
  },
63
63
  label: {
64
+ fontSize: '3',
64
65
  fontWeight: 'normal',
66
+ lineHeight: '3',
65
67
  marginBottom: 0,
66
68
  },
67
69
  spinner: {
@@ -2,6 +2,7 @@ import { ReactNode } from 'react';
2
2
  import {
3
3
  FormControl,
4
4
  FormControlProps,
5
+ FormErrorMessage,
5
6
  FormHelperText,
6
7
  FormLabel,
7
8
  Spinner,
@@ -13,14 +14,16 @@ import {
13
14
  import Box from '../Box/Box';
14
15
 
15
16
  export interface ToggleProps extends Omit<FormControlProps, 'label'> {
16
- dataTestid?: string;
17
+ 'data-testid'?: string;
17
18
  defaultChecked?: SwitchProps['defaultChecked'];
19
+ errorText?: string;
18
20
  id?: SwitchProps['id'];
19
21
  isChecked?: SwitchProps['isChecked'];
20
22
  isDisabled?: SwitchProps['isDisabled'];
21
23
  isLoading?: boolean;
22
- helpherText?: string;
24
+ helperText?: string;
23
25
  label?: ReactNode;
26
+ name?: string;
24
27
  onChange?: SwitchProps['onChange'];
25
28
  value?: SwitchProps['value'];
26
29
  }
@@ -30,31 +33,41 @@ export interface ToggleProps extends Omit<FormControlProps, 'label'> {
30
33
  */
31
34
  const Toggle = forwardRef<ToggleProps, 'div'>((props, ref) => {
32
35
  const {
33
- dataTestid,
36
+ 'data-testid': dataTestid,
34
37
  defaultChecked,
35
- helpherText,
38
+ errorText,
39
+ helperText,
36
40
  id,
37
41
  isChecked,
42
+ isInvalid,
38
43
  isDisabled,
39
44
  isLoading,
40
45
  label,
46
+ name,
41
47
  onChange,
42
48
  value,
43
49
  ...rest
44
50
  } = props;
51
+ const formControlProps = {
52
+ isDisabled: isDisabled || isLoading,
53
+ isInvalid: isInvalid || !!errorText,
54
+ ...rest,
55
+ ref,
56
+ };
45
57
  const switchProps = {
46
- dataTestid,
58
+ 'data-testid': dataTestid,
47
59
  defaultChecked,
48
60
  id,
49
61
  isChecked,
50
62
  isDisabled: isDisabled || isLoading,
63
+ name,
51
64
  onChange,
52
65
  value,
53
66
  };
54
67
  const css = useMultiStyleConfig('Switch');
55
68
  return (
56
- <FormControl {...rest} ref={ref}>
57
- <Box sx={css.formControl}>
69
+ <FormControl {...formControlProps}>
70
+ <Box sx={css.labelWrapper}>
58
71
  <Switch {...switchProps} />
59
72
  {label && (
60
73
  <FormLabel htmlFor={id} sx={css.label}>
@@ -63,7 +76,8 @@ const Toggle = forwardRef<ToggleProps, 'div'>((props, ref) => {
63
76
  )}
64
77
  {isLoading && <Spinner sx={css.spinner} />}
65
78
  </Box>
66
- {helpherText && <FormHelperText as="p">{helpherText}</FormHelperText>}
79
+ {errorText && <FormErrorMessage as="p">{errorText}</FormErrorMessage>}
80
+ {helperText && <FormHelperText as="p">{helperText}</FormHelperText>}
67
81
  </FormControl>
68
82
  );
69
83
  });
@@ -5,6 +5,7 @@ const shadows = {
5
5
  inner: '0 0.125rem 0.1875rem 0 rgba(0, 0, 0, 0.1) inset',
6
6
  outline: '0 0 0 3px #C289E6',
7
7
  tooltip: '0 0.0625rem 0.1875rem rgba(0, 0, 0, 0.2)',
8
+ formFocus: '0 0.125rem 0.1875rem 0 rgba(0, 0, 0, 0.1) inset, inset 0 0 0 3px rgba(146, 71, 194, 0.3)',
8
9
  none: 'none',
9
10
  };
10
11