-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #401 from lidofinance/feature/ui-833-migrate-addre…
…ssbadge Migrated to css modules addressbadge & identicon
- Loading branch information
Showing
16 changed files
with
172 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,40 @@ | ||
import React, { ForwardedRef, forwardRef } from 'react' | ||
import { ForwardedRef, forwardRef } from 'react' | ||
import { useBreakpoint } from '../hooks' | ||
import { AddressBadgeStyle } from './AddressBadgeStyles' | ||
import { AddressBadgeProps } from './types' | ||
import cn from 'classnames' | ||
import styles from './AddressBadge.module.css' | ||
import { IdenticonBadge, IdenticonBadgeProps } from '../identicon' | ||
|
||
function AddressBadge( | ||
props: AddressBadgeProps, | ||
ref?: ForwardedRef<HTMLDivElement>, | ||
) { | ||
const { address, symbolsMobile = 3, symbolsDesktop = 6 } = props | ||
const isMobile = useBreakpoint('md') | ||
|
||
return ( | ||
<AddressBadgeStyle | ||
symbols={isMobile ? symbolsMobile : symbolsDesktop} | ||
address={address ?? ''} | ||
ref={ref} | ||
/> | ||
) | ||
export type AddressBadgeProps = Omit< | ||
IdenticonBadgeProps, | ||
'address' | 'symbols' | ||
> & { | ||
address?: string | ||
symbolsMobile?: number | ||
symbolsDesktop?: number | ||
} | ||
|
||
export default forwardRef(AddressBadge) | ||
export const AddressBadge = forwardRef( | ||
( | ||
{ | ||
address, | ||
symbolsMobile = 3, | ||
symbolsDesktop = 6, | ||
className, | ||
...rest | ||
}: AddressBadgeProps, | ||
ref?: ForwardedRef<HTMLDivElement>, | ||
) => { | ||
const isMobile = useBreakpoint('md') | ||
|
||
return ( | ||
<IdenticonBadge | ||
symbols={isMobile ? symbolsMobile : symbolsDesktop} | ||
address={address ?? ''} | ||
className={cn(styles.addressBadge, className)} | ||
{...rest} | ||
ref={ref} | ||
/> | ||
) | ||
}, | ||
) | ||
AddressBadge.displayName = 'AddressBadge' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
export { default as AddressBadge } from './AddressBadge' | ||
export * from './types' | ||
export * from './AddressBadge' |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* export const IdenticonStyle = styled.div` */ | ||
.identicon { | ||
border-radius: 1000px; | ||
overflow: hidden; | ||
line-height: 0; | ||
display: inline-block; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,38 @@ | ||
import React, { ForwardedRef, forwardRef } from 'react' | ||
import { IdenticonProps } from './types' | ||
import { IdenticonStyle } from './IdenticonStyles' | ||
import { ForwardedRef, forwardRef } from 'react' | ||
import Jazzicon, { jsNumberForAddress } from 'react-jazzicon' | ||
import cn from 'classnames' | ||
import styles from './Identicon.module.css' | ||
import { NewLidoComponentProps } from '../utils' | ||
|
||
function Identicon(props: IdenticonProps, ref?: ForwardedRef<HTMLDivElement>) { | ||
const { diameter = 24, address, paperStyles, svgStyles, ...rest } = props | ||
const iconProps = { diameter, paperStyles, svgStyles } | ||
export type IdenticonProps = NewLidoComponentProps< | ||
'div', | ||
{ | ||
address: string | ||
diameter?: number | ||
paperStyles?: React.CSSProperties | ||
svgStyles?: React.CSSProperties | ||
} | ||
> | ||
|
||
return ( | ||
<IdenticonStyle {...rest} ref={ref}> | ||
<Jazzicon seed={jsNumberForAddress(address)} {...iconProps} /> | ||
</IdenticonStyle> | ||
) | ||
} | ||
export const Identicon = forwardRef( | ||
( | ||
{ | ||
diameter = 24, | ||
address, | ||
paperStyles, | ||
svgStyles, | ||
className, | ||
...rest | ||
}: IdenticonProps, | ||
ref?: ForwardedRef<HTMLDivElement>, | ||
) => { | ||
const iconProps = { diameter, paperStyles, svgStyles } | ||
|
||
export default forwardRef(Identicon) | ||
return ( | ||
<div className={cn(styles.identicon, className)} {...rest} ref={ref}> | ||
<Jazzicon seed={jsNumberForAddress(address)} {...iconProps} /> | ||
</div> | ||
) | ||
}, | ||
) | ||
Identicon.displayName = 'Identicon' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* export const IdenticonBadgeStyle = styled.div<{ $color: IdenticonBadgeColors }>` | ||
${({ $color }) => colors[$color]} | ||
` */ | ||
|
||
.identiconBadge { | ||
border-radius: 1000px; | ||
padding: 4px; | ||
margin: 0 6px; | ||
display: inline-flex; | ||
align-items: center; | ||
} | ||
|
||
.background { | ||
background: var(--lido-color-background); | ||
color: var(--lido-color-textSecondary); | ||
} | ||
|
||
.accent { | ||
background: var(--lido-color-accentDarken); | ||
color: var(--lido-color-accentContrast); | ||
} | ||
|
||
.wrapper { | ||
padding: 0 6px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,55 @@ | ||
import React, { ForwardedRef, forwardRef } from 'react' | ||
import { ForwardedRef, forwardRef } from 'react' | ||
import { Address } from '../address' | ||
import { IdenticonBadgeProps } from './types' | ||
import { IdenticonBadgeStyle, AddressWrapperStyle } from './IdenticonStyles' | ||
import Identicon from './Identicon' | ||
import { Identicon, IdenticonProps } from './Identicon' | ||
import cn from 'classnames' | ||
import styles from './IdenticonBadge.module.css' | ||
|
||
function IdenticonBadge( | ||
props: IdenticonBadgeProps, | ||
ref?: ForwardedRef<HTMLDivElement>, | ||
) { | ||
const { | ||
symbols = 3, | ||
color = 'background', | ||
diameter, | ||
address, | ||
paperStyles, | ||
svgStyles, | ||
...rest | ||
} = props | ||
const identiconProps = { address, diameter, paperStyles, svgStyles } | ||
export enum IdenticonBadgeColor { | ||
background, | ||
accent, | ||
} | ||
export type IdenticonBadgeColors = keyof typeof IdenticonBadgeColor | ||
|
||
return ( | ||
<IdenticonBadgeStyle $color={color} {...rest} ref={ref}> | ||
{symbols > 0 ? ( | ||
<AddressWrapperStyle> | ||
<Address address={address} symbols={symbols} /> | ||
</AddressWrapperStyle> | ||
) : ( | ||
'' | ||
)} | ||
<Identicon {...identiconProps} /> | ||
</IdenticonBadgeStyle> | ||
) | ||
export type IdenticonBadgeProps = IdenticonProps & { | ||
symbols?: number | ||
color?: IdenticonBadgeColors | ||
} | ||
|
||
export default forwardRef(IdenticonBadge) | ||
export const IdenticonBadge = forwardRef( | ||
( | ||
{ | ||
symbols = 3, | ||
color = 'background', | ||
diameter, | ||
address, | ||
paperStyles, | ||
svgStyles, | ||
className, | ||
...rest | ||
}: IdenticonBadgeProps, | ||
ref?: ForwardedRef<HTMLDivElement>, | ||
) => { | ||
const identiconProps = { address, diameter, paperStyles, svgStyles } | ||
|
||
return ( | ||
<div | ||
className={cn(styles.identiconBadge, className, { | ||
[styles.background]: color === 'background', | ||
[styles.accent]: color === 'accent', | ||
})} | ||
{...rest} | ||
ref={ref} | ||
> | ||
{symbols > 0 ? ( | ||
<div className={styles.wrapper}> | ||
<Address address={address} symbols={symbols} /> | ||
</div> | ||
) : ( | ||
'' | ||
)} | ||
<Identicon {...identiconProps} /> | ||
</div> | ||
) | ||
}, | ||
) | ||
IdenticonBadge.displayName = 'IdenticonBadge' |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
export { default as IdenticonBadge } from './IdenticonBadge' | ||
export { default as Identicon } from './Identicon' | ||
export * from './types' | ||
export * from './IdenticonBadge' | ||
export * from './Identicon' |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.