AddressMini.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. // Copyright 2017-2020 @polkadot/app-staking authors & contributors
  2. // This software may be modified and distributed under the terms
  3. // of the Apache-2.0 license. See the LICENSE file for details.
  4. import { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces';
  5. import BN from 'bn.js';
  6. import React from 'react';
  7. import styled from 'styled-components';
  8. import { KeyringItemType } from '@polkadot/ui-keyring/types';
  9. import { classes, toShortAddress } from './util';
  10. import AccountName from './AccountName';
  11. import BalanceDisplay from './Balance';
  12. import BondedDisplay from './Bonded';
  13. import IdentityIcon from './IdentityIcon';
  14. import LockedVote from './LockedVote';
  15. interface Props {
  16. balance?: BN | BN[];
  17. bonded?: BN | BN[];
  18. children?: React.ReactNode;
  19. className?: string;
  20. iconInfo?: React.ReactNode;
  21. isHighlight?: boolean;
  22. isPadded?: boolean;
  23. isShort?: boolean;
  24. label?: React.ReactNode;
  25. labelBalance?: React.ReactNode;
  26. noLookup?: boolean;
  27. summary?: React.ReactNode;
  28. type?: KeyringItemType;
  29. value?: AccountId | AccountIndex | Address | string | null | Uint8Array;
  30. withAddress?: boolean;
  31. withBalance?: boolean;
  32. withBonded?: boolean;
  33. withLockedVote?: boolean;
  34. withSidebar?: boolean;
  35. withName?: boolean;
  36. withShrink?: boolean;
  37. }
  38. function AddressMini ({ balance, bonded, children, className = '', iconInfo, isHighlight, isPadded = true, label, labelBalance, noLookup, summary, value, withAddress = true, withBalance = false, withBonded = false, withLockedVote = false, withName = true, withShrink = false, withSidebar = true }: Props): React.ReactElement<Props> | null {
  39. if (!value) {
  40. return null;
  41. }
  42. return (
  43. <div className={classes('ui--AddressMini', isHighlight ? 'isHighlight' : '', isPadded ? 'padded' : '', withShrink ? 'withShrink' : '', className)}>
  44. {label && (
  45. <label className='ui--AddressMini-label'>{label}</label>
  46. )}
  47. <div className='ui--AddressMini-icon'>
  48. <IdentityIcon value={value as Uint8Array} />
  49. {iconInfo && (
  50. <div className='ui--AddressMini-icon-info'>
  51. {iconInfo}
  52. </div>
  53. )}
  54. </div>
  55. <div className='ui--AddressMini-info'>
  56. {withAddress && (
  57. <div className='ui--AddressMini-address'>
  58. {withName
  59. ? (
  60. <AccountName
  61. noLookup={noLookup}
  62. value={value}
  63. withSidebar={withSidebar}
  64. />
  65. )
  66. : toShortAddress(value)
  67. }
  68. </div>
  69. )}
  70. {children}
  71. </div>
  72. <div className='ui--AddressMini-balances'>
  73. {withBalance && (
  74. <BalanceDisplay
  75. balance={balance}
  76. label={labelBalance}
  77. params={value}
  78. />
  79. )}
  80. {withBonded && (
  81. <BondedDisplay
  82. bonded={bonded}
  83. label=''
  84. params={value}
  85. />
  86. )}
  87. {withLockedVote && (
  88. <LockedVote params={value} />
  89. )}
  90. {summary && (
  91. <div className='ui--AddressMini-summary'>{summary}</div>
  92. )}
  93. </div>
  94. </div>
  95. );
  96. }
  97. export default React.memo(styled(AddressMini)`
  98. display: inline-block;
  99. padding: 0 0.25rem 0 1rem;
  100. text-align: left;
  101. white-space: nowrap;
  102. &.padded {
  103. display: inline-block;
  104. padding: 0 1rem 0 0;
  105. }
  106. &.summary {
  107. position: relative;
  108. top: -0.2rem;
  109. }
  110. .ui--AddressMini-info {
  111. max-width: 12rem;
  112. min-width: 12rem;
  113. @media only screen and (max-width: 1800px) {
  114. max-width: 11.5rem;
  115. min-width: 11.5rem;
  116. }
  117. @media only screen and (max-width: 1700px) {
  118. max-width: 11rem;
  119. min-width: 11rem;
  120. }
  121. @media only screen and (max-width: 1600px) {
  122. max-width: 10.5rem;
  123. min-width: 10.5rem;
  124. }
  125. @media only screen and (max-width: 1500px) {
  126. max-width: 10rem;
  127. min-width: 10rem;
  128. }
  129. @media only screen and (max-width: 1400px) {
  130. max-width: 9.5rem;
  131. min-width: 9.5rem;
  132. }
  133. @media only screen and (max-width: 1300px) {
  134. max-width: 9rem;
  135. min-width: 9rem;
  136. }
  137. }
  138. .ui--AddressMini-address {
  139. overflow: hidden;
  140. text-align: left;
  141. text-overflow: ellipsis;
  142. width: fit-content;
  143. max-width: inherit;
  144. > div {
  145. overflow: hidden;
  146. text-overflow: ellipsis;
  147. }
  148. }
  149. &.withShrink {
  150. .ui--AddressMini-address {
  151. min-width: 3rem;
  152. }
  153. }
  154. .ui--AddressMini-label {
  155. margin: 0 0 -0.5rem 2.25rem;
  156. }
  157. .ui--AddressMini-balances {
  158. display: grid;
  159. .ui--Balance,
  160. .ui--Bonded,
  161. .ui--LockedVote {
  162. font-size: 0.75rem;
  163. margin-left: 2.25rem;
  164. margin-top: -0.5rem;
  165. text-align: left;
  166. }
  167. }
  168. .ui--AddressMini-icon {
  169. margin: 0 0.5rem 0 0;
  170. .ui--AddressMini-icon-info {
  171. position: absolute;
  172. right: -0.5rem;
  173. top: -0.5rem;
  174. z-index: 1;
  175. }
  176. .ui--IdentityIcon {
  177. margin: 0;
  178. vertical-align: middle;
  179. }
  180. }
  181. .ui--AddressMini-icon,
  182. .ui--AddressMini-info {
  183. display: inline-block;
  184. position: relative;
  185. vertical-align: middle;
  186. }
  187. .ui--AddressMini-summary {
  188. font-size: 0.75rem;
  189. line-height: 1.2;
  190. margin-left: 2.25rem;
  191. margin-top: -0.2rem;
  192. text-align: left;
  193. }
  194. `);