├── .gitignore ├── README.md ├── babel.config.js ├── package-lock.json ├── package.json └── src ├── App.vue ├── components ├── country-select.vue └── region-select.vue ├── data.js ├── index.js └── main.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | # local env files 6 | .env.local 7 | .env.*.local 8 | 9 | # Log files 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | 14 | # Editor directories and files 15 | .idea 16 | .vscode 17 | *.suo 18 | *.ntvs* 19 | *.njsproj 20 | *.sln 21 | *.sw* 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vue-Country-Region-Select ![CI status](https://img.shields.io/badge/build-passing-brightgreen.svg) 2 | 3 | Vue-Country-Region-Select provides a pair of Vue components that will allow you to easily put a country and region dropdown in your project that will work together or standalone. Supports vue-i18n. 4 | 5 | ## Installation 6 | `npm install vue-country-region-select --save` 7 | 8 | ## Dependencies 9 | Being that these are Vue components you will need to use them inside of Vue. 10 | 11 | The Data for the countries and regions are originally taken from: https://www.npmjs.com/package/country-region-data 12 | However the data set is now located in this project and is available to be edited to suit more countries and regions as you need. 13 | 14 | ## Usage 15 | Here is a sample use case of how you would use vue-country-region-select in your vue project. You can alternatively store the data in a store somewhere. Country and Region values will be returned in their short code values by default. 16 | 17 | Ex. country: 'US' and region: 'IL' 18 | 19 | There is a prop that will allow for country to be returned in full instead of in short code version. 20 | 21 | The library registers the components globally so only need to import the library once in order to make the components be available throughout your project. 22 | ```javascript 23 | // too be added before mounting app 24 | import Vue from 'vue' 25 | import vueCountryRegionSelect from 'vue-country-region-select' 26 | Vue.use(vueCountryRegionSelect) 27 | 28 | new Vue({}).$mount('#app') 29 | // end mounting app 30 | 31 | // then inside your vue components 32 | export default Vue.extend({ 33 | data: () => ({ 34 | country: '', 35 | region: '' 36 | }) 37 | }) 38 | 39 | 43 | ``` 44 | 45 | ## Options 46 | Here are the available attributes that can be used with the provided components. 47 | 48 | `````` 49 | 50 | Parameter | Required? | Default | Type | Description 51 | --------- | --------- | ------- | -------- | ---------- 52 | v-model | yes | ''| string | The data binding for your component 53 | country | yes | '' | string | Make this tied to the same piece of data as v-model 54 | topCountry | no | '' | string | By providing this value you will tell component what country to put at the top of the dropdown list for easy selection. Make sure to use country short code. So for United states you would provide 'US'. However, if you set countryName to true make sure to also write out full country name when setting a topCountry. In this scenerio United States would be 'United States'. 55 | countryName | no | false | boolean | By setting this value to true, country names will be output in full instead of using the abbreviated short codes. Make sure to set this true for both country and region if you are using. 56 | whiteList | no | [] | array | Fill this array with capitalized short codes of the countries you want to appear in the dropdown list. ex: ['US', 'CA', 'MX'] 57 | blackList | no | [] | array | Fill this array with capitalized short codes of the countries you want to remove from dropdown list. ex: ['US'] 58 | className | no | '' | string | Class name ex: `form-control` 59 | placeholder | no | 'Select Country' | string | The placeholder text for country select 60 | autocomplete | no | false | boolean | Set to true to enable browser to automatically fill out the country. 61 | shortCodeDropdown | no | false | boolean | Use this to have dropdown text display as short codes 62 | usei18n | no | true | boolean | Set to false if using i18n and want to disable for this component 63 | disablePlaceholder | no | false | boolean | Set to true to make placeholder non-selectable 64 | removePlaceholder | no | false | boolean | Set to true to remove placeholder all together, this will autoselect first in list automatically 65 | 66 | ``` ``` 67 | 68 | Parameter | Required? | Default | Type | Description 69 | --------- | --------- | ------- | -------- | ---------- 70 | v-model | yes | ''| string | The data binding for your component 71 | region | yes | '' | string | Make this tied to the same piece of data as v-model 72 | country | no | '' | string | This tells the component what country to grab the list of displayed regions from. To have it work in tandem with country component provide it the variable that is tied to the v-model of the country-select component. 73 | defaultRegion | no | 'US' | string | This allows you to set a default region when choosing not to use the country attribute. It will be set to regions of the United States if not provided. 74 | countryName | no | false | boolean | Set this to true if you are setting it to true while using Country Select. This is just to help keep the data values in sync. 75 | regionName | no | false | boolean | Set this to true if you want the v-model to output full region names instead of the default abbreviations. 76 | whiteList | no | [] | array | Fill this array with capitalized short codes of the regions you want to appear in the dropdown list. ex: ['AL', 'AK', 'WA'] 77 | blackList | no | [] | array | Fill this array with capitalized short codes of the regions you want to remove from dropdown list. ex: ['AZ'] 78 | className | no | '' | string | Class name ex: `form-control` 79 | placeholder | no | 'Select Region' | string | The placeholder text for region select 80 | autocomplete | no | false | boolean | Set to true to enable browser to automatically fill out the region. 81 | shortCodeDropdown | no | false | boolean | Use this to have dropdown text display as short codes 82 | usei18n | no | true | boolean | Set to false if using i18n and want to disable for this component 83 | disablePlaceholder | no | false | boolean | Set to true to make placeholder non-selectable, this will cause regions to set to first available when switching countries 84 | removePlaceholder | no | false | boolean | Set to true to remove placeholder all together, this will autoselect first in list automatically 85 | 86 | 87 | ## Contributing 88 | Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. 89 | 90 | ## License 91 | [MIT](https://choosealicense.com/licenses/mit/) 92 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/app' 4 | ] 5 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-country-region-select", 3 | "version": "2.0.16", 4 | "description": "A Country select component and Region select component for Vue.js. Work together and standalone.", 5 | "repository": "https://github.com/gehrj/vue-country-region-select", 6 | "author": "Justin Gehr ", 7 | "license": "MIT", 8 | "keywords": [ 9 | "vue-country-region-select", 10 | "vue-country-state-select", 11 | "vue country select", 12 | "vue region select", 13 | "vue", 14 | "select", 15 | "country", 16 | "region", 17 | "vue component", 18 | "component", 19 | "country select", 20 | "region select", 21 | "lightweight", 22 | "state select", 23 | "state", 24 | "vue state select", 25 | "country dropdown", 26 | "dropdown", 27 | "region dropdown", 28 | "state dropdown", 29 | "vue-country-region-dropdown", 30 | "vue-country-state-dropdown", 31 | "vue dropdown component", 32 | "country and state select" 33 | ], 34 | "private": false, 35 | "scripts": { 36 | "serve": "vue-cli-service serve", 37 | "build": "vue-cli-service build", 38 | "build-bundle": "vue-cli-service build --target lib --name vueCountryRegionSelect ./src/index.js", 39 | "test": "vue-cli-service test", 40 | "e2e": "vue-cli-service e2e", 41 | "lint": "vue-cli-service lint", 42 | "e2e:open": "vue-cli-service e2e:open" 43 | }, 44 | "files": [ 45 | "dist/vueCountryRegionSelect.umd.min.js" 46 | ], 47 | "main": "./dist/vueCountryRegionSelect.umd.min.js", 48 | "dependencies": { 49 | "vue": "^2.5.17" 50 | }, 51 | "devDependencies": { 52 | "@vue/cli-plugin-babel": "^3.6.0", 53 | "@vue/cli-plugin-eslint": "^3.0.5", 54 | "@vue/cli-service": "^3.6.0", 55 | "vue-template-compiler": "^2.5.17" 56 | }, 57 | "eslintConfig": { 58 | "root": true, 59 | "env": { 60 | "node": true 61 | }, 62 | "extends": [ 63 | "plugin:vue/essential", 64 | "eslint:recommended" 65 | ], 66 | "rules": {}, 67 | "parserOptions": { 68 | "parser": "babel-eslint" 69 | } 70 | }, 71 | "postcss": { 72 | "plugins": { 73 | "autoprefixer": {} 74 | } 75 | }, 76 | "browserslist": [ 77 | "> 1%", 78 | "last 2 versions", 79 | "not ie <= 8" 80 | ] 81 | } 82 | -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 27 | 28 | 38 | -------------------------------------------------------------------------------- /src/components/country-select.vue: -------------------------------------------------------------------------------- 1 | 123 | 124 | 132 | -------------------------------------------------------------------------------- /src/components/region-select.vue: -------------------------------------------------------------------------------- 1 | 121 | 122 | 129 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import CountrySelect from '@/components/country-select.vue' 2 | import RegionSelect from '@/components/region-select.vue' 3 | 4 | const install = function (Vue) { 5 | const components = { CountrySelect, RegionSelect } 6 | Object.keys(components).forEach(name => { 7 | Vue.component(name, components[name]) 8 | }) 9 | } 10 | 11 | const VueCountryRegionSelect = { CountrySelect, RegionSelect, install } 12 | 13 | export default VueCountryRegionSelect 14 | export { CountrySelect, RegionSelect } 15 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import App from './App.vue' 3 | 4 | Vue.config.productionTip = false 5 | 6 | new Vue({ 7 | render: h => h(App) 8 | }).$mount('#app') 9 | --------------------------------------------------------------------------------