mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-14 02:06:29 +00:00
extract SnippetForm component & add focsuing after form loaded & enhance CSS of Article focusing effect in
This commit is contained in:
@@ -5,92 +5,15 @@ var Catalyst = require('../Mixins/Catalyst')
|
|||||||
|
|
||||||
var Select = require('react-select')
|
var Select = require('react-select')
|
||||||
|
|
||||||
var PlanetActions = require('../Actions/PlanetActions')
|
|
||||||
var PlanetStore = require('../Stores/PlanetStore')
|
var PlanetStore = require('../Stores/PlanetStore')
|
||||||
|
|
||||||
// TODO: remove
|
var SnippetForm = require('./SnippetForm')
|
||||||
|
|
||||||
var options = [
|
var options = [
|
||||||
{ value: 'one', label: 'One' },
|
{ value: 'one', label: 'One' },
|
||||||
{ value: 'two', label: 'Two' }
|
{ value: 'two', label: 'Two' }
|
||||||
]
|
]
|
||||||
|
|
||||||
var SnippetForm = React.createClass({
|
|
||||||
mixins: [Catalyst.LinkedStateMixin, ReactRouter.State],
|
|
||||||
propTypes: {
|
|
||||||
close: React.PropTypes.func
|
|
||||||
},
|
|
||||||
getInitialState: function () {
|
|
||||||
return {
|
|
||||||
snippet: {
|
|
||||||
description: '',
|
|
||||||
mode: 'javascript',
|
|
||||||
content: '',
|
|
||||||
callSign: '',
|
|
||||||
Tags: []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
handleSnippetTagsChange: function (selected, all) {
|
|
||||||
var snippet = this.state.snippet
|
|
||||||
snippet.Tags = all
|
|
||||||
this.setState({snippet: snippet})
|
|
||||||
},
|
|
||||||
handleSnippetContentChange: function (e, value) {
|
|
||||||
var snippet = this.state.snippet
|
|
||||||
snippet.content = value
|
|
||||||
this.setState({snippet: snippet})
|
|
||||||
},
|
|
||||||
submit: function () {
|
|
||||||
var params = this.getParams()
|
|
||||||
var userName = params.userName
|
|
||||||
var planetName = params.planetName
|
|
||||||
var snippet = Object.assign({}, this.state.snippet)
|
|
||||||
snippet.Tags = snippet.Tags.map(function (tag) {
|
|
||||||
return tag.value
|
|
||||||
})
|
|
||||||
PlanetActions.createSnippet(userName + '/' + planetName, snippet)
|
|
||||||
},
|
|
||||||
render: function () {
|
|
||||||
return (
|
|
||||||
<div className='SnippetForm'>
|
|
||||||
<div className='modal-body'>
|
|
||||||
<div className='form-group'>
|
|
||||||
<textarea className='snippetDescription block-input' valueLink={this.linkState('snippet.description')} placeholder='Description'/>
|
|
||||||
</div>
|
|
||||||
<div className='form-group'>
|
|
||||||
<input className='inline-input' valueLink={this.linkState('snippet.callSign')} type='text' placeholder='Callsign'/>
|
|
||||||
<select className='inline-input' valueLink={this.linkState('snippet.mode')}>
|
|
||||||
<option value='javascript'>Javascript</option>
|
|
||||||
<option value='html'>HTML</option>
|
|
||||||
<option value='css'>CSS</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div className='form-group'>
|
|
||||||
<CodeEditor onChange={this.handleSnippetContentChange} code={this.state.snippet.content} mode={this.state.snippet.mode}/>
|
|
||||||
</div>
|
|
||||||
<div className='form-group'>
|
|
||||||
<Select
|
|
||||||
name='Tags'
|
|
||||||
multi={true}
|
|
||||||
allowCreate={true}
|
|
||||||
value={this.state.snippet.Tags}
|
|
||||||
placeholder='Tags...'
|
|
||||||
options={options}
|
|
||||||
onChange={this.handleSnippetTagsChange}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className='modal-footer'>
|
|
||||||
<div className='modal-control'>
|
|
||||||
<button onClick={this.props.close} className='btn-default'>Cancle</button>
|
|
||||||
<button onClick={this.submit} className='btn-primary'>Launch</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
var BlueprintForm = React.createClass({
|
var BlueprintForm = React.createClass({
|
||||||
mixins: [Catalyst.LinkedStateMixin, ReactRouter.State],
|
mixins: [Catalyst.LinkedStateMixin, ReactRouter.State],
|
||||||
propTypes: {
|
propTypes: {
|
||||||
@@ -105,6 +28,9 @@ var BlueprintForm = React.createClass({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
componentDidMount: function () {
|
||||||
|
React.findDOMNode(this.refs.title).focus()
|
||||||
|
},
|
||||||
handleBlueprintTagsChange: function (selected, all) {
|
handleBlueprintTagsChange: function (selected, all) {
|
||||||
var blueprint = this.state.blueprint
|
var blueprint = this.state.blueprint
|
||||||
blueprint.Tags = all
|
blueprint.Tags = all
|
||||||
@@ -123,7 +49,7 @@ var BlueprintForm = React.createClass({
|
|||||||
<div className='BlueprintForm'>
|
<div className='BlueprintForm'>
|
||||||
<div className='modal-body'>
|
<div className='modal-body'>
|
||||||
<div className='form-group'>
|
<div className='form-group'>
|
||||||
<input className='block-input' valueLink={this.linkState('blueprint.title')} placeholder='Title'/>
|
<input ref='title' className='block-input' valueLink={this.linkState('blueprint.title')} placeholder='Title'/>
|
||||||
</div>
|
</div>
|
||||||
<div className='form-group'>
|
<div className='form-group'>
|
||||||
<CodeEditor onChange={this.handleBlueprintContentChange} code={this.state.blueprint.content} mode={'markdown'}/>
|
<CodeEditor onChange={this.handleBlueprintContentChange} code={this.state.blueprint.content} mode={'markdown'}/>
|
||||||
|
|||||||
95
browser/main/Components/SnippetForm.jsx
Normal file
95
browser/main/Components/SnippetForm.jsx
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
var React = require('react/addons')
|
||||||
|
var ReactRouter = require('react-router')
|
||||||
|
var CodeEditor = require('./CodeEditor')
|
||||||
|
var Catalyst = require('../Mixins/Catalyst')
|
||||||
|
|
||||||
|
var Select = require('react-select')
|
||||||
|
|
||||||
|
var PlanetActions = require('../Actions/PlanetActions')
|
||||||
|
|
||||||
|
var options = [
|
||||||
|
{ value: 'one', label: 'One' },
|
||||||
|
{ value: 'two', label: 'Two' }
|
||||||
|
]
|
||||||
|
|
||||||
|
var SnippetForm = React.createClass({
|
||||||
|
mixins: [Catalyst.LinkedStateMixin, ReactRouter.State],
|
||||||
|
propTypes: {
|
||||||
|
close: React.PropTypes.func
|
||||||
|
},
|
||||||
|
getInitialState: function () {
|
||||||
|
return {
|
||||||
|
snippet: {
|
||||||
|
description: '',
|
||||||
|
mode: 'javascript',
|
||||||
|
content: '',
|
||||||
|
callSign: '',
|
||||||
|
Tags: []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
componentDidMount: function () {
|
||||||
|
React.findDOMNode(this.refs.description).focus()
|
||||||
|
},
|
||||||
|
handleSnippetTagsChange: function (selected, all) {
|
||||||
|
var snippet = this.state.snippet
|
||||||
|
snippet.Tags = all
|
||||||
|
this.setState({snippet: snippet})
|
||||||
|
},
|
||||||
|
handleSnippetContentChange: function (e, value) {
|
||||||
|
var snippet = this.state.snippet
|
||||||
|
snippet.content = value
|
||||||
|
this.setState({snippet: snippet})
|
||||||
|
},
|
||||||
|
submit: function () {
|
||||||
|
var params = this.getParams()
|
||||||
|
var userName = params.userName
|
||||||
|
var planetName = params.planetName
|
||||||
|
var snippet = Object.assign({}, this.state.snippet)
|
||||||
|
snippet.Tags = snippet.Tags.map(function (tag) {
|
||||||
|
return tag.value
|
||||||
|
})
|
||||||
|
PlanetActions.createSnippet(userName + '/' + planetName, snippet)
|
||||||
|
},
|
||||||
|
render: function () {
|
||||||
|
return (
|
||||||
|
<div className='SnippetForm'>
|
||||||
|
<div className='modal-body'>
|
||||||
|
<div className='form-group'>
|
||||||
|
<textarea ref='description' className='snippetDescription block-input' valueLink={this.linkState('snippet.description')} placeholder='Description'/>
|
||||||
|
</div>
|
||||||
|
<div className='form-group'>
|
||||||
|
<input className='inline-input' valueLink={this.linkState('snippet.callSign')} type='text' placeholder='Callsign'/>
|
||||||
|
<select className='inline-input' valueLink={this.linkState('snippet.mode')}>
|
||||||
|
<option value='javascript'>Javascript</option>
|
||||||
|
<option value='html'>HTML</option>
|
||||||
|
<option value='css'>CSS</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div className='form-group'>
|
||||||
|
<CodeEditor onChange={this.handleSnippetContentChange} code={this.state.snippet.content} mode={this.state.snippet.mode}/>
|
||||||
|
</div>
|
||||||
|
<div className='form-group'>
|
||||||
|
<Select
|
||||||
|
name='Tags'
|
||||||
|
multi={true}
|
||||||
|
allowCreate={true}
|
||||||
|
value={this.state.snippet.Tags}
|
||||||
|
placeholder='Tags...'
|
||||||
|
options={options}
|
||||||
|
onChange={this.handleSnippetTagsChange}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className='modal-footer'>
|
||||||
|
<div className='modal-control'>
|
||||||
|
<button onClick={this.props.close} className='btn-default'>Cancle</button>
|
||||||
|
<button onClick={this.submit} className='btn-primary'>Launch</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = SnippetForm
|
||||||
@@ -134,11 +134,14 @@ var PlanetArticleList = React.createClass({
|
|||||||
}.bind(this)
|
}.bind(this)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<li onClick={handleClick} className={isActive ? 'active' : ''} key={snippet.id}>
|
<li onClick={handleClick} key={snippet.id}>
|
||||||
|
<div className={isActive ? 'snippetItem active' : 'snippetItem'}>
|
||||||
<div className='callSign'><i className='fa fa-code'></i> {snippet.callSign}</div>
|
<div className='callSign'><i className='fa fa-code'></i> {snippet.callSign}</div>
|
||||||
<div className='description'>{snippet.description}</div>
|
<div className='description'>{snippet.description}</div>
|
||||||
<div className='updatedAt'>{snippet.updatedAt}</div>
|
<div className='updatedAt'>{snippet.updatedAt}</div>
|
||||||
<div className='tags'><i className='fa fa-tags'/>{tags}</div>
|
<div className='tags'><i className='fa fa-tags'/>{tags}</div>
|
||||||
|
</div>
|
||||||
|
<div className='divider'></div>
|
||||||
</li>
|
</li>
|
||||||
)
|
)
|
||||||
}.bind(this))
|
}.bind(this))
|
||||||
|
|||||||
@@ -128,9 +128,11 @@
|
|||||||
absolute top bottom left right
|
absolute top bottom left right
|
||||||
overflow-y auto
|
overflow-y auto
|
||||||
li
|
li
|
||||||
border-bottom solid 1px borderColor
|
.snippetItem
|
||||||
|
border solid 2px transparent
|
||||||
padding 10px
|
padding 10px
|
||||||
cursor pointer
|
cursor pointer
|
||||||
|
transition 0.1s
|
||||||
.callSign
|
.callSign
|
||||||
margin-bottom 5px
|
margin-bottom 5px
|
||||||
font-weight 600
|
font-weight 600
|
||||||
@@ -145,8 +147,9 @@
|
|||||||
&:active, &.active
|
&:active, &.active
|
||||||
background-color white
|
background-color white
|
||||||
&:active, &.active
|
&:active, &.active
|
||||||
border solid 2px brandBorderColor
|
border-color brandBorderColor
|
||||||
padding 9px 9px 8px
|
.divider
|
||||||
|
border-bottom solid 1px borderColor
|
||||||
|
|
||||||
.PlanetArticleDetail
|
.PlanetArticleDetail
|
||||||
absolute right bottom
|
absolute right bottom
|
||||||
|
|||||||
Reference in New Issue
Block a user