@ikatec/nebula-react 1.0.9 → 1.0.11

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/index.d.mts CHANGED
@@ -500,8 +500,9 @@ type InputPhoneProps = {
500
500
  isError?: boolean;
501
501
  defaultCountry?: RPNInput.Country;
502
502
  onChange: (value: string) => void;
503
+ value?: string | null;
503
504
  } & Omit<React__default.InputHTMLAttributes<HTMLInputElement>, 'onChange'>;
504
- declare function InputPhone({ value, onChange, className, disabled, isError, defaultCountry, ...props }: InputPhoneProps): react_jsx_runtime.JSX.Element;
505
+ declare function InputPhone({ className, disabled, isError, defaultCountry, value, onChange, ...props }: InputPhoneProps): react_jsx_runtime.JSX.Element;
505
506
 
506
507
  interface SkeletonProps extends React__default.HTMLAttributes<HTMLDivElement> {
507
508
  }
package/dist/index.d.ts CHANGED
@@ -500,8 +500,9 @@ type InputPhoneProps = {
500
500
  isError?: boolean;
501
501
  defaultCountry?: RPNInput.Country;
502
502
  onChange: (value: string) => void;
503
+ value?: string | null;
503
504
  } & Omit<React__default.InputHTMLAttributes<HTMLInputElement>, 'onChange'>;
504
- declare function InputPhone({ value, onChange, className, disabled, isError, defaultCountry, ...props }: InputPhoneProps): react_jsx_runtime.JSX.Element;
505
+ declare function InputPhone({ className, disabled, isError, defaultCountry, value, onChange, ...props }: InputPhoneProps): react_jsx_runtime.JSX.Element;
505
506
 
506
507
  interface SkeletonProps extends React__default.HTMLAttributes<HTMLDivElement> {
507
508
  }
package/dist/index.js CHANGED
@@ -3552,14 +3552,14 @@ var FlagComponent = ({ country, countryName }) => {
3552
3552
  };
