next-helios-fe 1.8.117 → 1.8.119

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-helios-fe",
3
- "version": "1.8.117",
3
+ "version": "1.8.119",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1466,16 +1466,20 @@ export interface PhoneNumberProps
1466
1466
  width?: "full" | "fit";
1467
1467
  height?: "short" | "medium" | "high";
1468
1468
  };
1469
+ selectedCountryDialCode?: (dialCode: any) => void;
1469
1470
  }
1470
1471
 
1471
1472
  export const PhoneNumber: React.FC<PhoneNumberProps> = ({
1472
1473
  options,
1473
1474
  label,
1474
1475
  description,
1476
+ selectedCountryDialCode,
1475
1477
  ...rest
1476
1478
  }) => {
1477
- const inputRef = useRef<HTMLDivElement>(null);
1479
+ const inputRef = useRef<HTMLInputElement>(null);
1480
+ const divInputRef = useRef<HTMLDivElement>(null);
1478
1481
  const dropdownRef = useRef<HTMLButtonElement>(null);
1482
+ const [tempValue, setTempValue] = useState("");
1479
1483
  const [selectedCountry, setSelectedCountry] = useState("62");
1480
1484
  const [openDropdown, setOpenDropdown] = useState(false);
1481
1485
  const [dropdownWidth, setDropdownWidth] = useState<number>(0);
@@ -1497,12 +1501,38 @@ export const PhoneNumber: React.FC<PhoneNumberProps> = ({
1497
1501
 
1498
1502
  useEffect(() => {
1499
1503
  if (rest.value) {
1504
+ setTempValue(
1505
+ (rest.value as string).replace(
1506
+ new RegExp(
1507
+ `^${
1508
+ countryPhoneCode.find((item) =>
1509
+ (rest.value as string).startsWith(item.dial_code)
1510
+ )?.dial_code
1511
+ }`
1512
+ ),
1513
+ ""
1514
+ )
1515
+ );
1516
+
1500
1517
  setSelectedCountry(
1501
1518
  countryPhoneCode.find((item) =>
1502
1519
  (rest.value as string).startsWith(item.dial_code)
1503
1520
  )?.dial_code || ""
1504
1521
  );
1505
1522
  } else if (rest.defaultValue) {
1523
+ setTempValue(
1524
+ (rest.defaultValue as string).replace(
1525
+ new RegExp(
1526
+ `^${
1527
+ countryPhoneCode.find((item) =>
1528
+ (rest.value as string).startsWith(item.dial_code)
1529
+ )?.dial_code
1530
+ }`
1531
+ ),
1532
+ ""
1533
+ )
1534
+ );
1535
+
1506
1536
  setSelectedCountry(
1507
1537
  countryPhoneCode.find((item) =>
1508
1538
  (rest.defaultValue as string).startsWith(item.dial_code)
@@ -1511,6 +1541,20 @@ export const PhoneNumber: React.FC<PhoneNumberProps> = ({
1511
1541
  }
1512
1542
  }, [rest.value, rest.defaultValue]);
1513
1543
 
1544
+ useEffect(() => {
1545
+ if (tempValue.startsWith(selectedCountry)) {
1546
+ inputRef.current?.setCustomValidity("Please enter a valid phone number.");
1547
+ } else {
1548
+ inputRef.current?.setCustomValidity("");
1549
+ }
1550
+ }, [tempValue, selectedCountry]);
1551
+
1552
+ useEffect(() => {
1553
+ if (selectedCountryDialCode) {
1554
+ selectedCountryDialCode(selectedCountry);
1555
+ }
1556
+ }, [selectedCountryDialCode, selectedCountry]);
1557
+
1514
1558
  return (
1515
1559
  <div className="flex flex-row-reverse items-end">
1516
1560
  <label className={`flex flex-col gap-2 ${width}`}>
@@ -1536,25 +1580,30 @@ export const PhoneNumber: React.FC<PhoneNumberProps> = ({
1536
1580
  )}
1537
1581
  </div>
1538
1582
  )}
1539
- <div ref={inputRef} className="flex flex-row-reverse gap-4">
1583
+ <div ref={divInputRef} className="flex flex-row-reverse gap-4">
1540
1584
  <div className="relative flex-1 flex items-center">
1541
1585
  <div className="absolute left-0 flex justify-center w-14 border-r">
1542
1586
  <span className="text-disabled">{`+${selectedCountry}`}</span>
1543
1587
  </div>
1544
1588
  <input
1545
- type="number"
1589
+ ref={inputRef}
1590
+ type="text"
1546
1591
  className={`w-full ps-16 pe-4 border-default border rounded-md bg-secondary-bg [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none placeholder:duration-300 placeholder:translate-x-0 focus:placeholder:translate-x-1 placeholder:text-silent focus:outline-none focus:ring-1 focus:ring-primary focus:shadow focus:shadow-primary focus:border-primary-dark disabled:bg-secondary-light disabled:text-disabled ${height}`}
1547
1592
  placeholder="Phone number"
1548
1593
  required={rest.required}
1549
1594
  disabled={rest.disabled}
1550
- value={((rest.value || "") as string).split(selectedCountry)[1]}
1595
+ value={tempValue || ""}
1551
1596
  onChange={(e) => {
1552
- rest.onChange &&
1553
- rest.onChange({
1554
- target: {
1555
- value: `${selectedCountry}${e.target.value}`,
1556
- } as HTMLInputElement,
1557
- } as any);
1597
+ if (/^\d*$/.test(e.target.value)) {
1598
+ setTempValue(e.target.value);
1599
+
1600
+ rest.onChange &&
1601
+ rest.onChange({
1602
+ target: {
1603
+ value: `${selectedCountry}${e.target.value}`,
1604
+ } as HTMLInputElement,
1605
+ } as any);
1606
+ }
1558
1607
  }}
1559
1608
  />
1560
1609
  </div>
@@ -1583,7 +1632,7 @@ export const PhoneNumber: React.FC<PhoneNumberProps> = ({
1583
1632
  setOpenDropdown(true);
1584
1633
  dropdownRef.current?.click();
1585
1634
  setDropdownWidth(
1586
- inputRef?.current?.getBoundingClientRect()?.width || 0
1635
+ divInputRef?.current?.getBoundingClientRect()?.width || 0
1587
1636
  );
1588
1637
  }}
1589
1638
  />
@@ -636,14 +636,16 @@ export const Table: TableComponentProps = ({
636
636
  </Dropdown>
637
637
  )}
638
638
  {options?.toolbar?.search?.show !== false && (
639
- <Form.Search
640
- options={{ width: "fit" }}
641
- placeholder="Search..."
642
- value={search}
643
- onChange={(e) => {
644
- setSearch(e.target.value);
645
- }}
646
- />
639
+ <div className="min-w-40">
640
+ <Form.Search
641
+ options={{ width: "fit" }}
642
+ placeholder="Search..."
643
+ value={search}
644
+ onChange={(e) => {
645
+ setSearch(e.target.value);
646
+ }}
647
+ />
648
+ </div>
647
649
  )}
648
650
  {options?.toolbar?.export?.show !== false && (
649
651
  <Button