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`}>
<form
onSubmit={(e)=>{
e.preventDefault()
props.onPressed?.(name)
setName("")
setShow(false)
}}>
<input <input
type="text" type="text"
onChange={(e)=>{ onChange={(e)=>setName(e.target.value)}
setName(e.target.value)
}}
value={name} value={name}
ref={input}
onBlur={()=>{
setShow(false)
setName("")
}}
/> />
<button {/* <button
onClick={()=>{ onClick={()=>{
props.onPressed?.(name) props.onPressed?.(name)
setName("") setName("")
setShow(false)
}} }}
> >
Create Create
</button> </button> */}
</form>
</div> </div>
</div> </div>
) )