Skip to content

Commit

Permalink
chore(react): seperate react library
Browse files Browse the repository at this point in the history
  • Loading branch information
oktaysenkan committed Oct 5, 2024
1 parent 6c9448a commit 811319c
Show file tree
Hide file tree
Showing 19 changed files with 27 additions and 53 deletions.
2 changes: 1 addition & 1 deletion apps/next/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Iconify } from "@oktaytest/ui";
import { Iconify } from "@oktaytest/react";

import styles from "../styles/index.module.css";

Expand Down
2 changes: 1 addition & 1 deletion apps/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"@oktaytest/ui": "*",
"@oktaytest/react": "*",
"next": "^14.0.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/rollup-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"dev": "rollup -c --watch"
},
"dependencies": {
"@oktaytest/ui": "*",
"@oktaytest/react": "*",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
Expand Down
2 changes: 1 addition & 1 deletion apps/rollup-react/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { Iconify } from "@oktaytest/ui";
import { Iconify } from "@oktaytest/react";

const App = () => {
return (
Expand Down
2 changes: 1 addition & 1 deletion apps/rspack-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"@oktaytest/ui": "*"
"@oktaytest/react": "*"
},
"devDependencies": {
"@rspack/plugin-react-refresh": "1.0.0",
Expand Down
3 changes: 2 additions & 1 deletion apps/rspack-react/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react";
import { Iconify } from "@oktaytest/ui";
import { Iconify } from "@oktaytest/react";

import "./App.css";

function App() {
Expand Down
2 changes: 1 addition & 1 deletion apps/vite-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"preview": "vite preview"
},
"dependencies": {
"@oktaytest/ui": "*",
"@oktaytest/react": "*",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
Expand Down
2 changes: 1 addition & 1 deletion apps/vite-react/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "./App.css";

import { Iconify } from "@oktaytest/ui";
import { Iconify } from "@oktaytest/react";

function App() {
return (
Expand Down
8 changes: 5 additions & 3 deletions packages/native/src/iconify.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect, ReactNode } from "react";
import React from "react";

import { IconifyProps, RuntimeIcon, RuntimeIconifyProps } from "./types";
import { setAttributes } from "./utils";
Expand Down Expand Up @@ -72,7 +72,9 @@ const getComponent = async (props: RuntimeIconifyProps) => {
};

export const Iconify = (props: IconifyProps) => {
const [Component, setComponent] = useState<ReactNode | null>(null);
const [Component, setComponent] = React.useState<React.ReactNode | null>(
null
);

const renderIcon = async () => {
const icon = await getIcon(props.name);
Expand All @@ -85,7 +87,7 @@ export const Iconify = (props: IconifyProps) => {
setComponent(component);
};

useEffect(() => {
React.useEffect(() => {
renderIcon();
}, [props]);

Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 2 additions & 5 deletions packages/ui/package.json → packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@oktaytest/ui",
"name": "@oktaytest/react",
"version": "0.0.119",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down Expand Up @@ -29,7 +29,6 @@
"devDependencies": {
"@oktaytest/typescript-config": "*",
"@types/react": "^18.2.46",
"@types/react-native": "^0.73.0",
"tsup": "^8.0.1",
"typescript": "^5.3.3"
},
Expand All @@ -38,8 +37,6 @@
"@oktaytest/core": "*"
},
"peerDependencies": {
"react": ">=18.2.0",
"react-native": ">=0.63.0",
"react-native-svg": ">=13.2.0"
"react": ">=18.2.0"
}
}
38 changes: 6 additions & 32 deletions packages/ui/src/iconify.tsx → packages/react/src/iconify.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
import React, { useState, useEffect, ReactNode } from "react";
import React from "react";

import { IconifyProps, RuntimeIcon, RuntimeIconifyProps } from "./types";
import { setAttributes } from "./utils";

const isReactNative = async () => {
try {
if (typeof navigator === "undefined") return true;

require("react-native");

return true;
} catch (error) {
return false;
}
};

const getIcon = (iconName: string) =>
new Promise<RuntimeIcon>(async (resolve, reject) => {
try {
Expand Down Expand Up @@ -46,19 +35,6 @@ const getIcon = (iconName: string) =>
}
});

const nativeIcon = async (props: RuntimeIconifyProps) => {
const { SvgXml } = require("react-native-svg");

return (
<SvgXml
{...props}
xml={props.icon.svg}
width={props.icon.width}
height={props.icon.height}
/>
);
};

const webIcon = async (props: RuntimeIconifyProps) => {
// @ts-ignore
const parse = await import("html-react-parser");
Expand All @@ -69,15 +45,13 @@ const webIcon = async (props: RuntimeIconifyProps) => {
const getComponent = async (props: RuntimeIconifyProps) => {
const formatted = setAttributes(props);

const isNative = await isReactNative();

if (isNative) return nativeIcon(formatted);

return webIcon(formatted);
};

export const Iconify = (props: IconifyProps) => {
const [Component, setComponent] = useState<ReactNode | null>(null);
const [Component, setComponent] = React.useState<React.ReactNode | null>(
null
);

const renderIcon = async () => {
const icon = await getIcon(props.name);
Expand All @@ -90,7 +64,7 @@ export const Iconify = (props: IconifyProps) => {
setComponent(component);
};

useEffect(() => {
React.useEffect(() => {
renderIcon();
}, [props]);

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"dependsOn": ["^build"]
},

"ui#build": {
"react#build": {
"dependsOn": ["core#build"]
},
"native#build": {
Expand Down Expand Up @@ -55,16 +55,16 @@
]
},
"next#build": {
"dependsOn": ["webpack#build", "ui#build"]
"dependsOn": ["webpack#build", "react#build"]
},
"vite-react#build": {
"dependsOn": ["vite#build", "ui#build"]
"dependsOn": ["vite#build", "react#build"]
},
"rspack-react#build": {
"dependsOn": ["rspack#build", "ui#build"]
"dependsOn": ["rspack#build", "react#build"]
},
"rollup-react#build": {
"dependsOn": ["rollup#build", "ui#build"]
"dependsOn": ["rollup#build", "react#build"]
},
"vite-vue#build": {
"dependsOn": ["vite#build", "vue#build"]
Expand Down

0 comments on commit 811319c

Please sign in to comment.