npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-currency-select

v0.2.1

Published

Reusable currency-select dropdown component built in Vue, based on transferwise/tw-currency-select

Downloads

588

Readme

vue-currency-select

vue-currency-select is a reusable dropdown component for selecting currency, built with Vue 2. This project heavily referencing transferwise/tw-currency-select, with several differences in styles and framework used.

Note: This package will be updated with Vue 3 after Vue 3 is on stable channel, with Vue 2 backward compatibility

Install

npm install vue-currency-select
# or
yarn add vue-currency-select

Setup

You can use this component as Vue plugin or component itself:

With plugin

import vCurrencySelect from 'vue-currency-select';

Vue.use(vCurrencySelect);

With component

// e.g., in MyComponent.vue,

<script>
import vCurrencySelect from 'vue-currency-select';

export default {
  components: {
    vCurrencySelect
  }
}
</script>

Either you load it as individual component or plugin, you can use this component as html tag:

<v-currency-select></v-currency-select>

Usage

By default, vue-currency-select provides a default currency set of 43 countries. There are some optional props that you can use to customize more of its behavior, like v-model, label and so on:

| Prop Name | Type | Description | Example value | | ------------ | ------ | ------------- | ------------- | | label | String | Label for <select> element. <label> will not render if this prop is not provided | 'Select currency:' | | options | Array | Options array for <v-select />. If not provided, vue-currency-select will use its default options with 43 countries currency | [{ currency: 'MYR', country: 'MY' }, ...] | | value | String | Value of selected currency. To be used with v-model | 'MYR' | | selected-option-id | String | HTML id attr for selected option input. Most likely you won't use it, this prop exists just to be compatible with vanilla js project, so you can use DOM operation to directly query selected option | 'option-id' | show-deselect-btn | Boolean| Show or hide deselect button (the button showed on the right side of selected item). Default to false |

Example

With vue, default options and v-model two-way data binding (recommended)

<template>
  <v-currency-select
    label="Select currency:"
    v-model="selectedCurrency"
    @input-"selectChanged"
  ></v-currency-select>
</template>

<script>
export default {
  data() {
    return {
      selectedCurrency: ''
    };
  },
  methods: {
    // do something after selectedCurrency changed
    selectChanged() {
      console.log(this.selectedCurrency);
    }
  }
}
</script>

With partial vue, vanilla js and default options

<v-currency-select
  label="Select currency:"
  selected-option-id="selectedOptionId"
></v-currency-select>

<script>
  const selectedOption = document.querySelector('#selectedOptionId');
  console.log(selectedOption.innerText); // output selected option value
</script>

With partial vue, JQuery and default options

<v-currency-select
  label="Select currency:"
  selected-option-id="selectedOptionId"
></v-currency-select>

<script>
  console.log($('#selectedOptionId').text()); // output selected option value
</script>

With custom options (not recommended)

<script>
// first you have to create an options array that meet this component requirement
const customOptions = [
  {
    currency: 'EXP',
    country: 'EX'
  },
  // ... and so on
];
</script>

<v-currency-select
  label="Select currency:"
  options="customOptions"
>
</v-currency-select>

Unless you have a good reason to use custom options, it's way better to stick with default options, which is sufficient for most use case.

Local development setup

To develop vue-currency-select, run the following commands:

This project assume you installed Vue CLI.

Please note that vue-currency-select uses the following version of npm & node:

  • npm >= 6.13.4
  • node >= 12.16.1
npm install
# or
yarn install

Compiles and hot-reloads for development

npm run serve ./src/CurrencySelect.vue
# or
yarn serve ./src/CurrencySelect.vue

Compiles and minifies for production

npm run build
# or
yarn build

Lints and fixes files

npm run lint
# or
yarn lint

Packages

The main npm packages used in this project are the following:

License

MIT © 2020 Andy Tan