@cloudscape-design/components 3.0.359 → 3.0.361
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/app-layout/index.d.ts.map +1 -1
- package/app-layout/index.js +4 -5
- package/app-layout/index.js.map +1 -1
- package/app-layout/utils/use-content-width.js +1 -1
- package/app-layout/utils/use-content-width.js.map +1 -1
- package/app-layout/utils/use-observed-element.js +1 -1
- package/app-layout/utils/use-observed-element.js.map +1 -1
- package/area-chart/model/use-chart-model.d.ts.map +1 -1
- package/area-chart/model/use-chart-model.js +2 -2
- package/area-chart/model/use-chart-model.js.map +1 -1
- package/code-editor/listeners.js +2 -2
- package/code-editor/listeners.js.map +1 -1
- package/code-editor/resizable-box/index.js +2 -2
- package/code-editor/resizable-box/index.js.map +1 -1
- package/internal/breakpoints.d.ts +1 -0
- package/internal/breakpoints.d.ts.map +1 -1
- package/internal/breakpoints.js +3 -0
- package/internal/breakpoints.js.map +1 -1
- package/internal/components/autosuggest-input/index.d.ts.map +1 -1
- package/internal/components/autosuggest-input/index.js +1 -1
- package/internal/components/autosuggest-input/index.js.map +1 -1
- package/internal/components/dark-ribbon/index.js +2 -2
- package/internal/components/dark-ribbon/index.js.map +1 -1
- package/internal/components/dropdown/dropdown-fit-handler.d.ts +13 -2
- package/internal/components/dropdown/dropdown-fit-handler.d.ts.map +1 -1
- package/internal/components/dropdown/dropdown-fit-handler.js +30 -10
- package/internal/components/dropdown/dropdown-fit-handler.js.map +1 -1
- package/internal/components/dropdown/index.d.ts +1 -1
- package/internal/components/dropdown/index.d.ts.map +1 -1
- package/internal/components/dropdown/index.js +7 -6
- package/internal/components/dropdown/index.js.map +1 -1
- package/internal/components/dropdown/interfaces.d.ts +4 -0
- package/internal/components/dropdown/interfaces.d.ts.map +1 -1
- package/internal/components/dropdown/interfaces.js.map +1 -1
- package/internal/components/dropdown/styles.css.js +21 -20
- package/internal/components/dropdown/styles.scoped.css +38 -35
- package/internal/components/dropdown/styles.selectors.js +21 -20
- package/internal/components/options-list/index.d.ts.map +1 -1
- package/internal/components/options-list/index.js +2 -2
- package/internal/components/options-list/index.js.map +1 -1
- package/internal/environment.js +1 -1
- package/internal/environment.json +1 -1
- package/internal/hooks/container-queries/index.d.ts +0 -1
- package/internal/hooks/container-queries/index.d.ts.map +1 -1
- package/internal/hooks/container-queries/index.js +0 -1
- package/internal/hooks/container-queries/index.js.map +1 -1
- package/internal/hooks/container-queries/use-height-measure.js +1 -1
- package/internal/hooks/container-queries/use-height-measure.js.map +1 -1
- package/internal/hooks/use-dynamic-overlap/index.js +1 -1
- package/internal/hooks/use-dynamic-overlap/index.js.map +1 -1
- package/internal/hooks/use-mobile/index.js +1 -1
- package/internal/hooks/use-mobile/index.js.map +1 -1
- package/internal/hooks/use-mouse-down-target.js +1 -1
- package/internal/hooks/use-mouse-down-target.js.map +1 -1
- package/internal/hooks/use-mutation-observer/index.d.ts.map +1 -1
- package/internal/hooks/use-mutation-observer/index.js +2 -3
- package/internal/hooks/use-mutation-observer/index.js.map +1 -1
- package/internal/manifest.json +1 -1
- package/multiselect/internal.d.ts.map +1 -1
- package/multiselect/internal.js +1 -1
- package/multiselect/internal.js.map +1 -1
- package/package.json +1 -1
- package/pie-chart/labels.js +1 -1
- package/pie-chart/labels.js.map +1 -1
- package/popover/container.d.ts.map +1 -1
- package/popover/container.js +1 -1
- package/popover/container.js.map +1 -1
- package/s3-resource-selector/s3-in-context/use-versions-fetch.d.ts.map +1 -1
- package/s3-resource-selector/s3-in-context/use-versions-fetch.js +2 -2
- package/s3-resource-selector/s3-in-context/use-versions-fetch.js.map +1 -1
- package/s3-resource-selector/s3-modal/basic-table.d.ts.map +1 -1
- package/s3-resource-selector/s3-modal/basic-table.js +2 -2
- package/s3-resource-selector/s3-modal/basic-table.js.map +1 -1
- package/select/internal.d.ts.map +1 -1
- package/select/internal.js +1 -1
- package/select/internal.js.map +1 -1
- package/split-panel/bottom.js +1 -1
- package/split-panel/bottom.js.map +1 -1
- package/table/body-cell/click-away.js +2 -2
- package/table/body-cell/click-away.js.map +1 -1
- package/table/resizer/index.js +3 -3
- package/table/resizer/index.js.map +1 -1
- package/table/sticky-columns/use-sticky-columns.d.ts.map +1 -1
- package/table/sticky-columns/use-sticky-columns.js +2 -3
- package/table/sticky-columns/use-sticky-columns.js.map +1 -1
- package/table/use-sticky-header.js +1 -1
- package/table/use-sticky-header.js.map +1 -1
- package/tag-editor/index.d.ts.map +1 -1
- package/tag-editor/index.js +6 -6
- package/tag-editor/index.js.map +1 -1
- package/internal/hooks/container-queries/use-resize-observer.d.ts +0 -21
- package/internal/hooks/container-queries/use-resize-observer.d.ts.map +0 -1
- package/internal/hooks/container-queries/use-resize-observer.js +0 -54
- package/internal/hooks/container-queries/use-resize-observer.js.map +0 -1
- package/internal/hooks/container-queries/utils.d.ts +0 -4
- package/internal/hooks/container-queries/utils.d.ts.map +0 -1
- package/internal/hooks/container-queries/utils.js +0 -10
- package/internal/hooks/container-queries/utils.js.map +0 -1
- package/internal/hooks/use-singleton-handler/index.d.ts +0 -11
- package/internal/hooks/use-singleton-handler/index.d.ts.map +0 -1
- package/internal/hooks/use-singleton-handler/index.js +0 -45
- package/internal/hooks/use-singleton-handler/index.js.map +0 -1
- package/internal/hooks/use-stable-event-handler/index.d.ts +0 -10
- package/internal/hooks/use-stable-event-handler/index.d.ts.map +0 -1
- package/internal/hooks/use-stable-event-handler/index.js +0 -19
- package/internal/hooks/use-stable-event-handler/index.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"lib/default/","sources":["code-editor/resizable-box/index.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC3D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"lib/default/","sources":["code-editor/resizable-box/index.tsx"],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jE,CAAC,CAAC;QACF,MAAM,SAAS,GAAG,GAAG,EAAE;YACrB,aAAa,CAAC,IAAI,CAAC,CAAC;QACtB,CAAC,CAAC;QACF,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC;QACrD,QAAQ,CAAC,gBAAgB,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;QACpD,QAAQ,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QAChD,OAAO,GAAG,EAAE;YACV,QAAQ,CAAC,mBAAmB,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;YACvD,QAAQ,CAAC,mBAAmB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;YACnD,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC;QAC1D,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,UAAU,EAAE,SAAS,EAAE,cAAc,CAAC,CAAC,CAAC;IAE5C,OAAO,CACL,6BAAK,GAAG,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE;QAC1E,QAAQ;QACT,8BAAM,SAAS,EAAE,MAAM,CAAC,sBAAsB,CAAC,EAAE,WAAW,EAAE,WAAW,GAAI,CACzE,CACP,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useEffect, useRef, useState } from 'react';\nimport styles from './styles.css.js';\nimport { useStableCallback } from '@cloudscape-design/component-toolkit/internal';\n\nexport interface ResizeBoxProps {\n children: React.ReactNode;\n height: number;\n minHeight: number;\n onResize: (newHeight: number) => void;\n}\n\nexport function ResizableBox({ children, height, minHeight, onResize }: ResizeBoxProps) {\n const [dragOffset, setDragOffset] = useState<null | number>(null);\n const onResizeStable = useStableCallback(onResize);\n const containerRef = useRef<HTMLDivElement>(null);\n\n const onMouseDown: React.MouseEventHandler = event => {\n if (event.button !== 0 || !containerRef.current) {\n return;\n }\n const containerBottom = containerRef.current.getBoundingClientRect().bottom;\n setDragOffset(containerBottom - event.clientY);\n };\n\n useEffect(() => {\n if (dragOffset === null || !containerRef.current) {\n return;\n }\n const container = containerRef.current;\n\n const onMouseMove = (event: MouseEvent) => {\n const { top } = container.getBoundingClientRect();\n const cursor = event.clientY;\n onResizeStable(Math.max(cursor + dragOffset - top, minHeight));\n };\n const onMouseUp = () => {\n setDragOffset(null);\n };\n document.body.classList.add(styles['resize-active']);\n document.addEventListener('mousemove', onMouseMove);\n document.addEventListener('mouseup', onMouseUp);\n return () => {\n document.removeEventListener('mousemove', onMouseMove);\n document.removeEventListener('mouseup', onMouseUp);\n document.body.classList.remove(styles['resize-active']);\n };\n }, [dragOffset, minHeight, onResizeStable]);\n\n return (\n <div ref={containerRef} className={styles['resizable-box']} style={{ height }}>\n {children}\n <span className={styles['resizable-box-handle']} onMouseDown={onMouseDown} />\n </div>\n );\n}\n"]}
|
|
@@ -8,4 +8,5 @@ export declare function matchBreakpointMapping<T>(subset: Partial<Record<Breakpo
|
|
|
8
8
|
* Get the named breakpoint for a provided width, optionally filtering to a subset of breakpoints.
|
|
9
9
|
*/
|
|
10
10
|
export declare function getMatchingBreakpoint(width: number, breakpointFilter?: readonly Breakpoint[]): Breakpoint;
|
|
11
|
+
export declare function getBreakpointValue(breakpoint: Breakpoint): number;
|
|
11
12
|
//# sourceMappingURL=breakpoints.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"breakpoints.d.ts","sourceRoot":"lib/default/","sources":["internal/breakpoints.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,KAAK,GAAG,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,CAAC;AAY3E,eAAO,MAAM,gBAAgB,QAAsD,CAAC;AAIpF;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,GAAG,CAAC,GAAG,IAAI,CAS9G;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,gBAAgB,CAAC,EAAE,SAAS,UAAU,EAAE,GAAG,UAAU,CAOzG"}
|
|
1
|
+
{"version":3,"file":"breakpoints.d.ts","sourceRoot":"lib/default/","sources":["internal/breakpoints.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,KAAK,GAAG,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,CAAC;AAY3E,eAAO,MAAM,gBAAgB,QAAsD,CAAC;AAIpF;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,GAAG,CAAC,GAAG,IAAI,CAS9G;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,gBAAgB,CAAC,EAAE,SAAS,UAAU,EAAE,GAAG,UAAU,CAOzG;AAED,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAEjE"}
|
package/internal/breakpoints.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"breakpoints.js","sourceRoot":"lib/default/","sources":["internal/breakpoints.ts"],"names":[],"mappings":"AAIA,MAAM,kBAAkB,GAA2B;IACjD,CAAC,IAAI,EAAE,IAAI,CAAC;IACZ,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,IAAI,EAAE,GAAG,CAAC;IACX,CAAC,KAAK,EAAE,GAAG,CAAC;IACZ,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;CAChB,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEpF,MAAM,sBAAsB,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;AAEpE;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAI,MAAsC,EAAE,MAAkB;IAClG,MAAM,qBAAqB,GAAG,kBAAkB,CAAC,KAAK,CAAC,sBAAsB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IAC/F,KAAK,MAAM,CAAC,UAAU,CAAC,IAAI,qBAAqB,EAAE;QAChD,MAAM,eAAe,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;QAC3C,IAAI,eAAe,KAAK,SAAS,EAAE;YACjC,OAAO,eAAe,CAAC;SACxB;KACF;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAa,EAAE,gBAAwC;IAC3F,KAAK,MAAM,CAAC,UAAU,EAAE,eAAe,CAAC,IAAI,kBAAkB,EAAE;QAC9D,IAAI,KAAK,GAAG,eAAe,IAAI,CAAC,CAAC,gBAAgB,IAAI,gBAAgB,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;YACjG,OAAO,UAAU,CAAC;SACnB;KACF;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nexport type Breakpoint = 'default' | 'xxs' | 'xs' | 's' | 'm' | 'l' | 'xl';\n\nconst BREAKPOINT_MAPPING: [Breakpoint, number][] = [\n ['xl', 1840],\n ['l', 1320],\n ['m', 1120],\n ['s', 912],\n ['xs', 688],\n ['xxs', 465],\n ['default', -1],\n];\n\nexport const mobileBreakpoint = BREAKPOINT_MAPPING.filter(b => b[0] === 'xs')[0][1];\n\nconst BREAKPOINTS_DESCENDING = BREAKPOINT_MAPPING.map(([bp]) => bp);\n\n/**\n * Take a breakpoint mapping and return the breakpoint value that most closely matches the actual breakpoint.\n */\nexport function matchBreakpointMapping<T>(subset: Partial<Record<Breakpoint, T>>, actual: Breakpoint): T | null {\n const qualifyingBreakpoints = BREAKPOINT_MAPPING.slice(BREAKPOINTS_DESCENDING.indexOf(actual));\n for (const [breakpoint] of qualifyingBreakpoints) {\n const breakpointValue = subset[breakpoint];\n if (breakpointValue !== undefined) {\n return breakpointValue;\n }\n }\n return null;\n}\n\n/**\n * Get the named breakpoint for a provided width, optionally filtering to a subset of breakpoints.\n */\nexport function getMatchingBreakpoint(width: number, breakpointFilter?: readonly Breakpoint[]): Breakpoint {\n for (const [breakpoint, breakpointWidth] of BREAKPOINT_MAPPING) {\n if (width > breakpointWidth && (!breakpointFilter || breakpointFilter.indexOf(breakpoint) !== -1)) {\n return breakpoint;\n }\n }\n return 'default';\n}\n"]}
|
|
1
|
+
{"version":3,"file":"breakpoints.js","sourceRoot":"lib/default/","sources":["internal/breakpoints.ts"],"names":[],"mappings":"AAIA,MAAM,kBAAkB,GAA2B;IACjD,CAAC,IAAI,EAAE,IAAI,CAAC;IACZ,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,IAAI,CAAC;IACX,CAAC,GAAG,EAAE,GAAG,CAAC;IACV,CAAC,IAAI,EAAE,GAAG,CAAC;IACX,CAAC,KAAK,EAAE,GAAG,CAAC;IACZ,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;CAChB,CAAC;AAEF,MAAM,CAAC,MAAM,gBAA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2.0\nexport type Breakpoint = 'default' | 'xxs' | 'xs' | 's' | 'm' | 'l' | 'xl';\n\nconst BREAKPOINT_MAPPING: [Breakpoint, number][] = [\n ['xl', 1840],\n ['l', 1320],\n ['m', 1120],\n ['s', 912],\n ['xs', 688],\n ['xxs', 465],\n ['default', -1],\n];\n\nexport const mobileBreakpoint = BREAKPOINT_MAPPING.filter(b => b[0] === 'xs')[0][1];\n\nconst BREAKPOINTS_DESCENDING = BREAKPOINT_MAPPING.map(([bp]) => bp);\n\n/**\n * Take a breakpoint mapping and return the breakpoint value that most closely matches the actual breakpoint.\n */\nexport function matchBreakpointMapping<T>(subset: Partial<Record<Breakpoint, T>>, actual: Breakpoint): T | null {\n const qualifyingBreakpoints = BREAKPOINT_MAPPING.slice(BREAKPOINTS_DESCENDING.indexOf(actual));\n for (const [breakpoint] of qualifyingBreakpoints) {\n const breakpointValue = subset[breakpoint];\n if (breakpointValue !== undefined) {\n return breakpointValue;\n }\n }\n return null;\n}\n\n/**\n * Get the named breakpoint for a provided width, optionally filtering to a subset of breakpoints.\n */\nexport function getMatchingBreakpoint(width: number, breakpointFilter?: readonly Breakpoint[]): Breakpoint {\n for (const [breakpoint, breakpointWidth] of BREAKPOINT_MAPPING) {\n if (width > breakpointWidth && (!breakpointFilter || breakpointFilter.indexOf(breakpoint) !== -1)) {\n return breakpoint;\n }\n }\n return 'default';\n}\n\nexport function getBreakpointValue(breakpoint: Breakpoint): number {\n return BREAKPOINT_MAPPING.find(bp => bp[0] === breakpoint)![1];\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"lib/default/","sources":["internal/components/autosuggest-input/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAgE,MAAM,OAAO,CAAC;AAIrF,OAAO,EAAE,+BAA+B,EAAuB,MAAM,kCAAkC,CAAC;AACxG,OAAO,EAAE,kBAAkB,EAAgB,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAA8D,yBAA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AI,IAAI,IAAI,CAAC;IACb,KAAK,IAAI,IAAI,CAAC;CACf;AAED,QAAA,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"lib/default/","sources":["internal/components/autosuggest-input/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAgE,MAAM,OAAO,CAAC;AAIrF,OAAO,EAAE,+BAA+B,EAAuB,MAAM,kCAAkC,CAAC;AACxG,OAAO,EAAE,kBAAkB,EAAgB,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAA8D,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAErH,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,cAAc,EACf,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AAK5E,MAAM,WAAW,qBACf,SAAQ,kBAAkB,EACxB,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,+BAA+B,EAC/B,gBAAgB,EAChB,0BAA0B;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,eAAe,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAClC,cAAc,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACjC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,eAAe,CAAC,EAAE,yBAAyB,CAAC,IAAI,CAAC,CAAC;IAClD,cAAc,CAAC,EAAE,yBAAyB,CAAC,gBAAgB,CAAC,CAAC;IAC7D,gBAAgB,CAAC,EAAE,MAAM,IAAI,CAAC;IAC9B,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;IAC5B,YAAY,CAAC,EAAE,MAAM,OAAO,CAAC;CAC9B;AAED,MAAM,WAAW,4BAA4B;IAC3C,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,MAAM,WAAW,mBAAoB,SAAQ,gBAAgB,CAAC,GAAG;IAC/D,KAAK,CAAC,OAAO,CAAC,EAAE,4BAA4B,GAAG,IAAI,CAAC;IACpD,IAAI,IAAI,IAAI,CAAC;IACb,KAAK,IAAI,IAAI,CAAC;CACf;AAED,QAAA,MAAM,gBAAgB,mGAiPrB,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
|
@@ -150,7 +150,7 @@ const AutosuggestInput = React.forwardRef((_a, ref) => {
|
|
|
150
150
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
151
151
|
}, [open]);
|
|
152
152
|
return (React.createElement("div", Object.assign({}, baseProps, { className: clsx(baseProps.className, styles.root), ref: __internalRootRef }),
|
|
153
|
-
React.createElement(Dropdown, { minWidth: dropdownWidth, stretchWidth: !dropdownWidth, contentKey: dropdownContentKey, onFocus: handleFocus, onBlur: handleBlur, trigger: React.createElement(InternalInput, Object.assign({ type: "visualSearch", value: value, onChange: event => handleChange(event.detail.value), __onDelayedInput: event => handleDelayedInput(event.detail.value), onKeyDown: handleKeyDown, onKeyUp: onKeyUp, disabled: disabled, disableBrowserAutocorrect: disableBrowserAutocorrect, readOnly: readOnly, ariaRequired: ariaRequired, clearAriaLabel: clearAriaLabel, ref: inputRef, autoComplete: false, __nativeAttributes: nativeAttributes }, formFieldContext)), onMouseDown: handleDropdownMouseDown, open: open && !!dropdownContent, footer: dropdownFooterRef && (React.createElement("div", { ref: dropdownFooterRef, className: styles['dropdown-footer'] }, dropdownFooter)), expandToViewport: expandToViewport, loopFocus: loopFocus }, open && dropdownContent ? (React.createElement("div", { ref: dropdownContentRef, className: styles['dropdown-content'] }, dropdownContent)) : null)));
|
|
153
|
+
React.createElement(Dropdown, { minWidth: dropdownWidth, stretchWidth: !dropdownWidth, stretchBeyondTriggerWidth: true, contentKey: dropdownContentKey, onFocus: handleFocus, onBlur: handleBlur, trigger: React.createElement(InternalInput, Object.assign({ type: "visualSearch", value: value, onChange: event => handleChange(event.detail.value), __onDelayedInput: event => handleDelayedInput(event.detail.value), onKeyDown: handleKeyDown, onKeyUp: onKeyUp, disabled: disabled, disableBrowserAutocorrect: disableBrowserAutocorrect, readOnly: readOnly, ariaRequired: ariaRequired, clearAriaLabel: clearAriaLabel, ref: inputRef, autoComplete: false, __nativeAttributes: nativeAttributes }, formFieldContext)), onMouseDown: handleDropdownMouseDown, open: open && !!dropdownContent, footer: dropdownFooterRef && (React.createElement("div", { ref: dropdownFooterRef, className: styles['dropdown-footer'] }, dropdownFooter)), expandToViewport: expandToViewport, loopFocus: loopFocus }, open && dropdownContent ? (React.createElement("div", { ref: dropdownContentRef, className: styles['dropdown-content'] }, dropdownContent)) : null)));
|
|
154
154
|
});
|
|
155
155
|
export default AutosuggestInput;
|
|
156
156
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"lib/default/","sources":["internal/components/autosuggest-input/index.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;;AAEtC,OAAO,KAAK,EAAE,EAAO,MAAM,EAAE,QAAQ,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAErF,OAAO,QAAQ,MAAM,aAAa,CAAC;AAEnC,OAAO,EAAmC,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACxG,OAAO,EAAsB,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAiB,mBAAmB,EAAE,sBAAsB,EAA6B,MAAM,cAAc,CAAC;AACrH,OAAO,aAAa,MAAM,yBAAyB,CAAC;AAWpD,OAAO,EA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AAiB,IAAI,CACnB,6BAAK,GAAG,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,CAAC,iBAAiB,CAAC,IAC9D,cAAc,CACX,CACP,EAEH,gBAAgB,EAAE,gBAAgB,EAClC,SAAS,EAAE,SAAS,IAEnB,IAAI,IAAI,eAAe,CAAC,CAAC,CAAC,CACzB,6BAAK,GAAG,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,CAAC,kBAAkB,CAAC,IAChE,eAAe,CACZ,CACP,CAAC,CAAC,CAAC,IAAI,CACC,CACP,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,gBAAgB,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport React, { Ref, useRef, useState, useImperativeHandle, useEffect } from 'react';\n\nimport Dropdown from '../dropdown';\n\nimport { FormFieldValidationControlProps, useFormFieldContext } from '../../context/form-field-context';\nimport { BaseComponentProps, getBaseProps } from '../../base-component';\nimport { BaseKeyDetail, fireCancelableEvent, fireNonCancelableEvent, NonCancelableEventHandler } from '../../events';\nimport InternalInput from '../../../input/internal';\nimport {\n BaseChangeDetail,\n BaseInputProps,\n InputAutoCorrect,\n InputClearLabel,\n InputKeyEvents,\n} from '../../../input/interfaces';\nimport { AutosuggestProps } from '../../../autosuggest/interfaces';\nimport { ExpandToViewport } from '../dropdown/interfaces';\nimport { InternalBaseComponentProps } from '../../hooks/use-base-component';\nimport { KeyCode } from '../../keycode';\nimport styles from './styles.css.js';\nimport clsx from 'clsx';\n\nexport interface AutosuggestInputProps\n extends BaseComponentProps,\n BaseInputProps,\n InputAutoCorrect,\n InputKeyEvents,\n InputClearLabel,\n FormFieldValidationControlProps,\n ExpandToViewport,\n InternalBaseComponentProps {\n ariaControls?: string;\n ariaActivedescendant?: string;\n dropdownExpanded?: boolean;\n dropdownContentKey?: string;\n dropdownContentFocusable?: boolean;\n dropdownContent?: React.ReactNode;\n dropdownFooter?: React.ReactNode;\n dropdownWidth?: number;\n loopFocus?: boolean;\n onCloseDropdown?: NonCancelableEventHandler<null>;\n onDelayedInput?: NonCancelableEventHandler<BaseChangeDetail>;\n onPressArrowDown?: () => void;\n onPressArrowUp?: () => void;\n onPressEnter?: () => boolean;\n}\n\nexport interface AutosuggestInputFocusOptions {\n preventDropdown?: boolean;\n}\n\nexport interface AutosuggestInputRef extends AutosuggestProps.Ref {\n focus(options?: AutosuggestInputFocusOptions): void;\n open(): void;\n close(): void;\n}\n\nconst AutosuggestInput = React.forwardRef(\n (\n {\n value,\n onChange,\n onBlur,\n onFocus,\n onKeyUp,\n onKeyDown,\n name,\n placeholder,\n disabled,\n readOnly,\n autoFocus,\n ariaLabel,\n ariaRequired,\n disableBrowserAutocorrect = false,\n expandToViewport,\n ariaControls,\n ariaActivedescendant,\n clearAriaLabel,\n dropdownExpanded = true,\n dropdownContentKey,\n dropdownContentFocusable = false,\n dropdownContent = null,\n dropdownFooter = null,\n dropdownWidth,\n loopFocus,\n onCloseDropdown,\n onDelayedInput,\n onPressArrowDown,\n onPressArrowUp,\n onPressEnter,\n __internalRootRef,\n ...restProps\n }: AutosuggestInputProps,\n ref: Ref<AutosuggestInputRef>\n ) => {\n const baseProps = getBaseProps(restProps);\n const formFieldContext = useFormFieldContext(restProps);\n\n const inputRef = useRef<HTMLInputElement>(null);\n const dropdownContentRef = useRef<HTMLDivElement>(null);\n const dropdownFooterRef = useRef<HTMLDivElement>(null);\n const preventOpenOnFocusRef = useRef(false);\n const preventCloseOnBlurRef = useRef(false);\n\n const [open, setOpen] = useState(false);\n\n const openDropdown = () => !readOnly && setOpen(true);\n\n const closeDropdown = () => {\n setOpen(false);\n fireNonCancelableEvent(onCloseDropdown, null);\n };\n\n useImperativeHandle(ref, () => ({\n focus(options?: AutosuggestInputFocusOptions) {\n if (options?.preventDropdown) {\n preventOpenOnFocusRef.current = true;\n }\n inputRef.current?.focus();\n },\n select() {\n inputRef.current?.select();\n },\n open: openDropdown,\n close: closeDropdown,\n }));\n\n const handleBlur = () => {\n if (!preventCloseOnBlurRef.current) {\n closeDropdown();\n fireNonCancelableEvent(onBlur, null);\n }\n };\n\n const handleFocus = () => {\n if (!preventOpenOnFocusRef.current) {\n openDropdown();\n fireNonCancelableEvent(onFocus, null);\n }\n preventOpenOnFocusRef.current = false;\n };\n\n const fireKeydown = (event: CustomEvent<BaseKeyDetail>) => fireCancelableEvent(onKeyDown, event.detail, event);\n\n const handleKeyDown = (event: CustomEvent<BaseKeyDetail>) => {\n switch (event.detail.keyCode) {\n case KeyCode.down: {\n onPressArrowDown?.();\n openDropdown();\n event.preventDefault();\n break;\n }\n case KeyCode.up: {\n onPressArrowUp?.();\n openDropdown();\n event.preventDefault();\n break;\n }\n case KeyCode.enter: {\n if (open) {\n if (!onPressEnter?.()) {\n closeDropdown();\n }\n event.preventDefault();\n }\n fireKeydown(event);\n break;\n }\n case KeyCode.escape: {\n if (open) {\n closeDropdown();\n } else if (value) {\n fireNonCancelableEvent(onChange, { value: '' });\n }\n event.preventDefault();\n fireKeydown(event);\n break;\n }\n default: {\n fireKeydown(event);\n }\n }\n };\n\n const handleChange = (value: string) => {\n openDropdown();\n fireNonCancelableEvent(onChange, { value });\n };\n\n const handleDelayedInput = (value: string) => {\n fireNonCancelableEvent(onDelayedInput, { value });\n };\n\n const handleDropdownMouseDown: React.MouseEventHandler = event => {\n // Prevent currently focused element from losing focus.\n if (!dropdownContentFocusable) {\n event.preventDefault();\n }\n // Prevent closing dropdown on click inside.\n else {\n preventCloseOnBlurRef.current = true;\n requestAnimationFrame(() => {\n preventCloseOnBlurRef.current = false;\n });\n }\n };\n\n const expanded = open && dropdownExpanded;\n const nativeAttributes = {\n name,\n placeholder,\n autoFocus,\n onClick: openDropdown,\n role: 'combobox',\n 'aria-autocomplete': 'list',\n 'aria-expanded': expanded,\n 'aria-controls': open ? ariaControls : undefined,\n // 'aria-owns' needed for safari+vo to announce activedescendant content\n 'aria-owns': open ? ariaControls : undefined,\n 'aria-label': ariaLabel,\n 'aria-activedescendant': ariaActivedescendant,\n };\n\n // Closes dropdown when outside click is detected.\n // Similar to the internal dropdown implementation but includes the target as well.\n useEffect(() => {\n if (!open) {\n return;\n }\n\n const clickListener = (event: MouseEvent) => {\n if (\n !inputRef.current?.contains(event.target as Node) &&\n !dropdownContentRef.current?.contains(event.target as Node) &&\n !dropdownFooterRef.current?.contains(event.target as Node)\n ) {\n closeDropdown();\n }\n };\n\n window.addEventListener('mousedown', clickListener);\n\n return () => {\n window.removeEventListener('mousedown', clickListener);\n };\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [open]);\n\n return (\n <div {...baseProps} className={clsx(baseProps.className, styles.root)} ref={__internalRootRef}>\n <Dropdown\n minWidth={dropdownWidth}\n stretchWidth={!dropdownWidth}\n contentKey={dropdownContentKey}\n onFocus={handleFocus}\n onBlur={handleBlur}\n trigger={\n <InternalInput\n type=\"visualSearch\"\n value={value}\n onChange={event => handleChange(event.detail.value)}\n __onDelayedInput={event => handleDelayedInput(event.detail.value)}\n onKeyDown={handleKeyDown}\n onKeyUp={onKeyUp}\n disabled={disabled}\n disableBrowserAutocorrect={disableBrowserAutocorrect}\n readOnly={readOnly}\n ariaRequired={ariaRequired}\n clearAriaLabel={clearAriaLabel}\n ref={inputRef}\n autoComplete={false}\n __nativeAttributes={nativeAttributes}\n {...formFieldContext}\n />\n }\n onMouseDown={handleDropdownMouseDown}\n open={open && !!dropdownContent}\n footer={\n dropdownFooterRef && (\n <div ref={dropdownFooterRef} className={styles['dropdown-footer']}>\n {dropdownFooter}\n </div>\n )\n }\n expandToViewport={expandToViewport}\n loopFocus={loopFocus}\n >\n {open && dropdownContent ? (\n <div ref={dropdownContentRef} className={styles['dropdown-content']}>\n {dropdownContent}\n </div>\n ) : null}\n </Dropdown>\n </div>\n );\n }\n);\n\nexport default AutosuggestInput;\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"lib/default/","sources":["internal/components/autosuggest-input/index.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CAAC,EAAE,CAAC,kBAAkB,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EACjE,SAAS,EAAE,aAAa,EACxB,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,QAAQ,EAClB,yBAAyB,EAAE,yBAAyB,EACpD,QAAQ,EAAE,QAAQ,EAClB,YAAY,EAAE,YAAY,EAC1B,cAAc,EAAE,cAAc,EAC9B,GAAG,EAAE,QAAQ,EACb,YAAY,EAAE,KAAK,EACnB,kBAAkB,EAAE,gBAAgB,IAChC,gBAAgB,EACpB,EAEJ,WAAW,EAAE,uBAAuB,EACpC,IAAI,EAAE,IAAI,IAAI,CAAC,CAAC,eAAe,EAC/B,MAAM,EACJ,iBAAiB,IAAI,CACnB,6BAAK,GAAG,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,CAAC,iBAAiB,CAAC,IAC9D,cAAc,CACX,CACP,EAEH,gBAAgB,EAAE,gBAAgB,EAClC,SAAS,EAAE,SAAS,IAEnB,IAAI,IAAI,eAAe,CAAC,CAAC,CAAC,CACzB,6BAAK,GAAG,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,CAAC,kBAAkB,CAAC,IAChE,eAAe,CACZ,CACP,CAAC,CAAC,CAAC,IAAI,CACC,CACP,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,gBAAgB,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport React, { Ref, useRef, useState, useImperativeHandle, useEffect } from 'react';\n\nimport Dropdown from '../dropdown';\n\nimport { FormFieldValidationControlProps, useFormFieldContext } from '../../context/form-field-context';\nimport { BaseComponentProps, getBaseProps } from '../../base-component';\nimport { BaseKeyDetail, fireCancelableEvent, fireNonCancelableEvent, NonCancelableEventHandler } from '../../events';\nimport InternalInput from '../../../input/internal';\nimport {\n BaseChangeDetail,\n BaseInputProps,\n InputAutoCorrect,\n InputClearLabel,\n InputKeyEvents,\n} from '../../../input/interfaces';\nimport { AutosuggestProps } from '../../../autosuggest/interfaces';\nimport { ExpandToViewport } from '../dropdown/interfaces';\nimport { InternalBaseComponentProps } from '../../hooks/use-base-component';\nimport { KeyCode } from '../../keycode';\nimport styles from './styles.css.js';\nimport clsx from 'clsx';\n\nexport interface AutosuggestInputProps\n extends BaseComponentProps,\n BaseInputProps,\n InputAutoCorrect,\n InputKeyEvents,\n InputClearLabel,\n FormFieldValidationControlProps,\n ExpandToViewport,\n InternalBaseComponentProps {\n ariaControls?: string;\n ariaActivedescendant?: string;\n dropdownExpanded?: boolean;\n dropdownContentKey?: string;\n dropdownContentFocusable?: boolean;\n dropdownContent?: React.ReactNode;\n dropdownFooter?: React.ReactNode;\n dropdownWidth?: number;\n loopFocus?: boolean;\n onCloseDropdown?: NonCancelableEventHandler<null>;\n onDelayedInput?: NonCancelableEventHandler<BaseChangeDetail>;\n onPressArrowDown?: () => void;\n onPressArrowUp?: () => void;\n onPressEnter?: () => boolean;\n}\n\nexport interface AutosuggestInputFocusOptions {\n preventDropdown?: boolean;\n}\n\nexport interface AutosuggestInputRef extends AutosuggestProps.Ref {\n focus(options?: AutosuggestInputFocusOptions): void;\n open(): void;\n close(): void;\n}\n\nconst AutosuggestInput = React.forwardRef(\n (\n {\n value,\n onChange,\n onBlur,\n onFocus,\n onKeyUp,\n onKeyDown,\n name,\n placeholder,\n disabled,\n readOnly,\n autoFocus,\n ariaLabel,\n ariaRequired,\n disableBrowserAutocorrect = false,\n expandToViewport,\n ariaControls,\n ariaActivedescendant,\n clearAriaLabel,\n dropdownExpanded = true,\n dropdownContentKey,\n dropdownContentFocusable = false,\n dropdownContent = null,\n dropdownFooter = null,\n dropdownWidth,\n loopFocus,\n onCloseDropdown,\n onDelayedInput,\n onPressArrowDown,\n onPressArrowUp,\n onPressEnter,\n __internalRootRef,\n ...restProps\n }: AutosuggestInputProps,\n ref: Ref<AutosuggestInputRef>\n ) => {\n const baseProps = getBaseProps(restProps);\n const formFieldContext = useFormFieldContext(restProps);\n\n const inputRef = useRef<HTMLInputElement>(null);\n const dropdownContentRef = useRef<HTMLDivElement>(null);\n const dropdownFooterRef = useRef<HTMLDivElement>(null);\n const preventOpenOnFocusRef = useRef(false);\n const preventCloseOnBlurRef = useRef(false);\n\n const [open, setOpen] = useState(false);\n\n const openDropdown = () => !readOnly && setOpen(true);\n\n const closeDropdown = () => {\n setOpen(false);\n fireNonCancelableEvent(onCloseDropdown, null);\n };\n\n useImperativeHandle(ref, () => ({\n focus(options?: AutosuggestInputFocusOptions) {\n if (options?.preventDropdown) {\n preventOpenOnFocusRef.current = true;\n }\n inputRef.current?.focus();\n },\n select() {\n inputRef.current?.select();\n },\n open: openDropdown,\n close: closeDropdown,\n }));\n\n const handleBlur = () => {\n if (!preventCloseOnBlurRef.current) {\n closeDropdown();\n fireNonCancelableEvent(onBlur, null);\n }\n };\n\n const handleFocus = () => {\n if (!preventOpenOnFocusRef.current) {\n openDropdown();\n fireNonCancelableEvent(onFocus, null);\n }\n preventOpenOnFocusRef.current = false;\n };\n\n const fireKeydown = (event: CustomEvent<BaseKeyDetail>) => fireCancelableEvent(onKeyDown, event.detail, event);\n\n const handleKeyDown = (event: CustomEvent<BaseKeyDetail>) => {\n switch (event.detail.keyCode) {\n case KeyCode.down: {\n onPressArrowDown?.();\n openDropdown();\n event.preventDefault();\n break;\n }\n case KeyCode.up: {\n onPressArrowUp?.();\n openDropdown();\n event.preventDefault();\n break;\n }\n case KeyCode.enter: {\n if (open) {\n if (!onPressEnter?.()) {\n closeDropdown();\n }\n event.preventDefault();\n }\n fireKeydown(event);\n break;\n }\n case KeyCode.escape: {\n if (open) {\n closeDropdown();\n } else if (value) {\n fireNonCancelableEvent(onChange, { value: '' });\n }\n event.preventDefault();\n fireKeydown(event);\n break;\n }\n default: {\n fireKeydown(event);\n }\n }\n };\n\n const handleChange = (value: string) => {\n openDropdown();\n fireNonCancelableEvent(onChange, { value });\n };\n\n const handleDelayedInput = (value: string) => {\n fireNonCancelableEvent(onDelayedInput, { value });\n };\n\n const handleDropdownMouseDown: React.MouseEventHandler = event => {\n // Prevent currently focused element from losing focus.\n if (!dropdownContentFocusable) {\n event.preventDefault();\n }\n // Prevent closing dropdown on click inside.\n else {\n preventCloseOnBlurRef.current = true;\n requestAnimationFrame(() => {\n preventCloseOnBlurRef.current = false;\n });\n }\n };\n\n const expanded = open && dropdownExpanded;\n const nativeAttributes = {\n name,\n placeholder,\n autoFocus,\n onClick: openDropdown,\n role: 'combobox',\n 'aria-autocomplete': 'list',\n 'aria-expanded': expanded,\n 'aria-controls': open ? ariaControls : undefined,\n // 'aria-owns' needed for safari+vo to announce activedescendant content\n 'aria-owns': open ? ariaControls : undefined,\n 'aria-label': ariaLabel,\n 'aria-activedescendant': ariaActivedescendant,\n };\n\n // Closes dropdown when outside click is detected.\n // Similar to the internal dropdown implementation but includes the target as well.\n useEffect(() => {\n if (!open) {\n return;\n }\n\n const clickListener = (event: MouseEvent) => {\n if (\n !inputRef.current?.contains(event.target as Node) &&\n !dropdownContentRef.current?.contains(event.target as Node) &&\n !dropdownFooterRef.current?.contains(event.target as Node)\n ) {\n closeDropdown();\n }\n };\n\n window.addEventListener('mousedown', clickListener);\n\n return () => {\n window.removeEventListener('mousedown', clickListener);\n };\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [open]);\n\n return (\n <div {...baseProps} className={clsx(baseProps.className, styles.root)} ref={__internalRootRef}>\n <Dropdown\n minWidth={dropdownWidth}\n stretchWidth={!dropdownWidth}\n stretchBeyondTriggerWidth={true}\n contentKey={dropdownContentKey}\n onFocus={handleFocus}\n onBlur={handleBlur}\n trigger={\n <InternalInput\n type=\"visualSearch\"\n value={value}\n onChange={event => handleChange(event.detail.value)}\n __onDelayedInput={event => handleDelayedInput(event.detail.value)}\n onKeyDown={handleKeyDown}\n onKeyUp={onKeyUp}\n disabled={disabled}\n disableBrowserAutocorrect={disableBrowserAutocorrect}\n readOnly={readOnly}\n ariaRequired={ariaRequired}\n clearAriaLabel={clearAriaLabel}\n ref={inputRef}\n autoComplete={false}\n __nativeAttributes={nativeAttributes}\n {...formFieldContext}\n />\n }\n onMouseDown={handleDropdownMouseDown}\n open={open && !!dropdownContent}\n footer={\n dropdownFooterRef && (\n <div ref={dropdownFooterRef} className={styles['dropdown-footer']}>\n {dropdownFooter}\n </div>\n )\n }\n expandToViewport={expandToViewport}\n loopFocus={loopFocus}\n >\n {open && dropdownContent ? (\n <div ref={dropdownContentRef} className={styles['dropdown-content']}>\n {dropdownContent}\n </div>\n ) : null}\n </Dropdown>\n </div>\n );\n }\n);\n\nexport default AutosuggestInput;\n"]}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import React, { useEffect, useRef } from 'react';
|
|
4
4
|
import { useMutationObserver } from '../../hooks/use-mutation-observer';
|
|
5
|
-
import { useStableEventHandler } from '../../hooks/use-stable-event-handler';
|
|
6
5
|
import styles from './styles.css.js';
|
|
6
|
+
import { useStableCallback } from '@cloudscape-design/component-toolkit/internal';
|
|
7
7
|
function setIfChanged(oldValue, newValue, setter) {
|
|
8
8
|
if (oldValue !== newValue) {
|
|
9
9
|
setter(newValue);
|
|
@@ -12,7 +12,7 @@ function setIfChanged(oldValue, newValue, setter) {
|
|
|
12
12
|
export default function DarkRibbon({ children, isRefresh, hasPlainStyling }) {
|
|
13
13
|
const containerRef = useRef(null);
|
|
14
14
|
const fillRef = useRef(null);
|
|
15
|
-
const syncSizes =
|
|
15
|
+
const syncSizes = useStableCallback((from, to) => {
|
|
16
16
|
// JSDOM calls mutation observer callback even if attribute did not change
|
|
17
17
|
// https://github.com/jsdom/jsdom/issues/3305
|
|
18
18
|
// To prevent infinite loops, we need to check the values before setting
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"lib/default/","sources":["internal/components/dark-ribbon/index.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;A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8B;QAC9D,6BAAK,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,iBAAiB,CAAC,GAAI;QAC3D,6BAAK,SAAS,EAAE,MAAM,CAAC,OAAO,IAAG,QAAQ,CAAO,CAC5C,CACP,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useEffect, useRef } from 'react';\nimport { useMutationObserver } from '../../hooks/use-mutation-observer';\nimport styles from './styles.css.js';\nimport { useStableCallback } from '@cloudscape-design/component-toolkit/internal';\n\ninterface DarkRibbonProps {\n children: React.ReactNode;\n isRefresh: boolean;\n hasPlainStyling?: boolean;\n}\n\nfunction setIfChanged(oldValue: string, newValue: string, setter: (newValue: string) => void) {\n if (oldValue !== newValue) {\n setter(newValue);\n }\n}\n\nexport default function DarkRibbon({ children, isRefresh, hasPlainStyling }: DarkRibbonProps) {\n const containerRef = useRef<HTMLDivElement>(null);\n const fillRef = useRef<HTMLDivElement>(null);\n const syncSizes = useStableCallback((from: HTMLElement, to: HTMLElement) => {\n // JSDOM calls mutation observer callback even if attribute did not change\n // https://github.com/jsdom/jsdom/issues/3305\n // To prevent infinite loops, we need to check the values before setting\n const size = from.getBoundingClientRect();\n const { height: oldHeight, left: oldLeft, right: oldRight } = to.style;\n setIfChanged(oldHeight, `${size.height}px`, newHeight => (to.style.height = newHeight));\n setIfChanged(oldLeft, `${-1 * size.left}px`, newLeft => (to.style.left = newLeft));\n setIfChanged(\n oldRight,\n `${-1 * (document.body.clientWidth - size.right)}px`,\n newRight => (to.style.right = newRight)\n );\n });\n useMutationObserver(containerRef, node => {\n if (fillRef.current) {\n syncSizes(node, fillRef.current);\n }\n });\n useEffect(() => {\n const handler = () => {\n if (containerRef.current && fillRef.current) {\n syncSizes(containerRef.current, fillRef.current);\n }\n };\n window.addEventListener('resize', handler);\n return () => window.removeEventListener('resize', handler);\n }, [syncSizes]);\n\n if (hasPlainStyling === true || !isRefresh) {\n return <>{children}</>;\n }\n\n return (\n <div ref={containerRef} className=\"awsui-context-content-header\">\n <div ref={fillRef} className={styles['background-fill']} />\n <div className={styles.content}>{children}</div>\n </div>\n );\n}\n"]}
|
|
@@ -16,10 +16,21 @@ export interface InteriorDropdownPosition extends DropdownPosition {
|
|
|
16
16
|
bottom: string;
|
|
17
17
|
top: string;
|
|
18
18
|
}
|
|
19
|
+
export declare const defaultMaxDropdownWidth: number;
|
|
19
20
|
export declare const getAvailableSpace: (trigger: HTMLElement, dropdown: HTMLElement, overflowParents: ReadonlyArray<Dimensions>, stretchWidth?: boolean, stretchHeight?: boolean, isMobile?: boolean) => AvailableSpace;
|
|
20
21
|
export declare const getInteriorAvailableSpace: (trigger: HTMLElement, dropdown: HTMLElement, overflowParents: ReadonlyArray<Dimensions>, isMobile?: boolean) => AvailableSpace;
|
|
21
|
-
export declare const getDropdownPosition: (
|
|
22
|
+
export declare const getDropdownPosition: ({ triggerElement, dropdownElement, overflowParents, minWidth: desiredMinWidth, preferCenter, stretchWidth, stretchHeight, isMobile, stretchBeyondTriggerWidth, }: {
|
|
23
|
+
triggerElement: HTMLElement;
|
|
24
|
+
dropdownElement: HTMLElement;
|
|
25
|
+
overflowParents: ReadonlyArray<Dimensions>;
|
|
26
|
+
minWidth?: number | undefined;
|
|
27
|
+
preferCenter?: boolean | undefined;
|
|
28
|
+
stretchWidth?: boolean | undefined;
|
|
29
|
+
stretchHeight?: boolean | undefined;
|
|
30
|
+
isMobile?: boolean | undefined;
|
|
31
|
+
stretchBeyondTriggerWidth?: boolean | undefined;
|
|
32
|
+
}) => DropdownPosition;
|
|
22
33
|
export declare const getInteriorDropdownPosition: (trigger: HTMLElement, dropdown: HTMLElement, overflowParents: ReadonlyArray<Dimensions>, isMobile?: boolean) => InteriorDropdownPosition;
|
|
23
|
-
export declare const calculatePosition: (dropdownElement: HTMLDivElement, triggerElement: HTMLDivElement, verticalContainerElement: HTMLDivElement, interior: boolean, expandToViewport: boolean, preferCenter: boolean, stretchWidth: boolean, stretchHeight: boolean, isMobile: boolean, minWidth?: number) => [DropdownPosition, DOMRect];
|
|
34
|
+
export declare const calculatePosition: (dropdownElement: HTMLDivElement, triggerElement: HTMLDivElement, verticalContainerElement: HTMLDivElement, interior: boolean, expandToViewport: boolean, preferCenter: boolean, stretchWidth: boolean, stretchHeight: boolean, isMobile: boolean, minWidth?: number, stretchBeyondTriggerWidth?: boolean) => [DropdownPosition, DOMRect];
|
|
24
35
|
export {};
|
|
25
36
|
//# sourceMappingURL=dropdown-fit-handler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dropdown-fit-handler.d.ts","sourceRoot":"lib/default/","sources":["internal/components/dropdown/dropdown-fit-handler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dropdown-fit-handler.d.ts","sourceRoot":"lib/default/","sources":["internal/components/dropdown/dropdown-fit-handler.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAmD,MAAM,mCAAmC,CAAC;AAOhH,UAAU,cAAc;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AACD,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CACd;AACD,MAAM,WAAW,wBAAyB,SAAQ,gBAAgB;IAChE,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;CACb;AAkBD,eAAO,MAAM,uBAAuB,QAA4B,CAAC;AAEjE,eAAO,MAAM,iBAAiB,YACnB,WAAW,YACV,WAAW,mBACJ,cAAc,UAAU,CAAC,8DAG/B,OAAO,KACjB,cA8BF,CAAC;AAEF,eAAO,MAAM,yBAAyB,YAC3B,WAAW,YACV,WAAW,mBACJ,cAAc,UAAU,CAAC,aAC/B,OAAO,KACjB,cA+BF,CAAC;AAEF,eAAO,MAAM,mBAAmB;oBAWd,WAAW;qBACV,WAAW;qBACX,cAAc,UAAU,CAAC;;;;;;;MAOxC,gBA8DH,CAAC;AAEF,eAAO,MAAM,2BAA2B,YAC7B,WAAW,YACV,WAAW,mBACJ,cAAc,UAAU,CAAC,aAC/B,OAAO,KACjB,wBAmCF,CAAC;AAEF,eAAO,MAAM,iBAAiB,oBACX,cAAc,kBACf,cAAc,4BACJ,cAAc,YAC9B,OAAO,oBACC,OAAO,gBACX,OAAO,gBACP,OAAO,iBACN,OAAO,YACZ,OAAO,aACN,MAAM,8BACW,OAAO,KAClC,CAAC,gBAAgB,EAAE,OAAO,CA6B5B,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { getBreakpointValue } from '../../breakpoints';
|
|
3
4
|
import { getOverflowParents, getOverflowParentDimensions } from '../../utils/scrollable-containers';
|
|
4
5
|
import styles from './styles.css.js';
|
|
5
6
|
const AVAILABLE_SPACE_RESERVE_DEFAULT = 50;
|
|
@@ -17,6 +18,9 @@ const getClosestParentDimensions = (element) => {
|
|
|
17
18
|
});
|
|
18
19
|
return parents.shift();
|
|
19
20
|
};
|
|
21
|
+
// By default, most dropdowns should expand their content as necessary, but to a maximum of 465px (the XXS breakpoint).
|
|
22
|
+
// This value was determined by UX but may be subject to change in the future, depending on the feedback.
|
|
23
|
+
export const defaultMaxDropdownWidth = getBreakpointValue('xxs');
|
|
20
24
|
export const getAvailableSpace = (trigger, dropdown, overflowParents, stretchWidth = false, stretchHeight = false, isMobile) => {
|
|
21
25
|
const availableSpaceReserveVertical = stretchHeight
|
|
22
26
|
? 0
|
|
@@ -64,13 +68,19 @@ export const getInteriorAvailableSpace = (trigger, dropdown, overflowParents, is
|
|
|
64
68
|
};
|
|
65
69
|
}, { above: Number.MAX_VALUE, below: Number.MAX_VALUE, left: Number.MAX_VALUE, right: Number.MAX_VALUE });
|
|
66
70
|
};
|
|
67
|
-
export const getDropdownPosition = (
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
//
|
|
73
|
-
const
|
|
71
|
+
export const getDropdownPosition = ({ triggerElement, dropdownElement, overflowParents, minWidth: desiredMinWidth, preferCenter = false, stretchWidth = false, stretchHeight = false, isMobile = false, stretchBeyondTriggerWidth = false, }) => {
|
|
72
|
+
// Determine the space available around the dropdown that it can grow in
|
|
73
|
+
const availableSpace = getAvailableSpace(triggerElement, dropdownElement, overflowParents, stretchWidth, stretchHeight, isMobile);
|
|
74
|
+
// Determine the width of the trigger
|
|
75
|
+
const triggerWidth = triggerElement.getBoundingClientRect().width;
|
|
76
|
+
// Minimum width is determined by either an explicit number (desiredMinWidth) or the trigger width
|
|
77
|
+
const minWidth = desiredMinWidth ? Math.min(triggerWidth, desiredMinWidth) : triggerWidth;
|
|
78
|
+
// If stretchBeyondTriggerWidth is true, the maximum width is the XS breakpoint (465px) or the trigger width (if bigger).
|
|
79
|
+
const maxWidth = stretchBeyondTriggerWidth ? Math.max(defaultMaxDropdownWidth, triggerWidth) : Number.MAX_VALUE;
|
|
80
|
+
// Determine the actual dropdown width, the size that it "wants" to be
|
|
81
|
+
const requiredWidth = dropdownElement.getBoundingClientRect().width;
|
|
82
|
+
// Try to achieve the required/desired width within the given parameters
|
|
83
|
+
const idealWidth = Math.min(Math.max(requiredWidth, minWidth), maxWidth);
|
|
74
84
|
let dropLeft;
|
|
75
85
|
let left = null;
|
|
76
86
|
let width = idealWidth;
|
|
@@ -97,7 +107,7 @@ export const getDropdownPosition = (trigger, dropdown, overflowParents, minWidth
|
|
|
97
107
|
left = -spillOver;
|
|
98
108
|
}
|
|
99
109
|
}
|
|
100
|
-
const dropUp = availableSpace.below <
|
|
110
|
+
const dropUp = availableSpace.below < dropdownElement.offsetHeight && availableSpace.above > availableSpace.below;
|
|
101
111
|
const availableHeight = dropUp ? availableSpace.above : availableSpace.below;
|
|
102
112
|
// Try and crop the bottom item when all options can't be displayed, affordance for "there's more"
|
|
103
113
|
const croppedHeight = stretchHeight ? availableHeight : Math.floor(availableHeight / 31) * 31 + 16;
|
|
@@ -142,7 +152,7 @@ export const getInteriorDropdownPosition = (trigger, dropdown, overflowParents,
|
|
|
142
152
|
left: `${left}px`,
|
|
143
153
|
};
|
|
144
154
|
};
|
|
145
|
-
export const calculatePosition = (dropdownElement, triggerElement, verticalContainerElement, interior, expandToViewport, preferCenter, stretchWidth, stretchHeight, isMobile, minWidth) => {
|
|
155
|
+
export const calculatePosition = (dropdownElement, triggerElement, verticalContainerElement, interior, expandToViewport, preferCenter, stretchWidth, stretchHeight, isMobile, minWidth, stretchBeyondTriggerWidth) => {
|
|
146
156
|
// cleaning previously assigned values,
|
|
147
157
|
// so that they are not reused in case of screen resize and similar events
|
|
148
158
|
verticalContainerElement.style.maxHeight = '';
|
|
@@ -156,7 +166,17 @@ export const calculatePosition = (dropdownElement, triggerElement, verticalConta
|
|
|
156
166
|
const overflowParents = getOverflowParentDimensions(dropdownElement, interior, expandToViewport, stretchHeight);
|
|
157
167
|
const position = interior
|
|
158
168
|
? getInteriorDropdownPosition(triggerElement, dropdownElement, overflowParents, isMobile)
|
|
159
|
-
: getDropdownPosition(
|
|
169
|
+
: getDropdownPosition({
|
|
170
|
+
triggerElement,
|
|
171
|
+
dropdownElement,
|
|
172
|
+
overflowParents,
|
|
173
|
+
minWidth,
|
|
174
|
+
preferCenter,
|
|
175
|
+
stretchWidth,
|
|
176
|
+
stretchHeight,
|
|
177
|
+
isMobile,
|
|
178
|
+
stretchBeyondTriggerWidth,
|
|
179
|
+
});
|
|
160
180
|
const triggerBox = triggerElement.getBoundingClientRect();
|
|
161
181
|
return [position, triggerBox];
|
|
162
182
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dropdown-fit-handler.js","sourceRoot":"lib/default/","sources":["internal/components/dropdown/dropdown-fit-handler.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,EAAc,kBAAkB,EAAE,2BAA2B,EAAE,MAAM,mCAAmC,CAAC;AAChH,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAErC,MAAM,+BAA+B,GAAG,EAAE,CAAC;AAC3C,MAAM,uCAAuC,GAAG,EAAE,CAAC,CAAC,UAAU;AAC9D,MAAM,yCAAyC,GAAG,EAAE,CAAC;AAoBrD,MAAM,0BAA0B,GAAG,CAAC,OAAoB,EAAO,EAAE;IAC/D,MAAM,OAAO,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;QACnD,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,qBAAqB,EAAE,CAAC;QAChE,OAAO;YACL,MAAM;YACN,KAAK;YACL,GAAG;YACH,IAAI;SACL,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,KAAK,EAAE,CAAC;AACzB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,OAAoB,EACpB,QAAqB,EACrB,eAA0C,EAC1C,YAAY,GAAG,KAAK,EACpB,aAAa,GAAG,KAAK,EACrB,QAAkB,EACF,EAAE;IAClB,MAAM,6BAA6B,GAAG,aAAa;QACjD,CAAC,CAAC,CAAC;QACH,CAAC,CAAC,QAAQ;YACV,CAAC,CAAC,uCAAuC;YACzC,CAAC,CAAC,+BAA+B,CAAC;IACpC,MAAM,+BAA+B,GAAG,YAAY;QAClD,CAAC,CAAC,CAAC;QACH,CAAC,CAAC,QAAQ;YACV,CAAC,CAAC,yCAAyC;YAC3C,CAAC,CAAC,+BAA+B,CAAC;IACpC,MAAM,EA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C,CAAC,mBAAmB,CACjB,cAAc,EACd,eAAe,EACf,eAAe,EACf,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,QAAQ,CACT,CAAC;IACN,MAAM,UAAU,GAAG,cAAc,CAAC,qBAAqB,EAAE,CAAC;IAC1D,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;AAChC,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Dimensions, getOverflowParents, getOverflowParentDimensions } from '../../utils/scrollable-containers';\nimport styles from './styles.css.js';\n\nconst AVAILABLE_SPACE_RESERVE_DEFAULT = 50;\nconst AVAILABLE_SPACE_RESERVE_MOBILE_VERTICAL = 19; // 50 - 31\nconst AVAILABLE_SPACE_RESERVE_MOBILE_HORIZONTAL = 20;\n\ninterface AvailableSpace {\n above: number;\n below: number;\n left: number;\n right: number;\n}\nexport interface DropdownPosition {\n height: string;\n width: string;\n dropUp: boolean;\n dropLeft: boolean;\n left: string;\n}\nexport interface InteriorDropdownPosition extends DropdownPosition {\n bottom: string;\n top: string;\n}\n\nconst getClosestParentDimensions = (element: HTMLElement): any => {\n const parents = getOverflowParents(element).map(el => {\n const { height, width, top, left } = el.getBoundingClientRect();\n return {\n height,\n width,\n top,\n left,\n };\n });\n\n return parents.shift();\n};\n\nexport const getAvailableSpace = (\n trigger: HTMLElement,\n dropdown: HTMLElement,\n overflowParents: ReadonlyArray<Dimensions>,\n stretchWidth = false,\n stretchHeight = false,\n isMobile?: boolean\n): AvailableSpace => {\n const availableSpaceReserveVertical = stretchHeight\n ? 0\n : isMobile\n ? AVAILABLE_SPACE_RESERVE_MOBILE_VERTICAL\n : AVAILABLE_SPACE_RESERVE_DEFAULT;\n const availableSpaceReserveHorizontal = stretchWidth\n ? 0\n : isMobile\n ? AVAILABLE_SPACE_RESERVE_MOBILE_HORIZONTAL\n : AVAILABLE_SPACE_RESERVE_DEFAULT;\n const { bottom: triggerBottom, left: triggerLeft, right: triggerRight } = trigger.getBoundingClientRect();\n\n return overflowParents.reduce(\n ({ above, below, left, right }, overflowParent) => {\n const offsetTop = triggerBottom - overflowParent.top;\n const currentAbove = offsetTop - trigger.offsetHeight - availableSpaceReserveVertical;\n const currentBelow = overflowParent.height - offsetTop - availableSpaceReserveVertical;\n const currentLeft = triggerRight - overflowParent.left - availableSpaceReserveHorizontal;\n const currentRight = overflowParent.left + overflowParent.width - triggerLeft - availableSpaceReserveHorizontal;\n\n return {\n above: Math.min(above, currentAbove),\n below: Math.min(below, currentBelow),\n left: Math.min(left, currentLeft),\n right: Math.min(right, currentRight),\n };\n },\n { above: Number.MAX_VALUE, below: Number.MAX_VALUE, left: Number.MAX_VALUE, right: Number.MAX_VALUE }\n );\n};\n\nexport const getInteriorAvailableSpace = (\n trigger: HTMLElement,\n dropdown: HTMLElement,\n overflowParents: ReadonlyArray<Dimensions>,\n isMobile?: boolean\n): AvailableSpace => {\n const AVAILABLE_SPACE_RESERVE_VERTICAL = isMobile\n ? AVAILABLE_SPACE_RESERVE_MOBILE_VERTICAL\n : AVAILABLE_SPACE_RESERVE_DEFAULT;\n const AVAILABLE_SPACE_RESERVE_HORIZONTAL = isMobile\n ? AVAILABLE_SPACE_RESERVE_MOBILE_HORIZONTAL\n : AVAILABLE_SPACE_RESERVE_DEFAULT;\n const {\n bottom: triggerBottom,\n top: triggerTop,\n left: triggerLeft,\n right: triggerRight,\n } = trigger.getBoundingClientRect();\n\n return overflowParents.reduce(\n ({ above, below, left, right }, overflowParent) => {\n const currentAbove = triggerBottom - overflowParent.top - AVAILABLE_SPACE_RESERVE_VERTICAL;\n const currentBelow = overflowParent.height - triggerTop + overflowParent.top - AVAILABLE_SPACE_RESERVE_VERTICAL;\n const currentLeft = triggerLeft - overflowParent.left - AVAILABLE_SPACE_RESERVE_HORIZONTAL;\n const currentRight =\n overflowParent.left + overflowParent.width - triggerRight - AVAILABLE_SPACE_RESERVE_HORIZONTAL;\n\n return {\n above: Math.min(above, currentAbove),\n below: Math.min(below, currentBelow),\n left: Math.min(left, currentLeft),\n right: Math.min(right, currentRight),\n };\n },\n { above: Number.MAX_VALUE, below: Number.MAX_VALUE, left: Number.MAX_VALUE, right: Number.MAX_VALUE }\n );\n};\n\nexport const getDropdownPosition = (\n trigger: HTMLElement,\n dropdown: HTMLElement,\n overflowParents: ReadonlyArray<Dimensions>,\n minWidth?: number,\n preferCenter = false,\n stretchWidth = false,\n stretchHeight = false,\n isMobile?: boolean\n): DropdownPosition => {\n const availableSpace = getAvailableSpace(trigger, dropdown, overflowParents, stretchWidth, stretchHeight, isMobile);\n const triggerWidth = trigger.getBoundingClientRect().width;\n minWidth = minWidth ? Math.min(triggerWidth, minWidth) : triggerWidth;\n const requiredWidth = dropdown.getBoundingClientRect().width;\n // dropdown should not be smaller than the trigger\n const idealWidth = Math.max(requiredWidth, minWidth);\n\n let dropLeft: boolean;\n let left: number | null = null;\n let width = idealWidth;\n\n //1. Can it be positioned with ideal width to the right?\n if (idealWidth <= availableSpace.right) {\n dropLeft = false;\n //2. Can it be positioned with ideal width to the left?\n } else if (idealWidth <= availableSpace.left) {\n dropLeft = true;\n //3. Fit into biggest available space either on left or right\n } else {\n dropLeft = availableSpace.left > availableSpace.right;\n width = Math.max(availableSpace.left, availableSpace.right, minWidth);\n }\n\n if (preferCenter) {\n const spillOver = (idealWidth - triggerWidth) / 2;\n\n // availableSpace always includes the trigger width, but we want to exclude that\n const availableOutsideLeft = availableSpace.left - triggerWidth;\n const availableOutsideRight = availableSpace.right - triggerWidth;\n\n const fitsInCenter = availableOutsideLeft >= spillOver && availableOutsideRight >= spillOver;\n if (fitsInCenter) {\n left = -spillOver;\n }\n }\n\n const dropUp = availableSpace.below < dropdown.offsetHeight && availableSpace.above > availableSpace.below;\n const availableHeight = dropUp ? availableSpace.above : availableSpace.below;\n // Try and crop the bottom item when all options can't be displayed, affordance for \"there's more\"\n const croppedHeight = stretchHeight ? availableHeight : Math.floor(availableHeight / 31) * 31 + 16;\n\n return {\n dropUp,\n dropLeft,\n left: left === null ? 'auto' : `${left}px`,\n height: `${croppedHeight}px`,\n width: `${width}px`,\n };\n};\n\nexport const getInteriorDropdownPosition = (\n trigger: HTMLElement,\n dropdown: HTMLElement,\n overflowParents: ReadonlyArray<Dimensions>,\n isMobile?: boolean\n): InteriorDropdownPosition => {\n const availableSpace = getInteriorAvailableSpace(trigger, dropdown, overflowParents, isMobile);\n const { bottom: triggerBottom, top: triggerTop, width: triggerWidth } = trigger.getBoundingClientRect();\n const { top: parentDropdownTop, height: parentDropdownHeight } = getClosestParentDimensions(trigger);\n\n let dropLeft;\n\n let width = dropdown.getBoundingClientRect().width;\n const top = triggerTop - parentDropdownTop;\n if (width <= availableSpace.right) {\n dropLeft = false;\n } else if (width <= availableSpace.left) {\n dropLeft = true;\n } else {\n dropLeft = availableSpace.left > availableSpace.right;\n width = Math.max(availableSpace.left, availableSpace.right);\n }\n\n const left = dropLeft ? 0 - width : triggerWidth;\n\n const dropUp = availableSpace.below < dropdown.offsetHeight && availableSpace.above > availableSpace.below;\n const bottom = dropUp ? parentDropdownTop + parentDropdownHeight - triggerBottom : 0;\n const availableHeight = dropUp ? availableSpace.above : availableSpace.below;\n // Try and crop the bottom item when all options can't be displayed, affordance for \"there's more\"\n const croppedHeight = Math.floor(availableHeight / 31) * 31 + 16;\n\n return {\n dropUp,\n dropLeft,\n height: `${croppedHeight}px`,\n width: `${width}px`,\n top: `${top}px`,\n bottom: `${bottom}px`,\n left: `${left}px`,\n };\n};\n\nexport const calculatePosition = (\n dropdownElement: HTMLDivElement,\n triggerElement: HTMLDivElement,\n verticalContainerElement: HTMLDivElement,\n interior: boolean,\n expandToViewport: boolean,\n preferCenter: boolean,\n stretchWidth: boolean,\n stretchHeight: boolean,\n isMobile: boolean,\n minWidth?: number\n): [DropdownPosition, DOMRect] => {\n // cleaning previously assigned values,\n // so that they are not reused in case of screen resize and similar events\n verticalContainerElement.style.maxHeight = '';\n dropdownElement.style.width = '';\n dropdownElement.style.top = '';\n dropdownElement.style.bottom = '';\n dropdownElement.style.left = '';\n\n dropdownElement.classList.remove(styles['dropdown-drop-left']);\n dropdownElement.classList.remove(styles['dropdown-drop-right']);\n dropdownElement.classList.remove(styles['dropdown-drop-up']);\n\n const overflowParents = getOverflowParentDimensions(dropdownElement, interior, expandToViewport, stretchHeight);\n const position = interior\n ? getInteriorDropdownPosition(triggerElement, dropdownElement, overflowParents, isMobile)\n : getDropdownPosition(\n triggerElement,\n dropdownElement,\n overflowParents,\n minWidth,\n preferCenter,\n stretchWidth,\n stretchHeight,\n isMobile\n );\n const triggerBox = triggerElement.getBoundingClientRect();\n return [position, triggerBox];\n};\n"]}
|
|
1
|
+
{"version":3,"file":"dropdown-fit-handler.js","sourceRoot":"lib/default/","sources":["internal/components/dropdown/dropdown-fit-handler.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAc,kBAAkB,EAAE,2BAA2B,EAAE,MAAM,mCAAmC,CAAC;AAChH,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAErC,MAAM,+BAA+B,GAAG,EAAE,CAAC;AAC3C,MAAM,uCAAuC,GAAG,EAAE,CAAC,CAAC,UAAU;AAC9D,MAAM,yCAAyC,GAAG,EAAE,CAAC;AAoBrD,MAAM,0BAA0B,GAAG,CAAC,OAAoB,EAAO,EAAE;IAC/D,MAAM,OAAO,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;QACnD,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,qBAAqB,EAAE,CAAC;QAChE,OAAO;YACL,MAAM;YACN,KAAK;YACL,GAAG;YACH,IAAI;SACL,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,KAAK,E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identifier: Apache-2.0\nimport { getBreakpointValue } from '../../breakpoints';\nimport { Dimensions, getOverflowParents, getOverflowParentDimensions } from '../../utils/scrollable-containers';\nimport styles from './styles.css.js';\n\nconst AVAILABLE_SPACE_RESERVE_DEFAULT = 50;\nconst AVAILABLE_SPACE_RESERVE_MOBILE_VERTICAL = 19; // 50 - 31\nconst AVAILABLE_SPACE_RESERVE_MOBILE_HORIZONTAL = 20;\n\ninterface AvailableSpace {\n above: number;\n below: number;\n left: number;\n right: number;\n}\nexport interface DropdownPosition {\n height: string;\n width: string;\n dropUp: boolean;\n dropLeft: boolean;\n left: string;\n}\nexport interface InteriorDropdownPosition extends DropdownPosition {\n bottom: string;\n top: string;\n}\n\nconst getClosestParentDimensions = (element: HTMLElement): any => {\n const parents = getOverflowParents(element).map(el => {\n const { height, width, top, left } = el.getBoundingClientRect();\n return {\n height,\n width,\n top,\n left,\n };\n });\n\n return parents.shift();\n};\n\n// By default, most dropdowns should expand their content as necessary, but to a maximum of 465px (the XXS breakpoint).\n// This value was determined by UX but may be subject to change in the future, depending on the feedback.\nexport const defaultMaxDropdownWidth = getBreakpointValue('xxs');\n\nexport const getAvailableSpace = (\n trigger: HTMLElement,\n dropdown: HTMLElement,\n overflowParents: ReadonlyArray<Dimensions>,\n stretchWidth = false,\n stretchHeight = false,\n isMobile?: boolean\n): AvailableSpace => {\n const availableSpaceReserveVertical = stretchHeight\n ? 0\n : isMobile\n ? AVAILABLE_SPACE_RESERVE_MOBILE_VERTICAL\n : AVAILABLE_SPACE_RESERVE_DEFAULT;\n const availableSpaceReserveHorizontal = stretchWidth\n ? 0\n : isMobile\n ? AVAILABLE_SPACE_RESERVE_MOBILE_HORIZONTAL\n : AVAILABLE_SPACE_RESERVE_DEFAULT;\n const { bottom: triggerBottom, left: triggerLeft, right: triggerRight } = trigger.getBoundingClientRect();\n\n return overflowParents.reduce(\n ({ above, below, left, right }, overflowParent) => {\n const offsetTop = triggerBottom - overflowParent.top;\n const currentAbove = offsetTop - trigger.offsetHeight - availableSpaceReserveVertical;\n const currentBelow = overflowParent.height - offsetTop - availableSpaceReserveVertical;\n const currentLeft = triggerRight - overflowParent.left - availableSpaceReserveHorizontal;\n const currentRight = overflowParent.left + overflowParent.width - triggerLeft - availableSpaceReserveHorizontal;\n\n return {\n above: Math.min(above, currentAbove),\n below: Math.min(below, currentBelow),\n left: Math.min(left, currentLeft),\n right: Math.min(right, currentRight),\n };\n },\n { above: Number.MAX_VALUE, below: Number.MAX_VALUE, left: Number.MAX_VALUE, right: Number.MAX_VALUE }\n );\n};\n\nexport const getInteriorAvailableSpace = (\n trigger: HTMLElement,\n dropdown: HTMLElement,\n overflowParents: ReadonlyArray<Dimensions>,\n isMobile?: boolean\n): AvailableSpace => {\n const AVAILABLE_SPACE_RESERVE_VERTICAL = isMobile\n ? AVAILABLE_SPACE_RESERVE_MOBILE_VERTICAL\n : AVAILABLE_SPACE_RESERVE_DEFAULT;\n const AVAILABLE_SPACE_RESERVE_HORIZONTAL = isMobile\n ? AVAILABLE_SPACE_RESERVE_MOBILE_HORIZONTAL\n : AVAILABLE_SPACE_RESERVE_DEFAULT;\n const {\n bottom: triggerBottom,\n top: triggerTop,\n left: triggerLeft,\n right: triggerRight,\n } = trigger.getBoundingClientRect();\n\n return overflowParents.reduce(\n ({ above, below, left, right }, overflowParent) => {\n const currentAbove = triggerBottom - overflowParent.top - AVAILABLE_SPACE_RESERVE_VERTICAL;\n const currentBelow = overflowParent.height - triggerTop + overflowParent.top - AVAILABLE_SPACE_RESERVE_VERTICAL;\n const currentLeft = triggerLeft - overflowParent.left - AVAILABLE_SPACE_RESERVE_HORIZONTAL;\n const currentRight =\n overflowParent.left + overflowParent.width - triggerRight - AVAILABLE_SPACE_RESERVE_HORIZONTAL;\n\n return {\n above: Math.min(above, currentAbove),\n below: Math.min(below, currentBelow),\n left: Math.min(left, currentLeft),\n right: Math.min(right, currentRight),\n };\n },\n { above: Number.MAX_VALUE, below: Number.MAX_VALUE, left: Number.MAX_VALUE, right: Number.MAX_VALUE }\n );\n};\n\nexport const getDropdownPosition = ({\n triggerElement,\n dropdownElement,\n overflowParents,\n minWidth: desiredMinWidth,\n preferCenter = false,\n stretchWidth = false,\n stretchHeight = false,\n isMobile = false,\n stretchBeyondTriggerWidth = false,\n}: {\n triggerElement: HTMLElement;\n dropdownElement: HTMLElement;\n overflowParents: ReadonlyArray<Dimensions>;\n minWidth?: number;\n preferCenter?: boolean;\n stretchWidth?: boolean;\n stretchHeight?: boolean;\n isMobile?: boolean;\n stretchBeyondTriggerWidth?: boolean;\n}): DropdownPosition => {\n // Determine the space available around the dropdown that it can grow in\n const availableSpace = getAvailableSpace(\n triggerElement,\n dropdownElement,\n overflowParents,\n stretchWidth,\n stretchHeight,\n isMobile\n );\n // Determine the width of the trigger\n const triggerWidth = triggerElement.getBoundingClientRect().width;\n // Minimum width is determined by either an explicit number (desiredMinWidth) or the trigger width\n const minWidth = desiredMinWidth ? Math.min(triggerWidth, desiredMinWidth) : triggerWidth;\n // If stretchBeyondTriggerWidth is true, the maximum width is the XS breakpoint (465px) or the trigger width (if bigger).\n const maxWidth = stretchBeyondTriggerWidth ? Math.max(defaultMaxDropdownWidth, triggerWidth) : Number.MAX_VALUE;\n // Determine the actual dropdown width, the size that it \"wants\" to be\n const requiredWidth = dropdownElement.getBoundingClientRect().width;\n // Try to achieve the required/desired width within the given parameters\n const idealWidth = Math.min(Math.max(requiredWidth, minWidth), maxWidth);\n\n let dropLeft: boolean;\n let left: number | null = null;\n let width = idealWidth;\n\n //1. Can it be positioned with ideal width to the right?\n if (idealWidth <= availableSpace.right) {\n dropLeft = false;\n //2. Can it be positioned with ideal width to the left?\n } else if (idealWidth <= availableSpace.left) {\n dropLeft = true;\n //3. Fit into biggest available space either on left or right\n } else {\n dropLeft = availableSpace.left > availableSpace.right;\n width = Math.max(availableSpace.left, availableSpace.right, minWidth);\n }\n\n if (preferCenter) {\n const spillOver = (idealWidth - triggerWidth) / 2;\n\n // availableSpace always includes the trigger width, but we want to exclude that\n const availableOutsideLeft = availableSpace.left - triggerWidth;\n const availableOutsideRight = availableSpace.right - triggerWidth;\n\n const fitsInCenter = availableOutsideLeft >= spillOver && availableOutsideRight >= spillOver;\n if (fitsInCenter) {\n left = -spillOver;\n }\n }\n\n const dropUp = availableSpace.below < dropdownElement.offsetHeight && availableSpace.above > availableSpace.below;\n const availableHeight = dropUp ? availableSpace.above : availableSpace.below;\n // Try and crop the bottom item when all options can't be displayed, affordance for \"there's more\"\n const croppedHeight = stretchHeight ? availableHeight : Math.floor(availableHeight / 31) * 31 + 16;\n\n return {\n dropUp,\n dropLeft,\n left: left === null ? 'auto' : `${left}px`,\n height: `${croppedHeight}px`,\n width: `${width}px`,\n };\n};\n\nexport const getInteriorDropdownPosition = (\n trigger: HTMLElement,\n dropdown: HTMLElement,\n overflowParents: ReadonlyArray<Dimensions>,\n isMobile?: boolean\n): InteriorDropdownPosition => {\n const availableSpace = getInteriorAvailableSpace(trigger, dropdown, overflowParents, isMobile);\n const { bottom: triggerBottom, top: triggerTop, width: triggerWidth } = trigger.getBoundingClientRect();\n const { top: parentDropdownTop, height: parentDropdownHeight } = getClosestParentDimensions(trigger);\n\n let dropLeft;\n\n let width = dropdown.getBoundingClientRect().width;\n const top = triggerTop - parentDropdownTop;\n if (width <= availableSpace.right) {\n dropLeft = false;\n } else if (width <= availableSpace.left) {\n dropLeft = true;\n } else {\n dropLeft = availableSpace.left > availableSpace.right;\n width = Math.max(availableSpace.left, availableSpace.right);\n }\n\n const left = dropLeft ? 0 - width : triggerWidth;\n\n const dropUp = availableSpace.below < dropdown.offsetHeight && availableSpace.above > availableSpace.below;\n const bottom = dropUp ? parentDropdownTop + parentDropdownHeight - triggerBottom : 0;\n const availableHeight = dropUp ? availableSpace.above : availableSpace.below;\n // Try and crop the bottom item when all options can't be displayed, affordance for \"there's more\"\n const croppedHeight = Math.floor(availableHeight / 31) * 31 + 16;\n\n return {\n dropUp,\n dropLeft,\n height: `${croppedHeight}px`,\n width: `${width}px`,\n top: `${top}px`,\n bottom: `${bottom}px`,\n left: `${left}px`,\n };\n};\n\nexport const calculatePosition = (\n dropdownElement: HTMLDivElement,\n triggerElement: HTMLDivElement,\n verticalContainerElement: HTMLDivElement,\n interior: boolean,\n expandToViewport: boolean,\n preferCenter: boolean,\n stretchWidth: boolean,\n stretchHeight: boolean,\n isMobile: boolean,\n minWidth?: number,\n stretchBeyondTriggerWidth?: boolean\n): [DropdownPosition, DOMRect] => {\n // cleaning previously assigned values,\n // so that they are not reused in case of screen resize and similar events\n verticalContainerElement.style.maxHeight = '';\n dropdownElement.style.width = '';\n dropdownElement.style.top = '';\n dropdownElement.style.bottom = '';\n dropdownElement.style.left = '';\n\n dropdownElement.classList.remove(styles['dropdown-drop-left']);\n dropdownElement.classList.remove(styles['dropdown-drop-right']);\n dropdownElement.classList.remove(styles['dropdown-drop-up']);\n\n const overflowParents = getOverflowParentDimensions(dropdownElement, interior, expandToViewport, stretchHeight);\n const position = interior\n ? getInteriorDropdownPosition(triggerElement, dropdownElement, overflowParents, isMobile)\n : getDropdownPosition({\n triggerElement,\n dropdownElement,\n overflowParents,\n minWidth,\n preferCenter,\n stretchWidth,\n stretchHeight,\n isMobile,\n stretchBeyondTriggerWidth,\n });\n const triggerBox = triggerElement.getBoundingClientRect();\n return [position, triggerBox];\n};\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { DropdownProps } from './interfaces';
|
|
3
|
-
declare const Dropdown: ({ children, trigger, open, onDropdownClose, onMouseDown, header, footer, dropdownId, stretchTriggerHeight, stretchWidth, stretchHeight, stretchToTriggerWidth, expandToViewport, preferCenter, interior, minWidth, scrollable, loopFocus, onFocus, onBlur, contentKey, dropdownContentId, dropdownContentRole, ariaLabelledby, ariaDescribedby, }: DropdownProps) => JSX.Element;
|
|
3
|
+
declare const Dropdown: ({ children, trigger, open, onDropdownClose, onMouseDown, header, footer, dropdownId, stretchTriggerHeight, stretchWidth, stretchHeight, stretchToTriggerWidth, stretchBeyondTriggerWidth, expandToViewport, preferCenter, interior, minWidth, scrollable, loopFocus, onFocus, onBlur, contentKey, dropdownContentId, dropdownContentRole, ariaLabelledby, ariaDescribedby, }: DropdownProps) => JSX.Element;
|
|
4
4
|
export default Dropdown;
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"lib/default/","sources":["internal/components/dropdown/index.tsx"],"names":[],"mappings":";AAQA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"lib/default/","sources":["internal/components/dropdown/index.tsx"],"names":[],"mappings":";AAQA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AA6H7C,QAAA,MAAM,QAAQ,iXA2BX,aAAa,gBA0Rf,CAAC;AAMF,eAAe,QAAQ,CAAC"}
|
|
@@ -6,7 +6,7 @@ import { useMergeRefs } from '../../hooks/use-merge-refs';
|
|
|
6
6
|
import React, { useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
7
7
|
import { createPortal } from 'react-dom';
|
|
8
8
|
import { fireNonCancelableEvent } from '../../events';
|
|
9
|
-
import { calculatePosition } from './dropdown-fit-handler';
|
|
9
|
+
import { calculatePosition, defaultMaxDropdownWidth, } from './dropdown-fit-handler';
|
|
10
10
|
import { Transition } from '../transition';
|
|
11
11
|
import { useVisualRefresh } from '../../hooks/use-visual-mode';
|
|
12
12
|
import { usePortalModeClasses } from '../../hooks/use-portal-mode-classes';
|
|
@@ -28,7 +28,7 @@ const DropdownContainer = ({ children, renderWithPortal = false, id, referrerId,
|
|
|
28
28
|
return React.createElement(React.Fragment, null, children);
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
|
-
const TransitionContent = ({ state, transitionRef, dropdownClasses, stretchWidth, interior, isRefresh, dropdownRef, verticalContainerRef, expandToViewport, header, children, footer, position, open, onMouseDown, id, role, ariaLabelledby, ariaDescribedby, }) => {
|
|
31
|
+
const TransitionContent = ({ state, transitionRef, dropdownClasses, stretchWidth, interior, isRefresh, dropdownRef, verticalContainerRef, expandToViewport, stretchBeyondTriggerWidth, header, children, footer, position, open, onMouseDown, id, role, ariaLabelledby, ariaDescribedby, }) => {
|
|
32
32
|
const contentRef = useMergeRefs(dropdownRef, transitionRef);
|
|
33
33
|
return (React.createElement("div", { className: clsx(styles.dropdown, dropdownClasses, {
|
|
34
34
|
[styles.open]: open,
|
|
@@ -38,7 +38,8 @@ const TransitionContent = ({ state, transitionRef, dropdownClasses, stretchWidth
|
|
|
38
38
|
[styles['is-empty']]: !header && !children,
|
|
39
39
|
[styles.refresh]: isRefresh,
|
|
40
40
|
[styles['use-portal']]: expandToViewport && !interior,
|
|
41
|
-
|
|
41
|
+
[styles['stretch-beyond-trigger-width']]: stretchBeyondTriggerWidth,
|
|
42
|
+
}), ref: contentRef, id: id, role: role, "aria-labelledby": ariaLabelledby, "aria-describedby": ariaDescribedby, "data-open": open, "data-animating": state !== 'exited', "aria-hidden": !open, style: stretchBeyondTriggerWidth ? { maxWidth: defaultMaxDropdownWidth } : {}, onMouseDown: onMouseDown },
|
|
42
43
|
React.createElement("div", { className: clsx(styles['dropdown-content-wrapper'], isRefresh && styles.refresh) },
|
|
43
44
|
React.createElement("div", { className: styles['ie11-wrapper'] },
|
|
44
45
|
React.createElement("div", { ref: verticalContainerRef, className: styles['dropdown-content'] },
|
|
@@ -47,7 +48,7 @@ const TransitionContent = ({ state, transitionRef, dropdownClasses, stretchWidth
|
|
|
47
48
|
children,
|
|
48
49
|
footer))))));
|
|
49
50
|
};
|
|
50
|
-
const Dropdown = ({ children, trigger, open, onDropdownClose, onMouseDown, header, footer, dropdownId, stretchTriggerHeight = false, stretchWidth = true, stretchHeight = false, stretchToTriggerWidth = true, expandToViewport = false, preferCenter = false, interior = false, minWidth, scrollable = true, loopFocus = expandToViewport, onFocus, onBlur, contentKey, dropdownContentId, dropdownContentRole, ariaLabelledby, ariaDescribedby, }) => {
|
|
51
|
+
const Dropdown = ({ children, trigger, open, onDropdownClose, onMouseDown, header, footer, dropdownId, stretchTriggerHeight = false, stretchWidth = true, stretchHeight = false, stretchToTriggerWidth = true, stretchBeyondTriggerWidth = false, expandToViewport = false, preferCenter = false, interior = false, minWidth, scrollable = true, loopFocus = expandToViewport, onFocus, onBlur, contentKey, dropdownContentId, dropdownContentRole, ariaLabelledby, ariaDescribedby, }) => {
|
|
51
52
|
const wrapperRef = useRef(null);
|
|
52
53
|
const triggerRef = useRef(null);
|
|
53
54
|
const dropdownRef = useRef(null);
|
|
@@ -156,7 +157,7 @@ const Dropdown = ({ children, trigger, open, onDropdownClose, onMouseDown, heade
|
|
|
156
157
|
if (scrollable) {
|
|
157
158
|
dropdownRef.current.classList.add(styles.nowrap);
|
|
158
159
|
}
|
|
159
|
-
setDropdownPosition(...calculatePosition(dropdownRef.current, triggerRef.current, verticalContainerRef.current, interior, expandToViewport, preferCenter, stretchWidth, stretchHeight, isMobile, minWidth), dropdownRef.current, verticalContainerRef.current);
|
|
160
|
+
setDropdownPosition(...calculatePosition(dropdownRef.current, triggerRef.current, verticalContainerRef.current, interior, expandToViewport, preferCenter, stretchWidth, stretchHeight, isMobile, minWidth, stretchBeyondTriggerWidth), dropdownRef.current, verticalContainerRef.current);
|
|
160
161
|
if (scrollable) {
|
|
161
162
|
dropdownRef.current.classList.remove(styles.nowrap);
|
|
162
163
|
}
|
|
@@ -235,7 +236,7 @@ const Dropdown = ({ children, trigger, open, onDropdownClose, onMouseDown, heade
|
|
|
235
236
|
React.createElement(DropdownContainer, { renderWithPortal: expandToViewport && !interior, id: dropdownId, referrerId: referrerId, open: open },
|
|
236
237
|
React.createElement(Transition, { in: open !== null && open !== void 0 ? open : false, exit: false }, (state, ref) => (React.createElement("div", { ref: dropdownContainerRef },
|
|
237
238
|
React.createElement(TabTrap, { focusNextCallback: () => { var _a; return triggerRef.current && ((_a = getLastFocusable(triggerRef.current)) === null || _a === void 0 ? void 0 : _a.focus()); }, disabled: !open || !loopFocus }),
|
|
238
|
-
React.createElement(TransitionContent, { state: state, transitionRef: ref, dropdownClasses: dropdownClasses, open: open, stretchWidth: stretchWidth, interior: interior, header: header, expandToViewport: expandToViewport, footer: footer, onMouseDown: onMouseDown, isRefresh: isRefresh, dropdownRef: dropdownRef, verticalContainerRef: verticalContainerRef, position: position, id: dropdownContentId, role: dropdownContentRole, ariaLabelledby: ariaLabelledby, ariaDescribedby: ariaDescribedby }, children),
|
|
239
|
+
React.createElement(TransitionContent, { state: state, transitionRef: ref, dropdownClasses: dropdownClasses, open: open, stretchWidth: stretchWidth, interior: interior, header: header, expandToViewport: expandToViewport, stretchBeyondTriggerWidth: stretchBeyondTriggerWidth, footer: footer, onMouseDown: onMouseDown, isRefresh: isRefresh, dropdownRef: dropdownRef, verticalContainerRef: verticalContainerRef, position: position, id: dropdownContentId, role: dropdownContentRole, ariaLabelledby: ariaLabelledby, ariaDescribedby: ariaDescribedby }, children),
|
|
239
240
|
React.createElement(TabTrap, { focusNextCallback: () => { var _a; return triggerRef.current && ((_a = getFirstFocusable(triggerRef.current)) === null || _a === void 0 ? void 0 : _a.focus()); }, disabled: !open || !loopFocus })))))));
|
|
240
241
|
};
|
|
241
242
|
const isInteriorPosition = (position) => position.bottom !== undefined;
|