@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 +1 -1
- package/src/Components/Form/Checkbox/Checkbox.tsx +1 -1
- package/src/Components/Form/Form.theme.ts +1 -0
- package/src/Components/Form/Radio/Radio.tsx +1 -1
- package/src/Components/Form/Textarea/Textarea.stories.tsx +1 -1
- package/src/Components/Form/Textarea/Textarea.test.tsx +35 -0
- package/src/Components/Form/Textarea/Textarea.theme.ts +6 -1
- package/src/Components/Form/Textarea/Textarea.tsx +20 -8
- package/src/Components/Select/Select.stories.tsx +7 -0
- package/src/Components/Select/Select.tsx +64 -19
- package/src/Components/Toggle/Toggle.stories.tsx +2 -1
- package/src/Components/Toggle/Toggle.theme.ts +3 -1
- package/src/Components/Toggle/Toggle.tsx +22 -8
- package/src/Foundations/Shadows/Shadows.ts +1 -0
- package/src/tsconfig.tsbuildinfo +1 -1
package/package.json
CHANGED
|
@@ -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'
|
|
5
|
+
'data-testid'?: string;
|
|
6
6
|
};
|
|
7
7
|
|
|
8
8
|
export interface CheckboxProps extends Omit<ChakraCheckboxProps, 'icon' | 'iconColor' | 'iconSize' | 'inputProps'> {
|
|
@@ -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'
|
|
4
|
+
'data-testid'?: string;
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
export interface RadioProps extends Omit<ChakraRadioProps, 'inputProps'> {
|
|
@@ -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: '
|
|
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
|
-
|
|
13
|
+
export interface TextareaProps extends Omit<FormControlProps, 'label' | 'onChange' | 'onBlur'> {
|
|
14
|
+
'data-testid'?: string;
|
|
15
15
|
errorText?: string;
|
|
16
16
|
isLoading?: boolean;
|
|
17
|
-
|
|
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
|
-
|
|
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
|
|
59
|
+
<FormControl {...formControlProps}>
|
|
48
60
|
{label && <FormLabel>{label}</FormLabel>}
|
|
49
61
|
<ChakraTextarea {...textareaProps} />
|
|
50
62
|
{errorText && <FormErrorMessage as="p">{errorText}</FormErrorMessage>}
|
|
51
|
-
{
|
|
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 {
|
|
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
|
|
5
|
-
|
|
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, '
|
|
10
|
-
const {
|
|
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
|
|
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
|
-
|
|
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
|
|
25
|
-
|
|
64
|
+
if ('value' in selectProperties) {
|
|
65
|
+
selectProperties.value = selectProperties.value || '';
|
|
26
66
|
} else {
|
|
27
|
-
|
|
67
|
+
selectProperties.defaultValue = '';
|
|
28
68
|
}
|
|
29
69
|
}
|
|
30
70
|
return (
|
|
31
|
-
<
|
|
32
|
-
{
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 {...
|
|
57
|
-
<Box sx={css.
|
|
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
|
-
{
|
|
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
|
|