@prolibu-suite/cobalt-form-vue 0.1.0 → 0.1.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.
- package/README.md +101 -0
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# @prolibu-suite/cobalt-form-vue
|
|
2
|
+
|
|
3
|
+
Adapter Vue 3 para los formularios schema-driven del **Cobalt Design System**. Composable `useForm()` + componente `<CoFormRenderer>` con todo el estado reactivo de Vue.
|
|
4
|
+
|
|
5
|
+
## Instalación
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @prolibu-suite/cobalt-form-vue @prolibu-suite/cobalt-core @prolibu-suite/cobalt-tokens
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
`cobalt-form-vue` arrastra `cobalt-form-core` y AJV automáticamente.
|
|
12
|
+
|
|
13
|
+
## Setup mínimo
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
// main.js — registrá los Web Components base
|
|
17
|
+
import { defineCustomElements } from '@prolibu-suite/cobalt-core/loader';
|
|
18
|
+
defineCustomElements(window);
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
// vite.config.js — Vue debe reconocer co-*
|
|
23
|
+
import vue from '@vitejs/plugin-vue';
|
|
24
|
+
|
|
25
|
+
export default {
|
|
26
|
+
plugins: [vue({
|
|
27
|
+
template: {
|
|
28
|
+
compilerOptions: { isCustomElement: (tag) => tag.startsWith('co-') }
|
|
29
|
+
}
|
|
30
|
+
})]
|
|
31
|
+
};
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```css
|
|
35
|
+
/* CSS global */
|
|
36
|
+
@import '@prolibu-suite/cobalt-tokens/css';
|
|
37
|
+
@import '@prolibu-suite/cobalt-tokens/css/dark';
|
|
38
|
+
@import '@prolibu-suite/cobalt-form-vue/style.css';
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Uso
|
|
42
|
+
|
|
43
|
+
```vue
|
|
44
|
+
<script setup>
|
|
45
|
+
import { useForm, CoFormRenderer } from '@prolibu-suite/cobalt-form-vue';
|
|
46
|
+
|
|
47
|
+
const form = useForm(() => ({
|
|
48
|
+
schema: {
|
|
49
|
+
modelSchema: {
|
|
50
|
+
email: { type: 'String', required: true, format: 'email' },
|
|
51
|
+
password: { type: 'String', required: true, minLength: 8 },
|
|
52
|
+
},
|
|
53
|
+
locale: 'es',
|
|
54
|
+
},
|
|
55
|
+
}));
|
|
56
|
+
|
|
57
|
+
function onSubmit({ values }) {
|
|
58
|
+
console.log('payload:', values);
|
|
59
|
+
}
|
|
60
|
+
</script>
|
|
61
|
+
|
|
62
|
+
<template>
|
|
63
|
+
<CoFormRenderer :form="form" @submit="onSubmit" />
|
|
64
|
+
</template>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## API · `useForm()`
|
|
68
|
+
|
|
69
|
+
Retorna refs reactivas:
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
const form = useForm(() => ({ schema, initialValues }));
|
|
73
|
+
|
|
74
|
+
form.values // Ref<Record<string, any>>
|
|
75
|
+
form.errors // Ref<Record<string, string[]>>
|
|
76
|
+
form.isValid // Ref<boolean>
|
|
77
|
+
form.touched // Ref<Record<string, boolean>>
|
|
78
|
+
|
|
79
|
+
form.setValue(name, value);
|
|
80
|
+
form.touch(name);
|
|
81
|
+
form.touchAll();
|
|
82
|
+
form.submit();
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Componentes de campo
|
|
86
|
+
|
|
87
|
+
Si necesitás un renderer custom, podés componer tus propios fields:
|
|
88
|
+
|
|
89
|
+
```vue
|
|
90
|
+
<script setup>
|
|
91
|
+
import { FieldText, FieldNumber, FieldSelect, FieldBoolean, FieldDate, FieldRef } from '@prolibu-suite/cobalt-form-vue';
|
|
92
|
+
</script>
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Documentación
|
|
96
|
+
|
|
97
|
+
→ [cobalt-docs/formularios](https://dev10.prolibu.com/ui/static/cobalt-docs/formularios/useform/) — `useForm()`, `CoFormRenderer`, ejemplos completos.
|
|
98
|
+
|
|
99
|
+
## License
|
|
100
|
+
|
|
101
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prolibu-suite/cobalt-form-vue",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Cobalt Form — Vue 3 adapter. useForm() composable + CoFormRenderer component.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"vue": "^3.0.0",
|
|
30
|
-
"@prolibu-suite/cobalt-core": "0.1.
|
|
30
|
+
"@prolibu-suite/cobalt-core": "0.1.1"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@prolibu-suite/cobalt-form-core": "0.1.
|
|
33
|
+
"@prolibu-suite/cobalt-form-core": "0.1.1"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@vitejs/plugin-vue": "^5.2.1",
|