site: update color picker position

This commit is contained in:
afc163 2017-09-04 12:24:40 +08:00
parent 24e2af63f2
commit 6cb3ae46a2
2 changed files with 30 additions and 19 deletions

View File

@ -12,6 +12,7 @@ export default class ColorPicker extends Component {
static defaultProps = {
onChange: noop,
onChangeComplete: noop,
position: 'bottom',
}
constructor(props) {
@ -39,7 +40,7 @@ export default class ColorPicker extends Component {
this.props.onChangeComplete(color.hex);
};
render() {
const { small, type } = this.props;
const { small, type, position } = this.props;
const Picker = pickers[type];
@ -74,25 +75,34 @@ export default class ColorPicker extends Component {
zIndex: '100',
},
};
return (
<div>
<div style={styles.swatch} onClick={this.handleClick}>
<div style={styles.color} />
</div>
{this.state.displayColorPicker ? (
<div style={styles.popover}>
<div style={styles.cover} onClick={this.handleClose} />
<div style={styles.wrapper}>
<Picker
{...this.props}
color={this.state.color}
onChange={this.handleChange}
onChangeComplete={this.handleChangeComplete}
/>
</div>
</div>
) : null}
if (position === 'top') {
styles.wrapper.transform = 'translateY(-100%)';
styles.wrapper.paddingBottom = 8;
}
const swatch = (
<div style={styles.swatch} onClick={this.handleClick}>
<div style={styles.color} />
</div>
);
const picker = this.state.displayColorPicker ? (
<div style={styles.popover}>
<div style={styles.cover} onClick={this.handleClose} />
<div style={styles.wrapper}>
<Picker
{...this.props}
color={this.state.color}
onChange={this.handleChange}
onChangeComplete={this.handleChangeComplete}
/>
</div>
</div>
) : null;
if (position === 'top') {
return <div>{picker}{swatch}</div>;
}
return <div>{swatch}{picker}</div>;
}
}

View File

@ -104,6 +104,7 @@ class Footer extends React.Component {
type="sketch"
small
color={this.state.color}
position="top"
presetColors={[
'#f04134',
'#00a854',