0.0.8 • Published 11 months ago

@toby.mosque/quasar-ui-qdecimal v0.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Component QDecimal

npm npm

Compatible with Quasar UI v2 and Vue 3.

Component QDecimal

in short, QDecimal is a QInput powered by the Intl.NumberFormat

Usage

Quasar CLI project

Install the App Extension.

OR:

Create and register a boot file:

import Vue from 'vue'
import Plugin from '@toby.mosque/quasar-ui-qdecimal'
import '@toby.mosque/quasar-ui-qdecimal/dist/index.css'

Vue.use(Plugin)

OR:

<style src="@toby.mosque/quasar-ui-qdecimal/dist/index.css"></style>

<script>
import { Component as QDecimal } from '@toby.mosque/quasar-ui-qdecimal'

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

Vue CLI project

import Vue from 'vue'
import Plugin from '@toby.mosque/quasar-ui-qdecimal'
import '@toby.mosque/quasar-ui-qdecimal/dist/index.css'

Vue.use(Plugin)

OR:

<style src="@toby.mosque/quasar-ui-qdecimal/dist/index.css"></style>

<script>
import { Component as QDecimal } from '@toby.mosque/quasar-ui-qdecimal'

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

UMD variant

Exports window.qDecimal.

Add the following tag(s) after the Quasar ones:

<head>
  <!-- AFTER the Quasar stylesheet tags: -->
  <link href="https://cdn.jsdelivr.net/npm/@toby.mosque/quasar-ui-qdecimal/dist/index.min.css" rel="stylesheet" type="text/css">
</head>
<body>
  <!-- at end of body, AFTER Quasar script(s): -->
  <script src="https://cdn.jsdelivr.net/npm/@toby.mosque/quasar-ui-qdecimal/dist/index.umd.min.js"></script>
</body>

If you need the RTL variant of the CSS, then go for the following (instead of the above stylesheet link):

<link href="https://cdn.jsdelivr.net/npm/@toby.mosque/quasar-ui-qdecimal/dist/index.rtl.min.css" rel="stylesheet" type="text/css">

QInput similarities and differences

let's review the QInput description

The QInput component is used to capture text input from the user. It uses v-model, similar to a regular input. It has support for errors and validation, and comes in a variety of styles, colors, and types.

Similarities

everything what applies to the QInput also applies to the QDecimal, so let say you wanna to style the QDecimal as dense and filled and configure the append slot to show a icon, you can follow the QInput docs and do the same:

<template>
  <q-decimal filled dense v-model="number">
    <template v-slot:append>
      <q-avatar>
        <img src="https://cdn.quasar.dev/logo-v2/svg/logo.svg">
      </q-avatar>
    </template>
  </q-decimal>
</template>
<script setup lang="ts">
import { ref } from 'vue';

const number = ref(12.34);
</script>

Differences

QDecimal overrides the behavior of that 6 properties.

PropertyDetail
modelValuethe modelValue/v-model only accept number values, so you can't pass a string as you would do with the QInput.
typethe default value is tel instead of text, that ensures that a numerical keyboard will appear instead of the full one. I opted by the tel instead of the number because of the odd behaviors of the later one.
minmin will prevent the user to input values smaller than the expected.
maxmax will prevent the user to input values greater than the expected.
prefixwill also accept a boolean, if true, the prefix will depend of the combination of the mode, the currency and the display. e.g: if mode: currency, currency: EUR and display: symbol so the displayed preffix will be
suffixwill also accept a boolean, if true, the prefix will depend of the combination of the mode, the currency and the display. e.g: if mode: currency, currency: EUR and display: symbol so the displayed preffix will be

QDecimal additional properties

