From 0934186ce9c4691025bd3e57cde70d029d616fc0 Mon Sep 17 00:00:00 2001 From: Sean Date: Thu, 13 Dec 2018 16:30:42 -0500 Subject: [PATCH] Fix setting menu movement (#602) --- components/Settings.js | 147 ++++++++++++++++++++++++----------------- components/Slider.js | 10 +-- 2 files changed, 91 insertions(+), 66 deletions(-) diff --git a/components/Settings.js b/components/Settings.js index e8a4968..567efd6 100644 --- a/components/Settings.js +++ b/components/Settings.js @@ -26,7 +26,9 @@ const WindowSettings = React.memo( windowControls, lineNumbers, widthAdjustment, - watermark + watermark, + onWidthChanging, + onWidthChanged }) => { return (
@@ -45,6 +47,8 @@ const WindowSettings = React.memo( label="Padding (horiz)" value={paddingHorizontal} onChange={onChange.bind(null, 'paddingHorizontal')} + onMouseDown={onWidthChanging} + onMouseUp={onWidthChanged} />
{ - return ( -
- - - -
- ) -}) +const TypeSettings = React.memo( + ({ onChange, font, size, lineHeight, onWidthChanging, onWidthChanged }) => { + return ( +
+ + + +
+ ) + } +) const MiscSettings = React.memo(({ format, reset }) => { return ( @@ -411,9 +419,12 @@ class Settings extends React.PureComponent { isVisible: false, selectedMenu: 'Window', showPresets: false, - previousSettings: null + previousSettings: null, + widthChanging: false } + settingsRef = React.createRef() + presetContentRef = React.createRef() componentDidMount() { @@ -431,40 +442,14 @@ class Settings extends React.PureComponent { selectMenu = selectedMenu => () => this.setState({ selectedMenu }) - renderContent = () => { - switch (this.state.selectedMenu) { - case 'Window': - return ( - - ) - case 'Type': - return ( - - ) - case 'Misc': - return - default: - return null - } + handleWidthChanging = () => { + const rect = this.settingsRef.current.getBoundingClientRect() + this.settingPosition = { top: rect.bottom + 12, left: rect.left } + this.setState({ widthChanging: true }) } + handleWidthChanged = () => this.setState({ widthChanging: false }) + handleChange = (key, value) => { this.props.onChange(key, value) this.setState({ previousSettings: null }) @@ -533,12 +518,50 @@ class Settings extends React.PureComponent { savePresets = () => savePresets(localStorage, this.state.presets.filter(p => p.custom)) + renderContent = () => { + switch (this.state.selectedMenu) { + case 'Window': + return ( + + ) + case 'Type': + return ( + + ) + case 'Misc': + return + default: + return null + } + } + render() { - const { isVisible, selectedMenu, showPresets, presets, previousSettings } = this.state + const { isVisible, selectedMenu, showPresets, presets, previousSettings, widthChanging } = this.state const { preset } = this.props return ( -
+
{}, + onMouseUp: () => {} } - handleChange(e) { + handleChange = e => { this.props.onChange(`${e.target.value}${this.props.usePercentage ? '%' : 'px'}`) } @@ -32,6 +32,8 @@ class Slider extends React.Component { type="range" defaultValue={this.props.value} onChange={this.handleChange} + onMouseDown={this.props.onMouseDown} + onMouseUp={this.props.onMouseUp} min={minValue} max={maxValue} step={step}