-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve exports and release version patch
- Loading branch information
1 parent
03a0018
commit e76dd95
Showing
13 changed files
with
432 additions
and
41 deletions.
There are no files selected for viewing
223 changes: 223 additions & 0 deletions
223
examples/src/pages/tests/table/context-menus/custom-filter-menu.page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,223 @@ | ||
import * as React from 'react'; | ||
|
||
import { | ||
InfiniteTable, | ||
InfiniteTablePropColumns, | ||
DataSource, | ||
useInfiniteHeaderCell, | ||
useInfinitePortalContainer, | ||
alignNode, | ||
InfiniteTableColumn, | ||
} from '@infinite-table/infinite-react'; | ||
import { createPortal } from 'react-dom'; | ||
import { FilterIcon } from 'lucide-react'; | ||
|
||
type Developer = { | ||
id: number; | ||
|
||
firstName: string; | ||
lastName: string; | ||
|
||
currency: string; | ||
preferredLanguage: string; | ||
stack: string; | ||
canDesign: 'yes' | 'no'; | ||
|
||
age: number; | ||
}; | ||
|
||
const data: Developer[] = [ | ||
{ | ||
id: 1, | ||
firstName: 'John', | ||
lastName: 'Bob', | ||
age: 20, | ||
canDesign: 'yes', | ||
currency: 'USD', | ||
preferredLanguage: 'JavaScript', | ||
stack: 'frontend', | ||
}, | ||
{ | ||
id: 2, | ||
firstName: 'Marry', | ||
lastName: 'Bob', | ||
age: 25, | ||
canDesign: 'yes', | ||
currency: 'USD', | ||
preferredLanguage: 'JavaScript', | ||
stack: 'frontend', | ||
}, | ||
{ | ||
id: 3, | ||
firstName: 'Bill', | ||
lastName: 'Bobson', | ||
age: 30, | ||
canDesign: 'no', | ||
currency: 'CAD', | ||
preferredLanguage: 'TypeScript', | ||
stack: 'frontend', | ||
}, | ||
{ | ||
id: 4, | ||
firstName: 'Mark', | ||
lastName: 'Twain', | ||
age: 31, | ||
canDesign: 'yes', | ||
currency: 'CAD', | ||
preferredLanguage: 'Rust', | ||
stack: 'backend', | ||
}, | ||
{ | ||
id: 5, | ||
firstName: 'Matthew', | ||
lastName: 'Hilson', | ||
age: 29, | ||
canDesign: 'yes', | ||
currency: 'CAD', | ||
preferredLanguage: 'Go', | ||
stack: 'backend', | ||
}, | ||
]; | ||
|
||
function ColumnFilterMenuIcon() { | ||
const { renderBag, htmlElementRef: alignToRef } = useInfiniteHeaderCell(); | ||
|
||
const portalContainer = useInfinitePortalContainer(); | ||
|
||
const [visible, setVisible] = React.useState(false); | ||
|
||
React.useEffect(() => { | ||
if (!domRef.current || !alignToRef.current) { | ||
return; | ||
} | ||
|
||
alignNode(domRef.current, { | ||
alignTo: alignToRef.current, | ||
alignPosition: [ | ||
['TopRight', 'BottomRight'], | ||
['TopRight', 'BottomRight'], | ||
], | ||
}); | ||
}); | ||
|
||
const domRef = React.useRef<HTMLDivElement>(null); | ||
|
||
return ( | ||
<div | ||
onMouseDown={(e) => { | ||
if (e.nativeEvent) { | ||
// @ts-ignore | ||
e.nativeEvent.__insideMenu = true; | ||
} | ||
}} | ||
onPointerDown={(event) => { | ||
event.stopPropagation(); | ||
|
||
if (visible) { | ||
setVisible(false); | ||
return; | ||
} | ||
|
||
setVisible(true); | ||
|
||
function handleMouseDown(event: MouseEvent) { | ||
// @ts-ignore | ||
if (event.__insideMenu !== true) { | ||
setVisible(false); | ||
document.documentElement.removeEventListener( | ||
'mousedown', | ||
handleMouseDown, | ||
); | ||
} | ||
} | ||
document.documentElement.addEventListener('mousedown', handleMouseDown); | ||
}} | ||
> | ||
<FilterIcon size={16} /> | ||
{createPortal( | ||
<div | ||
ref={domRef} | ||
style={{ | ||
position: 'absolute', | ||
color: 'white', | ||
top: 0, | ||
overflow: 'visible', | ||
background: 'var(--infinite-background)', | ||
border: `1px solid currentColor`, | ||
left: 0, | ||
width: 200, | ||
padding: 10, | ||
display: visible ? 'block' : 'none', | ||
}} | ||
> | ||
{renderBag.filterEditor} | ||
</div>, | ||
portalContainer!, | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
const customHeader: InfiniteTableColumn<any>['renderHeader'] = ({ | ||
renderBag, | ||
}) => { | ||
return ( | ||
<> | ||
{renderBag.header} | ||
<div style={{ flex: 1 }}></div> | ||
|
||
{renderBag.filterIcon} | ||
|
||
{renderBag.menuIcon} | ||
<ColumnFilterMenuIcon /> | ||
</> | ||
); | ||
}; | ||
|
||
const columns: InfiniteTablePropColumns<Developer> = { | ||
firstName: { | ||
field: 'firstName', | ||
renderHeader: customHeader, | ||
defaultFilterable: false, | ||
}, | ||
age: { | ||
field: 'age', | ||
type: 'number', | ||
|
||
renderHeader: customHeader, | ||
}, | ||
|
||
stack: { field: 'stack', renderMenuIcon: false }, | ||
currency: { field: 'currency' }, | ||
}; | ||
|
||
export default () => { | ||
return ( | ||
<> | ||
<React.StrictMode> | ||
<DataSource<Developer> | ||
data={data} | ||
primaryKey="id" | ||
defaultFilterValue={[]} | ||
> | ||
<InfiniteTable<Developer> | ||
domProps={{ | ||
style: { | ||
margin: '5px', | ||
|
||
height: '80vh', | ||
width: '80vw', | ||
border: '1px solid gray', | ||
position: 'relative', | ||
}, | ||
}} | ||
showColumnFilters={true} | ||
columnDefaultWidth={300} | ||
columnMinWidth={50} | ||
columns={columns} | ||
/> | ||
</DataSource> | ||
</React.StrictMode> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
source/src/components/InfiniteTable/hooks/useInfinitePortalContainer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { useMasterDetailContext } from '../../DataSource/publicHooks/useDataSourceState'; | ||
import { useInfiniteTable } from './useInfiniteTable'; | ||
|
||
export function useInfinitePortalContainer() { | ||
const masterContext = useMasterDetailContext(); | ||
|
||
const masterState = masterContext ? masterContext.getMasterState() : null; | ||
const infiniteState = useInfiniteTable().getState(); | ||
|
||
const portalContainer = (masterState || infiniteState).portalDOMRef.current; | ||
|
||
return portalContainer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.