@etsoo/react 1.5.79 → 1.5.80
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.
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ComboBox } from '../../src';
|
|
3
|
+
import { fireEvent, render, screen } from '@testing-library/react';
|
|
4
|
+
import '@testing-library/jest-dom/extend-expect';
|
|
5
|
+
|
|
6
|
+
it('Render ComboBox', async () => {
|
|
7
|
+
// Arrange
|
|
8
|
+
type T = { id: number; name: string };
|
|
9
|
+
const options: T[] = [
|
|
10
|
+
{ id: 1, name: 'Name 1' },
|
|
11
|
+
{ id: 2, name: 'Name 2' }
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
render(
|
|
15
|
+
<ComboBox<T>
|
|
16
|
+
name="Test"
|
|
17
|
+
options={options}
|
|
18
|
+
labelField="name"
|
|
19
|
+
label="Test"
|
|
20
|
+
/>
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
// Act, click the list
|
|
24
|
+
const clicked = fireEvent.click(screen.getByRole('button'));
|
|
25
|
+
expect(clicked).toBeTruthy();
|
|
26
|
+
|
|
27
|
+
// Get list item
|
|
28
|
+
const item = screen.getByText('Name 1');
|
|
29
|
+
expect(item.nodeName).toBe('LI');
|
|
30
|
+
});
|
|
@@ -14,7 +14,7 @@ root.append(container);
|
|
|
14
14
|
|
|
15
15
|
// The state provider
|
|
16
16
|
const Provider = NotifierMU.setup();
|
|
17
|
-
const reactRoot = createRoot(container);
|
|
17
|
+
const reactRoot = createRoot(container);
|
|
18
18
|
|
|
19
19
|
act(() => {
|
|
20
20
|
// Concorrent renderer needs act block
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SelectEx } from '../../src';
|
|
3
|
+
import { findByText, fireEvent, render, screen } from '@testing-library/react';
|
|
4
|
+
import '@testing-library/jest-dom/extend-expect';
|
|
5
|
+
|
|
6
|
+
it('Render SelectEx', async () => {
|
|
7
|
+
// Arrange
|
|
8
|
+
type T = { id: number; name: string };
|
|
9
|
+
const options: T[] = [
|
|
10
|
+
{ id: 1, name: 'Name 1' },
|
|
11
|
+
{ id: 2, name: 'Name 2' }
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
// Render component
|
|
15
|
+
const { baseElement } = render(
|
|
16
|
+
<SelectEx<T> options={options} name="test" search labelField="name" />
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
// Act, click to show the list
|
|
20
|
+
const button = screen.getByRole('button');
|
|
21
|
+
fireEvent.mouseDown(button); // Not click
|
|
22
|
+
|
|
23
|
+
// Get list item
|
|
24
|
+
const item = await findByText(baseElement, 'Name 2');
|
|
25
|
+
expect(item.nodeName).toBe('SPAN');
|
|
26
|
+
});
|
package/lib/mu/SelectEx.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export declare type SelectExProps<T extends object, D extends DataTypes.Keys<T>
|
|
|
16
16
|
/**
|
|
17
17
|
* Item icon renderer
|
|
18
18
|
*/
|
|
19
|
-
itemIconRenderer?: (id:
|
|
19
|
+
itemIconRenderer?: (id: T[D]) => React.ReactNode;
|
|
20
20
|
/**
|
|
21
21
|
* Label field
|
|
22
22
|
*/
|
|
@@ -28,7 +28,7 @@ export declare type SelectExProps<T extends object, D extends DataTypes.Keys<T>
|
|
|
28
28
|
/**
|
|
29
29
|
* Item click handler
|
|
30
30
|
*/
|
|
31
|
-
onItemClick?: (event: React.MouseEvent,
|
|
31
|
+
onItemClick?: (event: React.MouseEvent, option: T) => void;
|
|
32
32
|
/**
|
|
33
33
|
* On load data handler
|
|
34
34
|
*/
|
package/lib/mu/SelectEx.js
CHANGED
|
@@ -77,7 +77,7 @@ export function SelectEx(props) {
|
|
|
77
77
|
const getLabel = (option) => {
|
|
78
78
|
return typeof labelField === 'function'
|
|
79
79
|
? labelField(option)
|
|
80
|
-
:
|
|
80
|
+
: option[labelField];
|
|
81
81
|
};
|
|
82
82
|
// Refs
|
|
83
83
|
const divRef = React.useRef();
|
|
@@ -142,7 +142,7 @@ export function SelectEx(props) {
|
|
|
142
142
|
// Option
|
|
143
143
|
return (React.createElement(MenuItem, { key: id, value: id, onClick: (event) => {
|
|
144
144
|
if (onItemClick) {
|
|
145
|
-
onItemClick(event,
|
|
145
|
+
onItemClick(event, option);
|
|
146
146
|
if (event.defaultPrevented)
|
|
147
147
|
return;
|
|
148
148
|
}
|
|
@@ -151,6 +151,6 @@ export function SelectEx(props) {
|
|
|
151
151
|
} },
|
|
152
152
|
multiple && React.createElement(Checkbox, { checked: itemChecked(id) }),
|
|
153
153
|
React.createElement(ListItemText, { primary: label }),
|
|
154
|
-
itemIconRenderer && (React.createElement(ListItemRightIcon, null, itemIconRenderer(
|
|
154
|
+
itemIconRenderer && (React.createElement(ListItemRightIcon, null, itemIconRenderer(option[idField])))));
|
|
155
155
|
}))));
|
|
156
156
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/react",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.80",
|
|
4
4
|
"description": "TypeScript ReactJs framework",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -51,9 +51,9 @@
|
|
|
51
51
|
"@emotion/css": "^11.10.0",
|
|
52
52
|
"@emotion/react": "^11.10.0",
|
|
53
53
|
"@emotion/styled": "^11.10.0",
|
|
54
|
-
"@etsoo/appscript": "^1.2.
|
|
54
|
+
"@etsoo/appscript": "^1.2.85",
|
|
55
55
|
"@etsoo/notificationbase": "^1.1.7",
|
|
56
|
-
"@etsoo/shared": "^1.1.
|
|
56
|
+
"@etsoo/shared": "^1.1.51",
|
|
57
57
|
"@mui/icons-material": "^5.10.2",
|
|
58
58
|
"@mui/material": "^5.10.2",
|
|
59
59
|
"@types/pica": "^9.0.1",
|
|
@@ -79,17 +79,17 @@
|
|
|
79
79
|
"@babel/plugin-transform-runtime": "^7.18.10",
|
|
80
80
|
"@babel/preset-env": "^7.18.10",
|
|
81
81
|
"@babel/runtime-corejs3": "^7.18.9",
|
|
82
|
+
"@testing-library/jest-dom": "^5.16.5",
|
|
83
|
+
"@testing-library/react": "^13.3.0",
|
|
82
84
|
"@types/jest": "^28.1.8",
|
|
83
|
-
"@types/react-test-renderer": "^18.0.0",
|
|
84
85
|
"@typescript-eslint/eslint-plugin": "^5.35.1",
|
|
85
86
|
"@typescript-eslint/parser": "^5.35.1",
|
|
86
|
-
"eslint": "^8.
|
|
87
|
+
"eslint": "^8.23.0",
|
|
87
88
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
88
89
|
"eslint-plugin-import": "^2.26.0",
|
|
89
|
-
"eslint-plugin-react": "^7.31.
|
|
90
|
+
"eslint-plugin-react": "^7.31.1",
|
|
90
91
|
"jest": "^28.1.3",
|
|
91
92
|
"jest-environment-jsdom": "^28.1.3",
|
|
92
|
-
"react-test-renderer": "^18.2.0",
|
|
93
93
|
"ts-jest": "^28.0.8",
|
|
94
94
|
"typescript": "^4.8.2"
|
|
95
95
|
}
|
package/src/mu/SelectEx.tsx
CHANGED
|
@@ -42,7 +42,7 @@ export type SelectExProps<
|
|
|
42
42
|
/**
|
|
43
43
|
* Item icon renderer
|
|
44
44
|
*/
|
|
45
|
-
itemIconRenderer?: (id:
|
|
45
|
+
itemIconRenderer?: (id: T[D]) => React.ReactNode;
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
48
|
* Label field
|
|
@@ -57,7 +57,7 @@ export type SelectExProps<
|
|
|
57
57
|
/**
|
|
58
58
|
* Item click handler
|
|
59
59
|
*/
|
|
60
|
-
onItemClick?: (event: React.MouseEvent,
|
|
60
|
+
onItemClick?: (event: React.MouseEvent, option: T) => void;
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* On load data handler
|
|
@@ -172,7 +172,7 @@ export function SelectEx<
|
|
|
172
172
|
const getLabel = (option: T) => {
|
|
173
173
|
return typeof labelField === 'function'
|
|
174
174
|
? labelField(option)
|
|
175
|
-
:
|
|
175
|
+
: (option[labelField] as string);
|
|
176
176
|
};
|
|
177
177
|
|
|
178
178
|
// Refs
|
|
@@ -268,7 +268,7 @@ export function SelectEx<
|
|
|
268
268
|
value={id}
|
|
269
269
|
onClick={(event) => {
|
|
270
270
|
if (onItemClick) {
|
|
271
|
-
onItemClick(event,
|
|
271
|
+
onItemClick(event, option);
|
|
272
272
|
if (event.defaultPrevented) return;
|
|
273
273
|
}
|
|
274
274
|
if (!multiple) setItemValue(id);
|
|
@@ -278,7 +278,7 @@ export function SelectEx<
|
|
|
278
278
|
<ListItemText primary={label} />
|
|
279
279
|
{itemIconRenderer && (
|
|
280
280
|
<ListItemRightIcon>
|
|
281
|
-
{itemIconRenderer(
|
|
281
|
+
{itemIconRenderer(option[idField])}
|
|
282
282
|
</ListItemRightIcon>
|
|
283
283
|
)}
|
|
284
284
|
</MenuItem>
|