|
1 | 1 | # vue-component-component
|
2 | 2 |
|
3 |
| -## Project setup |
4 |
| -``` |
5 |
| -yarn install |
6 |
| -``` |
| 3 | +<p align="center"> |
7 | 4 |
|
8 |
| -### Compiles and hot-reloads for development |
9 |
| -``` |
10 |
| -yarn run serve |
11 |
| -``` |
| 5 | + |
| 6 | +[](https://github.com/koca/vue-component-component) |
| 7 | +[](https://circleci.com/gh/koca/vue-component-component/tree/master) |
| 8 | + |
| 9 | + |
| 10 | +</p> |
| 11 | + |
| 12 | +Vue version of [@Reach/component-component](https://github.com/reach/reach-ui/). |
| 13 | + |
| 14 | +> A dynamic version of Vue.Component, a component component if you will. Useful for inline lifecycles and state. It's also incredibly composable. |
| 15 | +
|
| 16 | + |
| 17 | + |
| 18 | +## Example |
12 | 19 |
|
13 |
| -### Compiles and minifies for production |
| 20 | +A Todo App: |
| 21 | + |
| 22 | +```html |
| 23 | +<vue-component :initial-state="{ newTodo: 'work', items:[]}"> |
| 24 | + <div slot-scope="{ state }"> |
| 25 | + What to do?: |
| 26 | + <input type="text" ref="inp" v-model="state.newTodo"> |
| 27 | + <button |
| 28 | + @click="()=>{ |
| 29 | + state.items.push(state.newTodo) |
| 30 | + state.newTodo = ''; |
| 31 | + $refs.inp.focus(); |
| 32 | + }" |
| 33 | + >Add</button> |
| 34 | + <br> |
| 35 | + <ul> |
| 36 | + <li :key="item" v-for="item in state.items">{{item}}</li> |
| 37 | + </ul> |
| 38 | + </div> |
| 39 | +</vue-component> |
14 | 40 | ```
|
15 |
| -yarn run build |
| 41 | + |
| 42 | +More Examples on [Codesandbox](https://codesandbox.io/s/01r8wko0v0). |
| 43 | + |
| 44 | +## Install |
| 45 | + |
| 46 | +```sh |
| 47 | +npm install vue-component-component |
16 | 48 | ```
|
17 | 49 |
|
18 |
| -### Lints and fixes files |
| 50 | +or |
| 51 | + |
| 52 | +```sh |
| 53 | +yarn add vue-component-component |
19 | 54 | ```
|
20 |
| -yarn run lint |
| 55 | + |
| 56 | +## Usage |
| 57 | + |
| 58 | +Register the component locally and use it (recommended) |
| 59 | + |
| 60 | +```js |
| 61 | +import Component from "vue-component-component"; |
| 62 | +export default { |
| 63 | + components: { |
| 64 | + // ⚠️ `<component>` tag is reserved by vue |
| 65 | + "vue-component": Component |
| 66 | + } |
| 67 | +}; |
21 | 68 | ```
|
22 | 69 |
|
23 |
| -### Run your unit tests |
| 70 | +Or register the component globally in `main.js` |
| 71 | + |
| 72 | +```js |
| 73 | +import Component from "vue-component-component"; |
| 74 | +Vue.component("vue-component", Component); |
24 | 75 | ```
|
25 |
| -yarn run test:unit |
| 76 | + |
| 77 | +Browser usage: |
| 78 | + |
| 79 | +```html |
| 80 | +<!-- vue-component-component JavaScript --> |
| 81 | +<script src="https://unpkg.com/vue-component-component"></script> |
| 82 | + |
| 83 | +<!-- use --> |
| 84 | +<script> |
| 85 | +Vue.component('vue-component', VueComponent) |
| 86 | +new Vue({ |
| 87 | + el: '#app' |
| 88 | +}) |
| 89 | +</script> |
26 | 90 | ```
|
| 91 | + |
| 92 | +## API |
| 93 | +TODO. |
| 94 | + |
| 95 | +All the life cycle hooks and `slot-scope` gets `state` and `setState`. |
| 96 | + |
| 97 | +## Props |
| 98 | + |
| 99 | +| Name | Type | Default | Description | |
| 100 | +| -------------------------- | ---------- | ------- | ------------------------------------------------------------------------------------------------------------ | |
| 101 | +| initialState | `object` | `{}` | initial state aka `data: ()=> ({})` | |
| 102 | +| created | `Function` | - | Called when the component is created. | |
| 103 | +| mounted | `Function` | - | Called when the component is mounted. | |
| 104 | +| All other Life Cycle Hooks | `Function` | - | "beforeMount", "mounted", "beforeUpdate", "updated", "activated", "deactivated", "beforeDestroy","destroyed" | |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | +## About |
| 109 | + |
| 110 | +Inspired by [@Reach/component-component](https://github.com/reach/reach-ui/). |
| 111 | +Thanks [Ryan](https://twitter.com/ryanflorence) 👍 |
| 112 | + |
| 113 | +# Todos |
| 114 | + |
| 115 | +- Refs? |
| 116 | + |
| 117 | +## Author |
| 118 | + |
| 119 | +**vue-component-component** © [koca](https://github.com/koca), Released under the [MIT](./LICENSE) License.<br> |
| 120 | +Authored and maintained by koca with help from contributors ([list](https://github.com/koca/vue-component-component/contributors)). |
| 121 | + |
| 122 | +> [mesutkoca.com](https://mesutkoca.com) · GitHub [@koca](https://github.com/koca) · Twitter [@imesutkoca](https://twitter.com/imesutkoca) |
0 commit comments