Skip to content

Commit

Permalink
fix: block height calculation (nocobase#4629)
Browse files Browse the repository at this point in the history
* fix: block height calculation

* fix: test
  • Loading branch information
Katherine authored Jun 12, 2024
1 parent 20f85cd commit aecc4a9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import { useFieldSchema } from '@formily/react';
import cls from 'classnames';
import { css } from '@emotion/css';
import { theme } from 'antd';
import React, { useMemo } from 'react';
import { withDynamicSchemaProps } from '../../../hoc/withDynamicSchemaProps';
import { CustomCreateStylesUtils, createStyles } from '../../../style';
Expand All @@ -18,6 +20,7 @@ import { useGetAriaLabelOfBlockItem } from './hooks/useGetAriaLabelOfBlockItem';
import { ErrorBoundary } from 'react-error-boundary';
import { ErrorFallback } from '../error-fallback';
import { useSchemaToolbarRender } from '../../../application';
import { useDesignable } from '../../';

const useStyles = createStyles(({ css, token }: CustomCreateStylesUtils) => {
return css`
Expand Down Expand Up @@ -81,15 +84,29 @@ export const BlockItem: React.FC<BlockItemProps> = withDynamicSchemaProps(
// 新版 UISchema(1.0 之后)中已经废弃了 useProps,这里之所以继续保留是为了兼容旧版的 UISchema
const { className, children } = useProps(props);
const { styles: blockItemCss } = useStyles();

const fieldSchema = useFieldSchema();
const { render } = useSchemaToolbarRender(fieldSchema);
const { getAriaLabel } = useGetAriaLabelOfBlockItem(props.name);

const { token } = theme.useToken();
const { designable } = useDesignable();
const label = useMemo(() => getAriaLabel(), [getAriaLabel]);

return (
<SortableItem role="button" aria-label={label} className={cls('nb-block-item', className, blockItemCss)}>
<SortableItem
role="button"
aria-label={label}
className={cls(
'nb-block-item',
className,
blockItemCss,
css`
margin-bottom: ${designable ? token.marginLG : 0}px !important;
.ant-card {
margin-bottom: ${designable ? token.marginLG : 0}px !important;
}
`,
)}
>
{render()}
<ErrorBoundary FallbackComponent={ErrorFallback} onError={(err) => console.log(err)}>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('CollectionSelect', () => {
>
<div
aria-label="block-item-demo title"
class="nb-sortable-designer nb-block-item nb-form-item acss-gw2dva"
class="nb-sortable-designer nb-block-item nb-form-item acss-gw2dva css-vua9sf"
role="button"
>
<div
Expand Down Expand Up @@ -187,7 +187,7 @@ describe('CollectionSelect', () => {
>
<div
aria-label="block-item-demo title"
class="nb-sortable-designer nb-block-item nb-form-item acss-gw2dva"
class="nb-sortable-designer nb-block-item nb-form-item acss-gw2dva css-vua9sf"
role="button"
>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const useStyles = genStyleHook('nb-page', (token) => {
},

'.nb-page-wrapper': {
padding: `${token.paddingPageVertical}px ${token.paddingPageHorizontal}px 0px ${token.paddingPageHorizontal}px`,
padding: `${token.paddingPageVertical}px`,
flex: 1,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ const getPageHeaderHeight = (disablePageHeader, enablePageTabs, hidePageTitle, t
}
return token.controlHeight + token.marginXS + (token.paddingXXS + 2) * 2 + token.paddingContentHorizontalLG;
} else {
if (enablePageTabs) {
return (
token.controlPaddingHorizontal + 3 * token.controlPaddingHorizontalSM + 22 + token.paddingContentHorizontalLG
);
}
return token.paddingContentHorizontalLG + 12;
}
}
Expand Down

0 comments on commit aecc4a9

Please sign in to comment.