Swap to using defineComponent for Vue (req. 2.7+) (#732)

* Swap to using definedComponent for Vue (req. 2.7+)

* Adjust

* Adjust

* CHANGELOG
This commit is contained in:
Jaco authored and GitHub committed 2023-03-12 13:29:49 +02:00
1 parent 172051cedc
commit 45b330aa90
25 files changed
+84 -59

No files matched your search

+1 -1
View File
@@ -32,6 +32,6 @@
"peerDependencies": {
"@polkadot/util": "*",
"@polkadot/util-crypto": "*",
"vue": "*"
"vue": "^2.7"
}
}
+29 -11
View File
@@ -3,7 +3,7 @@
import type { Prefix } from '@polkadot/util-crypto/address/types';
import Vue, { VNode } from 'vue';
import { defineComponent, VNode } from 'vue';
import { isHex, isU8a, u8aToHex } from '@polkadot/util';
import { decodeAddress, encodeAddress } from '@polkadot/util-crypto';
@@ -46,7 +46,7 @@ function encodeAccount (value: string | Uint8Array, prefix?: Prefix): Account {
* <Identicon :size="128" :theme="polkadot" :value="..." />
* ```
*/
export const Identicon = Vue.extend({
export const Identicon = defineComponent({
components: {
Beachball,
Empty,
@@ -81,19 +81,37 @@ export const Identicon = Vue.extend({
},
props: ['prefix', 'isAlternative', 'size', 'theme', 'value'],
render (h): VNode {
const { address, iconSize, isAlternativeIcon, publicKey, type } = this.$data as Data;
const { address, iconSize, isAlternativeIcon, publicKey, type } = this.$data;
if (type === 'empty') {
return h('Empty', { attrs: { key: address, size: iconSize } }, []);
return h('Empty', {
attrs: {
key: address,
size: iconSize
}
}, []);
} else if (type === 'jdenticon') {
return h('Jdenticon', { attrs: { key: address, publicKey, size: iconSize } }, []);
} else {
// handles: beachball and polkadot
// TODO: substrate
const cmp = type.charAt(0).toUpperCase() + type.slice(1);
return h(cmp, { attrs: { address, isAlternative: isAlternativeIcon, key: address, size: iconSize } }, []);
return h('Jdenticon', {
attrs: {
key: address,
publicKey,
size: iconSize
}
}, []);
} else if (type === 'substrate') {
throw new Error('substrate type is not supported');
}
const cmp = type.charAt(0).toUpperCase() + type.slice(1);
return h(cmp, {
attrs: {
address,
isAlternative: isAlternativeIcon,
key: address,
size: iconSize
}
}, []);
},
watch: {
value: function (): void {
+10 -7
View File
@@ -1,11 +1,11 @@
// Copyright 2017-2023 @polkadot/vue-identicon authors & contributors
// SPDX-License-Identifier: Apache-2.0
import Vue, { VNode } from 'vue';
import { defineComponent, VNode } from 'vue';
import { beachballIcon } from '@polkadot/ui-shared';
type propsType = {
type PropsType = {
address: string;
size: number;
isAlternative: boolean;
@@ -15,13 +15,16 @@ type propsType = {
* @name Beachball
* @description The Beachball identicon
*/
export const Beachball = Vue.extend({
export const Beachball = defineComponent({
props: ['address', 'size', 'isAlternative'],
// eslint-disable-next-line quotes
render (h): VNode {
const { address, isAlternative, size } = this.$props as propsType;
const bb = beachballIcon(address, { isAlternative, size });
const { address, isAlternative, size } = this.$props as PropsType;
return h(Vue.component('VCBeachball', { template: bb.outerHTML }));
return h({
template: beachballIcon(address, {
isAlternative,
size
}).outerHTML
});
}
});
+2 -2
View File
@@ -1,13 +1,13 @@
// Copyright 2017-2023 @polkadot/vue-identicon authors & contributors
// SPDX-License-Identifier: Apache-2.0
import Vue from 'vue';
import { defineComponent } from 'vue';
/**
* @name Empty
* @description An empty identicon
*/
export const Empty = Vue.extend({
export const Empty = defineComponent({
props: ['size'],
template: `
<svg :height="size" :width="size" viewBox="0 0 64 64">
@@ -2,9 +2,9 @@
// SPDX-License-Identifier: Apache-2.0
import * as jdenticon from 'jdenticon';
import Vue, { VNode } from 'vue';
import { defineComponent, VNode } from 'vue';
type propsType = {
type PropsType = {
publicKey: string,
size: number
}
@@ -13,13 +13,13 @@ type propsType = {
* @name Jdenticon
* @description The substrate default via Jdenticon
*/
export const Jdenticon = Vue.extend({
export const Jdenticon = defineComponent({
props: ['publicKey', 'size'],
// eslint-disable-next-line quotes
render (h): VNode {
const { publicKey, size } = this.$props as propsType;
const cmp = Vue.component('CJdenticon', { template: jdenticon.toSvg(publicKey.substring(2), size) });
const { publicKey, size } = this.$props as PropsType;
return h(cmp);
return h({
template: jdenticon.toSvg(publicKey.substring(2), size)
});
}
});
+11 -12
View File
@@ -1,7 +1,7 @@
// Copyright 2017-2023 @polkadot/vue-identicon authors & contributors
// SPDX-License-Identifier: Apache-2.0
import Vue, { VNode } from 'vue';
import { defineComponent, VNode } from 'vue';
import { polkadotIcon } from '@polkadot/ui-shared';
@@ -15,21 +15,20 @@ type propsType = {
* @name Polkadot
* @description The Polkadot default identicon
*/
export const Polkadot = Vue.extend({
export const Polkadot = defineComponent({
props: ['address', 'isAlternative', 'size'],
// eslint-disable-next-line quotes
render (h): VNode {
const { address, isAlternative, size } = this.$props as propsType;
const circles = polkadotIcon(address, {
isAlternative: isAlternative || false
}).map(({ cx,
cy,
fill,
r }) => {
return h('circle', { attrs: { cx, cy, fill, r } }, []);
}
const circles = polkadotIcon(address, { isAlternative }).map(({ cx, cy, fill, r }) =>
h('circle', { attrs: { cx, cy, fill, r } }, [])
);
return h('svg', { attrs: { height: size, viewBox: '0 0 64 64', width: size } }, circles);
return h('svg', {
attrs: {
height: size,
viewBox: '0 0 64 64',
width: size
}
}, circles);
}
});