@pezkuwi/react-identicon 3.16.8 → 3.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/build/Identicon.js +104 -0
  2. package/build/README.md +34 -0
  3. package/{bundle-pezkuwi-react-identicon.js → build/bundle-pezkuwi-react-identicon.js} +62 -50
  4. package/build/bundle.js +3 -0
  5. package/build/cjs/Identicon.d.ts +5 -0
  6. package/build/cjs/Identicon.js +108 -0
  7. package/build/cjs/bundle.d.ts +3 -0
  8. package/build/cjs/bundle.js +9 -0
  9. package/build/cjs/icons/Beachball.js +17 -0
  10. package/build/cjs/icons/Empty.js +10 -0
  11. package/build/cjs/icons/Ethereum.js +18 -0
  12. package/build/cjs/icons/Jdenticon.js +12 -0
  13. package/{icons/Polkadot.d.ts → build/cjs/icons/Pezkuwi.d.ts} +1 -1
  14. package/build/cjs/icons/Pezkuwi.js +15 -0
  15. package/{icons → build/cjs/icons}/index.d.ts +1 -1
  16. package/build/cjs/icons/index.js +13 -0
  17. package/build/cjs/index.js +7 -0
  18. package/build/cjs/packageInfo.js +4 -0
  19. package/build/cjs/styled.js +5 -0
  20. package/{types.d.ts → build/cjs/types.d.ts} +1 -1
  21. package/build/cjs/types.js +2 -0
  22. package/build/icons/Beachball.d.ts +5 -0
  23. package/build/icons/Beachball.js +13 -0
  24. package/build/icons/Empty.d.ts +5 -0
  25. package/build/icons/Empty.js +6 -0
  26. package/build/icons/Ethereum.d.ts +5 -0
  27. package/build/icons/Ethereum.js +14 -0
  28. package/build/icons/Jdenticon.d.ts +5 -0
  29. package/build/icons/Jdenticon.js +8 -0
  30. package/build/icons/Pezkuwi.d.ts +5 -0
  31. package/build/icons/Pezkuwi.js +11 -0
  32. package/build/icons/index.d.ts +5 -0
  33. package/build/icons/index.js +5 -0
  34. package/build/index.d.ts +4 -0
  35. package/build/index.js +4 -0
  36. package/build/package.json +249 -0
  37. package/build/packageDetect.d.ts +1 -0
  38. package/build/packageDetect.js +5 -0
  39. package/build/packageInfo.d.ts +6 -0
  40. package/build/packageInfo.js +1 -0
  41. package/build/styled.d.ts +1 -0
  42. package/build/styled.js +1 -0
  43. package/build/types.d.ts +23 -0
  44. package/build/types.js +1 -0
  45. package/{cjs/icons/Polkadot.d.ts → build-tsc/icons/Pezkuwi.d.ts} +1 -1
  46. package/{cjs → build-tsc}/icons/index.d.ts +1 -1
  47. package/{cjs → build-tsc}/types.d.ts +1 -1
  48. package/{cjs → build-tsc-cjs}/Identicon.js +2 -2
  49. package/{cjs/icons/Polkadot.js → build-tsc-cjs/icons/Pezkuwi.js} +3 -3
  50. package/{cjs → build-tsc-cjs}/icons/index.js +3 -3
  51. package/build-tsc-cjs/packageDetect.js +7 -0
  52. package/{cjs → build-tsc-cjs}/packageInfo.js +1 -1
  53. package/{Identicon.js → build-tsc-esm/Identicon.js} +3 -3
  54. package/{icons/Polkadot.js → build-tsc-esm/icons/Pezkuwi.js} +3 -3
  55. package/{icons → build-tsc-esm/icons}/index.js +1 -1
  56. package/{packageInfo.js → build-tsc-esm/packageInfo.js} +1 -1
  57. package/demo.png +0 -0
  58. package/index.html +17 -0
  59. package/package.json +8 -209
  60. package/src/Identicon.tsx +154 -0
  61. package/src/bundle.ts +6 -0
  62. package/src/icons/Beachball.tsx +32 -0
  63. package/src/icons/Empty.tsx +20 -0
  64. package/src/icons/Ethereum.tsx +37 -0
  65. package/src/icons/Jdenticon.tsx +24 -0
  66. package/src/icons/Pezkuwi.tsx +47 -0
  67. package/src/icons/index.ts +8 -0
  68. package/src/index.ts +10 -0
  69. package/src/packageDetect.ts +13 -0
  70. package/src/packageInfo.ts +6 -0
  71. package/src/styled.ts +4 -0
  72. package/src/types.ts +30 -0
  73. package/tsconfig.build.json +12 -0
  74. package/tsconfig.build.tsbuildinfo +1 -0
  75. /package/{cjs → build}/Identicon.d.ts +0 -0
  76. /package/{LICENSE → build/LICENSE} +0 -0
  77. /package/{cjs → build}/bundle.d.ts +0 -0
  78. /package/{icons → build/cjs/icons}/Beachball.d.ts +0 -0
  79. /package/{icons → build/cjs/icons}/Empty.d.ts +0 -0
  80. /package/{icons → build/cjs/icons}/Ethereum.d.ts +0 -0
  81. /package/{icons → build/cjs/icons}/Jdenticon.d.ts +0 -0
  82. /package/{index.d.ts → build/cjs/index.d.ts} +0 -0
  83. /package/{cjs → build/cjs}/package.json +0 -0
  84. /package/{packageDetect.d.ts → build/cjs/packageDetect.d.ts} +0 -0
  85. /package/{cjs → build/cjs}/packageDetect.js +0 -0
  86. /package/{packageInfo.d.ts → build/cjs/packageInfo.d.ts} +0 -0
  87. /package/{styled.d.ts → build/cjs/styled.d.ts} +0 -0
  88. /package/{Identicon.d.ts → build-tsc/Identicon.d.ts} +0 -0
  89. /package/{bundle.d.ts → build-tsc/bundle.d.ts} +0 -0
  90. /package/{cjs → build-tsc}/icons/Beachball.d.ts +0 -0
  91. /package/{cjs → build-tsc}/icons/Empty.d.ts +0 -0
  92. /package/{cjs → build-tsc}/icons/Ethereum.d.ts +0 -0
  93. /package/{cjs → build-tsc}/icons/Jdenticon.d.ts +0 -0
  94. /package/{cjs → build-tsc}/index.d.ts +0 -0
  95. /package/{cjs → build-tsc}/packageDetect.d.ts +0 -0
  96. /package/{cjs → build-tsc}/packageInfo.d.ts +0 -0
  97. /package/{cjs → build-tsc}/styled.d.ts +0 -0
  98. /package/{cjs → build-tsc-cjs}/bundle.js +0 -0
  99. /package/{cjs → build-tsc-cjs}/icons/Beachball.js +0 -0
  100. /package/{cjs → build-tsc-cjs}/icons/Empty.js +0 -0
  101. /package/{cjs → build-tsc-cjs}/icons/Ethereum.js +0 -0
  102. /package/{cjs → build-tsc-cjs}/icons/Jdenticon.js +0 -0
  103. /package/{cjs → build-tsc-cjs}/index.js +0 -0
  104. /package/{cjs → build-tsc-cjs}/styled.js +0 -0
  105. /package/{cjs → build-tsc-cjs}/types.js +0 -0
  106. /package/{bundle.js → build-tsc-esm/bundle.js} +0 -0
  107. /package/{icons → build-tsc-esm/icons}/Beachball.js +0 -0
  108. /package/{icons → build-tsc-esm/icons}/Empty.js +0 -0
  109. /package/{icons → build-tsc-esm/icons}/Ethereum.js +0 -0
  110. /package/{icons → build-tsc-esm/icons}/Jdenticon.js +0 -0
  111. /package/{index.js → build-tsc-esm/index.js} +0 -0
  112. /package/{packageDetect.js → build-tsc-esm/packageDetect.js} +0 -0
  113. /package/{styled.js → build-tsc-esm/styled.js} +0 -0
  114. /package/{types.js → build-tsc-esm/types.js} +0 -0
