Skip to content

Commit

Permalink
fix: 修复嵌套 container 宽度计算错乱逻辑 (#652)
Browse files Browse the repository at this point in the history
修复两种类型的 gap 嵌套使用导致 grid 宽度意外减去了 gap 的问题

Co-authored-by: Jack <[email protected]>
  • Loading branch information
iahu and jack0pan authored Dec 29, 2020
1 parent e5c9c0a commit 7158844
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/components/src/components/grid/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const Grid: React.FC<GridProps> = (props: React.PropsWithChildren<GridProps>) =>
data-collapse={collapse}
data-gap={!!gap}
data-container={!!container}
data-full={isNumber(span) && (span as number) >= 12}
style={{ ...cssProps, ...style }}
>
{children}
Expand Down
23 changes: 14 additions & 9 deletions packages/components/src/components/grid/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,37 @@
box-sizing: border-box;

--gio-grid-gap-size: calc(var(--gio-grid-gap, 0) * 8px);
--gio-grid-gap-bias: 1;

&[data-container='true'] {
position: relative;
width: 100%;
}

&[data-full='true'] {
--gio-grid-gap-bias: 0;
}

.normal-gap {
width: calc(100% * var(--gio-grid-span) / 12 - var(--gio-grid-gap-size));
width: calc(100% * var(--gio-grid-span) / 12 - (var(--gio-grid-gap-bias) * var(--gio-grid-gap-size)));

&[data-gap='true'] {
> * {
--gio-grid-item-marign: calc(var(--gio-grid-gap-size) / 2);
margin: var(--gio-grid-item-marign);
&[data-gap='true'][data-collapse='false'] {
> [data-gap] {
--gio-grid-item-marign: calc(var(--gio-grid-gap-bias) * var(--gio-grid-gap-size) / 2);
margin: calc(var(--gio-grid-gap-bias) * var(--gio-grid-item-marign));
}
}
}

.css-grid-gap {
gap: var(--gio-grid-gap-size);
width: calc((100% + var(--gio-grid-gap-size)) / 12 * var(--gio-grid-span) - var(--gio-grid-gap-size));
width: calc(
(100% + var(--gio-grid-gap-size)) / 12 * var(--gio-grid-span) -
(var(--gio-grid-gap-bias) * var(--gio-grid-gap-size))
);

&[data-gap='true'] {
--gio-grid-item-marign: unset;
// > * {
// margin: unset !important;
// }
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import { Grid } from '@gio-design/components';

import '@gio-design/components/es/components/grid/style/index.css';
import './style.less';

const Base = (): JSX.Element => {
return (
<Grid className="demo">
<Grid span={12}>span=12</Grid>
<Grid container span={12} gap={1}>
<Grid span={3}>span=3</Grid>
<Grid container span={9} gap={1}>
<Grid span={6}>span=6</Grid>
<Grid span={6}>span=6</Grid>
</Grid>
</Grid>
</Grid>
);
};

export default Base;
3 changes: 3 additions & 0 deletions packages/website/src/components/basic/grid/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ group:

打开控制台,查看元素,Demo 的 calssName 前缀应该已经替换成了 `cool`。对应的 less 变量也替换了。

## 嵌套

`Grid` 可以多层嵌套使用

<code src='./demo/nested.tsx' title='嵌套使用' />
<code src='./demo/nested-container.tsx' title='嵌套 container' />

### 间距

Expand Down

1 comment on commit 7158844

@vercel
Copy link

@vercel vercel bot commented on 7158844 Dec 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.