@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.
- package/build/Identicon.js +104 -0
- package/build/README.md +34 -0
- package/{bundle-pezkuwi-react-identicon.js → build/bundle-pezkuwi-react-identicon.js} +62 -50
- package/build/bundle.js +3 -0
- package/build/cjs/Identicon.d.ts +5 -0
- package/build/cjs/Identicon.js +108 -0
- package/build/cjs/bundle.d.ts +3 -0
- package/build/cjs/bundle.js +9 -0
- package/build/cjs/icons/Beachball.js +17 -0
- package/build/cjs/icons/Empty.js +10 -0
- package/build/cjs/icons/Ethereum.js +18 -0
- package/build/cjs/icons/Jdenticon.js +12 -0
- package/{icons/Polkadot.d.ts → build/cjs/icons/Pezkuwi.d.ts} +1 -1
- package/build/cjs/icons/Pezkuwi.js +15 -0
- package/{icons → build/cjs/icons}/index.d.ts +1 -1
- package/build/cjs/icons/index.js +13 -0
- package/build/cjs/index.js +7 -0
- package/build/cjs/packageInfo.js +4 -0
- package/build/cjs/styled.js +5 -0
- package/{types.d.ts → build/cjs/types.d.ts} +1 -1
- package/build/cjs/types.js +2 -0
- package/build/icons/Beachball.d.ts +5 -0
- package/build/icons/Beachball.js +13 -0
- package/build/icons/Empty.d.ts +5 -0
- package/build/icons/Empty.js +6 -0
- package/build/icons/Ethereum.d.ts +5 -0
- package/build/icons/Ethereum.js +14 -0
- package/build/icons/Jdenticon.d.ts +5 -0
- package/build/icons/Jdenticon.js +8 -0
- package/build/icons/Pezkuwi.d.ts +5 -0
- package/build/icons/Pezkuwi.js +11 -0
- package/build/icons/index.d.ts +5 -0
- package/build/icons/index.js +5 -0
- package/build/index.d.ts +4 -0
- package/build/index.js +4 -0
- package/build/package.json +249 -0
- package/build/packageDetect.d.ts +1 -0
- package/build/packageDetect.js +5 -0
- package/build/packageInfo.d.ts +6 -0
- package/build/packageInfo.js +1 -0
- package/build/styled.d.ts +1 -0
- package/build/styled.js +1 -0
- package/build/types.d.ts +23 -0
- package/build/types.js +1 -0
- package/{cjs/icons/Polkadot.d.ts → build-tsc/icons/Pezkuwi.d.ts} +1 -1
- package/{cjs → build-tsc}/icons/index.d.ts +1 -1
- package/{cjs → build-tsc}/types.d.ts +1 -1
- package/{cjs → build-tsc-cjs}/Identicon.js +2 -2
- package/{cjs/icons/Polkadot.js → build-tsc-cjs/icons/Pezkuwi.js} +3 -3
- package/{cjs → build-tsc-cjs}/icons/index.js +3 -3
- package/build-tsc-cjs/packageDetect.js +7 -0
- package/{cjs → build-tsc-cjs}/packageInfo.js +1 -1
- package/{Identicon.js → build-tsc-esm/Identicon.js} +3 -3
- package/{icons/Polkadot.js → build-tsc-esm/icons/Pezkuwi.js} +3 -3
- package/{icons → build-tsc-esm/icons}/index.js +1 -1
- package/{packageInfo.js → build-tsc-esm/packageInfo.js} +1 -1
- package/demo.png +0 -0
- package/index.html +17 -0
- package/package.json +8 -209
- package/src/Identicon.tsx +154 -0
- package/src/bundle.ts +6 -0
- package/src/icons/Beachball.tsx +32 -0
- package/src/icons/Empty.tsx +20 -0
- package/src/icons/Ethereum.tsx +37 -0
- package/src/icons/Jdenticon.tsx +24 -0
- package/src/icons/Pezkuwi.tsx +47 -0
- package/src/icons/index.ts +8 -0
- package/src/index.ts +10 -0
- package/src/packageDetect.ts +13 -0
- package/src/packageInfo.ts +6 -0
- package/src/styled.ts +4 -0
- package/src/types.ts +30 -0
- package/tsconfig.build.json +12 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- /package/{cjs → build}/Identicon.d.ts +0 -0
- /package/{LICENSE → build/LICENSE} +0 -0
- /package/{cjs → build}/bundle.d.ts +0 -0
- /package/{icons → build/cjs/icons}/Beachball.d.ts +0 -0
- /package/{icons → build/cjs/icons}/Empty.d.ts +0 -0
- /package/{icons → build/cjs/icons}/Ethereum.d.ts +0 -0
- /package/{icons → build/cjs/icons}/Jdenticon.d.ts +0 -0
- /package/{index.d.ts → build/cjs/index.d.ts} +0 -0
- /package/{cjs → build/cjs}/package.json +0 -0
- /package/{packageDetect.d.ts → build/cjs/packageDetect.d.ts} +0 -0
- /package/{cjs → build/cjs}/packageDetect.js +0 -0
- /package/{packageInfo.d.ts → build/cjs/packageInfo.d.ts} +0 -0
- /package/{styled.d.ts → build/cjs/styled.d.ts} +0 -0
- /package/{Identicon.d.ts → build-tsc/Identicon.d.ts} +0 -0
- /package/{bundle.d.ts → build-tsc/bundle.d.ts} +0 -0
- /package/{cjs → build-tsc}/icons/Beachball.d.ts +0 -0
- /package/{cjs → build-tsc}/icons/Empty.d.ts +0 -0
- /package/{cjs → build-tsc}/icons/Ethereum.d.ts +0 -0
- /package/{cjs → build-tsc}/icons/Jdenticon.d.ts +0 -0
- /package/{cjs → build-tsc}/index.d.ts +0 -0
- /package/{cjs → build-tsc}/packageDetect.d.ts +0 -0
- /package/{cjs → build-tsc}/packageInfo.d.ts +0 -0
- /package/{cjs → build-tsc}/styled.d.ts +0 -0
- /package/{cjs → build-tsc-cjs}/bundle.js +0 -0
- /package/{cjs → build-tsc-cjs}/icons/Beachball.js +0 -0
- /package/{cjs → build-tsc-cjs}/icons/Empty.js +0 -0
- /package/{cjs → build-tsc-cjs}/icons/Ethereum.js +0 -0
- /package/{cjs → build-tsc-cjs}/icons/Jdenticon.js +0 -0
- /package/{cjs → build-tsc-cjs}/index.js +0 -0
- /package/{cjs → build-tsc-cjs}/styled.js +0 -0
- /package/{cjs → build-tsc-cjs}/types.js +0 -0
- /package/{bundle.js → build-tsc-esm/bundle.js} +0 -0
- /package/{icons → build-tsc-esm/icons}/Beachball.js +0 -0
- /package/{icons → build-tsc-esm/icons}/Empty.js +0 -0
- /package/{icons → build-tsc-esm/icons}/Ethereum.js +0 -0
- /package/{icons → build-tsc-esm/icons}/Jdenticon.js +0 -0
- /package/{index.js → build-tsc-esm/index.js} +0 -0
- /package/{packageDetect.js → build-tsc-esm/packageDetect.js} +0 -0
- /package/{styled.js → build-tsc-esm/styled.js} +0 -0
- /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);
|
package/build/README.md
ADDED
|
@@ -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
|
+
```
|