Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(TreeList): provide types for renderContainerProps #1842

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading