@lime-bundles/react 7.3.0 → 7.3.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.js CHANGED
@@ -3076,6 +3076,8 @@ function normalizeText2(str) {
3076
3076
  return str.normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase();
3077
3077
  }
3078
3078
  var FILTERS_ALL2 = "__all__";
3079
+ var STEP_CASCADE_MS = 500;
3080
+ var AUTO_ADVANCE_HOLD_MS = 160;
3079
3081
  function MultiStepPicker({
3080
3082
  bundle,
3081
3083
  currency,
@@ -3099,6 +3101,8 @@ function MultiStepPicker({
3099
3101
  const closeBtnRef = useRef7(null);
3100
3102
  const listRef = useRef7(null);
3101
3103
  const mouseDownTarget = useRef7(null);
3104
+ const cascadeTimer = useRef7(null);
3105
+ const autoAdvanceTimer = useRef7(null);
3102
3106
  const [open, setOpen] = useState11(false);
3103
3107
  const [stepIndex, setStepIndex] = useState11(
3104
3108
  () => Math.max(0, Math.min(steps.length - 1, initialStep))
@@ -3134,6 +3138,14 @@ function MultiStepPicker({
3134
3138
  const id = requestAnimationFrame(() => setOpen(true));
3135
3139
  return () => cancelAnimationFrame(id);
3136
3140
  }, []);
3141
+ useEffect14(() => {
3142
+ return () => {
3143
+ if (cascadeTimer.current !== null) clearTimeout(cascadeTimer.current);
3144
+ if (autoAdvanceTimer.current !== null) {
3145
+ clearTimeout(autoAdvanceTimer.current);
3146
+ }
3147
+ };
3148
+ }, []);
3137
3149
  useScrollLock(true);
3138
3150
  useFocusTrap({
3139
3151
  active: true,
@@ -3162,12 +3174,36 @@ function MultiStepPicker({
3162
3174
  lastSeen.current = { step: stepIndex, units: unitsInStep };
3163
3175
  if (!autoAdvance || isLastStep || prev.step !== stepIndex) return;
3164
3176
  if (unitsInStep <= prev.units) return;
3165
- if (stepHeadroom(step?.maxQuantity ?? null, unitsInStep) === 0) {
3166
- goToStep(stepIndex + 1);
3177
+ if (stepHeadroom(step?.maxQuantity ?? null, unitsInStep) !== 0) return;
3178
+ const from = stepIndex;
3179
+ if (autoAdvanceTimer.current !== null) {
3180
+ clearTimeout(autoAdvanceTimer.current);
3167
3181
  }
3182
+ autoAdvanceTimer.current = setTimeout(() => {
3183
+ autoAdvanceTimer.current = null;
3184
+ goToStep(from + 1);
3185
+ }, AUTO_ADVANCE_HOLD_MS);
3168
3186
  });
3169
3187
  function goToStep(i) {
3170
3188
  const clamped = Math.max(0, Math.min(steps.length - 1, i));
3189
+ if (autoAdvanceTimer.current !== null) {
3190
+ clearTimeout(autoAdvanceTimer.current);
3191
+ autoAdvanceTimer.current = null;
3192
+ }
3193
+ const dialog = dialogRef.current;
3194
+ if (dialog && clamped !== stepIndex) {
3195
+ if (cascadeTimer.current !== null) clearTimeout(cascadeTimer.current);
3196
+ dialog.removeAttribute("data-step-transition");
3197
+ void dialog.offsetHeight;
3198
+ dialog.setAttribute(
3199
+ "data-step-transition",
3200
+ clamped > stepIndex ? "forward" : "back"
3201
+ );
3202
+ cascadeTimer.current = setTimeout(() => {
3203
+ cascadeTimer.current = null;
3204
+ dialog.removeAttribute("data-step-transition");
3205
+ }, STEP_CASCADE_MS);
3206
+ }
3171
3207
  setStepIndex(clamped);
3172
3208
  setQuery("");
3173
3209
  setActiveType(FILTERS_ALL2);