Skip to content
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

refactor: [M3-6195] - MUI v5 Migration - Components > Button (part 2) #9325

Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tech Stories
---

MUI v5 Migration - Components > Button ([#9325](https://github.com/linode/manager/pull/9325))
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Theme } from '@mui/material/styles';
import * as React from 'react';
import Button from 'src/components/Button';
import { Button } from 'src/components/Button/Button';
import CheckBox from 'src/components/CheckBox';
import { TableBody } from 'src/components/TableBody';
import { TableHead } from 'src/components/TableHead';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Button from 'src/components/Button';
import { Button } from 'src/components/Button/Button';
import ActionsPanel from '../ActionsPanel';
import Accordion from './Accordion';
import { Canvas, Meta, Story, ArgsTable } from '@storybook/addon-docs';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import Tooltip, { TooltipProps } from 'src/components/core/Tooltip';
import Button from '../Button';
import { Button } from '../Button/Button';

export interface Props extends Omit<TooltipProps, 'children' | 'title'> {
display?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import type { Meta, StoryObj } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import Button from './Button';
import { Button } from './Button';
import { StyledLinkButton } from 'src/components/Button/StyledLinkButton';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/manager/src/components/Button/Button.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import Button from './Button';
import { Button } from './Button';
import { render } from '@testing-library/react';

describe('Button', () => {
Expand Down
29 changes: 17 additions & 12 deletions packages/manager/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import Reload from 'src/assets/icons/reload.svg';
import _Button, { ButtonProps } from '@mui/material/Button';
import _Button, { ButtonProps as _ButtonProps } from '@mui/material/Button';
import { TooltipIcon } from 'src/components/TooltipIcon/TooltipIcon';
import { useTheme, styled, Theme } from '@mui/material/styles';
import { SxProps } from '@mui/system';
Expand All @@ -9,18 +9,27 @@ import { rotate360 } from '../../styles/keyframes';

export type ButtonType = 'primary' | 'secondary' | 'outlined';

export interface Props extends ButtonProps {
export interface ButtonProps extends _ButtonProps {
/** The button variant to render */
buttonType?: ButtonType;
/** Additional css class to pass to the component */
className?: string;
/** The `sx` prop can be either object or function */
sx?: SxProps<Theme>;
/** Reduce the padding on the x-axis */
/**
* Reduce the padding on the x-axis
* @default false
*/
compactX?: boolean;
/** Reduce the padding on the y-axis */
/**
* Reduce the padding on the y-axis
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the current compactX and compactY eliminates the the padding.

* @default false
*/
compactY?: boolean;
/** Show a loading indicator */
/**
* Show a loading indicator
* @default false
*/
loading?: boolean;
/** Tooltip text */
tooltipText?: string;
Expand All @@ -31,7 +40,7 @@ export interface Props extends ButtonProps {
const StyledButton = styled(_Button, {
shouldForwardProp: (prop) =>
isPropValid(['compactX', 'compactY', 'loading', 'buttonType'], prop),
})<Props>(({ theme, ...props }) => ({
})<ButtonProps>(({ theme, ...props }) => ({
...(props.buttonType === 'secondary' &&
props.compactX && {
minWidth: 50,
Expand Down Expand Up @@ -67,7 +76,7 @@ const Span = styled('span')({
},
});

const Button = React.forwardRef<HTMLButtonElement, Props>(
export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
(
{
// default to secondary as some components never define a buttonType (usually buttons with icons)
Expand All @@ -84,7 +93,7 @@ const Button = React.forwardRef<HTMLButtonElement, Props>(
tooltipText,
tooltipAnalyticsEvent,
...rest
}: Props,
},
ref
) => {
const theme = useTheme();
Expand Down Expand Up @@ -129,7 +138,3 @@ const Button = React.forwardRef<HTMLButtonElement, Props>(
);
}
);

Button.displayName = 'Button';

export default Button;
5 changes: 0 additions & 5 deletions packages/manager/src/components/Button/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/manager/src/components/CheckoutBar/styles.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useTheme } from '@mui/material/styles';
import { styled } from '@mui/system';
import Button from 'src/components/Button';
import { Button } from 'src/components/Button/Button';

const StyledButton = styled(Button)(({ theme }) => ({
marginTop: 18,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import ActionsPanel from 'src/components/ActionsPanel';
import Button from 'src/components/Button';
import { Button } from 'src/components/Button/Button';
import { ConfirmationDialog } from 'src/components/ConfirmationDialog/ConfirmationDialog';
import { action } from '@storybook/addon-actions';
import type { Meta, StoryObj } from '@storybook/react';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import ActionsPanel from 'src/components/ActionsPanel';
import Button from 'src/components/Button';
import { Button } from 'src/components/Button/Button';
import { ConfirmationDialog } from 'src/components/ConfirmationDialog/ConfirmationDialog';
import { useTheme } from '@mui/material/styles';
import Typography from 'src/components/core/Typography';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ArgsTable, Canvas, Meta, Story } from '@storybook/addon-docs';
import Button from 'src/components/Button';
import { Button } from 'src/components/Button/Button';
import DismissibleBanner from './DismissibleBanner';
import Grid from '@mui/material/Unstable_Grid2';
import Link from 'src/components/Link';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import Button from 'src/components/Button';
import { Button } from 'src/components/Button/Button';
import { CSVLink } from 'react-csv';
import { SxProps } from '@mui/system';
import type { ButtonType } from 'src/components/Button/Button';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import Button from 'src/components/Button';
import { Button } from 'src/components/Button/Button';
import Typography from 'src/components/core/Typography';
import ActionsPanel from '../ActionsPanel';
import { TextField } from '../TextField';
Expand Down
2 changes: 1 addition & 1 deletion packages/manager/src/components/Drawer/Drawer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Close from '@mui/icons-material/Close';
import * as React from 'react';
import Button from 'src/components/Button';
import { Button } from 'src/components/Button/Button';
import _Drawer, { DrawerProps } from 'src/components/core/Drawer';
import { makeStyles } from 'tss-react/mui';
import { Theme } from '@mui/material/styles';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Close from '@mui/icons-material/Close';
import Edit from '@mui/icons-material/Edit';
import classNames from 'classnames';
import * as React from 'react';
import Button from 'src/components/Button';
import { Button } from 'src/components/Button/Button';
import ClickAwayListener from 'src/components/core/ClickAwayListener';
import { makeStyles } from '@mui/styles';
import { Theme } from '@mui/material/styles';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Edit from '@mui/icons-material/Edit';
import { Theme } from '@mui/material/styles';
import * as React from 'react';
import { Link } from 'react-router-dom';
import Button from 'src/components/Button';
import { Button } from 'src/components/Button/Button';
import { H1Header } from 'src/components/H1Header/H1Header';
import ClickAwayListener from 'src/components/core/ClickAwayListener';
import { fadeIn } from 'src/styles/keyframes';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import Minus from 'src/assets/icons/LKEminusSign.svg';
import Plus from 'src/assets/icons/LKEplusSign.svg';
import Button from 'src/components/Button';
import { Button } from 'src/components/Button/Button';
import { styled } from '@mui/material/styles';
import { TextField } from 'src/components/TextField';
import Box from '@mui/material/Box';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import type { Meta, StoryObj } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import { EntityHeader } from 'src/components/EntityHeader/EntityHeader';
import Button from '../Button';
import { Button } from '../Button/Button';
import Link from '../Link';
import Box from 'src/components/core/Box';
import Hidden from 'src/components/core/Hidden';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Button from 'src/components/Button';
import { Button } from 'src/components/Button/Button';
import { styled } from '@mui/material/styles';
import { isPropValid } from 'src/utilities/isPropValid';
import Typography from 'src/components/core/Typography';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { Link } from 'react-router-dom';
import Button from 'src/components/Button';
import { Button } from 'src/components/Button/Button';
import { makeStyles } from 'tss-react/mui';
import { Theme } from '@mui/material/styles';
import SvgIcon from 'src/components/core/SvgIcon';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable react/jsx-no-useless-fragment */
import * as React from 'react';
import { Link } from 'react-router-dom';
import Button from 'src/components/Button/Button';
import { Button } from 'src/components/Button/Button';
import { makeStyles } from '@mui/styles';
import { Theme } from '@mui/material/styles';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React from 'react';
import type { Meta, StoryObj } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import LandingHeader from './LandingHeader';
import Button from '../Button';
import { Button } from '../Button/Button';

const meta: Meta<typeof LandingHeader> = {
title: 'Components/LandingHeader',
component: LandingHeader,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import Button from 'src/components/Button';
import { Button } from 'src/components/Button/Button';
import {
Breadcrumb,
BreadcrumbProps,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Button from 'src/components/Button';
import { Button } from 'src/components/Button/Button';
import { Table } from 'src/components/Table';
import { TableHead } from 'src/components/TableHead';
import { TableBody } from 'src/components/TableBody';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { InputBaseProps } from '@mui/material/InputBase';
import Close from '@mui/icons-material/Close';
import * as React from 'react';
import Button from 'src/components/Button';
import { Button } from 'src/components/Button/Button';
import InputLabel from 'src/components/core/InputLabel';
import { makeStyles } from 'tss-react/mui';
import { Theme } from '@mui/material/styles';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import ActionsPanel from '../ActionsPanel';
import Button from '../Button';
import { Button } from '../Button/Button';
import { ConfirmationDialog } from 'src/components/ConfirmationDialog/ConfirmationDialog';
import { PaymentMethod } from '@linode/api-v4/lib/account/types';
import CreditCard from 'src/features/Billing/BillingPanels/BillingSummary/PaymentDrawer/CreditCard';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import LinodeIcon from 'src/assets/addnewmenu/linode.svg';
import Button, { ButtonProps } from 'src/components/Button';
import { Button, ButtonProps } from 'src/components/Button/Button';
import { styled, useTheme } from '@mui/material/styles';
import Typography from 'src/components/core/Typography';
import { H1Header } from 'src/components/H1Header/H1Header';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { Link } from 'react-router-dom';
import HeavenlyBucketIcon from 'src/assets/icons/promotionalOffers/heavenly-bucket.svg';
import Button from 'src/components/core/Button';
import Button from '@mui/material/Button';
import Paper from 'src/components/core/Paper';
import { makeStyles } from 'tss-react/mui';
import { Theme } from '@mui/material/styles';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { makeStyles } from 'tss-react/mui';
import { Theme } from '@mui/material/styles';
import KeyboardArrowRight from '@mui/icons-material/KeyboardArrowRight';
import Button from 'src/components/Button';
import { Button } from 'src/components/Button/Button';
import Collapse from 'src/components/core/Collapse';

const useStyles = makeStyles<void, 'caret'>()(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { APIError } from '@linode/api-v4/lib/types';
import * as React from 'react';
import ActionsPanel from 'src/components/ActionsPanel';
import Button from 'src/components/Button';
import { Button } from 'src/components/Button/Button';
import Box from 'src/components/core/Box';
import { Notice } from 'src/components/Notice/Notice';
import { TextField, TextFieldProps } from 'src/components/TextField';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Box from '@mui/material/Box';
import { Theme, useTheme } from '@mui/material/styles';
import * as React from 'react';
import { Link, useHistory } from 'react-router-dom';
import Button from 'src/components/Button';
import { Button } from 'src/components/Button/Button';
import { CopyTooltip } from 'src/components/CopyTooltip/CopyTooltip';
import { Chip } from 'src/components/core/Chip';
import Divider from 'src/components/core/Divider';
Expand Down
2 changes: 1 addition & 1 deletion packages/manager/src/components/Tile/Tile.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import Button from 'src/components/core/Button';
import Button from '@mui/material/Button';
import { makeStyles } from 'tss-react/mui';
import { Theme } from '@mui/material/styles';
import Typography from 'src/components/core/Typography';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { APIError } from '@linode/api-v4/lib/types';
import * as React from 'react';
import ActionsPanel from 'src/components/ActionsPanel';
import Button from 'src/components/Button';
import { Button } from 'src/components/Button/Button';
import {
ConfirmationDialog,
ConfirmationDialogProps,
Expand Down
6 changes: 0 additions & 6 deletions packages/manager/src/components/core/Button.ts

This file was deleted.

8 changes: 0 additions & 8 deletions packages/manager/src/components/core/ButtonBase.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { APIError } from '@linode/api-v4/lib/types';
import * as React from 'react';
import { useHistory } from 'react-router-dom';
import ActionsPanel from 'src/components/ActionsPanel';
import Button from 'src/components/Button';
import { Button } from 'src/components/Button/Button';
import { ConfirmationDialog } from 'src/components/ConfirmationDialog/ConfirmationDialog';
import { makeStyles } from 'tss-react/mui';
import { Theme } from '@mui/material/styles';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import Accordion from 'src/components/Accordion';
import Button from 'src/components/Button';
import { Button } from 'src/components/Button/Button';
import Grid from '@mui/material/Unstable_Grid2';
import CloseAccountDialog from './CloseAccountDialog';

Expand Down
2 changes: 1 addition & 1 deletion packages/manager/src/features/Account/EnableManaged.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { APIError } from '@linode/api-v4/lib/types';
import * as React from 'react';
import Accordion from 'src/components/Accordion';
import ActionsPanel from 'src/components/ActionsPanel';
import Button from 'src/components/Button';
import { Button } from 'src/components/Button/Button';
import { ConfirmationDialog } from 'src/components/ConfirmationDialog/ConfirmationDialog';
import Typography from 'src/components/core/Typography';
import ExternalLink from 'src/components/ExternalLink';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as React from 'react';
import { Link } from 'react-router-dom';
import Accordion from 'src/components/Accordion';
import ActionsPanel from 'src/components/ActionsPanel';
import Button from 'src/components/Button';
import { Button } from 'src/components/Button/Button';
import { ConfirmationDialog } from 'src/components/ConfirmationDialog/ConfirmationDialog';
import { Notice } from 'src/components/Notice/Notice';
import { TypeToConfirm } from 'src/components/TypeToConfirm/TypeToConfirm';
Expand Down
2 changes: 1 addition & 1 deletion packages/manager/src/features/Backups/BackupDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { QueryClient } from 'react-query';
import { connect, MapDispatchToProps, MapStateToProps } from 'react-redux';
import { compose } from 'recompose';
import ActionsPanel from 'src/components/ActionsPanel';
import Button from 'src/components/Button';
import { Button } from 'src/components/Button/Button';
import Typography from 'src/components/core/Typography';
import { DisplayPrice } from 'src/components/DisplayPrice';
import Drawer from 'src/components/Drawer';
Expand Down
Loading