@lumx/react 3.20.1-alpha.36 → 3.20.1-alpha.38

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.
Files changed (106) hide show
  1. package/index.d.ts +4 -15
  2. package/index.js +13966 -64
  3. package/index.js.map +1 -0
  4. package/package.json +3 -3
  5. package/utils/index.js +159 -3
  6. package/utils/index.js.map +1 -0
  7. package/_internal/035c132d.js +0 -314
  8. package/_internal/0b9c76cb.js +0 -5
  9. package/_internal/0ea95af1.js +0 -819
  10. package/_internal/230173a8.js +0 -12
  11. package/_internal/2a3d237c.js +0 -11
  12. package/_internal/2c2b6a89.js +0 -51
  13. package/_internal/3181f000.js +0 -13
  14. package/_internal/36bd7352.js +0 -218
  15. package/_internal/3864a6c1.js +0 -436
  16. package/_internal/3a1facc0.js +0 -17
  17. package/_internal/49bbeed3.js +0 -5
  18. package/_internal/4daccdd5.js +0 -24
  19. package/_internal/4f4c0582.js +0 -2169
  20. package/_internal/5cef5e8c.js +0 -74
  21. package/_internal/6a60381c.js +0 -117
  22. package/_internal/6f084a40.js +0 -111
  23. package/_internal/76ddefd4.js +0 -61
  24. package/_internal/78df9309.js +0 -19
  25. package/_internal/7ad474e4.js +0 -98
  26. package/_internal/7b293665.js +0 -19
  27. package/_internal/7daf0f24.js +0 -76
  28. package/_internal/825ac334.js +0 -129
  29. package/_internal/827b804a.js +0 -5
  30. package/_internal/8bce732e.js +0 -8
  31. package/_internal/9d1336a1.js +0 -18
  32. package/_internal/a38bdcd0.js +0 -49
  33. package/_internal/b326655a.js +0 -682
  34. package/_internal/b83e864b.js +0 -76
  35. package/_internal/bace1bf1.js +0 -103
  36. package/_internal/c57190eb.js +0 -146
  37. package/_internal/components/alert-dialog/index-284fed80.js +0 -163
  38. package/_internal/components/autocomplete/__mockData__/index-96fc7ea7.js +0 -27
  39. package/_internal/components/autocomplete/index-27a49d5d.js +0 -261
  40. package/_internal/components/avatar/index-b8bc3cae.js +0 -83
  41. package/_internal/components/badge/index-9880f056.js +0 -81
  42. package/_internal/components/button/index-d919f96d.js +0 -47
  43. package/_internal/components/checkbox/index-dd478de9.js +0 -143
  44. package/_internal/components/chip/index-7f84cdbd.js +0 -102
  45. package/_internal/components/comment-block/index-e942de30.js +0 -138
  46. package/_internal/components/date-picker/index-a258d3ce.js +0 -596
  47. package/_internal/components/dialog/index-c7066813.js +0 -238
  48. package/_internal/components/divider/index-b6934baf.js +0 -50
  49. package/_internal/components/drag-handle/index-80e5af6c.js +0 -52
  50. package/_internal/components/dropdown/index-cebfc268.js +0 -147
  51. package/_internal/components/expansion-panel/index-9d45a211.js +0 -167
  52. package/_internal/components/flag/index-33e9d909.js +0 -59
  53. package/_internal/components/flex-box/index-0d6b6b43.js +0 -56
  54. package/_internal/components/generic-block/index-836c4352.js +0 -124
  55. package/_internal/components/grid/index-8c16a4f1.js +0 -104
  56. package/_internal/components/grid-column/index-4a2f56bb.js +0 -59
  57. package/_internal/components/heading/index-fd558a9a.js +0 -53
  58. package/_internal/components/icon/index-e7b9b40e.js +0 -1
  59. package/_internal/components/image-block/index-7021c2f1.js +0 -110
  60. package/_internal/components/image-lightbox/index-27017547.js +0 -759
  61. package/_internal/components/inline-list/index-52efec7f.js +0 -74
  62. package/_internal/components/input-helper/index-5a837e7c.js +0 -71
  63. package/_internal/components/input-label/index-0113f382.js +0 -59
  64. package/_internal/components/lightbox/index-fad5a9f2.js +0 -155
  65. package/_internal/components/link/index-008bae4b.js +0 -72
  66. package/_internal/components/link-preview/index-3e9c32f2.js +0 -117
  67. package/_internal/components/list/index-da88c6e9.js +0 -71
  68. package/_internal/components/message/index-17b568f2.js +0 -98
  69. package/_internal/components/mosaic/index-2d40e01c.js +0 -95
  70. package/_internal/components/navigation/index-dc17c639.js +0 -225
  71. package/_internal/components/notification/index-a1101015.js +0 -146
  72. package/_internal/components/popover/index-dbca63f1.js +0 -2
  73. package/_internal/components/popover-dialog/index-654d2abc.js +0 -66
  74. package/_internal/components/post-block/index-4b6b4dcb.js +0 -109
  75. package/_internal/components/progress/index-6f578c31.js +0 -182
  76. package/_internal/components/progress-tracker/index-700bc4c2.js +0 -309
  77. package/_internal/components/radio-button/index-89b725af.js +0 -149
  78. package/_internal/components/select/index-2755aa32.js +0 -458
  79. package/_internal/components/side-navigation/index-0bbe1fdd.js +0 -165
  80. package/_internal/components/skeleton/index-b2f8501c.js +0 -166
  81. package/_internal/components/slider/index-4f9b891b.js +0 -311
  82. package/_internal/components/slideshow/index-d4604589.js +0 -150
  83. package/_internal/components/switch/index-58fe0f0c.js +0 -122
  84. package/_internal/components/table/index-d541aa88.js +0 -297
  85. package/_internal/components/tabs/index-af1538d6.js +0 -298
  86. package/_internal/components/text/index-5bfc6d5e.js +0 -1
  87. package/_internal/components/text-field/index-47c98d09.js +0 -360
  88. package/_internal/components/thumbnail/index-71545d95.js +0 -41
  89. package/_internal/components/toolbar/index-7041a5a6.js +0 -61
  90. package/_internal/components/tooltip/index-8bb97e60.js +0 -327
  91. package/_internal/components/uploader/index-8f6f55de.js +0 -153
  92. package/_internal/components/user-block/index-70d4ce8f.js +0 -145
  93. package/_internal/d0e3f49e.js +0 -23
  94. package/_internal/de24f857.js +0 -3
  95. package/_internal/e806b848.js +0 -8
  96. package/_internal/e913a3af.js +0 -117
  97. package/_internal/ea04260d.js +0 -28
  98. package/_internal/eaf6c45a.js +0 -3
  99. package/_internal/ebdcb0c7.js +0 -60
  100. package/_internal/ef5d1aac.js +0 -3
  101. package/_internal/f0d7d6ea.js +0 -29
  102. package/_internal/utils/ClickAwayProvider/index-1234ce76.js +0 -94
  103. package/_internal/utils/MaterialThemeSwitcher/index-8d22de5a.js +0 -48
  104. package/_internal/utils/Portal/index-6e0a7404.js +0 -44
  105. package/_internal/utils/disabled/index-075b99c3.js +0 -36
  106. package/_internal/utils/type/index-ea9fc197.js +0 -2
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": "^3.20.1-alpha.36",
10
- "@lumx/icons": "^3.20.1-alpha.36",
9
+ "@lumx/core": "^3.20.1-alpha.38",
10
+ "@lumx/icons": "^3.20.1-alpha.38",
11
11
  "@popperjs/core": "^2.5.4",
