-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e941db3
commit 52beacf
Showing
13 changed files
with
530 additions
and
415 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,74 @@ | ||
import { __ } from '@wordpress/i18n'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { useRef, useEffect, useState, memo } from '@wordpress/element'; | ||
|
||
/** | ||
* Interface Text Inputs with standard design. | ||
* | ||
* @returns | ||
* @param root0 | ||
* @param root0.title | ||
* @param root0.hint | ||
* @param root0.placeholder | ||
* @param root0.height | ||
* @param root0.maxCharacters | ||
* @param root0.textValue | ||
* @param root0.textValueSetter | ||
* @return | ||
*/ | ||
const TextInput = ({ title, hint, placeholder, height, maxCharacters, textValue, textValueSetter }) => { | ||
const TextInput = ( { | ||
title, | ||
hint, | ||
placeholder, | ||
height, | ||
maxCharacters, | ||
textValue, | ||
textValueSetter, | ||
} ) => { | ||
const textareaRef = useRef( null ); | ||
const [ inputText, setInputText ] = useState( 'nfd-input__field' ); | ||
|
||
const textareaRef = useRef(null); | ||
const [inputText, setInputText] = useState("nfd-input__field"); | ||
useEffect( () => { | ||
textareaRef.current.style.height = height; | ||
const scrollHeight = textareaRef.current.scrollHeight; | ||
textareaRef.current.style.height = scrollHeight + 'px'; | ||
}, [ textValue ] ); | ||
|
||
useEffect(() => { | ||
textareaRef.current.style.height = height; | ||
const scrollHeight = textareaRef.current.scrollHeight; | ||
textareaRef.current.style.height = scrollHeight + "px"; | ||
}, [textValue]); | ||
const onTextChange = ( e ) => { | ||
e.preventDefault(); | ||
textValueSetter( e.target.value ); | ||
|
||
const onTextChange = (e) => { | ||
e.preventDefault(); | ||
textValueSetter(e.target.value); | ||
|
||
e.target.value.length == maxCharacters ? | ||
setInputText("nfd-input__field nfd-input__field_error") : | ||
setInputText("nfd-input__field") | ||
} | ||
e.target.value.length == maxCharacters | ||
? setInputText( 'nfd-input__field nfd-input__field_error' ) | ||
: setInputText( 'nfd-input__field' ); | ||
}; | ||
|
||
return ( | ||
<div className='nfd-input'> | ||
<label> | ||
<div className='nfd-input__label'> | ||
<p className='nfd-input__label_title'>{__( | ||
title, | ||
'wp-module-onboarding' | ||
)}</p> | ||
<p className='nfd-input__label_maxChar'>{`(${maxCharacters - textValue?.length} characters left)`}</p> | ||
</div> | ||
<textarea | ||
type="text" | ||
className={inputText} | ||
ref={textareaRef} | ||
style={{height: height}} | ||
placeholder={placeholder} | ||
value={textValue} | ||
maxLength={maxCharacters} | ||
onChange={(e) => onTextChange(e)} | ||
/> | ||
<p className='nfd-input__hint'>{__( | ||
hint, | ||
'wp-module-onboarding' | ||
)}</p> | ||
</label> | ||
</div> | ||
); | ||
return ( | ||
<div className="nfd-input"> | ||
<label> | ||
<div className="nfd-input__label"> | ||
<p className="nfd-input__label_title"> | ||
{ __( title, 'wp-module-onboarding' ) } | ||
</p> | ||
<p className="nfd-input__label_maxChar">{ `(${ | ||
maxCharacters - textValue?.length | ||
} characters left)` }</p> | ||
</div> | ||
<textarea | ||
type="text" | ||
className={ inputText } | ||
ref={ textareaRef } | ||
style={ { height } } | ||
placeholder={ placeholder } | ||
value={ textValue } | ||
maxLength={ maxCharacters } | ||
onChange={ ( e ) => onTextChange( e ) } | ||
/> | ||
<p className="nfd-input__hint"> | ||
{ __( hint, 'wp-module-onboarding' ) } | ||
</p> | ||
</label> | ||
</div> | ||
); | ||
}; | ||
|
||
const TextInputMemo = memo(TextInput) | ||
const TextInputMemo = memo( TextInput ); | ||
export default TextInputMemo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.