create dir button layout

This commit is contained in:
Niklas 2021-08-20 17:02:18 +02:00
parent b8f9fbf73a
commit 5256da3631

View File

@ -1,4 +1,5 @@
import React from "react" import React, { useRef } from "react"
import { useEffect } from "react"
import { useState } from "react" import { useState } from "react"
interface Props { interface Props {
@ -8,28 +9,53 @@ interface Props {
const CreateDirButton: React.FC<Props> = (props) => { const CreateDirButton: React.FC<Props> = (props) => {
const [name,setName] = useState("") const [name,setName] = useState("")
const [show,setShow] = useState(false)
const input = useRef<HTMLInputElement>(null)
useEffect(()=>{
if(show){
input.current?.focus()
}
},[show])
return ( return (
<div> <div>
<button> <button
onClick={()=>{
setShow(!show)
}}
>
Create Dir Create Dir
</button> </button>
<div> <div className={`${!show?"hidden":""} flex`}>
<input <form
type="text" onSubmit={(e)=>{
onChange={(e)=>{ e.preventDefault()
setName(e.target.value)
}}
value={name}
/>
<button
onClick={()=>{
props.onPressed?.(name) props.onPressed?.(name)
setName("") setName("")
}} setShow(false)
> }}>
Create <input
</button> type="text"
onChange={(e)=>setName(e.target.value)}
value={name}
ref={input}
onBlur={()=>{
setShow(false)
setName("")
}}
/>
{/* <button
onClick={()=>{
props.onPressed?.(name)
setName("")
setShow(false)
}}
>
Create
</button> */}
</form>
</div> </div>
</div> </div>
) )