|
| 1 | +# Vue CSC Selector |
| 2 | + |
| 3 | +[](https://www.npmjs.com/package/@toneflix/vue-place-selector) |
| 4 | +[](https://www.npmjs.com/package/@toneflix/vue-place-selector) |
| 5 | + |
| 6 | +Country State City Selector component for Vue3. - See a live demo [here](https://toneflix.github.io/vue-component-pack/vue-place-selector/demo.html). |
| 7 | + |
| 8 | +<p align="center"> |
| 9 | + <img width="200" src="https://toneflix.github.io/vue-component-pack/vue-place-selector/images/banner.png" alt="CSC Selector"> |
| 10 | + <!--<img width="200" src="https://vuejs.org/images/logo.png" alt="Vue.js">--> |
| 11 | +</p> |
| 12 | + |
| 13 | +## Documentation |
| 14 | + |
| 15 | +Read the full documentation [here](https://toneflix.github.io/vue-component-pack/vue-place-selector/) |
| 16 | + |
| 17 | +## Installation |
| 18 | + |
| 19 | +```bash |
| 20 | +npm install @toneflix/vue-place-selector |
| 21 | +#or |
| 22 | +yarn add @toneflix/vue-place-selector |
| 23 | +#or |
| 24 | +pnpm add @toneflix/vue-place-selector |
| 25 | +``` |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +## Get API Key |
| 30 | + |
| 31 | +This package depends on the `Toneflix Places API` for it's data set, the `Toneflix Places API` requires an API key for use on production, the get you api keys, head to `https://naija-places.toneflix.com.ng`: |
| 32 | + |
| 33 | +1. Click on `Portal`. |
| 34 | +2. Login if required. |
| 35 | +3. Click on `API Keys` |
| 36 | +4. Click on `Create new API Key` |
| 37 | +5. Provide a name to identify your API key and click on `Create` |
| 38 | + |
| 39 | +### Global Registration |
| 40 | + |
| 41 | +You can make `Vue CSC Selector` available throughout your Vue project. |
| 42 | + |
| 43 | +**main.js or main.ts** |
| 44 | + |
| 45 | +```js |
| 46 | +import { createApp } from 'vue' |
| 47 | +import App from './app.vue' |
| 48 | +import VuePlaceSelector from '@toneflix/vue-place-selector' |
| 49 | + |
| 50 | +const app = createApp(App) |
| 51 | +app.use(VuePlaceSelector) |
| 52 | +app.mount('#app') |
| 53 | +``` |
| 54 | + |
| 55 | +### Local Registration |
| 56 | + |
| 57 | +You can also import the component in your Vue component. |
| 58 | + |
| 59 | +**SomeComponent.vue** |
| 60 | + |
| 61 | +```vue |
| 62 | +<script setup> |
| 63 | +import { VuePlaceSelector } from '@toneflix/vue-place-selector' |
| 64 | +</script> |
| 65 | +``` |
| 66 | + |
| 67 | +### Use the Registered Component in Your Vue Template |
| 68 | + |
| 69 | +**SomeComponent.vue** |
| 70 | + |
| 71 | +```vue |
| 72 | +<script setup lang="ts"> |
| 73 | +import { VuePlaceSelector } from '@toneflix/vue-place-selector' |
| 74 | +import { ref } from 'vue' |
| 75 | +
|
| 76 | +const form = ref({ |
| 77 | + country: '', |
| 78 | + state: '', |
| 79 | + city: '' |
| 80 | +}) |
| 81 | +</script> |
| 82 | +
|
| 83 | +<template> |
| 84 | + <div style="display: flex; flex-direction: row;"> |
| 85 | + <div> |
| 86 | + <VuePlaceSelector type="country" v-model="form.country" @error="console.log" /> |
| 87 | + </div> |
| 88 | + <div> |
| 89 | + <VuePlaceSelector |
| 90 | + type="state" |
| 91 | + v-model="form.state" |
| 92 | + :params="{ countries: form.country }" |
| 93 | + @error="console.log" |
| 94 | + /> |
| 95 | + </div> |
| 96 | + <div> |
| 97 | + <VuePlaceSelector |
| 98 | + type="city" |
| 99 | + v-model="form.city" |
| 100 | + :params="{ countries: form.country, states: form.state }" |
| 101 | + @error="console.log" |
| 102 | + /> |
| 103 | + </div> |
| 104 | + </div> |
| 105 | +</template> |
| 106 | +``` |
| 107 | + |
| 108 | +### Setup API Key (For Production) |
| 109 | + |
| 110 | +If you have an `env` file, that would be the best place to provide your API key, add `VITE_VUE_PLACESELECTOR_API_KEY` to your env file with your API Key as the value |
| 111 | + |
| 112 | +```env |
| 113 | +VITE_VUE_PLACESELECTOR_API_KEY=ExampleApiKeyHere |
| 114 | +``` |
| 115 | + |
| 116 | +If you do not have an `env` file, you can pass the `api-key` prop to each component instance. |
| 117 | + |
| 118 | +```vue |
| 119 | +<template> |
| 120 | + <VuePlaceSelector |
| 121 | + api-key="ExampleApiKeyHere" |
| 122 | + v-model="form.city" |
| 123 | + :params="{ countries: form.country, states: form.state }" |
| 124 | + @error="console.log" |
| 125 | + /> |
| 126 | +</template> |
| 127 | +``` |
0 commit comments