Skip to content

Commit

Permalink
feat: tab 버튼 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
JaeHyup0504 committed Apr 26, 2024
1 parent dda4572 commit 5290549
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 63 deletions.
47 changes: 37 additions & 10 deletions src/components/Common/Tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,50 @@
import React, { ReactNode } from "react";
import React, { Children } from "react";
import clsx from "clsx";

interface TabsProps {
children: ReactNode;
children?: React.ReactNode;
value: string | undefined;
onClick?: (value: string | undefined) => void;
}

export const Tabs = ({ children }: TabsProps) => {
return <div className="w-full min-h-[30px] flex flex-row gap-[40px]">{children}</div>;
interface TabProps extends TabsProps {
selectedTab?: string | undefined;
}

export const Tabs = ({ children, onClick, value }: TabsProps) => {
return (
<div className="w-full min-h-[30px] flex flex-row gap-[40px] mx-[10px]">
{Children.toArray(children).map((child, idx) => (
<Tab
key={idx}
selectedTab={value}
value={(child as React.ReactElement<TabProps>).props.value}
onClick={onClick}
/>
))}
</div>
);
};

interface TabProps {
children: ReactNode;
value: string;
}
export const Tab = ({ value, selectedTab, onClick }: TabProps) => {
const handleClick = () => {
onClick && onClick(value);
};
const boolean = value === selectedTab;

export const Tab = ({ children, value }: TabProps) => {
return (
<>
<div className="h-full w-auto cursor-pointer text-textSecondary flex items-center">{children}</div>
<div onClick={handleClick} className="h-full w-auto cursor-pointer flex items-center">
<p
className={clsx("mb-0", {
"text-textBlue": boolean,
"font-semibold": boolean,
"text-textSecondary": !boolean,
})}
>
{value}
</p>
</div>
</>
);
};
58 changes: 28 additions & 30 deletions src/components/Editor/Components/AutoForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import { Add } from "@carbon/icons-react";
import clsx from "clsx";

interface List {
title: string,
placeholder: string
title: string;
placeholder: string;
}

const AutoForm = () => {
const formList: List[] = [
{title : "프로젝트 제목", placeholder: "프로젝트 제목을 입력해주세요."},
];
const formList: List[] = [{ title: "프로젝트 제목", placeholder: "프로젝트 제목을 입력해주세요." }];

return (
<div className="w-full h-full max-h-full rounded-[8px] border-solid border border-textTertiary p-[20px] flex flex-col gap-[30px]">
Expand All @@ -20,42 +18,42 @@ const AutoForm = () => {
<p className="text-textSecondary">
GitHub 링크를 통해 ChatGPT가
<br />
Readme를 대신 써드립니다
Readme를 대신 써드립니다
</p>
</div>
<div className={clsx(
"h-full flex flex-col gap-[30px] px-[10px] overflow-scroll",
)}>
<div className={clsx("h-full flex flex-col gap-[30px] px-[10px] overflow-scroll")}>
<div className="w-full h-[70px]">
<p className="text-textPrimary mb-[10px] ml-[10px]">GitHub 링크 <RequiredDot/></p>
<input type="text" className="w-full h-[45px] p-[10px] rounded-[8px] border-solid border border-[#DEE2E6]" placeholder="GitHub 링크를 입력해주세요."></input>
<p className="text-textPrimary mb-[10px] ml-[10px]">
GitHub 링크 <RequiredDot />
</p>
<input
type="text"
className="w-full h-[45px] p-[10px] rounded-[8px] border-solid border border-[#DEE2E6]"
placeholder="GitHub 링크를 입력해주세요."
></input>
</div>
{
formList?.map(({title, placeholder}) => (
<div className="w-full h-[70px]" key={title}>
<p className="text-textPrimary mb-[10px] ml-[10px]">{title}</p>
<input
type="text"
className="w-full h-[45px] p-[10px] rounded-[8px] border-solid border border-[#DEE2E6]"
placeholder={placeholder}
/>
</div>
))
}
{formList?.map(({ title, placeholder }) => (
<div className="w-full h-[70px]" key={title}>
<p className="text-textPrimary mb-[10px] ml-[10px]">{title}</p>
<input
type="text"
className="w-full h-[45px] p-[10px] rounded-[8px] border-solid border border-[#DEE2E6]"
placeholder={placeholder}
/>
</div>
))}
</div>
<div className="w-full min-h-[40px] cursor-pointer flex justify-center" onClick={() => alert("추가 버튼")}>
<Add size={40} className="fill-textBlue"/>
<Add size={40} className="fill-textBlue" />
</div>
<div className="w-full flex flex-row min-h-[45px] gap-[20px] px-[10px]">
<button className="w-1/2 rounded-[8px] border-solid border border-textTertiary text-textPrimary">
Cancle
</button>
<button className="w-1/2 rounded-[8px] bg-textBlue text-white">
Create
<button className="w-1/2 rounded-[8px] border-solid border border-textTertiary text-textPrimary hover:bg-gray-50">
Cancle
</button>
<button className="w-1/2 rounded-[8px] bg-textBlue text-white hover:bg-[#6E9EFF]">Create</button>
</div>
</div>
);
};

export default AutoForm;
export default AutoForm;
16 changes: 8 additions & 8 deletions src/components/Editor/EditorPreviewContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@ import Raw from "./Components/Raw";
import { Tab, Tabs } from "../Common/Tabs";

const EditorPreviewContainer = () => {
const [selectedTab, setSelectedTab] = useState<string | undefined>("preivew");
const [selectedTab, setSelectedTab] = useState<string | undefined>("Preview");

const onChange = (value?: string) => {
const handleTabClick = (value?: string | undefined) => {
setSelectedTab(value);
};

return (
<>
<div className="w-1/2">
<div className="w-full h-full flex flex-col gap-[10px]">
<div className="min-h-[30px] mx-[15px] flex items-center">
<div className="min-h-[30px] mx-[10px] flex items-center">
<p className="text-textBlue font-semibold mb-0">Edior</p>
</div>
<Editor />
</div>
</div>
<div className="w-1/2">
<div className="w-full h-full flex flex-col gap-[10px]">
<Tabs>
<Tab value="preview">Preview</Tab>
<Tab value="raw">Raw</Tab>
<Tabs value={selectedTab} onClick={handleTabClick}>
<Tab value="Preview">Preview</Tab>
<Tab value="Raw">Raw</Tab>
</Tabs>
{selectedTab === "preivew" && <Preview />}
{selectedTab === "raw" && <Raw />}
{selectedTab === "Preview" && <Preview />}
{selectedTab === "Raw" && <Raw />}
</div>
</div>
</>
Expand Down
22 changes: 16 additions & 6 deletions src/components/Editor/SectionsContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
import React from "react";
import { Tab, Tabs } from "components/Common/Tabs";
import React, { useState } from "react";
import Auto from "./Components/Auto";
import Builder from "./Components/Builder";


const SectionsContainer = () => {
const [selectedTab, setSelectedTab] = useState<string | undefined>("Builder");

const handleTabClick = (value?: string | undefined) => {
setSelectedTab(value);
};

return (
<div className="w-full h-full flex flex-col gap-[10px]">
<div className="min-h-[30px] mx-[15px] flex items-center">
<Tabs value={selectedTab} onClick={handleTabClick}>
<Tab value="Builder">Builder</Tab>
<Tab value="Auto">Auto</Tab>
</Tabs>
<div className="w-full h-full flex flex-col gap-[10px]">
{selectedTab === "Builder" && <Builder />}
{selectedTab === "Auto" && <Auto />}
</div>
{/* <Auto/> */}
<Builder/>
</div>
);
};

export default SectionsContainer;
export default SectionsContainer;
24 changes: 15 additions & 9 deletions src/pages/builder/ReadmeBuilder.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import Header from "common/Header/Header";
import React from "react";
import EditorPreviewContainer from "../../components/Editor/EditorPreviewContainer";
import SectionsContainer from "../../components/Editor/SectionsContainer";

const ReadmeBuilder = () => {
return (
<div className="w-full h-[calc(100%_-_64px)]">
<div className="max-w-full h-full p-[35px] flex flex-row gap-[30px]">
<div className="max-w-[400px] w-full h-full">
<SectionsContainer/>
<div className="w-full h-full flex flex-col">
<div className="h-[80px] flex-Center">
<Header />
</div>
<div className="w-full h-[calc(100%_-_64px)]">
<div className="max-w-full h-full p-[30px] pt-[20px] flex flex-row gap-[30px]">
<div className="max-w-[400px] w-full h-full">
<SectionsContainer />
</div>
<div className="max-w-full w-full h-full flex flex-row gap-[30px]">
<EditorPreviewContainer />
</div>
</div>
<div className="max-w-full w-full h-full flex flex-row gap-[30px]">
<EditorPreviewContainer/>
</div>
</div>
</div>
</div>
);
};

export default ReadmeBuilder;
export default ReadmeBuilder;

0 comments on commit 5290549

Please sign in to comment.