//
// SPDX-License-Identifier: AGPL-3.0
-import * as React from 'react';
+import React from 'react';
import { Chip, Grid, StyleRulesCallback, withStyles } from '@material-ui/core';
-import { DragSource, DragSourceSpec, DragSourceCollector, ConnectDragSource, DropTarget, DropTargetSpec, DropTargetCollector, ConnectDropTarget } from 'react-dnd';
+import {
+ DragSource,
+ DragSourceSpec,
+ DragSourceCollector,
+ ConnectDragSource,
+ DropTarget,
+ DropTargetSpec,
+ DropTargetCollector,
+ ConnectDropTarget
+} from 'react-dnd';
import { compose } from 'lodash/fp';
import { WithStyles } from '@material-ui/core/styles';
interface ChipsProps<Value> {
render() {
const { values, filler } = this.props;
return <Grid container spacing={8} className={this.props.classes.root}>
- {values.map(this.renderChip)}
+ {values && values.map(this.renderChip)}
{filler && <Grid item xs>{filler}</Grid>}
</Grid>;
}
- renderChip = (value: Value, index: number) =>
- <Grid item key={index}>
- <this.chip {...{ value }} />
+ renderChip = (value: Value, index: number) => {
+ const { deletable, getLabel } = this.props;
+ return <Grid item key={index}>
+ <Chip onDelete={deletable ? this.deleteValue(value) : undefined}
+ label={getLabel !== undefined ? getLabel(value) : value} />
</Grid>
+ }
type = 'chip';
interface DraggableChipProps<Value> {
value: Value;
-}
\ No newline at end of file
+}