@@ -0,0 +1,104 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import React from 'react';
3
+ import CopyToClipboard from 'react-copy-to-clipboard';
4
+ import { ICON_DEFAULT_HOST, settings } from '@pezkuwi/ui-settings';
5
+ import { isHex, isU8a, u8aToHex } from '@pezkuwi/util';
6
+ import { decodeAddress, encodeAddress, ethereumEncode } from '@pezkuwi/util-crypto';
7
+ import { Beachball, Empty, Ethereum, Jdenticon, Pezkuwi } from './icons/index.js';
8
+ import { styled } from './styled.js';
9
+ const Fallback = Beachball;
10
+ const DEFAULT_SIZE = 64;
11
+ const Components = {
12
+ beachball: Beachball,
13
+ bizinikiwi: Jdenticon,
14
+ empty: Empty,
15
+ ethereum: Ethereum,
16
+ jdenticon: Jdenticon,
17
+ pezkuwi: Pezkuwi
18
+ };
19
+ class BaseIcon extends React.PureComponent {
20
+ state = {
21
+ address: '',
22
+ publicKey: '0x'
23
+ };
24
+ static prefix = undefined;
25
+ static setDefaultPrefix(prefix) {
26
+ BaseIcon.prefix = prefix;
27
+ }
28
+ static getDerivedStateFromProps({ prefix = BaseIcon.prefix, theme, value }, prevState) {
29
+ if (theme === 'ethereum') {
30
+ const address = isU8a(value)
31
+ ? ethereumEncode(value)
32
+ : value || '';
33
+ return { address, publicKey: '' };
34
+ }
35
+ try {
36
+ const address = isU8a(value) || isHex(value)
37
+ ? encodeAddress(value, prefix)
38
+ : (value || '');
39
+ const publicKey = u8aToHex(decodeAddress(address, false, prefix));
40
+ return address === prevState.address
41
+ ? null
42
+ : {
43
+ address,
44
+ publicKey
45
+ };
46
+ }
47
+ catch {
48
+ return {
49
+ address: '',
50
+ publicKey: '0x'
51
+ };
52
+ }
53
+ }
54
+ render() {
55
+ const { address } = this.state;
56
+ const wrapped = this.getWrapped(this.state, this.props);
57
+ return !address
58
+ ? wrapped
59
+ : (_jsx(CopyToClipboard, { onCopy: this.onCopy, text: address, children: wrapped }));
60
+ }
61
+ getWrapped({ address, publicKey }, { Custom }) {
62
+ const { className = '', isAlternative, isHighlight, size = DEFAULT_SIZE, style = {}, theme = settings.icon } = this.props;
63
+ const Component = !address
64
+ ? Empty
65
+ : Custom || Components[theme === 'default' ? ICON_DEFAULT_HOST : theme] || Fallback;
66
+ return (_jsx(StyledDiv, { className: `ui--IdentityIcon ${className}`, style: style, children: _jsx(Component, { address: address, className: isHighlight ? 'highlight' : '', isAlternative: isAlternative, publicKey: publicKey, size: size }) }, address));
67
+ }
68
+ onCopy = () => {
69
+ const { onCopy } = this.props;
70
+ const { address } = this.state;
71
+ if (address && onCopy) {
72
+ onCopy(address);
73
+ }
74
+ };
75
+ }
76
+ function Icon(props) {
77
+ return _jsx(BaseIcon, { ...props });
78
+ }
79
+ const StyledDiv = styled.div `
80
+ cursor: copy;
81
+ display: inline-block;
82
+ line-height: 0;
83
+
84
+ > .container {
85
+ position: relative;
86
+
87
+ > div,
88
+ > svg {
89
+ position: relative;
90
+ }
91
+
92
+ &.highlight:before {
93
+ position: absolute;
94
+ top: 0;
95
+ left: 0;
96
+ right: 0;
97
+ bottom: 0;
98
+ border-radius: 50%;
99
+ box-shadow: 0 0 5px 2px #aaa;
100
+ content: '';
101
+ }
102
+ }
103
+ `;
104
+ export const Identicon = React.memo(Icon);
@@ -0,0 +1,34 @@
1
+ # @pezkuwi/react-identicon
2
+
3
+ A generic identity icon that can render icons based on the theme, be it Substrate or Polkadot
4
+
5
+ ## Usage Examples
6
+
7
+ To install the component, do `yarn add @pezkuwi/react-identicon`
8
+
9
+ Inside a React component, you can now render any account with the associated icon -
10
+
11
+ ```javascript
12
+ import Identicon from '@pezkuwi/react-identicon';
13
+
14
+ ...
15
+ render () {
16
+ // address is an ss58-encoded address or publicKey (hex string or Uint8Array)
17
+ const { address } = this.props;
18
+ // size (optional) is a number, indicating the size (in pixels, 64 as default)
19
+ const size = 32;
20
+ // theme (optional), depicts the type of icon, one of
21
+ // 'polkadot', 'substrate' (default), 'beachball' or 'jdenticon'
22
+ const theme = 'polkadot';
23
+
24
+ // standard className & style props are also available
25
+ return (
26
+ <Identicon
27
+ value={address}
28
+ size={size}
29
+ theme={theme}
30
+ />
31
+ );
32
+ }
33
+ ...
34
+ ```