Files
nebula.js/commands/serve/web/components/Visualize/Search.jsx
Johan Lahti 5e35fb61fd feat(ListBox): break out header and add unlock button (#1466)
* fix: error on esc in search

* fix: reset zoom on iphone on nebula level

* fix: show toolbar when icons demand

* feat: unlock cover btn and break out header

* fix: move option

* feat: move showLock option to public options

* fix: centered svg unlock icon

* fix: listen to lock changes

* fix: search icon show fixes

* fix: hide header correctly

* fix: make text overflow great again

* test: updated expected snapshots

* fix: tweak icon sizes more

* fix: apply header style color

* test: update snapshots

* fix: override text explicitly to make it work

* fix: rtl actions keyboard nav inverted

* fix: keyboard nav for unlock button

* fix: align numerical search results correctly

* fix: recreate header on layout or isLocked change

* fix: give layout to can-funcs to stay up to date

* Update apis/nucleus/src/components/listbox/ListBoxInline.jsx

Co-authored-by: Daniel Sjöstrand <99665802+DanielS-Qlik@users.noreply.github.com>

* refactor: add loading icon and block interaction

* fix: justify center when loading

* fix: adjust spinner timeout

* chore: update specs

* feat: moved translation strings

---------

Co-authored-by: Daniel Sjöstrand <99665802+DanielS-Qlik@users.noreply.github.com>
2024-02-01 16:51:05 +01:00

76 lines
1.9 KiB
JavaScript

import React, { useState } from 'react';
import { styled } from '@mui/material/styles';
import { Grid, TextField } from '@mui/material';
import SearchIcon from '@nebula.js/ui/icons/search';
const PREFIX = 'Search';
const classes = {
gridContainer: `${PREFIX}-gridContainer`,
gridItem: `${PREFIX}-gridItem`,
};
const StyledGrid = styled(Grid)(({ theme }) => ({
[`& .${classes.gridContainer}`]: {
padding: theme.spacing(0, 1, 0, 1),
},
[`& .${classes.gridItem}`]: {
padding: theme.spacing(0, 1, 0, 1),
},
}));
/**
* Run this on small devices to reset the zoom. Required when focusing
* an input field and the browser auto zooms the page. Browsers do not
* expose any API for handling this currently.
*/
function resetZoom() {
const viewportMetaTag = document.querySelector('meta[name="viewport"]');
if (viewportMetaTag instanceof HTMLMetaElement) {
viewportMetaTag.content = 'width=device-width, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0';
}
}
export default function Search({ onChange = () => {}, onEnter = () => {}, onEscape = () => {} }) {
const [value, setValue] = useState('');
const handleChange = (e) => {
setValue(e.target.value);
onChange(e.target.value);
};
const onKeyDown = (e) => {
switch (e.key) {
case 'Enter':
onEnter();
setValue('');
break;
case 'Escape':
onEscape();
break;
default:
break;
}
};
const placeholder = 'Search';
return (
<StyledGrid className={classes.gridContainer} item container direction="row" alignItems="center">
<Grid item>
<SearchIcon />
</Grid>
<Grid className={classes.gridItem} item xs>
<TextField
fullWidth
autoFocus
placeholder={placeholder}
value={value}
onChange={handleChange}
onFocus={resetZoom}
onKeyDown={onKeyDown}
/>
</Grid>
</StyledGrid>
);
}