Update OptIn component to use arrow func properties
parent
6ab5b77f89
commit
2b2f07eb1c
|
@ -5,24 +5,22 @@ import onClickOutside from 'shared/components/OnClickOutside'
|
||||||
class ClickOutsideInput extends Component {
|
class ClickOutsideInput extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
this.handleClickOutside = ::this.handleClickOutside
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleClickOutside(e) {
|
handleClickOutside = e => {
|
||||||
this.props.handleClickOutsideCustomValueInput(e)
|
this.props.handleClickOutsideInput(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
id,
|
id,
|
||||||
type,
|
type,
|
||||||
customPlaceholder,
|
|
||||||
onGetRef,
|
|
||||||
customValue,
|
|
||||||
onFocus,
|
onFocus,
|
||||||
onChange,
|
onChange,
|
||||||
|
onGetRef,
|
||||||
onKeyDown,
|
onKeyDown,
|
||||||
|
customValue,
|
||||||
|
customPlaceholder,
|
||||||
} = this.props
|
} = this.props
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -53,7 +51,7 @@ ClickOutsideInput.propTypes = {
|
||||||
onFocus: func.isRequired,
|
onFocus: func.isRequired,
|
||||||
onChange: func.isRequired,
|
onChange: func.isRequired,
|
||||||
onKeyDown: func.isRequired,
|
onKeyDown: func.isRequired,
|
||||||
handleClickOutsideCustomValueInput: func.isRequired,
|
handleClickOutsideInput: func.isRequired,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default onClickOutside(ClickOutsideInput)
|
export default onClickOutside(ClickOutsideInput)
|
||||||
|
|
|
@ -19,77 +19,57 @@ class OptIn extends Component {
|
||||||
|
|
||||||
this.id = uuid.v4()
|
this.id = uuid.v4()
|
||||||
this.isCustomValueInputFocused = false
|
this.isCustomValueInputFocused = false
|
||||||
|
|
||||||
this.useFixedValue = ::this.useFixedValue
|
|
||||||
this.useCustomValue = ::this.useCustomValue
|
|
||||||
this.considerResetCustomValue = ::this.considerResetCustomValue
|
|
||||||
this.setCustomValue = ::this.setCustomValue
|
|
||||||
this.setValue = ::this.setValue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
useFixedValue() {
|
useFixedValue = () => {
|
||||||
this.setState({useCustomValue: false, customValue: ''}, () =>
|
this.setState({useCustomValue: false, customValue: ''}, () =>
|
||||||
this.setValue()
|
this.setValue()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
useCustomValue() {
|
useCustomValue = () => {
|
||||||
this.setState({useCustomValue: true}, () => this.setValue())
|
this.setState({useCustomValue: true}, () => this.setValue())
|
||||||
}
|
}
|
||||||
|
|
||||||
handleClickFixedValueField() {
|
handleClickToggle = () => {
|
||||||
return () => this.useFixedValue()
|
const useCustomValueNext = !this.state.useCustomValue
|
||||||
}
|
if (useCustomValueNext) {
|
||||||
|
|
||||||
handleClickToggle() {
|
|
||||||
return () => {
|
|
||||||
const useCustomValueNext = !this.state.useCustomValue
|
|
||||||
if (useCustomValueNext) {
|
|
||||||
this.useCustomValue()
|
|
||||||
this.customValueInput.focus()
|
|
||||||
} else {
|
|
||||||
this.useFixedValue()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
handleFocusCustomValueInput() {
|
|
||||||
return () => {
|
|
||||||
this.isCustomValueInputFocused = true
|
|
||||||
this.useCustomValue()
|
this.useCustomValue()
|
||||||
|
this.customValueInput.focus()
|
||||||
|
} else {
|
||||||
|
this.useFixedValue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChangeCustomValue() {
|
handleFocusCustomValueInput = () => {
|
||||||
return e => {
|
this.isCustomValueInputFocused = true
|
||||||
this.setCustomValue(e.target.value)
|
this.useCustomValue()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleKeyDownCustomValueInput() {
|
handleChangeCustomValue = e => {
|
||||||
return e => {
|
this.setCustomValue(e.target.value)
|
||||||
if (e.key === 'Enter' || e.key === 'Tab') {
|
}
|
||||||
if (e.key === 'Enter') {
|
|
||||||
this.customValueInput.blur()
|
handleKeyDownCustomValueInput = e => {
|
||||||
}
|
if (e.key === 'Enter' || e.key === 'Tab') {
|
||||||
this.considerResetCustomValue()
|
if (e.key === 'Enter') {
|
||||||
|
this.customValueInput.blur()
|
||||||
}
|
}
|
||||||
|
this.considerResetCustomValue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleClickOutsideCustomValueInput() {
|
handleClickOutsideInput = e => {
|
||||||
return e => {
|
if (
|
||||||
if (
|
e.target.id !== this.grooveKnob.id &&
|
||||||
e.target.id !== this.grooveKnob.id &&
|
e.target.id !== this.grooveKnobContainer.id &&
|
||||||
e.target.id !== this.grooveKnobContainer.id &&
|
this.isCustomValueInputFocused
|
||||||
this.isCustomValueInputFocused
|
) {
|
||||||
) {
|
this.considerResetCustomValue()
|
||||||
this.considerResetCustomValue()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
considerResetCustomValue() {
|
considerResetCustomValue = () => {
|
||||||
const customValue = this.customValueInput.value.trim()
|
const customValue = this.customValueInput.value.trim()
|
||||||
|
|
||||||
this.setState({customValue})
|
this.setState({customValue})
|
||||||
|
@ -101,11 +81,11 @@ class OptIn extends Component {
|
||||||
this.isCustomValueInputFocused = false
|
this.isCustomValueInputFocused = false
|
||||||
}
|
}
|
||||||
|
|
||||||
setCustomValue(value) {
|
setCustomValue = value => {
|
||||||
this.setState({customValue: value}, this.setValue)
|
this.setState({customValue: value}, this.setValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
setValue() {
|
setValue = () => {
|
||||||
const {onSetValue} = this.props
|
const {onSetValue} = this.props
|
||||||
const {useCustomValue, fixedValue, customValue} = this.state
|
const {useCustomValue, fixedValue, customValue} = this.state
|
||||||
|
|
||||||
|
@ -116,6 +96,8 @@ class OptIn extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleInputRef = el => (this.customValueInput = el)
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {fixedPlaceholder, customPlaceholder, type} = this.props
|
const {fixedPlaceholder, customPlaceholder, type} = this.props
|
||||||
const {useCustomValue, customValue} = this.state
|
const {useCustomValue, customValue} = this.state
|
||||||
|
@ -129,20 +111,20 @@ class OptIn extends Component {
|
||||||
<ClickOutsideInput
|
<ClickOutsideInput
|
||||||
id={this.id}
|
id={this.id}
|
||||||
type={type}
|
type={type}
|
||||||
customPlaceholder={customPlaceholder}
|
|
||||||
customValue={customValue}
|
customValue={customValue}
|
||||||
onGetRef={el => (this.customValueInput = el)}
|
onGetRef={this.handleInputRef}
|
||||||
onFocus={this.handleFocusCustomValueInput()}
|
customPlaceholder={customPlaceholder}
|
||||||
onChange={this.handleChangeCustomValue()}
|
onChange={this.handleChangeCustomValue}
|
||||||
onKeyDown={this.handleKeyDownCustomValueInput()}
|
onFocus={this.handleFocusCustomValueInput}
|
||||||
handleClickOutsideCustomValueInput={this.handleClickOutsideCustomValueInput()}
|
onKeyDown={this.handleKeyDownCustomValueInput}
|
||||||
|
handleClickOutsideInput={this.handleClickOutsideInput}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
className="opt-in--groove-knob-container"
|
className="opt-in--groove-knob-container"
|
||||||
id={this.id}
|
id={this.id}
|
||||||
ref={el => (this.grooveKnobContainer = el)}
|
ref={el => (this.grooveKnobContainer = el)}
|
||||||
onClick={this.handleClickToggle()}
|
onClick={this.handleClickToggle}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className="opt-in--groove-knob"
|
className="opt-in--groove-knob"
|
||||||
|
@ -150,10 +132,7 @@ class OptIn extends Component {
|
||||||
ref={el => (this.grooveKnob = el)}
|
ref={el => (this.grooveKnob = el)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div className="opt-in--left-label" onClick={this.useFixedValue}>
|
||||||
className="opt-in--left-label"
|
|
||||||
onClick={this.handleClickFixedValueField()}
|
|
||||||
>
|
|
||||||
{fixedPlaceholder}
|
{fixedPlaceholder}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue