Skip to content

Commit

Permalink
fix(TreeList): provide types for renderContainerProps (#1842)
Browse files Browse the repository at this point in the history
  • Loading branch information
DakEnviy authored Sep 9, 2024
1 parent c8e1ebb commit 90ca9cc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/components/TreeList/TreeList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type {TreeListContainerProps, TreeListProps} from './types';

const b = block('tree-list');

export const TreeList = <T,>({
export const TreeList = <T, P extends {} = {}>({
qa,
id,
size = 'm',
Expand All @@ -29,7 +29,7 @@ export const TreeList = <T,>({
renderContainer = ListContainer,
onItemClick: propsOnItemClick,
mapItemDataToContentProps,
}: TreeListProps<T>) => {
}: TreeListProps<T, P>) => {
const uniqId = useUniqId();
const treeListId = id ?? uniqId;
const containerRefLocal = React.useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -61,12 +61,12 @@ export const TreeList = <T,>({
list,
});

const renderItem: TreeListContainerProps<T>['renderItem'] = (
const renderItem: TreeListContainerProps<T, P>['renderItem'] = (
itemId,
index,
renderContainerProps,
) => {
const renderState = getItemRenderState({
const renderState = getItemRenderState<T>({
qa,
id: itemId,
size,
Expand Down
2 changes: 1 addition & 1 deletion src/components/TreeList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type TreeListRenderItem<T, P extends {} = {}> = (props: {
renderContainerProps?: P;
}) => React.JSX.Element;

export type TreeListContainerProps<T> = ListContainerProps<T> & {
export type TreeListContainerProps<T, P extends {} = {}> = ListContainerProps<T, P> & {
size: ListItemSize;
};

Expand Down
8 changes: 4 additions & 4 deletions src/components/TreeSelect/TreeSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const defaultItemRenderer: TreeListRenderItem<unknown> = (renderState) => {
return <ListItemView {...renderState.props} {...renderState.renderContainerProps} />;
};

export const TreeSelect = React.forwardRef(function TreeSelect<T>(
export const TreeSelect = React.forwardRef(function TreeSelect<T, P extends {} = {}>(
{
id,
qa,
Expand Down Expand Up @@ -55,14 +55,14 @@ export const TreeSelect = React.forwardRef(function TreeSelect<T>(
onOpenChange,
onUpdate,
renderControl,
renderItem = defaultItemRenderer as TreeListRenderItem<T>,
renderItem = defaultItemRenderer as TreeListRenderItem<T, P>,
renderContainer,
mapItemDataToContentProps,
onFocus,
onBlur,
getItemId,
onItemClick,
}: TreeSelectProps<T>,
}: TreeSelectProps<T, P>,
ref: React.Ref<HTMLButtonElement>,
) {
const mobile = useMobile();
Expand Down Expand Up @@ -218,7 +218,7 @@ export const TreeSelect = React.forwardRef(function TreeSelect<T>(
>
{slotBeforeListBody}

<TreeList<T>
<TreeList<T, P>
list={list}
size={size}
className={b('list', containerClassName)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {ListContainerView} from '../ListContainerView';
import type {ListContainerViewProps} from '../ListContainerView/ListContainerView';
import {ListItemRecursiveRenderer} from '../ListRecursiveRenderer/ListRecursiveRenderer';

export type ListContainerProps<T> = Omit<ListContainerViewProps, 'children'> & {
export type ListContainerProps<T, P extends {} = {}> = Omit<ListContainerViewProps, 'children'> & {
list: UseListResult<T>;
containerRef?: React.RefObject<HTMLDivElement>;
renderItem(
Expand All @@ -14,16 +14,16 @@ export type ListContainerProps<T> = Omit<ListContainerViewProps, 'children'> & {
/**
* Ability to transfer props from an overridden container render
*/
renderContainerProps?: Object,
renderContainerProps?: P,
): React.JSX.Element;
};

export function ListContainer<T>({
export function ListContainer<T, P extends {} = {}>({
containerRef,
renderItem,
list,
...props
}: ListContainerProps<T>) {
}: ListContainerProps<T, P>) {
return (
<ListContainerView ref={containerRef} {...props}>
{list.structure.items.map((item, index) => (
Expand Down

0 comments on commit 90ca9cc

Please sign in to comment.