@bitrise/bitkit 10.36.2 → 11.0.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.
Files changed (64) hide show
  1. package/package.json +17 -38
  2. package/src/Components/Menu/MenuItem.tsx +1 -1
  3. package/tsconfig.json +0 -5
  4. package/src/Components/Accordion/Accordion.stories.tsx +0 -63
  5. package/src/Components/Accordion/Accordion.test.tsx +0 -34
  6. package/src/Components/AspectRatio/AspectRatio.stories.tsx +0 -24
  7. package/src/Components/Avatar/Avatar.stories.tsx +0 -15
  8. package/src/Components/Badge/Badge.stories.tsx +0 -13
  9. package/src/Components/Box/Box.stories.tsx +0 -20
  10. package/src/Components/Breadcrumb/Breadcrumb.stories.tsx +0 -49
  11. package/src/Components/Button/Button.stories.tsx +0 -25
  12. package/src/Components/ButtonGroup/ButtonGroup.stories.tsx +0 -21
  13. package/src/Components/Card/Card.stories.tsx +0 -44
  14. package/src/Components/ColorButton/ColorButton.stories.tsx +0 -30
  15. package/src/Components/DatePicker/DatePicker.stories.tsx +0 -16
  16. package/src/Components/DatePicker/DatePicker.test.tsx +0 -94
  17. package/src/Components/Dialog/Dialog.stories.tsx +0 -82
  18. package/src/Components/Divider/Divider.stories.tsx +0 -18
  19. package/src/Components/Dot/Dot.stories.tsx +0 -15
  20. package/src/Components/Dropdown/Dropdown.stories.tsx +0 -154
  21. package/src/Components/Dropdown/Dropdown.test.tsx +0 -626
  22. package/src/Components/EmptyState/EmptyState.stories.tsx +0 -18
  23. package/src/Components/Fade/Fade.stories.tsx +0 -5
  24. package/src/Components/Form/Checkbox/Checkbox.stories.tsx +0 -43
  25. package/src/Components/Form/Input/Input.stories.tsx +0 -71
  26. package/src/Components/Form/Radio/Radio.stories.tsx +0 -35
  27. package/src/Components/Form/Textarea/Textarea.stories.tsx +0 -20
  28. package/src/Components/Form/Textarea/Textarea.test.tsx +0 -35
  29. package/src/Components/Icon/Icon.stories.tsx +0 -10
  30. package/src/Components/IconButton/IconButton.stories.tsx +0 -27
  31. package/src/Components/Icons/index.stories.tsx +0 -60
  32. package/src/Components/Image/Image.stories.tsx +0 -15
  33. package/src/Components/LightBox/LightBox.stories.tsx +0 -39
  34. package/src/Components/Link/Link.stories.tsx +0 -28
  35. package/src/Components/List/List.stories.tsx +0 -24
  36. package/src/Components/Menu/Menu.stories.tsx +0 -90
  37. package/src/Components/Notification/Notification.stories.tsx +0 -84
  38. package/src/Components/OverflowMenu/OverflowMenu.stories.tsx +0 -30
  39. package/src/Components/Popover/Popover.stories.tsx +0 -19
  40. package/src/Components/ProgressBar/ProgressBar.stories.tsx +0 -11
  41. package/src/Components/ProgressBitbot/ProgressBitbot.stories.tsx +0 -12
  42. package/src/Components/ProgressSpinner/ProgressSpinner.stories.tsx +0 -12
  43. package/src/Components/Ribbon/Ribbon.stories.tsx +0 -35
  44. package/src/Components/Select/Select.stories.tsx +0 -100
  45. package/src/Components/Select/Select.test.tsx +0 -96
  46. package/src/Components/Skeleton/Skeleton.stories.tsx +0 -18
  47. package/src/Components/Table/Table.stories.tsx +0 -216
  48. package/src/Components/Tabs/Tabs.stories.tsx +0 -65
  49. package/src/Components/Tabs/Tabs.test.tsx +0 -36
  50. package/src/Components/Text/Text.stories.tsx +0 -22
  51. package/src/Components/Toast/Toast.stories.tsx +0 -30
  52. package/src/Components/Toggle/Toggle.stories.tsx +0 -19
  53. package/src/Foundations/Colors/Colors.stories.mdx +0 -9
  54. package/src/Foundations/Radii/Radii.examples.tsx +0 -25
  55. package/src/Foundations/Radii/Radii.stories.mdx +0 -6
  56. package/src/Foundations/Responsive/Responsive.examples.tsx +0 -95
  57. package/src/Foundations/Responsive/Responsive.stories.mdx +0 -6
  58. package/src/Foundations/Shadows/Shadows.examples.tsx +0 -24
  59. package/src/Foundations/Shadows/Shadows.stories.mdx +0 -6
  60. package/src/Foundations/Sizes/Sizes.examples.tsx +0 -25
  61. package/src/Foundations/Sizes/Sizes.stories.mdx +0 -6
  62. package/src/Foundations/Typography/Typography.examples.tsx +0 -63
  63. package/src/Foundations/Typography/Typography.stories.mdx +0 -8
  64. package/src/tsconfig.tsbuildinfo +0 -1
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.36.2",
4
+ "version": "11.0.0",
5
5
  "repository": "git@github.com:bitrise-io/bitkit.git",
