-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apps: align LocalIdentityBadge implementations
- Loading branch information
Showing
6 changed files
with
89 additions
and
43 deletions.
There are no files selected for viewing
47 changes: 11 additions & 36 deletions
47
apps/agent/app/src/components/LocalIdentityBadge/LocalIdentityBadge.js
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,60 +1,35 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import styled from 'styled-components' | ||
import { useNetwork } from '@aragon/api-react' | ||
import { Badge, IdentityBadge, font } from '@aragon/ui' | ||
import { IdentityBadge } from '@aragon/ui' | ||
import { useIdentity } from '../IdentityManager/IdentityManager' | ||
import LocalLabelPopoverTitle from './LocalLabelPopoverTitle' | ||
import LocalLabelPopoverActionLabel from './LocalLabelPopoverActionLabel' | ||
|
||
const LocalIdentityBadge = ({ entity, ...props }) => { | ||
const LocalIdentityBadge = ({ defaultLabel, entity, ...props }) => { | ||
const network = useNetwork() | ||
const [label, showLocalIdentityModal] = useIdentity(entity) | ||
const handleClick = () => showLocalIdentityModal(entity) | ||
return ( | ||
<IdentityBadge | ||
{...props} | ||
networkType={network && network.type} | ||
customLabel={label || ''} | ||
label={label || defaultLabel} | ||
entity={entity} | ||
networkType={network && network.type} | ||
popoverAction={{ | ||
label: `${label ? 'Edit' : 'Add'} custom label`, | ||
label: <LocalLabelPopoverActionLabel hasLabel={Boolean(label)} />, | ||
onClick: handleClick, | ||
}} | ||
popoverTitle={ | ||
label ? ( | ||
<Wrap> | ||
<Label>{label}</Label> | ||
<StyledBadge>Custom label</StyledBadge> | ||
</Wrap> | ||
) : ( | ||
'Address' | ||
) | ||
label ? <LocalLabelPopoverTitle label={label} /> : undefined | ||
} | ||
{...props} | ||
/> | ||
) | ||
} | ||
|
||
LocalIdentityBadge.propTypes = { | ||
entity: PropTypes.string.isRequired, | ||
defaultLabel: PropTypes.string, | ||
...IdentityBadge.propTypes, | ||
} | ||
|
||
const Wrap = styled.div` | ||
display: grid; | ||
align-items: center; | ||
grid-template-columns: auto 1fr; | ||
padding-right: 24px; | ||
` | ||
|
||
const Label = styled.span` | ||
display: inline-block; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
white-space: nowrap; | ||
` | ||
|
||
const StyledBadge = styled(Badge)` | ||
margin-left: 16px; | ||
text-transform: uppercase; | ||
${font({ size: 'xxsmall' })}; | ||
` | ||
|
||
export default LocalIdentityBadge |
26 changes: 26 additions & 0 deletions
26
apps/agent/app/src/components/LocalIdentityBadge/LocalLabelPopoverActionLabel.js
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 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { IconLabel, GU } from '@aragon/ui' | ||
|
||
function LocalLabelPopoverActionLabel({ hasLabel }) { | ||
return ( | ||
<div | ||
css={` | ||
display: flex; | ||
align-items: center; | ||
`} | ||
> | ||
<IconLabel | ||
css={` | ||
margin-right: ${1 * GU}px; | ||
`} | ||
/> | ||
{hasLabel ? 'Edit' : 'Add'} custom label | ||
</div> | ||
) | ||
} | ||
LocalLabelPopoverActionLabel.propTypes = { | ||
hasLabel: PropTypes.bool, | ||
} | ||
|
||
export default LocalLabelPopoverActionLabel |
39 changes: 39 additions & 0 deletions
39
apps/agent/app/src/components/LocalIdentityBadge/LocalLabelPopoverTitle.js
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,39 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { Tag, GU } from '@aragon/ui' | ||
|
||
function LocalLabelPopoverTitle({ label }) { | ||
return ( | ||
<div | ||
css={` | ||
display: grid; | ||
align-items: center; | ||
grid-template-columns: auto 1fr; | ||
`} | ||
> | ||
<span | ||
css={` | ||
display: inline-block; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
white-space: nowrap; | ||
`} | ||
> | ||
{label} | ||
</span> | ||
<Tag | ||
mode="identifier" | ||
css={` | ||
margin-left: ${2 * GU}px; | ||
`} | ||
> | ||
Custom label | ||
</Tag> | ||
</div> | ||
) | ||
} | ||
LocalLabelPopoverTitle.propTypes = { | ||
label: PropTypes.string.isRequired, | ||
} | ||
|
||
export default LocalLabelPopoverTitle |
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