forked from ant-design/ant-design
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: useBreakpoint hook (ant-design#22226)
* feat: useBreakpoint hook * update snapshots * update snapshots * update snapshots * add useBreakpoint hook test
- Loading branch information
1 parent
869f93d
commit 61d0d6b
Showing
8 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ Array [ | |
"Drawer", | ||
"Empty", | ||
"Form", | ||
"Grid", | ||
"Input", | ||
"InputNumber", | ||
"Layout", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
order: 10 | ||
title: useBreakpoint Hook | ||
--- | ||
|
||
## zh-CN | ||
|
||
使用 `useBreakpoint` Hook 个性化布局。 | ||
|
||
## en-US | ||
|
||
Use `useBreakpoint` Hook povide personalized layout. | ||
|
||
```jsx | ||
import { Row, Col, Grid } from 'antd'; | ||
|
||
const { useBreakpoint } = Grid; | ||
|
||
function UseBreakpointDemo() { | ||
const screens = useBreakpoint(); | ||
|
||
return ( | ||
<Row> | ||
<Col> | ||
Current break point: | ||
{Object.entries(screens) | ||
.filter(screen => !!screen[1]) | ||
.map(screen => screen[0]) | ||
.join(' ')} | ||
</Col> | ||
</Row> | ||
); | ||
} | ||
|
||
ReactDOM.render(<UseBreakpointDemo />, mountNode); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useEffect, useState } from 'react'; | ||
import ResponsiveObserve, { ScreenMap } from '../../_util/responsiveObserve'; | ||
|
||
function useBreakpoint(): ScreenMap { | ||
const [screens, setScreens] = useState<ScreenMap>({}); | ||
|
||
useEffect(() => { | ||
const token = ResponsiveObserve.subscribe(supportScreens => { | ||
setScreens(supportScreens); | ||
}); | ||
|
||
return () => ResponsiveObserve.unsubscribe(token); | ||
}, []); | ||
|
||
return screens; | ||
} | ||
|
||
export default useBreakpoint; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
import Row from './row'; | ||
import Col from './col'; | ||
import useBreakpoint from './hooks/useBreakpoint'; | ||
|
||
export { RowProps } from './row'; | ||
export { ColProps, ColSize } from './col'; | ||
|
||
export { Row, Col }; | ||
|
||
export default { useBreakpoint }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ Array [ | |
"Drawer", | ||
"Empty", | ||
"Form", | ||
"Grid", | ||
"Input", | ||
"InputNumber", | ||
"Layout", | ||
|