Skip to content

Commit f41d36f

Browse files
committed
A
1 parent c38bd7f commit f41d36f

File tree

8 files changed

+70
-88
lines changed

8 files changed

+70
-88
lines changed

examples/App.vue

+15-16
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
<template>
22
<div id="app">
3-
<img alt="Vue logo" src="./assets/logo.png">
4-
<HelloWorld msg="Welcome to Your Vue.js + TypeScript App"/>
3+
<button class="button" v-ripple="'red'" >Ripple</button>
54
</div>
65
</template>
76

87
<script lang="ts">
98
import { Component, Vue } from 'vue-property-decorator';
10-
import HelloWorld from './components/HelloWorld.vue';
119
12-
@Component({
13-
components: {
14-
HelloWorld,
15-
},
16-
})
17-
export default class App extends Vue {}
10+
@Component
11+
export default class App extends Vue {
12+
private opts: any = {
13+
color: 'red',
14+
}
15+
}
1816
</script>
1917

2018
<style lang="scss">
21-
#app {
22-
font-family: 'Avenir', Helvetica, Arial, sans-serif;
23-
-webkit-font-smoothing: antialiased;
24-
-moz-osx-font-smoothing: grayscale;
25-
text-align: center;
26-
color: #2c3e50;
27-
margin-top: 60px;
19+
.button {
20+
padding: 8px 16px;
21+
background: #0077ff;
22+
border: none;
23+
color: #fff;
24+
border-radius: 8px;
25+
outline: 0;
26+
cursor: pointer;
2827
}
2928
</style>

examples/components/HelloWorld.vue

-59
This file was deleted.

examples/main.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import Vue from 'vue';
22
import App from './App.vue';
3+
import Ripple from '../packages/index';
34

45
Vue.config.productionTip = false;
6+
Vue.use(Ripple);
57

68
new Vue({
79
render: h => h(App),

packages/directive.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { DirectiveBinding } from 'vue/types/options.d';
2+
import { IRippleOpts } from 'types/index.d';
3+
4+
export default class Directive {
5+
static options: IRippleOpts = {
6+
name: 'ripple',
7+
event: 'mousedown',
8+
transition: 600,
9+
color: 'rgba(0, 0, 0, 0.15)',
10+
};
11+
12+
public install(options: IRippleOpts) {
13+
Directive.options = Object.assign({}, Directive.options, options);
14+
return {
15+
bind: (el: HTMLElement, bind: DirectiveBinding) => this.bind(el, bind),
16+
};
17+
}
18+
19+
bind(el: HTMLElement, bind: DirectiveBinding) {
20+
if (bind.modifiers && bind.modifiers.click) {
21+
Directive.options.event = 'click';
22+
}
23+
if (bind.modifiers && bind.modifiers.mousedown) {
24+
Directive.options.event = 'mousedown';
25+
}
26+
if (bind.value) Directive.options.color = bind.value;
27+
}
28+
}

packages/index.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Vue } from 'vue-property-decorator';
2+
import { IRippleOpts } from 'types/index.d';
3+
import Ripple from './directive';
4+
5+
export default {
6+
install(instance: typeof Vue, options: IRippleOpts) {
7+
/* eslint-disable no-param-reassign */
8+
options = options || { name: 'ripple' };
9+
instance.directive(options.name, new Ripple().install(options));
10+
},
11+
};

tsconfig.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@
2727
]
2828
},
2929
"include": [
30-
"src/**/*.ts",
31-
"src/**/*.tsx",
32-
"src/**/*.vue",
30+
"examples/**/*.ts",
31+
"examples/**/*.tsx",
32+
"examples/**/*.vue",
33+
"packages/**/*.ts",
34+
"packages/**/*.tsx",
35+
"packages/**/*.vue",
3336
"tests/**/*.ts",
3437
"tests/**/*.tsx"
3538
],

types/index.d.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export interface IRippleOpts {
2+
name: string,
3+
event?: string,
4+
transition?: number,
5+
color?: string,
6+
}

vue.config.js

+2-10
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,7 @@ module.exports = {
1515
},
1616
chainWebpack: config => {
1717
config.resolve.alias
18-
.set('~', path.resolve('packages'));
19-
config.module
20-
.rule('ts')
21-
.include.add('/packages')
22-
.end()
23-
.use('bable')
24-
.loader('bable-loader')
25-
.tap(options => {
26-
return options;
27-
});
18+
.set('~', path.resolve('packages'))
19+
.set('types', path.resolve('types'));
2820
},
2921
}

0 commit comments

Comments
 (0)