mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 09:46:22 +00:00
new folder modalにcolor select追加
This commit is contained in:
@@ -3,45 +3,50 @@ import React, { PropTypes } from 'react'
|
||||
const BLUE = '#3460C7'
|
||||
const LIGHTBLUE = '#2BA5F7'
|
||||
const ORANGE = '#FF8E00'
|
||||
const YELLOW = '#EAEF31'
|
||||
const GREEN = '#02FF26'
|
||||
const DARKGREEN = '#008A59'
|
||||
const YELLOW = '#E8D252'
|
||||
const GREEN = '#3FD941'
|
||||
const DARKGREEN = '#1FAD85'
|
||||
const RED = '#E10051'
|
||||
const PURPLE = '#B013A4'
|
||||
const BRAND_COLOR = '#2BAC8F'
|
||||
|
||||
function getColorByIndex (index) {
|
||||
switch (index % 8) {
|
||||
case 0:
|
||||
return LIGHTBLUE
|
||||
return RED
|
||||
case 1:
|
||||
return ORANGE
|
||||
case 2:
|
||||
return RED
|
||||
return YELLOW
|
||||
case 3:
|
||||
return GREEN
|
||||
case 4:
|
||||
return DARKGREEN
|
||||
case 5:
|
||||
return YELLOW
|
||||
return LIGHTBLUE
|
||||
case 6:
|
||||
return BLUE
|
||||
case 7:
|
||||
return PURPLE
|
||||
default:
|
||||
return BRAND_COLOR
|
||||
return DARKGREEN
|
||||
}
|
||||
}
|
||||
|
||||
export default class FolderMark extends React.Component {
|
||||
render () {
|
||||
let color = getColorByIndex(this.props.color)
|
||||
let className = 'FolderMark fa fa-square fa-fw'
|
||||
if (this.props.className != null) {
|
||||
className += ' active'
|
||||
}
|
||||
|
||||
return (
|
||||
<i className='fa fa-square fa-fw' style={{color: color}}/>
|
||||
<i className={className} style={{color: color}}/>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
FolderMark.propTypes = {
|
||||
color: PropTypes.number
|
||||
color: PropTypes.number,
|
||||
className: PropTypes.string
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import React, { PropTypes } from 'react'
|
||||
import linkState from 'boost/linkState'
|
||||
import { createFolder } from 'boost/actions'
|
||||
import store from 'boost/store'
|
||||
import FolderMark from 'boost/components/FolderMark'
|
||||
|
||||
export default class CreateNewFolder extends React.Component {
|
||||
constructor (props) {
|
||||
@@ -9,6 +10,7 @@ export default class CreateNewFolder extends React.Component {
|
||||
|
||||
this.state = {
|
||||
name: '',
|
||||
color: Math.round(Math.random() * 7),
|
||||
alert: null
|
||||
}
|
||||
}
|
||||
@@ -20,9 +22,11 @@ export default class CreateNewFolder extends React.Component {
|
||||
handleConfirmButton (e) {
|
||||
this.setState({alert: null}, () => {
|
||||
let { close } = this.props
|
||||
let name = this.state.name
|
||||
let { name, color } = this.state
|
||||
|
||||
let input = {
|
||||
name
|
||||
name,
|
||||
color
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -38,6 +42,14 @@ export default class CreateNewFolder extends React.Component {
|
||||
})
|
||||
}
|
||||
|
||||
handleColorClick (colorIndex) {
|
||||
return e => {
|
||||
this.setState({
|
||||
color: colorIndex
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
render () {
|
||||
let alert = this.state.alert
|
||||
let alertElement = alert != null ? (
|
||||
@@ -45,6 +57,21 @@ export default class CreateNewFolder extends React.Component {
|
||||
{alert.message}
|
||||
</p>
|
||||
) : null
|
||||
let colorIndexes = []
|
||||
for (let i = 0; i < 8; i++) {
|
||||
colorIndexes.push(i)
|
||||
}
|
||||
let colorElements = colorIndexes.map(index => {
|
||||
let className = index === this.state.color
|
||||
? 'active'
|
||||
: null
|
||||
|
||||
return (
|
||||
<span className='option' key={index} onClick={e => this.handleColorClick(index)(e)}>
|
||||
<FolderMark className={className} color={index}/>
|
||||
</span>
|
||||
)
|
||||
})
|
||||
|
||||
return (
|
||||
<div className='CreateNewFolder modal'>
|
||||
@@ -53,6 +80,9 @@ export default class CreateNewFolder extends React.Component {
|
||||
<div className='title'>Create new folder</div>
|
||||
|
||||
<input className='ipt' type='text' valueLink={this.linkState('name')} placeholder='Enter folder name'/>
|
||||
<div className='colorSelect'>
|
||||
{colorElements}
|
||||
</div>
|
||||
{alertElement}
|
||||
|
||||
<button onClick={e => this.handleConfirmButton(e)} className='confirmBtn'>Create</button>
|
||||
|
||||
@@ -26,9 +26,7 @@ function folders (state = initialFolders, action) {
|
||||
Object.assign(newFolder, {
|
||||
key: keygen(),
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
// random number (0-7)
|
||||
color: Math.round(Math.random() * 7)
|
||||
updatedAt: new Date()
|
||||
})
|
||||
|
||||
if (newFolder.length === 0) throw new Error('Folder name is required')
|
||||
|
||||
Reference in New Issue
Block a user