-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RNMobile] Add inserter block search #29169
Changes from all commits
866b791
65548fd
b11163d
38993db
fc15948
6cd98b9
4e3010e
faf0d26
8baadf6
ea5aaa3
0a8d03d
3504864
abd950b
bddeedf
743535d
6cfa7a5
a53a08d
d89e312
e0c871b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { TextInput, View, TouchableHighlight } from 'react-native'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useState, useRef } from '@wordpress/element'; | ||
import { usePreferredColorSchemeStyle } from '@wordpress/compose'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { ToolbarButton } from '@wordpress/components'; | ||
import { | ||
Icon, | ||
cancelCircleFilled, | ||
arrowLeft, | ||
search as searchIcon, | ||
} from '@wordpress/icons'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import styles from './style.scss'; | ||
|
||
function InserterSearchForm( { value, onChange, onLayout = () => {} } ) { | ||
const [ isActive, setIsActive ] = useState( false ); | ||
|
||
const inputRef = useRef(); | ||
|
||
const searchFormStyle = usePreferredColorSchemeStyle( | ||
styles.searchForm, | ||
styles.searchFormDark | ||
); | ||
|
||
const searchFormInputStyle = usePreferredColorSchemeStyle( | ||
styles.searchFormInput, | ||
styles.searchFormInputDark | ||
); | ||
|
||
const placeholderStyle = usePreferredColorSchemeStyle( | ||
styles.searchFormPlaceholder, | ||
styles.searchFormPlaceholderDark | ||
); | ||
|
||
return ( | ||
<TouchableHighlight accessible={ false } onLayout={ onLayout }> | ||
<View style={ searchFormStyle }> | ||
{ isActive ? ( | ||
<ToolbarButton | ||
title={ __( 'Cancel search' ) } | ||
icon={ arrowLeft } | ||
onClick={ () => { | ||
inputRef.current.blur(); | ||
onChange( '' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of curiousity, why default to empty string instead of undefined? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question, I was thinking the same when I looked back at this PR 😆 . After reviewing the changes as they are now I can't find an explicit reason. I believe as some point while I was drafting the changes I was treating I might update the |
||
setIsActive( false ); | ||
} } | ||
/> | ||
) : ( | ||
<ToolbarButton | ||
title={ __( 'Search block' ) } | ||
icon={ searchIcon } | ||
onClick={ () => { | ||
inputRef.current.focus(); | ||
setIsActive( true ); | ||
} } | ||
/> | ||
) } | ||
<TextInput | ||
ref={ inputRef } | ||
style={ searchFormInputStyle } | ||
placeholderTextColor={ placeholderStyle.color } | ||
onChangeText={ onChange } | ||
onFocus={ () => setIsActive( true ) } | ||
value={ value } | ||
placeholder={ __( 'Search blocks' ) } | ||
/> | ||
|
||
{ !! value && ( | ||
<ToolbarButton | ||
title={ __( 'Clear search' ) } | ||
icon={ <Icon icon={ cancelCircleFilled } /> } | ||
onClick={ () => { | ||
onChange( '' ); | ||
} } | ||
/> | ||
) } | ||
</View> | ||
</TouchableHighlight> | ||
); | ||
} | ||
|
||
export default InserterSearchForm; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor thing, but I wonder if instead of using a let here we could used two
const
variables with names that showed how they were different.