perf(Grid): improve style performance

This commit is contained in:
Zeke Zhang 2024-10-30 11:23:16 +08:00
parent 5f9bbf580d
commit 95cabdc409
2 changed files with 51 additions and 49 deletions

View File

@ -7,62 +7,64 @@
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
import { createStyles } from 'antd-style';
import { genStyleHook } from '../__builtins__/style';
const useStyles = createStyles(({ token, css, cx }: any) => {
const useStyles = genStyleHook('nb-grid-in-css-in-js', (token) => {
const { componentCls } = token;
// 如果相等,说明当前是在 Form 区块中,会加上 !important否则会导致字段间距收到影响
const important = token.marginBlock === token.marginLG ? ' !important' : '';
return {
wrapper: css``,
container: css`
.ColDivider {
flex-shrink: 0;
width: ${token.marginBlock}px${important};
}
[componentCls]: {
position: 'relative',
.DraggableNode {
&::before {
content: ' ';
width: 100%;
height: 100%;
position: absolute;
cursor: col-resize;
}
&:hover {
&::before {
background: var(--colorBgSettingsHover) !important;
}
}
width: ${token.marginBlock}px${important};
height: 100%;
position: absolute;
cursor: col-resize;
}
'.ColDivider': {
flexShrink: 0,
width: `${token.marginBlock}px${important}`,
},
.RowDivider {
height: ${token.marginBlock}px${important};
width: 100%;
position: absolute;
margin-top: calc(-1 * ${token.marginBlock}px) ${important};
}
'.DraggableNode': {
'&::before': {
content: '" "',
width: '100%',
height: '100%',
position: 'absolute',
cursor: 'col-resize',
},
'&:hover': {
'&::before': {
background: 'var(--colorBgSettingsHover) !important',
},
},
width: `${token.marginBlock}px${important}`,
height: '100%',
position: 'absolute',
cursor: 'col-resize',
},
.CardRow {
display: flex;
position: relative;
}
'.RowDivider': {
height: `${token.marginBlock}px${important}`,
width: '100%',
position: 'absolute',
marginTop: `calc(-1 * ${token.marginBlock}px)${important}`,
},
.showDivider {
margin: 0 calc(-1 * ${token.marginBlock}px) ${important};
}
'.CardRow': {
display: 'flex',
position: 'relative',
},
.nb-grid-warp > button:last-child {
margin-bottom: ${token.marginBlock}px;
}
.nb-grid-warp .nb-grid-warp > button:last-child {
margin-bottom: ${token.margin}px;
}
`,
'.showDivider': {
margin: `0 calc(-1 * ${token.marginBlock}px)${important}`,
},
'.nb-grid-warp > button:last-child': {
marginBottom: `${token.marginBlock}px`,
},
'.nb-grid-warp .nb-grid-warp > button:last-child': {
marginBottom: `${token.margin}px`,
},
} as any,
};
});

View File

@ -332,7 +332,7 @@ export const Grid: any = observer(
const addr = field.address.toString();
const rows = useRowProperties();
const { setPrintContent } = useFormBlockContext();
const { styles } = useStyles();
const { componentCls, hashId } = useStyles();
const distributedValue =
distributed === undefined
? fieldSchema?.parent['x-component'] === 'Page' || fieldSchema?.parent['x-component'] === 'Tabs.TabPane'
@ -355,8 +355,8 @@ export const Grid: any = observer(
return (
<FilterBlockProvider>
<GridContext.Provider value={gridContextValue}>
<div className={cls('nb-grid-container', styles.wrapper)}>
<div className={cls(`nb-grid ${styles.container}`)} style={{ position: 'relative' }} ref={gridRef}>
<div className={cls('nb-grid-container')}>
<div className={cls(`nb-grid ${componentCls} ${hashId}`)} ref={gridRef}>
<div className="nb-grid-warp">
<DndWrapper dndContext={props.dndContext}>
{showDivider ? (