@cloudscape-design/components 3.0.65 → 3.0.66
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/annotation-context/annotation/annotation-popover.d.ts.map +1 -1
- package/annotation-context/annotation/annotation-popover.js +2 -2
- package/annotation-context/annotation/annotation-popover.js.map +1 -1
- package/autosuggest/interfaces.d.ts +2 -2
- package/autosuggest/interfaces.d.ts.map +1 -1
- package/autosuggest/interfaces.js.map +1 -1
- package/button-dropdown/tooltip.js +2 -2
- package/button-dropdown/tooltip.js.map +1 -1
- package/calendar/interfaces.d.ts +2 -1
- package/calendar/interfaces.d.ts.map +1 -1
- package/calendar/interfaces.js.map +1 -1
- package/calendar/internal.d.ts +2 -1
- package/calendar/internal.d.ts.map +1 -1
- package/calendar/internal.js +8 -3
- package/calendar/internal.js.map +1 -1
- package/cards/index.d.ts.map +1 -1
- package/cards/index.js +15 -5
- package/cards/index.js.map +1 -1
- package/checkbox/base-checkbox.d.ts +1 -5
- package/checkbox/base-checkbox.d.ts.map +1 -1
- package/checkbox/base-checkbox.js.map +1 -1
- package/checkbox/internal.d.ts.map +1 -1
- package/checkbox/internal.js +3 -1
- package/checkbox/internal.js.map +1 -1
- package/container/internal.d.ts +2 -1
- package/container/internal.d.ts.map +1 -1
- package/container/internal.js +3 -2
- package/container/internal.js.map +1 -1
- package/date-input/index.d.ts.map +1 -1
- package/date-input/index.js +3 -4
- package/date-input/index.js.map +1 -1
- package/date-input/internal.d.ts.map +1 -1
- package/date-input/internal.js +2 -2
- package/date-input/internal.js.map +1 -1
- package/date-range-picker/calendar/index.js +2 -2
- package/date-range-picker/calendar/index.js.map +1 -1
- package/form-field/internal.d.ts.map +1 -1
- package/form-field/internal.js +2 -2
- package/form-field/internal.js.map +1 -1
- package/index.d.ts +2 -0
- package/index.d.ts.map +1 -1
- package/index.js +2 -0
- package/index.js.map +1 -1
- package/input/interfaces.d.ts +11 -9
- package/input/interfaces.d.ts.map +1 -1
- package/input/interfaces.js.map +1 -1
- package/input/internal.d.ts +2 -2
- package/input/internal.d.ts.map +1 -1
- package/input/internal.js.map +1 -1
- package/internal/components/autosuggest-input/index.d.ts +2 -2
- package/internal/components/autosuggest-input/index.d.ts.map +1 -1
- package/internal/components/autosuggest-input/index.js.map +1 -1
- package/internal/components/chart-popover/index.js +2 -2
- package/internal/components/chart-popover/index.js.map +1 -1
- package/internal/environment.js +1 -1
- package/link/interfaces.d.ts +1 -1
- package/link/interfaces.d.ts.map +1 -1
- package/link/interfaces.js.map +1 -1
- package/link/styles.css.js +20 -19
- package/link/styles.scoped.css +75 -70
- package/link/styles.selectors.js +20 -19
- package/package.json +3 -1
- package/popover/body.d.ts +1 -4
- package/popover/body.d.ts.map +1 -1
- package/popover/body.js +2 -4
- package/popover/body.js.map +1 -1
- package/popover/container.d.ts +4 -1
- package/popover/container.d.ts.map +1 -1
- package/popover/container.js +51 -37
- package/popover/container.js.map +1 -1
- package/popover/internal.js +2 -2
- package/popover/internal.js.map +1 -1
- package/popover/styles.css.js +49 -48
- package/popover/styles.scoped.css +209 -89
- package/popover/styles.selectors.js +49 -48
- package/popover/utils/positions.d.ts +1 -0
- package/popover/utils/positions.d.ts.map +1 -1
- package/popover/utils/positions.js +40 -14
- package/popover/utils/positions.js.map +1 -1
- package/radio-group/interfaces.d.ts +5 -0
- package/radio-group/interfaces.d.ts.map +1 -1
- package/radio-group/interfaces.js.map +1 -1
- package/tag-editor/interfaces.d.ts +1 -1
- package/tag-editor/interfaces.d.ts.map +1 -1
- package/tag-editor/interfaces.js.map +1 -1
- package/test-utils/dom/form-field/index.js +1 -1
- package/test-utils/dom/form-field/index.js.map +1 -1
- package/test-utils/dom/index.d.ts +6 -0
- package/test-utils/dom/index.js +18 -2
- package/test-utils/dom/index.js.map +1 -1
- package/test-utils/selectors/form-field/index.js +1 -1
- package/test-utils/selectors/form-field/index.js.map +1 -1
- package/test-utils/selectors/index.d.ts +6 -0
- package/test-utils/selectors/index.js +18 -2
- package/test-utils/selectors/index.js.map +1 -1
- package/test-utils/tsconfig.tsbuildinfo +1 -1
- package/textarea/interfaces.d.ts +2 -2
- package/textarea/interfaces.d.ts.map +1 -1
- package/textarea/interfaces.js.map +1 -1
- package/time-input/interfaces.d.ts +2 -2
- package/time-input/interfaces.d.ts.map +1 -1
- package/time-input/interfaces.js.map +1 -1
- package/toggle/internal.d.ts.map +1 -1
- package/toggle/internal.js +3 -1
- package/toggle/internal.js.map +1 -1
package/popover/container.js
CHANGED
|
@@ -4,47 +4,50 @@ import { __assign } from "tslib";
|
|
|
4
4
|
import React, { useCallback, useLayoutEffect, useRef, useState } from 'react';
|
|
5
5
|
import clsx from 'clsx';
|
|
6
6
|
import { getContainingBlock, nodeContains } from '../internal/utils/dom';
|
|
7
|
-
import {
|
|
7
|
+
import { useResizeObserver } from '../internal/hooks/container-queries';
|
|
8
8
|
import { calculatePosition } from './utils/positions';
|
|
9
9
|
import styles from './styles.css.js';
|
|
10
10
|
import { useVisualRefresh } from '../internal/hooks/use-visual-mode';
|
|
11
|
-
import { useMergeRefs } from '../internal/hooks/use-merge-refs';
|
|
12
11
|
var INITIAL_STYLES = { position: 'absolute', top: -9999, left: -9999 };
|
|
13
12
|
export default function PopoverContainer(_a) {
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
var roundedRect = { width: Math.round(rect.width), height: Math.round(rect.height) };
|
|
17
|
-
return (prev === null || prev === void 0 ? void 0 : prev.width) === roundedRect.width && (prev === null || prev === void 0 ? void 0 : prev.height) === roundedRect.height ? prev : rect;
|
|
18
|
-
}), popoverRect = _b[0], ref = _b[1];
|
|
13
|
+
var _b;
|
|
14
|
+
var position = _a.position, trackRef = _a.trackRef, trackKey = _a.trackKey, arrow = _a.arrow, children = _a.children, zIndex = _a.zIndex, renderWithPortal = _a.renderWithPortal, size = _a.size, fixedWidth = _a.fixedWidth, variant = _a.variant;
|
|
19
15
|
var bodyRef = useRef(null);
|
|
16
|
+
var contentRef = useRef(null);
|
|
17
|
+
var popoverRef = useRef(null);
|
|
20
18
|
var arrowRef = useRef(null);
|
|
21
|
-
var _c = useState(INITIAL_STYLES),
|
|
19
|
+
var _c = useState(INITIAL_STYLES), popoverStyle = _c[0], setPopoverStyle = _c[1];
|
|
22
20
|
var _d = useState(null), internalPosition = _d[0], setInternalPosition = _d[1];
|
|
23
21
|
var isRefresh = useVisualRefresh();
|
|
24
22
|
// Store the handler in a ref so that it can still be replaced from outside of the listener closure.
|
|
25
23
|
var positionHandlerRef = useRef(function () { });
|
|
26
24
|
// Updates the position handler.
|
|
27
25
|
var updatePositionHandler = useCallback(function () {
|
|
28
|
-
if (!trackRef.current || !
|
|
26
|
+
if (!trackRef.current || !popoverRef.current || !bodyRef.current || !contentRef.current || !arrowRef.current) {
|
|
29
27
|
return;
|
|
30
28
|
}
|
|
31
29
|
// Get important elements
|
|
30
|
+
var popover = popoverRef.current;
|
|
32
31
|
var body = bodyRef.current;
|
|
33
32
|
var arrow = arrowRef.current;
|
|
34
|
-
var document =
|
|
33
|
+
var document = popover.ownerDocument;
|
|
35
34
|
var track = trackRef.current;
|
|
36
35
|
// If the popover body isn't being rendered for whatever reason (e.g. "display: none" or JSDOM),
|
|
37
36
|
// or track does not belong to the document - bail on calculating dimensions.
|
|
38
|
-
if (
|
|
37
|
+
if (popover.offsetWidth === 0 || popover.offsetHeight === 0 || !nodeContains(document.body, track)) {
|
|
39
38
|
return;
|
|
40
39
|
}
|
|
41
40
|
// Imperatively move body off-screen to give it room to expand.
|
|
42
41
|
// Not doing this in React because this recalculation should happen
|
|
43
42
|
// in the span of a single frame without rerendering anything.
|
|
44
|
-
var prevTop =
|
|
45
|
-
var prevLeft =
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
var prevTop = popover.style.top;
|
|
44
|
+
var prevLeft = popover.style.left;
|
|
45
|
+
popover.style.top = '0';
|
|
46
|
+
popover.style.left = '0';
|
|
47
|
+
// Imperatively remove body styles that can remain from the previous computation.
|
|
48
|
+
body.style.maxHeight = '';
|
|
49
|
+
body.style.overflowX = '';
|
|
50
|
+
body.style.overflowY = '';
|
|
48
51
|
// Get rects representing key elements
|
|
49
52
|
// Use getComputedStyle for arrowRect to avoid modifications made by transform
|
|
50
53
|
var viewportRect = getViewportRect(document.defaultView);
|
|
@@ -53,43 +56,48 @@ export default function PopoverContainer(_a) {
|
|
|
53
56
|
width: parseFloat(getComputedStyle(arrow).width),
|
|
54
57
|
height: parseFloat(getComputedStyle(arrow).height)
|
|
55
58
|
};
|
|
56
|
-
var containingBlock = getContainingBlock(
|
|
59
|
+
var containingBlock = getContainingBlock(popover);
|
|
57
60
|
var containingBlockRect = containingBlock ? containingBlock.getBoundingClientRect() : viewportRect;
|
|
58
|
-
|
|
59
|
-
var
|
|
60
|
-
var
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
width: Math.ceil(bodyRect.width),
|
|
64
|
-
height: Math.ceil(bodyRect.height)
|
|
61
|
+
var bodyBorderWidth = getBorderWidth(body);
|
|
62
|
+
var contentRect = contentRef.current.getBoundingClientRect();
|
|
63
|
+
var contentBoundingBox = {
|
|
64
|
+
width: contentRect.width + 2 * bodyBorderWidth,
|
|
65
|
+
height: contentRect.height + 2 * bodyBorderWidth
|
|
65
66
|
};
|
|
66
67
|
// Calculate the arrow direction and viewport-relative position of the popover.
|
|
67
|
-
var _a = calculatePosition(position, trackRect, arrowRect,
|
|
68
|
+
var _a = calculatePosition(position, trackRect, arrowRect, contentBoundingBox, containingBlock ? containingBlockRect : getDocumentRect(document), viewportRect, renderWithPortal), scrollable = _a.scrollable, newInternalPosition = _a.internalPosition, boundingOffset = _a.boundingOffset;
|
|
68
69
|
// Get the position of the popover relative to the offset parent.
|
|
69
70
|
var popoverOffset = toRelativePosition(boundingOffset, containingBlockRect);
|
|
70
71
|
// Cache the distance between the trigger and the popover (which stays the same as you scroll),
|
|
71
72
|
// and use that to recalculate the new popover position.
|
|
72
73
|
var trackRelativeOffset = toRelativePosition(popoverOffset, toRelativePosition(trackRect, containingBlockRect));
|
|
73
|
-
// Bring back the container to its original position to prevent any
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
body
|
|
74
|
+
// Bring back the container to its original position to prevent any flashing.
|
|
75
|
+
popover.style.top = prevTop;
|
|
76
|
+
popover.style.left = prevLeft;
|
|
77
|
+
// Allow popover body to scroll if can't fit the popover into the container/viewport otherwise.
|
|
78
|
+
if (scrollable) {
|
|
79
|
+
body.style.maxHeight = boundingOffset.height + 'px';
|
|
80
|
+
body.style.overflowX = 'hidden';
|
|
81
|
+
body.style.overflowY = 'auto';
|
|
82
|
+
}
|
|
77
83
|
// Position the popover
|
|
78
84
|
setInternalPosition(newInternalPosition);
|
|
79
|
-
|
|
85
|
+
setPopoverStyle({ top: popoverOffset.top, left: popoverOffset.left });
|
|
80
86
|
positionHandlerRef.current = function () {
|
|
81
87
|
var newTrackOffset = toRelativePosition(track.getBoundingClientRect(), containingBlock ? containingBlock.getBoundingClientRect() : viewportRect);
|
|
82
|
-
|
|
88
|
+
setPopoverStyle({
|
|
83
89
|
top: newTrackOffset.top + trackRelativeOffset.top,
|
|
84
90
|
left: newTrackOffset.left + trackRelativeOffset.left
|
|
85
91
|
});
|
|
86
92
|
};
|
|
87
|
-
}, [position, trackRef,
|
|
88
|
-
//
|
|
93
|
+
}, [position, trackRef, renderWithPortal]);
|
|
94
|
+
// Recalculate position when properties change.
|
|
89
95
|
useLayoutEffect(function () {
|
|
90
96
|
updatePositionHandler();
|
|
91
|
-
}, [updatePositionHandler, trackKey
|
|
92
|
-
//
|
|
97
|
+
}, [updatePositionHandler, trackKey]);
|
|
98
|
+
// Recalculate position when content size changes.
|
|
99
|
+
useResizeObserver(contentRef, function () { return updatePositionHandler(); });
|
|
100
|
+
// Recalculate position on DOM events.
|
|
93
101
|
useLayoutEffect(function () {
|
|
94
102
|
/*
|
|
95
103
|
This is a heuristic. Some layout changes are caused by user clicks (e.g. toggling the tools panel, submitting a form),
|
|
@@ -108,10 +116,16 @@ export default function PopoverContainer(_a) {
|
|
|
108
116
|
window.removeEventListener('scroll', refreshPosition, true);
|
|
109
117
|
};
|
|
110
118
|
}, [updatePositionHandler]);
|
|
111
|
-
|
|
112
|
-
return (React.createElement("div", { ref: mergedRef, style: __assign(__assign({}, inlineStyle), { zIndex: zIndex }), className: clsx(styles.container, isRefresh && styles.refresh) },
|
|
119
|
+
return (React.createElement("div", { ref: popoverRef, style: __assign(__assign({}, popoverStyle), { zIndex: zIndex }), className: clsx(styles.container, isRefresh && styles.refresh) },
|
|
113
120
|
React.createElement("div", { ref: arrowRef, className: clsx(styles["container-arrow"], styles["container-arrow-position-".concat(internalPosition)]), "aria-hidden": true }, arrow(internalPosition)),
|
|
114
|
-
|
|
121
|
+
React.createElement("div", { ref: bodyRef, className: clsx(styles['container-body'], styles["container-body-size-".concat(size)], (_b = {},
|
|
122
|
+
_b[styles['fixed-width']] = fixedWidth,
|
|
123
|
+
_b[styles["container-body-variant-".concat(variant)]] = variant,
|
|
124
|
+
_b)) },
|
|
125
|
+
React.createElement("div", { ref: contentRef }, children))));
|
|
126
|
+
}
|
|
127
|
+
function getBorderWidth(element) {
|
|
128
|
+
return parseInt(getComputedStyle(element).borderWidth) || 0;
|
|
115
129
|
}
|
|
116
130
|
/**
|
|
117
131
|
* Convert a viewport-relative offset to an element-relative offset.
|
package/popover/container.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"container.js","sourceRoot":"","sources":["../../../src/popover/container.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAiB,WAAW,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC7F,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAuB,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAE7F,OAAO,EAAE,iBA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AACJ,CAAC;AAED,SAAS,eAAe,CAAC,QAAkB;IACnC,IAAA,KAAgB,QAAQ,CAAC,eAAe,CAAC,qBAAqB,EAAE,EAA9D,GAAG,SAAA,EAAE,IAAI,UAAqD,CAAC;IACvE,OAAO;QACL,GAAG,KAAA;QACH,IAAI,MAAA;QACJ,KAAK,EAAE,QAAQ,CAAC,eAAe,CAAC,WAAW;QAC3C,MAAM,EAAE,QAAQ,CAAC,eAAe,CAAC,YAAY;KAC9C,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { CSSProperties, useCallback, useLayoutEffect, useRef, useState } from 'react';\nimport clsx from 'clsx';\n\nimport { getContainingBlock, nodeContains } from '../internal/utils/dom';\nimport { ContainerQueryEntry, useContainerQuery } from '../internal/hooks/container-queries';\nimport { BoundingOffset, InternalPosition, Offset, PopoverProps } from './interfaces';\nimport { calculatePosition } from './utils/positions';\nimport styles from './styles.css.js';\nimport { useVisualRefresh } from '../internal/hooks/use-visual-mode';\nimport { useMergeRefs } from '../internal/hooks/use-merge-refs';\n\nexport interface PopoverContainerProps {\n /** References the element the container is positioned against. */\n trackRef: React.RefObject<Element>;\n /**\n Used to update the container position in case track or track position changes:\n \n const trackRef = useRef<Element>(null)\n return (<>\n <Track style={getPosition(selectedItemId)} ref={trackRef} />\n <PopoverContainer trackRef={trackRef} trackKey={selectedItemId} .../>\n </>)\n */\n trackKey?: string | number;\n position: PopoverProps.Position;\n zIndex?: React.CSSProperties['zIndex'];\n arrow: (position: InternalPosition | null) => React.ReactNode;\n children: React.ReactNode;\n renderWithPortal?: boolean;\n}\n\nconst INITIAL_STYLES: CSSProperties = { position: 'absolute', top: -9999, left: -9999 };\n\nexport default function PopoverContainer({\n position,\n trackRef,\n trackKey,\n arrow,\n children,\n zIndex,\n renderWithPortal,\n}: PopoverContainerProps) {\n const [popoverRect, ref] = useContainerQuery((rect, prev) => {\n const roundedRect = { width: Math.round(rect.width), height: Math.round(rect.height) };\n return prev?.width === roundedRect.width && prev?.height === roundedRect.height ? prev : rect;\n }) as [ContainerQueryEntry | null, React.MutableRefObject<HTMLDivElement | null>];\n\n const bodyRef = useRef<HTMLDivElement | null>(null);\n const arrowRef = useRef<HTMLDivElement | null>(null);\n\n const [inlineStyle, setInlineStyle] = useState<CSSProperties>(INITIAL_STYLES);\n const [internalPosition, setInternalPosition] = useState<InternalPosition | null>(null);\n const isRefresh = useVisualRefresh();\n\n // Store the handler in a ref so that it can still be replaced from outside of the listener closure.\n const positionHandlerRef = useRef<() => void>(() => {});\n\n // Updates the position handler.\n const updatePositionHandler = useCallback(() => {\n if (!trackRef.current || !ref.current || !bodyRef.current || !arrowRef.current) {\n return;\n }\n\n // Get important elements\n const body = bodyRef.current;\n const arrow = arrowRef.current;\n const document = ref.current.ownerDocument;\n const track = trackRef.current;\n\n // If the popover body isn't being rendered for whatever reason (e.g. \"display: none\" or JSDOM),\n // or track does not belong to the document - bail on calculating dimensions.\n if (body.offsetWidth === 0 || body.offsetHeight === 0 || !nodeContains(document.body, track)) {\n return;\n }\n\n // Imperatively move body off-screen to give it room to expand.\n // Not doing this in React because this recalculation should happen\n // in the span of a single frame without rerendering anything.\n const prevTop = body.style.top;\n const prevLeft = body.style.left;\n body.style.top = '0';\n body.style.left = '0';\n\n // Get rects representing key elements\n // Use getComputedStyle for arrowRect to avoid modifications made by transform\n const viewportRect = getViewportRect(document.defaultView!);\n const trackRect = track.getBoundingClientRect();\n const arrowRect = {\n width: parseFloat(getComputedStyle(arrow).width),\n height: parseFloat(getComputedStyle(arrow).height),\n };\n const containingBlock = getContainingBlock(body);\n const containingBlockRect = containingBlock ? containingBlock.getBoundingClientRect() : viewportRect;\n\n // Round up dimensions (IE11 doesn't handle subpixels too accurately)\n const bodyRect = body.getBoundingClientRect();\n const bodyRectCeil = {\n top: bodyRect.top,\n left: bodyRect.left,\n width: Math.ceil(bodyRect.width),\n height: Math.ceil(bodyRect.height),\n };\n\n // Calculate the arrow direction and viewport-relative position of the popover.\n const { internalPosition: newInternalPosition, boundingOffset } = calculatePosition(\n position,\n trackRect,\n arrowRect,\n bodyRectCeil,\n containingBlock ? containingBlockRect : getDocumentRect(document),\n viewportRect,\n renderWithPortal\n );\n\n // Get the position of the popover relative to the offset parent.\n const popoverOffset = toRelativePosition(boundingOffset, containingBlockRect);\n\n // Cache the distance between the trigger and the popover (which stays the same as you scroll),\n // and use that to recalculate the new popover position.\n const trackRelativeOffset = toRelativePosition(popoverOffset, toRelativePosition(trackRect, containingBlockRect));\n\n // Bring back the container to its original position to prevent any\n // flashing.\n body.style.top = prevTop;\n body.style.left = prevLeft;\n\n // Position the popover\n setInternalPosition(newInternalPosition);\n setInlineStyle({ top: popoverOffset.top, left: popoverOffset.left });\n\n positionHandlerRef.current = () => {\n const newTrackOffset = toRelativePosition(\n track.getBoundingClientRect(),\n containingBlock ? containingBlock.getBoundingClientRect() : viewportRect\n );\n setInlineStyle({\n top: newTrackOffset.top + trackRelativeOffset.top,\n left: newTrackOffset.left + trackRelativeOffset.left,\n });\n };\n }, [position, trackRef, ref, renderWithPortal]);\n\n // Update the handler when properties change.\n useLayoutEffect(() => {\n updatePositionHandler();\n }, [updatePositionHandler, trackKey, popoverRect]);\n\n // Attach document listeners.\n useLayoutEffect(() => {\n /*\n This is a heuristic. Some layout changes are caused by user clicks (e.g. toggling the tools panel, submitting a form),\n and by tracking the click event we can adapt the popover's position to the new layout.\n\n TODO: extend this to Enter and Spacebar?\n */\n const updatePosition = () => requestAnimationFrame(() => updatePositionHandler());\n const refreshPosition = () => requestAnimationFrame(() => positionHandlerRef.current());\n\n window.addEventListener('click', updatePosition);\n window.addEventListener('resize', updatePosition);\n window.addEventListener('scroll', refreshPosition, true);\n return () => {\n window.removeEventListener('click', updatePosition);\n window.removeEventListener('resize', updatePosition);\n window.removeEventListener('scroll', refreshPosition, true);\n };\n }, [updatePositionHandler]);\n\n const mergedRef = useMergeRefs(bodyRef, ref);\n\n return (\n <div\n ref={mergedRef}\n style={{ ...inlineStyle, zIndex }}\n className={clsx(styles.container, isRefresh && styles.refresh)}\n >\n <div\n ref={arrowRef}\n className={clsx(styles[`container-arrow`], styles[`container-arrow-position-${internalPosition}`])}\n aria-hidden={true}\n >\n {arrow(internalPosition)}\n </div>\n {children}\n </div>\n );\n}\n\n/**\n * Convert a viewport-relative offset to an element-relative offset.\n */\nfunction toRelativePosition(element: Offset, parent: Offset): Offset {\n return {\n top: element.top - parent.top,\n left: element.left - parent.left,\n };\n}\n\n/**\n * Get a BoundingOffset that represents the visible viewport.\n */\nfunction getViewportRect(window: Window): BoundingOffset {\n return {\n top: 0,\n left: 0,\n width: window.innerWidth,\n height: window.innerHeight,\n };\n}\n\nfunction getDocumentRect(document: Document): BoundingOffset {\n const { top, left } = document.documentElement.getBoundingClientRect();\n return {\n top,\n left,\n width: document.documentElement.scrollWidth,\n height: document.documentElement.scrollHeight,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"container.js","sourceRoot":"","sources":["../../../src/popover/container.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAiB,WAAW,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC7F,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAExE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAyBrE,IAAM,cAAc,GAAkB,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;AAExF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AAI,GAAG,MAAM,CAAC,IAAI;KACjC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,eAAe,CAAC,MAAc;IACrC,OAAO;QACL,GAAG,EAAE,CAAC;QACN,IAAI,EAAE,CAAC;QACP,KAAK,EAAE,MAAM,CAAC,UAAU;QACxB,MAAM,EAAE,MAAM,CAAC,WAAW;KAC3B,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,QAAkB;IACnC,IAAA,KAAgB,QAAQ,CAAC,eAAe,CAAC,qBAAqB,EAAE,EAA9D,GAAG,SAAA,EAAE,IAAI,UAAqD,CAAC;IACvE,OAAO;QACL,GAAG,KAAA;QACH,IAAI,MAAA;QACJ,KAAK,EAAE,QAAQ,CAAC,eAAe,CAAC,WAAW;QAC3C,MAAM,EAAE,QAAQ,CAAC,eAAe,CAAC,YAAY;KAC9C,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { CSSProperties, useCallback, useLayoutEffect, useRef, useState } from 'react';\nimport clsx from 'clsx';\n\nimport { getContainingBlock, nodeContains } from '../internal/utils/dom';\nimport { useResizeObserver } from '../internal/hooks/container-queries';\nimport { BoundingOffset, InternalPosition, Offset, PopoverProps } from './interfaces';\nimport { calculatePosition } from './utils/positions';\nimport styles from './styles.css.js';\nimport { useVisualRefresh } from '../internal/hooks/use-visual-mode';\n\nexport interface PopoverContainerProps {\n /** References the element the container is positioned against. */\n trackRef: React.RefObject<Element>;\n /**\n Used to update the container position in case track or track position changes:\n \n const trackRef = useRef<Element>(null)\n return (<>\n <Track style={getPosition(selectedItemId)} ref={trackRef} />\n <PopoverContainer trackRef={trackRef} trackKey={selectedItemId} .../>\n </>)\n */\n trackKey?: string | number;\n position: PopoverProps.Position;\n zIndex?: React.CSSProperties['zIndex'];\n arrow: (position: InternalPosition | null) => React.ReactNode;\n children: React.ReactNode;\n renderWithPortal?: boolean;\n size: PopoverProps.Size;\n fixedWidth: boolean;\n variant?: 'annotation';\n}\n\nconst INITIAL_STYLES: CSSProperties = { position: 'absolute', top: -9999, left: -9999 };\n\nexport default function PopoverContainer({\n position,\n trackRef,\n trackKey,\n arrow,\n children,\n zIndex,\n renderWithPortal,\n size,\n fixedWidth,\n variant,\n}: PopoverContainerProps) {\n const bodyRef = useRef<HTMLDivElement | null>(null);\n const contentRef = useRef<HTMLDivElement | null>(null);\n const popoverRef = useRef<HTMLDivElement | null>(null);\n const arrowRef = useRef<HTMLDivElement | null>(null);\n\n const [popoverStyle, setPopoverStyle] = useState<CSSProperties>(INITIAL_STYLES);\n const [internalPosition, setInternalPosition] = useState<InternalPosition | null>(null);\n const isRefresh = useVisualRefresh();\n\n // Store the handler in a ref so that it can still be replaced from outside of the listener closure.\n const positionHandlerRef = useRef<() => void>(() => {});\n\n // Updates the position handler.\n const updatePositionHandler = useCallback(() => {\n if (!trackRef.current || !popoverRef.current || !bodyRef.current || !contentRef.current || !arrowRef.current) {\n return;\n }\n\n // Get important elements\n const popover = popoverRef.current;\n const body = bodyRef.current;\n const arrow = arrowRef.current;\n const document = popover.ownerDocument;\n const track = trackRef.current;\n\n // If the popover body isn't being rendered for whatever reason (e.g. \"display: none\" or JSDOM),\n // or track does not belong to the document - bail on calculating dimensions.\n if (popover.offsetWidth === 0 || popover.offsetHeight === 0 || !nodeContains(document.body, track)) {\n return;\n }\n\n // Imperatively move body off-screen to give it room to expand.\n // Not doing this in React because this recalculation should happen\n // in the span of a single frame without rerendering anything.\n const prevTop = popover.style.top;\n const prevLeft = popover.style.left;\n popover.style.top = '0';\n popover.style.left = '0';\n // Imperatively remove body styles that can remain from the previous computation.\n body.style.maxHeight = '';\n body.style.overflowX = '';\n body.style.overflowY = '';\n\n // Get rects representing key elements\n // Use getComputedStyle for arrowRect to avoid modifications made by transform\n const viewportRect = getViewportRect(document.defaultView!);\n const trackRect = track.getBoundingClientRect();\n const arrowRect = {\n width: parseFloat(getComputedStyle(arrow).width),\n height: parseFloat(getComputedStyle(arrow).height),\n };\n const containingBlock = getContainingBlock(popover);\n const containingBlockRect = containingBlock ? containingBlock.getBoundingClientRect() : viewportRect;\n\n const bodyBorderWidth = getBorderWidth(body);\n const contentRect = contentRef.current.getBoundingClientRect();\n const contentBoundingBox = {\n width: contentRect.width + 2 * bodyBorderWidth,\n height: contentRect.height + 2 * bodyBorderWidth,\n };\n\n // Calculate the arrow direction and viewport-relative position of the popover.\n const {\n scrollable,\n internalPosition: newInternalPosition,\n boundingOffset,\n } = calculatePosition(\n position,\n trackRect,\n arrowRect,\n contentBoundingBox,\n containingBlock ? containingBlockRect : getDocumentRect(document),\n viewportRect,\n renderWithPortal\n );\n\n // Get the position of the popover relative to the offset parent.\n const popoverOffset = toRelativePosition(boundingOffset, containingBlockRect);\n\n // Cache the distance between the trigger and the popover (which stays the same as you scroll),\n // and use that to recalculate the new popover position.\n const trackRelativeOffset = toRelativePosition(popoverOffset, toRelativePosition(trackRect, containingBlockRect));\n\n // Bring back the container to its original position to prevent any flashing.\n popover.style.top = prevTop;\n popover.style.left = prevLeft;\n\n // Allow popover body to scroll if can't fit the popover into the container/viewport otherwise.\n if (scrollable) {\n body.style.maxHeight = boundingOffset.height + 'px';\n body.style.overflowX = 'hidden';\n body.style.overflowY = 'auto';\n }\n\n // Position the popover\n setInternalPosition(newInternalPosition);\n setPopoverStyle({ top: popoverOffset.top, left: popoverOffset.left });\n\n positionHandlerRef.current = () => {\n const newTrackOffset = toRelativePosition(\n track.getBoundingClientRect(),\n containingBlock ? containingBlock.getBoundingClientRect() : viewportRect\n );\n setPopoverStyle({\n top: newTrackOffset.top + trackRelativeOffset.top,\n left: newTrackOffset.left + trackRelativeOffset.left,\n });\n };\n }, [position, trackRef, renderWithPortal]);\n\n // Recalculate position when properties change.\n useLayoutEffect(() => {\n updatePositionHandler();\n }, [updatePositionHandler, trackKey]);\n\n // Recalculate position when content size changes.\n useResizeObserver(contentRef, () => updatePositionHandler());\n\n // Recalculate position on DOM events.\n useLayoutEffect(() => {\n /*\n This is a heuristic. Some layout changes are caused by user clicks (e.g. toggling the tools panel, submitting a form),\n and by tracking the click event we can adapt the popover's position to the new layout.\n\n TODO: extend this to Enter and Spacebar?\n */\n const updatePosition = () => requestAnimationFrame(() => updatePositionHandler());\n const refreshPosition = () => requestAnimationFrame(() => positionHandlerRef.current());\n\n window.addEventListener('click', updatePosition);\n window.addEventListener('resize', updatePosition);\n window.addEventListener('scroll', refreshPosition, true);\n return () => {\n window.removeEventListener('click', updatePosition);\n window.removeEventListener('resize', updatePosition);\n window.removeEventListener('scroll', refreshPosition, true);\n };\n }, [updatePositionHandler]);\n\n return (\n <div\n ref={popoverRef}\n style={{ ...popoverStyle, zIndex }}\n className={clsx(styles.container, isRefresh && styles.refresh)}\n >\n <div\n ref={arrowRef}\n className={clsx(styles[`container-arrow`], styles[`container-arrow-position-${internalPosition}`])}\n aria-hidden={true}\n >\n {arrow(internalPosition)}\n </div>\n\n <div\n ref={bodyRef}\n className={clsx(styles['container-body'], styles[`container-body-size-${size}`], {\n [styles['fixed-width']]: fixedWidth,\n [styles[`container-body-variant-${variant}`]]: variant,\n })}\n >\n <div ref={contentRef}>{children}</div>\n </div>\n </div>\n );\n}\n\nfunction getBorderWidth(element: HTMLElement) {\n return parseInt(getComputedStyle(element).borderWidth) || 0;\n}\n\n/**\n * Convert a viewport-relative offset to an element-relative offset.\n */\nfunction toRelativePosition(element: Offset, parent: Offset): Offset {\n return {\n top: element.top - parent.top,\n left: element.left - parent.left,\n };\n}\n\n/**\n * Get a BoundingOffset that represents the visible viewport.\n */\nfunction getViewportRect(window: Window): BoundingOffset {\n return {\n top: 0,\n left: 0,\n width: window.innerWidth,\n height: window.innerHeight,\n };\n}\n\nfunction getDocumentRect(document: Document): BoundingOffset {\n const { top, left } = document.documentElement.getBoundingClientRect();\n return {\n top,\n left,\n width: document.documentElement.scrollWidth,\n height: document.documentElement.scrollHeight,\n };\n}\n"]}
|
package/popover/internal.js
CHANGED
|
@@ -65,8 +65,8 @@ function InternalPopover(_a, ref) {
|
|
|
65
65
|
onKeyDown: onTriggerKeyDown,
|
|
66
66
|
className: clsx(styles.trigger, styles["trigger-type-".concat(triggerType)])
|
|
67
67
|
};
|
|
68
|
-
var popoverContent = (React.createElement("span", { "aria-live": dismissButton ? undefined : 'polite', "aria-atomic": dismissButton ? undefined : true, className: popoverClasses }, visible && (React.createElement(PopoverContainer, { position: position, trackRef: triggerRef, arrow: function (position) { return React.createElement(Arrow, { position: position }); }, renderWithPortal: renderWithPortal, zIndex: renderWithPortal ? 7000 : undefined },
|
|
69
|
-
React.createElement(PopoverBody, {
|
|
68
|
+
var popoverContent = (React.createElement("span", { "aria-live": dismissButton ? undefined : 'polite', "aria-atomic": dismissButton ? undefined : true, className: popoverClasses }, visible && (React.createElement(PopoverContainer, { size: size, fixedWidth: fixedWidth, position: position, trackRef: triggerRef, arrow: function (position) { return React.createElement(Arrow, { position: position }); }, renderWithPortal: renderWithPortal, zIndex: renderWithPortal ? 7000 : undefined },
|
|
69
|
+
React.createElement(PopoverBody, { dismissButton: dismissButton, dismissAriaLabel: dismissAriaLabel, header: header, onDismiss: onDismiss, overflowVisible: "both" }, content)))));
|
|
70
70
|
var mergedRef = useMergeRefs(popoverRef, __internalRootRef);
|
|
71
71
|
return (React.createElement("span", __assign({}, baseProps, { className: clsx(styles.root, baseProps.className), ref: mergedRef, onMouseDown: function () {
|
|
72
72
|
// Indicate there was a click inside popover recently, including nested portals.
|
package/popover/internal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/popover/internal.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAC;AAC7F,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,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AAW,EAAE;YACX,gFAAgF;YAChF,YAAY,CAAC,OAAO,GAAG,qBAAqB,CAAC;gBAC3C,YAAY,CAAC,OAAO,GAAG,IAAI,CAAC;YAC9B,CAAC,CAAC,CAAC;QACL,CAAC;QAEA,WAAW,KAAK,MAAM,CAAC,CAAC,CAAC,CACxB,2CAAY,YAAY,IAAE,IAAI,EAAC,QAAQ,mBAAe,QAAQ,IAAK,YAAY;YAC7E,8BAAM,SAAS,EAAE,MAAM,CAAC,oBAAoB,CAAC,IAAG,QAAQ,CAAQ,CACzD,CACV,CAAC,CAAC,CAAC,CACF,yCAAU,YAAY,GAAG,QAAQ,CAAQ,CAC1C;QACA,gBAAgB,CAAC,CAAC,CAAC,oBAAC,MAAM,QAAE,cAAc,CAAU,CAAC,CAAC,CAAC,cAAc,CACjE,CACR,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useCallback, useEffect, useRef, useState, useImperativeHandle } from 'react';\nimport clsx from 'clsx';\n\nimport { KeyCode } from '../internal/keycode';\nimport { getBaseProps } from '../internal/base-component';\nimport useFocusVisible from '../internal/hooks/focus-visible';\n\nimport Arrow from './arrow';\nimport Portal from '../internal/components/portal';\nimport { PopoverProps } from './interfaces';\nimport PopoverContainer from './container';\nimport PopoverBody from './body';\n\nimport styles from './styles.css.js';\nimport { NonCancelableEventHandler, fireNonCancelableEvent } from '../internal/events/index';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component';\nimport { useMergeRefs } from '../internal/hooks/use-merge-refs';\nimport { usePortalModeClasses } from '../internal/hooks/use-portal-mode-classes';\n\nexport interface InternalPopoverProps extends PopoverProps, InternalBaseComponentProps {\n __onOpen?: NonCancelableEventHandler<null>;\n}\n\nexport interface InternalPopoverRef {\n dismissPopover: () => void;\n}\n\nexport default React.forwardRef(InternalPopover);\n\nfunction InternalPopover(\n {\n position = 'right',\n size = 'medium',\n fixedWidth = false,\n triggerType = 'text',\n dismissButton = true,\n dismissAriaLabel,\n\n children,\n header,\n content,\n\n renderWithPortal = false,\n\n __onOpen,\n __internalRootRef = null,\n ...restProps\n }: InternalPopoverProps,\n ref: React.Ref<InternalPopoverRef>\n) {\n const baseProps = getBaseProps(restProps);\n const focusVisible = useFocusVisible();\n const triggerRef = useRef<HTMLElement | null>(null);\n const popoverRef = useRef<HTMLSpanElement | null>(null);\n const clickFrameId = useRef<number | null>(null);\n\n const [visible, setVisible] = useState(false);\n\n const onTriggerClick = useCallback(() => {\n fireNonCancelableEvent(__onOpen);\n setVisible(true);\n }, [__onOpen]);\n\n const onDismiss = useCallback(() => {\n setVisible(false);\n }, []);\n\n const onTriggerKeyDown = useCallback((event: React.KeyboardEvent) => {\n if (event.keyCode === KeyCode.tab || event.keyCode === KeyCode.escape) {\n setVisible(false);\n }\n }, []);\n\n useImperativeHandle(ref, () => ({\n dismissPopover: onDismiss,\n }));\n\n useEffect(() => {\n if (!triggerRef.current) {\n return;\n }\n const document = triggerRef.current.ownerDocument;\n\n const onDocumentClick = () => {\n // Dismiss popover unless there was a click inside within the last animation frame.\n if (clickFrameId.current === null) {\n setVisible(false);\n }\n };\n\n // useCapture=false makes sure this listener is called after the one attached to the element.\n // the options.capture notation is unsupported by IE.\n document.addEventListener('mousedown', onDocumentClick, false);\n\n return () => {\n document.removeEventListener('mousedown', onDocumentClick, false);\n };\n }, []);\n\n const popoverClasses = usePortalModeClasses(triggerRef);\n\n const triggerProps = {\n // https://github.com/microsoft/TypeScript/issues/36659\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ref: triggerRef as any,\n onClick: onTriggerClick,\n onKeyDown: onTriggerKeyDown,\n className: clsx(styles.trigger, styles[`trigger-type-${triggerType}`]),\n };\n\n const popoverContent = (\n <span\n aria-live={dismissButton ? undefined : 'polite'}\n aria-atomic={dismissButton ? undefined : true}\n className={popoverClasses}\n >\n {visible && (\n <PopoverContainer\n size={size}\n fixedWidth={fixedWidth}\n position={position}\n trackRef={triggerRef}\n arrow={position => <Arrow position={position} />}\n renderWithPortal={renderWithPortal}\n zIndex={renderWithPortal ? 7000 : undefined}\n >\n <PopoverBody\n dismissButton={dismissButton}\n dismissAriaLabel={dismissAriaLabel}\n header={header}\n onDismiss={onDismiss}\n overflowVisible=\"both\"\n >\n {content}\n </PopoverBody>\n </PopoverContainer>\n )}\n </span>\n );\n\n const mergedRef = useMergeRefs(popoverRef, __internalRootRef);\n\n return (\n <span\n {...baseProps}\n className={clsx(styles.root, baseProps.className)}\n ref={mergedRef}\n onMouseDown={() => {\n // Indicate there was a click inside popover recently, including nested portals.\n clickFrameId.current = requestAnimationFrame(() => {\n clickFrameId.current = null;\n });\n }}\n >\n {triggerType === 'text' ? (\n <button {...triggerProps} type=\"button\" aria-haspopup=\"dialog\" {...focusVisible}>\n <span className={styles['trigger-inner-text']}>{children}</span>\n </button>\n ) : (\n <span {...triggerProps}>{children}</span>\n )}\n {renderWithPortal ? <Portal>{popoverContent}</Portal> : popoverContent}\n </span>\n );\n}\n"]}
|
package/popover/styles.css.js
CHANGED
|
@@ -1,53 +1,54 @@
|
|
|
1
1
|
|
|
2
2
|
import './styles.scoped.css';
|
|
3
3
|
export default {
|
|
4
|
-
"arrow": "
|
|
5
|
-
"arrow-outer": "awsui_arrow-
|
|
6
|
-
"arrow-inner": "awsui_arrow-
|
|
7
|
-
"arrow-position-right-top": "awsui_arrow-position-right-
|
|
8
|
-
"arrow-position-right-bottom": "awsui_arrow-position-right-
|
|
9
|
-
"arrow-position-left-top": "awsui_arrow-position-left-
|
|
10
|
-
"arrow-position-left-bottom": "awsui_arrow-position-left-
|
|
11
|
-
"arrow-position-top-center": "awsui_arrow-position-top-
|
|
12
|
-
"arrow-position-top-right": "awsui_arrow-position-top-
|
|
13
|
-
"arrow-position-top-left": "awsui_arrow-position-top-
|
|
14
|
-
"arrow-position-top-responsive": "awsui_arrow-position-top-
|
|
15
|
-
"arrow-position-bottom-center": "awsui_arrow-position-bottom-
|
|
16
|
-
"arrow-position-bottom-right": "awsui_arrow-position-bottom-
|
|
17
|
-
"arrow-position-bottom-left": "awsui_arrow-position-bottom-
|
|
18
|
-
"arrow-position-bottom-responsive": "awsui_arrow-position-bottom-
|
|
19
|
-
"body": "
|
|
20
|
-
"body-overflow-visible": "awsui_body-overflow-
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"container": "
|
|
34
|
-
"container-
|
|
35
|
-
"container-arrow
|
|
36
|
-
"container-arrow-position-right-
|
|
37
|
-
"container-arrow-position-
|
|
38
|
-
"container-arrow-position-left-
|
|
39
|
-
"container-arrow-position-
|
|
40
|
-
"container-arrow-position-top-
|
|
41
|
-
"container-arrow-position-top-
|
|
42
|
-
"container-arrow-position-top-
|
|
43
|
-
"container-arrow-position-
|
|
44
|
-
"container-arrow-position-bottom-
|
|
45
|
-
"container-arrow-position-bottom-
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"trigger
|
|
51
|
-
"trigger-
|
|
4
|
+
"arrow": "awsui_arrow_xjuzf_1aa2b_185",
|
|
5
|
+
"arrow-outer": "awsui_arrow-outer_xjuzf_1aa2b_189",
|
|
6
|
+
"arrow-inner": "awsui_arrow-inner_xjuzf_1aa2b_189",
|
|
7
|
+
"arrow-position-right-top": "awsui_arrow-position-right-top_xjuzf_1aa2b_220",
|
|
8
|
+
"arrow-position-right-bottom": "awsui_arrow-position-right-bottom_xjuzf_1aa2b_220",
|
|
9
|
+
"arrow-position-left-top": "awsui_arrow-position-left-top_xjuzf_1aa2b_223",
|
|
10
|
+
"arrow-position-left-bottom": "awsui_arrow-position-left-bottom_xjuzf_1aa2b_223",
|
|
11
|
+
"arrow-position-top-center": "awsui_arrow-position-top-center_xjuzf_1aa2b_226",
|
|
12
|
+
"arrow-position-top-right": "awsui_arrow-position-top-right_xjuzf_1aa2b_226",
|
|
13
|
+
"arrow-position-top-left": "awsui_arrow-position-top-left_xjuzf_1aa2b_226",
|
|
14
|
+
"arrow-position-top-responsive": "awsui_arrow-position-top-responsive_xjuzf_1aa2b_226",
|
|
15
|
+
"arrow-position-bottom-center": "awsui_arrow-position-bottom-center_xjuzf_1aa2b_229",
|
|
16
|
+
"arrow-position-bottom-right": "awsui_arrow-position-bottom-right_xjuzf_1aa2b_229",
|
|
17
|
+
"arrow-position-bottom-left": "awsui_arrow-position-bottom-left_xjuzf_1aa2b_229",
|
|
18
|
+
"arrow-position-bottom-responsive": "awsui_arrow-position-bottom-responsive_xjuzf_1aa2b_229",
|
|
19
|
+
"body": "awsui_body_xjuzf_1aa2b_325",
|
|
20
|
+
"body-overflow-visible": "awsui_body-overflow-visible_xjuzf_1aa2b_339",
|
|
21
|
+
"has-dismiss": "awsui_has-dismiss_xjuzf_1aa2b_343",
|
|
22
|
+
"dismiss": "awsui_dismiss_xjuzf_1aa2b_348",
|
|
23
|
+
"dismiss-control": "awsui_dismiss-control_xjuzf_1aa2b_355",
|
|
24
|
+
"header-row": "awsui_header-row_xjuzf_1aa2b_359",
|
|
25
|
+
"header": "awsui_header_xjuzf_1aa2b_359",
|
|
26
|
+
"content": "awsui_content_xjuzf_1aa2b_381",
|
|
27
|
+
"content-overflow-visible": "awsui_content-overflow-visible_xjuzf_1aa2b_388",
|
|
28
|
+
"container": "awsui_container_xjuzf_1aa2b_484",
|
|
29
|
+
"container-body": "awsui_container-body_xjuzf_1aa2b_492",
|
|
30
|
+
"container-body-variant-annotation": "awsui_container-body-variant-annotation_xjuzf_1aa2b_507",
|
|
31
|
+
"container-body-size-small": "awsui_container-body-size-small_xjuzf_1aa2b_512",
|
|
32
|
+
"fixed-width": "awsui_fixed-width_xjuzf_1aa2b_515",
|
|
33
|
+
"container-body-size-medium": "awsui_container-body-size-medium_xjuzf_1aa2b_519",
|
|
34
|
+
"container-body-size-large": "awsui_container-body-size-large_xjuzf_1aa2b_526",
|
|
35
|
+
"container-arrow": "awsui_container-arrow_xjuzf_1aa2b_538",
|
|
36
|
+
"container-arrow-position-right-top": "awsui_container-arrow-position-right-top_xjuzf_1aa2b_542",
|
|
37
|
+
"container-arrow-position-right-bottom": "awsui_container-arrow-position-right-bottom_xjuzf_1aa2b_542",
|
|
38
|
+
"container-arrow-position-left-top": "awsui_container-arrow-position-left-top_xjuzf_1aa2b_554",
|
|
39
|
+
"container-arrow-position-left-bottom": "awsui_container-arrow-position-left-bottom_xjuzf_1aa2b_554",
|
|
40
|
+
"container-arrow-position-top-center": "awsui_container-arrow-position-top-center_xjuzf_1aa2b_566",
|
|
41
|
+
"container-arrow-position-top-right": "awsui_container-arrow-position-top-right_xjuzf_1aa2b_566",
|
|
42
|
+
"container-arrow-position-top-left": "awsui_container-arrow-position-top-left_xjuzf_1aa2b_566",
|
|
43
|
+
"container-arrow-position-top-responsive": "awsui_container-arrow-position-top-responsive_xjuzf_1aa2b_566",
|
|
44
|
+
"container-arrow-position-bottom-center": "awsui_container-arrow-position-bottom-center_xjuzf_1aa2b_582",
|
|
45
|
+
"container-arrow-position-bottom-right": "awsui_container-arrow-position-bottom-right_xjuzf_1aa2b_586",
|
|
46
|
+
"container-arrow-position-bottom-left": "awsui_container-arrow-position-bottom-left_xjuzf_1aa2b_590",
|
|
47
|
+
"awsui-motion-fade-in": "awsui_awsui-motion-fade-in_xjuzf_1aa2b_1",
|
|
48
|
+
"refresh": "awsui_refresh_xjuzf_1aa2b_708",
|
|
49
|
+
"root": "awsui_root_xjuzf_1aa2b_730",
|
|
50
|
+
"trigger": "awsui_trigger_xjuzf_1aa2b_742",
|
|
51
|
+
"trigger-type-text": "awsui_trigger-type-text_xjuzf_1aa2b_749",
|
|
52
|
+
"trigger-inner-text": "awsui_trigger-inner-text_xjuzf_1aa2b_778"
|
|
52
53
|
};
|
|
53
54
|
|