6
6
  "main": "src/index.ts",
7
7
  "license": "UNLICENSED",
@@ -27,14 +27,11 @@
27
27
  "@emotion/react": "^11.9.3",
28
28
  "@emotion/styled": "^11.9.3",
29
29
  "@floating-ui/react-dom-interactions": "^0.8.1",
30
- "@popperjs/core": "^2.11.5",
31
- "classnames": "^2.3.1",
32
30
  "framer-motion": "^6.5.1",
33
31
  "luxon": "^3.0.3",
34
32
  "react": "^18.2.0",
35
33
  "react-dom": "^18.2.0",
36
- "react-focus-lock": "^2.9.1",
37
- "react-popper": "^2.3.0"
34
+ "react-focus-lock": "^2.9.1"
38
35
  },
39
36
  "peerDependencies": {
40
37
  "react": "^18.2.0",
@@ -42,46 +39,34 @@
42
39
  },
43
40
  "devDependencies": {
44
41
  "@babel/core": "^7.18.9",
45
- "@babel/parser": "^7.18.9",
46
42
  "@bitrise/eslint-plugin": "^2.2.0",
47
- "@chakra-ui/cli": "^2.1.2",
48
43
  "@commitlint/cli": "^16.3.0",
49
44
  "@commitlint/config-conventional": "^16.2.4",
50
45
  "@google-cloud/storage": "^5.20.5",
51
46
  "@semantic-release/changelog": "^6.0.1",
52
47
  "@semantic-release/commit-analyzer": "^9.0.2",
53
48
  "@semantic-release/git": "^10.0.1",
54
- "@storybook/addon-actions": "^6.5.9",
55
- "@storybook/addon-essentials": "^6.5.9",
56
- "@storybook/addon-interactions": "^6.5.9",
57
- "@storybook/addon-links": "^6.5.9",
58
- "@storybook/addons": "^6.5.9",
59
- "@storybook/builder-webpack5": "^6.5.9",
60
- "@storybook/manager-webpack5": "^6.5.9",
61
- "@storybook/react": "^6.5.9",
49
+ "@storybook/addon-actions": "^6.5.12",
50
+ "@storybook/addon-essentials": "^6.5.12",
51
+ "@storybook/addon-interactions": "^6.5.12",
52
+ "@storybook/addon-links": "^6.5.12",
53
+ "@storybook/addons": "^6.5.12",
54
+ "@storybook/builder-webpack5": "^6.5.12",
55
+ "@storybook/manager-webpack5": "^6.5.12",
56
+ "@storybook/react": "^6.5.12",
62
57
  "@storybook/testing-library": "^0.0.13",
63
- "@storybook/theming": "^6.5.9",
64
- "@svgr/core": "^6.3.0",
58
+ "@storybook/theming": "^6.5.12",
65
59
  "@testing-library/dom": "^8.16.0",
66
60
  "@testing-library/jest-dom": "^5.16.4",
67
61
  "@testing-library/react": "^13.3.0",
68
62
  "@testing-library/user-event": "^14.4.3",
69
- "@types/cheerio": "^0.22.31",
70
- "@types/enzyme": "^3.10.12",
71
63
  "@types/jest": "^29.0.3",
72
- "@types/luxon": "^2.4.0",
73
- "@types/react": "18.0.18",
64
+ "@types/luxon": "^3.0.1",
65
+ "@types/react": "^18.0.21",
74
66
  "@types/react-dom": "^18.0.6",
75
- "@types/vfile-message": "^2.0.0",
76
67
  "@typescript-eslint/eslint-plugin": "^5.30.7",
77
68
  "@typescript-eslint/parser": "^5.30.7",
78
- "@wojtekmaj/enzyme-adapter-react-17": "^0.6.7",
79
69
  "axios": "^0.27.2",
80
- "babel-eslint": "^10.0.1",
81
- "babel-loader": "^8.2.5",
82
- "babel-plugin-polyfill-corejs2": "^0.3.1",
83
- "enzyme": "^3.11.0",
84
- "enzyme-to-json": "^3.6.2",
85
70
  "eslint": "^8.20.0",
86
71
  "eslint-plugin-import": "^2.26.0",
87
72
  "eslint-plugin-jest": "^26.6.0",
@@ -93,30 +78,24 @@
93
78
  "eslint-plugin-testing-library": "^5.5.1",
94
79
  "glob": "^8.0.3",
95
80
  "husky": "^7.0.4",
96
- "identity-obj-proxy": "^3.0.0",
97
81
  "jest": "^29.0.3",
98
82
  "jest-environment-jsdom": "^28.1.3",
99
- "jsdom": "^19.0.0",
83
+ "jsdom": "^20.0.0",
100
84
  "prettier": "^2.7.1",
101
85
  "react-hook-form": "^7.33.1",
102
- "recast": "^0.21.1",
103
86
  "semantic-release": "^19.0.3",
104
87
  "ts-jest": "^29.0.1",
105
- "ts-node": "^10.9.1",
106
- "tsconfig-paths-webpack-plugin": "^3.5.2",
107
- "typescript": "^4.8.2",
108
- "webpack": "^5.73.0"
88
+ "typescript": "^4.8.2"
109
89
  },
