Skip to content

Commit 9cbea3d

Browse files
committed
No TS in demo App.vue for now, improves readme
1 parent 78a39e6 commit 9cbea3d

File tree

3 files changed

+67
-9
lines changed

3 files changed

+67
-9
lines changed

README.md

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,64 @@ _or_
1515
Use the UMD build from [Unpkg](https://unpkg.com/vue-input-autowidth), available as `VueInputAutowidth` in the global scope.
1616

1717
```html
18-
<script src="/vendor/vue.js">
19-
<script src="https://unpkg.com/vue-input-autowidth">
18+
<script src="/vendor/vue.js" />
19+
<script src="https://unpkg.com/vue-input-autowidth" />
2020
```
21+
22+
## Usage
23+
24+
### Globally
25+
26+
Import and register the directive in your app's entrypoint.
27+
28+
```js
29+
import { createApp } from "vue";
30+
import App from "./App.vue";
31+
import { plugin as VueInputAutowidth } from "vue-input-autowidth";
32+
33+
createApp(App).use(VueInputAutowidth).mount("#app");
34+
```
35+
36+
### Per-component
37+
38+
```js
39+
<script>
40+
import { directive as VueInputAutowidth } from "vue-input-autowidth"
41+
42+
export default {
43+
directives: { autowidth: VueInputAutowidth },
44+
setup() {
45+
...
46+
},
47+
}
48+
</script>
49+
```
50+
51+
...and in your template:
52+
53+
```html
54+
<template>
55+
<input type="text" placeholder="First Name" v-model="msg" v-autowidth />
56+
</template>
57+
```
58+
59+
You can also pass some options:
60+
61+
```html
62+
<template>
63+
<input
64+
type="text"
65+
placeholder="First Name"
66+
v-model="msg"
67+
v-autowidth="{
68+
minWidth: '75px',
69+
maxWidth: '75%',
70+
comfortZone: '1ch',
71+
}"
72+
/>
73+
</template>
74+
```
75+
76+
## License
77+
78+
MIT © [Collin Henderson](https://github.com/syropian)

demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.0.0",
44
"scripts": {
55
"dev": "vite",
6-
"build": "vue-tsc --noEmit && vite build -c ./vite.demo.config.ts",
6+
"build": "vue-tsc --noEmit && vite build",
77
"serve": "vite preview"
88
},
99
"dependencies": {

demo/src/App.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,28 +59,28 @@
5959
</div>
6060
</template>
6161

62-
<script setup lang="ts">
63-
import { Ref, ref } from "vue";
62+
<script setup>
63+
import { ref } from "vue";
6464
65-
const msg: Ref<string> = ref("");
65+
const msg = ref("");
6666
6767
const installCode = ref(`$ npm install vue-input-autowidth@next --save
6868
# or...
6969
$ yarn add vue-input-autowidth@next`);
7070
const addGlobalCode = ref(`import { createApp } from 'vue'
7171
import App from './App.vue'
72-
import VueInputAutowidth from 'vue-input-autowidth'
72+
import { plugin as VueInputAutowidth } from 'vue-input-autowidth'
7373
7474
createApp(App).use(VueInputAutowidth).mount("#app")
7575
`);
7676
const perComponentCode = `import { directive as VueInputAutowidth } from 'vue-input-autowidth'
7777
78-
export default defineComponent({
78+
export default {
7979
directives: { autowidth: VueInputAutowidth },
8080
setup() {
8181
...
8282
},
83-
})`;
83+
}`;
8484
const useDirectiveCode = `<input
8585
type="text"
8686
placeholder="Watch me change size with my content!"

0 commit comments

Comments
 (0)