-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add GridTreeColumn header and footer renderers (#194)
- Loading branch information
1 parent
0462893
commit 5d7cf31
Showing
4 changed files
with
84 additions
and
23 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,44 @@ | ||
import { type ComponentType, type ForwardedRef, forwardRef, type ReactElement, type RefAttributes } from 'react'; | ||
import type { GridDefaultItem } from './generated/Grid.js'; | ||
import { | ||
GridTreeColumnElement, | ||
GridTreeColumn as _GridTreeColumn, | ||
type GridTreeColumnProps as _GridTreeColumnProps, | ||
} from './generated/GridTreeColumn.js'; | ||
import type { GridEdgeReactRendererProps } from './renderers/grid.js'; | ||
import { useSimpleRenderer } from './renderers/useSimpleRenderer.js'; | ||
import type { OmittedGridColumnHTMLAttributes } from './GridColumn.js'; | ||
|
||
export * from './generated/GridTreeColumn.js'; | ||
|
||
export type GridTreeColumnProps<TItem> = Partial< | ||
Omit< | ||
_GridTreeColumnProps<TItem>, | ||
'children' | 'footerRenderer' | 'headerRenderer' | 'renderer' | keyof OmittedGridColumnHTMLAttributes<TItem> | ||
> | ||
> & | ||
Readonly<{ | ||
footerRenderer?: ComponentType<GridEdgeReactRendererProps<TItem>> | null; | ||
headerRenderer?: ComponentType<GridEdgeReactRendererProps<TItem>> | null; | ||
}>; | ||
|
||
function GridTreeColumn<TItem = GridDefaultItem>( | ||
props: GridTreeColumnProps<TItem>, | ||
ref: ForwardedRef<GridTreeColumnElement<TItem>>, | ||
): ReactElement | null { | ||
const [headerPortals, headerRenderer] = useSimpleRenderer(props.headerRenderer); | ||
const [footerPortals, footerRenderer] = useSimpleRenderer(props.footerRenderer); | ||
|
||
return ( | ||
<_GridTreeColumn<TItem> {...props} headerRenderer={headerRenderer} footerRenderer={footerRenderer} ref={ref}> | ||
{headerPortals} | ||
{footerPortals} | ||
</_GridTreeColumn> | ||
); | ||
} | ||
|
||
const ForwardedGridTreeColumn = forwardRef(GridTreeColumn) as <TItem = GridDefaultItem>( | ||
props: GridTreeColumnProps<TItem> & RefAttributes<GridTreeColumnElement<TItem>>, | ||
) => ReactElement | null; | ||
|
||
export { ForwardedGridTreeColumn as GridTreeColumn }; |
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