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

Commit

Permalink
Update for material-ui 1.0.0-beta.24 and rename props to match the br…
Browse files Browse the repository at this point in the history
…eaking change over there.

Closes #170
  • Loading branch information
leMaik committed Dec 19, 2017
1 parent c4b8a6f commit 4275625
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 133 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ import ChipInput from 'material-ui-chip-input'
// controlled input
<ChipInput
value={yourChips}
onRequestAdd={(chip) => handleAddChip(chip)}
onRequestDelete={(chip, index) => handleDeleteChip(chip, index)}
onAdd={(chip) => handleAddChip(chip)}
onDelete={(chip, index) => handleDeleteChip(chip, index)}
/>
```

## Properties
| Name | Type | Default | Description |
| --- | --- | --- | --- |
| allowDuplicates | `bool` | `false` | Allows duplicate chips if set to true. |
| chipRenderer | `function` | | A function of the type `({ value, text, chip, isFocused, isDisabled, handleClick, handleRequestDelete, className }, key) => node` that returns a chip based on the given properties. This can be used to customize chip styles. Each item in the `dataSource` array will be passed to `chipRenderer` as arguments `chip`, `value` and `text`. If `dataSource` is an array of objects and `dataSourceConfig` is present, then `value` and `text` will instead correspond to the object values defined in `dataSourceConfig`. If `dataSourceConfig` is not set and `dataSource` is an array of objects, then a custom `chipRenderer` must be set. `chip` is always the raw value from `dataSource`, either an object or a string.|
| chipRenderer | `function` | | A function of the type `({ value, text, chip, isFocused, isDisabled, handleClick, handleDelete, className }, key) => node` that returns a chip based on the given properties. This can be used to customize chip styles. Each item in the `dataSource` array will be passed to `chipRenderer` as arguments `chip`, `value` and `text`. If `dataSource` is an array of objects and `dataSourceConfig` is present, then `value` and `text` will instead correspond to the object values defined in `dataSourceConfig`. If `dataSourceConfig` is not set and `dataSource` is an array of objects, then a custom `chipRenderer` must be set. `chip` is always the raw value from `dataSource`, either an object or a string.|
| classes | `object` | | Extends the styles applied to this component. |
| clearOnBlur | `bool` | `true` | If true, clears the input value after the component loses focus. |
| dataSource | `array` | | Data source for auto complete. This should be an array of strings or objects.|
Expand All @@ -50,11 +50,11 @@ import ChipInput from 'material-ui-chip-input'
| fullWidthInput | `bool` | `false` | If true, the input field will always be below the chips and fill the available space. By default, it will try to be beside the chips. |
| label | `node` | | The content of the floating label. |
| newChipKeyCodes | `number[]` | `[13]` (enter key) | The key codes used to determine when to create a new chip. |
| onBeforeRequestAdd | `function` | | Callback function that is called with the chip to be added and should return true to add the chip or false to prevent the chip from being added without clearing the text input. |
| onBeforeAdd | `function` | | Callback function that is called with the chip to be added and should return true to add the chip or false to prevent the chip from being added without clearing the text input. |
| onBlur | `function` | | Callback function that is called with `event` when the input loses focus, where `event.target.value` is the current value of the text input. |
| onChange | `function` | | Callback function that is called when the chips change (in uncontrolled mode). |
| onRequestAdd | `function` | | Callback function that is called when a new chip was added (in controlled mode). |
| onRequestDelete | `function` | | Callback function that is called when a new chip was removed (in controlled mode). |
| onAdd | `function` | | Callback function that is called when a new chip was added (in controlled mode). |
| onDelete | `function` | | Callback function that is called when a new chip was removed (in controlled mode). |
| onUpdateInput | `function` | | Callback function that is called when the input changes (useful for auto complete). |
| openOnFocus | `bool` | `false` | Opens the auto complete list on focus if set to true. |
| placeholder | `node` | | A short placeholder that is displayed if the input has no values. |
Expand Down
103 changes: 40 additions & 63 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"enzyme-to-json": "^3.2.2",
"gh-pages": "^1.0.0",
"jest": "^21.2.1",
"material-ui": "^1.0.0-beta.21",
"material-ui": "^1.0.0-beta.24",
"react": "^16.1.1",
"react-dom": "^16.1.1",
"react-test-renderer": "^16.2.0",
Expand Down
32 changes: 16 additions & 16 deletions src/ChipInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ const styles = (theme) => ({
}
})

const defaultChipRenderer = ({ value, text, isFocused, isDisabled, handleClick, handleRequestDelete, className }, key) => (
const defaultChipRenderer = ({ value, text, isFocused, isDisabled, handleClick, handleDelete, className }, key) => (
<Chip
key={key}
className={className}
style={{ pointerEvents: isDisabled ? 'none' : undefined, backgroundColor: isFocused ? blue[300] : undefined }}
onClick={handleClick}
onRequestDelete={handleRequestDelete}
onDelete={handleDelete}
label={text}
/>
)
Expand Down Expand Up @@ -289,7 +289,7 @@ class ChipInput extends React.Component {
}

handleAddChip (chip) {
if (this.props.onBeforeRequestAdd && !this.props.onBeforeRequestAdd(chip)) {
if (this.props.onBeforeAdd && !this.props.onBeforeAdd(chip)) {
return this.setState({ preventChipCreation: true })
}
this.setState({ inputValue: '' })
Expand All @@ -304,8 +304,8 @@ class ChipInput extends React.Component {
}

if (this.props.allowDuplicates || !chips.some((c) => c[this.props.dataSourceConfig.value] === chip[this.props.dataSourceConfig.value])) {
if (this.props.value && this.props.onRequestAdd) {
this.props.onRequestAdd(chip)
if (this.props.value && this.props.onAdd) {
this.props.onAdd(chip)
} else {
this.setState({ chips: [ ...this.state.chips, chip ] })
if (this.props.onChange) {
Expand All @@ -315,8 +315,8 @@ class ChipInput extends React.Component {
}
} else if (chip.trim().length > 0) {
if (this.props.allowDuplicates || chips.indexOf(chip) === -1) {
if (this.props.value && this.props.onRequestAdd) {
this.props.onRequestAdd(chip)
if (this.props.value && this.props.onAdd) {
this.props.onAdd(chip)
} else {
this.setState({ chips: [ ...this.state.chips, chip ] })
if (this.props.onChange) {
Expand All @@ -329,8 +329,8 @@ class ChipInput extends React.Component {

handleDeleteChip (chip, i) {
if (this.props.value) {
if (this.props.onRequestDelete) {
this.props.onRequestDelete(chip, i)
if (this.props.onDelete) {
this.props.onDelete(chip, i)
}
} else {
const chips = this.state.chips.slice()
Expand Down Expand Up @@ -397,9 +397,9 @@ class ChipInput extends React.Component {
label,
labelClassName,
newChipKeyCodes, // eslint-disable-line no-unused-vars
onBeforeRequestAdd,
onRequestAdd, // eslint-disable-line no-unused-vars
onRequestDelete, // eslint-disable-line no-unused-vars
onBeforeAdd,
onAdd, // eslint-disable-line no-unused-vars
onDelete, // eslint-disable-line no-unused-vars
onBlur, // eslint-disable-line no-unused-vars
onChange, // eslint-disable-line no-unused-vars
onFocus, // eslint-disable-line no-unused-vars
Expand Down Expand Up @@ -464,7 +464,7 @@ class ChipInput extends React.Component {
isDisabled: !!disabled,
isFocused: this.state.focusedChip === i,
handleClick: () => this.setState({ focusedChip: i }),
handleRequestDelete: () => this.handleDeleteChip(value, i),
handleDelete: () => this.handleDeleteChip(value, i),
className: classes.chip
}, i)
})}
Expand Down Expand Up @@ -508,9 +508,9 @@ ChipInput.propTypes = {
defaultValue: PropTypes.array,
onChange: PropTypes.func,
value: PropTypes.array,
onBeforeRequestAdd: PropTypes.func,
onRequestAdd: PropTypes.func,
onRequestDelete: PropTypes.func,
onBeforeAdd: PropTypes.func,
onAdd: PropTypes.func,
onDelete: PropTypes.func,
dataSource: PropTypes.array,
onUpdateInput: PropTypes.func,
openOnFocus: PropTypes.bool,
Expand Down
2 changes: 1 addition & 1 deletion src/ChipInput.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ describe('custom chips', () => {
isDisabled: false,
isFocused: false,
handleClick: expect.any(Function),
handleRequestDelete: expect.any(Function)
handleDelete: expect.any(Function)
})
})
})
Expand Down
Loading

0 comments on commit 4275625

Please sign in to comment.