Skip to content

Commit

Permalink
updating components structures
Browse files Browse the repository at this point in the history
  • Loading branch information
moovendhan-v committed Apr 24, 2024
1 parent d2319b2 commit b9e41c1
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 106 deletions.
3 changes: 0 additions & 3 deletions ui_tailwind_shadecn/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ function App() {
<Route path="/login" element={<Login />} />
<Route path="/profile" element={<Profile />} />




{/* <Route path="/:catogries/:title" element={<ViewComponent />} /> */}

{/* <Route path="/search" element={<Componenets catogreise={"search"} />} /> */}
Expand Down
116 changes: 78 additions & 38 deletions ui_tailwind_shadecn/src/components/custom_ui/OutputComponents.tsx
Original file line number Diff line number Diff line change
@@ -1,60 +1,100 @@
import { ComponentType } from "@/enums/iframEnums";
import { CodeIcon, TailwindCss } from "./Svg";
import { ComponentData } from "@/types/ComponentData.type"
import { ComponentStore } from "@/types/ComponentStore.type";

interface OutputOfComponentsProps {
html?: string;
css?: string;
js?: string;
componentsDetails?: ComponentData;
type?: ComponentType;
mode?: boolean;
isDarkMode?: boolean;
}

const OutputsOfComponents: React.FC<OutputOfComponentsProps> = ({ html, css, js, type, mode }) => {
const backgroundColor = mode === true ? '#1e1e1e' : 'whitesmoke';
const OutputsOfComponents: React.FC<OutputOfComponentsProps> = ({ componentsDetails, type, isDarkMode = false }) => {
const backgroundColor = isDarkMode === true ? '#1e1e1e' : 'whitesmoke';
const fontColor = type === ComponentType.VIEW ? 'white' : "black";
const borderRadius = type === ComponentType.VIEW ? "rounded-l-lg":"rounded-md";
const borderRadius = type === ComponentType.VIEW ? "rounded-l-lg" : "rounded-md";
const iframeContent = `
<html className="bg-primary " style="width: 100%;height: 100%; position: relative;display: ${type === ComponentType.COMPONENTS ? "flex" : ""};align-items: ${type === ComponentType.COMPONENTS ? "center" : ""};justify-content: center;cursor: pointer;z-index: 1; background:${backgroundColor}; color:${fontColor}">
<head>
<style>${css}</style>
<style>${componentsDetails?.css}</style>
</head>
<body>
${html}
<script>${js}</script>
${componentsDetails?.html}
<script>${componentsDetails?.js}</script>
</body>
</html>
`;

return (
<div className="relative group">

{type === ComponentType.COMPONENTS && (
<div className="hidden group-hover:block absolute bottom-0 right-0 p-2">
<div className="flex bg-primary p-1">
<div><CodeIcon /></div>
<div><p className="text-white">Get Code</p></div>
</div>
</div>
)}

{type === ComponentType.COMPONENTS && (
<div className="absolute top-0 left-0 p-2">
<div className="flex bg-primary p-1 rounded-full">
<div><p className="text-white"><TailwindCss /></p></div>
<div><p className="text-white"><TailwindCss /></p></div>
</div>
<>
<div className="relative group">

{type === ComponentType.COMPONENTS && (
<div className="hidden group-hover:block absolute bottom-0 right-0 p-2">
<div className="flex bg-primary p-1">
<div><CodeIcon /></div>
<div><p className="text-white">Get Code</p></div>
</div>
</div>
)}

{type === ComponentType.COMPONENTS && (
<div className="absolute top-0 left-0 p-2">
<div className="flex bg-primary p-1 rounded-full">
<div><p className="text-white"><TailwindCss /></p></div>
<div><p className="text-white"><TailwindCss /></p></div>
</div>
</div>
)}

<iframe
title="output"
srcDoc={iframeContent}
style={{ width: "100%", height: type }}
sandbox="allow-scripts"
className={`transition-opacity duration-300 ${borderRadius}`}
/>
</div>
)}

<iframe
title="output"
srcDoc={iframeContent}
style={{ width: "100%", height: type }}
sandbox="allow-scripts"
className={`transition-opacity duration-300 ${borderRadius}`}
/>
</div>
<a className=" items-center">
<span className="flex justify-between flex-row pt-1">
<span className="title-font font-medium">{componentsDetails?.title}</span>
<span className="title-font font-thin text-gray-200">{componentsDetails?.admin.name}</span>
</span>
</a>
</>


);
};

export default OutputsOfComponents;
const OutputViewComponents: React.FC<ComponentStore> = ({ html, css, js }) => {
const backgroundColor = '#1e1e1e'
const iframe = `
<html className=""style="width: 100%; background:${backgroundColor}; height: 100%; position: relative; justify-content: center;cursor: pointer;z-index: 1;">
<head>
<style>${css}</style>
</head>
<body>
${html}
<script>${js}</script>
</body>
</html>
`;
return (
<>
<div className="relative group">
<iframe
title="output"
srcDoc={iframe}
style={{ width: "100%", height: "500px" }}
sandbox="allow-scripts"
className={`transition-opacity duration-300`}
/>
</div>
</>
)

}

export default OutputsOfComponents;
export { OutputViewComponents };
8 changes: 1 addition & 7 deletions ui_tailwind_shadecn/src/screens/Components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,7 @@ export function Components() {
to={`/${component.catogries}/${component.folder_name}`}
key={index}
>
<div ><OutputsOfComponents html={component.html} css={component.css} js={component.js} type={ComponentType.COMPONENTS} />
<a className=" items-center">
<span className="flex justify-between flex-row pt-1">
<span className="title-font font-medium">{component.title}</span>
<span className="title-font font-thin text-gray-200">{component.admin.name}</span>
</span>
</a>
<div ><OutputsOfComponents componentsDetails={component} type={ComponentType.COMPONENTS} />
</div>
</Link>
</div>
Expand Down
38 changes: 5 additions & 33 deletions ui_tailwind_shadecn/src/screens/Profile/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
import { Input } from "@/components/ui/input"
import { Sheet, SheetContent, SheetTrigger } from "@/components/ui/sheet"
import { Link } from "react-router-dom"
import Icons, { Logo } from "@/components/custom_ui/Svg"
import { Logo } from "@/components/custom_ui/Svg"
import { useCategoriesStore } from "@/store/store"
import { useEffect } from "react"
import { fetchCategories } from "@/api/components/categories"
Expand All @@ -37,34 +37,6 @@ import OutputsOfComponents from "@/components/custom_ui/OutputComponents"
import { ComponentType } from "@/enums/iframEnums"


const images = [
"https://images.unsplash.com/photo-1554080353-a576cf803bda?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=3387&q=80",
"https://images.unsplash.com/photo-1505144808419-1957a94ca61e?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=3070&q=80",
"https://images.unsplash.com/photo-1470252649378-9c29740c9fa8?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=3540&q=80",
"https://images.unsplash.com/photo-1554080353-a576cf803bda?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=3387&q=80",
"https://images.unsplash.com/photo-1505144808419-1957a94ca61e?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=3070&q=80",
"https://images.unsplash.com/photo-1470252649378-9c29740c9fa8?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=3540&q=80",
"https://images.unsplash.com/photo-1682686581854-5e71f58e7e3f?ixlib=rb-4.0.3&ixid=M3wxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=3540&q=80",
"https://images.unsplash.com/photo-1510784722466-f2aa9c52fff6?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=3540&q=80",
"https://images.unsplash.com/photo-1505765050516-f72dcac9c60e?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=3540&q=80",
"https://images.unsplash.com/photo-1439853949127-fa647821eba0?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=2640&q=80",
"https://images.unsplash.com/photo-1554080353-a576cf803bda?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=3387&q=80",
"https://images.unsplash.com/photo-1505144808419-1957a94ca61e?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=3070&q=80",
"https://images.unsplash.com/photo-1470252649378-9c29740c9fa8?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=3540&q=80",
"https://images.unsplash.com/photo-1554080353-a576cf803bda?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=3387&q=80",
"https://images.unsplash.com/photo-1505144808419-1957a94ca61e?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=3070&q=80",
"https://images.unsplash.com/photo-1554080353-a576cf803bda?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=3387&q=80",
"https://images.unsplash.com/photo-1505144808419-1957a94ca61e?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=3070&q=80",
"https://images.unsplash.com/photo-1470252649378-9c29740c9fa8?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=3540&q=80",
"https://images.unsplash.com/photo-1554080353-a576cf803bda?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=3387&q=80",
"https://images.unsplash.com/photo-1505144808419-1957a94ca61e?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=3070&q=80",
"https://images.unsplash.com/photo-1554080353-a576cf803bda?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=3387&q=80",
"https://images.unsplash.com/photo-1505144808419-1957a94ca61e?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=3070&q=80",
"https://images.unsplash.com/photo-1470252649378-9c29740c9fa8?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=3540&q=80",
"https://images.unsplash.com/photo-1554080353-a576cf803bda?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=3387&q=80",
"https://images.unsplash.com/photo-1505144808419-1957a94ca61e?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=3070&q=80",
];

export function Profile() {

// const user = useLoginStore((state) => state.isLogin);
Expand Down Expand Up @@ -287,11 +259,11 @@ export function Profile() {


<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-2 lg:grid-cols-3 gap-4">
<div ><OutputsOfComponents html="Testing" css="Testing" js="testing" type={ComponentType.COMPONENTS} />
<div ><OutputsOfComponents type={ComponentType.COMPONENTS} />
</div>
<div ><OutputsOfComponents html="Testing" css="Testing" js="testing" type={ComponentType.COMPONENTS} /></div>
<div ><OutputsOfComponents html="Testing" css="Testing" js="testing" type={ComponentType.COMPONENTS} /></div>
<div ><OutputsOfComponents html="Testing" css="Testing" js="testing" type={ComponentType.COMPONENTS} /></div>
<div ><OutputsOfComponents type={ComponentType.COMPONENTS} /></div>
<div ><OutputsOfComponents type={ComponentType.COMPONENTS} /></div>
<div ><OutputsOfComponents type={ComponentType.COMPONENTS} /></div>
</div>
</div>
</section>
Expand Down
27 changes: 2 additions & 25 deletions ui_tailwind_shadecn/src/screens/View.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import OutputsOfComponents from "@/components/custom_ui/OutputComponents"
import { OutputViewComponents } from "@/components/custom_ui/OutputComponents"
import {
ResizableHandle,
ResizablePanel,
ResizablePanelGroup,
} from "@/components/ui/resizable"
import { ComponentType } from "@/enums/iframEnums";
// import CodeEditor from '@/components/custom_ui/code_editor/Editor';

import { Button } from "@/components/ui/button"
import { SheetTrigger, SheetContent, Sheet } from "@/components/ui/sheet"
Expand All @@ -16,7 +14,6 @@ import { CircleUser, Layers, Menu, Search, Github } from "lucide-react";
import { LeftArrow, Logo, LogoPlain } from "@/components/custom_ui/Svg";
import MonacoEditorComponent from "@/components/custom_ui/code_editor/CodeEditor";
import { useState } from "react";
import { Switch } from "@/components/ui/switch"
import { useCategoriesStore } from '@/store/store';
import { fetchCategories } from '@/api/components/categories';
import { useEffect } from "react";
Expand All @@ -31,7 +28,6 @@ import { CommandDialogDemo } from "@/components/ui/commandMenu";

export function View() {

const [isSwitchOn, setIsSwitchOn] = useState(true);
const [isSticky, setIsSticky] = useState(false);
const [componentDetails, setComponentDetails] = useState<ComponentStore | null>(null);
type componentParamType = {
Expand All @@ -44,9 +40,6 @@ export function View() {
const defaultCategorie = categorie === null ? "all" : categorie;
const defaultTitle = title === null ? "error" : title;

const handleSwitchToggle = () => {
setIsSwitchOn((prev) => !prev);
};
const fetchComponentDetails = async () => {
try {
const componentStore = await fetchComponentStore(defaultCategorie, defaultTitle);
Expand Down Expand Up @@ -273,9 +266,8 @@ export function View() {
<ResizablePanel>
<div className="relative">
<div className="absolute p-4 right-0 top-0">
<Switch onChange={handleSwitchToggle} />
</div>
<OutputsOfComponents html={componentDetails.html} css={componentDetails.css} js={componentDetails.js} type={ComponentType.VIEW} mode={isSwitchOn} />
<OutputViewComponents html={componentDetails.html} css={componentDetails.css} js={componentDetails.js}/>
</div>
</ResizablePanel>
<ResizableHandle className="px-1" withHandle />
Expand Down Expand Up @@ -340,21 +332,6 @@ export function View() {
</ResizablePanelGroup>

<div className="bg-secondary rounded">
{/* <a className="inline-flex items-center">
<img
alt="blog"
src="https://dummyimage.com/104x104"
className="w-12 h-12 rounded-full flex-shrink-0 object-cover object-center"
/>
<span className="flex-grow flex flex-col pl-4">
<span className="title-font font-medium ">
Holden Caulfield
</span>
<span className=" text-xs tracking-widest mt-0.5">
UI DEVELOPER
</span>
</span>
</a> */}
</div>

<header className=" bg-gray-900 body-font">
Expand Down

0 comments on commit b9e41c1

Please sign in to comment.