diff --git a/src/Helper.js b/src/Helper.js index ff0496b..de99bb6 100644 --- a/src/Helper.js +++ b/src/Helper.js @@ -8,6 +8,10 @@ class Helper { return this.charAt(0).toUpperCase() + this.slice(1); } } + + getLastLetter (string) { + return string.substr(string.length - 1, 1); + } } export default new Helper; diff --git a/src/components/management/IPAField.jsx b/src/components/management/IPAField.jsx new file mode 100644 index 0000000..01825b9 --- /dev/null +++ b/src/components/management/IPAField.jsx @@ -0,0 +1,66 @@ +import Inferno from 'inferno'; +import Component from 'inferno-component'; + +import Helper from '../../Helper'; + +export class IPAField extends Component { + constructor (props) { + super(props); + + this.letterPossibilities = { + "a": ['aaa', 'wow'] + } + + this.state = { + value: '' + , isFocused: false + , shouldDisplay: false + } + } + + checkDisplay () { + const lastLetter = Helper.getLastLetter(this.state.value).toLowerCase(); + const letterHasSuggestions = this.letterPossibilities.hasOwnProperty(lastLetter); + + this.setState({ + shouldDisplay: this.state.isFocused && letterHasSuggestions + }); + } + + listSuggestions () { + if (this.state.shouldDisplay) { + return ( +
+ this.setState({ isFocused: true })} + onBlur={() => this.setState({ isFocused: false })} + onInput={event => { + this.setState({ value: event.target.value }, this.checkDisplay); + }} + onChange={() => this.props.onChange(this.state.value)} /> + + {this.listSuggestions()} +
+- { - this.setState({ wordPronunciation: event.target.value }); - }} /> -
-