mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-03 06:12:51 +00:00
Add click handler for readTags to open text input
Clicking on a readTag now converts that tag to a text input, and maintains the tag value. It also closes any other open text inputs amongst the tags (but leaves the "new tag" input open).
This commit is contained in:
@@ -7,13 +7,26 @@ const TagInput = ({unique = true, values = [], ...props})=>{
|
|||||||
const [temporaryValue, setTemporaryValue] = useState('');
|
const [temporaryValue, setTemporaryValue] = useState('');
|
||||||
const [valueContext, setValueContext] = useState(values.map((value)=>({ value: value, editing : false })));
|
const [valueContext, setValueContext] = useState(values.map((value)=>({ value: value, editing : false })));
|
||||||
|
|
||||||
const readTag = (value)=>{
|
|
||||||
|
const editTag = (evt)=>{
|
||||||
|
setValueContext(valueContext.map((context)=>{
|
||||||
|
context.editing = context.value === evt.target.dataset.value ? true : false;
|
||||||
|
return context;
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
const renderReadTag = (value)=>{
|
||||||
return (
|
return (
|
||||||
<div className={`tag`}>{value}</div>
|
<div key={value}
|
||||||
|
data-value={value}
|
||||||
|
className={`tag`}
|
||||||
|
onClick={(evt)=>editTag(evt)}>
|
||||||
|
{value}
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const writeTag = (value)=>{
|
const renderWriteTag = (value)=>{
|
||||||
return (
|
return (
|
||||||
<input type='text' value={value} />
|
<input type='text' value={value} />
|
||||||
)
|
)
|
||||||
@@ -25,7 +38,7 @@ const TagInput = ({unique = true, values = [], ...props})=>{
|
|||||||
<label>{props.label}</label>
|
<label>{props.label}</label>
|
||||||
<div className='list'>
|
<div className='list'>
|
||||||
|
|
||||||
{Object.values(valueContext).map((context, i)=>{ return context.editing ? writeTag(context.value) : readTag(context.value) })}
|
{Object.values(valueContext).map((context, i)=>{ return context.editing ? renderWriteTag(context.value) : renderReadTag(context.value) })}
|
||||||
|
|
||||||
<input type='text'
|
<input type='text'
|
||||||
className={`value`}
|
className={`value`}
|
||||||
|
|||||||
Reference in New Issue
Block a user