@helpwave/hightide 0.8.0 → 0.8.1

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
@@ -2428,12 +2428,24 @@ declare const useFocusOnceVisible: (ref: RefObject<HTMLElement>, disable?: boole
2428
2428
  declare const useIsMounted: () => boolean;
2429
2429
 
2430
2430
  interface ControlledStateProps<T> {
2431
+ /**
2432
+ * The controlled value of the state.
2433
+ *
2434
+ * This is determines whether the state:
2435
+ * 1. (value !== undefined) => controlled
2436
+ * 2. (value === undefined) => uncontrolled
2437
+ *
2438
+ * If you need to include undefined as a valid state, you can set isControlled to true to force the component to be controlled.
2439
+ */
2431
2440
  value?: T;
2441
+ /** The callback whenever a setter changes the value */
2432
2442
  onValueChange?: (value: T) => void;
2443
+ /** The default value to use if the component is uncontrolled */
2433
2444
  defaultValue?: T;
2445
+ /** Forces the component to be controlled even if value is undefined */
2434
2446
  isControlled?: boolean;
2435
2447
  }
2436
- declare const useControlledState: <T>({ value, onValueChange, defaultValue, isControlled: isEnforcingControlled }: ControlledStateProps<T>) => [T, react__default.Dispatch<react__default.SetStateAction<T>>];
2448
+ declare const useControlledState: <T>({ value: controlledValue, onValueChange, defaultValue, isControlled: isEnforcingControlled }: ControlledStateProps<T>) => [T, react__default.Dispatch<react__default.SetStateAction<T>>];
2437
2449
 
2438
2450
  declare function useEventCallbackStabilizer<T extends (...args: any[]) => any>(callback?: T): (...args: Parameters<T>) => ReturnType<T>;
2439
2451
 
package/dist/index.d.ts CHANGED
@@ -2428,12 +2428,24 @@ declare const useFocusOnceVisible: (ref: RefObject<HTMLElement>, disable?: boole
2428
2428
  declare const useIsMounted: () => boolean;
2429
2429
 
2430
2430
  interface ControlledStateProps<T> {
2431
+ /**
2432
+ * The controlled value of the state.
2433
+ *
2434
+ * This is determines whether the state:
2435
+ * 1. (value !== undefined) => controlled
2436
+ * 2. (value === undefined) => uncontrolled
2437
+ *
2438
+ * If you need to include undefined as a valid state, you can set isControlled to true to force the component to be controlled.
2439
+ */
2431
2440
  value?: T;
2441
+ /** The callback whenever a setter changes the value */
2432
2442
  onValueChange?: (value: T) => void;
2443
+ /** The default value to use if the component is uncontrolled */
2433
2444
  defaultValue?: T;
2445
+ /** Forces the component to be controlled even if value is undefined */
2434
2446
  isControlled?: boolean;
2435
2447
  }
2436
- declare const useControlledState: <T>({ value, onValueChange, defaultValue, isControlled: isEnforcingControlled }: ControlledStateProps<T>) => [T, react__default.Dispatch<react__default.SetStateAction<T>>];
2448
+ declare const useControlledState: <T>({ value: controlledValue, onValueChange, defaultValue, isControlled: isEnforcingControlled }: ControlledStateProps<T>) => [T, react__default.Dispatch<react__default.SetStateAction<T>>];
2437
2449
 
2438
2450
  declare function useEventCallbackStabilizer<T extends (...args: any[]) => any>(callback?: T): (...args: Parameters<T>) => ReturnType<T>;
2439
2451
 
package/dist/index.js CHANGED
@@ -10378,28 +10378,34 @@ function resolveSetState(action, prev) {
10378
10378
 
10379
10379
  // src/hooks/useControlledState.ts
10380
10380
  var useControlledState = ({
10381
- value,
10381
+ value: controlledValue,
10382
10382
  onValueChange,
10383
10383
  defaultValue,
10384
10384
  isControlled: isEnforcingControlled
10385
10385
  }) => {
10386
- const [internalValue, setInternalValue] = (0, import_react26.useState)(defaultValue);
10387
- const [isControlled] = (0, import_react26.useState)(isEnforcingControlled || value !== void 0);
10386
+ const [internalValue, setInternalValue] = (0, import_react26.useState)(() => defaultValue);
10387
+ const [isControlled] = (0, import_react26.useState)(isEnforcingControlled || controlledValue !== void 0);
10388
10388
  const onValueChangeStable = useEventCallbackStabilizer(onValueChange);
10389
10389
  useLogOnce(
10390
10390
  "useControlledState: Attempted to change from controlled to uncontrolled or vice versa.For a controlled state: isControlled === true OR value !== undefinedFor an uncontrolled state: isControlled === false OR value === undefined",
10391
- isControlled !== (isEnforcingControlled || value !== void 0),
10391
+ isControlled !== (isEnforcingControlled || controlledValue !== void 0),
10392
10392
  { type: "error" }
10393
10393
  );
10394
- if (isControlled) {
10395
- return [value, onValueChangeStable];
10396
- }
10397
- const onChangeWrapper = (action) => {
10398
- const resolved = resolveSetState(action, internalValue);
10399
- setInternalValue(resolved);
10394
+ const lastValue = (0, import_react26.useRef)(isControlled ? controlledValue : internalValue);
10395
+ (0, import_react26.useEffect)(() => {
10396
+ lastValue.current = isControlled ? controlledValue : internalValue;
10397
+ }, [isControlled, controlledValue, internalValue]);
10398
+ const setState = (0, import_react26.useCallback)((action) => {
10399
+ const resolved = resolveSetState(action, lastValue.current);
10400
+ if (resolved === lastValue.current) return;
10401
+ if (!isControlled) {
10402
+ lastValue.current = resolved;
10403
+ setInternalValue(resolved);
10404
+ }
10400
10405
  onValueChangeStable(resolved);
10401
- };
10402
- return [internalValue, onChangeWrapper];
10406
+ }, [onValueChangeStable, isControlled]);
10407
+ const value = isControlled ? controlledValue : internalValue;
10408
+ return [value, setState];
10403
10409
  };
10404
10410
 
10405
10411
  // src/components/layout/Expandable.tsx
@@ -15613,16 +15619,16 @@ var Checkbox = ({
15613
15619
  onClick: (event) => {
15614
15620
  if (!disabled) {
15615
15621
  setValue((prev) => !prev);
15616
- props.onClick?.(event);
15617
15622
  }
15623
+ props.onClick?.(event);
15618
15624
  },
15619
15625
  onKeyDown: (event) => {
15620
15626
  if (disabled) return;
15621
15627
  if (event.key === " " || event.key === "Enter") {
15622
15628
  event.preventDefault();
15623
15629
  setValue((prev) => !prev);
15624
- props.onKeyDown?.(event);
15625
15630
  }
15631
+ props.onKeyDown?.(event);
15626
15632
  },
15627
15633
  "data-checked": !indeterminate ? value : "indeterminate",
15628
15634
  "data-size": size ?? void 0,