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

Commit 3930ee7

Browse files
DiegoHueltesleMaik
authored andcommitted
Added default style to chip render function. Update storybook example and docs. (#82)
Added default style to chip render function. Updated storybook examples and docs.
1 parent ea1f7e6 commit 3930ee7

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import ChipInput from 'material-ui-chip-input'
3333
## Properties
3434
| Name | Type | Default | Description |
3535
| --- | --- | --- | --- |
36-
| chipRenderer | `function` | | A function of the type `({ value, text, isFocused, isDisabled, handleClick, handleRequestDelete }, key) => node` that returns a chip based on the given properties. This can be used to customize chip styles. |
36+
| chipRenderer | `function` | | A function of the type `({ value, text, isFocused, isDisabled, handleClick, handleRequestDelete, defaultStyle }, key) => node` that returns a chip based on the given properties. This can be used to customize chip styles. |
3737
| clearOnBlur | `bool` | `true` | If true, clears the input value after the component loses focus. |
3838
| dataSource | `array` | | Data source for auto complete. |
3939
| dataSourceConfig | `object` | | Config for objects list dataSource, e.g. `{ text: 'text', value: 'value' }`. If not specified, the `dataSource` must be a flat array of strings. |

src/ChipInput.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ const getStyles = (props, context, state) => {
7070
},
7171
floatingLabelFocusStyle: {
7272
transform: 'scale(0.75) translate(0, -36px)'
73+
},
74+
defaultChip: {
75+
margin: '8px 8px 0 0',
76+
float: 'left'
7377
}
7478
};
7579

@@ -90,10 +94,10 @@ const getStyles = (props, context, state) => {
9094
return styles;
9195
};
9296

93-
const defaultChipRenderer = ({ value, text, isFocused, isDisabled, handleClick, handleRequestDelete }, key) => (
97+
const defaultChipRenderer = ({ value, text, isFocused, isDisabled, handleClick, handleRequestDelete, defaultStyle }, key) => (
9498
<Chip
9599
key={key}
96-
style={{ margin: '8px 8px 0 0', float: 'left', pointerEvents: isDisabled ? 'none' : undefined }}
100+
style={{ ...defaultStyle, pointerEvents: isDisabled ? 'none' : undefined }}
97101
backgroundColor={isFocused ? blue300 : null}
98102
onTouchTap={handleClick}
99103
onRequestDelete={handleRequestDelete}
@@ -370,10 +374,10 @@ class ChipInput extends React.Component {
370374
/**
371375
* Sets a reference to the AutoComplete instance.
372376
*
373-
* Using a bound class method here to set `autoComplete` to avoid it being set
377+
* Using a bound class method here to set `autoComplete` to avoid it being set
374378
* to null by an inline ref callback.
375379
*
376-
* See [Isuue #71](https://github.com/TeamWertarbyte/material-ui-chip-input/issues/71)
380+
* See [Issue #71](https://github.com/TeamWertarbyte/material-ui-chip-input/issues/71)
377381
*
378382
* @param {Object} autoComplete - The AutoComplete DOM element or null
379383
*/
@@ -491,7 +495,8 @@ class ChipInput extends React.Component {
491495
isDisabled: disabled,
492496
isFocused: this.state.focusedChip === value,
493497
handleClick: () => this.setState({ focusedChip: value }),
494-
handleRequestDelete: () => this.handleDeleteChip(value, i)
498+
handleRequestDelete: () => this.handleDeleteChip(value, i),
499+
defaultStyle: styles.defaultChip
495500
}, i)
496501
})}
497502
</div>

stories/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ storiesOf('ChipInput', module)
9898
<ChipInput
9999
defaultValue={['foo', 'bar']}
100100
fullWidth
101-
chipRenderer={({ value, isFocused, isDisabled, handleClick, handleRequestDelete }, key) => (
101+
chipRenderer={({ value, isFocused, isDisabled, handleClick, handleRequestDelete, defaultStyle }, key) => (
102102
<Chip
103103
key={key}
104-
style={{ margin: '8px 8px 0 0', float: 'left', pointerEvents: isDisabled ? 'none' : undefined }}
104+
style={{ ...defaultStyle, pointerEvents: isDisabled ? 'none' : undefined }}
105105
backgroundColor={isFocused ? green800 : green300}
106106
onTouchTap={handleClick}
107107
onRequestDelete={handleRequestDelete}

0 commit comments

Comments
 (0)