Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AppBar] Add color transparent support #19393

Merged
merged 3 commits into from Feb 3, 2020
Merged

[AppBar] Add color transparent support #19393

merged 3 commits into from Feb 3, 2020

Conversation

ghost
Copy link

@ghost ghost commented Jan 26, 2020

Closes #19391

@ghost
Copy link
Author

ghost commented Jan 26, 2020

A fix for #19391.

@ghost ghost requested review from mbrookes and oliviertassinari January 26, 2020 03:12
@mui-pr-bot
Copy link

mui-pr-bot commented Jan 26, 2020

Details of bundle changes.

Comparing: 39c8170...e269421

bundle Size Change Size Gzip Change Gzip
AppBar ▲ +81 B (+0.13% ) 64.2 kB ▲ +24 B (+0.12% ) 20.1 kB
docs.main ▲ +81 B (+0.01% ) 596 kB ▲ +14 B (+0.01% ) 194 kB
@material-ui/core[umd] ▲ +81 B (+0.03% ) 317 kB ▲ +9 B (+0.01% ) 91.9 kB
@material-ui/core ▲ +81 B (+0.02% ) 361 kB ▲ +7 B (+0.01% ) 98.7 kB
@material-ui/lab -- 185 kB -- 55.3 kB
@material-ui/styles -- 51.4 kB -- 15.4 kB
@material-ui/system -- 14.8 kB -- 4.07 kB
Alert -- 84 kB -- 26.3 kB
AlertTitle -- 64.3 kB -- 20.3 kB
Autocomplete -- 132 kB -- 41.4 kB
Avatar -- 65.4 kB -- 20.7 kB
AvatarGroup -- 62.4 kB -- 19.6 kB
Backdrop -- 68 kB -- 21 kB
Badge -- 65.5 kB -- 20.4 kB
BottomNavigation -- 62.6 kB -- 19.6 kB
BottomNavigationAction -- 75.7 kB -- 23.9 kB
Box -- 71 kB -- 21.7 kB
Breadcrumbs -- 67.9 kB -- 21.3 kB
Button -- 79.9 kB -- 24.5 kB
ButtonBase -- 74.2 kB -- 23.3 kB
ButtonGroup -- 83.4 kB -- 25.5 kB
Card -- 63 kB -- 19.7 kB
CardActionArea -- 75.3 kB -- 23.7 kB
CardActions -- 62.2 kB -- 19.5 kB
CardContent -- 62.1 kB -- 19.5 kB
CardHeader -- 65.2 kB -- 20.5 kB
CardMedia -- 62.5 kB -- 19.7 kB
Checkbox -- 83.2 kB -- 26.3 kB
Chip -- 82.8 kB -- 25.4 kB
CircularProgress -- 64.3 kB -- 20.3 kB
ClickAwayListener -- 3.91 kB -- 1.55 kB
Collapse -- 68.2 kB -- 21.1 kB
colorManipulator -- 3.88 kB -- 1.52 kB
Container -- 63.4 kB -- 19.8 kB
CssBaseline -- 57.7 kB -- 18.1 kB
Dialog -- 83.2 kB -- 25.9 kB
DialogActions -- 62.2 kB -- 19.5 kB
DialogContent -- 62.4 kB -- 19.6 kB
DialogContentText -- 64.2 kB -- 20.2 kB
DialogTitle -- 64.4 kB -- 20.2 kB
Divider -- 62.7 kB -- 19.7 kB
docs.landing -- 60.5 kB -- 16.4 kB
Drawer -- 85 kB -- 25.8 kB
ExpansionPanel -- 72.5 kB -- 22.7 kB
ExpansionPanelActions -- 62.2 kB -- 19.5 kB
ExpansionPanelDetails -- 62.1 kB -- 19.5 kB
ExpansionPanelSummary -- 78.3 kB -- 24.7 kB
Fab -- 77 kB -- 24 kB
Fade -- 23.4 kB -- 7.98 kB
FilledInput -- 73.7 kB -- 22.9 kB
FormControl -- 64.6 kB -- 20.2 kB
FormControlLabel -- 65.7 kB -- 20.7 kB
FormGroup -- 62.2 kB -- 19.5 kB
FormHelperText -- 63.5 kB -- 20 kB
FormLabel -- 63.6 kB -- 19.8 kB
Grid -- 65.3 kB -- 20.5 kB
GridList -- 62.6 kB -- 19.7 kB
GridListTile -- 63.9 kB -- 20 kB
GridListTileBar -- 63.4 kB -- 19.9 kB
Grow -- 24 kB -- 8.19 kB
Hidden -- 66.1 kB -- 20.8 kB
Icon -- 62.9 kB -- 19.8 kB
IconButton -- 76.3 kB -- 23.8 kB
Input -- 72.7 kB -- 22.7 kB
InputAdornment -- 65.3 kB -- 20.5 kB
InputBase -- 70.8 kB -- 22.2 kB
InputLabel -- 65.5 kB -- 20.2 kB
LinearProgress -- 65.5 kB -- 20.5 kB
Link -- 66.8 kB -- 21.1 kB
List -- 62.5 kB -- 19.5 kB
ListItem -- 77.3 kB -- 24.2 kB
ListItemAvatar -- 62.3 kB -- 19.5 kB
ListItemIcon -- 62.3 kB -- 19.5 kB
ListItemSecondaryAction -- 62.2 kB -- 19.5 kB
ListItemText -- 65.1 kB -- 20.5 kB
ListSubheader -- 62.9 kB -- 19.8 kB
Menu -- 89 kB -- 27.4 kB
MenuItem -- 78.4 kB -- 24.5 kB
MenuList -- 66.2 kB -- 20.7 kB
MobileStepper -- 68 kB -- 21.4 kB
Modal -- 14.5 kB -- 5.05 kB
NativeSelect -- 77 kB -- 24.3 kB
NoSsr -- 2.19 kB -- 1.04 kB
OutlinedInput -- 74.7 kB -- 23.3 kB
Paper -- 62.5 kB -- 19.5 kB
Popover -- 83.3 kB -- 25.8 kB
Popper -- 28.8 kB -- 10.3 kB
Portal -- 2.92 kB -- 1.3 kB
Radio -- 84.2 kB -- 26.5 kB
RadioGroup -- 64.6 kB -- 20.1 kB
Rating -- 70.7 kB -- 22.7 kB
RootRef -- 4.24 kB -- 1.64 kB
Select -- 117 kB -- 34.6 kB
Skeleton -- 63.1 kB -- 20 kB
Slide -- 25.5 kB -- 8.71 kB
Slider -- 76.8 kB -- 24.3 kB
Snackbar -- 75.6 kB -- 23.7 kB
SnackbarContent -- 63.7 kB -- 20.1 kB
SpeedDial -- 86.4 kB -- 27.2 kB
SpeedDialAction -- 119 kB -- 37.5 kB
SpeedDialIcon -- 64.7 kB -- 20.3 kB
Step -- 62.8 kB -- 19.7 kB
StepButton -- 82.5 kB -- 26.1 kB
StepConnector -- 62.9 kB -- 19.8 kB
StepContent -- 69.3 kB -- 21.7 kB
StepIcon -- 64.8 kB -- 20.2 kB
StepLabel -- 68.8 kB -- 21.7 kB
Stepper -- 65 kB -- 20.5 kB
styles/createMuiTheme -- 16.5 kB -- 5.81 kB
SvgIcon -- 63.2 kB -- 19.8 kB
SwipeableDrawer -- 92.4 kB -- 28.9 kB
Switch -- 82.3 kB -- 26 kB
Tab -- 76.5 kB -- 24.2 kB
Table -- 62.7 kB -- 19.7 kB
TableBody -- 62.3 kB -- 19.5 kB
TableCell -- 64.2 kB -- 20.2 kB
TableContainer -- 62.1 kB -- 19.5 kB
TableFooter -- 62.3 kB -- 19.5 kB
TableHead -- 62.3 kB -- 19.5 kB
TablePagination -- 144 kB -- 42 kB
TableRow -- 62.6 kB -- 19.7 kB
TableSortLabel -- 77.6 kB -- 24.4 kB
Tabs -- 85.8 kB -- 27.2 kB
TextareaAutosize -- 5.12 kB -- 2.14 kB
TextField -- 125 kB -- 36.6 kB
ToggleButton -- 76.3 kB -- 24.2 kB
ToggleButtonGroup -- 63.4 kB -- 20 kB
Toolbar -- 62.5 kB -- 19.6 kB
Tooltip -- 102 kB -- 32.4 kB
TreeItem -- 74.2 kB -- 23.5 kB
TreeView -- 66.8 kB -- 21.1 kB
Typography -- 63.8 kB -- 20 kB
useAutocomplete -- 14.6 kB -- 5.3 kB
useMediaQuery -- 2.58 kB -- 1.07 kB
Zoom -- 23.5 kB -- 8.1 kB

