forked from primefaces/primereact
-
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.
Fix primefaces#3693: Datatable allow responsive stack and scrollable
- Loading branch information
Showing
4 changed files
with
81 additions
and
27 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
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,13 +1,14 @@ | ||
import { usePrevious } from './usePrevious'; | ||
import { useMountEffect } from './useMountEffect'; | ||
import { useUpdateEffect } from './useUpdateEffect'; | ||
import { useUnmountEffect } from './useUnmountEffect'; | ||
import { useEventListener } from './useEventListener'; | ||
import { useInterval } from './useInterval'; | ||
import { useMediaQuery } from './useMediaQuery'; | ||
import { useMountEffect } from './useMountEffect'; | ||
import { useOverlayListener } from './useOverlayListener'; | ||
import { useOverlayScrollListener } from './useOverlayScrollListener'; | ||
import { usePrevious } from './usePrevious'; | ||
import { useResizeListener } from './useResizeListener'; | ||
import { useInterval } from './useInterval'; | ||
import { useStorage, useLocalStorage, useSessionStorage } from './useStorage'; | ||
import { useLocalStorage, useSessionStorage, useStorage } from './useStorage'; | ||
import { useTimeout } from './useTimeout'; | ||
import { useUnmountEffect } from './useUnmountEffect'; | ||
import { useUpdateEffect } from './useUpdateEffect'; | ||
|
||
export { usePrevious, useMountEffect, useUpdateEffect, useUnmountEffect, useEventListener, useOverlayListener, useOverlayScrollListener, useResizeListener, useInterval, useStorage, useLocalStorage, useSessionStorage, useTimeout }; | ||
export { usePrevious, useMediaQuery, useMountEffect, useUpdateEffect, useUnmountEffect, useEventListener, useOverlayListener, useOverlayScrollListener, useResizeListener, useInterval, useStorage, useLocalStorage, useSessionStorage, useTimeout }; |
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,44 @@ | ||
import { useEffect, useRef, useState } from 'react'; | ||
|
||
/** | ||
* Hook to notify when media queries are satisfied. | ||
* | ||
* @param {*} query the media query like '(min-width: 900px)' | ||
* @param {*} initialValue override the initial value if you don't want it detected | ||
* @returns boolean if the media query matches | ||
*/ | ||
export function useMediaQuery(query, initialValue) { | ||
const [matches, setMatches] = useState(getInitialValue(query, initialValue)); | ||
const queryRef = useRef(); | ||
|
||
useEffect(() => { | ||
if ('matchMedia' in window) { | ||
queryRef.current = window.matchMedia(query); | ||
setMatches(queryRef.current.matches); | ||
|
||
return attachMediaListener(queryRef.current, (event) => setMatches(event.matches)); | ||
} | ||
|
||
return undefined; | ||
}, [query]); | ||
|
||
return matches; | ||
} | ||
|
||
function attachMediaListener(query, callback) { | ||
query.addEventListener('change', callback); | ||
|
||
return () => query.removeEventListener('change', callback); | ||
} | ||
|
||
function getInitialValue(query, initialValue) { | ||
if (typeof initialValue === 'boolean') { | ||
return initialValue; | ||
} | ||
|
||
if (typeof window !== 'undefined' && 'matchMedia' in window) { | ||
return window.matchMedia(query).matches; | ||
} | ||
|
||
return false; | ||
} |