@indielayer/ui 0.2.0 → 0.2.1

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.
@@ -1,4 +1,4 @@
1
- import { ref, computed, watch } from 'vue'
1
+ import { ref, computed, inject, watch, onMounted, onUnmounted } from 'vue'
2
2
  import {
3
3
  withValidator as withInteractiveValidator,
4
4
  withProps as withInteractiveProps,
@@ -52,10 +52,21 @@ export const withEmits = (useListeners = true) => {
52
52
  }
53
53
 
54
54
  export const useInputtable = (props, { attrs, emit, useListeners = true } = {}) => {
55
+ const interactive = useInteractive()
56
+
55
57
  const isFirstValidation = ref(true)
56
58
  const errorInternal = ref(props.error)
57
59
 
60
+ const name = props.name ? props.name : (Math.random() + 1).toString(36).substring(7)
61
+ const nameInternal = ref(name)
62
+
58
63
  watch(() => props.error, (val) => { errorInternal.value = val })
64
+ watch(() => props.name, (val) => { if (val) nameInternal.value = val })
65
+
66
+ const form = inject('form', {
67
+ registerInput: () => {},
68
+ unregisterInput: () => {},
69
+ })
59
70
 
60
71
  const reset = () => {
61
72
  errorInternal.value = ''
@@ -63,7 +74,7 @@ export const useInputtable = (props, { attrs, emit, useListeners = true } = {})
63
74
  emit('update:modelValue', '')
64
75
  }
65
76
 
66
- const setErrorInternal = (val) => {
77
+ const setError = (val) => {
67
78
  errorInternal.value = val
68
79
  }
69
80
 
@@ -120,8 +131,16 @@ export const useInputtable = (props, { attrs, emit, useListeners = true } = {})
120
131
  }
121
132
  }) : ref({})
122
133
 
134
+ onMounted(() => {
135
+ form.registerInput(nameInternal.value, { focus: interactive.focus, validate, setError })
136
+ })
137
+
138
+ onUnmounted(() => {
139
+ form.unregisterInput(nameInternal.value)
140
+ })
141
+
123
142
  return {
124
- ...useInteractive(),
143
+ ...interactive,
125
144
 
126
145
  // data
127
146
  isFirstValidation,
@@ -133,6 +152,6 @@ export const useInputtable = (props, { attrs, emit, useListeners = true } = {})
133
152
  // methods
134
153
  reset,
135
154
  validate,
136
- setErrorInternal,
155
+ setError,
137
156
  }
138
157
  }
@@ -25,14 +25,12 @@ export const withValidator = () => validator
25
25
  export const useInteractive = () => {
26
26
  const focusRef = ref(null)
27
27
 
28
- const methods = {
29
- focus: () => {
30
- if (focusRef.value) focusRef.value.focus()
31
- },
28
+ const focus = () => {
29
+ if (focusRef.value) focusRef.value.focus()
32
30
  }
33
31
 
34
32
  return {
35
33
  focusRef,
36
- ...methods,
34
+ focus,
37
35
  }
38
36
  }
@@ -1,11 +0,0 @@
1
- 'use strict';
2
-
3
- var Colors_vue_vue_type_template_id_039e5c98_lang = require('./Colors.vue_vue_type_template_id_039e5c98_lang.js');
4
-
5
- const script = {};
6
-
7
-
8
- script.render = Colors_vue_vue_type_template_id_039e5c98_lang.render;
9
- var script$1 = script;
10
-
11
- module.exports = script$1;