@youngonesworks/ui 0.1.117 → 0.1.118

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.cjs CHANGED
@@ -35,8 +35,8 @@ const date_fns = __toESM(require("date-fns"));
35
35
  const date_fns_locale = __toESM(require("date-fns/locale"));
36
36
  const react_dom = __toESM(require("react-dom"));
37
37
  const react_tooltip = __toESM(require("react-tooltip"));
38
- const __hooks_phone_usePhoneNumber = __toESM(require("@hooks/phone/usePhoneNumber"));
39
- const __hooks_phone_usePhoneNumberPrefix = __toESM(require("@hooks/phone/usePhoneNumberPrefix"));
38
+ const phone = __toESM(require("phone"));
39
+ const country_list_with_dial_code_and_flag = __toESM(require("country-list-with-dial-code-and-flag"));
40
40
  const __tiptap_extension_placeholder = __toESM(require("@tiptap/extension-placeholder"));
41
41
  const __tiptap_extension_underline = __toESM(require("@tiptap/extension-underline"));
42
42
  const __tiptap_react = __toESM(require("@tiptap/react"));
@@ -3078,10 +3078,63 @@ const UnorderedListItem = ({ children, actionItem, className, header = false,...
3078
3078
  })]
3079
3079
  });
3080
3080
 
3081
+ //#endregion
3082
+ //#region src/hooks/phone/usePhoneNumber.ts
3083
+ function usePhoneNumber() {
3084
+ /**
3085
+ * Validates a phone number and returns parsing results
3086
+ */
3087
+ const validatePhone = (0, react.useCallback)((phoneNumber, options) => (0, phone.default)(phoneNumber, options), []);
3088
+ /**
3089
+ * Strips the country code from a phone number
3090
+ * Example: +85265698900 -> 65698900
3091
+ */
3092
+ const stripCountryCode = (0, react.useCallback)((phoneNumber) => {
3093
+ const result = (0, phone.default)(phoneNumber);
3094
+ if (!result.isValid) return phoneNumber;
3095
+ return result.phoneNumber.replace(result.countryCode, "");
3096
+ }, []);
3097
+ /**
3098
+ * Returns the country code from a phone number
3099
+ * Example: +85265698900 -> +852
3100
+ */
3101
+ const getCountryCode = (0, react.useCallback)((phoneNumber) => {
3102
+ const result = (0, phone.default)(phoneNumber);
3103
+ if (!result.isValid) return phoneNumber;
3104
+ return result.countryCode;
3105
+ }, []);
3106
+ /**
3107
+ * Formats a phone number to international format with country code
3108
+ * Example: 0648711212 (with country: 'NL') -> +31648711212
3109
+ */
3110
+ const formatToInternational = (0, react.useCallback)((phoneNumber, options) => {
3111
+ const result = (0, phone.default)(phoneNumber, options);
3112
+ if (!result.isValid) return phoneNumber;
3113
+ return result.phoneNumber;
3114
+ }, []);
3115
+ return {
3116
+ validatePhone,
3117
+ stripCountryCode,
3118
+ getCountryCode,
3119
+ formatToInternational
3120
+ };
3121
+ }
3122
+
3123
+ //#endregion
3124
+ //#region src/hooks/phone/usePhoneNumberPrefix.ts
3125
+ const usePhoneNumberPrefix = (defaultCountry) => {
3126
+ const countryList = country_list_with_dial_code_and_flag.default.getAll();
3127
+ return countryList.filter((country) => country.dial_code).sort((a, b) => {
3128
+ if (a?.code === defaultCountry) return -1;
3129
+ if (b?.code === defaultCountry) return 1;
3130
+ return a.name.localeCompare(b.name);
3131
+ });
3132
+ };
3133
+
3081
3134
  //#endregion
3082
3135
  //#region src/components/phoneInput/index.tsx
3083
3136
  const CountrySelector = ({ searchPlaceholder, defaultCountry, ref }) => {
3084
- const phoneNumberPrefixes = (0, __hooks_phone_usePhoneNumberPrefix.usePhoneNumberPrefix)(defaultCountry);
3137
+ const phoneNumberPrefixes = usePhoneNumberPrefix(defaultCountry);
3085
3138
  const [selectedCountry, setSelectedCountry] = (0, react.useState)(phoneNumberPrefixes.find((country) => country.code === defaultCountry) || null);
3086
3139
  const [openDropdown, setOpenDropdown] = (0, react.useState)(false);
3087
3140
  const [searchQuery, setSearchQuery] = (0, react.useState)("");
@@ -3240,7 +3293,7 @@ const CountrySelector = ({ searchPlaceholder, defaultCountry, ref }) => {
3240
3293
  const PhoneInput = ({ placeholder, searchPlaceHolder, defaultCountry = "NL", invalidMessage, defaultValue, onChange, ref,...rest }) => {
3241
3294
  const inputRef = (0, react.useRef)(null);
3242
3295
  const [phoneNumber, setPhoneNumber] = (0, react.useState)(defaultValue || "");
3243
- const { validatePhone, stripCountryCode, getCountryCode, formatToInternational } = (0, __hooks_phone_usePhoneNumber.usePhoneNumber)();
3296
+ const { validatePhone, stripCountryCode, getCountryCode, formatToInternational } = usePhoneNumber();
3244
3297
  const countrySelectorRef = (0, react.useRef)(null);
3245
3298
  const [error, setError] = (0, react.useState)("");
3246
3299
  const filterPhoneInput = (value) => value.replace(/[^0-9+()]/g, "");