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

small fixes and new props #22

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ build/Release
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
test/manual/bundle.js

#Editors
.idea
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ The props are very straightforward.
|placeholder|string|A placeholder will be given in the input box.|Add a tag|
|getTagStyle|function| A function from the tag text (string) to an object with any or all of the following keys: `base`, `content` and `delete`. The values are React style objects. This example renders 1-letter long tags in red: `text => text.length === 1 ? {base: {color: "red"}} : {}` | () => ({}) |
|getCreateNewText|function| A function that returns the text to display when the user types an unrecognized tag, given a title and text.| (title, text) => `Create new ${title} "${text}"` |
|getTagStyle|function| A function from the tag (object with at least the keys `title` and `category`) to an object with any or all of the following keys: `base`, `content` and `delete`. The values are React style objects. This example renders 1-letter long tags in red: `text => text.length === 1 ? {base: {color: "red"}} : {}` | () => ({}) |
|inputClass|string| Optional, overwrite default class for the <input> element.|cti__input__input|
|inputAutoSize|bool| Optional, update the <input> size attribute with the text length.|true|

#### The tag object
Tag objects look like this:
Expand All @@ -54,6 +55,7 @@ Tag objects look like this:

}
```
`onChange` will receive an array of tag objects.

#### The category object
The category object for the dataset looks like this:
Expand All @@ -64,6 +66,7 @@ The category object for the dataset looks like this:
title: 'Title displayed on the category row',
items: ['Array', 'With', 'Tags'],
single: optional boolean. If is true the row will be treated as one-valued row. It does not have the option of adding new items to the category
addNew: optional boolean. Explicity allow or dissalow for a category to receive new tags, from the user.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/dissalow/disallow/

}
```

Expand Down
1 change: 1 addition & 0 deletions categorized-tag-input.css
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
.cti__tag__delete, .cti__tag__content, .cti__tag__content > span {
display: inline-block;
vertical-align: middle;
white-space: pre;
}

.cti__tag__delete {
Expand Down
2 changes: 1 addition & 1 deletion categorized-tag-input.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion categorized-tag-input.js.map

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions src/CategorizedTagInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ const CategorizedTagInput = React.createClass({
onChange: PropTypes.func,
placeholder: PropTypes.string,
getTagStyle: PropTypes.func,
getCreateNewText: PropTypes.func
getCreateNewText: PropTypes.func,
inputClass: PropTypes.string,
inputAutoSize: PropTypes.bool
},

getInitialState() {
Expand All @@ -50,7 +52,8 @@ const CategorizedTagInput = React.createClass({
return {
onChange(newTags){
// do nothing
}
},
inputAutoSize: true
};
},

Expand Down Expand Up @@ -234,7 +237,8 @@ const CategorizedTagInput = React.createClass({
getTagStyle={this.props.getTagStyle}
tags={this.props.value}
transformTag={this.props.transformTag}
onBlur={this.props.onBlur} ref='input' />
onBlur={this.props.onBlur} ref='input' inputClass={this.props.inputClass}
inputAutoSize={this.props.inputAutoSize} />
{this.state.panelOpened && this.state.value.length > 0 ? <Panel categories={this.state.categories}
selection={this.state.selection} onAdd={this.onAdd}
input={this.state.value}
Expand Down
19 changes: 13 additions & 6 deletions src/Input.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ const Input = React.createClass({
placeholder: PropTypes.string,
onBlur: PropTypes.func,
getTagStyle: PropTypes.func,
transformTag: PropTypes.func
transformTag: PropTypes.func,
inputClass: PropTypes.string,
inputAutoSize: PropTypes.bool
},

focusInput() {
Expand Down Expand Up @@ -56,18 +58,23 @@ const Input = React.createClass({

render() {
const placeholder = this.props.placeholder || '';
let size = this.props.value.length === 0 ?
placeholder.length :
this.props.value.length;
let extraProps = {};

if (this.props.inputAutoSize){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space between ) and {

extraProps["size"] = (this.props.value.length === 0 ?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since there are no more extraProps right now, and I don't know if there will be in the future, what do you think about moving this to a size variable which, by default is null and set it directly as size={size} (which won't be rendered when it's null)?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, with null is better, I forgot that react is so smart. I would like to add other props, for example "maxlength" is a must, for me at least it ruins CSS if you type or paste a large text, when using the "size" attribute.

placeholder.length :
this.props.value.length) + 2
}

return (
<div className='cti__input' onClick={this.focusInput}>
{this.getTags()}
<input type='text' ref='input' value={this.props.value}
size={size + 2}
{...extraProps}
onFocus={this.props.openPanel} onBlur={this.onBlur}
onChange={this.props.onValueChange} onKeyDown={this.props.onKeyDown}
placeholder={placeholder} aria-label={placeholder}
className='cti__input__input' />
className={this.props.inputClass === undefined ? 'cti__input__input' : this.props.inputClass} />
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/this.props.inputClass === undefined/!this.props.inputClass/

<div className='cti__input__arrow' />
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion src/Panel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const Panel = React.createClass({
<Category key={c.id} items={c.items} category={c.id} title={c.title}
selected={this.props.selection.category === i}
selectedItem={this.props.selection.item}
input={this.props.input} addNew={this.props.addNew}
input={this.props.input} addNew={c.addNew===undefined ? this.props.addNew : !!c.addNew}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/c.addNew === undefined/!c.addNew/

type={c.type} onAdd={this.props.onAdd} single={c.single}
getTagStyle={this.props.getTagStyle}
getCreateNewText={this.props.getCreateNewText} />
Expand Down