-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[useStyles] Prop passing after v5 migration #29904
Comments
Hi. thanks for the report. Can you provide a codesandbox that shows the error directly? You can fork this template. https://codesandbox.io/s/mui-issue-latest-s2dsx |
@cengizcmataraci Please provide the full version of the file, so that we can reproduce it. |
Sure but are you want to before migration file or after migration file?
|
I will send before migration file, can you please tell me how i can tranform new way? Codeimport { useMemo, useContext } from 'react';
import { makeStyles } from '@mui/styles';
import { Typography, Card, CardContent, Tooltip } from '@mui/material';
import clsx from 'clsx';
import { VendorHelper } from 'utils/helpers';
import { useBoolean, useQueryString } from 'utils/hooks';
import ResponsiveModal from 'components/ResponsiveModal';
import { DialogContent, IconButton } from '@mui/material';
import MarketplaceFormGenerator from './vendorComponents/marketplaceGenerator';
import CarrierGenerator from './vendorComponents/carrierGenerator';
import { primaryColor } from 'assets/jss/material-kit-pro-react';
import SettingsIcon from '@mui/icons-material/Settings';
import PropTypes from 'prop-types';
import { AuthContext } from 'services/contexts/AuthContext';
import { useTranslation } from 'react-i18next';
const useStyles = (vendorColor, isActiveVendor, hasIntegration, isActive) =>
makeStyles((theme) => ({
headerColor: {
color: '#546E7A',
},
activeCard: {
height: 25,
marginBottom: hasIntegration ? 14 : 0,
width: '100%',
backgroundColor: !isActiveVendor
? '#f8f4e8'
: hasIntegration
? isActive
? '#4CAF50'
: '#C6C9C7'
: 'white',
},
settingsIcon: {
padding: 3,
float: 'right',
color: 'white',
},
fontSizeSmall: {
fontSize: 'medium',
},
justifyCenter: {
display: 'flex',
justifyContent: 'center',
},
spaceAround: {
display: 'flex',
justifyContent: 'space-around',
alignItems: 'center',
},
paddingTop8: {
paddingTop: hasIntegration ? 0 : 12,
},
lighterText: {
fontWeight: 400,
},
itemCard: {
width: 130,
border: 'solid',
borderRadius: 12,
backgroundColor: !isActiveVendor && '#f8f4e8',
borderColor: isActiveVendor
? hasIntegration
? isActive
? '#4CAF50'
: '#C6C9C7'
: 'white'
: '#f8f4e8',
'&:hover': {
borderColor: isActiveVendor ? vendorColor : '#f8f4e8',
cursor: isActiveVendor && 'pointer',
},
},
link: {
color: primaryColor[0],
cursor: 'pointer',
},
marginTop2: {
marginTop: theme.spacing(2),
},
paddingBottom2: {
paddingBottom: theme.spacing(10),
},
label: {
marginTop: -12,
marginLeft: 5,
},
beta: {
fontSize: 10,
color: '#ff8c00',
},
marginLeft: {
marginLeft: 5,
},
}));
const VendorItem = ({ vendor, vendorData }) => {
const {
vendorDefinitions,
vendorColors,
vendorSmallImages,
vendorTypeKeys,
vendorList,
} = VendorHelper.default;
const { isBetaUser, isAdmin } = useContext(AuthContext);
const hasIntegration = !!vendorData && vendorData.id !== 0;
const isUseable = vendor.isActive && ((vendor.isBeta && isBetaUser) || !vendor.isBeta || isAdmin);
const isActive = !!vendorData && vendorData.isActive;
const { t } = useTranslation('views.integrationsPage');
const vendorQueryString = useQueryString('vendor');
const modalOpen = useBoolean(
useQueryString('vendor')?.toLowerCase() === vendor.name.toLowerCase()
);
const vendorType = useMemo(
() =>
!!vendor
? vendor.vendorType
: vendorList.find((v) => v.name.toLowerCase() === vendorQueryString.toLowerCase())
.vendorType,
// eslint-disable-next-line
[vendor, vendorQueryString]
);
const classes = useStyles(
vendorColors[vendor.id],
isUseable,
vendorType === vendorTypeKeys.Carrier && hasIntegration,
isActive
)();
return <>
<Tooltip
title={
isUseable
? vendorType === vendorTypeKeys.Carrier && hasIntegration
? isActive
? t('vendorItem.hasIntegration')
: t('vendorItem.integrationActive')
: t('vendorItem.addIntegration')
: t('vendorItem.improveYet')
}
>
<Card className={classes.itemCard} onClick={() => isUseable && modalOpen.setTrue()}>
<div className={classes.activeCard}>
{vendor.isActive && hasIntegration ? (
<Tooltip title={t('vendorItem.seeSettings')}>
<IconButton className={classes.settingsIcon} size="large">
<SettingsIcon className={classes.fontSizeSmall} />
</IconButton>
</Tooltip>
) : (
<></>
)}
</div>
<CardContent className={clsx(classes.spaceAround, classes.paddingTop8)}>
<img
src={vendorSmallImages[vendor.id]}
width={vendor.imageWidth}
alt={vendorDefinitions[vendor.id]}
/>
{vendor.isShowName ? (
<Typography
className={clsx(classes.headerColor, classes.lighterText, classes.marginLeft)}
variant="h5"
>
{vendorDefinitions[vendor.id]}
</Typography>
) : (
<></>
)}
{vendor.isBeta && (isBetaUser || isAdmin) && (
<span className={classes.label}>
<b className={classes.beta}>BETA</b>
</span>
)}
</CardContent>
</Card>
</Tooltip>
{modalOpen.value && vendorType && (
<ResponsiveModal
open={modalOpen.value}
onClose={() => modalOpen.setFalse()}
modalId="integrationModal"
hasHeader={false}
>
<DialogContent>
<div>
{vendorType === vendorTypeKeys.Marketplace && (
<MarketplaceFormGenerator vendorId={vendor.id} />
)}
{vendorType === vendorTypeKeys.Carrier && (
<CarrierGenerator
vendorId={vendor.id}
vendorData={vendorData}
modalOpen={modalOpen}
/>
)}
</div>
</DialogContent>
</ResponsiveModal>
)}
</>;
};
VendorItem.propTypes = {
vendor: PropTypes.object.isRequired,
vendorData: PropTypes.object,
};
export default VendorItem; |
I also get the error "Transformation error (Unexpected token (168:2)) SyntaxError: Unexpected token (168:2)" when I refer to the styled code mode, and another 116 files also get an error. |
@cengizcmataraci as far as I can see the API you are using is not correct. Check https://mui.com/styles/basics/#adapting-based-on-props On the other hand, if you wish to adopt to v5, you can use |
Duplicates
Latest version
Current behavior 😯
We are trying to migrate from v4 to v5 and we use a lot of makeStyles and useStyles. We are trying to migrate the style component and apply the styled code mode, but many files are throwing errors. For example, we use useStyles for prop pass, but the code mod using useStyles was deleted, but props remained idle. And naturally the app doesn't compile.
Expected behavior 🤔
We don't know how to use the props we give to useStyles when using styled-component. If we know what we can use instead of use useStyles, we can apply it.
Your environment 🌎
`npx @mui/envinfo`
The text was updated successfully, but these errors were encountered: