Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Genetics] Begin TS Refactor of Autocomplete, fix Control/Input abstr…
…action (#354) * rename: src/ot-ui-components/components/search/Autocomplete.jsx -> src/ot-ui-components/components/search/Autocomplete.tsx * rename: src/ot-ui-components/components/search/NoOptionsMessage.jsx -> src/ot-ui-components/components/search/NoOptionsMessage.tsx * refactor: convert NoOptionsMessage to ts * rename: Control.jsx -> Control.tsx * refactor: convert Control to ts * refactor: for Autocomplete, change Control to handle container only, and add Input element to use Textfield
- Loading branch information
1 parent
ba71246
commit fd4f78d
Showing
6 changed files
with
69 additions
and
84 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
37 changes: 0 additions & 37 deletions
37
apps/genetics/src/ot-ui-components/components/search/Control.jsx
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
apps/genetics/src/ot-ui-components/components/search/Control.tsx
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,23 @@ | ||
import React from "react"; | ||
import { makeStyles } from "@material-ui/core/styles"; | ||
import { ControlProps } from "react-select"; | ||
import { Box } from "@material-ui/core"; | ||
|
||
const useStyles = makeStyles(_theme => ({ | ||
control: { | ||
display: "flex", | ||
backgroundColor: "#eee", | ||
padding: "4px", | ||
}, | ||
})); | ||
|
||
const Control = ({ innerProps, children }: ControlProps) => { | ||
const classes = useStyles(); | ||
return ( | ||
<Box id="control" className={classes.control} {...innerProps}> | ||
{children} | ||
</Box> | ||
); | ||
}; | ||
|
||
export default Control; |
9 changes: 9 additions & 0 deletions
9
apps/genetics/src/ot-ui-components/components/search/Input.tsx
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,9 @@ | ||
import React from "react"; | ||
import { TextField } from "@material-ui/core"; | ||
import { InputProps } from "react-select"; | ||
|
||
const Input = ({ innerRef, ...innerProps }: InputProps) => { | ||
return <TextField fullWidth inputProps={{ ref: innerRef, ...innerProps }} />; | ||
}; | ||
|
||
export default Input; |
23 changes: 0 additions & 23 deletions
23
apps/genetics/src/ot-ui-components/components/search/NoOptionsMessage.jsx
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
apps/genetics/src/ot-ui-components/components/search/NoOptionsMessage.tsx
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,34 @@ | ||
import React from "react"; | ||
import Typography from "@material-ui/core/Typography"; | ||
import { makeStyles } from "@material-ui/core/styles"; | ||
import { GroupBase, NoticeProps } from "react-select"; | ||
|
||
const useStyles = makeStyles(theme => { | ||
return { | ||
noOptionsMessage: { | ||
padding: `${theme.spacing(1)}px ${theme.spacing(2)}px`, | ||
}, | ||
}; | ||
}); | ||
|
||
const NoOptionsMessage = <Option, IsMulti extends boolean, Group extends GroupBase<Option>>({ | ||
innerProps, | ||
children, | ||
}: Partial<NoticeProps<Option, IsMulti, Group>>) => { | ||
const classes = useStyles(); | ||
// Parse out innerProps properties that are incompatible with Typography | ||
const { color, ref, ...restProps } = innerProps || {}; | ||
return ( | ||
<Typography | ||
color="textSecondary" | ||
className={classes.noOptionsMessage} | ||
{...restProps} | ||
// `react-select` NoticeProps innerProps is a `div` element, but `Typography` expects a `span` element | ||
ref={ref as React.RefObject<HTMLSpanElement>} | ||
> | ||
{children} | ||
</Typography> | ||
); | ||
}; | ||
|
||
export default NoOptionsMessage; |