Skip to content

Commit

Permalink
refactor: [M3-6391] - MUI v5 Migration - `Components > SingleTextFiel…
Browse files Browse the repository at this point in the history
…dForm` (#9292)

* style migration and clean up

* Added changeset: MUI v5 Migration - Components > SingleTextFieldForm

* use `sx`

---------

Co-authored-by: Banks Nussman <banks@nussman.us>
  • Loading branch information
bnussman-akamai and bnussman authored Jun 22, 2023
1 parent b37e7b0 commit e85306c
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tech Stories
---

MUI v5 Migration - Components > SingleTextFieldForm ([#9292](https://github.com/linode/manager/pull/9292))
4 changes: 2 additions & 2 deletions packages/manager/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import Reload from 'src/assets/icons/reload.svg';
import _Button, { ButtonProps } from '@mui/material/Button';
import { TooltipIcon } from 'src/components/TooltipIcon/TooltipIcon';
import { useTheme, styled } from '@mui/material/styles';
import { useTheme, styled, Theme } from '@mui/material/styles';
import { SxProps } from '@mui/system';
import { isPropValid } from '../../utilities/isPropValid';
import { rotate360 } from '../../styles/keyframes';
Expand All @@ -15,7 +15,7 @@ export interface Props extends ButtonProps {
/** Additional css class to pass to the component */
className?: string;
/** The `sx` prop can be either object or function */
sx?: SxProps;
sx?: SxProps<Theme>;
/** Reduce the padding on the x-axis */
compactX?: boolean;
/** Reduce the padding on the y-axis */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as React from 'react';
import SingleTextFieldForm, { Props } from './SingleTextFieldForm';
import { SingleTextFieldForm } from './SingleTextFieldForm';
import { renderWithTheme } from 'src/utilities/testHelpers';
import { fireEvent, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

describe('SingleTextFieldForm', () => {
const props: Props = {
const props = {
label: 'Username',
submitForm: jest.fn(() => Promise.resolve()),
initialValue: 'jane-doe',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,20 @@ import * as React from 'react';
import ActionsPanel from 'src/components/ActionsPanel';
import Button from 'src/components/Button';
import Box from 'src/components/core/Box';
import { makeStyles } from '@mui/styles';
import { Theme } from '@mui/material/styles';
import { Notice } from 'src/components/Notice/Notice';
import TextField, { Props as TextFieldProps } from 'src/components/TextField';
import { getAPIErrorOrDefault, getErrorMap } from 'src/utilities/errorUtils';

const useStyles = makeStyles((theme: Theme) => ({
root: {
[theme.breakpoints.down('md')]: {
flexDirection: 'column',
},
},
input: {
minWidth: 415,
[theme.breakpoints.down('md')]: {
minWidth: 'auto',
},
},
button: {
minWidth: 180,
[theme.breakpoints.up('md')]: {
marginTop: 16,
},
},
}));

export interface Props {
label: string;
interface Props extends TextFieldProps {
fieldName?: string;
submitForm: (value: string) => Promise<any>;
initialValue?: string;
disabled?: boolean;
tooltipText?: string;
successMessage?: string;
errorMessage?: string;
successCallback?: () => void;
}

export const SingleTextFieldForm: React.FC<Props & TextFieldProps> = (
props
) => {
const classes = useStyles();

export const SingleTextFieldForm = React.memo((props: Props) => {
const {
label,
fieldName,
Expand Down Expand Up @@ -96,11 +67,20 @@ export const SingleTextFieldForm: React.FC<Props & TextFieldProps> = (
<Box
display="flex"
justifyContent="space-between"
className={classes.root}
sx={(theme) => ({
[theme.breakpoints.down('md')]: {
flexDirection: 'column',
},
})}
>
<TextField
{...textFieldProps}
className={classes.input}
sx={(theme) => ({
minWidth: 415,
[theme.breakpoints.down('md')]: {
minWidth: 'auto',
},
})}
label={label}
value={value}
onChange={(e) => setValue(e.target.value)}
Expand All @@ -110,7 +90,12 @@ export const SingleTextFieldForm: React.FC<Props & TextFieldProps> = (
/>
<ActionsPanel>
<Button
className={classes.button}
sx={(theme) => ({
minWidth: 180,
[theme.breakpoints.up('md')]: {
marginTop: 2,
},
})}
buttonType="primary"
onClick={handleSubmit}
disabled={disabled || value === initialValue}
Expand All @@ -133,6 +118,4 @@ export const SingleTextFieldForm: React.FC<Props & TextFieldProps> = (
) : null}
</>
);
};

export default React.memo(SingleTextFieldForm);
});
5 changes: 0 additions & 5 deletions packages/manager/src/components/SingleTextFieldForm/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export const DisplaySettings = () => {
inputRef={emailRef}
type="email"
/>
<Divider spacingTop={24} spacingBottom={16} />
<Divider spacingTop={24} spacingBottom={8} />
<TimezoneForm loggedInAsCustomer={loggedInAsCustomer} />
</Paper>
);
Expand Down

0 comments on commit e85306c

Please sign in to comment.