mirror of
https://github.com/qlik-oss/nebula.js.git
synced 2026-05-30 16:00:18 -04:00
57 lines
1.3 KiB
JavaScript
57 lines
1.3 KiB
JavaScript
import React, { useState } from 'react';
|
|
import { Grid, TextField } from '@material-ui/core';
|
|
import SearchIcon from '@nebula.js/ui/icons/search';
|
|
|
|
import { makeStyles } from '@nebula.js/ui/theme';
|
|
|
|
const useStyles = makeStyles(theme => ({
|
|
gridContainer: {
|
|
padding: theme.spacing(0, 1, 0, 1),
|
|
},
|
|
gridItem: {
|
|
padding: theme.spacing(0, 1, 0, 1),
|
|
},
|
|
}));
|
|
|
|
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 { gridContainer, gridItem } = useStyles();
|
|
const placeholder = 'Search';
|
|
|
|
return (
|
|
<Grid className={gridContainer} item container direction="row" alignItems="center">
|
|
<Grid item>
|
|
<SearchIcon />
|
|
</Grid>
|
|
<Grid className={gridItem} item xs>
|
|
<TextField
|
|
fullWidth
|
|
autoFocus
|
|
placeholder={placeholder}
|
|
value={value}
|
|
onChange={handleChange}
|
|
onKeyDown={onKeyDown}
|
|
/>
|
|
</Grid>
|
|
</Grid>
|
|
);
|
|
}
|