-
Notifications
You must be signed in to change notification settings - Fork 196
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
frontend: Remove mui/styles, makeStyles and use sx, part 5 #1911
Conversation
191b4f4
to
4995d92
Compare
b5cf05d
to
c0040eb
Compare
0054892
to
04a025a
Compare
I was also work on some of them. here is my current state of others. |
import { Grid, GridProps } from '@mui/material';
import React from 'react';
import { ValueLabel } from '../Label';
export interface NameValueTableRow {
/** The name (key) for this row */
name: string | JSX.Element;
/** The value for this row */
value?: string | JSX.Element | JSX.Element[];
/** Whether this row should be hidden (can be a boolean or a function that will take the
* @param value and return a boolean) */
hide?: boolean | ((value: NameValueTableRow['value']) => boolean);
/** Extra properties to pass to the value cell */
valueCellProps?: GridProps;
/** Whether to highlight the row (used for titles, separators, etc.). */
withHighlightStyle?: boolean;
}
export interface NameValueTableProps {
rows: NameValueTableRow[];
valueCellProps?: GridProps;
}
function Value({
value,
}: {
value: string | JSX.Element | JSX.Element[] | undefined;
}): JSX.Element | null {
if (typeof value === 'undefined') {
return null;
} else if (typeof value === 'string') {
return <ValueLabel>{value}</ValueLabel>;
} else if (Array.isArray(value)) {
return (
<>
{value.map((val, i) => (
<Value value={val} key={i} />
))}
</>
);
} else {
return value;
}
}
export default function NameValueTable(props: NameValueTableProps) {
const { rows, valueCellProps: globalValueCellProps } = props;
const visibleRows = React.useMemo(
() =>
rows.filter(({ value, hide = false }) => {
let shouldHide = false;
if (typeof hide === 'function') {
shouldHide = hide(value);
} else {
shouldHide = hide;
}
return !shouldHide;
}),
[rows]
);
return (
<Grid
container
component="dl" // mount a Definition List
sx={theme => ({
border: '1px solid #e7e7e7',
borderRadius: theme.shape.borderRadius,
})}
>
{visibleRows.flatMap(
({ name, value, hide = false, withHighlightStyle = false, valueCellProps = {} }, i) => {
let shouldHide = false;
if (typeof hide === 'function') {
shouldHide = hide(value);
} else {
shouldHide = hide;
}
if (shouldHide) {
return null;
}
const last = visibleRows.length === i + 1;
const { className, ...otherValueCellProps } = globalValueCellProps || {};
const hideValueGridItem = withHighlightStyle && !value;
const items = [
<Grid
item
key={i}
xs={12}
sm={hideValueGridItem ? 12 : 4}
component="dt"
sx={theme => {
let extra = withHighlightStyle
? {
color: theme.palette.tables.head.color,
fontWeight: 'bold',
background: theme.palette.tables.head.background,
}
: {};
return {
fontSize: '1rem',
textAlign: 'left',
maxWidth: '100%',
minWidth: '10rem',
verticalAlign: 'top',
color: theme.palette.text.secondary,
borderBottom: last ? 'none' : `1px solid ${theme.palette.divider}`,
padding: '7px 12px',
[theme.breakpoints.down('sm')]: {
color: theme.palette.text.primary,
fontSize: '1.5rem',
minWidth: '100%',
width: '100%',
maxWidth: '100%',
display: 'block',
borderTop: `1px solid ${theme.palette.divider}`,
borderBottom: `none`,
},
...extra,
};
}}
>
{name}
</Grid>,
];
if (!hideValueGridItem) {
items.push(
<Grid
item
key={i + 10000}
xs={12}
sm={8}
component="dd"
sx={theme => {
let extra = withHighlightStyle
? {
color: theme.palette.tables.head.color,
fontWeight: 'bold',
background: theme.palette.tables.head.background,
}
: {};
return {
width: '100%',
verticalAlign: 'top',
fontSize: '1rem',
overflowWrap: 'anywhere',
padding: '7px 12px',
borderBottom: last ? 'none' : `1px solid ${theme.palette.divider}`,
[theme.breakpoints.down('sm')]: {
color: theme.palette.text.secondary,
minWidth: '100%',
width: '100%',
maxWidth: '100%',
display: 'block',
marginBottom: '2rem',
borderBottom: `none`,
},
...extra,
};
}}
{...otherValueCellProps}
{...valueCellProps}
>
<Value value={value} />
</Grid>
);
}
return items;
}
)}
</Grid>
);
} My work on NameValueTable. |
Hey @farodin91 thanks! I'll add your changes in here and add you as a co author to all the commits if that's ok? |
Sounds good to me! |
663215b
to
2a90770
Compare
d041e1d
to
8106808
Compare
983dfce
to
ef1db1d
Compare
@farodin91 this should be the last of it. I left mui/styles in there still for a little while longer for backwards compatibility for any plugins that might still be using it. This should the only mui/styles left as far as I know. |
@joaquimrocha I don't expect a conflict would be more than a few lines, and probably generating the snapshots again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noticed a regression.
frontend/src/components/common/NameValueTable/NameValueTable.tsx
Outdated
Show resolved
Hide resolved
Co-Authored-By: farodin91 <github@jan-jansen.net> Signed-off-by: farodin91 <github@jan-jansen.net> Signed-off-by: René Dudfield <renedudfield@microsoft.com>
Co-Authored-By: farodin91 <github@jan-jansen.net> Signed-off-by: farodin91 <github@jan-jansen.net> Signed-off-by: René Dudfield <renedudfield@microsoft.com>
Co-Authored-By: farodin91 <github@jan-jansen.net> Signed-off-by: farodin91 <github@jan-jansen.net> Signed-off-by: René Dudfield <renedudfield@microsoft.com>
Co-Authored-By: farodin91 <github@jan-jansen.net> Signed-off-by: farodin91 <github@jan-jansen.net> Signed-off-by: René Dudfield <renedudfield@microsoft.com>
Co-Authored-By: farodin91 <github@jan-jansen.net> Signed-off-by: farodin91 <github@jan-jansen.net> Signed-off-by: René Dudfield <renedudfield@microsoft.com>
Co-Authored-By: farodin91 <github@jan-jansen.net> Signed-off-by: farodin91 <github@jan-jansen.net> Signed-off-by: René Dudfield <renedudfield@microsoft.com>
Co-Authored-By: farodin91 <github@jan-jansen.net> Signed-off-by: farodin91 <github@jan-jansen.net> Signed-off-by: René Dudfield <renedudfield@microsoft.com>
Co-Authored-By: farodin91 <github@jan-jansen.net> Signed-off-by: farodin91 <github@jan-jansen.net> Signed-off-by: René Dudfield <renedudfield@microsoft.com>
Co-Authored-By: farodin91 <github@jan-jansen.net> Signed-off-by: farodin91 <github@jan-jansen.net> Signed-off-by: René Dudfield <renedudfield@microsoft.com>
Co-Authored-By: farodin91 <github@jan-jansen.net> Signed-off-by: farodin91 <github@jan-jansen.net> Signed-off-by: René Dudfield <renedudfield@microsoft.com>
Co-Authored-By: farodin91 <github@jan-jansen.net> Signed-off-by: farodin91 <github@jan-jansen.net> Signed-off-by: René Dudfield <renedudfield@microsoft.com>
mui/styles id deprecated Signed-off-by: René Dudfield <renedudfield@microsoft.com>
Signed-off-by: René Dudfield <renedudfield@microsoft.com>
Signed-off-by: René Dudfield <renedudfield@microsoft.com>
Signed-off-by: René Dudfield <renedudfield@microsoft.com>
Signed-off-by: René Dudfield <renedudfield@microsoft.com>
Signed-off-by: René Dudfield <renedudfield@microsoft.com>
Rebased from main again. WIP, doing a retest... |
Signed-off-by: René Dudfield <renedudfield@microsoft.com>
It's not used anymore. Signed-off-by: René Dudfield <renedudfield@microsoft.com>
Signed-off-by: René Dudfield <renedudfield@microsoft.com>
Signed-off-by: René Dudfield <renedudfield@microsoft.com>
Thanks a lot for such a comprehensive and important work, @farodin91 and @illume ! |
Updating to get rid of deprecated styling.
-- https://mui.com/system/styles/basics/
Continues on from this series.
Note: this leaves the
@mui/styles
in here for now. For backwards compatibility with plugins. That will come in a later PR.Testing done
How to test?
Use Headlamp, and it should look and feel as it did before.