Skip to content
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

feat: 🆕 new Space component #22363

Merged
merged 12 commits into from
Mar 22, 2020
Merged

feat: 🆕 new Space component #22363

merged 12 commits into from
Mar 22, 2020

Conversation

shaodahong
Copy link
Member

@shaodahong shaodahong commented Mar 18, 2020

🤔 This is a ...

  • New feature
  • Bug fix
  • Site / document update
  • Component style update
  • TypeScript definition update
  • Refactoring
  • Code style optimization
  • Test Case
  • Branch merge
  • Other (about what?)

🔗 Related issue link

Close #19860

💡 Background and solution

📝 Changelog

Language Changelog
🇺🇸 English new Space component
🇨🇳 Chinese 新的 Space 组件

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

View rendered components/space/demo/base.md
View rendered components/space/demo/vertical.md
View rendered components/space/index.en-US.md
View rendered components/space/index.zh-CN.md

@shaodahong shaodahong changed the title feat: 🌹 new Space component feat: new Space component Mar 18, 2020
@ant-design-bot
Copy link
Contributor

ant-design-bot commented Mar 18, 2020

@shaodahong shaodahong changed the title feat: new Space component feat: 🆕 new Space component Mar 18, 2020
@afc163 afc163 requested a review from zombieJ March 18, 2020 12:59
@afc163
Copy link
Member

afc163 commented Mar 18, 2020

wow~

@zombieJ
Copy link
Member

zombieJ commented Mar 18, 2020

wow~ +1

@yoyo837
Copy link
Contributor

yoyo837 commented Mar 18, 2020

wow~ +2

const len = items.length;

return (
<div className={cn} {...otherProps}>
Copy link
Contributor

@yoyo837 yoyo837 Mar 18, 2020

Choose a reason for hiding this comment

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

可不可以是 挂一层ConfigConsumer 修改size等值往下传递的方式, 并且不产生额外DOM的?

Copy link
Member Author

Choose a reason for hiding this comment

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

可以不产生额外的 DOM 但是感觉不太好,不符合组件的规范,用户设置 <Space style className></Space> 发现不生效

Copy link
Member Author

@shaodahong shaodahong Mar 18, 2020

Choose a reason for hiding this comment

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

我自己项目很早就封装了 Space 组件,对实际开发提效有帮助,尤其设置 Button 的时候,但是有一个缺点,就是不支持 <Popconfirm /> 等这种包裹组件

Copy link
Contributor

Choose a reason for hiding this comment

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

我对这个组件的理解就是一个局部的ConfigContext, 至于className,就好比Fragment那样不接受className呗。

Copy link
Member

Choose a reason for hiding this comment

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

尤其设置 Button 的时候,但是有一个缺点,就是不支持 等这种包裹组件

可以给这些组件加个 style 属性传递到 children 上。

Copy link
Member

Choose a reason for hiding this comment

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

不太推荐直接注入样式,我的想法是外层用 inline-flex 保持内联,内部额外一个 dom 做 maring-cell 来处理。这样可以覆盖那些不能注入的情况。

<Space>
  2333
  <Button />
  6666
</Space>

Copy link
Member Author

Choose a reason for hiding this comment

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

外层如果设置 inline-flex 会干扰到内部的样式,需要容错 child 是 块或者行,如果不是 element 我会包个 span

Copy link
Member

Choose a reason for hiding this comment

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

我的理解 Space 就是一个内联的元素,你说的干扰指的是?

Copy link
Member Author

Choose a reason for hiding this comment

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

嗯,想了下你是对的,不能覆盖的组件有点多,一开始想的干扰是内部可能是个块级元素,后台想块级元素没必要包在里面,不需要考虑,我改了

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 1169090767635374d51b4e559cc68287f2ebb695:

Sandbox Source
antd reproduction template Configuration

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 42a48ba4a246fc12fb33e99fde11aa2284f6e052:

Sandbox Source
antd reproduction template Configuration

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 18, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit cab1c8e:

Sandbox Source
antd reproduction template Configuration

@AshoneA
Copy link
Contributor

AshoneA commented Mar 19, 2020

 .space > * {
   margin-right: 10px;
 }

以前我都是这么解决的...

@Nomnomburger
Copy link

Yay I needed this all along! :)

@afc163
Copy link
Member

afc163 commented Mar 19, 2020

  • Add demo for large | default | small size.
  • Add demo for custom number size.

@afc163
Copy link
Member

afc163 commented Mar 19, 2020

rebase 一下 feature 即可修复 ci。

@codecov
Copy link

codecov bot commented Mar 19, 2020

Codecov Report

Merging #22363 into feature will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##           feature   #22363      +/-   ##
===========================================
+ Coverage    98.11%   98.12%   +<.01%     
===========================================
  Files          359      360       +1     
  Lines         7173     7196      +23     
  Branches      1916     1968      +52     
===========================================
+ Hits          7038     7061      +23     
  Misses         135      135
Impacted Files Coverage Δ
components/config-provider/context.tsx 100% <ø> (ø) ⬆️
components/config-provider/index.tsx 95.83% <ø> (ø) ⬆️
components/index.tsx 100% <ø> (ø) ⬆️
components/space/index.tsx 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 86946f4...cab1c8e. Read the comment docs.

components/space/index.tsx Outdated Show resolved Hide resolved
@shaodahong
Copy link
Member Author

shaodahong commented Mar 20, 2020

With like Fragment

<Space>
  233
  {hasAuth && (
    <Space>
      <Button />
      <Button />
    </Space>
  )}
  666
</Space>

components/space/index.tsx Outdated Show resolved Hide resolved
components/space/index.tsx Outdated Show resolved Hide resolved
@shaodahong
Copy link
Member Author

Done.

components/space/index.tsx Outdated Show resolved Hide resolved
@zombieJ
Copy link
Member

zombieJ commented Mar 21, 2020

LGTM

@Airkro
Copy link
Contributor

Airkro commented May 6, 2020

 .space > * {
   margin-right: 10px;
 }

以前我都是这么解决的...

起初光看 releases,我以为 Space 会是 Divider 那样的子组件,能在 Row 当中使用,以代替很多用样式固化的 margin,例如 model/result 的按钮间距。

@afc163
Copy link
Member

afc163 commented May 6, 2020

@Airkro 这也是最开始讨论的其中一种 API 的形式。不过我个人不太能接受类似下面的累加 Space 的写法:

<Button>按钮</Button>
<Space />
<Space />
<Button>按钮</Button>
<Space />
<Button>按钮</Button>
<Button>按钮</Button>
<Space />
<Space />
<Space />
<Button>按钮</Button>

@Airkro
Copy link
Contributor

Airkro commented May 6, 2020

@afc163 如果不进行累加,只使用一个,或许有使用价值,因为组件之间要加 margin 的地方很多。但还是产生了不必要的节点,好像并不划算。

另外建议将 Divider 在文档里的位置移动到 “ 布局 ”

@afc163
Copy link
Member

afc163 commented May 6, 2020

另外建议将 Divider 在文档里的位置移动到 “ 布局 ”

来个 PR~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants