@ttoss/forms 0.14.7 → 0.14.10

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/esm/index.js CHANGED
@@ -49,7 +49,14 @@ var ErrorMessage = ({
49
49
  {
50
50
  errors,
51
51
  name,
52
- as: /* @__PURE__ */ jsx2(Text, { variant: "text.error", role: "alert" })
52
+ as: /* @__PURE__ */ jsx2(
53
+ Text,
54
+ {
55
+ variant: "text.error",
56
+ role: "alert",
57
+ sx: { fontFamily: "caption", fontSize: "xs" }
58
+ }
59
+ )
53
60
  }
54
61
  );
55
62
  };
@@ -100,7 +107,7 @@ var FormFieldCheckbox = ({
100
107
  });
101
108
  const id = `form-field-checkbox-${name}`;
102
109
  return /* @__PURE__ */ jsxs2(Box3, { children: [
103
- /* @__PURE__ */ jsxs2(Flex, { sx: { alignItems: "center" }, children: [
110
+ /* @__PURE__ */ jsx4(Flex, { sx: { alignItems: "center" }, children: /* @__PURE__ */ jsxs2(Label2, { "aria-disabled": checkboxProps.disabled, htmlFor: id, children: [
104
111
  /* @__PURE__ */ jsx4(
105
112
  Checkbox,
106
113
  {
@@ -113,8 +120,8 @@ var FormFieldCheckbox = ({
113
120
  ...checkboxProps
114
121
  }
115
122
  ),
116
- label && /* @__PURE__ */ jsx4(Label2, { "aria-disabled": checkboxProps.disabled, htmlFor: id, children: label })
117
- ] }),
123
+ label
124
+ ] }) }),
118
125
  /* @__PURE__ */ jsx4(ErrorMessage, { name })
119
126
  ] });
120
127
  };
@@ -138,7 +145,8 @@ var FormFieldInput = ({
138
145
  ...inputProps
139
146
  }) => {
140
147
  const {
141
- field: { onChange, onBlur, value, ref }
148
+ field: { onChange, onBlur, value, ref },
149
+ formState: { errors }
142
150
  } = useController3({
143
151
  name,
144
152
  defaultValue: ""
@@ -150,6 +158,7 @@ var FormFieldInput = ({
150
158
  return String(value).length;
151
159
  }, [value]);
152
160
  const id = `form-field-input-${name}`;
161
+ const hasError = !!errors[name]?.message;
153
162
  return /* @__PURE__ */ jsxs3(Box4, { children: [
154
163
  label && /* @__PURE__ */ jsxs3(
155
164
  Label3,
@@ -173,7 +182,8 @@ var FormFieldInput = ({
173
182
  sx: {
174
183
  marginLeft: "auto",
175
184
  fontSize: "xs",
176
- lineHeight: 0
185
+ lineHeight: 0,
186
+ color: "underemphasize"
177
187
  },
178
188
  variant: "character-counter",
179
189
  children: characterCounter
@@ -187,6 +197,7 @@ var FormFieldInput = ({
187
197
  {
188
198
  ref,
189
199
  onChange,
200
+ className: hasError ? "error" : "",
190
201
  onBlur,
191
202
  value,
192
203
  name,
package/dist/index.js CHANGED
@@ -91,7 +91,14 @@ var ErrorMessage = ({
91
91
  {
92
92
  errors,
93
93
  name,
94
- as: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui2.Text, { variant: "text.error", role: "alert" })
94
+ as: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
95
+ import_ui2.Text,
96
+ {
97
+ variant: "text.error",
98
+ role: "alert",
99
+ sx: { fontFamily: "caption", fontSize: "xs" }
100
+ }
101
+ )
95
102
  }
96
103
  );
97
104
  };
@@ -140,7 +147,7 @@ var FormFieldCheckbox = ({
140
147
  });
141
148
  const id = `form-field-checkbox-${name}`;
142
149
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_ui4.Box, { children: [
143
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_ui4.Flex, { sx: { alignItems: "center" }, children: [
150
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_ui4.Flex, { sx: { alignItems: "center" }, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_ui4.Label, { "aria-disabled": checkboxProps.disabled, htmlFor: id, children: [
144
151
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
145
152
  import_ui4.Checkbox,
146
153
  {
@@ -153,8 +160,8 @@ var FormFieldCheckbox = ({
153
160
  ...checkboxProps
154
161
  }
155
162
  ),
156
- label && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_ui4.Label, { "aria-disabled": checkboxProps.disabled, htmlFor: id, children: label })
157
- ] }),
163
+ label
164
+ ] }) }),
158
165
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ErrorMessage, { name })
159
166
  ] });
160
167
  };
@@ -172,7 +179,8 @@ var FormFieldInput = ({
172
179
  ...inputProps
173
180
  }) => {
174
181
  const {
175
- field: { onChange, onBlur, value, ref }
182
+ field: { onChange, onBlur, value, ref },
183
+ formState: { errors }
176
184
  } = (0, import_react_hook_form5.useController)({
177
185
  name,
178
186
  defaultValue: ""
@@ -184,6 +192,7 @@ var FormFieldInput = ({
184
192
  return String(value).length;
185
193
  }, [value]);
186
194
  const id = `form-field-input-${name}`;
195
+ const hasError = !!errors[name]?.message;
187
196
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_ui5.Box, { children: [
188
197
  label && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
189
198
  import_ui5.Label,
@@ -207,7 +216,8 @@ var FormFieldInput = ({
207
216
  sx: {
208
217
  marginLeft: "auto",
209
218
  fontSize: "xs",
210
- lineHeight: 0
219
+ lineHeight: 0,
220
+ color: "underemphasize"
211
221
  },
212
222
  variant: "character-counter",
213
223
  children: characterCounter
@@ -221,6 +231,7 @@ var FormFieldInput = ({
221
231
  {
222
232
  ref,
223
233
  onChange,
234
+ className: hasError ? "error" : "",
224
235
  onBlur,
225
236
  value,
226
237
  name,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/forms",
3
- "version": "0.14.7",
3
+ "version": "0.14.10",
4
4
  "license": "UNLICENSED",
5
5
  "author": "ttoss",
6
6
  "contributors": [
@@ -31,7 +31,7 @@
31
31
  "devDependencies": {
32
32
  "@ttoss/config": "^1.28.3",
33
33
  "@ttoss/test-utils": "^1.20.5",
34
- "@ttoss/ui": "^1.30.7",
34
+ "@ttoss/ui": "^1.30.10",
35
35
  "@types/jest": "^29.4.0",
36
36
  "jest": "^29.5.0",
37
37
  "react": "^18.2.0",
@@ -41,5 +41,5 @@
41
41
  "publishConfig": {
42
42
  "access": "public"
43
43
  },
44
- "gitHead": "56e8cfde36a962deaa5514453618280699824b4f"
44
+ "gitHead": "5a7f5a875b4474af9c78bbec65355cde6e6a7c81"
45
45
  }
@@ -15,7 +15,13 @@ export const ErrorMessage = <TFieldValues extends FieldValues = FieldValues>({
15
15
  <HookFormErrorMessage
16
16
  errors={errors}
17
17
  name={name as any}
18
- as={<Text variant="text.error" role="alert" />}
18
+ as={
19
+ <Text
20
+ variant="text.error"
21
+ role="alert"
22
+ sx={{ fontFamily: 'caption', fontSize: 'xs' }}
23
+ />
24
+ }
19
25
  />
20
26
  );
21
27
  };
@@ -24,20 +24,18 @@ export const FormFieldCheckbox = <
24
24
  return (
25
25
  <Box>
26
26
  <Flex sx={{ alignItems: 'center' }}>
27
- <Checkbox
28
- id={id}
29
- ref={ref}
30
- checked={value}
31
- onChange={onChange}
32
- onBlur={onBlur}
33
- name={name}
34
- {...checkboxProps}
35
- />
36
- {label && (
37
- <Label aria-disabled={checkboxProps.disabled} htmlFor={id}>
38
- {label}
39
- </Label>
40
- )}
27
+ <Label aria-disabled={checkboxProps.disabled} htmlFor={id}>
28
+ <Checkbox
29
+ id={id}
30
+ ref={ref}
31
+ checked={value}
32
+ onChange={onChange}
33
+ onBlur={onBlur}
34
+ name={name}
35
+ {...checkboxProps}
36
+ />
37
+ {label}
38
+ </Label>
41
39
  </Flex>
42
40
  <ErrorMessage name={name} />
43
41
  </Box>
@@ -28,6 +28,7 @@ export const FormFieldInput = <
28
28
  } & InputProps) => {
29
29
  const {
30
30
  field: { onChange, onBlur, value, ref },
31
+ formState: { errors },
31
32
  } = useController<any>({
32
33
  name,
33
34
  defaultValue: '',
@@ -43,6 +44,8 @@ export const FormFieldInput = <
43
44
 
44
45
  const id = `form-field-input-${name}`;
45
46
 
47
+ const hasError = !!errors[name]?.message;
48
+
46
49
  return (
47
50
  <Box>
48
51
  {label && (
@@ -67,6 +70,7 @@ export const FormFieldInput = <
67
70
  marginLeft: 'auto',
68
71
  fontSize: 'xs',
69
72
  lineHeight: 0,
73
+ color: 'underemphasize',
70
74
  }}
71
75
  variant="character-counter"
72
76
  >
@@ -79,6 +83,7 @@ export const FormFieldInput = <
79
83
  <Input
80
84
  ref={ref}
81
85
  onChange={onChange}
86
+ className={hasError ? 'error' : ''}
82
87
  onBlur={onBlur}
83
88
  value={value}
84
89
  name={name}