-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update: Data views grid layout: Allow users to adjust grid density, a…
…nd consumers to set default density
- Loading branch information
1 parent
abdc991
commit 1b3bbbc
Showing
6 changed files
with
105 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { RangeControl, Button } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { useViewportMatch } from '@wordpress/compose'; | ||
import { plus, lineSolid } from '@wordpress/icons'; | ||
|
||
export function useDensityValue( densityDelta: number ) { | ||
const isHuge = useViewportMatch( 'huge', '>=' ); | ||
const isXlarge = useViewportMatch( 'xlarge', '>=' ); | ||
const isMobile = useViewportMatch( 'mobile', '>=' ); | ||
if ( isHuge ) { | ||
return 4 + densityDelta; | ||
} | ||
if ( isXlarge ) { | ||
return 3 + densityDelta; | ||
} | ||
if ( isMobile ) { | ||
return 2 + densityDelta; | ||
} | ||
return 1 + densityDelta; | ||
} | ||
|
||
export default function DensityPicker( { | ||
densityDelta, | ||
setDensityDelta, | ||
}: { | ||
densityDelta: number; | ||
setDensityDelta: ( delta: number ) => void; | ||
} ) { | ||
const densityValue = useDensityValue( densityDelta ); | ||
const sumValue = densityValue - densityDelta; | ||
return ( | ||
<> | ||
<Button | ||
size="compact" | ||
icon={ lineSolid } | ||
label={ __( 'Decrease density' ) } | ||
onClick={ () => { | ||
setDensityDelta( densityDelta - 1 ); | ||
} } | ||
/> | ||
<RangeControl | ||
className="dataviews-density-picker__range-control" | ||
label={ __( 'Density' ) } | ||
hideLabelFromVision | ||
value={ densityValue } | ||
min={ 1 } | ||
max={ 10 } | ||
withInputField={ false } | ||
onChange={ ( value = 0 ) => { | ||
setDensityDelta( value - sumValue ); | ||
} } | ||
step={ 1 } | ||
/> | ||
<Button | ||
size="compact" | ||
icon={ plus } | ||
label={ __( 'Increase density' ) } | ||
onClick={ () => { | ||
setDensityDelta( densityDelta + 1 ); | ||
} } | ||
/> | ||
</> | ||
); | ||
} |
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