mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 23:16:03 +00:00
perf(Grid): improve style performance
This commit is contained in:
parent
5f9bbf580d
commit
95cabdc409
@ -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,
|
||||
};
|
||||
});
|
||||
|
||||
|
@ -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 ? (
|
||||
|
Loading…
Reference in New Issue
Block a user