1- import { createStyles , IconButton , makeStyles , Tooltip } from '@material-ui/core'
1+ import { createStyles , IconButton , makeStyles } from '@material-ui/core'
22import Clear from '@material-ui/icons/Clear'
33import Search from '@material-ui/icons/Search'
44import { debounce } from '@sensenet/client-utils'
@@ -10,7 +10,7 @@ import Autosuggest, { SuggestionSelectedEventData, SuggestionsFetchRequestedPara
1010import { useHistory } from 'react-router-dom'
1111import { ResponsiveContext , ResponsivePersonalSettings } from '../../context'
1212import { globals } from '../../globalStyles'
13- import { useLocalization , useSelectionService , useSnRoute , useTheme } from '../../hooks'
13+ import { useLocalization , useSelectionService , useSnRoute } from '../../hooks'
1414import { CommandProviderManager } from '../../services'
1515import { ContentContextMenu } from '../context-menu/content-context-menu'
1616import { CommandPaletteHitsContainer } from './CommandPaletteHitsContainer'
@@ -26,7 +26,7 @@ export interface CommandPaletteItem {
2626 parameters ?: string [ ]
2727}
2828
29- const useStyles = makeStyles ( ( ) => {
29+ const useStyles = makeStyles ( ( theme ) => {
3030 return createStyles ( {
3131 buttonWrapper : {
3232 display : 'flex' ,
@@ -37,6 +37,9 @@ const useStyles = makeStyles(() => {
3737 '& .MuiIconButton-root' : {
3838 color : globals . common . headerText ,
3939 } ,
40+ [ theme . breakpoints . down ( 'sm' ) ] : {
41+ flex : '0 0 auto' ,
42+ } ,
4043 } ,
4144 iconButton : {
4245 color : globals . common . headerText ,
@@ -48,6 +51,23 @@ const useStyles = makeStyles(() => {
4851 width : '50%' ,
4952 marginRight : '9px' ,
5053 } ,
54+ mobileComboBox : {
55+ position : 'absolute' ,
56+ top : globals . common . headerHeight ,
57+ left : 0 ,
58+ right : 0 ,
59+ zIndex : theme . zIndex . appBar + 1 ,
60+ width : 'auto' ,
61+ marginRight : 0 ,
62+ padding : '6px 8px' ,
63+ boxSizing : 'border-box' ,
64+ backgroundColor : globals . common . headerBackground ,
65+ boxShadow : theme . shadows [ 2 ] ,
66+ } ,
67+ mobileOpenButton : {
68+ padding : '8px' ,
69+ marginRight : '2px' ,
70+ } ,
5171 input : {
5272 color : 'white' ,
5373 backgroundColor : '#016ea5ff' ,
@@ -94,7 +114,6 @@ export const CommandPalette = () => {
94114 const [ items , setItems ] = useState < CommandPaletteItem [ ] > ( [ ] )
95115 const [ inputValue , setInputValue ] = useState ( '' )
96116 const localization = useLocalization ( ) . commandPalette
97- const theme = useTheme ( )
98117 const history = useHistory ( )
99118 const classes = useStyles ( )
100119 const device = useContext ( ResponsiveContext )
@@ -237,6 +256,8 @@ export const CommandPalette = () => {
237256 }
238257
239258 const actionMode = inputValue . startsWith ( '>' )
259+ const isMobile = device === 'mobile'
260+ const showCollapsedMobileSearch = isMobile && ! isOpened
240261 const actionContextHeader = actionMode ? (
241262 < div className = { classes . actionContextHeader } data-test = "command-palette-action-context" >
242263 { activeContent ? (
@@ -255,72 +276,87 @@ export const CommandPalette = () => {
255276
256277 return (
257278 < div className = { classes . buttonWrapper } >
258- < div ref = { containerRef } className = { classes . comboBox } data-test = "command-box" >
259- < Autosuggest < CommandPaletteItem >
260- theme = { {
261- suggestionsList : {
262- listStyle : 'none' ,
263- margin : 0 ,
264- padding : 0 ,
265- } ,
266- inputFocused : {
267- outlineWidth : 0 ,
268- } ,
269- } }
270- alwaysRenderSuggestions = { isOpened }
271- suggestions = { items }
272- highlightFirstSuggestion = { true }
273- onSuggestionSelected = { handleSelectSuggestion }
274- onSuggestionsFetchRequested = { handleSuggestionsFetchRequested }
275- onSuggestionsClearRequested = { ( ) => setItems ( [ ] ) }
276- getSuggestionValue = { ( suggestion ) => suggestion . primaryText }
277- renderSuggestion = { ( suggestion , params ) => (
278- < CommandPaletteSuggestion
279- suggestion = { suggestion }
280- params = { params }
281- onOpenContextMenu = { handleOpenSuggestionContextMenu }
282- />
279+ { showCollapsedMobileSearch ? (
280+ < IconButton
281+ aria-label = { localization . title }
282+ title = { localization . title }
283+ className = { classes . mobileOpenButton }
284+ onClick = { ( ) => setIsOpened ( true ) }
285+ data-test = "command-palette-mobile-open" >
286+ < Search />
287+ </ IconButton >
288+ ) : (
289+ < div
290+ ref = { containerRef }
291+ className = { clsx ( classes . comboBox , isMobile && classes . mobileComboBox ) }
292+ data-test = "command-box" >
293+ < Autosuggest < CommandPaletteItem >
294+ theme = { {
295+ suggestionsList : {
296+ listStyle : 'none' ,
297+ margin : 0 ,
298+ padding : 0 ,
299+ } ,
300+ inputFocused : {
301+ outlineWidth : 0 ,
302+ } ,
303+ } }
304+ alwaysRenderSuggestions = { isOpened }
305+ suggestions = { items }
306+ highlightFirstSuggestion = { true }
307+ onSuggestionSelected = { handleSelectSuggestion }
308+ onSuggestionsFetchRequested = { handleSuggestionsFetchRequested }
309+ onSuggestionsClearRequested = { ( ) => setItems ( [ ] ) }
310+ getSuggestionValue = { ( suggestion ) => suggestion . primaryText }
311+ renderSuggestion = { ( suggestion , params ) => (
312+ < CommandPaletteSuggestion
313+ suggestion = { suggestion }
314+ params = { params }
315+ onOpenContextMenu = { handleOpenSuggestionContextMenu }
316+ />
317+ ) }
318+ renderSuggestionsContainer = { ( params ) => (
319+ < CommandPaletteHitsContainer { ...params } header = { actionContextHeader } />
320+ ) }
321+ inputProps = { {
322+ className : `${ classes . input } ${ inputValue ? classes . inputOpened : '' } ` ,
323+ value : inputValue ,
324+ placeholder : localization . title ,
325+ onChange : ( _ev , changeEvent ) => {
326+ setInputValue ( changeEvent . newValue )
327+ } ,
328+ id : 'CommandBoxInput' ,
329+ spellCheck : false ,
330+ onBlur : ( ) => {
331+ if ( ! isContextMenuInteractingRef . current ) {
332+ setIsOpened ( false )
333+ }
334+ } ,
335+ } }
336+ />
337+ { ! inputValue && (
338+ < IconButton
339+ title = { localization . title }
340+ style = { { position : 'absolute' , right : '8px' , zIndex : 2 , top : '50%' , transform : 'translateY(-50%)' } }
341+ onMouseDown = { ( ev ) => ev . preventDefault ( ) } >
342+ < Search />
343+ </ IconButton >
283344 ) }
284- renderSuggestionsContainer = { ( params ) => (
285- < CommandPaletteHitsContainer { ...params } header = { actionContextHeader } />
345+ { inputValue && (
346+ < IconButton
347+ title = { localization . clear }
348+ style = { { position : 'absolute' , right : '8px' , zIndex : 2 , top : '50%' , transform : 'translateY(-50%)' } }
349+ onClick = { ( ) => {
350+ setInputValue ( '' )
351+ setItems ( [ ] )
352+ handleSuggestionsFetchRequested ( { value : '' , reason : 'input-changed' } )
353+ } }
354+ onMouseDown = { ( ev ) => ev . preventDefault ( ) } >
355+ < Clear />
356+ </ IconButton >
286357 ) }
287- inputProps = { {
288- className : `${ classes . input } ${ inputValue ? classes . inputOpened : '' } ` ,
289- value : inputValue ,
290- placeholder : 'Search' ,
291- onChange : ( _ev , changeEvent ) => {
292- setInputValue ( changeEvent . newValue )
293- } ,
294- id : 'CommandBoxInput' ,
295- spellCheck : false ,
296- onBlur : ( ) => {
297- if ( ! isContextMenuInteractingRef . current ) {
298- setIsOpened ( false )
299- }
300- } ,
301- } }
302- />
303- { ! inputValue && (
304- < IconButton
305- title = { 'search' }
306- style = { { position : 'absolute' , right : '0px' , zIndex : 2 , top : '50%' , transform : 'translateY(-50%)' } } >
307- < Search />
308- </ IconButton >
309- ) }
310- { inputValue && (
311- < IconButton
312- title = { localization . clear }
313- style = { { position : 'absolute' , right : '0px' , zIndex : 2 , top : '50%' , transform : 'translateY(-50%)' } }
314- onClick = { ( ) => {
315- setInputValue ( '' )
316- setItems ( [ ] )
317- handleSuggestionsFetchRequested ( { value : '' , reason : 'input-changed' } )
318- } }
319- onMouseDown = { ( ev ) => ev . preventDefault ( ) } >
320- < Clear />
321- </ IconButton >
322- ) }
323- </ div >
358+ </ div >
359+ ) }
324360 { contextMenuContent ? (
325361 < ContentContextMenu
326362 isOpened = { isContextMenuOpened }
0 commit comments