Skip to content

Commit

Permalink
Remove dependency on react-children-utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
tsung-ju committed Jun 22, 2021
1 parent 974281e commit 4102b8a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 82 deletions.
76 changes: 0 additions & 76 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
"react": "17.x.x || 16.x.x || 15.x.x"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^13.0.0",
"@types/react": "^17.0.11",
"react-children-utilities": "^2.5.3",
"rollup": "^2.52.2",
"rollup-plugin-typescript2": "^0.30.0",
"tslib": "^2.3.0",
Expand Down
3 changes: 1 addition & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import resolve from "@rollup/plugin-node-resolve";
import typescript from "rollup-plugin-typescript2";
import pkg from "./package.json";

Expand All @@ -14,6 +13,6 @@ export default {
format: "esm",
},
],
plugins: [resolve(), typescript()],
plugins: [typescript()],
external: ["react", "react/jsx-runtime"],
};
15 changes: 13 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useEffect, useRef } from "react";
import onlyText from "react-children-utilities/lib/onlyText.js";
import React, { Children, useEffect, useRef } from "react";

export interface TruncateLinesProps
extends React.HTMLAttributes<HTMLSpanElement> {
Expand Down Expand Up @@ -54,3 +53,15 @@ function lastIndexWhere(
}
return start;
}

function onlyText(children: React.ReactNode): string {
let result = "";
Children.forEach(children, (child) => {
if (typeof child === "number" || typeof child === "string") {
result += child.toString();
} else {
throw new TypeError("Unexpected child type");
}
});
return result;
}

0 comments on commit 4102b8a

Please sign in to comment.