From 85521b9e8131fcb64cf9eaafcb80166943cd491f Mon Sep 17 00:00:00 2001 From: Sarah Allen Date: Fri, 29 Mar 2019 15:26:05 -0500 Subject: [PATCH 01/22] Initial button refactor --- .../FieldGuideButton/FieldGuideButton.js | 53 +++++++++---------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/packages/lib-classifier/src/components/Classifier/components/ImageToolbar/components/FieldGuideButton/FieldGuideButton.js b/packages/lib-classifier/src/components/Classifier/components/ImageToolbar/components/FieldGuideButton/FieldGuideButton.js index 2989639c91..5275448dea 100644 --- a/packages/lib-classifier/src/components/Classifier/components/ImageToolbar/components/FieldGuideButton/FieldGuideButton.js +++ b/packages/lib-classifier/src/components/Classifier/components/ImageToolbar/components/FieldGuideButton/FieldGuideButton.js @@ -2,10 +2,11 @@ import { withFocusProps, withHoverProps } from '@klarna/higher-order-components' import { SpacedText } from '@zooniverse/react-components' import zooTheme from '@zooniverse/grommet-theme' import counterpart from 'counterpart' -import { Box } from 'grommet' +import { Button, Box } from 'grommet' import React from 'react' import PropTypes from 'prop-types' import styled from 'styled-components' +import { inject, observer } from 'mobx-react' import en from './locales/en' import HelpIcon from './HelpIcon' @@ -34,44 +35,42 @@ const StyledHelpIcon = styled(HelpIcon)` width: 25px; ` -@withHoverProps({ hovered: true }) -@withFocusProps({ focused: true }) -class FieldGuideButton extends React.Component { - constructor () { - super() - this.onClick = this.onClick.bind(this) +function storeMapper(stores) { + const { active: fieldGuide, setModalVisibility } = stores.classifierStore.fieldGuide + return { + fieldGuide, + setModalVisibility } +} +@inject(storeMapper) +@observer +class FieldGuideButton extends React.Component { onClick () { + const { setModalVisibility } = this.props console.info('Open field guide') + setModalVisibility(true) } render () { const { - focused, - hovered, - onBlur, - onFocus, - onMouseOver, - onMouseOut + fieldGuide, } = this.props + const disabled = !fieldGuide || fieldGuide.items.length === 0 + // const eventHandlers = { + // onBlur, + // onFocus, + // onMouseOver, + // onMouseOut + // } - const eventHandlers = { - onBlur, - onFocus, - onMouseOver, - onMouseOut - } - - const hoveredOrFocused = hovered || focused + // const hoveredOrFocused = hovered || focused return ( - @@ -82,7 +81,7 @@ class FieldGuideButton extends React.Component { - + ) } } From 794738fee05dab46806794988d67a156167b0312 Mon Sep 17 00:00:00 2001 From: Sarah Allen Date: Fri, 29 Mar 2019 15:46:36 -0500 Subject: [PATCH 02/22] Set the label correctly --- .../FieldGuideButton/FieldGuideButton.js | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/packages/lib-classifier/src/components/Classifier/components/ImageToolbar/components/FieldGuideButton/FieldGuideButton.js b/packages/lib-classifier/src/components/Classifier/components/ImageToolbar/components/FieldGuideButton/FieldGuideButton.js index 5275448dea..5dacfc8899 100644 --- a/packages/lib-classifier/src/components/Classifier/components/ImageToolbar/components/FieldGuideButton/FieldGuideButton.js +++ b/packages/lib-classifier/src/components/Classifier/components/ImageToolbar/components/FieldGuideButton/FieldGuideButton.js @@ -35,6 +35,20 @@ const StyledHelpIcon = styled(HelpIcon)` width: 25px; ` +export function ButtonLabel () { + return ( + + + {counterpart('FieldGuideButton.buttonLabel.field')} + + + {counterpart('FieldGuideButton.buttonLabel.guide')} + + + + ) +} + function storeMapper(stores) { const { active: fieldGuide, setModalVisibility } = stores.classifierStore.fieldGuide return { @@ -57,6 +71,8 @@ class FieldGuideButton extends React.Component { fieldGuide, } = this.props const disabled = !fieldGuide || fieldGuide.items.length === 0 + + console.log(disabled, fieldGuide) // const eventHandlers = { // onBlur, // onFocus, @@ -68,20 +84,11 @@ class FieldGuideButton extends React.Component { return ( + primary + /> ) } } From d8f9c781858aee82f3fa21692d6954fd6daf3066 Mon Sep 17 00:00:00 2001 From: Sarah Allen Date: Fri, 29 Mar 2019 16:50:06 -0500 Subject: [PATCH 03/22] Reorganize and start field guide modal --- .../FieldGuide/FieldGuideContainer.js | 73 +++++++++++++++++++ .../FieldGuideContainer.spec.js} | 0 .../components/FieldGuide/FieldGuide.js | 22 ++++++ .../components/FieldGuide/FieldGuide.spec.js | 0 .../FieldGuide/components/FieldGuide/index.js | 1 + .../FieldGuideButton/FieldGuideButton.js | 60 ++++++--------- .../FieldGuideButton/FieldGuideButton.spec.js | 0 .../components/FieldGuideButton/HelpIcon.js | 0 .../components/FieldGuideButton/index.js | 1 + .../FieldGuideButton/locales/en.json | 0 .../Classifier/components/FieldGuide/index.js | 1 + .../components/FieldGuide/locales/en.json | 5 ++ .../components/ImageToolbar/ImageToolbar.js | 4 +- .../components/FieldGuideButton/index.js | 1 - 14 files changed, 129 insertions(+), 39 deletions(-) create mode 100644 packages/lib-classifier/src/components/Classifier/components/FieldGuide/FieldGuideContainer.js rename packages/lib-classifier/src/components/Classifier/components/{ImageToolbar/components/FieldGuideButton/FieldGuideButton.spec.js => FieldGuide/FieldGuideContainer.spec.js} (100%) create mode 100644 packages/lib-classifier/src/components/Classifier/components/FieldGuide/components/FieldGuide/FieldGuide.js create mode 100644 packages/lib-classifier/src/components/Classifier/components/FieldGuide/components/FieldGuide/FieldGuide.spec.js create mode 100644 packages/lib-classifier/src/components/Classifier/components/FieldGuide/components/FieldGuide/index.js rename packages/lib-classifier/src/components/Classifier/components/{ImageToolbar => FieldGuide}/components/FieldGuideButton/FieldGuideButton.js (57%) create mode 100644 packages/lib-classifier/src/components/Classifier/components/FieldGuide/components/FieldGuideButton/FieldGuideButton.spec.js rename packages/lib-classifier/src/components/Classifier/components/{ImageToolbar => FieldGuide}/components/FieldGuideButton/HelpIcon.js (100%) create mode 100644 packages/lib-classifier/src/components/Classifier/components/FieldGuide/components/FieldGuideButton/index.js rename packages/lib-classifier/src/components/Classifier/components/{ImageToolbar => FieldGuide}/components/FieldGuideButton/locales/en.json (100%) create mode 100644 packages/lib-classifier/src/components/Classifier/components/FieldGuide/index.js create mode 100644 packages/lib-classifier/src/components/Classifier/components/FieldGuide/locales/en.json delete mode 100644 packages/lib-classifier/src/components/Classifier/components/ImageToolbar/components/FieldGuideButton/index.js diff --git a/packages/lib-classifier/src/components/Classifier/components/FieldGuide/FieldGuideContainer.js b/packages/lib-classifier/src/components/Classifier/components/FieldGuide/FieldGuideContainer.js new file mode 100644 index 0000000000..3e2bb000d5 --- /dev/null +++ b/packages/lib-classifier/src/components/Classifier/components/FieldGuide/FieldGuideContainer.js @@ -0,0 +1,73 @@ +import { Modal } from '@zooniverse/react-components' +import zooTheme from '@zooniverse/grommet-theme' +import counterpart from 'counterpart' +import { Button, Box } from 'grommet' +import React from 'react' +import PropTypes from 'prop-types' +import styled from 'styled-components' +import { inject, observer } from 'mobx-react' +import FieldGuideButton from './components/FieldGuideButton' +import FieldGuide from './components/FieldGuide' +import en from './locales/en' + +counterpart.registerTranslations('en', en) + +function storeMapper(stores) { + const { active: fieldGuide, setModalVisibility, showModal } = stores.classifierStore.fieldGuide + return { + fieldGuide, + setModalVisibility, + showModal + } +} + +@inject(storeMapper) +@observer +class FieldGuideContainer extends React.Component { + onClose () { + const { setModalVisibility } = this.props + setModalVisibility(false) + } + + render () { + const { + fieldGuide, + showModal + } = this.props + + return ( + <> + + + + + + ) + } +} + +FieldGuideContainer.wrappedComponent.defaultProps = { + fieldGuide: { + items: [] + }, + showModal: false +} + +FieldGuideContainer.propTypes = { + fieldGuide: PropTypes.shape({ + items: PropTypes.array + }), + setModalVisibility: PropTypes.func.isRequired, + showModal: PropTypes.bool +} + +// FieldGuide.propTypes = { +// eventHandlers: PropTypes.object, +// hoverOrFocus: PropTypes.bool +// } + +export default FieldGuideContainer diff --git a/packages/lib-classifier/src/components/Classifier/components/ImageToolbar/components/FieldGuideButton/FieldGuideButton.spec.js b/packages/lib-classifier/src/components/Classifier/components/FieldGuide/FieldGuideContainer.spec.js similarity index 100% rename from packages/lib-classifier/src/components/Classifier/components/ImageToolbar/components/FieldGuideButton/FieldGuideButton.spec.js rename to packages/lib-classifier/src/components/Classifier/components/FieldGuide/FieldGuideContainer.spec.js diff --git a/packages/lib-classifier/src/components/Classifier/components/FieldGuide/components/FieldGuide/FieldGuide.js b/packages/lib-classifier/src/components/Classifier/components/FieldGuide/components/FieldGuide/FieldGuide.js new file mode 100644 index 0000000000..e4d46945b9 --- /dev/null +++ b/packages/lib-classifier/src/components/Classifier/components/FieldGuide/components/FieldGuide/FieldGuide.js @@ -0,0 +1,22 @@ +import zooTheme from '@zooniverse/grommet-theme' +import counterpart from 'counterpart' +import { Button, Box } from 'grommet' +import React from 'react' +import { Markdownz } from '@zooniverse/react-components' +import PropTypes from 'prop-types' +import styled from 'styled-components' +import { inject, observer } from 'mobx-react' + +export default function FieldGuide ({ items }) { + return ( + + {items.map((item) => { + return ( + + {item.content} + + ) + })} + + ) +} \ No newline at end of file diff --git a/packages/lib-classifier/src/components/Classifier/components/FieldGuide/components/FieldGuide/FieldGuide.spec.js b/packages/lib-classifier/src/components/Classifier/components/FieldGuide/components/FieldGuide/FieldGuide.spec.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/lib-classifier/src/components/Classifier/components/FieldGuide/components/FieldGuide/index.js b/packages/lib-classifier/src/components/Classifier/components/FieldGuide/components/FieldGuide/index.js new file mode 100644 index 0000000000..8a9512b85c --- /dev/null +++ b/packages/lib-classifier/src/components/Classifier/components/FieldGuide/components/FieldGuide/index.js @@ -0,0 +1 @@ +export { default } from './FieldGuide' \ No newline at end of file diff --git a/packages/lib-classifier/src/components/Classifier/components/ImageToolbar/components/FieldGuideButton/FieldGuideButton.js b/packages/lib-classifier/src/components/Classifier/components/FieldGuide/components/FieldGuideButton/FieldGuideButton.js similarity index 57% rename from packages/lib-classifier/src/components/Classifier/components/ImageToolbar/components/FieldGuideButton/FieldGuideButton.js rename to packages/lib-classifier/src/components/Classifier/components/FieldGuide/components/FieldGuideButton/FieldGuideButton.js index 5dacfc8899..b916ba3d76 100644 --- a/packages/lib-classifier/src/components/Classifier/components/ImageToolbar/components/FieldGuideButton/FieldGuideButton.js +++ b/packages/lib-classifier/src/components/Classifier/components/FieldGuide/components/FieldGuideButton/FieldGuideButton.js @@ -1,4 +1,3 @@ -import { withFocusProps, withHoverProps } from '@klarna/higher-order-components' import { SpacedText } from '@zooniverse/react-components' import zooTheme from '@zooniverse/grommet-theme' import counterpart from 'counterpart' @@ -6,6 +5,7 @@ import { Button, Box } from 'grommet' import React from 'react' import PropTypes from 'prop-types' import styled from 'styled-components' +import { tint } from 'polished' import { inject, observer } from 'mobx-react' import en from './locales/en' @@ -13,15 +13,13 @@ import HelpIcon from './HelpIcon' counterpart.registerTranslations('en', en) -const StyledButton = styled.button` - height: auto; - flex-direction: column; - display: flex; - align-items: center; - padding: 10px; - background: ${zooTheme.global.colors.brand} - border: 0; +const StyledButton = styled(Button)` + background: ${zooTheme.global.colors.brand}; padding: 15px 10px; + + &:hover, &:focus { + background: ${tint(0.5, zooTheme.global.colors.brand)}; + } ` const StyledSpacedText = styled(SpacedText)` @@ -36,17 +34,17 @@ const StyledHelpIcon = styled(HelpIcon)` ` export function ButtonLabel () { - return ( - - - {counterpart('FieldGuideButton.buttonLabel.field')} - - - {counterpart('FieldGuideButton.buttonLabel.guide')} - - - - ) + return ( + + + {counterpart('FieldGuideButton.buttonLabel.field')} + + + {counterpart('FieldGuideButton.buttonLabel.guide')} + + + + ) } function storeMapper(stores) { @@ -72,30 +70,20 @@ class FieldGuideButton extends React.Component { } = this.props const disabled = !fieldGuide || fieldGuide.items.length === 0 - console.log(disabled, fieldGuide) - // const eventHandlers = { - // onBlur, - // onFocus, - // onMouseOver, - // onMouseOut - // } - - // const hoveredOrFocused = hovered || focused - return ( -