From f866932de56218348d08a341b1c1b28af765e168 Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Sat, 9 Dec 2017 15:07:28 -0700 Subject: [PATCH] Make WordForm float in LeftColumn and closed by default Expands RightColumn display when closed and compresses when open, unless on mobile screen. --- src/components/MainDisplay.jsx | 112 ++++++++++++------ src/components/structure/LeftColumn/index.jsx | 69 +++++++---- .../structure/LeftColumn/styles.scss | 18 ++- src/components/structure/RightColumn.jsx | 25 ++-- 4 files changed, 151 insertions(+), 73 deletions(-) diff --git a/src/components/MainDisplay.jsx b/src/components/MainDisplay.jsx index fdb45d2..e025245 100644 --- a/src/components/MainDisplay.jsx +++ b/src/components/MainDisplay.jsx @@ -1,4 +1,5 @@ import Inferno from 'inferno'; +import Component from 'inferno-component'; import PropTypes from 'prop-types'; import { LeftColumn } from './structure/LeftColumn'; @@ -8,46 +9,83 @@ import { WordForm } from './management/WordForm'; import { DictionaryDetails } from './display/DictionaryDetails'; import { WordsList } from './display/WordsList'; -export const MainDisplay = (props) => { - PropTypes.checkPropTypes({ - dictionaryInfo: PropTypes.object.isRequired, - wordsToDisplay: PropTypes.array.isRequired, - updateDisplay: PropTypes.func.isRequired, - updater: PropTypes.object.isRequired, - }, props, 'prop', 'MainDisplay'); +export class MainDisplay extends Component { + constructor (props) { + super(props); - const { dictionaryInfo, wordsToDisplay, updateDisplay, updater } = props; + PropTypes.checkPropTypes({ + dictionaryInfo: PropTypes.object.isRequired, + wordsToDisplay: PropTypes.array.isRequired, + updateDisplay: PropTypes.func.isRequired, + updater: PropTypes.object.isRequired, + }, props, 'prop', 'MainDisplay'); - return ( -
-
-
- - - - + this.state = { + isMobile: false, + wordFormIsOpen: false, + }; + } - - + openWordForm () { + this.setState({ wordFormIsOpen: true }); + } - - - + closeWordForm () { + this.setState({ wordFormIsOpen: false }); + } + + checkIsMobile () { + this.setState({ isMobile: window.innerWidth < 769 }); + } + + componentDidMount () { + window.addEventListener('resize', this.checkIsMobile.bind(this)); + } + + componentWillUnmount () { + window.removeEventListener('resize'); + } + + render () { + const { dictionaryInfo, wordsToDisplay, updateDisplay, updater } = this.props; + const { isMobile, wordFormIsOpen } = this.state; + + return ( +
+
+
+ + + + + + + + + + + +
-
-
- ); + + ); + } } diff --git a/src/components/structure/LeftColumn/index.jsx b/src/components/structure/LeftColumn/index.jsx index 20dcd24..99f8174 100644 --- a/src/components/structure/LeftColumn/index.jsx +++ b/src/components/structure/LeftColumn/index.jsx @@ -1,32 +1,55 @@ import Inferno from 'inferno'; -import Component from 'inferno-component'; +import PropTypes from 'prop-types'; import { Modal } from '../Modal'; import './styles.scss'; -export class LeftColumn extends Component { - constructor (props) { - super(props); +export const LeftColumn = (props) => { + PropTypes.checkPropTypes({ + isMobile: PropTypes.bool.isRequired, + displayForm: PropTypes.bool.isRequired, + openWordForm: PropTypes.func.isRequired, + closeWordForm: PropTypes.func.isRequired, + children: PropTypes.object, + }, props, 'prop', 'LeftColumn'); - this.isMobile = window.innerWidth < 769; - } + const { isMobile, displayForm, openWordForm, closeWordForm } = props; - render () { - return ( -
- {this.isMobile - ? ( -
- } - > - { this.props.children } - -
- ) : this.props.children - } -
- ); - } + return ( +
+ {isMobile + ? ( +
+ } + > + { props.children } + +
+ ) : ( +
+ {displayForm + ? ( +
+ + + + { props.children } +
+ ) : ( +
+ + + +
+ ) + } +
+ ) + } +
+ ); } diff --git a/src/components/structure/LeftColumn/styles.scss b/src/components/structure/LeftColumn/styles.scss index f40d64a..8c91d44 100644 --- a/src/components/structure/LeftColumn/styles.scss +++ b/src/components/structure/LeftColumn/styles.scss @@ -1,13 +1,29 @@ +@import '../../node_modules/bulma/sass/utilities/initial-variables'; +@import '../../node_modules/bulma/sass/utilities/derived-variables'; @import '../../node_modules/bulma/sass/utilities/mixins'; @import '../../node_modules/bulma/sass/grid/columns'; +@import '../../node_modules/bulma/sass/components/navbar'; -.left-column { +.left-column-open { @extend .column; @extend .is-one-third; } .floating-word-button { + margin: $column-gap; +} + +.floating-word-button, +.floating-word-form { position: fixed; z-index: 2; + top: $navbar-height; left: 0; } + +.floating-word-form { + @extend .column; + @extend .is-one-third; + + overflow-y: auto; +} diff --git a/src/components/structure/RightColumn.jsx b/src/components/structure/RightColumn.jsx index 8f5971b..cd94bc8 100644 --- a/src/components/structure/RightColumn.jsx +++ b/src/components/structure/RightColumn.jsx @@ -1,16 +1,17 @@ import Inferno from 'inferno'; -import Component from 'inferno-component'; +import PropTypes from 'prop-types'; -export class RightColumn extends Component { - constructor (props) { - super(props); - } +export const RightColumn = (props) => { + PropTypes.checkPropTypes({ + formIsDisplayed: PropTypes.bool.isRequired, + children: PropTypes.object, + }, props, 'prop', 'RightColumn'); - render () { - return ( -
- { this.props.children } -
- ); - } + const { formIsDisplayed } = props; + + return ( +
+ { props.children } +
+ ); }