Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make previewChips use the grid system as well #173

Merged
merged 2 commits into from
Jun 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/components/DropzoneArea.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,30 @@ const handlePreviewIcon = (fileObject, classes) => {
getPreviewIcon={handlePreviewIcon}
/>
```
### Using chips for preview

Chips use the Grid system as well, so you can customize the way they appears and benefit from the Material-UI grid customizations

```jsx
import * as React from 'react';
import { createStyles, makeStyles, Theme } from '@material-ui/core/styles';

const useStyles = makeStyles((theme: Theme) => createStyles({
previewChip: {
minWidth: 160,
maxWidth: 210
}
}),
)

const classes = useStyles()

<DropzoneArea
showPreviews={true}
showPreviewsInDropzone={false}
useChipsForPreview
previewGridProps={{container: { spacing: 1, direction: 'row' }}}
previewChipProps={{classes: { root: classes.previewChip } }}
previewText="Selected files"
/>
```
35 changes: 25 additions & 10 deletions src/components/PreviewList.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,31 @@ function PreviewList({
}) {
if (useChipsForPreview) {
return (
fileObjects.map((fileObject, i) => (
<div key={i}>
<Chip
variant="outlined"
{...previewChipProps}
label={fileObject.file.name}
onDelete={handleRemove(i)}
/>
</div>
))
<Grid
spacing: 1
direction: 'row'
{...previewGridProps.container}
panz3r marked this conversation as resolved.
Show resolved Hide resolved
container={true}
className={clsx(classes.root, previewGridClasses.container)}
panz3r marked this conversation as resolved.
Show resolved Hide resolved
>
{fileObjects.map((fileObject, i) => {
return (
<Grid
{...previewGridProps.item}
panz3r marked this conversation as resolved.
Show resolved Hide resolved
item={true}
key={`${fileObject.file?.name ?? 'file'}-${i}`}
className={classes.imageContainer}
>
<Chip
variant="outlined"
{...previewChipProps}
label={fileObject.file.name}
onDelete={handleRemove(i)}
/>
</Grid>
);
})}
</Grid>
);
}

Expand Down