-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e4fadf9
commit c176b48
Showing
5 changed files
with
332 additions
and
452 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
const { Tile } = | ||
VM.require("${REPL_DEVHUB}/widget/devhub.components.molecule.Tile") || | ||
(() => <></>); | ||
|
||
const { data, setList, validate, invalidate } = props; | ||
|
||
const [newItem, setNewItem] = useState(""); | ||
|
||
const handleAddItem = () => { | ||
if (validate(newItem)) { | ||
setList([...data.list, newItem]); | ||
setNewItem(""); | ||
} else { | ||
return invalidate(); | ||
} | ||
}; | ||
|
||
const handleDeleteItem = (index) => { | ||
const updatedData = [...data.list]; | ||
updatedData.splice(index, 1); | ||
setList(updatedData); | ||
}; | ||
|
||
const Item = styled.div` | ||
padding: 10px; | ||
margin: 5px; | ||
display: flex; | ||
align-items: center; | ||
flex-direction: row; | ||
gap: 10px; | ||
`; | ||
|
||
return ( | ||
<> | ||
{data.list.map((item, index) => ( | ||
<Item key={index}> | ||
<div className="flex-grow-1"> | ||
<Widget | ||
src="${REPL_DEVHUB}/widget/devhub.components.molecule.Input" | ||
props={{ | ||
className: "flex-grow-1", | ||
value: item, | ||
skipPaddingGap: true, | ||
placeholder: data.placeholder, | ||
inputProps: { | ||
prefix: data.prefix, | ||
disabled: true, | ||
}, | ||
}} | ||
/> | ||
</div> | ||
<button | ||
className="btn btn-outline-danger" | ||
onClick={() => handleDeleteItem(index)} | ||
> | ||
<i className="bi bi-trash-fill" /> | ||
</button> | ||
</Item> | ||
))} | ||
{data.list.length < data.maxLength && ( | ||
<Item> | ||
<div className="flex-grow-1"> | ||
<Widget | ||
src="${REPL_DEVHUB}/widget/devhub.components.molecule.Input" | ||
props={{ | ||
className: "flex-grow-1", | ||
skipPaddingGap: true, | ||
onChange: (e) => setNewItem(e.target.value), | ||
value: newItem, | ||
placeholder: data.placeholder, | ||
inputProps: { | ||
prefix: data.prefix, | ||
}, | ||
}} | ||
/> | ||
</div> | ||
<button | ||
className="btn btn-success add-member" | ||
onClick={handleAddItem} | ||
disabled={newItem === ""} | ||
> | ||
<i className="bi bi-plus" /> | ||
</button> | ||
</Item> | ||
)} | ||
</> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.