PropertyDefaultDetail
preset_defaultpreset is a preconfigure and reusable set of properties, for example, you can configure a preset called de-money with mode: 'currency' and places: 2, in this case, you set preset="money" instead of mode="currency" :places="2"
lang--A string with a BCP 47 language tag. e.g.: en-US, en, pt-BR, es. the default will be same as the quasar lang package.
modedecimalThe formatting style to use. possivel values: decimal, currency, percent or unit
currencymaxA string with the ISO 4217 currency codes. e.g.: USD, EUR or BRL.
displaysymbolHow to format the currency symbol. e.g.: symbol, narrowSymbol, code or name.
places--The maximum number of significant digits to use.
precision2The maximum number of fraction digits to use.
step1the values what would be increated when is pressed or decreased when is pressed.

Composables

We`d two composables who helps to configure the presets:

createPreset

createPreset allow the dev to create a new preset what can be used later.

type

interface PresetPayload {
  type?: string
  suffix?: string | boolean,
  prefix?: string | boolean,
  mode?: "decimal" | "currency" | "percent"
  currency?: string,
  display?: "symbol" | "code" | "name",
  places?: number,
  precision?: number,
  step?: number
}

export function createPreset(name: string, {
  type = 'tef',
  preffix = undefined,
  suffix = undefined,
  mode = 'decimal',
  currency = undefined,
  display = 'symbol',
  places = undefined,
  precision = 2,
  step = 1
}: PresetPayload = {}) {

}

usage

import { createPreset } from '@toby.mosque/quasar-ui-qdecimal'

createPreset('money', {
  preffix: true,
  mode: 'currency',
  currency: 'EUR',
})

usePreset

usePreset allow to modify a previously created preset.

type

import type { ToRefs } from 'vue'
interface PresetPayload {
  type?: string
  suffix?: string | boolean,
  prefix?: string | boolean,
  mode?: "decimal" | "currency" | "percent"
  currency?: string,
  display?: "symbol" | "code" | "name",
  places?: number,
  precision?: number,
  step?: number
}

export function usePreset(name: string) : ToRefs<PresetPayload> {

}

usage

<template>
  <q-form class="row q-col-gutter-sm">
    <div class="col">
      <q-select label="Mode" v-model="mode" :options="modes"></q-select>
    </div>
    <div class="col">
      <q-select label="Currency" v-model="currency" :options="currencies"></q-select>
    </div>
    <div class="col">
      <q-checkbox label="Preffix" v-model="preffix"></q-checkbox>
    </div>
    <div class="col">
      <q-decimal preset="money" v-model="number"></q-decimal>
    </div>
  <q-form>
</template>
<script setup lang="ts">
import { usePreset } from '@toby.mosque/quasar-ui-qdecimal'
import { ref } from 'vue'

const { preffix, mode, currency } = usePreset('money')
const modes = ['decimal', 'currency', 'percentage']
const currencies = ['EUR', 'USD', 'BRL']
const number = ref(12.34);
</script>

Setup

$ yarn

Developing

# start dev in SPA mode
$ yarn dev

# start dev in UMD mode
$ yarn dev:umd

# start dev in SSR mode
$ yarn dev:ssr

# start dev in Cordova iOS mode
$ yarn dev:ios

# start dev in Cordova Android mode
$ yarn dev:android

# start dev in Electron mode
$ yarn dev:electron

Building package

$ yarn build

Adding Testing Components

in the ui/dev/src/pages you can add Vue files to test your component/directive. When using yarn dev to build the UI, any pages in that location will automatically be picked up by dynamic routing and added to the test page.

Adding Assets

If you have a component that has assets, like language or icon-sets, you will need to provide these for UMD. In the ui/build/script.javascript.js file, you will find a couple of commented out commands that call addAssets. Uncomment what you need and add your assets to have them be built and put into the ui/dist folder.

Donate

If you appreciate the work that went into this, please consider donating to Quasar.

License

MIT (c) Tobias Mesquita tobias.mesquita@gmail.com

0.0.8

11 months ago

0.0.7

11 months ago

0.0.6

11 months ago

0.0.5

11 months ago

0.0.4

11 months ago

0.0.3

11 months ago

0.0.2

11 months ago

0.0.1

11 months ago