-
Notifications
You must be signed in to change notification settings - Fork 2
Use some sort of multiple select component for Tag input #52
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,11 @@ | ||
| import React from 'react'; | ||
| import { connect } from 'react-redux'; | ||
| import { Controlled as CodeMirror } from 'react-codemirror2'; | ||
| import Tags from 'react-tagging-input'; | ||
|
|
||
| import 'codemirror/lib/codemirror.css'; | ||
|
|
||
| import Title from './common/Title'; | ||
| import Input from './common/Input'; | ||
| import ListBoxWithSearch from './ListBoxWithSearch'; | ||
| import * as actions from '../actions'; | ||
|
|
||
|
|
@@ -20,28 +20,35 @@ class NewSnippet extends React.Component { | |
| tags: [], | ||
| syntax: '', // eslint-disable-line react/no-unused-state | ||
| }; | ||
| this.onKeyPress = (e) => { | ||
| if (e.which === 13) { e.preventDefault(); } | ||
| }; | ||
| this.postSnippet = this.postSnippet.bind(this); | ||
| this.onSyntaxClick = this.onSyntaxClick.bind(this); | ||
| this.onInputChange = this.onInputChange.bind(this); | ||
| this.onTagAdded = this.onTagAdded.bind(this); | ||
| this.onTagRemoved = this.onTagRemoved.bind(this); | ||
| } | ||
|
|
||
| componentDidMount() { | ||
| const { dispatch } = this.props; | ||
|
|
||
| dispatch(actions.fetchSyntaxes); | ||
| } | ||
|
|
||
| onTagAdded(tag) { | ||
| this.setState({ tags: [...this.state.tags, tag] }); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I think we currently do not enforce it at the API level, but maybe we should prevent duplicates of tags on the same snippet? @ikalnytskyi what do you think?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it makes sense. Will you file an issue for API to enforce that?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ikalnytskyi do you want to reject requests with duplicates with
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @malor Honestly, I don't have strong opinion here. Both approaches have their own pros and cons. What do you think? |
||
| } | ||
|
|
||
| onTagRemoved(tag) { | ||
| this.setState({ tags: this.state.tags.filter(item => item !== tag) }); | ||
| } | ||
|
|
||
| onSyntaxClick(syntax) { | ||
| this.setState({ syntax }); // eslint-disable-line react/no-unused-state | ||
| } | ||
|
|
||
| onInputChange(e) { | ||
| const { name } = e.target; | ||
| let { value } = e.target; | ||
|
|
||
| if (name === 'tags') { | ||
| value = value.split(',').map(item => item.trim()); | ||
| } | ||
| const { name, value } = e.target; | ||
|
|
||
| this.setState({ [name]: value }); | ||
| } | ||
|
|
@@ -56,20 +63,28 @@ class NewSnippet extends React.Component { | |
| return ( | ||
| [ | ||
| <Title title="New snippet" key="New Snippet Title" />, | ||
| <form className="new-snippet" key="New Snippet" onSubmit={this.postSnippet}> | ||
| <form | ||
| className="new-snippet" | ||
| key="New Snippet" | ||
| onKeyPress={this.onKeyPress} | ||
| onSubmit={this.postSnippet} | ||
| role="presentation" | ||
| > | ||
| <div className="new-snippet-code-wrapper"> | ||
| <div className="new-snippet-code-header"> | ||
| <Input | ||
| <input | ||
| className="input" | ||
| placeholder="Title" | ||
| name="title" | ||
| onChangeHandler={this.onInputChange} | ||
| type="text" | ||
| value={this.state.title} | ||
| onChange={this.onInputChange} | ||
| /> | ||
| <Input | ||
| placeholder="Tags (separate tags by comma)" | ||
| name="tags" | ||
| onChangeHandler={this.onInputChange} | ||
| value={this.state.tags.toString()} | ||
| <Tags | ||
| tags={this.state.tags} | ||
| placeholder="Tags" | ||
| onAdded={this.onTagAdded} | ||
| onRemoved={this.onTagRemoved} | ||
| /> | ||
| </div> | ||
| <div className="new-snippet-code"> | ||
|
|
||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| @import './common/variables.styl' | ||
|
|
||
| basic-input() | ||
| width: 100% | ||
| background-color: transparent | ||
| border: none | ||
| border-bottom: 1px solid rgba(text-light, .4) | ||
| outline: none | ||
| color: text-light | ||
| font-size: 15px | ||
| font-family: font-quicksand | ||
| letter-spacing: -.3px | ||
| &::placeholder | ||
| color: rgba(text-light, .6) | ||
| &:focus | ||
| border-bottom: 1px solid text-light |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a constant for that? If not let's at least document, that
13is a keycode ofEnter