toggle-components-library 1.13.1 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toggle-components-library",
3
- "version": "1.13.1",
3
+ "version": "1.14.0",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "serve": "vue-cli-service serve",
@@ -0,0 +1,158 @@
1
+ <template>
2
+ <div class="toggle-input-container" :class="{'toggle-input-is-invalid':isInvalid }" @click="focusClosestInput">
3
+ <label v-if="label" :for="name ? name : 'ToggleInputNumberUnit' " class="toggle-input-label" >
4
+ {{ label }}
5
+ </label>
6
+ <input
7
+ :name="name ? name : 'ToggleInputNumberUnit' "
8
+ :class="[ 'toggle-input', size]"
9
+ :placeholder="placeholder ? placeholder : '' "
10
+ :autocomplete="autocomplete ? 'on' : 'off' "
11
+ :required="required"
12
+ v-model="inputVal"
13
+ @blur="onBlur"
14
+ @focus="onFocus"
15
+ @keyup="onKeyup"
16
+ />
17
+ <label class="toggle-input-label-error" v-if="isInvalid" :for="name ? name : 'ToggleInputNumberUnit' ">
18
+ {{ errorMessage }}
19
+ </label>
20
+ </div>
21
+ </template>
22
+
23
+ <script>
24
+
25
+ import { mixins } from '../mixins/mixins'
26
+
27
+ export default {
28
+ mixins:[mixins],
29
+ props: {
30
+ value: {
31
+ type: [Number, String]
32
+ },
33
+ allowBlank:{
34
+ type:Boolean,
35
+ default:false
36
+ },
37
+ name: {
38
+ type: String,
39
+ default: "ToggleInputNumberUnit"
40
+ },
41
+ label: {
42
+ type: String,
43
+ required: false
44
+ },
45
+ placeholder: {
46
+ type: String,
47
+ required: false
48
+ },
49
+ autocomplete: {
50
+ type: Boolean,
51
+ default: true
52
+ },
53
+ size: {
54
+ type: String,
55
+ validator: function (value) {
56
+ return ['extra-small', 'small', 'medium', 'large', 'full'].indexOf(value) !== -1
57
+ }
58
+ },
59
+ required: {
60
+ type: Boolean,
61
+ default: false
62
+ },
63
+ isInvalid: {
64
+ type: Boolean,
65
+ default: false
66
+ },
67
+ errorMessage: {
68
+ type: String,
69
+ required: false
70
+ },
71
+ appendString: {
72
+ type: String,
73
+ required: false
74
+ },
75
+ prependString: {
76
+ type: String,
77
+ required: false
78
+ }
79
+ },
80
+
81
+ data() {
82
+ return {
83
+ inputActive: false
84
+ };
85
+ },
86
+ computed: {
87
+ inputVal: {
88
+ get() {
89
+ if (this.inputActive) {
90
+ if((this.value === '' || this.value === null) && this.allowBlank)
91
+ return '';
92
+
93
+ return this.value;
94
+ } else {
95
+ if(this.value === '' || this.value == null || this.value === 0)
96
+ return '';
97
+
98
+ return this.value;
99
+ }
100
+ },
101
+ set(modifiedValue) {
102
+ this.$emit('input', modifiedValue);
103
+ }
104
+ },
105
+ appendStringLength() {
106
+ return this.appendString.length ?? 0;
107
+ },
108
+ prependStringLength() {
109
+ return this.prependString.length ?? 0;
110
+ }
111
+ },
112
+ methods: {
113
+ onKeyup() {
114
+ // Remove any non-numbers from the input value
115
+ this.$emit('input', this.value.replace(/[^0-9]/g,''))
116
+ },
117
+
118
+ onFocus() {
119
+ this.inputActive = true;
120
+ // When the user clicks in the box, remove the append and/or prepend values
121
+ if ((this.value != 0) && (this.value != '')) {
122
+ let tempValue = this.value;
123
+ if (this.appendString) {
124
+ // First take off the appended string
125
+ tempValue = this.value.slice(0, -this.appendStringLength)
126
+ }
127
+ if (this.prependString) {
128
+ // Then take off the prepended string
129
+ tempValue = tempValue.slice(this.prependStringLength, this.value.length)
130
+ }
131
+ this.$emit('input', tempValue);
132
+ }
133
+ },
134
+
135
+ onBlur(){
136
+ this.inputActive = false;
137
+
138
+ // Don't add the unit if the value is left empty
139
+ if (this.value != '') {
140
+ // When the user clicks out of the box, add the prepend and/or append values
141
+ let tempValue = this.value;
142
+ if (this.appendString) {
143
+ // First add the append string
144
+ tempValue += this.appendString;
145
+ }
146
+ if (this.prependString) {
147
+ // Then add the prepend string
148
+ tempValue = this.prependString + tempValue;
149
+ }
150
+ this.$emit('input', tempValue)
151
+ }
152
+ },
153
+ }
154
+ }
155
+
156
+
157
+
158
+ </script>
package/src/index.js CHANGED
@@ -51,6 +51,8 @@ import ToggleInfoText from "./components/text/ToggleInfoText.vue";
51
51
 
52
52
  import ToggleFontPicker from "./components/forms/ToggleFontPicker.vue";
53
53
 
54
+ import ToggleInputNumberUnit from "./components/forms/ToggleInputNumberUnit.vue";
55
+
54
56
  import './sass/main.scss';
55
57
 
56
58
  const Components = {
@@ -95,7 +97,8 @@ const Components = {
95
97
  ToggleHelperTextSmall,
96
98
  ToggleInfoText,
97
99
  ToggleInternationalPhoneInputSelect,
98
- ToggleFontPicker
100
+ ToggleFontPicker,
101
+ ToggleInputNumberUnit
99
102
  }
100
103
 
101
104
  Object.keys(Components).forEach(name => {