@lumx/react 4.2.0 → 4.2.1-alpha.0

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/package.json CHANGED
@@ -6,8 +6,8 @@
6
6
  "url": "https://github.com/lumapps/design-system/issues"
7
7
  },
8
8
  "dependencies": {
9
- "@lumx/core": "^4.2.0",
10
- "@lumx/icons": "^4.2.0",
9
+ "@lumx/core": "^4.2.1-alpha.0",
10
+ "@lumx/icons": "^4.2.1-alpha.0",
11
11
  "@popperjs/core": "^2.5.4",
12
12
  "body-scroll-lock": "^3.1.5",
13
13
  "react-popper": "^2.2.4"
@@ -81,11 +81,12 @@
81
81
  },
82
82
  "scripts": {
83
83
  "build": "rollup -c",
84
- "test": "vitest run",
84
+ "test": "vitest run --run",
85
85
  "type-check": "yarn tsc -p tsconfig.json",
86
86
  "start:storybook": "storybook dev -p 9000",
87
87
  "build:storybook": "storybook build"
88
88
  },
89
89
  "sideEffects": false,
90
- "version": "4.2.0"
90
+ "version": "4.2.1-alpha.0",
91
+ "stableVersion": "4.2.0"
91
92
  }
package/utils/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import React__default, { RefObject } from 'react';
1
+ import React__default, { RefObject, ReactNode, AriaAttributes } from 'react';
2
2
  import { Falsy } from '@lumx/core/js/types';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import { DisabledStateContextValue } from '@lumx/core/js/utils/disabledState';
