Skip to content
This repository has been archived by the owner on Dec 23, 2022. It is now read-only.

Commit

Permalink
Allow customizing chips with classes, add a demo that shows how it wo…
Browse files Browse the repository at this point in the history
…rks.

Closes #165
  • Loading branch information
leMaik committed Dec 3, 2017
1 parent a0bc432 commit a8978b5
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 99 deletions.
19 changes: 10 additions & 9 deletions src/ChipInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import FormHelperText from 'material-ui/Form/FormHelperText'
import cx from 'classnames'

const styles = (theme) => ({
root: {},
inputRoot: {
display: 'inline-block',
marginTop: 0
Expand Down Expand Up @@ -99,18 +100,18 @@ const styles = (theme) => ({
backgroundColor: theme.palette.error.A400,
transform: 'scaleX(1)' // error is always underlined in red
}
},
chip: {
margin: '0 8px 8px 0',
float: 'left'
}
})

const defaultChipStyle = {
margin: '0 8px 8px 0',
float: 'left'
}

const defaultChipRenderer = ({ value, text, isFocused, isDisabled, handleClick, handleRequestDelete, defaultStyle }, key) => (
const defaultChipRenderer = ({ value, text, isFocused, isDisabled, handleClick, handleRequestDelete, className }, key) => (
<Chip
key={key}
style={{ ...defaultStyle, pointerEvents: isDisabled ? 'none' : undefined, backgroundColor: isFocused ? blue[300] : undefined }}
className={className}
style={{ pointerEvents: isDisabled ? 'none' : undefined, backgroundColor: isFocused ? blue[300] : undefined }}
onClick={handleClick}
onRequestDelete={handleRequestDelete}
label={text}
Expand Down Expand Up @@ -424,7 +425,7 @@ class ChipInput extends React.Component {
<FormControl
ref={rootRef}
fullWidth={fullWidth}
className={className}
className={cx(className, classes.root)}
error={error}
required={required}
onClick={this.focus}
Expand Down Expand Up @@ -464,7 +465,7 @@ class ChipInput extends React.Component {
isFocused: this.state.focusedChip === i,
handleClick: () => this.setState({ focusedChip: i }),
handleRequestDelete: () => this.handleDeleteChip(value, i),
defaultStyle: defaultChipStyle
className: classes.chip
}, i)
})}
<Input
Expand Down
4 changes: 2 additions & 2 deletions src/ChipInput.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,11 @@ describe('custom chips', () => {
value: 'a',
text: 'a',
chip: 'a',
className: expect.any(String),
isDisabled: false,
isFocused: false,
handleClick: expect.any(Function),
handleRequestDelete: expect.any(Function),
defaultStyle: expect.any(Object)
handleRequestDelete: expect.any(Function)
})
})
})
Loading

0 comments on commit a8978b5

Please sign in to comment.