@bricks-toolkit/toolkit 0.1.13 → 0.1.15

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.
@@ -1,5 +1,5 @@
1
1
  import { cn } from './chunk-OCPFOFJ4.mjs';
2
- import { forwardRef, useId, useState, useRef, useEffect } from 'react';
2
+ import { forwardRef, useId, useState, useRef, useMemo, useEffect } from 'react';
3
3
  import { ChevronDownIcon, XMarkIcon } from '@heroicons/react/20/solid';
4
4
  import { jsxs, jsx } from 'react/jsx-runtime';
5
5
 
@@ -212,7 +212,7 @@ var Phone = forwardRef(function Phone2({
212
212
  const [isOpen, setIsOpen] = useState(false);
213
213
  const [searchTerm, setSearchTerm] = useState("");
214
214
  const dropdownRef = useRef(null);
215
- const initialDialCode = (() => {
215
+ const initialDialCode = useMemo(() => {
216
216
  if (defaultCountry) {
217
217
  const country = COUNTRIES.find(
218
218
  (c) => c.id.toLowerCase() === defaultCountry.toLowerCase()
@@ -220,10 +220,18 @@ var Phone = forwardRef(function Phone2({
220
220
  if (country) return country.dialCode;
221
221
  }
222
222
  return defaultCountryCode;
223
- })();
223
+ }, [defaultCountry, defaultCountryCode]);
224
224
  const [internalPhone, setInternalPhone] = useState(
225
225
  defaultValue ?? { countryCode: initialDialCode, phoneNumber: "" }
226
226
  );
227
+ useEffect(() => {
228
+ if (!defaultValue && !value && internalPhone.phoneNumber === "") {
229
+ setInternalPhone((prev) => ({
230
+ ...prev,
231
+ countryCode: initialDialCode
232
+ }));
233
+ }
234
+ }, [initialDialCode, defaultValue, value]);
227
235
  const isControlled = value !== void 0;
228
236
  const currentPhone = isControlled ? value : internalPhone;
229
237
  const activeCountry = COUNTRIES.find((c) => c.dialCode === currentPhone.countryCode) ?? COUNTRIES[0];
@@ -214,7 +214,7 @@ var Phone = react.forwardRef(function Phone2({
214
214
  const [isOpen, setIsOpen] = react.useState(false);
215
215
  const [searchTerm, setSearchTerm] = react.useState("");
216
216
  const dropdownRef = react.useRef(null);
217
- const initialDialCode = (() => {
217
+ const initialDialCode = react.useMemo(() => {
218
218
  if (defaultCountry) {
219
219
  const country = COUNTRIES.find(
220
220
  (c) => c.id.toLowerCase() === defaultCountry.toLowerCase()
@@ -222,10 +222,18 @@ var Phone = react.forwardRef(function Phone2({
222
222
  if (country) return country.dialCode;
223
223
  }
224
224
  return defaultCountryCode;
225
- })();
225
+ }, [defaultCountry, defaultCountryCode]);
226
226
  const [internalPhone, setInternalPhone] = react.useState(
227
227
  defaultValue ?? { countryCode: initialDialCode, phoneNumber: "" }
228
228
  );
229
+ react.useEffect(() => {
230
+ if (!defaultValue && !value && internalPhone.phoneNumber === "") {
231
+ setInternalPhone((prev) => ({
232
+ ...prev,
233
+ countryCode: initialDialCode
234
+ }));
235
+ }
236
+ }, [initialDialCode, defaultValue, value]);
229
237
  const isControlled = value !== void 0;
230
238
  const currentPhone = isControlled ? value : internalPhone;
231
239
  const activeCountry = COUNTRIES.find((c) => c.dialCode === currentPhone.countryCode) ?? COUNTRIES[0];
package/dist/index.cjs CHANGED
@@ -16,7 +16,7 @@ var chunkS7VEND5Z_cjs = require('./chunk-S7VEND5Z.cjs');
16
16
  var chunk56ILK7Y4_cjs = require('./chunk-56ILK7Y4.cjs');
17
17
  var chunkNRZIXK35_cjs = require('./chunk-NRZIXK35.cjs');
18
18
  var chunk5RKET2JO_cjs = require('./chunk-5RKET2JO.cjs');
19
- var chunkB2FU2E2X_cjs = require('./chunk-B2FU2E2X.cjs');
19
+ var chunkMP3GFB25_cjs = require('./chunk-MP3GFB25.cjs');
20
20
  var chunkVRZFAKSV_cjs = require('./chunk-VRZFAKSV.cjs');
21
21
  var chunk7R5JRJ2W_cjs = require('./chunk-7R5JRJ2W.cjs');
22
22
  var chunkOEU5VG3D_cjs = require('./chunk-OEU5VG3D.cjs');
@@ -697,7 +697,7 @@ Object.defineProperty(exports, "PasswordInput", {
697
697
  });
698
698
  Object.defineProperty(exports, "Phone", {
699
699
  enumerable: true,
700
- get: function () { return chunkB2FU2E2X_cjs.Phone; }
700
+ get: function () { return chunkMP3GFB25_cjs.Phone; }
701
701
  });
702
702
  Object.defineProperty(exports, "RadioButton", {
703
703
  enumerable: true,
package/dist/index.mjs CHANGED
@@ -14,7 +14,7 @@ export { Skeleton, SkeletonAvatar, SkeletonCard, SkeletonTable, SkeletonText } f
14
14
  export { MultiSelect } from './chunk-JKPNJ4PZ.mjs';
15
15
  export { OtpInput } from './chunk-RYWDZHKG.mjs';
16
16
  export { PasswordInput } from './chunk-446OJWC6.mjs';
17
- export { Phone } from './chunk-TBMIMUU4.mjs';
17
+ export { Phone } from './chunk-C2MMUQPD.mjs';
18
18
  export { RadioButton } from './chunk-DN2GFJF4.mjs';
19
19
  export { Select } from './chunk-TIVSMCXZ.mjs';
20
20
  export { Pagination, Table } from './chunk-7364SUK6.mjs';
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
- var chunkB2FU2E2X_cjs = require('../chunk-B2FU2E2X.cjs');
3
+ var chunkMP3GFB25_cjs = require('../chunk-MP3GFB25.cjs');
4
4
  require('../chunk-L5VQZZVR.cjs');
5
5
 
6
6
 
7
7
 
8
8
  Object.defineProperty(exports, "Phone", {
9
9
  enumerable: true,
10
- get: function () { return chunkB2FU2E2X_cjs.Phone; }
10
+ get: function () { return chunkMP3GFB25_cjs.Phone; }
11
11
  });
@@ -1,2 +1,2 @@
1
- export { Phone } from '../chunk-TBMIMUU4.mjs';
1
+ export { Phone } from '../chunk-C2MMUQPD.mjs';
2
2
  import '../chunk-OCPFOFJ4.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bricks-toolkit/toolkit",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "Micro-modularized, fully independent, type-safe UI component library",
5
5
  "license": "MIT",
6
6
  "author": "ITProfound",