From 675f7271642bdddbc008d22678e277c72032bdcd Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Thu, 18 Aug 2022 02:08:21 +0200 Subject: feat(frontend): responsive editor styling --- subprojects/frontend/src/editor/SearchToolbar.tsx | 108 ++++++++++++++++------ 1 file changed, 82 insertions(+), 26 deletions(-) (limited to 'subprojects/frontend/src/editor/SearchToolbar.tsx') diff --git a/subprojects/frontend/src/editor/SearchToolbar.tsx b/subprojects/frontend/src/editor/SearchToolbar.tsx index dd7859c5..a5925328 100644 --- a/subprojects/frontend/src/editor/SearchToolbar.tsx +++ b/subprojects/frontend/src/editor/SearchToolbar.tsx @@ -2,7 +2,6 @@ import CloseIcon from '@mui/icons-material/Close'; import FindReplaceIcon from '@mui/icons-material/FindReplace'; import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown'; import KeyboardArrowUpIcon from '@mui/icons-material/KeyboardArrowUp'; -import SearchIcon from '@mui/icons-material/Search'; import Button from '@mui/material/Button'; import Checkbox from '@mui/material/Checkbox'; import FormControlLabel from '@mui/material/FormControlLabel'; @@ -10,20 +9,31 @@ import FormHelperText from '@mui/material/FormHelperText'; import IconButton from '@mui/material/IconButton'; import Stack from '@mui/material/Stack'; import TextField from '@mui/material/TextField'; +import ToggleButton from '@mui/material/ToggleButton'; import Toolbar from '@mui/material/Toolbar'; +import useMediaQuery from '@mui/material/useMediaQuery'; import { observer } from 'mobx-react-lite'; -import React, { useCallback } from 'react'; +import React, { useCallback, useState } from 'react'; import type SearchPanelStore from './SearchPanelStore'; +const SPLIT_MEDIA_QUERY = '@media (max-width: 1200px)'; +const ABBREVIATE_MEDIA_QUERY = '@media (max-width: 720px)'; + function SearchToolbar({ store }: { store: SearchPanelStore }): JSX.Element { const { id: panelId, query: { search, valid, caseSensitive, literal, regexp, replace }, invalidRegexp, } = store; + const split = useMediaQuery(SPLIT_MEDIA_QUERY); + const abbreviate = useMediaQuery(ABBREVIATE_MEDIA_QUERY); + const [showRepalceState, setShowReplaceState] = useState(false); + + const showReplace = !split || showRepalceState || replace !== ''; const searchHelperId = `${panelId}-search-helper`; + const replaceId = `${panelId}-replace`; const searchFieldRef = useCallback( (element: HTMLInputElement | null) => @@ -32,13 +42,20 @@ function SearchToolbar({ store }: { store: SearchPanelStore }): JSX.Element { ); return ( - + {invalidRegexp && ( @@ -92,6 +109,7 @@ function SearchToolbar({ store }: { store: SearchPanelStore }): JSX.Element { aria-label="Previous" disabled={!valid} onClick={() => store.findPrevious()} + color="inherit" > @@ -99,19 +117,17 @@ function SearchToolbar({ store }: { store: SearchPanelStore }): JSX.Element { aria-label="Next" disabled={!valid} onClick={() => store.findNext()} + color="inherit" > - - + } - label="Match case" + aria-label="Match case" + label={abbreviate ? 'Case' : 'Match case'} /> } - label="Literal" + aria-label="Literal" + label={abbreviate ? 'Lit' : 'Literal'} /> + {split && ( + { + if (showReplace) { + store.updateQuery({ replace: '' }); + setShowReplaceState(false); + } else { + setShowReplaceState(true); + } + }} + aria-label="Show replace options" + aria-controls={replaceId} + size="small" + sx={{ borderRadius: '100%' }} + > + + + )} - + - +