Skip to content

Commit 8cba4a6

Browse files
committed
feat: accordion
1 parent e16ce1c commit 8cba4a6

File tree

6 files changed

+170
-0
lines changed

6 files changed

+170
-0
lines changed

accordion/App.tsx

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { useState, FC } from "react";
2+
import "./styles.css";
3+
type SectionPropType = {
4+
title: String;
5+
description: String;
6+
isSectionVisible: Boolean;
7+
toggleSection: () => void;
8+
};
9+
const Section: FC<SectionPropType> = ({
10+
title,
11+
description,
12+
isSectionVisible,
13+
toggleSection,
14+
}) => {
15+
return (
16+
<div className="section">
17+
<h2 className="cursor-pointer underline" onClick={() => toggleSection()}>
18+
{title}{" "}
19+
</h2>
20+
{isSectionVisible && <p>{description}</p>}
21+
</div>
22+
);
23+
};
24+
25+
export default function App() {
26+
const [activeSection, setActiveSection] = useState<String>("section1");
27+
return (
28+
<div className="App">
29+
<Section
30+
title={`What is Lorem Ipsum?`}
31+
description={`Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the`}
32+
isSectionVisible={activeSection === "section1"}
33+
toggleSection={() => {
34+
setActiveSection((prev) => (prev == "section1" ? "" : "section1"));
35+
}}
36+
/>
37+
38+
<Section
39+
title={`Why do we use it?`}
40+
description={`Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the`}
41+
isSectionVisible={activeSection === "section2"}
42+
toggleSection={() => {
43+
setActiveSection((prev) => (prev == "section2" ? "" : "section2"));
44+
}}
45+
/>
46+
47+
<Section
48+
title={`Where can I get some?`}
49+
description={`Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the`}
50+
isSectionVisible={activeSection === "section3"}
51+
toggleSection={() => {
52+
setActiveSection((prev) => (prev == "section3" ? "" : "section3"));
53+
}}
54+
/>
55+
</div>
56+
);
57+
}

accordion/index.html

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta
6+
name="viewport"
7+
content="width=device-width, initial-scale=1, shrink-to-fit=no"
8+
/>
9+
<meta name="theme-color" content="#000000" />
10+
<!--
11+
manifest.json provides metadata used when your web app is added to the
12+
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
13+
-->
14+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
15+
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
16+
<!--
17+
Notice the use of %PUBLIC_URL% in the tags above.
18+
It will be replaced with the URL of the `public` folder during the build.
19+
Only files inside the `public` folder can be referenced from the HTML.
20+
21+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
22+
work correctly both with client-side routing and a non-root public URL.
23+
Learn how to configure a non-root public URL by running `npm run build`.
24+
-->
25+
<title>React App</title>
26+
</head>
27+
28+
<body>
29+
<noscript> You need to enable JavaScript to run this app. </noscript>
30+
<div id="root"></div>
31+
<!--
32+
This HTML file is a template.
33+
If you open it directly in the browser, you will see an empty page.
34+
35+
You can add webfonts, meta tags, or analytics to this file.
36+
The build step will place the bundled scripts into the <body> tag.
37+
38+
To begin the development, run `npm start` or `yarn start`.
39+
To create a production bundle, use `npm run build` or `yarn build`.
40+
-->
41+
</body>
42+
</html>

accordion/index.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from "react";
2+
import ReactDOM from "react-dom/client";
3+
import App from "./App";
4+
const rootElement = document.getElementById("root")!;
5+
const root = ReactDOM.createRoot(rootElement);
6+
7+
root.render(
8+
<React.StrictMode>
9+
<App />
10+
</React.StrictMode>
11+
);

accordion/package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "react-typescript",
3+
"version": "1.0.0",
4+
"description": "React and TypeScript example starter project",
5+
"keywords": ["typescript", "react", "starter"],
6+
"main": "src/index.tsx",
7+
"dependencies": {
8+
"loader-utils": "3.2.1",
9+
"react": "18.2.0",
10+
"react-dom": "18.2.0",
11+
"react-scripts": "5.0.1"
12+
},
13+
"devDependencies": {
14+
"@types/react": "18.2.37",
15+
"@types/react-dom": "18.2.15",
16+
"@typescript-eslint/eslint-plugin": "^6.9.1",
17+
"@typescript-eslint/parser": "^6.9.1",
18+
"eslint": "^8.52.0",
19+
"eslint-plugin-react": "^7.33.2",
20+
"eslint-plugin-react-hooks": "^4.6.0",
21+
"eslint-plugin-react-refresh": "^0.4.4",
22+
"typescript": "4.4.2"
23+
},
24+
"scripts": {
25+
"start": "react-scripts start",
26+
"build": "react-scripts build",
27+
"test": "react-scripts test --env=jsdom",
28+
"eject": "react-scripts eject"
29+
},
30+
"browserslist": [">0.2%", "not dead", "not ie <= 11", "not op_mini all"]
31+
}

accordion/styles.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.App {
2+
font-family: sans-serif;
3+
text-align: center;
4+
}
5+
.section {
6+
border: 1px solid;
7+
padding: 5px;
8+
margin: 5px;
9+
}
10+
.cursor-pointer {
11+
cursor: pointer;
12+
}
13+
.underline {
14+
text-decoration: underline;
15+
}

accordion/tsconfig.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"include": [
3+
"./src/**/*"
4+
],
5+
"compilerOptions": {
6+
"strict": true,
7+
"esModuleInterop": true,
8+
"lib": [
9+
"dom",
10+
"es2015"
11+
],
12+
"jsx": "react-jsx"
13+
}
14+
}

0 commit comments

Comments
 (0)