Skip to content

Commit

Permalink
feat: allow react elements in external field mapRow
Browse files Browse the repository at this point in the history
  • Loading branch information
camhammel authored and chrisvxd committed Nov 14, 2024
1 parent 5ba9399 commit 2f781de
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions packages/core/components/ExternalInput/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { useMemo, useEffect, useState, useCallback } from "react";
import {
useMemo,
useEffect,
useState,
useCallback,
isValidElement,
} from "react";
import styles from "./styles.module.css";
import getClassNameFactory from "../../lib/get-class-name-factory";
import { ExternalField } from "../../types";
Expand Down Expand Up @@ -54,7 +60,11 @@ export const ExternalInput = ({

for (const item of mappedData) {
for (const key of Object.keys(item)) {
if (typeof item[key] === "string" || typeof item[key] === "number") {
if (
typeof item[key] === "string" ||
typeof item[key] === "number" ||
isValidElement(item[key])
) {
validKeys.add(key);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/types/Fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export type ExternalField<
filters: Record<string, any>;
}) => Promise<any[] | null>;
mapProp?: (value: any) => Props;
mapRow?: (value: any) => Record<string, string | number>;
mapRow?: (value: any) => Record<string, string | number | ReactElement>;
getItemSummary?: (item: Props, index?: number) => string;
showSearch?: boolean;
initialQuery?: string;
Expand Down

0 comments on commit 2f781de

Please sign in to comment.