-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3912794
commit 0087c4f
Showing
6 changed files
with
59 additions
and
56 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
25 changes: 0 additions & 25 deletions
25
packages/dataviews/src/dataviews-layouts/grid/use-density-options.ts
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
packages/dataviews/src/dataviews-layouts/grid/use-grid-style.ts
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,45 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useViewportMatch } from '@wordpress/compose'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { ViewGrid } from '../../types'; | ||
import { Density } from '../../types'; | ||
|
||
export default function useGridStyle( view: ViewGrid ) { | ||
const isXHuge = useViewportMatch( 'xhuge' ); | ||
const isHuge = useViewportMatch( 'huge' ); | ||
const isXlarge = useViewportMatch( 'xlarge' ); | ||
const isMedium = useViewportMatch( 'small' ); | ||
// The `Density.medium` (default) is handled with css. If another density is selected, | ||
// we query the viewport to determine the number of columns to display per option. | ||
if ( | ||
! [ Density.comfortable, Density.compact ].includes( | ||
view.density as Density | ||
) | ||
) { | ||
return; | ||
} | ||
|
||
let gridColumns; | ||
if ( isXHuge ) { | ||
gridColumns = { min: 4, max: 6 }; | ||
} else if ( isHuge ) { | ||
gridColumns = { min: 3, max: 5 }; | ||
} else if ( isXlarge ) { | ||
gridColumns = { min: 2, max: 4 }; | ||
} else if ( isMedium ) { | ||
gridColumns = { min: 1, max: 3 }; | ||
} else { | ||
// Default to mobile. | ||
gridColumns = { min: 1, max: 2 }; | ||
} | ||
return { | ||
gridTemplateColumns: `repeat(${ | ||
view.density === Density.compact ? gridColumns.max : gridColumns.min | ||
}, minmax(0, 1fr))`, | ||
}; | ||
} |
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