Skip to content

Commit

Permalink
refactor: avoid defining a component inside another component
Browse files Browse the repository at this point in the history
  • Loading branch information
quanho committed Mar 29, 2023
1 parent 9ca11fe commit befae84
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
Expand Up @@ -3,9 +3,8 @@ import React, { useContext } from 'react';
import { styled } from '@mui/material/styles';
import InstanceContext from '../../../contexts/InstanceContext';

export default function ListBoxDisclaimer({ width, text, dense, tooltip }) {
const { translator } = useContext(InstanceContext);
const StyledText = styled(Typography)(() => ({
const StyledText = styled(Typography, { shouldForwardProp: (p) => !['width', 'dense'].includes(p) })(
({ width, dense }) => ({
minWidth: `${width}px`,
textAlign: 'center',
fontSize: `${dense ? '12px' : '14px'}`,
Expand All @@ -15,11 +14,15 @@ export default function ListBoxDisclaimer({ width, text, dense, tooltip }) {
whiteSpace: 'nowrap',
width,
}),
}));
})
);

export default function ListBoxDisclaimer({ width, text, dense, tooltip }) {
const { translator } = useContext(InstanceContext);

return (
<Tooltip title={tooltip ? translator.get(text) : ''}>
<StyledText component="div" variant="body1" py="12px">
<StyledText width={width} dense={dense} component="div" variant="body1" py="12px">
{translator.get(text)}
</StyledText>
</Tooltip>
Expand Down
16 changes: 8 additions & 8 deletions apis/nucleus/src/components/listbox/components/ListBoxError.jsx
Expand Up @@ -2,15 +2,15 @@ import { styled } from '@mui/material/styles';
import React, { useContext } from 'react';
import InstanceContext from '../../../contexts/InstanceContext';

const StyledDiv = styled('div')(() => ({
display: 'flex',
width: '100%',
height: '100%',
alignItems: 'center',
justifyContent: 'center',
}));

export default function ListBoxError({ text }) {
const { translator } = useContext(InstanceContext);
const StyledDiv = styled('div')(() => ({
display: 'flex',
width: '100%',
height: '100%',
alignItems: 'center',
justifyContent: 'center',
}));

return <StyledDiv>{translator.get(text)}</StyledDiv>;
}

0 comments on commit befae84

Please sign in to comment.