@farm-investimentos/front-mfe-components 12.2.1 → 12.2.3
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/dist/front-mfe-components.common.js +404 -284
- package/dist/front-mfe-components.common.js.map +1 -1
- package/dist/front-mfe-components.css +1 -1
- package/dist/front-mfe-components.umd.js +404 -284
- package/dist/front-mfe-components.umd.js.map +1 -1
- package/dist/front-mfe-components.umd.min.js +1 -1
- package/dist/front-mfe-components.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/src/components/AlertBox/AlertBox.stories.js +14 -0
- package/src/components/AlertBox/AlertBox.vue +11 -1
- package/src/components/AlertBox/__tests__/valueWatcher.spec.js +15 -0
- package/src/components/AlertBox/valueWatcher.ts +10 -0
- package/src/components/Buttons/DefaultButton/DefaultButton.scss +24 -9
- package/src/components/Buttons/DefaultButton/DefaultButton.stories.js +3 -3
- package/src/components/Checkbox/Checkbox.vue +29 -43
- package/src/components/Checkbox/__tests__/modelValueWatcher.spec.js +43 -0
- package/src/components/Checkbox/modelValueWatcher.ts +12 -0
- package/src/components/ContextMenu/ContextMenu.vue +3 -2
- package/src/components/Select/Select.stories.js +5 -1
- package/src/components/Select/Select.vue +18 -7
- package/src/components/TextArea/TextArea.vue +12 -1
- package/src/components/TextFieldV2/TextFieldV2.stories.js +4 -1
- package/src/components/TextFieldV2/TextFieldV2.vue +12 -0
- package/src/helpers/randomId.ts +9 -0
package/package.json
CHANGED
|
@@ -62,3 +62,17 @@ export const Colors = () => ({
|
|
|
62
62
|
<farm-alertbox class="mt-3" v-for="color of colors" :key="'random_10_' + color" :color="color" icon="book" dismissable>alert box</farm-alertbox>
|
|
63
63
|
</div> `,
|
|
64
64
|
});
|
|
65
|
+
|
|
66
|
+
export const withDismissableShowAgain = () => ({
|
|
67
|
+
data() {
|
|
68
|
+
return {
|
|
69
|
+
v: true,
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
template: `<div>
|
|
73
|
+
<farm-alertbox v-model="v" dismissable>alert box</farm-alertbox>
|
|
74
|
+
<farm-btn v-if="!v" @click="v = true;">
|
|
75
|
+
show
|
|
76
|
+
</farm-btn>
|
|
77
|
+
</div>`,
|
|
78
|
+
});
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
|
|
45
45
|
<script lang="ts">
|
|
46
46
|
import Vue, { ref, PropType } from 'vue';
|
|
47
|
+
import valueWatcher from './valueWatcher';
|
|
47
48
|
|
|
48
49
|
export default Vue.extend({
|
|
49
50
|
name: 'farm-alertbox',
|
|
@@ -87,20 +88,29 @@ export default Vue.extend({
|
|
|
87
88
|
>,
|
|
88
89
|
default: 'primary',
|
|
89
90
|
},
|
|
91
|
+
value: {
|
|
92
|
+
type: Boolean,
|
|
93
|
+
default: true,
|
|
94
|
+
},
|
|
90
95
|
},
|
|
91
|
-
setup() {
|
|
96
|
+
setup(props, { emit }) {
|
|
92
97
|
const visible = ref(true);
|
|
93
98
|
|
|
94
99
|
function close() {
|
|
95
100
|
visible.value = false;
|
|
101
|
+
emit('input', false);
|
|
96
102
|
}
|
|
97
103
|
|
|
104
|
+
valueWatcher(props, visible);
|
|
105
|
+
|
|
98
106
|
return {
|
|
99
107
|
visible,
|
|
100
108
|
close,
|
|
101
109
|
};
|
|
102
110
|
},
|
|
103
111
|
});
|
|
112
|
+
|
|
113
|
+
|
|
104
114
|
</script>
|
|
105
115
|
<style lang="scss" scoped>
|
|
106
116
|
@import './AlertBox';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ref, reactive } from 'vue';
|
|
2
|
+
import valueWatcher from '../valueWatcher';
|
|
3
|
+
|
|
4
|
+
describe('valueWatcher', () => {
|
|
5
|
+
it('Should change value for visible', done => {
|
|
6
|
+
const visible = ref(false);
|
|
7
|
+
const mockProps = reactive({ value: false });
|
|
8
|
+
valueWatcher(mockProps, visible);
|
|
9
|
+
mockProps.value = true;
|
|
10
|
+
setTimeout(() => {
|
|
11
|
+
expect(visible.value).toBeTruthy();
|
|
12
|
+
done();
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
@import '../../../configurations/variables';
|
|
2
2
|
@import '../../../configurations/mixins';
|
|
3
3
|
@import '../../../configurations/theme-colors';
|
|
4
|
+
$butonSizes: (
|
|
5
|
+
"xs": 12px,
|
|
6
|
+
"sm": 16px,
|
|
7
|
+
"md": 24px,
|
|
8
|
+
"lg": 48px,
|
|
9
|
+
"xl": 56px,
|
|
10
|
+
'default': 36px,
|
|
11
|
+
);
|
|
4
12
|
|
|
5
13
|
.farm-btn {
|
|
6
14
|
font-size: 14px;
|
|
@@ -29,9 +37,11 @@
|
|
|
29
37
|
width: 100%;
|
|
30
38
|
}
|
|
31
39
|
|
|
32
|
-
@each $size,
|
|
40
|
+
@each $size,
|
|
41
|
+
$value in $sizes {
|
|
33
42
|
&#{'.farm-btn[size=' + $size + ']'} {
|
|
34
43
|
font-size: $value;
|
|
44
|
+
height: map-get($butonSizes, $size);
|
|
35
45
|
}
|
|
36
46
|
}
|
|
37
47
|
|
|
@@ -95,6 +105,7 @@
|
|
|
95
105
|
|
|
96
106
|
&.farm-btn--plain {
|
|
97
107
|
background-color: transparent !important;
|
|
108
|
+
|
|
98
109
|
&:hover {
|
|
99
110
|
.farm-btn__content {
|
|
100
111
|
opacity: 0.68;
|
|
@@ -125,7 +136,8 @@
|
|
|
125
136
|
color: gray;
|
|
126
137
|
}
|
|
127
138
|
|
|
128
|
-
@each $size,
|
|
139
|
+
@each $size,
|
|
140
|
+
$value in $sizes {
|
|
129
141
|
&#{'.farm-btn[size=' + $size + ']'} {
|
|
130
142
|
font-size: $value;
|
|
131
143
|
}
|
|
@@ -160,15 +172,18 @@
|
|
|
160
172
|
background-color: var(--farm-#{$color}-base);
|
|
161
173
|
color: white;
|
|
162
174
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
175
|
+
&:not(.farm-btn--outlined):not(.farm-btn--plain):not(.farm-btn--icon) {
|
|
176
|
+
::v-deep .farm-btn__content {
|
|
177
|
+
i.mdi {
|
|
178
|
+
color: white;
|
|
179
|
+
}
|
|
167
180
|
|
|
168
|
-
|
|
169
|
-
|
|
181
|
+
.farm-btn__content i.mdi {
|
|
182
|
+
color: black;
|
|
183
|
+
}
|
|
170
184
|
}
|
|
171
185
|
}
|
|
186
|
+
|
|
172
187
|
}
|
|
173
188
|
|
|
174
189
|
.farm-btn--extra,
|
|
@@ -248,4 +263,4 @@
|
|
|
248
263
|
width: 100%;
|
|
249
264
|
margin: 0;
|
|
250
265
|
}
|
|
251
|
-
}
|
|
266
|
+
}
|
|
@@ -172,17 +172,17 @@ export const Icons = () => ({
|
|
|
172
172
|
template: `<div class="buttons-container">
|
|
173
173
|
<h4>Full</h4>
|
|
174
174
|
<farm-btn v-for="color of colors":key="'random_3_' + color" :color="color">
|
|
175
|
-
|
|
175
|
+
<farm-icon>book</farm-icon> book
|
|
176
176
|
</farm-btn>
|
|
177
177
|
|
|
178
178
|
<h4>Outlined</h4>
|
|
179
179
|
<farm-btn v-for="color of colors":key="color + 'outlined'" :color="color" outlined>
|
|
180
|
-
|
|
180
|
+
<farm-icon>book</farm-icon> book
|
|
181
181
|
</farm-btn>
|
|
182
182
|
|
|
183
183
|
<h4>Plain</h4>
|
|
184
184
|
<farm-btn v-for="color of colors":key="color + 'plain'" :color="color" plain>
|
|
185
|
-
|
|
185
|
+
<farm-icon color="primary">book</farm-icon> book
|
|
186
186
|
</farm-btn>
|
|
187
187
|
|
|
188
188
|
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="farm-checkbox__container" :color="$props.color">
|
|
3
|
-
<span
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
<span
|
|
4
|
+
:class="{
|
|
5
|
+
'farm-checkbox': true,
|
|
6
|
+
'farm-checkbox--checked': isChecked,
|
|
7
|
+
'farm-checkbox--disabled': disabled,
|
|
8
|
+
'farm-checkbox--indeterminate': indeterminate,
|
|
9
|
+
'farm-checkbox--lighten': variation === 'lighten',
|
|
10
|
+
'farm-checkbox--darken': variation === 'darken',
|
|
11
|
+
'farm-checkbox--error': showError,
|
|
12
|
+
}"
|
|
13
|
+
:size="$props.size"
|
|
14
|
+
@click="toggleValue"
|
|
15
|
+
>
|
|
12
16
|
<farm-icon :size="$props.size" v-if="innerValue && !indeterminate">check</farm-icon>
|
|
13
17
|
<farm-icon :size="$props.size" v-if="indeterminate">minus</farm-icon>
|
|
14
18
|
</span>
|
|
@@ -24,6 +28,7 @@ import validateFormStateBuilder from '../../composition/validateFormStateBuilder
|
|
|
24
28
|
import validateFormFieldBuilder from '../../composition/validateFormFieldBuilder';
|
|
25
29
|
import validateFormMethodBuilder from '../../composition/validateFormMethodBuilder';
|
|
26
30
|
import deepEqual from '../../composition/deepEqual';
|
|
31
|
+
import modelValueWatcher from './modelValueWatcher';
|
|
27
32
|
|
|
28
33
|
export default Vue.extend({
|
|
29
34
|
name: 'farm-checkbox',
|
|
@@ -100,46 +105,15 @@ export default Vue.extend({
|
|
|
100
105
|
return false;
|
|
101
106
|
}
|
|
102
107
|
isTouched.value = true;
|
|
103
|
-
|
|
104
|
-
innerValue.value = null;
|
|
105
|
-
} else {
|
|
106
|
-
innerValue.value = props.value;
|
|
107
|
-
}
|
|
108
|
+
innerValue.value = isChecked.value ? null : props.value;
|
|
108
109
|
emit('input', innerValue.value);
|
|
109
110
|
validate(innerValue.value);
|
|
110
111
|
};
|
|
111
112
|
|
|
112
|
-
const isChecked = computed(() =>
|
|
113
|
-
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
const hasError = computed(() => {
|
|
117
|
-
return errorBucket.value.length > 0;
|
|
118
|
-
});
|
|
119
|
-
|
|
113
|
+
const isChecked = computed(() => innerValue.value == props.value);
|
|
114
|
+
const hasError = computed(() => errorBucket.value.length > 0);
|
|
120
115
|
const showError = computed(() => hasError.value && isTouched.value);
|
|
121
116
|
|
|
122
|
-
|
|
123
|
-
watch(
|
|
124
|
-
() => props.modelValue,
|
|
125
|
-
(newValue) => {
|
|
126
|
-
isTouched.value = true;
|
|
127
|
-
innerValue.value = newValue;
|
|
128
|
-
validate(innerValue.value);
|
|
129
|
-
}
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
watch(
|
|
134
|
-
() => props.rules,
|
|
135
|
-
(newVal, oldVal) => {
|
|
136
|
-
if (deepEqual(newVal, oldVal)) return;
|
|
137
|
-
fieldValidator = validateFormFieldBuilder(rules.value);
|
|
138
|
-
validate = validateFormMethodBuilder(errorBucket, valid, fieldValidator);
|
|
139
|
-
validate(innerValue.value);
|
|
140
|
-
}
|
|
141
|
-
);
|
|
142
|
-
|
|
143
117
|
const reset = () => {
|
|
144
118
|
if (disabled.value) {
|
|
145
119
|
return false;
|
|
@@ -160,6 +134,18 @@ export default Vue.extend({
|
|
|
160
134
|
isTouched.value = false;
|
|
161
135
|
};
|
|
162
136
|
|
|
137
|
+
modelValueWatcher(props, isTouched, innerValue, validate);
|
|
138
|
+
|
|
139
|
+
watch(
|
|
140
|
+
() => props.rules,
|
|
141
|
+
(newVal, oldVal) => {
|
|
142
|
+
if (deepEqual(newVal, oldVal)) return;
|
|
143
|
+
fieldValidator = validateFormFieldBuilder(rules.value);
|
|
144
|
+
validate = validateFormMethodBuilder(errorBucket, valid, fieldValidator);
|
|
145
|
+
validate(innerValue.value);
|
|
146
|
+
}
|
|
147
|
+
);
|
|
148
|
+
|
|
163
149
|
return {
|
|
164
150
|
innerValue,
|
|
165
151
|
label,
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ref, reactive } from 'vue';
|
|
2
|
+
import modelValueWatcher from '../modelValueWatcher.ts';
|
|
3
|
+
|
|
4
|
+
describe('modelValueWatcher', () => {
|
|
5
|
+
let props;
|
|
6
|
+
let isTouched;
|
|
7
|
+
let innerValue;
|
|
8
|
+
let validate;
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
props = reactive({
|
|
12
|
+
modelValue: 'initial value',
|
|
13
|
+
});
|
|
14
|
+
isTouched = ref(false);
|
|
15
|
+
innerValue = ref('');
|
|
16
|
+
validate = jest.fn();
|
|
17
|
+
modelValueWatcher(props, isTouched, innerValue, validate);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should set isTouched.value to true when props.modelValue changes', done => {
|
|
21
|
+
props.modelValue = 'new value';
|
|
22
|
+
setTimeout(() => {
|
|
23
|
+
expect(isTouched.value).toBe(true);
|
|
24
|
+
done();
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should update innerValue.value with new props.modelValue', done => {
|
|
29
|
+
props.modelValue = 'new value';
|
|
30
|
+
setTimeout(() => {
|
|
31
|
+
expect(innerValue.value).toBe('new value');
|
|
32
|
+
done();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('should call validate function with new innerValue.value', done => {
|
|
37
|
+
props.modelValue = 'new value';
|
|
38
|
+
setTimeout(() => {
|
|
39
|
+
expect(validate).toHaveBeenCalledWith('new value');
|
|
40
|
+
done();
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Ref, watch } from 'vue';
|
|
2
|
+
|
|
3
|
+
export default function (props, isTouched: Ref, innerValue: Ref, validate: Function) {
|
|
4
|
+
watch(
|
|
5
|
+
() => props.modelValue,
|
|
6
|
+
newValue => {
|
|
7
|
+
isTouched.value = true;
|
|
8
|
+
innerValue.value = newValue;
|
|
9
|
+
validate(innerValue.value);
|
|
10
|
+
}
|
|
11
|
+
);
|
|
12
|
+
}
|
|
@@ -70,9 +70,10 @@ export default Vue.extend({
|
|
|
70
70
|
|
|
71
71
|
let hasBeenBoostrapped = false;
|
|
72
72
|
|
|
73
|
-
const outClick =
|
|
73
|
+
const outClick = event => {
|
|
74
|
+
const path = event.path || (event.composedPath && event.composedPath());
|
|
74
75
|
const isInside =
|
|
75
|
-
|
|
76
|
+
path.some((e: HTMLElement) => {
|
|
76
77
|
if (e.classList) {
|
|
77
78
|
return e.classList.contains('farm-contextmenu__popup--visible');
|
|
78
79
|
}
|
|
@@ -35,8 +35,12 @@ export const Primary = () => ({
|
|
|
35
35
|
};
|
|
36
36
|
},
|
|
37
37
|
template: `<div style="width: 120px;">
|
|
38
|
-
<farm-
|
|
38
|
+
<farm-label for="select_id">
|
|
39
|
+
label
|
|
40
|
+
</farm-label>
|
|
41
|
+
<farm-select id="select_id" v-model="v" :items="items" />
|
|
39
42
|
v-model: {{ v }}
|
|
43
|
+
|
|
40
44
|
</div>`,
|
|
41
45
|
});
|
|
42
46
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div
|
|
3
|
-
class="farm-textfield"
|
|
4
3
|
:class="{
|
|
5
4
|
'farm-textfield': true,
|
|
6
5
|
'farm-textfield--validatable': rules.length > 0,
|
|
@@ -11,8 +10,9 @@
|
|
|
11
10
|
'farm-textfield--hiddendetails': hideDetails,
|
|
12
11
|
}"
|
|
13
12
|
v-if="!readonly && !disabled"
|
|
13
|
+
:id="customId"
|
|
14
14
|
>
|
|
15
|
-
<farm-contextmenu bottom v-model="isVisible" :stay-open="multiple">
|
|
15
|
+
<farm-contextmenu bottom v-model="isVisible" :stay-open="multiple" ref="contextmenu">
|
|
16
16
|
<farm-list v-if="!readonly">
|
|
17
17
|
<farm-listitem
|
|
18
18
|
v-for="(item, index) in items"
|
|
@@ -29,15 +29,15 @@
|
|
|
29
29
|
value="1"
|
|
30
30
|
size="sm"
|
|
31
31
|
v-if="isChecked(item)"
|
|
32
|
-
|
|
32
|
+
/>
|
|
33
33
|
<farm-checkbox
|
|
34
34
|
class="farm-select__checkbox"
|
|
35
35
|
v-model="checked"
|
|
36
36
|
value="2"
|
|
37
37
|
size="sm"
|
|
38
38
|
v-else-if="multiple"
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
/>
|
|
40
|
+
<farm-caption bold tag="span">{{ item[itemText] }}</farm-caption>
|
|
41
41
|
</farm-listitem>
|
|
42
42
|
<farm-listitem v-if="!items || items.length === 0">
|
|
43
43
|
{{ noDataText }}
|
|
@@ -46,9 +46,9 @@
|
|
|
46
46
|
<template v-slot:activator="{}">
|
|
47
47
|
<div class="farm-textfield--input farm-textfield--input--iconed">
|
|
48
48
|
<input
|
|
49
|
+
v-bind="$attrs"
|
|
50
|
+
:id="$props.id"
|
|
49
51
|
v-model="selectedText"
|
|
50
|
-
:disabled="disabled"
|
|
51
|
-
:readonly="true"
|
|
52
52
|
@click="clickInput"
|
|
53
53
|
@keyup="onKeyUp"
|
|
54
54
|
@blur="onBlur"
|
|
@@ -75,6 +75,7 @@ import validateFormStateBuilder from '../../composition/validateFormStateBuilder
|
|
|
75
75
|
import validateFormFieldBuilder from '../../composition/validateFormFieldBuilder';
|
|
76
76
|
import validateFormMethodBuilder from '../../composition/validateFormMethodBuilder';
|
|
77
77
|
import deepEqual from '../../composition/deepEqual';
|
|
78
|
+
import randomId from '../../helpers/randomId';
|
|
78
79
|
|
|
79
80
|
export default Vue.extend({
|
|
80
81
|
name: 'farm-select',
|
|
@@ -152,6 +153,13 @@ export default Vue.extend({
|
|
|
152
153
|
type: Boolean,
|
|
153
154
|
default: false,
|
|
154
155
|
},
|
|
156
|
+
/**
|
|
157
|
+
* Select id
|
|
158
|
+
*/
|
|
159
|
+
id: {
|
|
160
|
+
type: String,
|
|
161
|
+
default: '',
|
|
162
|
+
},
|
|
155
163
|
},
|
|
156
164
|
setup(props, { emit }) {
|
|
157
165
|
const { rules, items, itemText, itemValue, disabled, multiple } = toRefs(props);
|
|
@@ -173,6 +181,8 @@ export default Vue.extend({
|
|
|
173
181
|
return errorBucket.value.length > 0;
|
|
174
182
|
});
|
|
175
183
|
|
|
184
|
+
const customId = 'farm-select-' + (props.id || randomId(2));
|
|
185
|
+
|
|
176
186
|
const showErrorText = computed(() => hasError.value && isTouched.value);
|
|
177
187
|
|
|
178
188
|
watch(
|
|
@@ -334,6 +344,7 @@ export default Vue.extend({
|
|
|
334
344
|
isTouched,
|
|
335
345
|
isBlured,
|
|
336
346
|
isVisible,
|
|
347
|
+
customId,
|
|
337
348
|
showErrorText,
|
|
338
349
|
validate,
|
|
339
350
|
reset,
|
|
@@ -17,8 +17,9 @@
|
|
|
17
17
|
}"
|
|
18
18
|
>
|
|
19
19
|
<textarea
|
|
20
|
-
v-bind="$attrs"
|
|
21
20
|
v-model="innerValue"
|
|
21
|
+
v-bind="$attrs"
|
|
22
|
+
:id="$props.id"
|
|
22
23
|
:rows="$props.rows"
|
|
23
24
|
:disabled="disabled"
|
|
24
25
|
:readonly="readonly"
|
|
@@ -42,6 +43,7 @@ import validateFormStateBuilder from '../../composition/validateFormStateBuilder
|
|
|
42
43
|
import validateFormFieldBuilder from '../../composition/validateFormFieldBuilder';
|
|
43
44
|
import validateFormMethodBuilder from '../../composition/validateFormMethodBuilder';
|
|
44
45
|
import deepEqual from '../../composition/deepEqual';
|
|
46
|
+
import randomId from '../../helpers/randomId';
|
|
45
47
|
|
|
46
48
|
export default Vue.extend({
|
|
47
49
|
name: 'farm-textarea',
|
|
@@ -95,6 +97,13 @@ export default Vue.extend({
|
|
|
95
97
|
type: Boolean,
|
|
96
98
|
default: false,
|
|
97
99
|
},
|
|
100
|
+
/**
|
|
101
|
+
* Select id
|
|
102
|
+
*/
|
|
103
|
+
id: {
|
|
104
|
+
type: String,
|
|
105
|
+
default: '',
|
|
106
|
+
},
|
|
98
107
|
},
|
|
99
108
|
setup(props, { emit }) {
|
|
100
109
|
const { rules } = toRefs(props);
|
|
@@ -109,6 +118,7 @@ export default Vue.extend({
|
|
|
109
118
|
const hasError = computed(() => {
|
|
110
119
|
return errorBucket.value.length > 0;
|
|
111
120
|
});
|
|
121
|
+
const customId = 'farm-textarea-' + (props.id || randomId(2));
|
|
112
122
|
|
|
113
123
|
const showErrorText = computed(() => hasError.value && isTouched.value);
|
|
114
124
|
|
|
@@ -171,6 +181,7 @@ export default Vue.extend({
|
|
|
171
181
|
valid,
|
|
172
182
|
validatable,
|
|
173
183
|
hasError,
|
|
184
|
+
customId,
|
|
174
185
|
isTouched,
|
|
175
186
|
isBlured,
|
|
176
187
|
showErrorText,
|
|
@@ -39,7 +39,10 @@ export const Primary = () => ({
|
|
|
39
39
|
};
|
|
40
40
|
},
|
|
41
41
|
template: `<div style="width: 480px;">
|
|
42
|
-
<farm-
|
|
42
|
+
<farm-label for="select_label">
|
|
43
|
+
label
|
|
44
|
+
</farm-label>
|
|
45
|
+
<farm-textfield-v2 id="select_label" v-model="v" />
|
|
43
46
|
v-model: {{ v }}
|
|
44
47
|
</div>`,
|
|
45
48
|
});
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
'farm-textfield--disabled': disabled,
|
|
11
11
|
'farm-textfield--hiddendetails': hideDetails,
|
|
12
12
|
}"
|
|
13
|
+
:id="customId"
|
|
13
14
|
>
|
|
14
15
|
<div
|
|
15
16
|
:class="{
|
|
@@ -28,6 +29,7 @@
|
|
|
28
29
|
v-bind="$attrs"
|
|
29
30
|
v-model="innerValue"
|
|
30
31
|
v-mask="mask"
|
|
32
|
+
:id="$props.id"
|
|
31
33
|
:disabled="disabled"
|
|
32
34
|
:readonly="readonly"
|
|
33
35
|
@click="$emit('click')"
|
|
@@ -61,6 +63,7 @@ import validateFormStateBuilder from '../../composition/validateFormStateBuilder
|
|
|
61
63
|
import validateFormFieldBuilder from '../../composition/validateFormFieldBuilder';
|
|
62
64
|
import validateFormMethodBuilder from '../../composition/validateFormMethodBuilder';
|
|
63
65
|
import deepEqual from '../../composition/deepEqual';
|
|
66
|
+
import randomId from '../../helpers/randomId';
|
|
64
67
|
|
|
65
68
|
export default Vue.extend({
|
|
66
69
|
name: 'farm-textfield-v2',
|
|
@@ -125,6 +128,13 @@ export default Vue.extend({
|
|
|
125
128
|
type: Boolean,
|
|
126
129
|
default: false,
|
|
127
130
|
},
|
|
131
|
+
/**
|
|
132
|
+
* Input id
|
|
133
|
+
*/
|
|
134
|
+
id: {
|
|
135
|
+
type: String,
|
|
136
|
+
default: '',
|
|
137
|
+
},
|
|
128
138
|
},
|
|
129
139
|
setup(props, { emit }) {
|
|
130
140
|
const { rules } = toRefs(props);
|
|
@@ -139,6 +149,7 @@ export default Vue.extend({
|
|
|
139
149
|
const hasError = computed(() => {
|
|
140
150
|
return errorBucket.value.length > 0;
|
|
141
151
|
});
|
|
152
|
+
const customId = 'farm-textfield-' + (props.id || randomId(2));
|
|
142
153
|
|
|
143
154
|
const showErrorText = computed(() => hasError.value && isTouched.value);
|
|
144
155
|
|
|
@@ -201,6 +212,7 @@ export default Vue.extend({
|
|
|
201
212
|
valid,
|
|
202
213
|
validatable,
|
|
203
214
|
hasError,
|
|
215
|
+
customId,
|
|
204
216
|
isTouched,
|
|
205
217
|
isBlured,
|
|
206
218
|
showErrorText,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default (length: number) => {
|
|
2
|
+
let text = '';
|
|
3
|
+
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
4
|
+
|
|
5
|
+
for (let i = 0; i < length; i++) {
|
|
6
|
+
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
7
|
+
}
|
|
8
|
+
return text;
|
|
9
|
+
};
|