generated from lucien/actix-react-template
Chaos Commit
This commit is contained in:
parent
525ce0515c
commit
e1bcb4b022
4 changed files with 107 additions and 0 deletions
10
front/src/components/chaos/MonInput.tsx
Normal file
10
front/src/components/chaos/MonInput.tsx
Normal file
|
@ -0,0 +1,10 @@
|
|||
//import { useState } from "react";
|
||||
|
||||
export default function MonInput({text, new_focus}) {
|
||||
|
||||
return (
|
||||
<div>
|
||||
<input readOnly value={text} onFocus={new_focus}></input>
|
||||
</div>
|
||||
)
|
||||
}
|
19
front/src/components/chaos/monButton.tsx
Normal file
19
front/src/components/chaos/monButton.tsx
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { useState } from "react";
|
||||
|
||||
|
||||
|
||||
export default function MonButton({letter,changetext,sizeFrontw,sizeFronth,rdmFront,color}) {
|
||||
|
||||
|
||||
|
||||
function clicked() {rdmFront();
|
||||
changetext(letter)}
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<div>
|
||||
<button className="key" onClick={clicked} style={{width:sizeFrontw,height:sizeFronth,background:color}}>{letter}</button>
|
||||
</div>
|
||||
)
|
||||
}
|
11
front/src/components/chaos/style.css
Normal file
11
front/src/components/chaos/style.css
Normal file
|
@ -0,0 +1,11 @@
|
|||
#keys {
|
||||
display: grid;
|
||||
grid-template-columns: auto auto 1fr;
|
||||
|
||||
|
||||
}
|
||||
|
||||
.key {
|
||||
font-size: 10px;
|
||||
border: solid black;
|
||||
}
|
67
front/src/pages/ChaosPage.tsx
Normal file
67
front/src/pages/ChaosPage.tsx
Normal file
|
@ -0,0 +1,67 @@
|
|||
import MonButton from "../components/chaos/monButton";
|
||||
import MonInput from "../components/chaos/MonInput";
|
||||
import "../components/chaos/style.css"
|
||||
import { useState } from "react";
|
||||
|
||||
|
||||
export default function ChaosPage(){
|
||||
|
||||
const array_input = [1,2,3,4];
|
||||
const [array_letter,setArray_letter]=useState(["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"," ","!"]);
|
||||
|
||||
const [sizeFrontw,setSizeFrontw] = useState(16)
|
||||
const [sizeFronth,setSizeFronth] = useState(10)
|
||||
const [color,setColor] = useState("#ffffff")
|
||||
|
||||
function randomFront(){setSizeFronth(Math.floor(Math.random() * (1000)));
|
||||
setSizeFrontw(Math.floor(Math.random() * (1000)));
|
||||
setColor(`#${Math.floor(Math.random() * 16777215).toString(16)}`)}
|
||||
|
||||
function shuffleArray(arr) {
|
||||
for (let i = arr.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1)); // Choisir un index aléatoire
|
||||
[arr[i], arr[j]] = [arr[j], arr[i]]; // Échanger les éléments
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
const myArray = [1, 2, 3, 4, 5];
|
||||
const shuffledArray = shuffleArray(myArray);
|
||||
|
||||
console.log(shuffledArray); // Affiche un tableau mélangé
|
||||
|
||||
|
||||
const [entry1,setEntry1] = useState("champ1")
|
||||
function E1(ent:string) {
|
||||
setEntry1(entry1+ent);
|
||||
}
|
||||
const [connarddefocus,setFocus] = useState(()=>E1)
|
||||
|
||||
const [entry2,setEntry2] = useState("champ2")
|
||||
function E2(ent:string) {
|
||||
setEntry2(entry2+ent);
|
||||
}
|
||||
|
||||
function changeFocus(E) {
|
||||
setArray_letter(shuffleArray(array_letter));
|
||||
setFocus(()=>E);
|
||||
}
|
||||
|
||||
|
||||
return(
|
||||
<div>
|
||||
<h1>Chaos Page</h1>
|
||||
<MonInput text={entry1} new_focus={()=>changeFocus(E1)}/>
|
||||
<MonInput text={entry2} new_focus={()=>changeFocus(E2)}/>
|
||||
<div id = "keys">
|
||||
{array_letter.map((letter) => {return <MonButton
|
||||
letter={letter}
|
||||
changetext={connarddefocus}
|
||||
sizeFrontw={sizeFrontw}
|
||||
sizeFronth={sizeFronth}
|
||||
rdmFront={randomFront}
|
||||
color={color}/> })}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue