mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
Set color picker pos correctly such that it is restricted to the viewport
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import React, { PropTypes } from 'react'
|
import React, { PropTypes } from 'react'
|
||||||
|
import ReactDOM from 'react-dom'
|
||||||
import CSSModules from 'browser/lib/CSSModules'
|
import CSSModules from 'browser/lib/CSSModules'
|
||||||
import styles from './StorageItem.styl'
|
import styles from './StorageItem.styl'
|
||||||
import consts from 'browser/lib/consts'
|
import consts from 'browser/lib/consts'
|
||||||
@@ -18,6 +19,7 @@ class UnstyledFolderItem extends React.Component {
|
|||||||
status: 'IDLE',
|
status: 'IDLE',
|
||||||
folder: {
|
folder: {
|
||||||
showColumnPicker: false,
|
showColumnPicker: false,
|
||||||
|
colorPickerPos: { left: 0, top: 0 },
|
||||||
color: props.color,
|
color: props.color,
|
||||||
name: props.name
|
name: props.name
|
||||||
}
|
}
|
||||||
@@ -52,8 +54,22 @@ class UnstyledFolderItem extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleColorButtonClick (e) {
|
handleColorButtonClick (e) {
|
||||||
const folder = Object.assign({}, this.state.folder, { showColumnPicker: true })
|
const folder = Object.assign({}, this.state.folder, { showColumnPicker: true, colorPickerPos: { left: 0, top: 0 } })
|
||||||
this.setState({ folder })
|
this.setState({ folder }, function() {
|
||||||
|
// After the color picker has been painted, re-calculate its position
|
||||||
|
// by comparing its dimensions to the host dimensions.
|
||||||
|
const { hostBoundingBox } = this.props;
|
||||||
|
const colorPickerNode = ReactDOM.findDOMNode(this.refs.colorPicker)
|
||||||
|
const colorPickerBox = colorPickerNode.getBoundingClientRect()
|
||||||
|
const offsetTop = hostBoundingBox.bottom - colorPickerBox.bottom
|
||||||
|
const folder = Object.assign({}, this.state.folder, {
|
||||||
|
colorPickerPos: {
|
||||||
|
left: 25,
|
||||||
|
top: offsetTop < 0 ? offsetTop - 5 : 0 // subtract 5px for aestetics
|
||||||
|
}
|
||||||
|
})
|
||||||
|
this.setState({ folder })
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
handleColorChange (color) {
|
handleColorChange (color) {
|
||||||
@@ -78,6 +94,9 @@ class UnstyledFolderItem extends React.Component {
|
|||||||
position: 'fixed',
|
position: 'fixed',
|
||||||
top: 0, right: 0, bottom: 0, left: 0
|
top: 0, right: 0, bottom: 0, left: 0
|
||||||
}
|
}
|
||||||
|
const pickerStyle = Object.assign({}, {
|
||||||
|
position: 'absolute'
|
||||||
|
}, this.state.folder.colorPickerPos)
|
||||||
return (
|
return (
|
||||||
<div styleName='folderList-item'>
|
<div styleName='folderList-item'>
|
||||||
<div styleName='folderList-item-left'>
|
<div styleName='folderList-item-left'>
|
||||||
@@ -88,10 +107,13 @@ class UnstyledFolderItem extends React.Component {
|
|||||||
<div style={ popover }>
|
<div style={ popover }>
|
||||||
<div style={ cover }
|
<div style={ cover }
|
||||||
onClick={ () => this.handleColorPickerClose() } />
|
onClick={ () => this.handleColorPickerClose() } />
|
||||||
<SketchPicker
|
<div style={pickerStyle}>
|
||||||
color={this.state.folder.color}
|
<SketchPicker
|
||||||
onChange={ (color) => this.handleColorChange(color) }
|
ref="colorPicker"
|
||||||
onChangeComplete={ (color) => this.handleColorChange(color) } />
|
color={this.state.folder.color}
|
||||||
|
onChange={ (color) => this.handleColorChange(color) }
|
||||||
|
onChangeComplete={ (color) => this.handleColorChange(color) } />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
: null }
|
: null }
|
||||||
<i className='fa fa-square'/>
|
<i className='fa fa-square'/>
|
||||||
@@ -154,13 +176,12 @@ class UnstyledFolderItem extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleEditButtonClick (e) {
|
handleEditButtonClick (e) {
|
||||||
let { folder } = this.props
|
let { folder: propsFolder } = this.props
|
||||||
|
let { folder: stateFolder } = this.state
|
||||||
|
const folder = Object.assign({}, stateFolder, propsFolder)
|
||||||
this.setState({
|
this.setState({
|
||||||
status: 'EDIT',
|
status: 'EDIT',
|
||||||
folder: {
|
folder
|
||||||
color: folder.color,
|
|
||||||
name: folder.name
|
|
||||||
}
|
|
||||||
}, () => {
|
}, () => {
|
||||||
this.refs.nameInput.select()
|
this.refs.nameInput.select()
|
||||||
})
|
})
|
||||||
@@ -293,11 +314,12 @@ class StorageItem extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
let { storage } = this.props
|
let { storage, hostBoundingBox } = this.props
|
||||||
let folderList = storage.folders.map((folder) => {
|
let folderList = storage.folders.map((folder) => {
|
||||||
return <FolderItem key={folder.key}
|
return <FolderItem key={folder.key}
|
||||||
folder={folder}
|
folder={folder}
|
||||||
storage={storage}
|
storage={storage}
|
||||||
|
hostBoundingBox={hostBoundingBox}
|
||||||
/>
|
/>
|
||||||
})
|
})
|
||||||
return (
|
return (
|
||||||
@@ -360,6 +382,14 @@ class StorageItem extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
StorageItem.propTypes = {
|
StorageItem.propTypes = {
|
||||||
|
hostBoundingBox: PropTypes.shape({
|
||||||
|
bottom: PropTypes.number,
|
||||||
|
height: PropTypes.number,
|
||||||
|
left: PropTypes.number,
|
||||||
|
right: PropTypes.number,
|
||||||
|
top: PropTypes.number,
|
||||||
|
width: PropTypes.number
|
||||||
|
}),
|
||||||
storage: PropTypes.shape({
|
storage: PropTypes.shape({
|
||||||
key: PropTypes.string
|
key: PropTypes.string
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -51,12 +51,15 @@ class StoragesTab extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderList () {
|
renderList () {
|
||||||
let { storages } = this.props
|
let { storages, boundingBox } = this.props
|
||||||
|
|
||||||
|
if (!boundingBox) { return null }
|
||||||
let storageList = storages.map((storage) => {
|
let storageList = storages.map((storage) => {
|
||||||
return <StorageItem
|
return <StorageItem
|
||||||
key={storage.key}
|
key={storage.key}
|
||||||
storage={storage}
|
storage={storage}
|
||||||
|
test={true}
|
||||||
|
hostBoundingBox={boundingBox}
|
||||||
/>
|
/>
|
||||||
})
|
})
|
||||||
return (
|
return (
|
||||||
@@ -217,6 +220,14 @@ class StoragesTab extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
StoragesTab.propTypes = {
|
StoragesTab.propTypes = {
|
||||||
|
boundingBox: PropTypes.shape({
|
||||||
|
bottom: PropTypes.number,
|
||||||
|
height: PropTypes.number,
|
||||||
|
left: PropTypes.number,
|
||||||
|
right: PropTypes.number,
|
||||||
|
top: PropTypes.number,
|
||||||
|
width: PropTypes.number
|
||||||
|
}),
|
||||||
dispatch: PropTypes.func
|
dispatch: PropTypes.func
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import React, { PropTypes } from 'react'
|
import React, { PropTypes } from 'react'
|
||||||
|
import ReactDOM from 'react-dom'
|
||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
import ConfigTab from './ConfigTab'
|
import ConfigTab from './ConfigTab'
|
||||||
import InfoTab from './InfoTab'
|
import InfoTab from './InfoTab'
|
||||||
@@ -17,6 +18,8 @@ class Preferences extends React.Component {
|
|||||||
|
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
this.refs.root.focus()
|
this.refs.root.focus()
|
||||||
|
const boundingBox = this.getContentBoundingBox()
|
||||||
|
this.setState({ boundingBox })
|
||||||
}
|
}
|
||||||
|
|
||||||
switchTeam (teamId) {
|
switchTeam (teamId) {
|
||||||
@@ -30,6 +33,7 @@ class Preferences extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderContent () {
|
renderContent () {
|
||||||
|
const { boundingBox } = this.state;
|
||||||
let { dispatch, config, storages } = this.props
|
let { dispatch, config, storages } = this.props
|
||||||
|
|
||||||
switch (this.state.currentTab) {
|
switch (this.state.currentTab) {
|
||||||
@@ -48,6 +52,7 @@ class Preferences extends React.Component {
|
|||||||
<StoragesTab
|
<StoragesTab
|
||||||
dispatch={dispatch}
|
dispatch={dispatch}
|
||||||
storages={storages}
|
storages={storages}
|
||||||
|
boundingBox={boundingBox}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -59,6 +64,11 @@ class Preferences extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getContentBoundingBox () {
|
||||||
|
const node = ReactDOM.findDOMNode(this.refs.content)
|
||||||
|
return node.getBoundingClientRect();
|
||||||
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
let content = this.renderContent()
|
let content = this.renderContent()
|
||||||
|
|
||||||
@@ -97,7 +107,7 @@ class Preferences extends React.Component {
|
|||||||
<div styleName='nav'>
|
<div styleName='nav'>
|
||||||
{navButtons}
|
{navButtons}
|
||||||
</div>
|
</div>
|
||||||
<div styleName='content'>
|
<div ref='content' styleName='content'>
|
||||||
{content}
|
{content}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user