Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(SelectionBar): Adapt max actions to wide device
With the French translation, I encountered a spacing issue with the action lists on wide devices. I added a wide breakpoint to have more granularity in the maximum action displayed. Breakpoints are specific to the selection bar because isTiny, isSmall, isMedium, isLarge will be deprecated in useBreakpoint
- Loading branch information
Showing
2 changed files
with
42 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { useState } from 'react' | ||
import throttle from 'lodash/throttle' | ||
|
||
import breakpointDefs, { getBreakpointsStatus } from '../helpers/breakpoints' | ||
import useEventListener from '../hooks/useEventListener' | ||
import { computeMaxAction } from './helpers' | ||
|
||
const huge = 1400 | ||
const large = 1200 | ||
|
||
const breakpoints = { | ||
isHuge: [large + 1, huge], | ||
...breakpointDefs | ||
} | ||
|
||
const getCurrentMaxAction = maxAction => | ||
computeMaxAction(maxAction, getBreakpointsStatus(breakpoints)) | ||
|
||
/** | ||
* Compute the maximum number of actions to display according to the breakpoint | ||
* @param {number|object} maxAction an number or a set of maximum for each breakpoint | ||
* @returns the maximum number or undefined if there is no matching result | ||
*/ | ||
const useMaxActions = maxAction => { | ||
const [currentMax, setCurrentMax] = useState(getCurrentMaxAction(maxAction)) | ||
|
||
const handleResize = throttle(() => { | ||
setCurrentMax(getCurrentMaxAction(maxAction)) | ||
}, 100) | ||
|
||
useEventListener(window, 'resize', handleResize) | ||
|
||
return currentMax | ||
} | ||
|
||
export default useMaxActions |