Generated by 🚫 dangerJS against e269421

@oliviertassinari oliviertassinari added the component: app bar This is the name of the generic UI component, not the React module! label Jan 26, 2020
@oliviertassinari oliviertassinari changed the title Fix AppBar color='inherit' [AppBar] Fix color inherit Jan 26, 2020
Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that we can accept the changes.
The use case is about keeping the background with a fixed positioning while leveraging color inheritance

packages/material-ui/src/AppBar/AppBar.js Show resolved Hide resolved
@oliviertassinari oliviertassinari added the out of scope The problem looks valid but we won't fix it (maybe we will revisit it in the future) label Jan 26, 2020
@ghost
Copy link
Author

ghost commented Jan 26, 2020

The use case is about keeping the background with a fixed positioning while leveraging color inheritance

I don't understand this. Can you please explain what's the intended strategy for color and backgrondColor styling when AppBar is passed color='inherit' prop?

@oliviertassinari
Copy link
Member

@lexskir I have looked at an older project I worked on and noticed we have used the color="inherit" prop only so we would get the paper background color. So from my perspective, the prop serves its purpose. However, I think that we can consider a better API/implementation for v5. Any idea? Some dimensions we could take into account:

  • In dark mode, the app bar shouldn't be colored
  • the background and the color need to be linked to guarantee AA+ contrast ratio.
  • a color prop that modifies the background color seems off.

