-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Conversation
awmleer
commented
Aug 25, 2019
•
edited
Loading
edited
interface ResponsiveInfo { | ||
[key: string]: boolean; | ||
} | ||
function configResponsive(config: ResponsiveConfig): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
文档需要再完善下,比如 ResponsiveConfig 的默认值是什么?如何设置。 光看 这个文档 应该看不太懂。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对。。这块文档还需要再补充一下
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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
}
There was a problem hiding this comment.
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 ? (...) : (...)
There was a problem hiding this comment.
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') ? (...) : (...)
就会变得非常复杂而且容易出错。
There was a problem hiding this comment.
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。
src/useResponsive/index.mdx
Outdated
|
||
### 配置 | ||
|
||
默认的响应式配置和bootstrap是一致的: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
中英文之间加空格哦
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
There was a problem hiding this comment.
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: [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 |