Skip to content

Commit 2af7862

Browse files
committed
refactor with composition api and tsx
1 parent 1b7dd3b commit 2af7862

File tree

23 files changed

+564
-117
lines changed

23 files changed

+564
-117
lines changed

.storybook/config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import { withOptions } from '@storybook/addon-options';
66
import { setConsoleOptions } from '@storybook/addon-console';
77
import { addReadme } from 'storybook-readme/vue';
88
import useVuetify from './vuetify';
9+
import Vue from 'vue';
10+
import VueCompositionAPI from '@vue/composition-api';
911

12+
Vue.use(VueCompositionAPI);
1013
addDecorator(addReadme);
1114
addDecorator(() => ({
1215
vuetify: useVuetify(),

.storybook/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = {
55
module: {
66
rules: [
77
{
8-
test: /.(js|ts)$/,
8+
test: /.(js|jsx|ts|tsx)$/,
99
use: [
1010
{loader: 'babel-loader'}
1111
],

@types/global.d.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,21 @@ declare module '*.md' {
2222
}
2323

2424
declare module '*.vue' {
25-
import Vue from 'vue';
26-
export default Vue;
25+
import type { VueConstructor } from 'vue';
26+
import type { defineComponent } from '@vue/composition-api';
27+
const component: ReturnType<typeof defineComponent> & {
28+
install(app: VueConstructor<Vue>): void
29+
};
30+
export default component;
31+
}
32+
33+
declare module '*.tsx' {
34+
import type { VueConstructor } from 'vue';
35+
import type { defineComponent } from '@vue/composition-api';
36+
const VueComponent: ReturnType<typeof defineComponent> & {
37+
install(app: VueConstructor<Vue>): void
38+
};
39+
export default VueComponent;
2740
}
2841

2942
declare module '@foxone/uikit';

@types/shim-tsx.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { VNode } from 'vue';
2+
import type { ComponentRenderProxy } from '@vue/composition-api';
3+
4+
declare global {
5+
namespace JSX {
6+
interface Element extends VNode { }
7+
interface ElementClass extends ComponentRenderProxy { }
8+
interface ElementAttributesProperty {
9+
$props: any;
10+
}
11+
interface IntrinsicElements {
12+
[elem: string]: any;
13+
}
14+
}
15+
}

babel.config.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,16 @@ module.exports = function (api) {
55
const presets = [
66
'@babel/preset-env',
77
'babel-preset-vue',
8+
['@vue/babel-preset-jsx', { compositionAPI: true }],
89
'@babel/preset-typescript'
910
];
1011

1112
const plugins = [
1213
'@babel/plugin-transform-runtime',
13-
['@babel/proposal-decorators', {
14-
legacy: true
15-
}],
16-
['@babel/proposal-class-properties', {
17-
loose: true
18-
}],
19-
['@babel/plugin-proposal-private-property-in-object', {
20-
loose: true
21-
}],
22-
['@babel/plugin-proposal-private-methods', {
23-
loose: true
24-
}]
14+
['@babel/plugin-proposal-decorators', { legacy: true }],
15+
['@babel/plugin-proposal-class-properties', { loose: true }],
16+
['@babel/plugin-proposal-private-property-in-object', { loose: true }],
17+
['@babel/plugin-proposal-private-methods', { loose: true }]
2518
];
2619

2720
const env = {

jest.config.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@ module.exports = {
77

88
moduleFileExtensions: [
99
'js',
10+
'jsx',
1011
'json',
1112
'ts',
13+
'tsx',
1214
'vue'
1315
],
1416

1517
roots: ['<rootDir>/src'],
1618

1719
testRegex:
18-
'(test|__test__)/.*.test.(vue|ts|js)?$',
20+
'(test|__test__)/.*.test.(vue|ts|tsx|js|jsx)?$',
1921

2022
transform: {
21-
'^.+.ts$': 'ts-jest',
23+
'^.+.tsx?$': 'babel-jest',
2224
'^.+.vue$': 'vue-jest',
2325
'^.+\\.svg$': 'jest-svg-transformer'
2426
},
@@ -35,6 +37,7 @@ module.exports = {
3537

3638
transformIgnorePatterns: [
3739
'/node_modules/(?!(vuetify)/)/',
38-
'/node_modules/(?!(@foxone/uikit)/)/'
40+
'/node_modules/(?!(@foxone/uikit)/)/',
41+
'/node_modules/(?!(@vue/composition-api)/)/'
3942
]
4043
};

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
},
4141
"license": "MIT",
4242
"dependencies": {
43+
"@vue/composition-api": "^1.0.0-rc.13",
4344
"classnames": "~2.2.6",
4445
"vue-slider-component": "~3.2.13"
4546
},
@@ -55,7 +56,7 @@
5556
"@commitlint/cli": "8.3.5",
5657
"@foxone/uikit": "~2.0.59",
5758
"@mdi/js": "^5.9.55",
58-
"@omni-door/cli": "^2.5.0",
59+
"@omni-door/cli": "^2.5.1",
5960
"@storybook/addon-actions": "5.3.21",
6061
"@storybook/addon-console": "1.2.2",
6162
"@storybook/addon-docs": "5.3.21",
@@ -72,6 +73,8 @@
7273
"@types/node": "~14.0.27",
7374
"@typescript-eslint/eslint-plugin": "~3.8.0",
7475
"@typescript-eslint/parser": "~3.8.0",
76+
"@vue/babel-helper-vue-jsx-merge-props": "^1.2.1",
77+
"@vue/babel-preset-jsx": "^1.2.4",
7578
"@vue/test-utils": "^1.2.0",
7679
"babel-jest": "~26.6.3",
7780
"babel-loader": "~8.1.0",
@@ -127,7 +130,7 @@
127130
"ts-jest": "^25.5.1",
128131
"ts-node": "8.6.2",
129132
"ttypescript": "~1.5.12",
130-
"typescript": "~3.9.7",
133+
"typescript": "~4.3.5",
131134
"typescript-transform-paths": "~2.0.3",
132135
"url-loader": "~3.0.0",
133136
"vue": "~2.6.8",

src/AssetRangeInput/__stories__/index.stories.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { INITIAL_VIEWPORTS } from '@storybook/addon-viewport';
33
import { themes } from '@storybook/theming';
44
import { AssetRangeInput } from '../';
55
import { RiskSlider } from '../../RiskSlider';
6-
import { ConnectWallet } from '../../ConnectWallet';
6+
import ConnectWallet from '../../ConnectWallet';
77
import '../style';
88

99
const asset = {

src/ConnectWallet/ConnectWallet.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/ConnectWallet/ConnectWallet.tsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import {
2+
defineComponent,
3+
onMounted
4+
} from '@vue/composition-api';
5+
import classnames from '@utils/classnames';
6+
/* import types */
7+
import type { CreateElement, VNode } from 'vue';
8+
9+
export default defineComponent({
10+
name: 'ConnectWallet',
11+
props: {
12+
className: {
13+
type: String,
14+
default: ''
15+
},
16+
text: {
17+
type: [String, Object],
18+
default: 'Connect Wallet'
19+
}
20+
},
21+
setup() {
22+
const classes = classnames('connect-wallet');
23+
onMounted(() => {
24+
console.info('ConnectWallet mounted!');
25+
});
26+
27+
return { classes };
28+
},
29+
render(h: CreateElement): VNode {
30+
return (
31+
<div class={this.classes(void 0, this.className)}>
32+
<span class={this.classes('text', 'f-greyscale-1 f-caption font-weight-bold pr-4')}>
33+
{ this.text }
34+
</span>
35+
</div>
36+
);
37+
}
38+
});

0 commit comments

Comments
 (0)