-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RNMobile] Add inserter block search (#29169)
* Refactor to functional component * Switch to useSelect hook * Switch to useDispatch Switch to useDispatch for insertDefaultBlock Switch to useDispatch for onSelect Switch to useDispatch for showInsertionPoint Remove withDispatch and WithSelect * Simplify clipboard flow * Move menu to search results * Move displaying items to a separate component Pass items to search results as a prop Move show/hide insertion point Move block insertion to menu Fix block insertion * Add insserter search form * Filter blocks by search query * First pass at styling for search Also re-org bottom sheet setup * Simplify search form * Add dev flag to enable search * Move BottomSheetConsumer to the menu * Add ebottom sheet padding for search form * Only show search if there are enough items to filter * Clean up styles * fix lint error Co-authored-by: Jason Johnston <[email protected]>
- Loading branch information
Showing
4 changed files
with
235 additions
and
64 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
92 changes: 92 additions & 0 deletions
92
packages/block-editor/src/components/inserter/search-form.native.js
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 |
---|---|---|
@@ -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( '' ); | ||
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; |
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