frame.select 1.0.3 → 1.0.5
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/dist/App.js +1 -1
- package/dist/components/ItemFilter.d.ts.map +1 -0
- package/dist/components/ItemFilter.test.d.ts +2 -0
- package/dist/components/ItemFilter.test.d.ts.map +1 -0
- package/dist/components/ItemFilter.test.js +41 -0
- package/dist/components/ItemList.d.ts.map +1 -0
- package/dist/components/ItemList.test.d.ts +2 -0
- package/dist/components/ItemList.test.d.ts.map +1 -0
- package/dist/components/ItemList.test.js +74 -0
- package/dist/components/itemTypes.d.ts.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -2
- package/dist/assets/components/ItemFilter.d.ts.map +0 -1
- package/dist/assets/components/ItemList.d.ts.map +0 -1
- package/dist/assets/components/itemTypes.d.ts.map +0 -1
- /package/dist/{assets/components → components}/ItemFilter.d.ts +0 -0
- /package/dist/{assets/components → components}/ItemFilter.js +0 -0
- /package/dist/{assets/components → components}/ItemList.d.ts +0 -0
- /package/dist/{assets/components → components}/ItemList.js +0 -0
- /package/dist/{assets/components → components}/itemTypes.d.ts +0 -0
- /package/dist/{assets/components → components}/itemTypes.js +0 -0
package/dist/App.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createColumnHelper } from '@tanstack/react-table';
|
|
2
2
|
import './App.css';
|
|
3
|
-
import ItemList from './
|
|
3
|
+
import ItemList from './components/ItemList';
|
|
4
4
|
import { useState } from 'react';
|
|
5
5
|
import React from 'react';
|
|
6
6
|
function App() {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ItemFilter.d.ts","sourceRoot":"","sources":["../../src/components/ItemFilter.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,UAAU,eAAe;IACvB,UAAU,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC;CAChC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,QAAA,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CAgCzC,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ItemFilter.test.d.ts","sourceRoot":"","sources":["../../src/components/ItemFilter.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { render, fireEvent } from '@testing-library/react';
|
|
2
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
3
|
+
import ItemFilter from './ItemFilter';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
describe('ItemFilter', () => {
|
|
6
|
+
it('should clear the filter when clearFilter is called', () => {
|
|
7
|
+
const setFilterMock = vi.fn();
|
|
8
|
+
const itemFilter = {
|
|
9
|
+
filter: 'test',
|
|
10
|
+
setFilter: setFilterMock,
|
|
11
|
+
placeholder: 'Filter Items',
|
|
12
|
+
property: 'name',
|
|
13
|
+
filterMatches: vi.fn(),
|
|
14
|
+
};
|
|
15
|
+
const { getByPlaceholderText, getByRole } = render(React.createElement(ItemFilter, { itemFilter: itemFilter }));
|
|
16
|
+
const input = getByPlaceholderText('Filter Items');
|
|
17
|
+
const button = getByRole('button');
|
|
18
|
+
// Ensure the input has the initial filter value
|
|
19
|
+
expect(input.value).toBe('test');
|
|
20
|
+
// Click the clear button
|
|
21
|
+
fireEvent.click(button);
|
|
22
|
+
// Ensure the setFilter function was called with an empty string
|
|
23
|
+
expect(setFilterMock).toHaveBeenCalledWith('');
|
|
24
|
+
});
|
|
25
|
+
it('should update the filter when handleInputChange is called', () => {
|
|
26
|
+
const setFilterMock = vi.fn();
|
|
27
|
+
const itemFilter = {
|
|
28
|
+
filter: '',
|
|
29
|
+
setFilter: setFilterMock,
|
|
30
|
+
placeholder: 'Filter Items',
|
|
31
|
+
property: 'name',
|
|
32
|
+
filterMatches: vi.fn(),
|
|
33
|
+
};
|
|
34
|
+
const { getByPlaceholderText } = render(React.createElement(ItemFilter, { itemFilter: itemFilter }));
|
|
35
|
+
const input = getByPlaceholderText('Filter Items');
|
|
36
|
+
// Simulate typing in the input field
|
|
37
|
+
fireEvent.change(input, { target: { value: 'new filter' } });
|
|
38
|
+
// Ensure the setFilter function was called with the new value
|
|
39
|
+
expect(setFilterMock).toHaveBeenCalledWith('new filter');
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ItemList.d.ts","sourceRoot":"","sources":["../../src/components/ItemList.tsx"],"names":[],"mappings":"AASA,OAAO,EAIL,IAAI,EAGL,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,WAAW,EAAE,OAAO,EAAS,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,GAAG,EAAsB,MAAM,OAAO,CAAC;AAChD,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,UAAU,aAAa,CAAC,CAAC;IACvB,QAAQ,EAAE,CAAC,EAAE,CAAC;IACd,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,KAAK,CAAC,SAAS,CAAC;IAC/C,UAAU,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IAC5B,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;IAC7C,YAAY,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5B,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAC7B;AAED,iBAAS,QAAQ,CAAC,CAAC,SAAS;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,EAC5C,QAAQ,EACR,UAAU,EACV,UAAU,EACV,SAAS,EACT,YAAiB,EACjB,KAA8D,GAC/D,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,OAAO,CAwJhC;AAED,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ItemList.test.d.ts","sourceRoot":"","sources":["../../src/components/ItemList.test.tsx"],"names":[],"mappings":"AACA,OAAO,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
2
|
+
import '@testing-library/jest-dom';
|
|
3
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
4
|
+
import { createColumnHelper } from '@tanstack/react-table';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import ItemList from './ItemList';
|
|
7
|
+
describe('ItemList', () => {
|
|
8
|
+
const itemList = [
|
|
9
|
+
{ name: 'Item 1' },
|
|
10
|
+
{ name: 'Item 2' },
|
|
11
|
+
{ name: 'Item 3' },
|
|
12
|
+
];
|
|
13
|
+
const filterMatches = (item, filter) => item.name.includes(filter);
|
|
14
|
+
// const filterEvent = vi.fn()
|
|
15
|
+
const renderItem = (item) => React.createElement("span", null, item);
|
|
16
|
+
const clickFunc = vi.fn();
|
|
17
|
+
const itemFilter = {
|
|
18
|
+
filter: 'Item',
|
|
19
|
+
setFilter: vi.fn(),
|
|
20
|
+
property: 'name',
|
|
21
|
+
filterMatches,
|
|
22
|
+
placeholder: 'Filter Items',
|
|
23
|
+
};
|
|
24
|
+
it('renders the item list', () => {
|
|
25
|
+
render(React.createElement(ItemList, { itemList: itemList }));
|
|
26
|
+
itemList.forEach((item) => {
|
|
27
|
+
expect(screen.getByText(item.name)).toBeInTheDocument();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
it('filters the item list based on filterMatches', () => {
|
|
31
|
+
render(React.createElement(ItemList, { itemList: itemList, itemFilter: itemFilter }));
|
|
32
|
+
expect(screen.getByText('Item 1')).toBeInTheDocument();
|
|
33
|
+
expect(screen.getByText('Item 2')).toBeInTheDocument();
|
|
34
|
+
expect(screen.getByText('Item 3')).toBeInTheDocument();
|
|
35
|
+
});
|
|
36
|
+
// it('calls filterEvent when filter is applied', () => {
|
|
37
|
+
// render(<ItemList itemList={itemList} filterEvent={filterEvent} itemFilter={itemFilter} />)
|
|
38
|
+
// expect(filterEvent).toHaveBeenCalledWith(itemList)
|
|
39
|
+
// })
|
|
40
|
+
it('renders custom item using renderItem', () => {
|
|
41
|
+
render(React.createElement(ItemList, { itemList: itemList, renderItem: renderItem }));
|
|
42
|
+
itemList.forEach((item) => {
|
|
43
|
+
expect(screen.getByText(item.name)).toBeInTheDocument();
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
it('calls clickFunc with the correct cell when an item is clicked', () => {
|
|
47
|
+
render(React.createElement(ItemList, { itemList: itemList, clickFunc: clickFunc }));
|
|
48
|
+
const itemButton = screen.getByText('Item 1').closest('button');
|
|
49
|
+
fireEvent.click(itemButton);
|
|
50
|
+
expect(clickFunc).toHaveBeenCalled();
|
|
51
|
+
expect(clickFunc.mock.calls[0][0].getValue()).toBe('Item 1');
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
describe('ItemList - createColumnHelper', () => {
|
|
55
|
+
it('creates columns correctly', () => {
|
|
56
|
+
const columnHelper = createColumnHelper();
|
|
57
|
+
const columns = [
|
|
58
|
+
columnHelper.accessor('name', {
|
|
59
|
+
header: 'Name',
|
|
60
|
+
cell: (info) => React.createElement("span", null, info.getValue()),
|
|
61
|
+
}),
|
|
62
|
+
columnHelper.accessor('age', {
|
|
63
|
+
header: 'Age',
|
|
64
|
+
cell: (info) => React.createElement("span", null, info.getValue()),
|
|
65
|
+
}),
|
|
66
|
+
];
|
|
67
|
+
expect(columns).toHaveLength(2);
|
|
68
|
+
expect(columns[0].accessorKey).toBe('name');
|
|
69
|
+
expect(columns[0].header).toBe('Name');
|
|
70
|
+
expect(typeof columns[0].cell).toBe('function');
|
|
71
|
+
expect(columns[1].header).toBe('Age');
|
|
72
|
+
expect(typeof columns[1].cell).toBe('function');
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"itemTypes.d.ts","sourceRoot":"","sources":["../../src/components/itemTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,MAAM,KAAK,GAAG;IAClB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAC3B,QAAQ,EAAE,MAAM,CAAC,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,aAAa,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;IACpD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI;IACvB,MAAM,EAAE,mBAAmB,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IACvC,MAAM,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;CACzB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAC5D,YAAY,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as ItemList } from './components/ItemList';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../src/app.tsx","../src/main.tsx","../src/vite-env.d.ts","../src/
|
|
1
|
+
{"root":["../src/app.tsx","../src/index.ts","../src/main.tsx","../src/vite-env.d.ts","../src/components/itemfilter.test.tsx","../src/components/itemfilter.tsx","../src/components/itemlist.test.tsx","../src/components/itemlist.tsx","../src/components/itemtypes.ts"],"version":"5.8.3"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "frame.select",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "A React component for selecting items from a list with a search bar.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"build": "tsc -b",
|
|
16
16
|
"build-and-vite": "tsc -b && vite build",
|
|
17
17
|
"lint": "eslint .",
|
|
18
|
+
"test": "vitest --config vitest.config.ts",
|
|
18
19
|
"preview": "vite preview"
|
|
19
20
|
},
|
|
20
21
|
"dependencies": {
|
|
@@ -28,6 +29,9 @@
|
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
30
31
|
"@eslint/js": "^9.21.0",
|
|
32
|
+
"@testing-library/dom": "^10.4.0",
|
|
33
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
34
|
+
"@testing-library/react": "^16.2.0",
|
|
31
35
|
"@types/react": "^19.0.10",
|
|
32
36
|
"@types/react-dom": "^19.1.2",
|
|
33
37
|
"@vitejs/plugin-react": "^4.3.4",
|
|
@@ -35,8 +39,10 @@
|
|
|
35
39
|
"eslint-plugin-react-hooks": "^5.1.0",
|
|
36
40
|
"eslint-plugin-react-refresh": "^0.4.19",
|
|
37
41
|
"globals": "^16.0.0",
|
|
42
|
+
"jsdom": "^26.0.0",
|
|
38
43
|
"typescript": "~5.8.3",
|
|
39
44
|
"typescript-eslint": "^8.24.1",
|
|
40
|
-
"vite": "^6.2.0"
|
|
45
|
+
"vite": "^6.2.0",
|
|
46
|
+
"vitest": "^3.0.9"
|
|
41
47
|
}
|
|
42
48
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ItemFilter.d.ts","sourceRoot":"","sources":["../../../src/assets/components/ItemFilter.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,UAAU,eAAe;IACvB,UAAU,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC;CAChC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,QAAA,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CAgCzC,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ItemList.d.ts","sourceRoot":"","sources":["../../../src/assets/components/ItemList.tsx"],"names":[],"mappings":"AASA,OAAO,EAIL,IAAI,EAGL,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,WAAW,EAAE,OAAO,EAAS,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,GAAG,EAAsB,MAAM,OAAO,CAAC;AAChD,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,UAAU,aAAa,CAAC,CAAC;IACvB,QAAQ,EAAE,CAAC,EAAE,CAAC;IACd,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,KAAK,CAAC,SAAS,CAAC;IAC/C,UAAU,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IAC5B,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;IAC7C,YAAY,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5B,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAC7B;AAED,iBAAS,QAAQ,CAAC,CAAC,SAAS;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,EAAE,EAC5C,QAAQ,EACR,UAAU,EACV,UAAU,EACV,SAAS,EACT,YAAiB,EACjB,KAA8D,GAC/D,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,OAAO,CAwJhC;AAED,eAAe,QAAQ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"itemTypes.d.ts","sourceRoot":"","sources":["../../../src/assets/components/itemTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,MAAM,KAAK,GAAG;IAClB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAC3B,QAAQ,EAAE,MAAM,CAAC,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,aAAa,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;IACpD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI;IACvB,MAAM,EAAE,mBAAmB,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IACvC,MAAM,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;CACzB,CAAC"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|