Skip to content

Conversation

@eps1lon
Copy link
Member

@eps1lon eps1lon commented Sep 2, 2019

component prop makes a component more complicated. We do have it documented but I can't see how this makes the component easier to customize. I would even argue that the change improved customization.

In any case this change is queued for v5

@eps1lon eps1lon added breaking change Introduces changes that are not backward compatible. component: SvgIcon The React component. labels Sep 2, 2019
@eps1lon eps1lon added this to the v5 milestone Sep 2, 2019
@mui-pr-bot
Copy link

mui-pr-bot commented Sep 2, 2019

Details of bundle changes.

Comparing: 7c3be01...37e1344

bundle parsed diff gzip diff prev parsed current parsed prev gzip current gzip
@material-ui/core -0.01% -0.01% 330,921 330,878 90,355 90,346
@material-ui/core/Paper 0.00% 0.00% 68,774 68,774 20,485 20,485
@material-ui/core/Paper.esm 0.00% 0.00% 62,148 62,148 19,214 19,214
@material-ui/core/Popper 0.00% 0.00% 28,466 28,466 10,190 10,190
@material-ui/core/Textarea 0.00% 0.00% 5,094 5,094 2,137 2,137
@material-ui/core/TrapFocus 0.00% 0.00% 3,834 3,834 1,613 1,613
@material-ui/core/styles/createMuiTheme 0.00% 0.00% 16,385 16,385 5,827 5,827
@material-ui/core/useMediaQuery 0.00% 0.00% 2,541 2,541 1,058 1,058
@material-ui/lab -0.03% -0.03% 153,179 153,136 46,669 46,654
@material-ui/styles 0.00% 0.00% 51,492 51,492 15,303 15,303
@material-ui/system 0.00% 0.00% 15,668 15,668 4,359 4,359
Button 0.00% 0.00% 78,661 78,661 24,053 24,053
Modal 0.00% 0.00% 14,335 14,335 5,017 5,017
Portal 0.00% 0.00% 2,907 2,907 1,318 1,318
Rating -0.06% -0.06% 70,014 69,971 21,866 21,852
Slider 0.00% 0.00% 74,282 74,282 23,012 23,012
colorManipulator 0.00% 0.00% 3,904 3,904 1,543 1,543
docs.landing 0.00% 0.00% 52,253 52,253 13,780 13,780
docs.main -0.01% -0.01% 597,346 597,303 190,794 190,782
packages/material-ui/build/umd/material-ui.production.min.js -0.01% +0.01% 🔺 301,843 301,800 86,690 86,696

Generated by 🚫 dangerJS against 37e1344

@oliviertassinari
Copy link
Member

What do we do with this demo https://material-ui.com/components/icons/#svg-icons?

@oliviertassinari
Copy link
Member

oliviertassinari commented Sep 2, 2019

I believe that the component prop is used anytime the SVG needs to be extended. Would this solution scale to the rest of the codebase?

@eps1lon
Copy link
Member Author

eps1lon commented Sep 2, 2019

What do we do with this demo material-ui.com/components/icons/#svg-icons?

Yep already fixed that but forgot to push. This is why I said the new approach is even better IMO.

@oliviertassinari
Copy link
Member

oliviertassinari commented Sep 2, 2019

Yep already fixed that but forgot to push. This is why I said the new approach is even better IMO.

I wish it could be that simple, but I think we need to add another constraint. Most people are using the pre-maid SVG icons. The solution was designed to accept @material-ui/icons/Home as input.

@mbrookes
Copy link
Member

mbrookes commented Sep 2, 2019

What percentage of the user-base do you estimate is performing advanced customisation of the stock icons in a way that required the component prop? (Or, perhaps, how many fingers of one hand does it represent?! 😉)

We should balance making it marginally easier for the few, vs, the overhead for everyone else.

I'm in favour of this change. Those that need to go further can do as you have done in this demo and create the icon as needed using the SvgIcon component (it's what it's there for after all).

@oliviertassinari
Copy link
Member

Removing it and seeing nobody complain would be a good confirmation of the hypotheses.

@eps1lon
Copy link
Member Author

eps1lon commented Sep 3, 2019

The solution was designed to accept @material-ui/icons/Home as input.

Could you add the code that was using the component prop so that I can better understand the requirements?

@oliviertassinari
Copy link
Member

oliviertassinari commented Sep 3, 2019

I don't understand your question.

To be more clear. What happens if we keep the same customization demo but we replace the custom home icon by the ready made one from @material-ui/icons?

@eps1lon
Copy link
Member Author

eps1lon commented Sep 3, 2019

Most people are using the pre-maid SVG icons. The solution was designed to accept @material-ui/icons/Home as input.

Could you add the code that uses this customization option? It's not clear to me why we need a component prop for that.

The documented customization can be solved with less and clearer code.

@oliviertassinari
Copy link
Member

This one

import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import { blue, red } from '@material-ui/core/colors';
import SvgIcon from '@material-ui/core/SvgIcon';
import HomeIcon from '@material-ui/icons/Home';

const useStyles = makeStyles(theme => ({
  root: {
    '& > svg': {
      margin: theme.spacing(2),
    },
  },
  iconHover: {
    '&:hover': {
      color: red[800],
    },
  },
}));

/*
function HomeIcon(props) {
  return (
    <SvgIcon {...props}>
      <path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z" />
    </SvgIcon>
  );
}
*/

export default function SvgIcons() {
  const classes = useStyles();

  return (
    <div className={classes.root}>
      <HomeIcon />
      <HomeIcon color="primary" />
      <HomeIcon color="secondary" />
      <HomeIcon color="action" />
      <HomeIcon className={classes.iconHover} color="error" style={{ fontSize: 30 }} />
      <HomeIcon color="disabled" fontSize="large" />
      <HomeIcon
        color="primary"
        fontSize="large"
        component={svgProps => {
          return (
            <svg {...svgProps}>
              <defs>
                <linearGradient id="gradient1">
                  <stop offset="30%" stopColor={blue[400]} />
                  <stop offset="70%" stopColor={red[400]} />
                </linearGradient>
              </defs>
              {React.cloneElement(svgProps.children[0], {
                fill: 'url(#gradient1)',
              })}
            </svg>
          );
        }}
      />
    </div>
  );
}

@eps1lon
Copy link
Member Author

eps1lon commented Sep 3, 2019

Thats changed in this PR.

@oliviertassinari
Copy link
Member

oliviertassinari commented Sep 3, 2019

The SVG path has to be copy and pasted in the developer codebase. We are giving up on supporting the icons package.

To be honest, it sounds OK to remove the prop, but maybe some of our users have found a legitimate use case.

I really think that we should start with a deprecation, something we can merge in a few months, then continue with removal if nobody complains. What do you think?

@oliviertassinari
Copy link
Member

I think that we should keep this prop. I have removed the gradient demo from the documentation, as likely covering a too narrow use case. The import svg files use case is interesting.

@eps1lon
Copy link
Member Author

eps1lon commented Nov 29, 2019

I think that we should keep this prop.

Why? Especially with the more complicated customization example removed there isn't even a documented use case anymore

@oliviertassinari
Copy link
Member

oliviertassinari commented Nov 29, 2019

I think that it's important so people can:

  1. benefit from the SvgIcon wrapper with a custom SVG (e.g. svgr use case)
  2. so they can change the svg structure (e.g. add a gradient)

@eps1lon eps1lon deleted the feat/SvgIcon/simplify-impl branch September 14, 2021 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Introduces changes that are not backward compatible. component: SvgIcon The React component.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants