@ttoss/forms 0.43.0 → 0.43.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 CHANGED
@@ -571,6 +571,46 @@ Input with custom format patterns.
571
571
  />
572
572
  ```
573
573
 
574
+ ### FormFieldPhone
575
+
576
+ Generic phone number field with an optional country-code dropdown. By default it renders a dropdown populated with `COMMON_PHONE_COUNTRY_CODES` (15 common countries + a Manual entry). The component manages the selected country code internally — no external state is needed.
577
+
578
+ ```tsx
579
+ import { FormFieldPhone, COMMON_PHONE_COUNTRY_CODES } from '@ttoss/forms';
580
+
581
+ // Minimal — dropdown defaults to COMMON_PHONE_COUNTRY_CODES, starts in Manual mode
582
+ <FormFieldPhone name="phone" label="Phone" />
583
+
584
+ // Set an initial country code (US +1)
585
+ <FormFieldPhone name="phone" label="Phone" defaultCountryCode="+1" />
586
+
587
+ // React to country-code changes without managing state
588
+ <FormFieldPhone
589
+ name="phone"
590
+ label="Phone"
591
+ defaultCountryCode="+1"
592
+ onCountryCodeChange={(code) => console.log('selected', code)}
593
+ />
594
+
595
+ // No dropdown — plain masked input with a fixed country code
596
+ <FormFieldPhone
597
+ name="phone"
598
+ label="Phone"
599
+ defaultCountryCode="+1"
600
+ format="(###) ###-####"
601
+ countryCodeOptions={[]}
602
+ />
603
+ ```
604
+
605
+ The submitted value always includes the country code prefix (e.g. `{ phone: '+15555555555' }`). When the user selects the **Manual** entry, the mask is removed and the user can type any international number freely (the value is stored with a `+` prefix).
606
+
607
+ **Key props:**
608
+
609
+ - `defaultCountryCode`: Initial calling code (e.g. `'+1'`). Defaults to the first entry in `countryCodeOptions`.
610
+ - `format`: Pattern string or function for the local number part (e.g. `'(###) ###-####'`).
611
+ - `countryCodeOptions`: List of `CountryCodeOption` objects. Defaults to `COMMON_PHONE_COUNTRY_CODES`. Pass `[]` to hide the dropdown.
612
+ - `onCountryCodeChange`: Optional callback fired when the user picks a different country code.
613
+
574
614
  ### FormFieldCreditCardNumber
575
615
 
576
616
  Credit card input with automatic formatting.
@@ -611,7 +651,7 @@ The package also exports `isCnpjValid(cnpj: string)` for standalone validation.
611
651
 
612
652
  #### FormFieldPhone
613
653
 
614
- Brazilian phone number input with formatting.
654
+ Brazilian phone number input with automatic formatting and the `+55` country code pre-set.
615
655
 
616
656
  ```tsx
617
657
  <FormFieldPhone name="phone" label="Phone" />
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { FieldValues, FieldPath } from 'react-hook-form';
3
- import { a as FormFieldPatternFormatProps, F as FormFieldProps, d as FormFieldPhoneProps$1 } from '../FormFieldPhone-BKeOS0i6.js';
3
+ import { a as FormFieldPatternFormatProps, F as FormFieldProps, d as FormFieldPhoneProps$1 } from '../FormFieldPhone--tC0Hlcf.js';
4
4
  import { PatternFormatProps, NumberFormatBaseProps } from 'react-number-format';
5
5
  import '@ttoss/ui';
6
6
  import 'react';
@@ -19,7 +19,7 @@ declare const FormFieldCPF: <TFieldValues extends FieldValues = FieldValues, TNa
19
19
  type FormFieldCPFOrCNPJProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = FormFieldProps<TFieldValues, TName> & Omit<NumberFormatBaseProps, 'name' | 'format'>;
20
20
  declare const FormFieldCPFOrCNPJ: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ disabled, ...props }: FormFieldCPFOrCNPJProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
21
21
 
22
- type FormFieldPhoneProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = Omit<FormFieldPhoneProps$1<TFieldValues, TName>, 'countryCode' | 'format'>;
22
+ type FormFieldPhoneProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = Omit<FormFieldPhoneProps$1<TFieldValues, TName>, 'defaultCountryCode' | 'format'>;
23
23
  /**
24
24
  * Brazilian phone number form field.
25
25
  *
@@ -109,11 +109,12 @@ declare const COMMON_PHONE_COUNTRY_CODES: CountryCodeOption[];
109
109
 
110
110
  type FormFieldPhoneProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = FormFieldProps<TFieldValues, TName> & Omit<PatternFormatProps, 'name' | 'format'> & {
111
111
  /**
112
- * The country calling code to display as a literal prefix in the input.
112
+ * The initial country calling code to display as a literal prefix in the input.
113
113
  * For example, '+55' for Brazil or '+1' for the United States.
114
114
  * Defaults to the first entry in `countryCodeOptions` when not provided.
115
+ * The component manages the selected code internally — no external state needed.
115
116
  */
116
- countryCode?: string;
117
+ defaultCountryCode?: string;
117
118
  /**
118
119
  * The pattern format for the local part of the phone number.
119
120
  * Accepts either a static string (e.g., '(##) #####-####') or a function
@@ -136,9 +137,10 @@ type FormFieldPhoneProps<TFieldValues extends FieldValues = FieldValues, TName e
136
137
  */
137
138
  countryCodeOptions?: CountryCodeOption[];
138
139
  /**
139
- * Called with the newly selected country code value when the user changes
140
- * the country code via the dropdown. Only relevant when
141
- * countryCodeOptions is non-empty.
140
+ * Optional callback fired with the newly selected country code value when
141
+ * the user changes the country code via the dropdown. The component
142
+ * manages the selected code internally, so this is only needed when the
143
+ * caller wants to react to country-code changes.
142
144
  */
143
145
  onCountryCodeChange?: (countryCode: string) => void;
144
146
  };
@@ -168,26 +170,30 @@ type FormFieldPhoneProps<TFieldValues extends FieldValues = FieldValues, TName e
168
170
  *
169
171
  * @example
170
172
  * ```tsx
171
- * // Default: dropdown with COMMON_PHONE_COUNTRY_CODES, US (+1) pre-selected
172
- * <FormFieldPhone name="phone" label="Phone" countryCode="+1" />
173
+ * // Default: dropdown with COMMON_PHONE_COUNTRY_CODES, country code managed internally.
174
+ * // The submitted value includes the country code prefix (e.g. '+15555555555').
175
+ * <FormFieldPhone name="phone" label="Phone" />
173
176
  * ```
174
177
  *
175
178
  * @example
176
179
  * ```tsx
177
- * // Controlled country code submitted value includes the prefix
178
- * // e.g. { phone: '+15555555555' }
179
- * const [countryCode, setCountryCode] = React.useState('+1');
180
+ * // Set a custom initial country code; the component manages further changes.
181
+ * <FormFieldPhone name="phone" label="Phone" defaultCountryCode="+55" />
182
+ * ```
183
+ *
184
+ * @example
185
+ * ```tsx
186
+ * // Listen for country-code changes without managing state externally.
180
187
  * <FormFieldPhone
181
188
  * name="phone"
182
189
  * label="Phone"
183
- * countryCode={countryCode}
184
- * onCountryCodeChange={setCountryCode}
190
+ * onCountryCodeChange={(code) => console.log('selected', code)}
185
191
  * />
186
192
  * ```
187
193
  *
188
194
  * @example
189
195
  * ```tsx
190
- * // No dropdown — plain phone input; value includes the prefix
196
+ * // No dropdown — plain phone input; value includes the prefix.
191
197
  * // e.g. { phone: '+15555555555' }
192
198
  * <FormFieldPhone
193
199
  * name="phone"
@@ -212,6 +218,6 @@ type FormFieldPhoneProps<TFieldValues extends FieldValues = FieldValues, TName e
212
218
  * />
213
219
  * ```
214
220
  */
215
- declare const FormFieldPhone: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ disabled, countryCode: countryCodeProp, format, countryCodeOptions, onCountryCodeChange, ...props }: FormFieldPhoneProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
221
+ declare const FormFieldPhone: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ disabled, defaultCountryCode: countryCodeProp, format, countryCodeOptions, onCountryCodeChange, ...props }: FormFieldPhoneProps<TFieldValues, TName>) => react_jsx_runtime.JSX.Element;
216
222
 
217
223
  export { type CountryCodeOption as C, type FormFieldProps as F, MANUAL_PHONE_COUNTRY_CODE as M, type FormFieldPatternFormatProps as a, FormField as b, FormFieldPatternFormat as c, type FormFieldPhoneProps as d, FormFieldPhone as e, COMMON_PHONE_COUNTRY_CODES as f };
