@bitrise/bitkit 10.24.0 → 10.24.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/Icons/16x16/History.tsx +3 -2
- package/src/Components/Icons/24x24/History.tsx +3 -2
- package/src/Components/Select/Select.stories.tsx +17 -0
- package/src/Components/Select/Select.test.tsx +96 -0
- package/src/Components/Select/Select.tsx +7 -5
- package/src/Components/Text/Text.tsx +5 -6
- package/src/tsconfig.tsbuildinfo +1 -1
package/package.json
CHANGED
|
@@ -3,10 +3,11 @@ import { Icon, IconProps, forwardRef } from '@chakra-ui/react';
|
|
|
3
3
|
const History = forwardRef<IconProps, 'svg'>((props, ref) => (
|
|
4
4
|
<Icon ref={ref} viewBox="0 0 16 16" {...props}>
|
|
5
5
|
<path
|
|
6
|
+
fillRule="evenodd"
|
|
7
|
+
clipRule="evenodd"
|
|
8
|
+
d="M1.36668 8.66667C1.7039 12.0234 4.55826 14.6667 8.00002 14.6667C11.6667 14.6667 14.6667 11.6667 14.6667 8C14.6667 4.33333 11.6667 1.33333 8.00002 1.33333C5.37001 1.33333 3.08299 2.87679 2.00002 5.10263L2.00002 3.33333H0.666687V7.33333L4.66669 7.33333V6H3.05803C3.85332 4.05009 5.77296 2.66667 8.00002 2.66667C10.9334 2.66667 13.3334 5.06667 13.3334 8C13.3334 10.9333 10.9334 13.3333 8.00002 13.3333C5.29235 13.3333 3.03911 11.2884 2.70845 8.66667H1.36668ZM8.26675 9.93333L11.0668 8.6L10.4668 7.4L8.66675 8.26667V4.66667H7.33342V9.33333L8.26675 9.93333Z"
|
|
6
9
|
fill="currentColor"
|
|
7
|
-
d="M1.333 8c0 3.442 2.644 6.296 6 6.633v-1.341C4.712 12.96 2.667 10.708 2.667 8c0-2.933 2.4-5.333 5.333-5.333 2.933 0 5.333 2.4 5.333 5.333 0 2.227-1.383 4.147-3.333 4.942v-1.609H8.667v4h4V14h-1.77c2.226-1.083 3.77-3.37 3.77-6 0-3.667-3-6.667-6.667-6.667S1.333 4.333 1.333 8Z"
|
|
8
10
|
/>
|
|
9
|
-
<path fill="currentColor" d="m11.067 8.6-2.8 1.333-.934-.6V4.667h1.334v3.6l1.8-.867.6 1.2Z" />
|
|
10
11
|
</Icon>
|
|
11
12
|
));
|
|
12
13
|
|
|
@@ -3,10 +3,11 @@ import { Icon, IconProps, forwardRef } from '@chakra-ui/react';
|
|
|
3
3
|
const History = forwardRef<IconProps, 'svg'>((props, ref) => (
|
|
4
4
|
<Icon ref={ref} viewBox="0 0 24 24" {...props}>
|
|
5
5
|
<path
|
|
6
|
-
|
|
6
|
+
fillRule="evenodd"
|
|
7
|
+
clipRule="evenodd"
|
|
8
|
+
d="M2.04999 13C2.55581 18.0351 6.83737 22 12 22C17.5 22 22 17.5 22 12C22 6.5 17.5 2 12 2C8.05498 2 4.62445 4.31518 3 7.65394L3 5L1 5V11H7V9L4.58701 9C5.77995 6.07513 8.6594 4 12 4C16.4 4 20 7.6 20 12C20 16.4 16.4 20 12 20C7.93849 20 4.55863 16.9326 4.06264 13H2.04999ZM12.4001 14.9L16.6001 12.9L15.7001 11.1L13.0001 12.4V7H11.0001V14L12.4001 14.9Z"
|
|
7
9
|
fill="currentColor"
|
|
8
10
|
/>
|
|
9
|
-
<path d="m16.6 12.9-4.2 2L11 14V7h2v5.4l2.7-1.3.9 1.8Z" fill="currentColor" />
|
|
10
11
|
</Icon>
|
|
11
12
|
));
|
|
12
13
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
2
|
import { ComponentStory, ComponentMeta } from '@storybook/react';
|
|
3
|
+
import { useForm } from 'react-hook-form';
|
|
3
4
|
import { sortObjectByKey } from '../../utils/storyUtils';
|
|
4
5
|
import Select from './Select';
|
|
5
6
|
|
|
@@ -54,6 +55,22 @@ export const Controlled = () => {
|
|
|
54
55
|
);
|
|
55
56
|
};
|
|
56
57
|
|
|
58
|
+
export const ControlledWithReactHookForm = () => {
|
|
59
|
+
const form = useForm({
|
|
60
|
+
defaultValues: {
|
|
61
|
+
field: undefined,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const props = form.register('field');
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<Select w="300px" placeholder="Test holder" {...props} isRequired>
|
|
69
|
+
{children}
|
|
70
|
+
</Select>
|
|
71
|
+
);
|
|
72
|
+
};
|
|
73
|
+
|
|
57
74
|
export const WithLoading = () => (
|
|
58
75
|
<>
|
|
59
76
|
<Select w="300px" isDisabled placeholder="Test holder">
|
|
@@ -0,0 +1,96 @@
|
|
|
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 Select from './Select';
|
|
5
|
+
|
|
6
|
+
const WithReactHookForm = ({ placeholder }: { placeholder?: string }) => {
|
|
7
|
+
const form = useForm({ defaultValues: { rating: undefined } });
|
|
8
|
+
const props = form.register('rating');
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<Select placeholder={placeholder} {...props}>
|
|
12
|
+
<option value="bad">Bad</option>
|
|
13
|
+
<option value="good">Good</option>
|
|
14
|
+
</Select>
|
|
15
|
+
);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const placeholder = 'What was your impression?';
|
|
19
|
+
|
|
20
|
+
describe('Select', () => {
|
|
21
|
+
it('renders placeholder option', async () => {
|
|
22
|
+
render(
|
|
23
|
+
<Select placeholder={placeholder}>
|
|
24
|
+
<option value="bad">Bad</option>
|
|
25
|
+
<option value="good">Good</option>
|
|
26
|
+
</Select>,
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const placeholderOption = screen.queryByRole('option', { name: placeholder });
|
|
30
|
+
expect(placeholderOption).toBeInTheDocument();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('renders placeholder option as disabled', async () => {
|
|
34
|
+
render(
|
|
35
|
+
<Select placeholder={placeholder}>
|
|
36
|
+
<option value="bad">Bad</option>
|
|
37
|
+
<option value="good">Good</option>
|
|
38
|
+
</Select>,
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const placeholderOption = screen.queryByRole('option', { name: placeholder });
|
|
42
|
+
expect(placeholderOption).toBeDisabled();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('placeholder option is selected if no value is set', async () => {
|
|
46
|
+
render(
|
|
47
|
+
<Select placeholder={placeholder}>
|
|
48
|
+
<option value="bad">Bad</option>
|
|
49
|
+
<option value="good">Good</option>
|
|
50
|
+
</Select>,
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const select = await screen.findByRole<HTMLInputElement>('combobox');
|
|
54
|
+
expect(select).toHaveValue('');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('updates selected option without placeholder', async () => {
|
|
58
|
+
render(<WithReactHookForm />);
|
|
59
|
+
|
|
60
|
+
const select = await screen.findByRole<HTMLInputElement>('combobox');
|
|
61
|
+
await userEvent.selectOptions(select, 'good');
|
|
62
|
+
expect(select).toHaveValue('good');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('updates selected option with placeholder', async () => {
|
|
66
|
+
render(<WithReactHookForm placeholder="What was your impression?" />);
|
|
67
|
+
|
|
68
|
+
const select = await screen.findByRole<HTMLInputElement>('combobox');
|
|
69
|
+
await userEvent.selectOptions(select, 'good');
|
|
70
|
+
expect(select).toHaveValue('good');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('handles defaultValue correctly without placeholder', async () => {
|
|
74
|
+
render(
|
|
75
|
+
<Select defaultValue="good">
|
|
76
|
+
<option value="bad">Bad</option>
|
|
77
|
+
<option value="good">Good</option>
|
|
78
|
+
</Select>,
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const select = await screen.findByRole<HTMLInputElement>('combobox');
|
|
82
|
+
expect(select).toHaveValue('good');
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('handles defaultValue correctly with placeholder', async () => {
|
|
86
|
+
render(
|
|
87
|
+
<Select placeholder="What was your impression?" defaultValue="good">
|
|
88
|
+
<option value="bad">Bad</option>
|
|
89
|
+
<option value="good">Good</option>
|
|
90
|
+
</Select>,
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
const select = await screen.findByRole<HTMLInputElement>('combobox');
|
|
94
|
+
expect(select).toHaveValue('good');
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -41,6 +41,7 @@ const Select = forwardRef<SelectProps, 'div'>((props, ref) => {
|
|
|
41
41
|
placeholder,
|
|
42
42
|
size,
|
|
43
43
|
value,
|
|
44
|
+
defaultValue,
|
|
44
45
|
...rest
|
|
45
46
|
} = props;
|
|
46
47
|
const iconSize = size === 'medium' ? '24' : '16';
|
|
@@ -48,7 +49,6 @@ const Select = forwardRef<SelectProps, 'div'>((props, ref) => {
|
|
|
48
49
|
isDisabled: isDisabled || isLoading,
|
|
49
50
|
isInvalid: isInvalid || !!errorText,
|
|
50
51
|
...rest,
|
|
51
|
-
ref,
|
|
52
52
|
};
|
|
53
53
|
const selectProperties: ChakraSelectProps = {
|
|
54
54
|
icon: isLoading ? (
|
|
@@ -61,21 +61,23 @@ const Select = forwardRef<SelectProps, 'div'>((props, ref) => {
|
|
|
61
61
|
onChange,
|
|
62
62
|
size,
|
|
63
63
|
value,
|
|
64
|
+
defaultValue,
|
|
64
65
|
variant: 'select',
|
|
65
66
|
};
|
|
66
67
|
if (placeholder) {
|
|
67
|
-
if ('value' in
|
|
68
|
-
selectProperties.value = selectProperties.value
|
|
68
|
+
if ('value' in props) {
|
|
69
|
+
selectProperties.value = selectProperties.value ?? '';
|
|
69
70
|
} else {
|
|
70
|
-
selectProperties.defaultValue = '';
|
|
71
|
+
selectProperties.defaultValue = props.defaultValue ?? '';
|
|
71
72
|
}
|
|
72
73
|
}
|
|
74
|
+
|
|
73
75
|
return (
|
|
74
76
|
<FormControl {...formControlProps}>
|
|
75
77
|
{label && <FormLabel>{label}</FormLabel>}
|
|
76
78
|
<ChakraSelect data-testid={dataTestid} ref={ref} {...selectProperties}>
|
|
77
79
|
{placeholder && (
|
|
78
|
-
<option
|
|
80
|
+
<option disabled value="">
|
|
79
81
|
{placeholder}
|
|
80
82
|
</option>
|
|
81
83
|
)}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Text as ChakraText, TextProps as ChakraTextProps, forwardRef } from '@chakra-ui/react';
|
|
1
|
+
import { Text as ChakraText, TextProps as ChakraTextProps, forwardRef, ResponsiveValue } from '@chakra-ui/react';
|
|
2
2
|
import { TextSizes } from '../../Foundations/Typography/Typography';
|
|
3
3
|
|
|
4
4
|
type TextTags =
|
|
@@ -37,21 +37,20 @@ type TextTags =
|
|
|
37
37
|
| 'var';
|
|
38
38
|
|
|
39
39
|
export interface TextProps extends ChakraTextProps {
|
|
40
|
-
align?: 'center' | 'justify' | 'left' | 'right'
|
|
40
|
+
align?: ResponsiveValue<'center' | 'justify' | 'left' | 'right'>;
|
|
41
41
|
/**
|
|
42
42
|
* Any valid HTML text tag
|
|
43
43
|
*/
|
|
44
44
|
as?: TextTags;
|
|
45
|
-
className?: string;
|
|
46
45
|
/**
|
|
47
46
|
* Font weight
|
|
48
47
|
*/
|
|
49
|
-
fontWeight?: 'bold' | 'normal'
|
|
48
|
+
fontWeight?: ResponsiveValue<'bold' | 'normal'>;
|
|
50
49
|
/**
|
|
51
50
|
* Size config (https://www.figma.com/file/grik9mTaJ5DfhydhWhXdP5/Bitkit-Foundations?node-id=211%3A12)
|
|
52
51
|
*/
|
|
53
|
-
size?: TextSizes
|
|
54
|
-
textTransform?: 'capitalize' | 'lowercase' | 'none' | 'uppercase'
|
|
52
|
+
size?: ResponsiveValue<TextSizes>;
|
|
53
|
+
textTransform?: ResponsiveValue<'capitalize' | 'lowercase' | 'none' | 'uppercase'>;
|
|
55
54
|
hasEllipsis?: boolean;
|
|
56
55
|
}
|
|
57
56
|
|