@@ -33,6 +33,67 @@ interface ClickAwayProviderProps extends ClickAwayParameters {
33
33
  */
34
34
  declare const ClickAwayProvider: React.FC<ClickAwayProviderProps>;
35
35
 
36
+ type EventCallback = (evt?: Event) => void;
37
+ interface InfiniteScrollProps {
38
+ callback: EventCallback;
39
+ options?: IntersectionObserverInit;
40
+ }
41
+ /**
42
+ * Handles basic callback pattern by using intersection observers.
43
+ *
44
+ * @param {Function} callback The callback to execute once the element is in the viewport or is intersecting
45
+ * with its root element.
46
+ * @param {Object} options The set of options we want to set to the intersection observer.
47
+ * @return {Element} The Infinite scroll element.
48
+ */
49
+ declare const InfiniteScroll: React__default.FC<InfiniteScrollProps>;
50
+
51
+ interface A11YLiveMessageProps {
52
+ /** The message that will be read. */
53
+ children?: ReactNode;
54
+ /** Whether the message should be hidden */
55
+ hidden?: boolean;
56
+ /**
57
+ * The type of message.
58
+ * Default to "polite"
59
+ * Assertive should only be used for messages than need immediate attention.
60
+ */
61
+ type?: AriaAttributes['aria-live'];
62
+ /**
63
+ * Indicates whether assistive technologies will present all, or only parts of, the changed region based on
64
+ * the change notifications defined by the aria-relevant attribute.
65
+ */
66
+ atomic?: AriaAttributes['aria-atomic'];
67
+ /**
68
+ * Indicates what notifications the user agent will trigger when the accessibility tree within a live region is modified.
69
+ * @see atomic.
70
+ */
71
+ relevant?: AriaAttributes['aria-relevant'];
72
+ /**
73
+ * Whether the live region reads a current status or
74
+ * raises an alert.
75
+ * Only use `alert` for time sensitive information that should be read immediately
76
+ * as it will interrupt anything being currently read.
77
+ */
78
+ role?: 'status' | 'alert';
79
+ /** Scope, for tracking purposes */
80
+ scope?: string;
81
+ /** Optionnal classname */
82
+ className?: string;
83
+ }
84
+ /**
85
+ * Live region to read a message to screen readers.
86
+ * Messages can be "polite" and be read when possible or
87
+ * "assertive" and interrupt any message currently be read. (To be used sparingly)
88
+ *
89
+ * More information here: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Live_Regions
90
+ *
91
+ * @family A11Y
92
+ * @param A11YLiveMessageProps
93
+ * @returns A11YLiveMessage
94
+ */
95
+ declare const A11YLiveMessage: React__default.FC<A11YLiveMessageProps>;
96
+
36
97
  type Container = DocumentFragment | Element;
37
98
  /**
38
99
  * Portal initializing function.
@@ -335,5 +396,5 @@ type Output = [
335
396
  */
336
397
  declare const useRovingTabIndex: (...args: BaseHookOptions) => Output;
337
398
 
338
- export { ClickAwayProvider, DisabledStateProvider, MovingFocusContext, MovingFocusProvider, Portal, PortalProvider, useDisabledStateContext, useRovingTabIndex, useVirtualFocus, useVirtualFocusParent };
339
- export type { PortalInit, PortalProps, PortalProviderProps };
399
+ export { A11YLiveMessage, ClickAwayProvider, DisabledStateProvider, InfiniteScroll, MovingFocusContext, MovingFocusProvider, Portal, PortalProvider, useDisabledStateContext, useRovingTabIndex, useVirtualFocus, useVirtualFocusParent };
400
+ export type { A11YLiveMessageProps, InfiniteScrollProps, PortalInit, PortalProps, PortalProviderProps };
package/utils/index.js CHANGED
@@ -1,14 +1,100 @@
1
- export { C as ClickAwayProvider, D as DisabledStateProvider, P as Portal, a as PortalProvider, u as useDisabledStateContext } from '../_internal/DpdvhbTO.js';
2
1
  import React__default, { useEffect } from 'react';
2
+ import { join, visuallyHidden } from '@lumx/core/js/utils/classNames';
3
+ import { jsx } from 'react/jsx-runtime';
4
+ export { C as ClickAwayProvider, D as DisabledStateProvider, P as Portal, a as PortalProvider, u as useDisabledStateContext } from '../_internal/DpdvhbTO.js';
3
5
  import noop from 'lodash/noop';
4
6
  import findLast from 'lodash/findLast';
5
7
  import find from 'lodash/find';
6
8
  import findLastIndex from 'lodash/findLastIndex';
7
9
  import isNil from 'lodash/isNil';
8
10
  import groupBy from 'lodash/groupBy';
9
- import { jsx } from 'react/jsx-runtime';
10
11
  import uniqueId from 'lodash/uniqueId';
11
12
 
13
+ // The error margin in px we want to have for triggering infinite scroll
14
+ const CLASSNAME = 'lumx-infinite-scroll-anchor';
15
+ /**
16
+ * Handles basic callback pattern by using intersection observers.
17
+ *
18
+ * @param {Function} callback The callback to execute once the element is in the viewport or is intersecting
19
+ * with its root element.
20
+ * @param {Object} options The set of options we want to set to the intersection observer.
21
+ * @return {Element} The Infinite scroll element.
22
+ */
23
+ const InfiniteScroll = ({
24
+ callback,
25
+ options
26
+ }) => {
27
+ const elementRef = React__default.useRef(null);
28
+ useEffect(() => {
29
+ const observer = new IntersectionObserver((entries = []) => {
30
+ const hasIntersection = entries.some(entry => entry.isIntersecting);
31
+
32
+ // Make sure at least one target element has intersected with the root element.
33
+ if (!hasIntersection) {
34
+ return;
35
+ }
36
+ callback();
37
+ }, options);
38
+ const currentRef = elementRef.current;
39
+ if (elementRef && elementRef.current) {
40
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
41
+ // @ts-ignore
42
+ observer.observe(elementRef.current);
43
+ }
44
+ return () => {
45
+ if (currentRef) {
46
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
47
+ // @ts-ignore
48
+ observer.unobserve(currentRef);
49
+ }
50
+ };
51
+ // eslint-disable-next-line react-hooks/exhaustive-deps
52
+ }, [elementRef.current, callback]);
53
+
54
+ // In order to avoid issues when a zoom is added to the browser, we add a small height to the div so that
55
+ // the intersection has a higher chance of working correctly.
56
+ return /*#__PURE__*/jsx("div", {
57
+ ref: elementRef,
58
+ "aria-hidden": "true",
59
+ className: CLASSNAME,
60
+ style: {
61
+ height: '4px'
62
+ }
63
+ });
64
+ };
65
+
66
+ /**
67
+ * Live region to read a message to screen readers.
68
+ * Messages can be "polite" and be read when possible or
69
+ * "assertive" and interrupt any message currently be read. (To be used sparingly)
70
+ *
71
+ * More information here: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Live_Regions
72
+ *
73
+ * @family A11Y
74
+ * @param A11YLiveMessageProps
75
+ * @returns A11YLiveMessage
76
+ */
77
+ const A11YLiveMessage = ({
78
+ type = 'polite',
79
+ atomic,
80
+ role,
81
+ hidden,
82
+ relevant,
83
+ children,
84
+ className,
85
+ ...forwardedProps
86
+ }) => {
87
+ return /*#__PURE__*/jsx("div", {
88
+ ...forwardedProps,
89
+ className: join(hidden ? visuallyHidden() : undefined, className),
90
+ role: role,
91
+ "aria-live": type,
92
+ "aria-atomic": atomic,
93
+ "aria-relevant": relevant,
94
+ children: children
95
+ });
96
+ };
97
+
12
98
  /**
13
99
  * Create a map from the given tab stop to sort them by rowKey;
14
100
  */
@@ -1403,5 +1489,5 @@ const useRovingTabIndex = (ref, disabled = false, rowKey = null, autofocus = fal
1403
1489
  return [tabIndex, focused, handleKeyDown, handleClick];
1404
1490
  };
1405
1491
 
1406
- export { MovingFocusContext, MovingFocusProvider, useRovingTabIndex, useVirtualFocus, useVirtualFocusParent };
1492
+ export { A11YLiveMessage, InfiniteScroll, MovingFocusContext, MovingFocusProvider, useRovingTabIndex, useVirtualFocus, useVirtualFocusParent };
1407
1493
  //# sourceMappingURL=index.js.map