@ikatec/nebula-react 1.0.10 → 1.0.12

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
@@ -15,6 +15,7 @@ import * as SwitchPrimitives from '@radix-ui/react-switch';
15
15
  import * as TooltipPrimitive from '@radix-ui/react-tooltip';
16
16
  import * as AccordionPrimitive from '@radix-ui/react-accordion';
17
17
  import * as TabsPrimitive from '@radix-ui/react-tabs';
18
+ import * as RPNInput from 'react-phone-number-input';
18
19
 
19
20
  declare enum buttonVariantEnum {
20
21
  primary = "\n bg-button-primary-background-default\n hover:bg-button-primary-background-hover\n active:bg-button-primary-background-active\n focus:bg-button-primary-background-focus\n focus:ring-button-primary-border-focus\n text-button-primary-text\n ",
@@ -495,7 +496,13 @@ interface LinkProps extends HTMLAttributes<HTMLAnchorElement> {
495
496
  }
496
497
  declare const Link: React__default.ForwardRefExoticComponent<LinkProps & React__default.RefAttributes<HTMLAnchorElement>>;
497
498
 
498
- declare function InputPhone(): react_jsx_runtime.JSX.Element;
499
+ type InputPhoneProps = {
500
+ isError?: boolean;
501
+ defaultCountry?: RPNInput.Country;
502
+ onChange: (value: string) => void;
503
+ value?: string | null;
504
+ } & Omit<React__default.InputHTMLAttributes<HTMLInputElement>, 'onChange'>;
505
+ declare function InputPhone({ className, disabled, isError, defaultCountry, value, onChange, ...props }: InputPhoneProps): react_jsx_runtime.JSX.Element;
499
506
 
500
507
  interface SkeletonProps extends React__default.HTMLAttributes<HTMLDivElement> {
501
508
  }
package/dist/index.d.ts CHANGED
@@ -15,6 +15,7 @@ import * as SwitchPrimitives from '@radix-ui/react-switch';
15
15
  import * as TooltipPrimitive from '@radix-ui/react-tooltip';
16
16
  import * as AccordionPrimitive from '@radix-ui/react-accordion';
17
17
  import * as TabsPrimitive from '@radix-ui/react-tabs';
18
+ import * as RPNInput from 'react-phone-number-input';
18
19
 
19
20
  declare enum buttonVariantEnum {
20
21
  primary = "\n bg-button-primary-background-default\n hover:bg-button-primary-background-hover\n active:bg-button-primary-background-active\n focus:bg-button-primary-background-focus\n focus:ring-button-primary-border-focus\n text-button-primary-text\n ",
@@ -495,7 +496,13 @@ interface LinkProps extends HTMLAttributes<HTMLAnchorElement> {
495
496
  }
496
497
  declare const Link: React__default.ForwardRefExoticComponent<LinkProps & React__default.RefAttributes<HTMLAnchorElement>>;
497
498
 
498
- declare function InputPhone(): react_jsx_runtime.JSX.Element;
499
+ type InputPhoneProps = {
500
+ isError?: boolean;
501
+ defaultCountry?: RPNInput.Country;
502
+ onChange: (value: string) => void;
503
+ value?: string | null;
504
+ } & Omit<React__default.InputHTMLAttributes<HTMLInputElement>, 'onChange'>;
505
+ declare function InputPhone({ className, disabled, isError, defaultCountry, value, onChange, ...props }: InputPhoneProps): react_jsx_runtime.JSX.Element;
499
506
 
500
507
  interface SkeletonProps extends React__default.HTMLAttributes<HTMLDivElement> {
501
508
  }
package/dist/index.js CHANGED
@@ -179,7 +179,7 @@ var buttonVariantsConfig = classVarianceAuthority.cva(
179
179
  items-center
180
180
  justify-center
181
181
  whitespace-nowrap
182
- rounded-full
182
+ rounded-button
183
183
  font-semibold
184
184
  ring-offset-background
185
185
  transition-colors
@@ -2266,7 +2266,7 @@ var Option = (props) => {
2266
2266
  };
2267
2267
  var controlStyles = ({ isDisabled, isFocused }, isError) => {
2268
2268
  return cn(
2269
- "flex w-full items-center border bg-inputSelect-default-background rounded-[20px] px-4 min-h-10 transition",
2269
+ "flex w-full items-center border bg-inputSelect-default-background rounded-input px-4 min-h-10 transition",
2270
2270
  {
2271
2271
  "ring-[3px] border-inputSelect-focus-border text-inputSelect-focus-text ring-inputSelect-focus-border": isFocused,
2272
2272
  "border-inputSelect-danger-border text-inputSelect-danger-icon": isError,
@@ -2382,7 +2382,7 @@ var InputText = React8__namespace.forwardRef(
2382
2382
  {
2383
2383
  ref,
2384
2384
  className: cn(
2385
- "w-full h-10 outline-none rounded-[20px] text-sm leading-none font-medium",
2385
+ "w-full h-10 outline-none rounded-input text-sm leading-none font-medium",
2386
2386
  "bg-inputText-background-default disabled:bg-inputText-background-disabled",
2387
2387
  "border border-inputText-border-default focus:ring-[3px] focus:ring-inputText-border-focus focus:border-inputText-border-focus",
2388
2388
  "text-inputText-text-filled focus:text-inputText-text-focus placeholder:text-inputText-text-default disabled:text-inputText-text-disabled",
@@ -3569,31 +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 [valueState, setValueState] = React8.useState("");
3581
+ const [isFirstRender, setIsFirstRender] = React8.useState(true);
3580
3582
  const countryCode = defaultCountry ? RPNInput__namespace.getCountryCallingCode(defaultCountry) : null;
3581
- const valueCorrection = React8__namespace.default.useMemo(() => {
3582
- if (!value || !countryCode) return "";
3583
- const stringValue = value.toString().trim();
3584
- if (stringValue.startsWith("+")) {
3585
- return stringValue;
3586
- }
3587
- if (stringValue.startsWith(countryCode)) {
3588
- return `+${stringValue}`;
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("");
3589
3607
  }
3590
- return `+${countryCode}${stringValue}`;
3591
- }, [value, countryCode]);
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
+ );
3592
3619
  return /* @__PURE__ */ jsxRuntime.jsx(
3593
3620
  RPNInput__namespace.default,
3594
3621
  {
3595
3622
  className: cn(
3596
- "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",
3623
+ "flex w-full h-10 bg-inputText-background-default rounded-input border border-inputText-border-default focus-within:ring-[3px] focus-within:ring-inputText-border-focus focus-within:border-inputText-border-focus",
3597
3624
  { "bg-inputText-background-disabled": disabled },
3598
3625
  {
3599
3626
  "text-inputText-icon-danger border-inputText-border-danger focus-within:border-inputText-border-danger focus-within:ring-button-danger-border-focus": isError
@@ -3601,16 +3628,16 @@ function InputPhone({
3601
3628
  className
3602
3629
  ),
3603
3630
  flagComponent: FlagComponent,
3604
- limitMaxLength: true,
3605
3631
  countrySelectComponent: CountrySelect,
3606
3632
  inputComponent: PhoneInput,
3607
3633
  disabled,
3608
- value: valueCorrection,
3609
- onChange: (newValue) => onChange(newValue ?? ""),
3610
- defaultCountry,
3611
- countryCallingCodeEditable: true,
3612
3634
  international: true,
3613
- ...props
3635
+ limitMaxLength: true,
3636
+ defaultCountry: isFirstRender && (!value || value === "") ? defaultCountry : valueState ? defaultCountry : void 0,
3637
+ countryCallingCodeEditable: true,
3638
+ ...props,
3639
+ value: valueState,
3640
+ onChange: handleChange
3614
3641
  }
3615
3642
  );
3616
3643
  }
package/dist/index.mjs CHANGED
@@ -139,7 +139,7 @@ var buttonVariantsConfig = cva(
139
139
  items-center
140
140
  justify-center
141
141
  whitespace-nowrap
142
- rounded-full
142
+ rounded-button
143
143
  font-semibold
144
144
  ring-offset-background
145
145
  transition-colors
@@ -2226,7 +2226,7 @@ var Option = (props) => {
2226
2226
  };
2227
2227
  var controlStyles = ({ isDisabled, isFocused }, isError) => {
2228
2228
  return cn(
2229
- "flex w-full items-center border bg-inputSelect-default-background rounded-[20px] px-4 min-h-10 transition",
2229
+ "flex w-full items-center border bg-inputSelect-default-background rounded-input px-4 min-h-10 transition",
2230
2230
  {
2231
2231
  "ring-[3px] border-inputSelect-focus-border text-inputSelect-focus-text ring-inputSelect-focus-border": isFocused,
2232
2232
  "border-inputSelect-danger-border text-inputSelect-danger-icon": isError,
@@ -2342,7 +2342,7 @@ var InputText = React8.forwardRef(
2342
2342
  {
2343
2343
  ref,
2344
2344
  className: cn(
2345
- "w-full h-10 outline-none rounded-[20px] text-sm leading-none font-medium",
2345
+ "w-full h-10 outline-none rounded-input text-sm leading-none font-medium",
2346
2346
  "bg-inputText-background-default disabled:bg-inputText-background-disabled",
2347
2347
  "border border-inputText-border-default focus:ring-[3px] focus:ring-inputText-border-focus focus:border-inputText-border-focus",
2348
2348
  "text-inputText-text-filled focus:text-inputText-text-focus placeholder:text-inputText-text-default disabled:text-inputText-text-disabled",
@@ -3529,31 +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 [valueState, setValueState] = useState("");
3541
+ const [isFirstRender, setIsFirstRender] = useState(true);
3540
3542
  const countryCode = defaultCountry ? RPNInput.getCountryCallingCode(defaultCountry) : null;
3541
- const valueCorrection = React8__default.useMemo(() => {
3542
- if (!value || !countryCode) return "";
3543
- const stringValue = value.toString().trim();
3544
- if (stringValue.startsWith("+")) {
3545
- return stringValue;
3546
- }
3547
- if (stringValue.startsWith(countryCode)) {
3548
- return `+${stringValue}`;
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("");
3549
3567
  }
3550
- return `+${countryCode}${stringValue}`;
3551
- }, [value, countryCode]);
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
+ );
3552
3579
  return /* @__PURE__ */ jsx(
3553
3580
  RPNInput.default,
3554
3581
  {
3555
3582
  className: cn(
3556
- "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",
3583
+ "flex w-full h-10 bg-inputText-background-default rounded-input border border-inputText-border-default focus-within:ring-[3px] focus-within:ring-inputText-border-focus focus-within:border-inputText-border-focus",
3557
3584
  { "bg-inputText-background-disabled": disabled },
3558
3585
  {
3559
3586
  "text-inputText-icon-danger border-inputText-border-danger focus-within:border-inputText-border-danger focus-within:ring-button-danger-border-focus": isError
@@ -3561,16 +3588,16 @@ function InputPhone({
3561
3588
  className
3562
3589
  ),
3563
3590
  flagComponent: FlagComponent,
3564
- limitMaxLength: true,
3565
3591
  countrySelectComponent: CountrySelect,
3566
3592
  inputComponent: PhoneInput,
3567
3593
  disabled,
3568
- value: valueCorrection,
3569
- onChange: (newValue) => onChange(newValue ?? ""),
3570
- defaultCountry,
3571
- countryCallingCodeEditable: true,
3572
3594
  international: true,
3573
- ...props
3595
+ limitMaxLength: true,
3596
+ defaultCountry: isFirstRender && (!value || value === "") ? defaultCountry : valueState ? defaultCountry : void 0,
3597
+ countryCallingCodeEditable: true,
3598
+ ...props,
3599
+ value: valueState,
3600
+ onChange: handleChange
3574
3601
  }
3575
3602
  );
3576
3603
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikatec/nebula-react",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "React components",
5
5
  "publishConfig": {
6
6
  "access": "public"