@@ -1,6 +1,6 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
2
  import * as React from 'react';
3
- import { FormField, FormFieldCNPJ, FormFieldCPF, FormFieldPatternFormat, FormFieldPhone, __name, isCnpjValid, isCpfValid } from "../chunk-ZORKZWD7.js";
3
+ import { FormField, FormFieldCNPJ, FormFieldCPF, FormFieldPatternFormat, FormFieldPhone, __name, isCnpjValid, isCpfValid } from "../chunk-U7QBQHMU.js";
4
4
 
5
5
  // src/Brazil/FormFieldCEP.tsx
6
6
  var FormFieldCEP = /* @__PURE__ */__name(({
@@ -84,7 +84,7 @@ var FormFieldPhone2 = /* @__PURE__ */__name(({
84
84
  }) => {
85
85
  return /* @__PURE__ */React.createElement(FormFieldPhone, {
86
86
  ...props,
87
- countryCode: BRAZIL_COUNTRY_CODE,
87
+ defaultCountryCode: BRAZIL_COUNTRY_CODE,
88
88
  format: getBrazilPhoneFormat,
89
89
  placeholder,
90
90
  countryCodeOptions
@@ -1,7 +1,7 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
2
  import * as React from 'react';
3
- import { Form, useForm, yupResolver } from "../chunk-4YLT3VPV.js";
4
- import { __name } from "../chunk-ZORKZWD7.js";
3
+ import { Form, useForm, yupResolver } from "../chunk-3M2OR5NH.js";
4
+ import { __name } from "../chunk-U7QBQHMU.js";
5
5
 
6
6
  // src/MultistepForm/MultistepForm.tsx
7
7
  import { Flex as Flex6 } from "@ttoss/ui";
@@ -1,6 +1,6 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
2
  import * as React from 'react';
3
- import { FormErrorMessage, FormField, FormFieldPatternFormat, __name, isCnpjValid, isCpfValid } from "./chunk-ZORKZWD7.js";
3
+ import { FormErrorMessage, FormField, FormFieldPatternFormat, __name, isCnpjValid, isCpfValid } from "./chunk-U7QBQHMU.js";
4
4
 
5
5
  // src/Form.tsx
6
6
  import { Box as Box2 } from "@ttoss/ui";
@@ -377,7 +377,7 @@ var PhoneDropdownWrapper = /* @__PURE__ */__name(({
377
377
  }, "PhoneDropdownWrapper");
378
378
  var FormFieldPhone = /* @__PURE__ */__name(({
379
379
  disabled,
380
- countryCode: countryCodeProp,
380
+ defaultCountryCode: countryCodeProp,
381
381
  format,
382
382
  countryCodeOptions = COMMON_PHONE_COUNTRY_CODES,
383
383
  onCountryCodeChange,
@@ -399,7 +399,11 @@ var FormFieldPhone = /* @__PURE__ */__name(({
399
399
  placeholder,
400
400
  ...patternFormatProps
401
401
  } = props;
402
- const countryCode = countryCodeProp ?? countryCodeOptions[0]?.value ?? void 0;
402
+ const [countryCode, setCountryCode] = React4.useState(countryCodeProp ?? countryCodeOptions[0]?.value ?? void 0);
403
+ const handleCountryCodeChange = /* @__PURE__ */__name(code => {
404
+ setCountryCode(code);
405
+ onCountryCodeChange?.(code);
406
+ }, "handleCountryCodeChange");
403
407
  const isManual = countryCode === MANUAL_PHONE_COUNTRY_CODE;
404
408
  const getFormat = /* @__PURE__ */__name(value => {
405
409
  const selectedOption = countryCodeOptions.find(opt => {
@@ -472,7 +476,7 @@ var FormFieldPhone = /* @__PURE__ */__name(({
472
476
  countryCode,
473
477
  countryCodeOptions,
474
478
  disabled: disabled ?? field.disabled,
475
- onCountryCodeChange,
479
+ onCountryCodeChange: handleCountryCodeChange,
476
480
  onPhoneReset: /* @__PURE__ */__name(() => {
477
481
  return field.onChange("");
478
482
  }, "onPhoneReset"),
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
- import { Controller, Form, FormActions, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldDatePicker, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldRadio, FormFieldRadioCard, FormFieldRadioCardIcony, FormFieldSegmentedControl, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, FormGroup, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormGroup, useFormState, useWatch, yup, yupResolver, z, zodResolver } from "./chunk-4YLT3VPV.js";
3
- import { COMMON_PHONE_COUNTRY_CODES, FormErrorMessage, FormField, FormFieldPatternFormat, FormFieldPhone, MANUAL_PHONE_COUNTRY_CODE } from "./chunk-ZORKZWD7.js";
2
+ import { Controller, Form, FormActions, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldDatePicker, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldRadio, FormFieldRadioCard, FormFieldRadioCardIcony, FormFieldSegmentedControl, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, FormGroup, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormGroup, useFormState, useWatch, yup, yupResolver, z, zodResolver } from "./chunk-3M2OR5NH.js";
3
+ import { COMMON_PHONE_COUNTRY_CODES, FormErrorMessage, FormField, FormFieldPatternFormat, FormFieldPhone, MANUAL_PHONE_COUNTRY_CODE } from "./chunk-U7QBQHMU.js";
4
4
  export { COMMON_PHONE_COUNTRY_CODES, Controller, Form, FormActions, FormErrorMessage, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldDatePicker, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldPatternFormat, FormFieldPhone, FormFieldRadio, FormFieldRadioCard, FormFieldRadioCardIcony, FormFieldSegmentedControl, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, FormGroup, FormProvider, MANUAL_PHONE_COUNTRY_CODE, useController, useFieldArray, useForm, useFormContext, useFormGroup, useFormState, useWatch, yup, yupResolver, z, zodResolver };
package/dist/index.d.ts CHANGED
@@ -4,8 +4,8 @@ import * as React from 'react';
4
4
  import { FieldValues, FormProviderProps, FieldName, FieldPath } from 'react-hook-form';
5
5
  export * from 'react-hook-form';
6
6
  export { Controller, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch } from 'react-hook-form';
7
- import { F as FormFieldProps, a as FormFieldPatternFormatProps } from './FormFieldPhone-BKeOS0i6.js';
8
- export { f as COMMON_PHONE_COUNTRY_CODES, C as CountryCodeOption, b as FormField, c as FormFieldPatternFormat, e as FormFieldPhone, d as FormFieldPhoneProps, M as MANUAL_PHONE_COUNTRY_CODE } from './FormFieldPhone-BKeOS0i6.js';
7
+ import { F as FormFieldProps, a as FormFieldPatternFormatProps } from './FormFieldPhone--tC0Hlcf.js';
8
+ export { f as COMMON_PHONE_COUNTRY_CODES, C as CountryCodeOption, b as FormField, c as FormFieldPatternFormat, e as FormFieldPhone, d as FormFieldPhoneProps, M as MANUAL_PHONE_COUNTRY_CODE } from './FormFieldPhone--tC0Hlcf.js';
9
9
  import { NumericFormatProps } from 'react-number-format';
10
10
  import { DateRange } from '@ttoss/components/DatePicker';
11
11
  import './typings.d-BzNUo1mD.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/forms",
3
- "version": "0.43.0",
3
+ "version": "0.43.1",
4
4
  "license": "MIT",
5
5
  "author": "ttoss",
6
6
  "contributors": [
@@ -40,9 +40,9 @@
40
40
  },
41
41
  "peerDependencies": {
42
42
  "react": ">=16.8.0",
43
+ "@ttoss/components": "^2.13.2",
43
44
  "@ttoss/react-i18n": "^2.1.0",
44
- "@ttoss/ui": "^6.8.0",
45
- "@ttoss/components": "^2.13.2"
45
+ "@ttoss/ui": "^6.8.0"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@types/jest": "^30.0.0",
@@ -52,13 +52,13 @@
52
52
  "react-error-boundary": "^6.1.0",
53
53
  "tsup": "^8.5.1",
54
54
  "yup": "^1.7.1",
55
+ "@ttoss/config": "^1.36.0",
55
56
  "@ttoss/components": "^2.13.2",
56
57
  "@ttoss/i18n-cli": "^0.7.39",
57
- "@ttoss/react-i18n": "^2.1.0",
58
58
  "@ttoss/react-icons": "^0.6.0",
59
59
  "@ttoss/test-utils": "^4.1.0",
60
- "@ttoss/ui": "^6.8.0",
61
- "@ttoss/config": "^1.36.0"
60
+ "@ttoss/react-i18n": "^2.1.0",
61
+ "@ttoss/ui": "^6.8.0"
62
62
  },
63
63
  "publishConfig": {
64
64
  "access": "public",