-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
746aac0
commit 1991b7d
Showing
18 changed files
with
500 additions
and
320 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react' | ||
import {render, screen} from '@testing-library/react' | ||
import ControlsGroup from './ControlsGroup' | ||
|
||
|
||
jest.mock('./Buttons', () => ({ | ||
TooltipIconButton: (props) => <button>{props.title}</button>, | ||
})) | ||
|
||
|
||
describe('ControlsGroup', () => { | ||
it('renders the search toggle', () => { | ||
render(<ControlsGroup fileOpen={jest.fn()}/>) | ||
const searchToggle = screen.getByText('Search') | ||
expect(searchToggle).toBeInTheDocument() | ||
}) | ||
|
||
it('renders the navigation toggle', () => { | ||
render(<ControlsGroup fileOpen={jest.fn()}/>) | ||
const navigationToggle = screen.getByText('Navigation') | ||
expect(navigationToggle).toBeInTheDocument() | ||
}) | ||
|
||
it('renders open model control button', () => { | ||
render(<ControlsGroup fileOpen={jest.fn()}/>) | ||
const navigationToggle = screen.getByText('Open IFC') | ||
expect(navigationToggle).toBeInTheDocument() | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1,38 +1,107 @@ | ||
import React from 'react' | ||
import Paper from '@mui/material/Paper' | ||
import Autocomplete from '@mui/material/Autocomplete' | ||
import InputAdornment from '@mui/material/InputAdornment' | ||
import IconButton from '@mui/material/IconButton' | ||
import TextField from '@mui/material/TextField' | ||
import Stack from '@mui/material/Stack' | ||
import {assertDefined} from '../utils/assert' | ||
import HighlightOffIcon from '@mui/icons-material/HighlightOff' | ||
import useTheme from '@mui/styles/useTheme' | ||
|
||
|
||
/** | ||
* Input with autocomplete feature. | ||
* InputAutocomplete Component. | ||
* | ||
* @property {Array<object>} elements suggested elements used to autocomple input,the object is in a shape of {title:'suggestion'} | ||
* @property {string} placeholder Input placeholder | ||
* @property {string} size MUI size of the input component | ||
* @param {string} inputText - The input text value. | ||
* @param {Function} setInputText - Function to set the input text. | ||
* @param {string} error - The error message. | ||
* @param {Function} onClear - Function to be executed when the clear button is clicked. | ||
* @param {Array<string>} options - Array of options for the autocomplete. | ||
* @param {React.ReactNode} startAdornment - Start adornment for the input. | ||
* @param {string} placeholder - Placeholder text for the input. | ||
* @return {React.Component} | ||
*/ | ||
export default function InputAutocomplete({elements, placeholder, size = 'small'}) { | ||
assertDefined(elements, placeholder) | ||
function InputAutocomplete({ | ||
inputText, | ||
setInputText, | ||
error = '', // Set default value | ||
onClear, | ||
options = [], | ||
startAdornment = null, | ||
placeholder = '', | ||
}) { | ||
const theme = useTheme() | ||
|
||
return ( | ||
<Stack spacing={3} sx={{minWidth: '280px'}}> | ||
<Paper elevation={1} variant='control'> | ||
<Autocomplete | ||
multiple | ||
options={elements} | ||
getOptionLabel={(option) => option.title} | ||
filterSelectedOptions | ||
size={size} | ||
renderInput={(params) => { | ||
return ( | ||
<TextField | ||
{...params} | ||
placeholder={placeholder} | ||
size={size} | ||
/> | ||
) | ||
} | ||
} | ||
fullWidth | ||
freeSolo | ||
options={options} | ||
value={inputText} | ||
onChange={(_, newValue) => setInputText(newValue || '')} | ||
onInputChange={(_, newInputValue) => setInputText(newInputValue || '')} | ||
inputValue={inputText} | ||
PaperComponent={({children}) => ( | ||
<Paper | ||
sx={{ | ||
'backgroundColor': theme.palette.scene.background, | ||
'.MuiAutocomplete-option': { | ||
backgroundColor: theme.palette.scene.background, | ||
}, | ||
}} | ||
> | ||
{children} | ||
</Paper> | ||
)} | ||
renderInput={(params) => ( | ||
<TextField | ||
{...params} | ||
size="small" | ||
error={!!error.length} | ||
placeholder={placeholder} | ||
variant="outlined" | ||
sx={{ | ||
'width': '100%', | ||
'border': 'none', | ||
'& fieldset': { | ||
border: 'none', | ||
}, | ||
'&:hover fieldset': { | ||
border: 'none', | ||
}, | ||
'&.Mui-focused fieldset': { | ||
border: 'none', | ||
}, | ||
'& .MuiOutlinedInput-root': { | ||
border: 'none', | ||
height: '46px', | ||
}, | ||
}} | ||
InputProps={{ | ||
...params.InputProps, | ||
startAdornment: startAdornment, | ||
endAdornment: inputText.length > 0 ? ( | ||
<InputAdornment position="end"> | ||
<IconButton | ||
size="small" | ||
onClick={onClear} | ||
style={{padding: 0, opacity: 0.8}} | ||
> | ||
<HighlightOffIcon | ||
className="icon-share" | ||
sx={{opacity: 0.8}} | ||
size="inherit" | ||
color="secondary" | ||
/> | ||
</IconButton> | ||
</InputAdornment> | ||
) : null, | ||
}} | ||
/> | ||
)} | ||
/> | ||
</Stack> | ||
</Paper> | ||
) | ||
} | ||
|
||
export default InputAutocomplete |
Oops, something went wrong.