Fix site icon size (#8814)

A new `SiteIcon` component has been created for showing icons
representing web3 sites. The icon has a border and background, and it
has a fallback in case no icon is given. This new component accepts a
`size` prop that controls the size of the icon.

The old `IconWithFallback` component had a hard-coded size in the
SCSS styles for the icon, which was being overridden in a few places.
It was difficult to customize, and overly complicated.

The old `IconWithFallback` component is still used, but it's now
simpler. It only handles rendering the underlying `img` for the icon,
or the fallback letter if no image is given.

A separate `IconBorder` component has been created for the border and
white background used. It's solely used by `SiteIcon` for now, but I
intend to use it elsewhere as well, where this same pattern of a white
background is embedded.
feature/default_network_editable
Mark Stacey 5 years ago committed by GitHub
parent a332c3edc1
commit ad5e16cfa7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      ui/app/components/app/account-menu/account-menu.component.js
  2. 4
      ui/app/components/app/connected-sites-list/connected-sites-list.component.js
  3. 6
      ui/app/components/app/index.scss
  4. 4
      ui/app/components/app/permissions-connect-header/permissions-connect-header.component.js
  5. 16
      ui/app/components/ui/icon-border/icon-border.js
  6. 10
      ui/app/components/ui/icon-border/icon-border.scss
  7. 1
      ui/app/components/ui/icon-border/index.js
  8. 18
      ui/app/components/ui/icon-with-fallback/icon-with-fallback.component.js
  9. 5
      ui/app/components/ui/icon-with-fallback/icon-with-fallback.scss
  10. 30
      ui/app/components/ui/icon-with-fallback/index.scss
  11. 1
      ui/app/components/ui/site-icon/index.js
  12. 24
      ui/app/components/ui/site-icon/site-icon.js
  13. 46
      ui/app/pages/permissions-connect/redirect/index.scss
  14. 10
      ui/app/pages/permissions-connect/redirect/permissions-redirect.component.js

@ -8,7 +8,7 @@ import { Menu, Item, Divider, CloseArea } from '../dropdowns/components/menu'
import { ENVIRONMENT_TYPE_POPUP } from '../../../../../app/scripts/lib/enums' import { ENVIRONMENT_TYPE_POPUP } from '../../../../../app/scripts/lib/enums'
import { getEnvironmentType } from '../../../../../app/scripts/lib/util' import { getEnvironmentType } from '../../../../../app/scripts/lib/util'
import Identicon from '../../ui/identicon' import Identicon from '../../ui/identicon'
import IconWithFallBack from '../../ui/icon-with-fallback' import SiteIcon from '../../ui/site-icon'
import UserPreferencedCurrencyDisplay from '../user-preferenced-currency-display' import UserPreferencedCurrencyDisplay from '../user-preferenced-currency-display'
import { PRIMARY } from '../../../helpers/constants/common' import { PRIMARY } from '../../../helpers/constants/common'
import { import {
@ -178,7 +178,7 @@ export default class AccountMenu extends Component {
{ iconAndNameForOpenDomain { iconAndNameForOpenDomain
? ( ? (
<div className="account-menu__icon-list"> <div className="account-menu__icon-list">
<IconWithFallBack icon={iconAndNameForOpenDomain.icon} name={iconAndNameForOpenDomain.name} /> <SiteIcon icon={iconAndNameForOpenDomain.icon} name={iconAndNameForOpenDomain.name} size={32} />
</div> </div>
) )
: null : null

@ -1,6 +1,6 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import IconWithFallBack from '../../ui/icon-with-fallback' import SiteIcon from '../../ui/site-icon'
import { stripHttpSchemes } from '../../../helpers/utils/util' import { stripHttpSchemes } from '../../../helpers/utils/util'
export default class ConnectedSitesList extends Component { export default class ConnectedSitesList extends Component {
@ -28,7 +28,7 @@ export default class ConnectedSitesList extends Component {
{ connectedDomains.map((domain) => ( { connectedDomains.map((domain) => (
<div key={domain.origin} className="connected-sites-list__content-row"> <div key={domain.origin} className="connected-sites-list__content-row">
<div className="connected-sites-list__domain-info"> <div className="connected-sites-list__domain-info">
<IconWithFallBack icon={domain.icon} name={domain.name} /> <SiteIcon icon={domain.icon} name={domain.name} size={32} />
<span className="connected-sites-list__domain-name" title={domain.extensionId || domain.origin}> <span className="connected-sites-list__domain-name" title={domain.extensionId || domain.origin}>
{this.getDomainDisplayName(domain)} {this.getDomainDisplayName(domain)}
</span> </span>

@ -90,10 +90,10 @@
@import 'connected-accounts-permissions/index'; @import 'connected-accounts-permissions/index';
@import '../ui/icon-with-fallback/index';
@import '../ui/icon/index'; @import '../ui/icon/index';
@import '../ui/icon-with-fallback/icon-with-fallback';
@import '../ui/icon-with-label/index'; @import '../ui/icon-with-label/index';
@import '../ui/circle-icon/index'; @import '../ui/circle-icon/index';
@ -113,3 +113,5 @@
@import 'wallet-overview/index'; @import 'wallet-overview/index';
@import '../ui/account-mismatch-warning/index'; @import '../ui/account-mismatch-warning/index';
@import '../ui/icon-border/icon-border';

@ -1,6 +1,6 @@
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import React, { Component } from 'react' import React, { Component } from 'react'
import IconWithFallBack from '../../ui/icon-with-fallback' import SiteIcon from '../../ui/site-icon'
export default class PermissionsConnectHeader extends Component { export default class PermissionsConnectHeader extends Component {
static propTypes = { static propTypes = {
@ -22,7 +22,7 @@ export default class PermissionsConnectHeader extends Component {
return ( return (
<div className="permissions-connect-header__icon"> <div className="permissions-connect-header__icon">
<IconWithFallBack icon={ icon } name={ iconName } /> <SiteIcon icon={ icon } name={ iconName } size={64} />
<div className="permissions-connect-header__text">{iconName}</div> <div className="permissions-connect-header__text">{iconName}</div>
</div> </div>
) )

@ -0,0 +1,16 @@
import React from 'react'
import PropTypes from 'prop-types'
export default function IconBorder ({ children, size }) {
const borderStyle = { height: `${size}px`, width: `${size}px` }
return (
<div className="icon-border" style={borderStyle}>
{ children }
</div>
)
}
IconBorder.propTypes = {
children: PropTypes.node.isRequired,
size: PropTypes.number.isRequired,
}

@ -0,0 +1,10 @@
.icon-border {
border-radius: 50%;
border: 1px solid #F2F3F4;
background: #FFFFFF;
display: flex;
justify-content: center;
align-items: center;
}

@ -0,0 +1 @@
export { default } from './icon-border'

@ -5,6 +5,7 @@ export default class IconWithFallback extends PureComponent {
static propTypes = { static propTypes = {
icon: PropTypes.string, icon: PropTypes.string,
name: PropTypes.string, name: PropTypes.string,
size: PropTypes.number.isRequired,
} }
static defaultProps = { static defaultProps = {
@ -17,26 +18,21 @@ export default class IconWithFallback extends PureComponent {
} }
render () { render () {
const { icon, name } = this.props const { icon, name, size } = this.props
const style = { height: `${size}px`, width: `${size}px` }
return ( return !this.state.iconError && icon
<div className="icon-with-fallback__identicon-container">
<div className="icon-with-fallback__identicon-border" />
{ !this.state.iconError && icon
? ( ? (
<img <img
className="icon-with-fallback__identicon"
src={icon}
onError={() => this.setState({ iconError: true })} onError={() => this.setState({ iconError: true })}
src={icon}
style={style}
/> />
) )
: ( : (
<i className="icon-with-fallback__identicon--default"> <i className="icon-with-fallback__fallback">
{ name.length ? name.charAt(0).toUpperCase() : '' } { name.length ? name.charAt(0).toUpperCase() : '' }
</i> </i>
) )
} }
</div>
)
}
} }

@ -0,0 +1,5 @@
.icon-with-fallback {
&__fallback {
color: black;
}
}

@ -1,30 +0,0 @@
.icon-with-fallback {
&__identicon-container {
position: relative;
display: flex;
justify-content: center;
align-items: center;
height: 32px;
width: 32px;
}
&__identicon-border {
height: 32px;
width: 32px;
border-radius: 50%;
border: 1px solid #F2F3F4;
position: absolute;
background: #FFFFFF;
}
&__identicon {
position: relative;
width: 24px;
height: 24px;
&--default {
position: relative;
color: black;
}
}
}

@ -0,0 +1 @@
export { default } from './site-icon'

@ -0,0 +1,24 @@
import React from 'react'
import PropTypes from 'prop-types'
import IconBorder from '../icon-border'
import IconWithFallback from '../icon-with-fallback'
export default function SiteIcon ({ icon, name, size }) {
const iconSize = Math.floor(size * 0.75)
return (
<IconBorder size={size}>
<IconWithFallback icon={icon} name={name} size={iconSize} />
</IconBorder>
)
}
SiteIcon.propTypes = {
icon: PropTypes.string,
name: PropTypes.string,
size: PropTypes.number.isRequired,
}
SiteIcon.defaultProps = {
icon: undefined,
name: undefined,
}

@ -33,50 +33,4 @@
background: white url("/images/permissions-check.svg") no-repeat; background: white url("/images/permissions-check.svg") no-repeat;
position: absolute; position: absolute;
} }
&__identicon, .icon-with-fallback__identicon {
width: 32px;
height: 32px;
&--default {
background-color: #777A87;
color: white;
width: 64px;
height: 64px;
border-radius: 32px;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
}
}
&__identicon-container, .icon-with-fallback__identicon-container {
height: auto;
position: relative;
display: flex;
justify-content: center;
align-items: center;
height: 64px;
width: 64px;
}
&__identicon-border, .icon-with-fallback__identicon-border {
height: 64px;
width: 64px;
border-radius: 50%;
border: 1px solid white;
background: #FFFFFF;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.25);
}
&__identicon-border {
display: flex;
justify-content: center;
align-items: center;
}
.icon-with-fallback__identicon-border {
position: absolute;
}
} }

@ -1,6 +1,6 @@
import React, { useContext } from 'react' import React, { useContext } from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import IconWithFallBack from '../../../components/ui/icon-with-fallback' import SiteIcon from '../../../components/ui/site-icon'
import { I18nContext } from '../../../contexts/i18n' import { I18nContext } from '../../../contexts/i18n'
export default function PermissionsRedirect ({ domainMetadata }) { export default function PermissionsRedirect ({ domainMetadata }) {
@ -12,16 +12,12 @@ export default function PermissionsRedirect ({ domainMetadata }) {
<div className="permissions-redirect__result"> <div className="permissions-redirect__result">
{ t('connecting') } { t('connecting') }
<div className="permissions-redirect__icons"> <div className="permissions-redirect__icons">
<IconWithFallBack icon={domainMetadata.icon} name={domainMetadata.name} /> <SiteIcon icon={domainMetadata.icon} name={domainMetadata.name} size={64} />
<div className="permissions-redirect__center-icon"> <div className="permissions-redirect__center-icon">
<span className="permissions-redirect__check" /> <span className="permissions-redirect__check" />
{ renderBrokenLine() } { renderBrokenLine() }
</div> </div>
<div className="permissions-redirect__identicon-container"> <SiteIcon icon="/images/logo/metamask-fox.svg" size={64} />
<div className="permissions-redirect__identicon-border">
<img src="/images/logo/metamask-fox.svg" />
</div>
</div>
</div> </div>
</div> </div>
</div> </div>

Loading…
Cancel
Save