|
1 | 1 | # Vue3 Use Hooks |
2 | 2 |
|
3 | | -This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more. |
| 3 | +<p align="center">Reusability and Composition functions.</p> |
4 | 4 |
|
5 | | -## Recommended IDE Setup |
| 5 | +## :sunflower: Introduction |
6 | 6 |
|
7 | | -- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) |
| 7 | +Vue Use Hooks implemented as vue composition functions. |
8 | 8 |
|
9 | | -## Type Support For `.vue` Imports in TS |
| 9 | +## :package: Installation |
10 | 10 |
|
11 | | -Since TypeScript cannot handle type information for `.vue` imports, they are shimmed to be a generic Vue component type by default. In most cases this is fine if you don't really care about component prop types outside of templates. However, if you wish to get actual prop types in `.vue` imports (for example to get props validation when using manual `h(...)` calls), you can enable Volar's Take Over mode by following these steps: |
| 11 | +```bash |
| 12 | +# install with yarn |
| 13 | +yarn add vue3-use-hooks |
| 14 | +# install with npm |
| 15 | +npm install vue3-use-hooks |
| 16 | +``` |
12 | 17 |
|
13 | | -1. Run `Extensions: Show Built-in Extensions` from VS Code's command palette, look for `TypeScript and JavaScript Language Features`, then right click and select `Disable (Workspace)`. By default, Take Over mode will enable itself if the default TypeScript extension is disabled. |
14 | | -2. Reload the VS Code window by running `Developer: Reload Window` from the command palette. |
| 18 | +## :sparkles: useModal |
15 | 19 |
|
16 | | -You can learn more about Take Over mode [here](https://github.com/johnsoncodehk/volar/discussions/471). |
| 20 | +```vue |
| 21 | +<script setup lang="ts"> |
| 22 | +import { useModal } from 'vue3-use-hooks'; |
| 23 | +
|
| 24 | +const contrubitors = [ |
| 25 | + { |
| 26 | + id: 1, |
| 27 | + emoji: '👨', |
| 28 | + fullname: 'Abdulnasır Olcan', |
| 29 | + programmer: 'Frontend Developer', |
| 30 | + }, |
| 31 | + { |
| 32 | + id: 2, |
| 33 | + emoji: '👩', |
| 34 | + fullname: 'Büşra Şanlıbayrak', |
| 35 | + programmer: 'Frontend Developer', |
| 36 | + }, |
| 37 | + { |
| 38 | + id: 3, |
| 39 | + emoji: '🧑', |
| 40 | + fullname: 'Mehmet Varol', |
| 41 | + programmer: 'Frontend Developer', |
| 42 | + }, |
| 43 | +]; |
| 44 | +const { visible, setVisible, current, openModal, closeModal } = useModal(); |
| 45 | +
|
| 46 | +const handleButton = () => { |
| 47 | + openModal(contrubitors); |
| 48 | + setVisible(true); |
| 49 | +}; |
| 50 | +</script> |
| 51 | +
|
| 52 | +<template> |
| 53 | + <div class="modal-vue"> |
| 54 | + <!-- button show --> |
| 55 | + <button class="btn fourth" @click="handleButton">show model</button> |
| 56 | +
|
| 57 | + <!-- overlay --> |
| 58 | + <div class="overlay" v-if="visible"></div> |
| 59 | +
|
| 60 | + <!-- modal --> |
| 61 | + <div class="modal" v-if="visible"> |
| 62 | + <div class="modal-header">Modal Header</div> |
| 63 | + <button class="close" @click="closeModal">x</button> |
| 64 | + <div class="modal-content" v-for="contrubitor in current" :key="contrubitor.id"> |
| 65 | + <ul> |
| 66 | + <li> |
| 67 | + <p>{{ contrubitor.emoji }}</p> |
| 68 | + <h1>{{ contrubitor.fullname }}</h1> |
| 69 | + <span>{{ contrubitor.programmer }}</span> |
| 70 | + </li> |
| 71 | + </ul> |
| 72 | + </div> |
| 73 | + <div class="modal-footer">Modal Footer</div> |
| 74 | + </div> |
| 75 | + </div> |
| 76 | +</template> |
| 77 | +``` |
| 78 | + |
| 79 | +## :sparkles: useState |
| 80 | + |
| 81 | +```vue |
| 82 | +<script setup lang="ts"> |
| 83 | +import { useState } from 'vue3-use-hooks'; |
| 84 | +const [count, setCount] = useState(0); |
| 85 | +
|
| 86 | +</script> |
| 87 | +
|
| 88 | +<template> |
| 89 | + <div> |
| 90 | + <p><b>Count: </b> {{ count }}</p> |
| 91 | + <button class="fourth" @click="setCount(count - 1)">Decrement</button> |
| 92 | + <button class="fourth" @click="setCount(count + 1)">Increment</button> |
| 93 | + </div> |
| 94 | +</template> |
| 95 | +``` |
| 96 | + |
| 97 | +## :sparkles: useStringCase |
| 98 | + |
| 99 | +```vue |
| 100 | +<script setup lang="ts"> |
| 101 | +import { reactive } from 'vue'; |
| 102 | +import { useStringCase } from 'vue3-use-hooks'; |
| 103 | +
|
| 104 | +const state = reactive({ |
| 105 | + name: 'imelda white', |
| 106 | + gender: 'female', |
| 107 | + company: 'NEUROCELL', |
| 108 | + email: 'Imeldawhite@nr.com', |
| 109 | + balance: '3,814.49', |
| 110 | + about: 'Veniam fugiat pariatur adipisicing do consequat.', |
| 111 | + address: 'bulwer place, lemoyne, district of columbia, 5597', |
| 112 | +}); |
| 113 | +
|
| 114 | +const { camelCase, kebabCase, pascalCase, upperCase, lowerCase, sentenceCase, capitalizeCase } = useStringCase(); |
| 115 | +
|
| 116 | +</script> |
| 117 | +
|
| 118 | +<template> |
| 119 | + <div> |
| 120 | + <p><b>CamelCase: </b>{{ camelCase(state.about) }}</p> |
| 121 | + <p><b>CapitalizeCase: </b>{{ capitalizeCase(state.name) }}</p> |
| 122 | + <p><b>SentenceCase: </b>{{ sentenceCase(state.company) }}</p> |
| 123 | + <p><b>KebabCase: </b>{{ kebabCase(state.balance) }}</p> |
| 124 | + <p><b>PascalCase: </b>{{ pascalCase(state.address) }}</p> |
| 125 | + <p><b>LowerCase: </b>{{ lowerCase(state.email) }}</p> |
| 126 | + <p><b>UpperCase: </b>{{ upperCase(state.gender) }}</p> |
| 127 | + </div> |
| 128 | +</template> |
| 129 | +``` |
| 130 | + |
| 131 | +## License |
| 132 | + |
| 133 | +MIT |
0 commit comments