@jobber/components 6.98.0 → 6.98.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/Menu-cjs.js CHANGED
@@ -43,31 +43,38 @@ function Menu({ activator, items, UNSAFE_className, UNSAFE_style, }) {
43
43
  // useRefocusOnActivator must come before useFocusTrap for them both to work
44
44
  jobberHooks.useRefocusOnActivator(visible);
45
45
  const menuRef = jobberHooks.useFocusTrap(visible);
46
+ const isLargeScreen = width >= SMALL_SCREEN_BREAKPOINT;
47
+ const middleware = React.useMemo(() => {
48
+ if (isLargeScreen) {
49
+ return [
50
+ floatingUi_react.offset(MENU_OFFSET),
51
+ floatingUi_react.flip({ fallbackPlacements: ["bottom-end", "top-start", "top-end"] }),
52
+ floatingUi_react.size({
53
+ apply({ availableHeight, elements }) {
54
+ // The inner element is the scrollable menu that requires the max height
55
+ const menuElement = elements.floating.querySelector('[role="menu"]');
56
+ if (menuElement) {
57
+ const viewportHeight = window.innerHeight;
58
+ const maxHeightVh = (viewportHeight * MENU_MAX_HEIGHT_PERCENTAGE) / 100;
59
+ const maxHeight$1 = maxHeight.calculateMaxHeight(availableHeight, {
60
+ maxHeight: maxHeightVh,
61
+ });
62
+ Object.assign(menuElement.style, {
63
+ maxHeight: `${maxHeight$1}px`,
64
+ });
65
+ }
66
+ },
67
+ }),
68
+ ];
69
+ }
70
+ return [];
71
+ }, [isLargeScreen]);
46
72
  const { refs, floatingStyles, context } = floatingUi_react.useFloating({
47
73
  open: visible,
48
74
  onOpenChange: setVisible,
49
75
  placement: "bottom-start",
50
76
  strategy: "fixed",
51
- middleware: [
52
- floatingUi_react.offset(MENU_OFFSET),
53
- floatingUi_react.flip({ fallbackPlacements: ["bottom-end", "top-start", "top-end"] }),
54
- floatingUi_react.size({
55
- apply({ availableHeight, elements }) {
56
- // The inner element is the scrollable menu that requires the max height
57
- const menuElement = elements.floating.querySelector('[role="menu"]');
58
- if (menuElement) {
59
- const viewportHeight = window.innerHeight;
60
- const maxHeightVh = (viewportHeight * MENU_MAX_HEIGHT_PERCENTAGE) / 100;
61
- const maxHeight$1 = maxHeight.calculateMaxHeight(availableHeight, {
62
- maxHeight: maxHeightVh,
63
- });
64
- Object.assign(menuElement.style, {
65
- maxHeight: `${maxHeight$1}px`,
66
- });
67
- }
68
- },
69
- }),
70
- ],
77
+ middleware,
71
78
  elements: {
72
79
  reference: referenceElement,
73
80
  },
@@ -75,7 +82,7 @@ function Menu({ activator, items, UNSAFE_className, UNSAFE_style, }) {
75
82
  });
76
83
  const dismiss = floatingUi_react.useDismiss(context);
77
84
  const { getFloatingProps } = floatingUi_react.useInteractions([dismiss]);
78
- const positionAttributes = width >= SMALL_SCREEN_BREAKPOINT
85
+ const positionAttributes = isLargeScreen
79
86
  ? {
80
87
  style: floatingStyles,
81
88
  }
package/dist/Menu-es.js CHANGED
@@ -1,8 +1,8 @@
1
- import React__default, { useState, useId, useRef } from 'react';
1
+ import React__default, { useState, useId, useMemo, useRef } from 'react';
2
2
  import classnames from 'classnames';
3
3
  import { AnimatePresence, motion } from 'framer-motion';
4
4
  import { useWindowDimensions, useRefocusOnActivator, useFocusTrap, useIsMounted } from '@jobber/hooks';
5
- import { u as useFloating, a as useDismiss, b as useInteractions, F as FloatingPortal, o as offset, f as flip, s as size, c as autoUpdate } from './floating-ui.react-es.js';
5
+ import { o as offset, f as flip, s as size, u as useFloating, a as useDismiss, b as useInteractions, F as FloatingPortal, c as autoUpdate } from './floating-ui.react-es.js';
6
6
  import { B as Button } from './Button-es.js';
7
7
  import { T as Typography } from './Typography-es.js';
8
8
  import { I as Icon } from './Icon-es.js';
@@ -41,31 +41,38 @@ function Menu({ activator, items, UNSAFE_className, UNSAFE_style, }) {
41
41
  // useRefocusOnActivator must come before useFocusTrap for them both to work
42
42
  useRefocusOnActivator(visible);
43
43
  const menuRef = useFocusTrap(visible);
44
+ const isLargeScreen = width >= SMALL_SCREEN_BREAKPOINT;
45
+ const middleware = useMemo(() => {
46
+ if (isLargeScreen) {
47
+ return [
48
+ offset(MENU_OFFSET),
49
+ flip({ fallbackPlacements: ["bottom-end", "top-start", "top-end"] }),
50
+ size({
51
+ apply({ availableHeight, elements }) {
52
+ // The inner element is the scrollable menu that requires the max height
53
+ const menuElement = elements.floating.querySelector('[role="menu"]');
54
+ if (menuElement) {
55
+ const viewportHeight = window.innerHeight;
56
+ const maxHeightVh = (viewportHeight * MENU_MAX_HEIGHT_PERCENTAGE) / 100;
57
+ const maxHeight = calculateMaxHeight(availableHeight, {
58
+ maxHeight: maxHeightVh,
59
+ });
60
+ Object.assign(menuElement.style, {
61
+ maxHeight: `${maxHeight}px`,
62
+ });
63
+ }
64
+ },
65
+ }),
66
+ ];
67
+ }
68
+ return [];
69
+ }, [isLargeScreen]);
44
70
  const { refs, floatingStyles, context } = useFloating({
45
71
  open: visible,
46
72
  onOpenChange: setVisible,
47
73
  placement: "bottom-start",
48
74
  strategy: "fixed",
49
- middleware: [
50
- offset(MENU_OFFSET),
51
- flip({ fallbackPlacements: ["bottom-end", "top-start", "top-end"] }),
52
- size({
53
- apply({ availableHeight, elements }) {
54
- // The inner element is the scrollable menu that requires the max height
55
- const menuElement = elements.floating.querySelector('[role="menu"]');
56
- if (menuElement) {
57
- const viewportHeight = window.innerHeight;
58
- const maxHeightVh = (viewportHeight * MENU_MAX_HEIGHT_PERCENTAGE) / 100;
59
- const maxHeight = calculateMaxHeight(availableHeight, {
60
- maxHeight: maxHeightVh,
61
- });
62
- Object.assign(menuElement.style, {
63
- maxHeight: `${maxHeight}px`,
64
- });
65
- }
66
- },
67
- }),
68
- ],
75
+ middleware,
69
76
  elements: {
70
77
  reference: referenceElement,
71
78
  },
@@ -73,7 +80,7 @@ function Menu({ activator, items, UNSAFE_className, UNSAFE_style, }) {
73
80
  });
74
81
  const dismiss = useDismiss(context);
75
82
  const { getFloatingProps } = useInteractions([dismiss]);
76
- const positionAttributes = width >= SMALL_SCREEN_BREAKPOINT
83
+ const positionAttributes = isLargeScreen
77
84
  ? {
78
85
  style: floatingStyles,
79
86
  }
package/dist/styles.css CHANGED
@@ -2899,6 +2899,7 @@ a._7BLGtYNuJOU-.zgRx3ehZ2z8-:hover {
2899
2899
  right: 0;
2900
2900
  bottom: 0;
2901
2901
  left: 0;
2902
+ max-height: 70vh;
2902
2903
  }
2903
2904
  }
2904
2905
 
@@ -2909,6 +2910,7 @@ a._7BLGtYNuJOU-.zgRx3ehZ2z8-:hover {
2909
2910
  right: 0;
2910
2911
  bottom: 0;
2911
2912
  left: 0;
2913
+ max-height: 70vh;
2912
2914
  }
2913
2915
  }
2914
2916
 
@@ -0,0 +1,6 @@
1
+ export interface ViewportDimensions {
2
+ readonly width?: number;
3
+ readonly height?: number;
4
+ }
5
+ export declare function mockViewport({ width, height, }: ViewportDimensions): () => void;
6
+ export declare function withMockedViewport(dimensions: ViewportDimensions, run: () => Promise<void> | void): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jobber/components",
3
- "version": "6.98.0",
3
+ "version": "6.98.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -541,5 +541,5 @@
541
541
  "> 1%",
542
542
  "IE 10"
543
543
  ],
544
- "gitHead": "2a10b70a25ca29414cfddfa2daf3fc980e976efc"
544
+ "gitHead": "242c797fed244210585dd6254cba023fe5612925"
545
545
  }