@v1nt1248/3nclient-lib 0.1.36 → 0.1.37

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
@@ -2,7 +2,7 @@
2
2
  "name": "@v1nt1248/3nclient-lib",
3
3
  "license": "AGPL-3.0-or-later",
4
4
  "author": "v1nt1248",
5
- "version": "0.1.36",
5
+ "version": "0.1.37",
6
6
  "description": "Library for 3NWeb clients",
7
7
  "type": "module",
8
8
  "files": [
@@ -7,7 +7,7 @@ export interface Ui3nInputProps {
7
7
  autofocus?: boolean;
8
8
  icon?: string;
9
9
  iconColor?: string;
10
- rules?: Array<(v: string) => any>;
10
+ rules?: Array<(v: unknown) => boolean | string>;
11
11
  displayStateMode?: 'error' | 'success';
12
12
  displayStateWithIcon?: boolean;
13
13
  displayStateMessage?: string;
@@ -21,13 +21,16 @@ export interface Ui3nInputEmits {
21
21
  (event: 'blur', value: Event): void;
22
22
  (event: 'clear'): void;
23
23
  (event: 'change', value: string): void;
24
- (event: 'enter', value: {
25
- value: string;
26
- altKey: boolean;
27
- ctrlKey: boolean;
28
- shiftKey: boolean;
29
- metaKey: boolean;
30
- }): void;
24
+ (
25
+ event: 'enter',
26
+ value: {
27
+ value: string;
28
+ altKey: boolean;
29
+ ctrlKey: boolean;
30
+ shiftKey: boolean;
31
+ metaKey: boolean;
32
+ },
33
+ ): void;
31
34
  (event: 'escape', value: Event): void;
32
35
  (event: 'update:modelValue', value: string): void;
33
36
  (event: 'update:valid', value: boolean): void;
@@ -12,6 +12,7 @@ const $css = useCssModule();
12
12
 
13
13
  const inputElement = ref<HTMLInputElement | null>(null);
14
14
  const text = ref<string>('');
15
+ const isDirty = ref(false);
15
16
  const isFocused = ref(false);
16
17
  const errorMessage = ref('');
17
18
 
@@ -24,7 +25,7 @@ const cssIconColor = computed(() => {
24
25
  });
25
26
 
26
27
  const isValid = computed(() => {
27
- if (!text.value) {
28
+ if (!isDirty.value) {
28
29
  return true;
29
30
  }
30
31
 
@@ -37,7 +38,7 @@ const mainCssClasses = computed(() => {
37
38
  props.icon && val.push($css.withIcon);
38
39
  props.clearable && text.value && val.push($css.clearable);
39
40
  props.disabled && val.push($css.disabled);
40
- (!!errorMessage.value || props.displayStateMode === 'error') && val.push($css.error);
41
+ ((!!errorMessage.value && !isValid.value) || props.displayStateMode === 'error') && val.push($css.error);
41
42
  props.displayStateMode === 'success' && val.push($css.success);
42
43
 
43
44
  return val;
@@ -52,9 +53,9 @@ const iconCssClasses = computed(() => {
52
53
 
53
54
  const messageCssClasses = computed(() => {
54
55
  const val = [$css.ui3nInputFieldMessage];
55
- (errorMessage.value || (props.displayStateMode === 'error' && !!props.displayStateMessage))
56
- && val.push($css.ui3nInputErrorMessage);
57
- props.displayStateMode === 'success' && props.displayStateMessage && val.push($css.ui3nInputSuccessMessage);
56
+ (errorMessage.value || (props.displayStateMode === 'error' && !!props.displayStateMessage)) &&
57
+ val.push($css.ui3nInputErrorMessage);
58
+ props.displayStateMode === 'success' && props.displayStateMessage && val.push($css.ui3nInputSuccessMessage);
58
59
 
59
60
  return val;
60
61
  });
@@ -80,6 +81,7 @@ function onChange(event: Event) {
80
81
  function onInput(ev: Event) {
81
82
  const value = (ev.target as HTMLInputElement).value;
82
83
  text.value = value;
84
+ isDirty.value = true;
83
85
  validate(value);
84
86
  emits('update:modelValue', value);
85
87
  emits('input', value);
@@ -88,13 +90,15 @@ function onInput(ev: Event) {
88
90
  function onEnterKeydown(event: KeyboardEvent) {
89
91
  const { altKey, ctrlKey, metaKey, shiftKey, target } = event;
90
92
  const value = (target as HTMLInputElement).value;
93
+ isDirty.value = true;
91
94
  validate(value);
92
95
  emits('update:modelValue', value);
93
- emits('enter', { value , altKey, ctrlKey, metaKey, shiftKey });
96
+ emits('enter', { value, altKey, ctrlKey, metaKey, shiftKey });
94
97
  }
95
98
 
96
99
  function onEscapeKeydown(event: KeyboardEvent) {
97
100
  const value = (event.target as HTMLInputElement).value;
101
+ isDirty.value = true;
98
102
  validate(value);
99
103
  emits('update:modelValue', value);
100
104
  emits('escape', event);
@@ -102,6 +106,7 @@ function onEscapeKeydown(event: KeyboardEvent) {
102
106
 
103
107
  function clearValue() {
104
108
  text.value = '';
109
+ isDirty.value = false;
105
110
  validate('');
106
111
  emits('update:modelValue', '');
107
112
  emits('input', '');
@@ -123,6 +128,12 @@ function validate(text: string) {
123
128
  }
124
129
  }
125
130
 
131
+ defineExpose({
132
+ isDirty,
133
+ isFocused,
134
+ clearValue,
135
+ })
136
+
126
137
  onMounted(() => {
127
138
  if (props.autofocus && inputElement.value) {
128
139
  inputElement.value.focus();
@@ -142,7 +153,9 @@ watch(
142
153
 
143
154
  watch(
144
155
  () => isValid.value,
145
- val => emits('update:valid', val),
156
+ val => {
157
+ emits('update:valid', val);
158
+ },
146
159
  { immediate: true },
147
160
  );
148
161
  </script>
@@ -152,7 +165,10 @@ watch(
152
165
  ref="wrapperElement"
153
166
  :class="mainCssClasses"
154
167
  >
155
- <label v-if="label" :class="$style.ui3nInputLabel">
168
+ <label
169
+ v-if="label"
170
+ :class="$style.ui3nInputLabel"
171
+ >
156
172
  {{ label }}
157
173
  </label>
158
174
 
@@ -170,7 +186,7 @@ watch(
170
186
  @focusin="onFocus"
171
187
  @focusout="onBlur"
172
188
  @change="onChange"
173
- >
189
+ />
174
190
 
175
191
  <ui3n-icon
176
192
  v-if="icon"
@@ -202,7 +218,7 @@ watch(
202
218
  />
203
219
 
204
220
  <div
205
- v-if="errorMessage || displayStateMessage"
221
+ v-if="(isDirty && errorMessage) || (displayStateMode && displayStateMessage)"
206
222
  :class="messageCssClasses"
207
223
  >
208
224
  {{ errorMessage || displayStateMessage }}
@@ -314,7 +330,7 @@ watch(
314
330
  }
315
331
 
316
332
  &.ui3nInputSuccessMessage {
317
- color: var(--success-content-default)
333
+ color: var(--success-content-default);
318
334
  }
319
335
  }
320
336