-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adjust grid layout and navigation with screen size and availabe…
… apps - Add tests for navigation of different grid layouts - Add GridNavigation class for grid helper methods - Modify grid layout hook
- Loading branch information
Showing
12 changed files
with
408 additions
and
189 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
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
61 changes: 61 additions & 0 deletions
61
components/header-bar/src/command-palette/hooks/use-grid-layout.js
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,61 @@ | ||
import { useEffect, useMemo, useState } from 'react' | ||
import { useCommandPaletteContext } from '../context/command-palette-context.js' | ||
import { | ||
GRID_COLUMNS_DESKTOP, | ||
GRID_COLUMNS_MOBILE, | ||
GRID_ROWS_DESKTOP, | ||
GRID_ROWS_MOBILE, | ||
} from '../utils/constants.js' | ||
|
||
function getGridLayout(apps, isMobile) { | ||
let columns = isMobile ? GRID_COLUMNS_MOBILE : GRID_COLUMNS_DESKTOP | ||
let rows = isMobile ? GRID_ROWS_MOBILE : GRID_ROWS_DESKTOP | ||
|
||
const expectedGridSize = rows * columns | ||
const availableApps = | ||
apps?.length >= expectedGridSize ? expectedGridSize : apps.length | ||
|
||
if (availableApps && availableApps < expectedGridSize) { | ||
if (availableApps / columns < 1) { | ||
columns = availableApps | ||
rows = 1 | ||
} else if (availableApps % columns === 0) { | ||
rows = availableApps / columns | ||
} else { | ||
rows = Math.trunc(availableApps / columns + 1) | ||
} | ||
} | ||
|
||
return { rows, columns, size: availableApps } | ||
} | ||
|
||
export const useGridLayout = (apps) => { | ||
const { setShowGrid } = useCommandPaletteContext() | ||
|
||
const [isMobile, setIsMobile] = useState(window.innerWidth <= 480) | ||
|
||
useEffect(() => { | ||
setShowGrid(apps?.length > 0) | ||
}, [apps, setShowGrid]) | ||
|
||
useEffect(() => { | ||
const handleResize = () => { | ||
setIsMobile(window.innerWidth <= 480) | ||
} | ||
|
||
handleResize() | ||
window.addEventListener('resize', handleResize) | ||
|
||
return () => window.removeEventListener('resize', handleResize) | ||
}, []) | ||
|
||
const gridLayout = useMemo( | ||
() => getGridLayout(apps, isMobile), | ||
[apps, isMobile] | ||
) | ||
|
||
return { | ||
gridLayout, | ||
isMobile, | ||
} | ||
} |
26 changes: 8 additions & 18 deletions
26
components/header-bar/src/command-palette/hooks/use-modal.js
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
Oops, something went wrong.