Skip to content

react instruction board added #160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions instructions-board/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
50 changes: 50 additions & 0 deletions instructions-board/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
export default tseslint.config({
languageOptions: {
// other options...
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
})
```

- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked`
- Optionally add `...tseslint.configs.stylisticTypeChecked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config:

```js
// eslint.config.js
import react from 'eslint-plugin-react'

export default tseslint.config({
// Set the react version
settings: { react: { version: '18.3' } },
plugins: {
// Add the react plugin
react,
},
rules: {
// other rules...
// Enable its recommended rules
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
},
})
```
28 changes: 28 additions & 0 deletions instructions-board/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'

export default tseslint.config(
{ ignores: ['dist'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
)
13 changes: 13 additions & 0 deletions instructions-board/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
30 changes: 30 additions & 0 deletions instructions-board/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "instructions-board",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-icons": "^5.3.0"
},
"devDependencies": {
"@eslint/js": "^9.15.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@vitejs/plugin-react": "^4.3.4",
"eslint": "^9.15.0",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.14",
"globals": "^15.12.0",
"typescript": "~5.6.2",
"typescript-eslint": "^8.15.0",
"vite": "^6.0.1"
}
}
1 change: 1 addition & 0 deletions instructions-board/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added instructions-board/src/App.css
Empty file.
16 changes: 16 additions & 0 deletions instructions-board/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useState } from "react";

import "./App.css";
import InstructionBoard from "./components/InstructionBoard";

function App() {
const [count, setCount] = useState(0);

return (
<>
<InstructionBoard />
</>
);
}

export default App;
1 change: 1 addition & 0 deletions instructions-board/src/assets/react.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
82 changes: 82 additions & 0 deletions instructions-board/src/components/InstructionBoard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import React, { useState } from "react";
import { AiFillCaretUp, AiFillCaretDown } from "react-icons/ai";
import "./InstructionStyle.css";

interface Instruction {
id: number;
instruction: string;
}

const InstructionBoard = () => {
const [instructions, setInstructions] = useState<Instruction[]>([]);
const [newInstruction, setNewInstruction] = useState<string>("");

const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setNewInstruction(e.target.value);
};

const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
if (newInstruction) {
setInstructions((prev) => [
...prev,
{
id: prev.length ? prev[prev.length - 1].id + 1 : 1,
instruction: newInstruction,
},
]);
setNewInstruction("");
}
};

const moveUp = (id: number) => {
if (id > 0) {
const updated = [...instructions];
[updated[id - 1], updated[id]] = [updated[id], updated[id - 1]];
setInstructions(updated);
}
};

const moveDown = (id: number) => {
if (id < instructions.length - 1) {
const updated = [...instructions];
[updated[id + 1], updated[id]] = [updated[id], updated[id + 1]];
setInstructions(updated);
}
};

return (
<div className="container">
<form className="main-section" onSubmit={handleSubmit}>
<input
type="text"
value={newInstruction}
onChange={handleChange}
placeholder="Enter new instruction"
/>
<button type="submit">Add Instruction</button>
</form>
{instructions.length > 0 && (
<div className="items-section">
<ul>
{instructions.map((item, index) => (
<li className="items" key={item.id}>
<span className="instruction-text">{item.instruction}</span>
<div className="icons">
<span onClick={() => moveDown(index)}>
<AiFillCaretDown />
</span>
<span onClick={() => moveUp(index)}>
<AiFillCaretUp />
</span>
</div>
</li>
))}
</ul>
</div>
)}
</div>
);
};

export default InstructionBoard;
129 changes: 129 additions & 0 deletions instructions-board/src/components/InstructionStyle.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/* Base styles for the container */
.container {
width: 100%;
max-width: 1000px;
background-color: #f5f5f5;
margin: 0 auto;
padding: 2rem;
display: flex;
flex-direction: column;
align-items: center;
}

/* Main input and button form */
.main-section {
width: 100%;
display: flex;
justify-content: center;
gap: 1rem;
margin-bottom: 2rem;
}

.main-section input {
width: 60%;
padding: 1rem;
border: 1px solid #ddd;
border-radius: 5px;
font-size: 1rem;
outline: none;
transition: border-color 0.3s ease;
}

.main-section input:focus {
border-color: #5d9bfa;
}

.main-section button {
padding: 1rem 2rem;
border: none;
border-radius: 5px;
background-color: #5d9bfa;
color: white;
font-size: 1rem;
cursor: pointer;
transition: background-color 0.3s ease;
}

.main-section button:hover {
background-color: #4a7ecf;
}

/* Instruction list and icons */
.items-section {
width: 100%;
background-color: #fff;
padding: 1rem;
border-radius: 5px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.items {
display: flex;
justify-content: space-between;
align-items: center;
background-color: #f9f9f9;
padding: 0.8rem;
margin-bottom: 1rem;
border-radius: 5px;
}

.instruction-text {
flex: 1;
font-size: 1.1rem;
color: #333;
}

.icons {
display: flex;
gap: 1rem;
}

.icons span {
font-size: 1.5rem;
cursor: pointer;
color: #5d9bfa;
transition: color 0.3s ease;
}

.icons span:hover {
color: #4a7ecf;
}

/* Responsive Design */
@media (max-width: 768px) {
.container {
padding: 1rem;
}

.main-section {
flex-direction: column;
gap: 0.5rem;
}

.main-section input {
width: 100%;
}

.main-section button {
width: 100%;
}

.items-section {
width: 100%;
}

.items {
flex-direction: column;
align-items: flex-start;
}

.icons {
flex-direction: row;
justify-content: flex-start;
}

.instruction-text {
font-size: 1rem;
margin-bottom: 0.5rem;
}
}
5 changes: 5 additions & 0 deletions instructions-board/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
Loading