Skip to content

chore: use emotion for styling (pt. 4) #10149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Oct 10, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
emotion: UserOrGroupAutocomplete
  • Loading branch information
aslilac committed Oct 9, 2023
commit e48ec94ac38f9b4faba65da835c71206437f96ed
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import CircularProgress from "@mui/material/CircularProgress";
import { makeStyles } from "@mui/styles";
import TextField from "@mui/material/TextField";
import Autocomplete from "@mui/material/Autocomplete";
import { useMachine } from "@xstate/react";
import { Group, User } from "api/typesGenerated";
import Box from "@mui/material/Box";
import { type ChangeEvent, useState } from "react";
import { css } from "@emotion/css";
import type { Group, User } from "api/typesGenerated";
import { AvatarData } from "components/AvatarData/AvatarData";
import { ChangeEvent, useState } from "react";
import { getGroupSubtitle } from "utils/groups";
import { searchUsersAndGroupsMachine } from "xServices/template/searchUsersAndGroupsXService";
import Box from "@mui/material/Box";
import { useDebouncedFunction } from "hooks/debounce";

export type UserOrGroupAutocompleteValue = User | Group | null;
Expand All @@ -25,10 +25,21 @@ export type UserOrGroupAutocompleteProps = {
exclude: UserOrGroupAutocompleteValue[];
};

const autoCompleteStyles = css`
width: 300px;

& .MuiFormControl-root {
width: 100%;
}

& .MuiInputBase-root {
width: 100%;
}
`;

export const UserOrGroupAutocomplete: React.FC<
UserOrGroupAutocompleteProps
> = ({ value, onChange, organizationId, templateID, exclude }) => {
const styles = useStyles();
const [isAutocompleteOpen, setIsAutocompleteOpen] = useState(false);
const [searchState, sendSearch] = useMachine(searchUsersAndGroupsMachine, {
context: {
Expand Down Expand Up @@ -92,7 +103,7 @@ export const UserOrGroupAutocomplete: React.FC<
}}
options={options}
loading={searchState.matches("searching")}
className={styles.autocomplete}
css={autoCompleteStyles}
renderInput={(params) => (
<>
<TextField
Expand All @@ -118,19 +129,3 @@ export const UserOrGroupAutocomplete: React.FC<
/>
);
};

export const useStyles = makeStyles(() => {
return {
autocomplete: {
width: "300px",

"& .MuiFormControl-root": {
width: "100%",
},

"& .MuiInputBase-root": {
width: "100%",
},
},
};
});