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
parent
a332c3edc1
commit
ad5e16cfa7
@ -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' |
@ -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, |
||||||
|
} |
Loading…
Reference in new issue