3553
3553
  var PhoneInput = React8__namespace.default.forwardRef(({ className, ...props }, ref) => {
3554
3554
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "nebula-ds flex items-center justify-center rounded-e-[20px] w-full", children: [
3555
- /* @__PURE__ */ jsxRuntime.jsx(Separator2, { orientation: "vertical", className: "nebula-ds w-[2px] h-5" }),
3555
+ /* @__PURE__ */ jsxRuntime.jsx(Separator2, { orientation: "vertical", className: "nebula-ds w-[1px] h-5 z-10" }),
3556
3556
  /* @__PURE__ */ jsxRuntime.jsx(
3557
3557
  InputText,
3558
3558
  {
3559
3559
  "data-slot": "phone-input",
3560
3560
  ref,
3561
3561
  className: cn(
3562
- "-ms-px rounded-s-none shadow-none focus-visible:z-10 ring-0 focus:ring-0 border-0 w-full",
3562
+ "-ms-px rounded-s-none shadow-none focus-visible:z-10 ring-0 focus:ring-0 border-0 w-full h-auto",
3563
3563
  className
3564
3564
  ),
3565
3565
  ...props
@@ -3569,20 +3569,58 @@ var PhoneInput = React8__namespace.default.forwardRef(({ className, ...props },
3569
3569
  });
3570
3570
  PhoneInput.displayName = "Input";
3571
3571
  function InputPhone({
3572
- value,
3573
- onChange,
3574
3572
  className,
3575
3573
  disabled,
3576
3574
  isError = false,
3577
3575
  defaultCountry = "BR",
3576
+ value,
3577
+ onChange,
3578
3578
  ...props
3579
3579
  }) {
3580
- const valueCorrection = value && value.toString().length && !value.toString().startsWith("+") ? `+${value}` : value;
3580
+ const [valueState, setValueState] = React8.useState("");
3581
+ const [isFirstRender, setIsFirstRender] = React8.useState(true);
3582
+ const countryCode = defaultCountry ? RPNInput__namespace.getCountryCallingCode(defaultCountry) : null;
3583
+ const normalizePhoneNumber = React8.useCallback(
3584
+ (inputValue) => {
3585
+ if (!inputValue) return "";
3586
+ const cleanValue = inputValue.toString().replace(/[^\d+]/g, "");
3587
+ if (!cleanValue) return "";
3588
+ if (cleanValue.startsWith("+")) {
3589
+ return cleanValue;
3590
+ }
3591
+ if (countryCode && cleanValue.startsWith(countryCode)) {
3592
+ return `+${cleanValue}`;
3593
+ }
3594
+ if (countryCode && /^\d{10,11}$/.test(cleanValue)) {
3595
+ return `+${countryCode}${cleanValue}`;
3596
+ }
3597
+ return cleanValue;
3598
+ },
3599
+ [countryCode]
3600
+ );
3601
+ React8.useEffect(() => {
3602
+ if (value !== void 0 && value !== null) {
3603
+ const normalizedValue = normalizePhoneNumber(value);
3604
+ setValueState(normalizedValue);
3605
+ } else {
3606
+ setValueState("");
3607
+ }
3608
+ }, [value, normalizePhoneNumber]);
3609
+ const handleChange = React8.useCallback(
3610
+ (newValue) => {
3611
+ setIsFirstRender(false);
3612
+ setValueState(newValue);
3613
+ if (onChange) {
3614
+ onChange(newValue || "");
3615
+ }
3616
+ },
3617
+ [onChange]
3618
+ );
3581
3619
  return /* @__PURE__ */ jsxRuntime.jsx(
3582
3620
  RPNInput__namespace.default,
3583
3621
  {
3584
3622
  className: cn(
3585
- "flex w-full bg-inputText-background-default rounded-[20px] border border-inputText-border-default focus-within:ring-[3px] focus-within:ring-inputText-border-focus focus-within:border-inputText-border-focus",
3623
+ "flex w-full h-10 bg-inputText-background-default rounded-[20px] border border-inputText-border-default focus-within:ring-[3px] focus-within:ring-inputText-border-focus focus-within:border-inputText-border-focus",
3586
3624
  { "bg-inputText-background-disabled": disabled },
3587
3625
  {
3588
3626
  "text-inputText-icon-danger border-inputText-border-danger focus-within:border-inputText-border-danger focus-within:ring-button-danger-border-focus": isError
@@ -3590,16 +3628,16 @@ function InputPhone({
3590
3628
  className
3591
3629
  ),
3592
3630
  flagComponent: FlagComponent,
3593
- limitMaxLength: true,
3594
3631
  countrySelectComponent: CountrySelect,
3595
3632
  inputComponent: PhoneInput,
3596
3633
  disabled,
3597
- value: valueCorrection?.toString(),
3598
- onChange: (newValue) => onChange(newValue ?? ""),
3634
+ international: true,
3635
+ limitMaxLength: true,
3636
+ defaultCountry: isFirstRender && (!value || value === "") ? defaultCountry : valueState ? defaultCountry : void 0,
3599
3637
  countryCallingCodeEditable: true,
3600
- initialValueFormat: "national",
3601
- defaultCountry,
3602
- ...props
3638
+ ...props,
3639
+ value: valueState,
3640
+ onChange: handleChange
3603
3641
  }
3604
3642
  );
3605
3643
  }
package/dist/index.mjs CHANGED
@@ -3512,14 +3512,14 @@ var FlagComponent = ({ country, countryName }) => {
3512
3512
  };
3513
3513
  var PhoneInput = React8__default.forwardRef(({ className, ...props }, ref) => {
3514
3514
  return /* @__PURE__ */ jsxs("div", { className: "nebula-ds flex items-center justify-center rounded-e-[20px] w-full", children: [
3515
- /* @__PURE__ */ jsx(Separator2, { orientation: "vertical", className: "nebula-ds w-[2px] h-5" }),
3515
+ /* @__PURE__ */ jsx(Separator2, { orientation: "vertical", className: "nebula-ds w-[1px] h-5 z-10" }),
3516
3516
  /* @__PURE__ */ jsx(
3517
3517
  InputText,
3518
3518
  {
3519
3519
  "data-slot": "phone-input",
3520
3520
  ref,
3521
3521
  className: cn(
3522
- "-ms-px rounded-s-none shadow-none focus-visible:z-10 ring-0 focus:ring-0 border-0 w-full",
3522
+ "-ms-px rounded-s-none shadow-none focus-visible:z-10 ring-0 focus:ring-0 border-0 w-full h-auto",
3523
3523
  className
3524
3524
  ),
3525
3525
  ...props
@@ -3529,20 +3529,58 @@ var PhoneInput = React8__default.forwardRef(({ className, ...props }, ref) => {
3529
3529
  });
3530
3530
  PhoneInput.displayName = "Input";
3531
3531
  function InputPhone({
3532
- value,
3533
- onChange,
3534
3532
  className,
3535
3533
  disabled,
3536
3534
  isError = false,
3537
3535
  defaultCountry = "BR",
3536
+ value,
3537
+ onChange,
3538
3538
  ...props
3539
3539
  }) {
3540
- const valueCorrection = value && value.toString().length && !value.toString().startsWith("+") ? `+${value}` : value;
3540
+ const [valueState, setValueState] = useState("");
3541
+ const [isFirstRender, setIsFirstRender] = useState(true);
3542
+ const countryCode = defaultCountry ? RPNInput.getCountryCallingCode(defaultCountry) : null;
3543
+ const normalizePhoneNumber = useCallback(
3544
+ (inputValue) => {
3545
+ if (!inputValue) return "";
3546
+ const cleanValue = inputValue.toString().replace(/[^\d+]/g, "");
3547
+ if (!cleanValue) return "";
3548
+ if (cleanValue.startsWith("+")) {
3549
+ return cleanValue;
3550
+ }
3551
+ if (countryCode && cleanValue.startsWith(countryCode)) {
3552
+ return `+${cleanValue}`;
3553
+ }
3554
+ if (countryCode && /^\d{10,11}$/.test(cleanValue)) {
3555
+ return `+${countryCode}${cleanValue}`;
3556
+ }
3557
+ return cleanValue;
3558
+ },
3559
+ [countryCode]
3560
+ );
3561
+ useEffect(() => {
3562
+ if (value !== void 0 && value !== null) {
3563
+ const normalizedValue = normalizePhoneNumber(value);
3564
+ setValueState(normalizedValue);
3565
+ } else {
3566
+ setValueState("");
3567
+ }
3568
+ }, [value, normalizePhoneNumber]);
3569
+ const handleChange = useCallback(
3570
+ (newValue) => {
3571
+ setIsFirstRender(false);
3572
+ setValueState(newValue);
3573
+ if (onChange) {
3574
+ onChange(newValue || "");
3575
+ }
3576
+ },
3577
+ [onChange]
3578
+ );
3541
3579
  return /* @__PURE__ */ jsx(
3542
3580
  RPNInput.default,
3543
3581
  {
3544
3582
  className: cn(
3545
- "flex w-full bg-inputText-background-default rounded-[20px] border border-inputText-border-default focus-within:ring-[3px] focus-within:ring-inputText-border-focus focus-within:border-inputText-border-focus",
3583
+ "flex w-full h-10 bg-inputText-background-default rounded-[20px] border border-inputText-border-default focus-within:ring-[3px] focus-within:ring-inputText-border-focus focus-within:border-inputText-border-focus",
3546
3584
  { "bg-inputText-background-disabled": disabled },
3547
3585
  {
3548
3586
  "text-inputText-icon-danger border-inputText-border-danger focus-within:border-inputText-border-danger focus-within:ring-button-danger-border-focus": isError
@@ -3550,16 +3588,16 @@ function InputPhone({
3550
3588
  className
3551
3589
  ),
3552
3590
  flagComponent: FlagComponent,
3553
- limitMaxLength: true,
3554
3591
  countrySelectComponent: CountrySelect,
3555
3592
  inputComponent: PhoneInput,
3556
3593
  disabled,
3557
- value: valueCorrection?.toString(),
3558
- onChange: (newValue) => onChange(newValue ?? ""),
3594
+ international: true,
3595
+ limitMaxLength: true,
3596
+ defaultCountry: isFirstRender && (!value || value === "") ? defaultCountry : valueState ? defaultCountry : void 0,
3559
3597
  countryCallingCodeEditable: true,
3560
- initialValueFormat: "national",
3561
- defaultCountry,
3562
- ...props
3598
+ ...props,
3599
+ value: valueState,
3600
+ onChange: handleChange
3563
3601
  }
3564
3602
  );
3565
3603
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikatec/nebula-react",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "React components",
5
5
  "publishConfig": {
6
6
  "access": "public"