Add button that removes an image (#134)

* Add button that removes an image

* Make remove button 100% width

The calc + 2px is to account for inconsistency with the other inputs
and selectors which appear to be 2px wider than 100% (presumably from
border)

* Make splice/filter operation clearer

The array has to be spread before filtering.
This is for the case where only a later image has a defined width/height
In those cases the width/height array would be defined as [4: 350]
for example.
Filtering on that array would give unexpected result.
The spreading creates the full array and then filters correctly.

Co-authored-by: Steven <steven@ceriously.com>
This commit is contained in:
Ben Spinks 2020-08-27 15:55:33 +01:00 committed by GitHub
parent 6708a95f33
commit 9b185b0107
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -73,7 +73,7 @@ button {
line-height: 0;
height: 24px;
width: 100px;
width: calc(100% + 2px);
padding: 0 10px;
font-size: 12px;
background: #fff;

View File

@ -355,6 +355,20 @@ const App = (_: any, state: AppState, setState: SetState) => {
setLoadingState({ heights: clone });
}
})
),
H('div',
{ className: 'field-flex' },
H(Button, {
label: `Remove Image ${i + 2}`,
onclick: (e: MouseEvent) => {
e.preventDefault();
const filter = (arr: any[]) => [...arr].filter((_, n) => n !== i + 1);
const imagesClone = filter(images);
const widthsClone = filter(widths);
const heightsClone = filter(heights);
setLoadingState({ images: imagesClone, widths: widthsClone, heights: heightsClone });
}
})
)
)
})),