Skip to content

Commit 55560ef

Browse files
committed
[Dashboard] Remove react-children-utilities
1 parent 1e141f3 commit 55560ef

File tree

3 files changed

+44
-14
lines changed

3 files changed

+44
-14
lines changed

apps/dashboard/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
"prismjs": "^1.29.0",
8080
"qrcode": "^1.5.3",
8181
"react": "18.3.1",
82-
"react-children-utilities": "^2.10.0",
8382
"react-day-picker": "^8.10.1",
8483
"react-dom": "18.3.1",
8584
"react-dropzone": "^14.2.9",

apps/dashboard/src/components/contract-components/published-contract/markdown-renderer.tsx

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,54 @@ import {
1313
UnorderedList,
1414
chakra,
1515
} from "@chakra-ui/react";
16-
import { onlyText } from "react-children-utilities";
16+
import { Children, type ReactNode, isValidElement } from "react";
1717
import ReactMarkdown from "react-markdown";
1818
import remarkGfm from "remark-gfm";
1919
import { CodeBlock, Heading, Text } from "tw-components";
2020

21+
// From https://github.com/fernandopasik/react-children-utilities
22+
const onlyText = (children: ReactNode | ReactNode[]): string => {
23+
if (!Array.isArray(children) && !isValidElement(children)) {
24+
return childToString(children);
25+
}
26+
27+
return Children.toArray(children).reduce(
28+
(text: string, child: ReactNode): string => {
29+
let newText = "";
30+
31+
if (
32+
isValidElement<{ children?: ReactNode[] }>(child) &&
33+
Boolean(child.props.children)
34+
) {
35+
newText = onlyText(child.props.children);
36+
} else if (isValidElement(child)) {
37+
newText = "";
38+
} else {
39+
newText = childToString(child);
40+
}
41+
42+
return text.concat(newText);
43+
},
44+
"",
45+
);
46+
};
47+
48+
const childToString = (child?: ReactNode): string => {
49+
if (
50+
typeof child === "undefined" ||
51+
child === null ||
52+
typeof child === "boolean"
53+
) {
54+
return "";
55+
}
56+
57+
if (JSON.stringify(child) === "{}") {
58+
return "";
59+
}
60+
61+
return (child as number | string).toString();
62+
};
63+
2164
const ChakraReactMarkdown = chakra(ReactMarkdown);
2265

2366
export const MarkdownRenderer: React.FC<

pnpm-lock.yaml

Lines changed: 0 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)