Fix setting menu movement (#602)

main
Sean 6 years ago committed by Michael Fix
parent f6f0adee6b
commit 0934186ce9

@ -26,7 +26,9 @@ const WindowSettings = React.memo(
windowControls, windowControls,
lineNumbers, lineNumbers,
widthAdjustment, widthAdjustment,
watermark watermark,
onWidthChanging,
onWidthChanged
}) => { }) => {
return ( return (
<div className="settings-content"> <div className="settings-content">
@ -45,6 +47,8 @@ const WindowSettings = React.memo(
label="Padding (horiz)" label="Padding (horiz)"
value={paddingHorizontal} value={paddingHorizontal}
onChange={onChange.bind(null, 'paddingHorizontal')} onChange={onChange.bind(null, 'paddingHorizontal')}
onMouseDown={onWidthChanging}
onMouseUp={onWidthChanged}
/> />
</div> </div>
<Toggle <Toggle
@ -102,29 +106,33 @@ const WindowSettings = React.memo(
} }
) )
const TypeSettings = React.memo(({ onChange, font, size, lineHeight }) => { const TypeSettings = React.memo(
return ( ({ onChange, font, size, lineHeight, onWidthChanging, onWidthChanged }) => {
<div className="settings-content"> return (
<FontSelect selected={font} onChange={onChange.bind(null, 'fontFamily')} /> <div className="settings-content">
<Slider <FontSelect selected={font} onChange={onChange.bind(null, 'fontFamily')} />
label="Size" <Slider
value={size} label="Size"
minValue={10} value={size}
maxValue={18} minValue={10}
step={0.5} maxValue={18}
onChange={onChange.bind(null, 'fontSize')} step={0.5}
/> onChange={onChange.bind(null, 'fontSize')}
<Slider onMouseDown={onWidthChanging}
label="Line height" onMouseUp={onWidthChanged}
value={lineHeight} />
minValue={90} <Slider
maxValue={250} label="Line height"
usePercentage={true} value={lineHeight}
onChange={onChange.bind(null, 'lineHeight')} minValue={90}
/> maxValue={250}
</div> usePercentage={true}
) onChange={onChange.bind(null, 'lineHeight')}
}) />
</div>
)
}
)
const MiscSettings = React.memo(({ format, reset }) => { const MiscSettings = React.memo(({ format, reset }) => {
return ( return (
@ -411,9 +419,12 @@ class Settings extends React.PureComponent {
isVisible: false, isVisible: false,
selectedMenu: 'Window', selectedMenu: 'Window',
showPresets: false, showPresets: false,
previousSettings: null previousSettings: null,
widthChanging: false
} }
settingsRef = React.createRef()
presetContentRef = React.createRef() presetContentRef = React.createRef()
componentDidMount() { componentDidMount() {
@ -431,40 +442,14 @@ class Settings extends React.PureComponent {
selectMenu = selectedMenu => () => this.setState({ selectedMenu }) selectMenu = selectedMenu => () => this.setState({ selectedMenu })
renderContent = () => { handleWidthChanging = () => {
switch (this.state.selectedMenu) { const rect = this.settingsRef.current.getBoundingClientRect()
case 'Window': this.settingPosition = { top: rect.bottom + 12, left: rect.left }
return ( this.setState({ widthChanging: true })
<WindowSettings
onChange={this.handleChange}
windowTheme={this.props.windowTheme}
paddingHorizontal={this.props.paddingHorizontal}
paddingVertical={this.props.paddingVertical}
dropShadow={this.props.dropShadow}
dropShadowBlurRadius={this.props.dropShadowBlurRadius}
dropShadowOffsetY={this.props.dropShadowOffsetY}
windowControls={this.props.windowControls}
lineNumbers={this.props.lineNumbers}
widthAdjustment={this.props.widthAdjustment}
watermark={this.props.watermark}
/>
)
case 'Type':
return (
<TypeSettings
onChange={this.handleChange}
font={this.props.fontFamily}
size={this.props.fontSize}
lineHeight={this.props.lineHeight}
/>
)
case 'Misc':
return <MiscSettings format={this.props.format} reset={this.handleReset} />
default:
return null
}
} }
handleWidthChanged = () => this.setState({ widthChanging: false })
handleChange = (key, value) => { handleChange = (key, value) => {
this.props.onChange(key, value) this.props.onChange(key, value)
this.setState({ previousSettings: null }) this.setState({ previousSettings: null })
@ -533,12 +518,50 @@ class Settings extends React.PureComponent {
savePresets = () => savePresets(localStorage, this.state.presets.filter(p => p.custom)) savePresets = () => savePresets(localStorage, this.state.presets.filter(p => p.custom))
renderContent = () => {
switch (this.state.selectedMenu) {
case 'Window':
return (
<WindowSettings
onChange={this.handleChange}
onWidthChanging={this.handleWidthChanging}
onWidthChanged={this.handleWidthChanged}
windowTheme={this.props.windowTheme}
paddingHorizontal={this.props.paddingHorizontal}
paddingVertical={this.props.paddingVertical}
dropShadow={this.props.dropShadow}
dropShadowBlurRadius={this.props.dropShadowBlurRadius}
dropShadowOffsetY={this.props.dropShadowOffsetY}
windowControls={this.props.windowControls}
lineNumbers={this.props.lineNumbers}
widthAdjustment={this.props.widthAdjustment}
watermark={this.props.watermark}
/>
)
case 'Type':
return (
<TypeSettings
onChange={this.handleChange}
onWidthChanging={this.handleWidthChanging}
onWidthChanged={this.handleWidthChanged}
font={this.props.fontFamily}
size={this.props.fontSize}
lineHeight={this.props.lineHeight}
/>
)
case 'Misc':
return <MiscSettings format={this.props.format} reset={this.handleReset} />
default:
return null
}
}
render() { render() {
const { isVisible, selectedMenu, showPresets, presets, previousSettings } = this.state const { isVisible, selectedMenu, showPresets, presets, previousSettings, widthChanging } = this.state
const { preset } = this.props const { preset } = this.props
return ( return (
<div className="settings-container"> <div className="settings-container" ref={this.settingsRef}>
<div <div
className={`settings-display ${isVisible ? 'is-visible' : ''}`} className={`settings-display ${isVisible ? 'is-visible' : ''}`}
onClick={this.toggleVisible} onClick={this.toggleVisible}
@ -610,9 +633,9 @@ class Settings extends React.PureComponent {
.settings-settings { .settings-settings {
display: none; display: none;
position: absolute; position: ${widthChanging ? 'fixed' : 'absolute'};
top: 52px; top: ${widthChanging ? this.settingPosition.top : 52}px;
left: 0; left: ${widthChanging ? this.settingPosition.left : 0}px;
border: 2px solid ${COLORS.SECONDARY}; border: 2px solid ${COLORS.SECONDARY};
width: 324px; width: 324px;
border-radius: 3px; border-radius: 3px;

@ -3,12 +3,12 @@ import React from 'react'
import { COLORS } from '../lib/constants' import { COLORS } from '../lib/constants'
class Slider extends React.Component { class Slider extends React.Component {
constructor(props) { static defaultProps = {
super(props) onMouseDown: () => {},
this.handleChange = this.handleChange.bind(this) onMouseUp: () => {}
} }
handleChange(e) { handleChange = e => {
this.props.onChange(`${e.target.value}${this.props.usePercentage ? '%' : 'px'}`) this.props.onChange(`${e.target.value}${this.props.usePercentage ? '%' : 'px'}`)
} }
@ -32,6 +32,8 @@ class Slider extends React.Component {
type="range" type="range"
defaultValue={this.props.value} defaultValue={this.props.value}
onChange={this.handleChange} onChange={this.handleChange}
onMouseDown={this.props.onMouseDown}
onMouseUp={this.props.onMouseUp}
min={minValue} min={minValue}
max={maxValue} max={maxValue}
step={step} step={step}

Loading…
Cancel
Save