@ghost
Copy link
Author

ghost commented Jan 26, 2020

In my opinion, color prop name is OK since you have it on <Button> as well and it doesn't seem to cause confusion. E.g. when people talk about button color they normally mean its background color, not its font color, despite the CSS naming conventions. However inherit is very confusing as a value. Users of the AppBar component should not be expected to know about its internal implementation detail - that it uses Paper under the cover. I had assumed that inherit inherits the color from the containing element which seemed very intuitive and caused me to file a bug and write this PR in the first place. Another clear way to achieve the same functionality as I expected is to add a transparent value for the color prop. What do you think?

@ghost
Copy link
Author

ghost commented Jan 26, 2020

Just to make it clear, which color=transparent, I don't mean CSS transparency. I mean the implementation is suggested above, where both backgroundColor and color CSS properties have the value inherit.

@oliviertassinari
Copy link
Member

@lexskir I like the transparent proposal, I have no objection to this new value 👍.

In 2018, I was doing the following:

import React from 'react'
import PropTypes from 'prop-types'
import classNames from 'classnames'
import { withStyles } from '@material-ui/core/styles'
import MuiAppBar from '@material-ui/core/AppBar'
import MuiToolbar from '@material-ui/core/Toolbar'

const styles = theme => ({
  root: {
    boxShadow: '0 0px 20px 0px rgba(0, 0, 0, 0.05)',
    paddingLeft: theme.spacing.unit * 4,
    paddingRight: theme.spacing.unit * 4,
    [theme.breakpoints.down('xs')]: {
      paddingLeft: theme.spacing.unit * 2,
      paddingRight: theme.spacing.unit * 2,
    },
  },
  transparent: {
    backgroundColor: 'transparent',
    boxShadow: 'none',
    '& a': {
      color: theme.palette.grey[300],
      '&:hover': {
        color: theme.palette.common.white,
      },
    },
  },
  essential: {
    boxShadow: 'none',
  },
  toolbar: {
    padding: 0,
  },
})

function AppBar(props) {
  const { children, classes, essential, header, position, transparent } = props

  return (
    <MuiAppBar
      className={classNames(classes.root, {
        [classes.transparent]: transparent,
        [classes.essential]: essential,
        'mui-fixed': transparent,
      })}
      color="inherit"
      elevation={0}
      position={transparent ? 'absolute' : position}
    >
      {header}
      <MuiToolbar className={classes.toolbar}>{children}</MuiToolbar>
    </MuiAppBar>
  )
}

AppBar.displayName = 'AppBar'

AppBar.propTypes = {
  children: PropTypes.node.isRequired,
  classes: PropTypes.object.isRequired,
  essential: PropTypes.bool,
  header: PropTypes.node,
  position: PropTypes.string,
  transparent: PropTypes.bool,
}

AppBar.defaultProps = {
  position: 'static',
}

export default withStyles(styles)(AppBar)

@oliviertassinari oliviertassinari added PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI and removed out of scope The problem looks valid but we won't fix it (maybe we will revisit it in the future) labels Jan 27, 2020
@oliviertassinari
Copy link
Member

@lexskir So, do you want to introduce a new 'transparent' value for the color prop? :)

@oliviertassinari oliviertassinari removed the PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI label Feb 1, 2020
@oliviertassinari oliviertassinari changed the title [AppBar] Fix color inherit [AppBar] Add color transparent support Feb 1, 2020
Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried an approach, let us know if it covers your need!

@@ -5,7 +5,7 @@ export interface AppBarProps extends StandardProps<PaperProps, AppBarClassKey> {
/**
* The color of the component. It supports those theme colors that make sense for this component.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description should probably be updated, since 'transparent' isn't a theme color.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What new description do you have in mind?

Copy link
Member

@joshwooding joshwooding Feb 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“It supports transparent and those theme colors that make sense ...”?

Copy link
Member

@mbrookes mbrookes Feb 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inherit has the same problem, and it hasn't caused any concern so far with this or other components, so I guess we can leave it as is for now.

@oliviertassinari oliviertassinari merged commit 62e439b into mui:master Feb 3, 2020
EsoterikStare pushed a commit to EsoterikStare/material-ui that referenced this pull request Feb 13, 2020
* Fix `AppBar color='inherit'`

* Update docs

* [AppBar] Add color transparent support

Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: app bar This is the name of the generic UI component, not the React module! new feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

<AppBar color='inherit'> does not work
4 participants