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

add useResponsive #40

Merged
merged 8 commits into from
Aug 25, 2019
Merged

add useResponsive #40

merged 8 commits into from
Aug 25, 2019

Conversation

awmleer
Copy link
Collaborator

@awmleer awmleer commented Aug 25, 2019

image

interface ResponsiveInfo {
[key: string]: boolean;
}
function configResponsive(config: ResponsiveConfig): void
Copy link
Collaborator

Choose a reason for hiding this comment

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

文档需要再完善下,比如 ResponsiveConfig 的默认值是什么?如何设置。 光看 这个文档 应该看不太懂。

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

对。。这块文档还需要再补充一下

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@brickspert 文档更新好了~

{
()=>{
function Demo(){
const responsive = useResponsive();
Copy link
Collaborator

Choose a reason for hiding this comment

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

我个人理解 useResponsive 返回的应该是 'lg' | 'xs' 等,就是一个字符串。
而目前是一个对象,感觉不太好。 @tli4 你觉得呢。

{
  'lg': true,
  'md': false
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

我最开始写的时候,是返回的字符串'lg'这样的,但是发现这样其实用起来非常不方便。
例如bootstrap中的.col-md-8,对应到这里的话,就是:

const responsive = useResponsive()
return responsive.md ? (...) : (...)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

如果只是返回一个breakpoint的名字,那么就只能知道满足条件的“最宽”的那个节点。
然而很多时候需要的逻辑是:当前页面的宽度是否已经大于了某个breakpoint,那么就需要写成:

const responsive = useResponsive() // responsive: 'lg' | 'md' | ...
return (responsive === 'md' || responsive === 'lg' || responsive === 'xl') ? (...) : (...)

就会变得非常复杂而且容易出错。

Copy link
Collaborator

Choose a reason for hiding this comment

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

确实是,我去看了下 antd pro 的用法,它是使用了 react-container-query,也是返回的 object。


### 配置

默认的响应式配置和bootstrap是一致的:
Copy link
Collaborator

Choose a reason for hiding this comment

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

中英文之间加空格哦

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

改好了

.eslintrc.js Outdated
@@ -0,0 +1,102 @@
"use strict";
module.exports = {
extends: [
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个文件扩展下 @umijs/fabric/dist/eslint 就可以吧?
image

@brickspert
Copy link
Collaborator

+1

@brickspert brickspert self-requested a review August 25, 2019 14:22
@brickspert brickspert merged commit f9f685f into alibaba:master Aug 25, 2019
@awmleer awmleer deleted the feat/use-responsive branch August 25, 2019 14:32
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.

2 participants