@charpente-ui/vue 2.2.1 → 2.3.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/README.md +14 -3
- package/dist/components/BaseField.d.ts +4 -1
- package/dist/components/BaseField.js +28 -25
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -249,7 +249,9 @@ messages for free. Charpente UI exposes that instead of reinventing it — opt i
|
|
|
249
249
|
Native escapes still work: `formnovalidate` on a submit button skips validation for that button.
|
|
250
250
|
|
|
251
251
|
`CField` stays zero-CSS: it never applies a class itself. If you need custom styling beyond `[aria-invalid]` or
|
|
252
|
-
`:invalid` selectors,
|
|
252
|
+
`:invalid` selectors, it gives you two ways to read its `invalid`/`message` state:
|
|
253
|
+
|
|
254
|
+
- **Default slot** — reaches elements placed directly inside `CField`:
|
|
253
255
|
|
|
254
256
|
```vue
|
|
255
257
|
<CField v-slot="{ invalid, message }">
|
|
@@ -259,8 +261,17 @@ messages for free. Charpente UI exposes that instead of reinventing it — opt i
|
|
|
259
261
|
</CField>
|
|
260
262
|
```
|
|
261
263
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
+
- **Template ref** — to style `CField`'s own wrapper element instead of a child:
|
|
265
|
+
|
|
266
|
+
```vue
|
|
267
|
+
<CField ref="fieldRef" :class="{ 'is-invalid': fieldRef?.invalid }">
|
|
268
|
+
<CLabel>Email</CLabel>
|
|
269
|
+
<CInput v-model="email" type="email" required/>
|
|
270
|
+
</CField>
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
Both only reach elements placed directly inside `CField`'s default slot, or the `CField` element itself — a custom
|
|
274
|
+
component nested deeper won't receive `invalid`/`message` automatically; pass them down as props if you need that.
|
|
264
275
|
|
|
265
276
|
## Components
|
|
266
277
|
|
|
@@ -10,7 +10,10 @@ declare function __VLS_template(): {
|
|
|
10
10
|
rootEl: any;
|
|
11
11
|
};
|
|
12
12
|
type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
|
|
13
|
-
declare const __VLS_component: import('vue').DefineComponent<{}, {
|
|
13
|
+
declare const __VLS_component: import('vue').DefineComponent<{}, {
|
|
14
|
+
invalid: import('vue').Ref<boolean, boolean>;
|
|
15
|
+
message: import('vue').Ref<string, string>;
|
|
16
|
+
}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
|
|
14
17
|
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
|
|
15
18
|
export default _default;
|
|
16
19
|
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
@@ -4,42 +4,45 @@ import { computed as t, createElementBlock as n, defineComponent as r, mergeProp
|
|
|
4
4
|
var d = /*@__PURE__*/ r({
|
|
5
5
|
inheritAttrs: !1,
|
|
6
6
|
__name: "BaseField",
|
|
7
|
-
setup(r) {
|
|
8
|
-
let
|
|
9
|
-
function v(e) {
|
|
10
|
-
p.value.push(e);
|
|
11
|
-
}
|
|
7
|
+
setup(r, { expose: d }) {
|
|
8
|
+
let f = l(), p = u(), m = s([]), h = s(""), g = s(!1), _ = t(() => typeof f.id == "string" ? f.id : p), v = t(() => m.value.at(-1));
|
|
12
9
|
function y(e) {
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
m.value.push(e);
|
|
11
|
+
}
|
|
12
|
+
function b(e) {
|
|
13
|
+
let t = m.value.indexOf(e);
|
|
14
|
+
t !== -1 && m.value.splice(t, 1);
|
|
15
15
|
}
|
|
16
|
-
let
|
|
17
|
-
let e = { ...
|
|
16
|
+
let x = t(() => {
|
|
17
|
+
let e = { ...f };
|
|
18
18
|
return delete e.id, e;
|
|
19
19
|
});
|
|
20
20
|
o(e, {
|
|
21
|
-
id:
|
|
22
|
-
supportingTextId:
|
|
23
|
-
validationMessage:
|
|
24
|
-
registerSupportingText:
|
|
25
|
-
unregisterSupportingText:
|
|
21
|
+
id: _,
|
|
22
|
+
supportingTextId: v,
|
|
23
|
+
validationMessage: h,
|
|
24
|
+
registerSupportingText: y,
|
|
25
|
+
unregisterSupportingText: b
|
|
26
26
|
});
|
|
27
|
-
function x(e) {
|
|
28
|
-
h.value = !0, m.value = e.target.validationMessage;
|
|
29
|
-
}
|
|
30
27
|
function S(e) {
|
|
31
|
-
|
|
28
|
+
g.value = !0, h.value = e.target.validationMessage;
|
|
29
|
+
}
|
|
30
|
+
function C(e) {
|
|
31
|
+
if (g.value) {
|
|
32
32
|
let t = e.target;
|
|
33
|
-
|
|
33
|
+
g.value = !t.validity.valid, h.value = t.validationMessage;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
return (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
return d({
|
|
37
|
+
invalid: g,
|
|
38
|
+
message: h
|
|
39
|
+
}), (e, t) => (a(), n("div", i(x.value, {
|
|
40
|
+
onInvalidCapture: S,
|
|
41
|
+
onInputCapture: C,
|
|
42
|
+
onChangeCapture: C
|
|
40
43
|
}), [c(e.$slots, "default", {
|
|
41
|
-
invalid:
|
|
42
|
-
message:
|
|
44
|
+
invalid: g.value,
|
|
45
|
+
message: h.value
|
|
43
46
|
})], 16));
|
|
44
47
|
}
|
|
45
48
|
});
|