Skip to content

Commit

Permalink
feat: add react utils package
Browse files Browse the repository at this point in the history
  • Loading branch information
abelflopes committed Dec 21, 2023
1 parent c1ad55e commit fe8737f
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/utils/react/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: "@react-ck/babel-config",
};
2 changes: 2 additions & 0 deletions packages/utils/react/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Hack for module resolution of non built packages
export * from "./src/index";
1 change: 1 addition & 0 deletions packages/utils/react/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { config as default } from "@react-ck/jest-config";
29 changes: 29 additions & 0 deletions packages/utils/react/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "@react-ck/react-utils",
"private": true,
"version": "1.0.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"/dist"
],
"homepage": "https://github.com/abelflopes/react-ck/tree/master/packages/utils/react-hooks#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/abelflopes/react-ck.git"
},
"scripts": {
"build": "tsc -p tsconfig.build.json",
"lint:typescript": "tsc --noEmit",
"test": "jest --testPathPattern=\".unit.*\""
},
"devDependencies": {
"@react-ck/babel-config": "^1.0.0",
"@react-ck/jest-config": "^1.0.0",
"@react-ck/typescript-config": "^1.0.0",
"@types/react": "^18.2.33"
},
"peerDependencies": {
"react": "^18.2.0"
}
}
13 changes: 13 additions & 0 deletions packages/utils/react/src/display-name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { type ReactElement } from "react";

export function getDisplayName(el: ReactElement): string | undefined {
if (typeof el.type === "string") {
return el.type;
}

if (typeof el.type !== "string" && "name" in el.type) {
return el.type.name;
}

return undefined;
}
1 change: 1 addition & 0 deletions packages/utils/react/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./display-name";
7 changes: 7 additions & 0 deletions packages/utils/react/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "@react-ck/typescript-config/tsconfig.build.json",
"compilerOptions": {
"outDir": "./dist"
},
"include": ["./*.d.ts", "./src/**/*", "./src/index.ts*"]
}
4 changes: 4 additions & 0 deletions packages/utils/react/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "@react-ck/typescript-config/tsconfig.json",
"include": ["./**/*"]
}

0 comments on commit fe8737f

Please sign in to comment.