Skip to content

Commit

Permalink
feat: Allow rounded blockie (#553)
Browse files Browse the repository at this point in the history
* feat: Allow rounded blockie

* fix: Remove important
  • Loading branch information
LautaroPetaccio authored Aug 6, 2024
1 parent 4f36cb1 commit bad4bfb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/components/Blockie/Blockie.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
margin-left: 0.1em;
}

.dcl.blockie.circle {
border-radius: 50%;
}

.dcl.blockie.small {
border-radius: 4px;
}
Expand Down
1 change: 1 addition & 0 deletions src/components/Blockie/Blockie.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ storiesOf('Blockie', module)
<Blockie seed={address} scale={21} />
</>
))
.add('Circular shape', () => <Blockie seed={address} shape="circle" />)
.add('In a paragraph', () => (
<p>
You've transfered <Mana inline>1,000</Mana> to{' '}
Expand Down
24 changes: 18 additions & 6 deletions src/components/Blockie/Blockie.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react'
import * as blockies from 'ethereum-blockies/blockies'
import './Blockie.css'
import classNames from 'classnames'

export type BlockieProps = {
seed: string
Expand All @@ -9,6 +10,7 @@ export type BlockieProps = {
bgcolor?: string
size?: number
scale?: number
shape?: 'circle' | 'square'
className?: string
children?: React.ReactNode
}
Expand Down Expand Up @@ -63,18 +65,28 @@ export class Blockie extends React.PureComponent<BlockieProps> {
}

render(): JSX.Element {
const { size, scale, children, className } = this.props
const { size, scale, shape, children, className } = this.props

let classes = `dcl blockie ${className}`.trim()
let scaleClass = ''
if (scale * size <= 16) {
classes += ' mini'
scaleClass += ' mini'
} else if (scale * size <= 24) {
classes += ' tiny'
scaleClass += ' tiny'
} else if (scale * size <= 36) {
classes += ' small'
scaleClass += ' small'
}

const canvas = <canvas className={classes} ref={this.canvas} />
const canvas = (
<canvas
className={classNames(
'dcl blockie',
className,
shape === 'circle' && 'circle',
shape !== 'circle' && scaleClass
)}
ref={this.canvas}
/>
)

if (children) {
return (
Expand Down

0 comments on commit bad4bfb

Please sign in to comment.