parent
52865497cd
commit
c8a39c9224
7 changed files with 213 additions and 77 deletions
@ -0,0 +1,23 @@ |
||||
import React, { useState } from 'react'; |
||||
import { TextField } from '@material-ui/core'; |
||||
|
||||
export default function MenuEditText(props: { |
||||
label: string, |
||||
onSubmit: (s: string) => void, |
||||
}) { |
||||
const [input, setInput] = useState(""); |
||||
|
||||
return <TextField |
||||
label={props.label} |
||||
variant="outlined" |
||||
value={input} |
||||
onChange={(e: any) => setInput(e.target.value)} |
||||
onKeyDown={(e: any) => { |
||||
if (e.key === 'Enter') { |
||||
// User submitted free-form value.
|
||||
props.onSubmit(input); |
||||
e.preventDefault(); |
||||
} |
||||
}} |
||||
/> |
||||
} |
@ -0,0 +1,54 @@ |
||||
import React, { useState } from 'react'; |
||||
import { Menu, MenuItem, TextField, Input } from '@material-ui/core'; |
||||
import NestedMenuItem from "material-ui-nested-menu-item"; |
||||
import MenuEditText from '../../common/MenuEditText'; |
||||
|
||||
export function PickCreateTag(props: { |
||||
tags: any[], |
||||
open: boolean, |
||||
parentId: string | null, |
||||
onCreate: (name: string, parentId: string | null) => void, |
||||
}) { |
||||
|
||||
return <> |
||||
<MenuEditText |
||||
label="Name" |
||||
onSubmit={(s: string) => { |
||||
props.onCreate(s, props.parentId); |
||||
}} |
||||
/> |
||||
{props.tags.map((tag: any) => { |
||||
return <NestedMenuItem |
||||
parentMenuOpen={props.open} |
||||
label={tag.name} |
||||
> |
||||
<PickCreateTag tags={tag.children} open={props.open} parentId={tag.tagId} onCreate={props.onCreate} /> |
||||
</NestedMenuItem> |
||||
})} |
||||
</> |
||||
} |
||||
|
||||
export default function NewTagMenu(props: { |
||||
position: null | number[], |
||||
open: boolean, |
||||
onCreate: (name: string, parentId: string | null) => void, |
||||
onClose: () => void, |
||||
changedTags: any[], // Tags organized hierarchically with "children" fields
|
||||
}) { |
||||
const pos = props.open && props.position ? |
||||
{ left: props.position[0], top: props.position[1] } |
||||
: { left: 0, top: 0 } |
||||
|
||||
return <Menu |
||||
open={props.open} |
||||
anchorReference="anchorPosition" |
||||
anchorPosition={pos} |
||||
keepMounted |
||||
onClose={props.onClose} |
||||
> |
||||
<PickCreateTag tags={props.changedTags} open={props.open} parentId={null} onCreate={(n: string, v: string | null) => { |
||||
props.onClose(); |
||||
props.onCreate(n, v); |
||||
}} /> |
||||
</Menu> |
||||
} |
Loading…
Reference in new issue