110
90
  "files": [
111
91
  "src",
112
92
  "tsconfig.json"
113
93
  ],
94
+ "sideEffects": false,
114
95
  "publishConfig": {
115
96
  "access": "public"
116
97
  },
117
98
  "resolutions": {
118
- "**/ast-types": "npm:@gkz/ast-types",
119
- "ts-node": "^10.9.1",
120
- "@types/react": "17.0.40"
99
+ "**/ast-types": "npm:@gkz/ast-types"
121
100
  }
122
101
  }
@@ -1,5 +1,5 @@
1
1
  import { MenuItem as ChakraMenuItem, MenuItemProps as ChakraMenuItemProps, forwardRef } from '@chakra-ui/react';
2
- import { Icon, TypeIconName } from '@bitrise/bitkit';
2
+ import Icon, { TypeIconName } from '../Icon/Icon';
3
3
 
4
4
  const dangerStyle = {
5
5
  color: 'red.50',
package/tsconfig.json CHANGED
@@ -13,11 +13,6 @@
13
13
  "jsx": "react-jsx",
14
14
  "module": "commonjs",
15
15
  "moduleResolution": "node",
16
- "paths": {
17
- "*": ["@types/*"],
18
- "@bitrise/bitkit": ["src"],
19
- "@/*": ["src/*"]
20
- },
21
16
  "resolveJsonModule": true,
22
17
  // https://github.com/chakra-ui/chakra-ui/issues/2955
23
18
  "skipLibCheck": true,
@@ -1,63 +0,0 @@
1
- import { MouseEvent } from 'react';
2
- import { ComponentStory, ComponentMeta } from '@storybook/react';
3
- import Box from '../Box/Box';
4
- import Button from '../Button/Button';
5
- import Icon from '../Icon/Icon';
6
- import Text from '../Text/Text';
7
- import Accordion from './Accordion';
8
- import AccordionItem from './AccordionItem';
9
-
10
- export default {
11
- title: 'Components/Accordion',
12
- component: Accordion,
13
- args: {
14
- colorScheme: 'white',
15
- },
16
- argTypes: {
17
- onChange: {
18
- action: 'onChange event',
19
- },
20
- },
21
- subcomponents: { AccordionItem },
22
- } as ComponentMeta<typeof Accordion>;
23
-
24
- const onButtonClick = (e: MouseEvent<HTMLButtonElement>) => {
25
- e.stopPropagation();
26
- };
27
-
28
- const ButtonContentElement = ({ title }: { title: string }) => {
29
- return (
30
- <Box display="flex" alignItems="center" flexGrow={1}>
31
- <Icon name="Doc" />
32
- <Text as="p" align="left" size="3" margin="0 auto 0 1rem">
33
- {title}
34
- <br />
35
- <Text as="span" size="2" textColor="neutral.40">
36
- Generated by clone-build workflow
37
- </Text>
38
- </Text>
39
- <Button as="a" href="#" size="small" onClick={onButtonClick} leftIconName="Download">
40
- Download
41
- </Button>
42
- </Box>
43
- );
44
- };
45
-
46
- export const DefaultVariant: ComponentStory<typeof Accordion> = (props) => (
47
- <Accordion {...props} marginLeft="32">
48
- <AccordionItem buttonContent="The buttonContent is a string" fontSize="2" id="first">
49
- Content - you can use any style prop on AccordionItem
50
- </AccordionItem>
51
- <AccordionItem
52
- buttonContent={<ButtonContentElement title="The buttonContent is a React element" />}
53
- fontSize="2"
54
- id="second"
55
- >
56
- Content - you can use any style prop on AccordionItem
57
- </AccordionItem>
58
- <AccordionItem buttonContent={<ButtonContentElement title="Without children" />} id="third" />
59
- <AccordionItem buttonContent="Fourth, enabled element" fontSize="2" id="fourth">
60
- Fourth, enabled element
61
- </AccordionItem>
62
- </Accordion>
63
- );
@@ -1,34 +0,0 @@
1
- import { render, screen } from '@testing-library/react';
2
- import userEvent from '@testing-library/user-event';
3
- import Accordion from './Accordion';
4
- import AccordionItem from './AccordionItem';
5
-
6
- describe('Accordion', () => {
7
- it('calls the onChange handler with the proper id if Accordion has a conditionally not rendered item', async () => {
8
- const thirdId = 'third-item';
9
- const thirdTitle = 'Third item';
10
-
11
- const handleChange = jest.fn();
12
-
13
- render(
14
- <Accordion onChange={handleChange}>
15
- <AccordionItem id="first" buttonContent="First item">
16
- First content
17
- </AccordionItem>
18
- {false && (
19
- <AccordionItem id="second" buttonContent="Second item">
20
- Second content
21
- </AccordionItem>
22
- )}
23
- <AccordionItem id={thirdId} buttonContent={thirdTitle}>
24
- Third content
25
- </AccordionItem>
26
- </Accordion>,
27
- );
28
-
29
- const thirdTab = await screen.findByText(thirdTitle);
30
- await userEvent.click(thirdTab);
31
-
32
- expect(handleChange).toHaveBeenCalledWith(['third-item'], [1]);
33
- });
34
- });
@@ -1,24 +0,0 @@
1
- import { ComponentStory, ComponentMeta } from '@storybook/react';
2
- import Image from '../Image/Image';
3
- import AspectRatio from './AspectRatio';
4
-
5
- export default {
6
- title: 'Components/AspectRatio',
7
- component: AspectRatio,
8
- } as ComponentMeta<typeof AspectRatio>;
9
-
10
- const Template: ComponentStory<typeof AspectRatio> = (props) => <AspectRatio {...props} />;
11
-
12
- export const WithImage = Template.bind({});
13
- WithImage.args = {
14
- children: <Image alt="Bitrise office" src="bitrise_office.jpg" />,
15
- maxWidth: 800,
16
- ratio: 1920 / 1280,
17
- };
18
-
19
- export const WithVideo = Template.bind({});
20
- WithVideo.args = {
21
- children: <iframe title="Intro to Bitrise" src="https://www.youtube.com/embed/JrCn9xWQ7IM" allowFullScreen />,
22
- maxWidth: 800,
23
- ratio: 16 / 9,
24
- };
@@ -1,15 +0,0 @@
1
- import { ComponentStory, ComponentMeta } from '@storybook/react';
2
- import Avatar from './Avatar';
3
-
4
- export default {
5
- title: 'Components/Avatar',
6
- component: Avatar,
7
- } as ComponentMeta<typeof Avatar>;
8
-
9
- export const WithProps: ComponentStory<typeof Avatar> = ({ contentProps, ...props }) => <Avatar {...props} />;
10
-
11
- WithProps.args = {
12
- ...Avatar.defaultProps,
13
- name: 'Bitrise website',
14
- src: 'https://bitrise-public-content-production.s3.amazonaws.com/org-icons/default_avatar-02.png',
15
- };
@@ -1,13 +0,0 @@
1
- import { ComponentStory, ComponentMeta } from '@storybook/react';
2
- import Badge from './Badge';
3
-
4
- export default {
5
- title: 'Components/Badge',
6
- component: Badge,
7
- } as ComponentMeta<typeof Badge>;
8
-
9
- export const WithProps: ComponentStory<typeof Badge> = (props) => <Badge {...props} />;
10
- WithProps.args = {
11
- children: 'Coming soon',
12
- ...Badge.defaultProps,
13
- };
@@ -1,20 +0,0 @@
1
- import { ComponentStory, ComponentMeta } from '@storybook/react';
2
- import Box from './Box';
3
-
4
- export default {
5
- title: 'Components/Box',
6
- component: Box,
7
- } as ComponentMeta<typeof Box>;
8
-
9
- const Template: ComponentStory<typeof Box> = (props) => <Box {...props} />;
10
-
11
- export const WithProps = Template.bind({});
12
- WithProps.args = {
13
- as: 'div',
14
- className: '',
15
- children: 'This is the Box',
16
- backgroundColor: 'brand.primary',
17
- color: 'neutral.95',
18
- padding: '12',
19
- width: '100%',
20
- };
@@ -1,49 +0,0 @@
1
- import { ComponentMeta } from '@storybook/react';
2
- import Breadcrumb from './Breadcrumb';
3
- import BreadcrumbLink from './BreadcrumbLink';
4
-
5
- export default {
6
- component: Breadcrumb,
7
- subcomponents: { BreadcrumbLink },
8
- args: {
9
- hasSeparatorAfterLast: true,
10
- hasSeparatorBeforeFirst: false,
11
- },
12
- } as ComponentMeta<typeof Breadcrumb>;
13
-
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
- };
30
-
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
- },
49
- };
@@ -1,25 +0,0 @@
1
- import { ComponentStory, ComponentMeta } from '@storybook/react';
2
- import { sortObjectByKey } from '../../utils/storyUtils';
3
- import Button from './Button';
4
-
5
- export default {
6
- title: 'Components/Button',
7
- component: Button,
8
- argTypes: {
9
- as: {
10
- control: 'inline-radio',
11
- options: ['a', 'button'],
12
- },
13
- },
14
- } as ComponentMeta<typeof Button>;
15
-
16
- const Template: ComponentStory<typeof Button> = (props) => <Button {...props} />;
17
-
18
- export const WithProps = Template.bind({});
19
- WithProps.args = sortObjectByKey({
20
- ...Button.defaultProps,
21
- children: 'Button',
22
- isDanger: false,
23
- isDisabled: false,
24
- isLoading: false,
25
- });
@@ -1,21 +0,0 @@
1
- import { ComponentMeta, ComponentStory } from '@storybook/react';
2
- import Button from '../Button/Button';
3
- import ButtonGroup from './ButtonGroup';
4
-
5
- export default {
6
- component: ButtonGroup,
7
- } as ComponentMeta<typeof ButtonGroup>;
8
-
9
- const Template: ComponentStory<typeof ButtonGroup> = (props) => (
10
- <ButtonGroup {...props} width="900px" flexDirection="row">
11
- <Button>Button 1</Button>
12
- <Button>Button 2</Button>
13
- <Button>Button 3</Button>
14
- </ButtonGroup>
15
- );
16
-
17
- export const WithProps = Template.bind({});
18
-
19
- WithProps.args = {
20
- isAttached: true,
21
- };
@@ -1,44 +0,0 @@
1
- import { ComponentStory, ComponentMeta } from '@storybook/react';
2
- import Divider from '../Divider/Divider';
3
- import Card from './Card';
4
- import CardContent from './CardContent';
5
-
6
- export default {
7
- title: 'Components/Card',
8
- component: Card,
9
- subcomponents: { CardContent },
10
- } as ComponentMeta<typeof Card>;
11
-
12
- export const WithProps: ComponentStory<typeof Card> = ({ contentProps, ...props }) => (
13
- <Card {...props}>
14
- <CardContent {...contentProps}>The quick brown fox jumps over the lazy dog.</CardContent>
15
- </Card>
16
- );
17
-
18
- WithProps.args = {
19
- ...Card.defaultProps,
20
- boxShadow: 'medium',
21
- className: '',
22
- withBorder: false,
23
- contentProps: {
24
- padding: '24',
25
- },
26
- };
27
-
28
- export const DividedContent: ComponentStory<typeof Card> = ({ contentProps, ...props }) => (
29
- <Card {...props}>
30
- <CardContent {...contentProps}>The quick brown fox jumps over the lazy dog.</CardContent>
31
- <Divider />
32
- <CardContent {...contentProps}>The quick brown fox jumps over the lazy dog.</CardContent>
33
- </Card>
34
- );
35
-
36
- DividedContent.args = {
37
- ...Card.defaultProps,
38
- boxShadow: 'medium',
39
- className: '',
40
- withBorder: false,
41
- contentProps: {
42
- padding: '24',
43
- },
44
- };
@@ -1,30 +0,0 @@
1
- import { ComponentStory, ComponentMeta } from '@storybook/react';
2
- import { sortObjectByKey } from '../../utils/storyUtils';
3
- import Box from '../Box/Box';
4
- import ColorButton from './ColorButton';
5
-
6
- export default {
7
- title: 'Components/ColorButton',
8
- component: ColorButton,
9
- argTypes: {
10
- as: {
11
- control: 'inline-radio',
12
- options: ['a', 'button'],
13
- },
14
- },
15
- } as ComponentMeta<typeof ColorButton>;
16
-
17
- const Template: ComponentStory<typeof ColorButton> = ({ colorScheme, ...props }) => (
18
- <Box padding={16} backgroundColor={colorScheme === 'neutral' ? 'black' : undefined}>
19
- <ColorButton colorScheme={colorScheme} {...props} />
20
- </Box>
21
- );
22
-
23
- export const WithProps = Template.bind({});
24
- WithProps.args = sortObjectByKey({
25
- ...ColorButton.defaultProps,
26
- children: 'ColorButton',
27
- colorScheme: 'blue',
28
- isDisabled: false,
29
- isLoading: false,
30
- });
@@ -1,16 +0,0 @@
1
- import { ComponentMeta } from '@storybook/react';
2
- import { DateTime } from 'luxon';
3
- import DatePicker from './DatePicker';
4
- import { DateRange } from './useDateRange';
5
-
6
- export default {
7
- component: DatePicker,
8
- args: { visible: true, children: <button type="button">ok</button> },
9
- } as ComponentMeta<typeof DatePicker>;
10
-
11
- export const Default = {};
12
- export const Selectable = {
13
- args: {
14
- selectable: new DateRange(DateTime.local(2022, 11, 20), DateTime.local(2022, 11, 30)),
15
- },
16
- };
@@ -1,94 +0,0 @@
1
- import { render, screen, waitFor, within } from '@testing-library/react';
2
- import { DateTime } from 'luxon';
3
- import userEventGlobal from '@testing-library/user-event';
4
- import Provider from '../Provider/Provider';
5
- import DatePicker, { DatePickerProps } from './DatePicker';
6
- import { DateRange } from './useDateRange';
7
-
8
- jest.mock('../../hooks/useResponsive', () => jest.fn(() => ({ isMobile: false })));
9
-
10
- jest.useFakeTimers();
11
- jest.setSystemTime(DateTime.local(2022, 1, 2).toJSDate());
12
- const userEvent = userEventGlobal.setup({ advanceTimers: (t) => jest.advanceTimersByTime(t) });
13
- const Subject = (props: Partial<DatePickerProps>) => (
14
- <Provider>
15
- <DatePicker onClose={() => {}} visible {...props}>
16
- <div />
17
- </DatePicker>
18
- </Provider>
19
- );
20
- describe('DatePicker', () => {
21
- it('works', async () => {
22
- const handler = jest.fn<void, [DateRange]>();
23
- render(<Subject onApply={handler} />);
24
- await userEvent.click(await screen.findByRole('button', { name: 'January' }));
25
- await userEvent.selectOptions(
26
- await screen.findByRole('listbox', { name: 'month' }),
27
- await screen.findByRole('option', { name: 'October' }),
28
- );
29
- const month = await screen.findByRole('listbox', { name: 'October 2022' });
30
- await userEvent.selectOptions(month, await within(month).findByRole('option', { name: '23' }));
31
- await userEvent.click(await screen.findByRole('button', { name: 'November' }));
32
- const year = await screen.findByRole('spinbutton', { name: 'year' });
33
- await userEvent.type(year, '{BackSpace}3');
34
- await userEvent.selectOptions(
35
- await screen.findByRole('listbox', { name: 'month' }),
36
- await screen.findByRole('option', { name: 'February' }),
37
- );
38
- const month2 = await screen.findByRole('listbox', { name: 'February 2023' });
39
- await userEvent.selectOptions(month2, await within(month2).findByRole('option', { name: '10' }));
40
- await userEvent.click(await screen.findByRole('button', { name: 'Apply' }));
41
- expect(handler).toHaveBeenCalledWith(expect.any(DateRange));
42
- const [{ from: begin, to: end }] = handler.mock.lastCall!;
43
- expect(begin! < end!).toBe(true);
44
- expect(begin?.toObject()).toMatchObject({ year: 2022, month: 10, day: 23 });
45
- expect(end?.toObject()).toMatchObject({ year: 2023, month: 2, day: 10 });
46
- });
47
- describe('with range pre-selected', () => {
48
- describe('when range start/end is in the same month', () => {
49
- it('shows the start month on the left and the next month on the right', async () => {
50
- render(<Subject selected={new DateRange(DateTime.local(2022, 2, 1), DateTime.local(2022, 2, 7))} />);
51
- const left = await screen.findByRole('listbox', { name: 'February 2022' });
52
- expect(left).toBeInTheDocument();
53
- const right = await screen.findByRole('listbox', { name: 'March 2022' });
54
- expect(right).toBeInTheDocument();
55
- });
56
- });
57
- describe('when range start/end is in consequitive months', () => {
58
- it('shows the start month on the left and the next month on the right', async () => {
59
- render(<Subject selected={new DateRange(DateTime.local(2022, 2, 1), DateTime.local(2022, 3, 7))} />);
60
- const left = await screen.findByRole('listbox', { name: 'February 2022' });
61
- expect(left).toBeInTheDocument();
62
- const right = await screen.findByRole('listbox', { name: 'March 2022' });
63
- expect(right).toBeInTheDocument();
64
- });
65
- });
66
- describe('when range start/end have more than 1 month between them', () => {
67
- it('shows the start month on the left and the next month on the right', async () => {
68
- render(<Subject selected={new DateRange(DateTime.local(2022, 2, 1), DateTime.local(2022, 5, 7))} />);
69
- const left = await screen.findByRole('listbox', { name: 'February 2022' });
70
- expect(left).toBeInTheDocument();
71
- const right = await screen.findByRole('listbox', { name: 'March 2022' });
72
- expect(right).toBeInTheDocument();
73
- });
74
- });
75
- });
76
- describe('month selector', () => {
77
- it('shows current month as selected', async () => {
78
- render(<Subject />);
79
- const left = await screen.findByRole('button', { name: 'January' });
80
- await userEvent.click(left);
81
- const jan = await screen.findByRole('option', { name: 'January' });
82
- const feb = await screen.findByRole('option', { name: 'February' });
83
- expect(jan).toHaveAttribute('aria-selected', 'true');
84
- expect(feb).not.toHaveAttribute('aria-selected');
85
- });
86
- it('focuses the year input when clicked', async () => {
87
- render(<Subject />);
88
- const left = await screen.findByRole('button', { name: 'January' });
89
- await userEvent.click(left);
90
- const year = await screen.findByRole('spinbutton', { name: 'year' });
91
- await waitFor(() => expect(year).toHaveFocus());
92
- });
93
- });
94
- });