From 1badaced348ac54f50d4dd1a979e4f833ddc0540 Mon Sep 17 00:00:00 2001 From: Mael Date: Thu, 26 Apr 2018 16:08:09 +0200 Subject: [PATCH] :sparkles: Externalisation des suggestions --- source/components/conversation/Input.js | 43 +++---------------- .../conversation/InputSuggestions.css | 24 +++++++++++ .../conversation/InputSuggestions.js | 43 +++++++++++++++++++ .../components/conversation/conversation.css | 23 ---------- 4 files changed, 74 insertions(+), 59 deletions(-) create mode 100644 source/components/conversation/InputSuggestions.css create mode 100644 source/components/conversation/InputSuggestions.js diff --git a/source/components/conversation/Input.js b/source/components/conversation/Input.js index ba9262509..967362045 100644 --- a/source/components/conversation/Input.js +++ b/source/components/conversation/Input.js @@ -1,10 +1,10 @@ import React, { Component } from 'react' -import { Trans, translate } from 'react-i18next' +import { translate } from 'react-i18next' import PropTypes from 'prop-types' import { FormDecorator } from './FormDecorator' import classnames from 'classnames' -import { toPairs } from 'ramda' import SendButton from './SendButton' +import InputSuggestions from './InputSuggestions' @FormDecorator('input') @translate() @@ -12,9 +12,6 @@ export default class Input extends Component { static contextTypes = { i18n: PropTypes.object.isRequired } - state = { - suggestion: null - } render() { let { input, @@ -61,39 +58,13 @@ export default class Input extends Component { {...{ disabled: submitDisabled, themeColours, error, submit }} /> - - {this.renderSuggestions(themeColours)} + this.props.setFormValue('' + value)} + onSecondClick={() => this.props.submit('suggestion')} + /> {inputError && {error}} ) } - - renderSuggestions(themeColours) { - let { setFormValue, suggestions, inverted } = this.props, - { i18n } = this.context - - if (!suggestions || inverted) return null - return ( -
- suggestions: -
    - {toPairs(suggestions).map(([text, value]) => ( -
  • { - setFormValue('' + value) - if (this.state.suggestion !== value) - this.setState({ suggestion: value }) - else this.props.submit('suggestion') - }} - style={{ color: themeColours.textColourOnWhite }}> - - {text} - -
  • - ))} -
-
- ) - } } diff --git a/source/components/conversation/InputSuggestions.css b/source/components/conversation/InputSuggestions.css new file mode 100644 index 000000000..de8dec706 --- /dev/null +++ b/source/components/conversation/InputSuggestions.css @@ -0,0 +1,24 @@ + +.inputSuggestions { + font-style: italic; + float: right; + clear: right; + font-size: 90%; + color: #222; +} +.inputSuggestions ul { + padding-left: 0; + list-style: none; + display: inline-flex; + align-items: flex-end; +} +.inputSuggestions li { +} +.inputSuggestions span { + padding: 0.1em 0.9em; + font-weight: 600; + cursor: pointer; +} +.inputSuggestions span:hover { + text-decoration: none; +} diff --git a/source/components/conversation/InputSuggestions.js b/source/components/conversation/InputSuggestions.js new file mode 100644 index 000000000..cb95ae202 --- /dev/null +++ b/source/components/conversation/InputSuggestions.js @@ -0,0 +1,43 @@ +import React, { Component } from 'react' +import './InputSuggestions.css' +import withColours from '../withColours' +import { toPairs } from 'ramda' +import { translate } from 'react-i18next' +import PropTypes from 'prop-types' + +@withColours +@translate() +export default class extends Component { + static contextTypes = { + i18n: PropTypes.object.isRequired + } + state = { suggestion: null } + render() { + let { suggestions, onSecondClick, onFirstClick } = this.props, + { i18n } = this.context + + if (!suggestions) return null + return ( +
+ suggestions: +
    + {toPairs(suggestions).map(([text, value]) => ( +
  • { + onFirstClick(value) + if (this.state.suggestion !== value) + this.setState({ suggestion: value }) + else onSecondClick(value) + }} + style={{ color: this.props.colours.textColourOnWhite }}> + + {text} + +
  • + ))} +
+
+ ) + } +} diff --git a/source/components/conversation/conversation.css b/source/components/conversation/conversation.css index 9ae05321a..d42230c8b 100644 --- a/source/components/conversation/conversation.css +++ b/source/components/conversation/conversation.css @@ -247,29 +247,6 @@ outline: none; } -.step .inputSuggestions { - font-style: italic; - float: right; - clear: right; - font-size: 90%; - color: #222; -} -.step .inputSuggestions ul { - padding-left: 0; - list-style: none; - display: inline-flex; - align-items: flex-end; -} -.step .inputSuggestions li { -} -.step .inputSuggestions span { - padding: 0.1em 0.9em; - font-weight: 600; - cursor: pointer; -} -.step .inputSuggestions span:hover { - text-decoration: none; -} .help-box { position: absolute;