-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs] Add density guide to customizations (#16410)
* [docs] Use dense theme * Reduce button size * Reach 48dp touch hit target * Add merge strategy for theme decorators * [Button] Default to small in a dense theme * [FilledInput] Use dense margin in dense theme * [FormControl] Use dense margin in a dense theme * [FormHelperText] Use dense margin in a dense theme * [Fab] Use small size in a dense theme * [IconButton] Use small size in a dense theme * [InputBase] Use dense margin in a dense theme * [InputLabel] Use dense margin in a dense theme * [ListItem] Use dense in a dense theme * [OutlinedInput] Use dense margin in a dense theme * [Table] Use small size in a dense theme * [Toolbar] Use dense variant in a dense theme * [docs] Update dense theme * [docs] Update API docs regarding density * Fancy dense switch [skip ci] * New draft for density guide * Test that density priority is props > context > theme * Exclude density customization * Remove theme.dense * Apply suggestions from Matt's code review Co-Authored-By: Matt <github@nospam.33m.co> * Apply suggestions from code review Co-Authored-By: Matt <github@nospam.33m.co>
- Loading branch information
Showing
10 changed files
with
353 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
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,94 @@ | ||
import React from 'react'; | ||
import { useTheme } from '@material-ui/core/styles'; | ||
import Grid from '@material-ui/core/Grid'; | ||
import Input from '@material-ui/core/Input'; | ||
import Typography from '@material-ui/core/Typography'; | ||
import Button from '@material-ui/core/Button'; | ||
import IconButton from '@material-ui/core/IconButton'; | ||
import FormControlLabel from '@material-ui/core/FormControlLabel'; | ||
import Switch from '@material-ui/core/Switch'; | ||
import { DispatchContext } from 'docs/src/modules/components/ThemeContext'; | ||
import IncreaseIcon from '@material-ui/icons/AddCircleOutline'; | ||
import DecreaseIcon from '@material-ui/icons/RemoveCircleOutline'; | ||
import { useSelector } from 'react-redux'; | ||
|
||
const minSpacing = 0; | ||
const maxSpacing = 20; | ||
|
||
export default function DensityTool() { | ||
const dispatch = React.useContext(DispatchContext); | ||
function handleDensityChange(event) { | ||
dispatch({ type: 'SET_DENSE', payload: event.target.checked }); | ||
} | ||
|
||
function handleSpacingChange(event, value) { | ||
dispatch({ type: 'SET_SPACING', payload: value || +event.target.value }); | ||
} | ||
|
||
function increaseSpacing() { | ||
dispatch({ type: 'INCREASE_SPACING' }); | ||
} | ||
|
||
function decreaseSpacing() { | ||
dispatch({ type: 'DECREASE_SPACING' }); | ||
} | ||
|
||
function resetDensity() { | ||
dispatch({ type: 'RESET_DENSITY' }); | ||
} | ||
|
||
const theme = useTheme(); | ||
const spacingUnit = theme.spacing(1); | ||
|
||
const t = useSelector(state => state.options.t); | ||
|
||
return ( | ||
<Grid container spacing={2}> | ||
<Grid container item> | ||
<FormControlLabel | ||
control={ | ||
<Switch | ||
checked={theme.dense} | ||
onChange={handleDensityChange} | ||
value="dense" | ||
color="secondary" | ||
/> | ||
} | ||
label={t('useHighDensity')} | ||
/> | ||
</Grid> | ||
<Grid container item alignItems="center" spacing={2}> | ||
<Grid item> | ||
<Typography id="input-slider" gutterBottom> | ||
{t('spacingUnit')} | ||
</Typography> | ||
</Grid> | ||
<Grid item> | ||
<IconButton aria-label={t('increaseSpacing')} onClick={decreaseSpacing}> | ||
<DecreaseIcon /> | ||
</IconButton> | ||
<Input | ||
value={spacingUnit} | ||
margin="dense" | ||
onChange={handleSpacingChange} | ||
inputProps={{ | ||
step: 1, | ||
min: minSpacing, | ||
max: maxSpacing, | ||
type: 'number', | ||
'aria-labelledby': 'input-slider', | ||
}} | ||
/> | ||
<IconButton aria-label={t('decreaseSpacing')} onClick={increaseSpacing}> | ||
<IncreaseIcon /> | ||
</IconButton> | ||
</Grid> | ||
</Grid> | ||
<Grid item> | ||
<Button color="primary" variant="contained" onClick={resetDensity}> | ||
{t('resetDensity')} | ||
</Button> | ||
</Grid> | ||
</Grid> | ||
); | ||
} |
Oops, something went wrong.