@bitrise/bitkit 10.25.4 → 10.27.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 +1 -1
- package/src/Components/Breadcrumb/Breadcrumb.stories.tsx +39 -20
- package/src/Components/Breadcrumb/Breadcrumb.theme.ts +11 -3
- package/src/Components/Dropdown/Dropdown.context.tsx +1 -1
- package/src/Components/Dropdown/Dropdown.test.tsx +42 -0
- package/src/Components/Dropdown/DropdownOption.tsx +9 -4
- package/src/tsconfig.tsbuildinfo +1 -1
package/package.json
CHANGED
|
@@ -1,30 +1,49 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ComponentMeta } from '@storybook/react';
|
|
2
2
|
import Breadcrumb from './Breadcrumb';
|
|
3
3
|
import BreadcrumbLink from './BreadcrumbLink';
|
|
4
4
|
|
|
5
5
|
export default {
|
|
6
|
-
title: 'Components/Breadcrumb',
|
|
7
6
|
component: Breadcrumb,
|
|
8
7
|
subcomponents: { BreadcrumbLink },
|
|
8
|
+
args: {
|
|
9
|
+
hasSeparatorAfterLast: true,
|
|
10
|
+
hasSeparatorBeforeFirst: false,
|
|
11
|
+
},
|
|
9
12
|
} as ComponentMeta<typeof Breadcrumb>;
|
|
10
13
|
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
export const DefaultVersion = {
|
|
15
|
+
args: {
|
|
16
|
+
children: [
|
|
17
|
+
<BreadcrumbLink
|
|
18
|
+
avatarUrl="https://bitrise-public-content-production.s3.amazonaws.com/org-icons/default_avatar-02.png"
|
|
19
|
+
href="#"
|
|
20
|
+
>
|
|
21
|
+
Bitrise #Core
|
|
22
|
+
</BreadcrumbLink>,
|
|
23
|
+
<BreadcrumbLink avatarName="Bitkit" href="#">
|
|
24
|
+
bitkit
|
|
25
|
+
</BreadcrumbLink>,
|
|
26
|
+
<BreadcrumbLink isCurrentPage>settings</BreadcrumbLink>,
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
};
|
|
25
30
|
|
|
26
|
-
export const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
export const WithLongText = {
|
|
32
|
+
args: {
|
|
33
|
+
children: [
|
|
34
|
+
<BreadcrumbLink
|
|
35
|
+
avatarUrl="https://bitrise-public-content-production.s3.amazonaws.com/org-icons/default_avatar-02.png"
|
|
36
|
+
href="#"
|
|
37
|
+
>
|
|
38
|
+
Bitrise #Core
|
|
39
|
+
</BreadcrumbLink>,
|
|
40
|
+
<BreadcrumbLink avatarName="Bitkit" href="#">
|
|
41
|
+
Bitkit
|
|
42
|
+
</BreadcrumbLink>,
|
|
43
|
+
<BreadcrumbLink href="#">
|
|
44
|
+
There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in
|
|
45
|
+
some form, by injected humour, or randomised words which don't look even slightly believable.
|
|
46
|
+
</BreadcrumbLink>,
|
|
47
|
+
],
|
|
48
|
+
},
|
|
30
49
|
};
|
|
@@ -8,13 +8,21 @@ const BreadcrumbTheme: SystemStyleObject = {
|
|
|
8
8
|
alignItems: 'center',
|
|
9
9
|
},
|
|
10
10
|
},
|
|
11
|
+
item: {
|
|
12
|
+
_last: {
|
|
13
|
+
minWidth: 0,
|
|
14
|
+
'.chakra-breadcrumb__link': {
|
|
15
|
+
maxWidth: '100%',
|
|
16
|
+
overflow: 'hidden',
|
|
17
|
+
textOverflow: 'ellipsis',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
11
21
|
link: {
|
|
12
22
|
display: 'flex',
|
|
13
23
|
alignItems: 'center',
|
|
14
24
|
gap: '8',
|
|
15
|
-
'
|
|
16
|
-
color: 'red',
|
|
17
|
-
},
|
|
25
|
+
whiteSpace: 'nowrap',
|
|
18
26
|
},
|
|
19
27
|
separator: {
|
|
20
28
|
display: 'flex',
|
|
@@ -16,7 +16,7 @@ type DropdownContext<T> = {
|
|
|
16
16
|
searchOnSubmit: () => void;
|
|
17
17
|
filter?: string;
|
|
18
18
|
activeIndex?: number | null;
|
|
19
|
-
getItemProps: (
|
|
19
|
+
getItemProps: (userProps?: React.HTMLProps<HTMLElement> | undefined) => Record<string, unknown>;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
const [DropdownContextProvider, useDropdownContext] = createContext<DropdownContext<unknown>>();
|
|
@@ -581,4 +581,46 @@ describe('Dropdown', () => {
|
|
|
581
581
|
expect(button).toHaveTextContent('Custom label');
|
|
582
582
|
});
|
|
583
583
|
});
|
|
584
|
+
|
|
585
|
+
describe('option onClick support', () => {
|
|
586
|
+
it('calls onClick handler on option', async () => {
|
|
587
|
+
const onChangeHandler = jest.fn();
|
|
588
|
+
const onClickHandler = jest.fn();
|
|
589
|
+
|
|
590
|
+
render(
|
|
591
|
+
<Dropdown onChange={onChangeHandler}>
|
|
592
|
+
<DropdownOption value="Test option 1">Test option 1</DropdownOption>
|
|
593
|
+
<DropdownOption value="Test option 2" onClick={onClickHandler}>
|
|
594
|
+
Test option 2
|
|
595
|
+
</DropdownOption>
|
|
596
|
+
</Dropdown>,
|
|
597
|
+
);
|
|
598
|
+
|
|
599
|
+
const button = await screen.findByRole('combobox');
|
|
600
|
+
await userEvent.click(button);
|
|
601
|
+
const option2 = await screen.findByRole('option', { name: 'Test option 2' });
|
|
602
|
+
await userEvent.click(option2);
|
|
603
|
+
expect(onClickHandler).toHaveBeenCalled();
|
|
604
|
+
expect(onChangeHandler).toHaveBeenCalled();
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
it("doesn't call onChange handler if option's onClick handler prevented it", async () => {
|
|
608
|
+
const onChangeHandler = jest.fn();
|
|
609
|
+
|
|
610
|
+
render(
|
|
611
|
+
<Dropdown onChange={onChangeHandler}>
|
|
612
|
+
<DropdownOption value="Test option 1">Test option 1</DropdownOption>
|
|
613
|
+
<DropdownOption value="Test option 2" onClick={(event) => event.preventDefault()}>
|
|
614
|
+
Test option 2
|
|
615
|
+
</DropdownOption>
|
|
616
|
+
</Dropdown>,
|
|
617
|
+
);
|
|
618
|
+
|
|
619
|
+
const button = await screen.findByRole('combobox');
|
|
620
|
+
await userEvent.click(button);
|
|
621
|
+
const option2 = await screen.findByRole('option', { name: 'Test option 2' });
|
|
622
|
+
await userEvent.click(option2);
|
|
623
|
+
expect(onChangeHandler).not.toHaveBeenCalled();
|
|
624
|
+
});
|
|
625
|
+
});
|
|
584
626
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ReactNode, useId } from 'react';
|
|
1
|
+
import { MouseEventHandler, ReactNode, useId } from 'react';
|
|
2
2
|
import { chakra } from '@chakra-ui/react';
|
|
3
3
|
import { cx } from '@chakra-ui/utils';
|
|
4
4
|
import Text from '../Text/Text';
|
|
@@ -9,8 +9,9 @@ export type DropdownOptionProps<T> = {
|
|
|
9
9
|
value?: T | null;
|
|
10
10
|
children?: ReactNode;
|
|
11
11
|
'aria-label'?: string;
|
|
12
|
+
onClick?: MouseEventHandler<HTMLElement>;
|
|
12
13
|
};
|
|
13
|
-
const DropdownOption = <T = string,>({ value = null, children, ...rest }: DropdownOptionProps<T>) => {
|
|
14
|
+
const DropdownOption = <T = string,>({ value = null, children, onClick, ...rest }: DropdownOptionProps<T>) => {
|
|
14
15
|
const { item } = useDropdownStyles();
|
|
15
16
|
const ctx = useDropdownContext<T | null>();
|
|
16
17
|
const { index } = rest as { index?: number };
|
|
@@ -30,8 +31,12 @@ const DropdownOption = <T = string,>({ value = null, children, ...rest }: Dropdo
|
|
|
30
31
|
)}
|
|
31
32
|
__css={item}
|
|
32
33
|
{...ctx.getItemProps({
|
|
33
|
-
onClick() {
|
|
34
|
-
|
|
34
|
+
onClick(event) {
|
|
35
|
+
onClick?.(event);
|
|
36
|
+
|
|
37
|
+
if (!event.defaultPrevented) {
|
|
38
|
+
ctx.onOptionSelected({ value, index, label: children });
|
|
39
|
+
}
|
|
35
40
|
},
|
|
36
41
|
})}
|
|
37
42
|
>
|