12
12
  "body-scroll-lock": "^3.1.5",
13
13
  "classnames": "^2.3.2",
@@ -90,5 +90,5 @@
90
90
  "build:storybook": "storybook build"
91
91
  },
92
92
  "sideEffects": false,
93
- "version": "3.20.1-alpha.36"
93
+ "version": "3.20.1-alpha.38"
94
94
  }
package/utils/index.js CHANGED
@@ -1,3 +1,159 @@
1
- export { ClickAwayProvider } from '../_internal/utils/ClickAwayProvider/index-1234ce76.js';
2
- export { Portal, PortalProvider } from '../_internal/utils/Portal/index-6e0a7404.js';
3
- export { D as DisabledStateProvider, u as useDisabledStateContext } from '../_internal/ea04260d.js';
1
+ import React__default, { useContext, useEffect, useMemo, useRef, createContext } from 'react';
2
+ import { isEmpty } from '@lumx/core/js/utils/collection/isEmpty';
3
+ import { jsx, Fragment } from 'react/jsx-runtime';
4
+ import { createPortal } from 'react-dom';
5
+
6
+ const DisabledStateContext = /*#__PURE__*/React__default.createContext({
7
+ state: null
8
+ });
9
+ /**
10
+ * Disabled state provider.
11
+ * All nested LumX Design System components inherit this disabled state.
12
+ */
13
+ function DisabledStateProvider({
14
+ children,
15
+ ...value
16
+ }) {
17
+ return /*#__PURE__*/jsx(DisabledStateContext.Provider, {
18
+ value: value,
19
+ children: children
20
+ });
21
+ }
22
+
23
+ /**
24
+ * Get DisabledState context value
25
+ */
26
+ function useDisabledStateContext() {
27
+ return useContext(DisabledStateContext);
28
+ }
29
+
30
+ const EVENT_TYPES = ['mousedown', 'touchstart'];
31
+ function isClickAway(targets, refs) {
32
+ // The targets elements are not contained in any of the listed element references.
33
+ return !refs.some(ref => targets.some(target => ref?.current?.contains(target)));
34
+ }
35
+ /**
36
+ * Listen to clicks away from the given elements and callback the passed in function.
37
+ *
38
+ * Warning: If you need to detect click away on nested React portals, please use the `ClickAwayProvider` component.
39
+ */
40
+ function useClickAway({
41
+ callback,
42
+ childrenRefs
43
+ }) {
44
+ useEffect(() => {
45
+ const {
46
+ current: currentRefs
47
+ } = childrenRefs;
48
+ if (!callback || !currentRefs || isEmpty(currentRefs)) {
49
+ return undefined;
50
+ }
51
+ const listener = evt => {
52
+ const targets = [evt.composedPath?.()[0], evt.target];
53
+ if (isClickAway(targets, currentRefs)) {
54
+ callback(evt);
55
+ }
56
+ };
57
+ EVENT_TYPES.forEach(evtType => document.addEventListener(evtType, listener));
58
+ return () => {
59
+ EVENT_TYPES.forEach(evtType => document.removeEventListener(evtType, listener));
60
+ };
61
+ }, [callback, childrenRefs]);
62
+ }
63
+
64
+ const ClickAwayAncestorContext = /*#__PURE__*/createContext(null);
65
+ /**
66
+ * Component combining the `useClickAway` hook with a React context to hook into the React component tree and make sure
67
+ * we take into account both the DOM tree and the React tree to detect click away.
68
+ *
69
+ * @return the react component.
70
+ */
71
+ const ClickAwayProvider = ({
72
+ children,
73
+ callback,
74
+ childrenRefs,
75
+ parentRef
76
+ }) => {
77
+ const parentContext = useContext(ClickAwayAncestorContext);
78
+ const currentContext = useMemo(() => {
79
+ const context = {
80
+ childrenRefs: [],
81
+ /**
82
+ * Add element refs to the current context and propagate to the parent context.
83
+ */
84
+ addRefs(...newChildrenRefs) {
85
+ // Add element refs that should be considered as inside the click away context.
86
+ context.childrenRefs.push(...newChildrenRefs);
87
+ if (parentContext) {
88
+ // Also add then to the parent context
89
+ parentContext.addRefs(...newChildrenRefs);
90
+ if (parentRef) {
91
+ // The parent element is also considered as inside the parent click away context but not inside the current context
92
+ parentContext.addRefs(parentRef);
93
+ }
94
+ }
95
+ }
96
+ };
97
+ return context;
98
+ }, [parentContext, parentRef]);
99
+ useEffect(() => {
100
+ const {
101
+ current: currentRefs
102
+ } = childrenRefs;
103
+ if (!currentRefs) {
104
+ return;
105
+ }
106
+ currentContext.addRefs(...currentRefs);
107
+ }, [currentContext, childrenRefs]);
108
+ useClickAway({
109
+ callback,
110
+ childrenRefs: useRef(currentContext.childrenRefs)
111
+ });
112
+ return /*#__PURE__*/jsx(ClickAwayAncestorContext.Provider, {
113
+ value: currentContext,
114
+ children: children
115
+ });
116
+ };
117
+ ClickAwayProvider.displayName = 'ClickAwayProvider';
118
+
119
+ /**
120
+ * Portal initializing function.
121
+ * If it does not provide a container, the Portal children will render in classic React tree and not in a portal.
122
+ */
123
+
124
+ const PortalContext = /*#__PURE__*/React__default.createContext(() => ({
125
+ container: document.body
126
+ }));
127
+ /**
128
+ * Customize where <Portal> wrapped elements render (tooltip, popover, dialog, etc.)
129
+ */
130
+ const PortalProvider = PortalContext.Provider;
131
+
132
+ /**
133
+ * Render children in a portal outside the current DOM position
134
+ * (defaults to `document.body` but can be customized with the PortalContextProvider)
135
+ */
136
+ const Portal = ({
137
+ children,
138
+ enabled = true
139
+ }) => {
140
+ const init = React__default.useContext(PortalContext);
141
+ const context = React__default.useMemo(() => {
142
+ return enabled ? init() : null;
143
+ },
144
+ // Only update on 'enabled'
145
+ // eslint-disable-next-line react-hooks/exhaustive-deps
146
+ [enabled]);
147
+ React__default.useLayoutEffect(() => {
148
+ return context?.teardown;
149
+ }, [context?.teardown, enabled]);
150
+ if (!context?.container) {
151
+ return /*#__PURE__*/jsx(Fragment, {
152
+ children: children
153
+ });
154
+ }
155
+ return /*#__PURE__*/createPortal(children, context.container);
156
+ };
157
+
158
+ export { ClickAwayProvider, DisabledStateProvider, Portal, PortalProvider, useDisabledStateContext };
159
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/utils/disabled/DisabledStateContext.tsx","../../src/hooks/useClickAway.tsx","../../src/utils/ClickAwayProvider/ClickAwayProvider.tsx","../../src/utils/Portal/PortalProvider.tsx","../../src/utils/Portal/Portal.tsx"],"sourcesContent":["import React, { useContext } from 'react';\n\n/** Disable state */\ntype DisabledStateContextValue =\n | {\n state: 'disabled';\n }\n | { state: undefined | null };\n\nexport const DisabledStateContext = React.createContext<DisabledStateContextValue>({ state: null });\n\nexport type DisabledStateProviderProps = DisabledStateContextValue & {\n children: React.ReactNode;\n};\n\n/**\n * Disabled state provider.\n * All nested LumX Design System components inherit this disabled state.\n */\nexport function DisabledStateProvider({ children, ...value }: DisabledStateProviderProps) {\n return <DisabledStateContext.Provider value={value}>{children}</DisabledStateContext.Provider>;\n}\n\n/**\n * Get DisabledState context value\n */\nexport function useDisabledStateContext(): DisabledStateContextValue {\n return useContext(DisabledStateContext);\n}\n","import { RefObject, useEffect } from 'react';\n\nimport { Falsy } from '@lumx/react/utils/type';\nimport { isEmpty } from '@lumx/core/js/utils/collection/isEmpty';\n\nconst EVENT_TYPES = ['mousedown', 'touchstart'];\n\nfunction isClickAway(targets: HTMLElement[], refs: Array<RefObject<HTMLElement>>): boolean {\n // The targets elements are not contained in any of the listed element references.\n return !refs.some((ref) => targets.some((target) => ref?.current?.contains(target)));\n}\n\nexport interface ClickAwayParameters {\n /**\n * A callback function to call when the user clicks away from the elements.\n */\n callback: EventListener | Falsy;\n /**\n * Elements considered within the click away context (clicking outside them will trigger the click away callback).\n */\n childrenRefs: RefObject<Array<RefObject<HTMLElement>>>;\n}\n\n/**\n * Listen to clicks away from the given elements and callback the passed in function.\n *\n * Warning: If you need to detect click away on nested React portals, please use the `ClickAwayProvider` component.\n */\nexport function useClickAway({ callback, childrenRefs }: ClickAwayParameters): void {\n useEffect(() => {\n const { current: currentRefs } = childrenRefs;\n if (!callback || !currentRefs || isEmpty(currentRefs)) {\n return undefined;\n }\n const listener: EventListener = (evt) => {\n const targets = [evt.composedPath?.()[0], evt.target] as HTMLElement[];\n if (isClickAway(targets, currentRefs)) {\n callback(evt);\n }\n };\n\n EVENT_TYPES.forEach((evtType) => document.addEventListener(evtType, listener));\n return () => {\n EVENT_TYPES.forEach((evtType) => document.removeEventListener(evtType, listener));\n };\n }, [callback, childrenRefs]);\n}\n","import { createContext, RefObject, useContext, useEffect, useMemo, useRef } from 'react';\nimport { ClickAwayParameters, useClickAway } from '@lumx/react/hooks/useClickAway';\n\ninterface ContextValue {\n childrenRefs: Array<RefObject<HTMLElement>>;\n addRefs(...newChildrenRefs: Array<RefObject<HTMLElement>>): void;\n}\n\nconst ClickAwayAncestorContext = createContext<ContextValue | null>(null);\n\ninterface ClickAwayProviderProps extends ClickAwayParameters {\n /**\n * (Optional) Element that should be considered as part of the parent\n */\n parentRef?: RefObject<HTMLElement>;\n /**\n * Children\n */\n children?: React.ReactNode;\n}\n\n/**\n * Component combining the `useClickAway` hook with a React context to hook into the React component tree and make sure\n * we take into account both the DOM tree and the React tree to detect click away.\n *\n * @return the react component.\n */\nexport const ClickAwayProvider: React.FC<ClickAwayProviderProps> = ({\n children,\n callback,\n childrenRefs,\n parentRef,\n}) => {\n const parentContext = useContext(ClickAwayAncestorContext);\n const currentContext = useMemo(() => {\n const context: ContextValue = {\n childrenRefs: [],\n /**\n * Add element refs to the current context and propagate to the parent context.\n */\n addRefs(...newChildrenRefs) {\n // Add element refs that should be considered as inside the click away context.\n context.childrenRefs.push(...newChildrenRefs);\n\n if (parentContext) {\n // Also add then to the parent context\n parentContext.addRefs(...newChildrenRefs);\n if (parentRef) {\n // The parent element is also considered as inside the parent click away context but not inside the current context\n parentContext.addRefs(parentRef);\n }\n }\n },\n };\n return context;\n }, [parentContext, parentRef]);\n\n useEffect(() => {\n const { current: currentRefs } = childrenRefs;\n if (!currentRefs) {\n return;\n }\n currentContext.addRefs(...currentRefs);\n }, [currentContext, childrenRefs]);\n\n useClickAway({ callback, childrenRefs: useRef(currentContext.childrenRefs) });\n return <ClickAwayAncestorContext.Provider value={currentContext}>{children}</ClickAwayAncestorContext.Provider>;\n};\nClickAwayProvider.displayName = 'ClickAwayProvider';\n","import React from 'react';\n\ntype Container = DocumentFragment | Element;\n\n/**\n * Portal initializing function.\n * If it does not provide a container, the Portal children will render in classic React tree and not in a portal.\n */\nexport type PortalInit = () => {\n container?: Container;\n teardown?: () => void;\n};\n\nexport const PortalContext = React.createContext<PortalInit>(() => ({ container: document.body }));\n\nexport interface PortalProviderProps {\n children?: React.ReactNode;\n value: PortalInit;\n}\n\n/**\n * Customize where <Portal> wrapped elements render (tooltip, popover, dialog, etc.)\n */\nexport const PortalProvider: React.FC<PortalProviderProps> = PortalContext.Provider;\n","import React from 'react';\nimport { createPortal } from 'react-dom';\nimport { PortalContext } from './PortalProvider';\n\nexport interface PortalProps {\n enabled?: boolean;\n children: React.ReactNode;\n}\n\n/**\n * Render children in a portal outside the current DOM position\n * (defaults to `document.body` but can be customized with the PortalContextProvider)\n */\nexport const Portal: React.FC<PortalProps> = ({ children, enabled = true }) => {\n const init = React.useContext(PortalContext);\n const context = React.useMemo(\n () => {\n return enabled ? init() : null;\n },\n // Only update on 'enabled'\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [enabled],\n );\n\n React.useLayoutEffect(() => {\n return context?.teardown;\n }, [context?.teardown, enabled]);\n\n if (!context?.container) {\n return <>{children}</>;\n }\n return createPortal(children, context.container);\n};\n"],"names":["DisabledStateContext","React","createContext","state","DisabledStateProvider","children","value","_jsx","Provider","useDisabledStateContext","useContext","EVENT_TYPES","isClickAway","targets","refs","some","ref","target","current","contains","useClickAway","callback","childrenRefs","useEffect","currentRefs","isEmpty","undefined","listener","evt","composedPath","forEach","evtType","document","addEventListener","removeEventListener","ClickAwayAncestorContext","ClickAwayProvider","parentRef","parentContext","currentContext","useMemo","context","addRefs","newChildrenRefs","push","useRef","displayName","PortalContext","container","body","PortalProvider","Portal","enabled","init","useLayoutEffect","teardown","_Fragment","createPortal"],"mappings":";;;;;AASO,MAAMA,oBAAoB,gBAAGC,cAAK,CAACC,aAAa,CAA4B;AAAEC,EAAAA,KAAK,EAAE,IAAA;AAAK,CAAC,CAAC,CAAA;AAMnG;AACA;AACA;AACA;AACO,SAASC,qBAAqBA,CAAC;EAAEC,QAAQ;EAAE,GAAGC,KAAAA;AAAkC,CAAC,EAAE;AACtF,EAAA,oBAAO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CAAA;GAC3B,EAAE,CAACd,OAAO,EAAEc,QAAQ,EAAEH,OAAO,CAAC,CAAC,CAAA;AAEhC,EAAA,IAAI,CAACX,OAAO,EAAEO,SAAS,EAAE;IACrB,oBAAOzC,GAAA,CAAAiD,QAAA,EAAA;AAAAnD,MAAAA,QAAA,EAAGA,QAAAA;AAAQ,KAAG,CAAC,CAAA;AAC1B,GAAA;AACA,EAAA,oBAAOoD,YAAY,CAACpD,QAAQ,EAAEoC,OAAO,CAACO,SAAS,CAAC,CAAA;AACpD;;;;"}
@@ -1,314 +0,0 @@
1
- import React__default, { useState, useEffect, useMemo } from 'react';
2
- import classNames from 'classnames';
3
- import { getRootClassName, handleBasicClasses } from '@lumx/core/js/utils/className';
4
- import { u as useMergeRefs } from './f0d7d6ea.js';
5
- import { AspectRatio, Theme, Size } from '@lumx/core/js/constants';
6
- import { u as useTheme } from './3181f000.js';
7
- import { f as forwardRef } from './8bce732e.js';
8
- import { R as RawClickable } from './2c2b6a89.js';
9
- import { jsxs, jsx } from 'react/jsx-runtime';
10
- import { useDisableStateProps } from './utils/disabled/index-075b99c3.js';
11
- import { I as Icon } from './bace1bf1.js';
12
-
13
- const mdiImageBroken = 'M19 3a2 2 0 0 1 2 2v6h-2v2h-2v2h-2v2h-2v2h-2v2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2zm2 12v4a2 2 0 0 1-2 2h-4v-2h2v-2h2v-2zm-2-6.5a.5.5 0 0 0-.5-.5h-13a.5.5 0 0 0-.5.5v7a.5.5 0 0 0 .5.5H11v-1h2v-2h2v-2h2V9h2z';
14
-
15
- function getState(img, event) {
16
- // Error event occurred or image has no source.
17
- if (event?.type === 'error' || img?.complete && !img.getAttribute('src')) {
18
- return 'hasError';
19
- }
20
- // Image is undefined or incomplete.
21
- if (!img || !img.complete) {
22
- return 'isLoading';
23
- }
24
- // Else loaded.
25
- return 'isLoaded';
26
- }
27
- function useImageLoad(imageURL, imgRef) {
28
- const [state, setState] = useState(getState(imgRef));
29
-
30
- // Update state when changing image URL or DOM reference.
31
- useEffect(() => {
32
- setState(getState(imgRef));
33
- }, [imageURL, imgRef]);
34
-
35
- // Listen to `load` and `error` event on image
36
- useEffect(() => {
37
- const img = imgRef;
38
- if (!img) return undefined;
39
- const update = event => setState(getState(img, event));
40
- img.addEventListener('load', update);
41
- img.addEventListener('error', update);
42
- return () => {
43
- img.removeEventListener('load', update);
44
- img.removeEventListener('error', update);
45
- };
46
- }, [imgRef, imgRef?.src]);
47
- return state;
48
- }
49
-
50
- // Calculate shift to center the focus point in the container.
51
- function shiftPosition({
52
- scale,
53
- focusPoint,
54
- imageSize,
55
- containerSize
56
- }) {
57
- const scaledSize = imageSize / scale;
58
- if (scaledSize === containerSize) return 0;
59
- const scaledFocusHeight = focusPoint * scaledSize;
60
- const startFocus = scaledFocusHeight - containerSize / 2;
61
- const shift = startFocus / (scaledSize - containerSize);
62
- return Math.floor(Math.max(Math.min(shift, 1), 0) * 100);
63
- }
64
-
65
- // Compute CSS properties to apply the focus point.
66
- const useFocusPointStyle = ({
67
- image,
68
- aspectRatio,
69
- focusPoint,
70
- imgProps: {
71
- width,
72
- height
73
- } = {}
74
- }, element, isLoaded) => {
75
- // Get natural image size from imgProps or img element.
76
- const imageSize = useMemo(() => {
77
- // Focus point is not applicable => exit early
78
- if (!image || aspectRatio === AspectRatio.original || !focusPoint?.x && !focusPoint?.y) return undefined;
79
- if (typeof width === 'number' && typeof height === 'number') return {
80
- width,
81
- height
82
- };
83
- if (element && isLoaded) return {
84
- width: element.naturalWidth,
85
- height: element.naturalHeight
86
- };
87
- return undefined;
88
- }, [aspectRatio, element, focusPoint?.x, focusPoint?.y, height, image, isLoaded, width]);
89
-
90
- // Get container size (dependant on imageSize).
91
- const [containerSize, setContainerSize] = useState(undefined);
92
- useEffect(function updateContainerSize() {
93
- const cWidth = element?.offsetWidth;
94
- const cHeight = element?.offsetHeight;
95
- if (cWidth && cHeight) {
96
- // Update only if needed.
97
- setContainerSize(oldContainerSize => oldContainerSize?.width === cWidth && oldContainerSize.height === cHeight ? oldContainerSize : {
98
- width: cWidth,
99
- height: cHeight
100
- });
101
- } else if (imageSize) {
102
- // Wait for a render (in case the container size is dependent on the image size).
103
- requestAnimationFrame(updateContainerSize);
104
- }
105
- }, [element?.offsetHeight, element?.offsetWidth, imageSize]);
106
-
107
- // Compute style.
108
- const style = useMemo(() => {
109
- // Focus point is not applicable => exit early
110
- if (!image || aspectRatio === AspectRatio.original || !focusPoint?.x && !focusPoint?.y) {
111
- return {};
112
- }
113
- if (!element || !imageSize) {
114
- // Focus point can be computed but now right now (image size unknown).
115
- return {
116
- visibility: 'hidden'
117
- };
118
- }
119
- if (!containerSize || !imageSize.height || !imageSize.width) {
120
- // Missing container or image size abort focus point compute.
121
- return {};
122
- }
123
- const heightScale = imageSize.height / containerSize.height;
124
- const widthScale = imageSize.width / containerSize.width;
125
- const scale = Math.min(widthScale, heightScale);
126
-
127
- // Focus Y relative to the top (instead of the center)
128
- const focusPointFromTop = Math.abs((focusPoint?.y || 0) - 1) / 2;
129
- const y = shiftPosition({
130
- scale,
131
- focusPoint: focusPointFromTop,
132
- imageSize: imageSize.height,
133
- containerSize: containerSize.height
134
- });
135
-
136
- // Focus X relative to the left (instead of the center)
137
- const focusPointFromLeft = Math.abs((focusPoint?.x || 0) + 1) / 2;
138
- const x = shiftPosition({
139
- scale,
140
- focusPoint: focusPointFromLeft,
141
- imageSize: imageSize.width,
142
- containerSize: containerSize.width
143
- });
144
- const objectPosition = `${x}% ${y}%`;
145
- return {
146
- objectPosition
147
- };
148
- }, [aspectRatio, containerSize, element, focusPoint?.x, focusPoint?.y, image, imageSize]);
149
- return style;
150
- };
151
-
152
- /**
153
- * Component display name.
154
- */
155
- const COMPONENT_NAME = 'Thumbnail';
156
-
157
- /**
158
- * Component default class name and class prefix.
159
- */
160
- const CLASSNAME = getRootClassName(COMPONENT_NAME);
161
-
162
- /**
163
- * Component default props.
164
- */
165
- const DEFAULT_PROPS = {
166
- fallback: mdiImageBroken,
167
- loading: 'lazy'
168
- };
169
-
170
- /**
171
- * Thumbnail component.
172
- *
173
- * @param props Component props.
174
- * @param ref Component ref.
175
- * @return React element.
176
- */
177
- const Thumbnail = forwardRef((props, ref) => {
178
- const {
179
- isAnyDisabled,
180
- otherProps,
181
- disabledStateProps
182
- } = useDisableStateProps(props);
183
- const defaultTheme = useTheme() || Theme.light;
184
- const {
185
- align,
186
- alt,
187
- aspectRatio = AspectRatio.original,
188
- badge,
189
- className,
190
- crossOrigin,
191
- fallback = DEFAULT_PROPS.fallback,
192
- fillHeight,
193
- // `focusPoint` needs to be here to remove it from `forwardedProps`.
194
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
195
- focusPoint,
196
- image,
197
- imgProps,
198
- imgRef: propImgRef,
199
- isLoading: isLoadingProp,
200
- objectFit,
201
- loading = DEFAULT_PROPS.loading,
202
- loadingPlaceholderImageRef,
203
- size,
204
- theme = defaultTheme,
205
- variant,
206
- linkProps,
207
- linkAs,
208
- ...forwardedProps
209
- } = otherProps;
210
- const [imgElement, setImgElement] = useState();
211
-
212
- // Image loading state.
213
- const loadingState = useImageLoad(image, imgElement);
214
- const isLoaded = loadingState === 'isLoaded';
215
- const isLoading = isLoadingProp || loadingState === 'isLoading';
216
- const hasError = loadingState === 'hasError';
217
-
218
- // Focus point.
219
- const focusPointStyle = useFocusPointStyle(props, imgElement, isLoaded);
220
- const hasIconErrorFallback = hasError && typeof fallback === 'string';
221
- const hasCustomErrorFallback = hasError && !hasIconErrorFallback;
222
- const imageErrorStyle = {};
223
- if (hasIconErrorFallback) {
224
- // Keep the image layout on icon fallback.
225
- imageErrorStyle.visibility = 'hidden';
226
- } else if (hasCustomErrorFallback) {
227
- // Remove the image on custom fallback.
228
- imageErrorStyle.display = 'none';
229
- }
230
- const isLink = Boolean(linkProps?.href || linkAs);
231
- const isClickable = !isAnyDisabled && Boolean(isLink || !!forwardedProps.onClick);
232
- const Wrapper = isClickable ? RawClickable : 'div';
233
- const wrapperProps = {
234
- ...forwardedProps
235
- };
236
- if (isClickable) {
237
- Object.assign(wrapperProps, {
238
- as: linkAs || (linkProps?.href ? 'a' : 'button')
239
- }, disabledStateProps);
240
- if (isLink) {
241
- Object.assign(wrapperProps, linkProps);
242
- } else {
243
- wrapperProps['aria-label'] = forwardedProps['aria-label'] || alt;
244
- }
245
- }
246
-
247
- // If we have a loading placeholder image that is really loaded (complete)
248
- const loadingPlaceholderImage = isLoading && loadingPlaceholderImageRef?.current?.complete && loadingPlaceholderImageRef?.current || undefined;
249
-
250
- // Set loading placeholder image as background
251
- const loadingStyle = loadingPlaceholderImage ? {
252
- backgroundImage: `url(${loadingPlaceholderImage.src})`
253
- } : undefined;
254
- return /*#__PURE__*/jsxs(Wrapper, {
255
- ...wrapperProps,
256
- ref: ref,
257
- className: classNames(linkProps?.className, className, handleBasicClasses({
258
- align,
259
- aspectRatio,
260
- prefix: CLASSNAME,
261
- size,
262
- theme,
263
- variant,
264
- isClickable,
265
- hasError,
266
- hasIconErrorFallback,
267
- hasCustomErrorFallback,
268
- isLoading,
269
- objectFit,
270
- hasBadge: !!badge
271
- }), fillHeight && `${CLASSNAME}--fill-height`),
272
- children: [/*#__PURE__*/jsxs("span", {
273
- className: `${CLASSNAME}__background`,
274
- children: [/*#__PURE__*/jsx("img", {
275
- // Use placeholder image size
276
- width: loadingPlaceholderImage?.naturalWidth,
277
- height: loadingPlaceholderImage?.naturalHeight,
278
- ...imgProps,
279
- style: {
280
- // Reserve space while loading (when possible)
281
- width: isLoading ? imgProps?.width || loadingPlaceholderImage?.naturalWidth : undefined,
282
- ...imgProps?.style,
283
- ...imageErrorStyle,
284
- ...focusPointStyle,
285
- ...loadingStyle
286
- },
287
- ref: useMergeRefs(setImgElement, propImgRef),
288
- className: classNames(handleBasicClasses({
289
- prefix: `${CLASSNAME}__image`,
290
- isLoading,
291
- hasDefinedSize: Boolean(imgProps?.height && imgProps.width)
292
- }), imgProps?.className),
293
- crossOrigin: crossOrigin,
294
- src: image,
295
- alt: alt,
296
- loading: loading
297
- }), !isLoading && hasError && /*#__PURE__*/jsx("span", {
298
- className: `${CLASSNAME}__fallback`,
299
- children: hasIconErrorFallback ? /*#__PURE__*/jsx(Icon, {
300
- icon: fallback,
301
- size: Size.xxs,
302
- theme: theme
303
- }) : fallback
304
- })]
305
- }), badge && /*#__PURE__*/React__default.cloneElement(badge, {
306
- className: classNames(`${CLASSNAME}__badge`, badge.props.className)
307
- })]
308
- });
309
- });
310
- Thumbnail.displayName = COMPONENT_NAME;
311
- Thumbnail.className = CLASSNAME;
312
- Thumbnail.defaultProps = DEFAULT_PROPS;
313
-
314
- export { Thumbnail as T, useFocusPointStyle as u };
@@ -1,5 +0,0 @@
1
- const mdiChevronDown = 'M7.41 8.58 12 13.17l4.59-4.59L18 10l-6 6-6-6z';
2
-
3
- const mdiChevronUp = 'M7.41 15.41 12 10.83l4.59 4.58L18 14l-6-6-6 6z';
4
-
5
- export { mdiChevronDown as a, mdiChevronUp as m };