@cloudscape-design/components 3.0.10 → 3.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/app-layout/visual-refresh/hooks/use-dynamic-overlap.d.ts +14 -0
  2. package/app-layout/visual-refresh/hooks/use-dynamic-overlap.d.ts.map +1 -0
  3. package/app-layout/visual-refresh/hooks/use-dynamic-overlap.js +29 -0
  4. package/app-layout/visual-refresh/hooks/use-dynamic-overlap.js.map +1 -0
  5. package/container/internal.d.ts.map +1 -1
  6. package/container/internal.js +4 -15
  7. package/container/internal.js.map +1 -1
  8. package/date-picker/calendar/header/button/index.d.ts +1 -2
  9. package/date-picker/calendar/header/button/index.d.ts.map +1 -1
  10. package/date-picker/calendar/header/button/index.js +2 -3
  11. package/date-picker/calendar/header/button/index.js.map +1 -1
  12. package/date-picker/calendar/header/index.d.ts +1 -2
  13. package/date-picker/calendar/header/index.d.ts.map +1 -1
  14. package/date-picker/calendar/header/index.js +3 -3
  15. package/date-picker/calendar/header/index.js.map +1 -1
  16. package/date-picker/calendar/index.d.ts +1 -6
  17. package/date-picker/calendar/index.d.ts.map +1 -1
  18. package/date-picker/calendar/index.js +34 -18
  19. package/date-picker/calendar/index.js.map +1 -1
  20. package/date-picker/index.d.ts.map +1 -1
  21. package/date-picker/index.js +7 -25
  22. package/date-picker/index.js.map +1 -1
  23. package/internal/components/content-layout/index.d.ts.map +1 -1
  24. package/internal/components/content-layout/index.js +4 -10
  25. package/internal/components/content-layout/index.js.map +1 -1
  26. package/internal/components/focus-lock/index.d.ts +7 -0
  27. package/internal/components/focus-lock/index.d.ts.map +1 -0
  28. package/internal/components/focus-lock/index.js +26 -0
  29. package/internal/components/focus-lock/index.js.map +1 -0
  30. package/internal/components/focus-lock/utils.d.ts +4 -0
  31. package/internal/components/focus-lock/utils.d.ts.map +1 -0
  32. package/internal/components/focus-lock/utils.js +35 -0
  33. package/internal/components/focus-lock/utils.js.map +1 -0
  34. package/internal/components/tab-trap/index.d.ts +1 -2
  35. package/internal/components/tab-trap/index.d.ts.map +1 -1
  36. package/internal/components/tab-trap/index.js +2 -3
  37. package/internal/components/tab-trap/index.js.map +1 -1
  38. package/internal/environment.js +1 -1
  39. package/package.json +1 -1
  40. package/table/styles.css.js +32 -32
  41. package/table/styles.scoped.css +38 -37
  42. package/table/styles.selectors.js +32 -32
  43. package/test-utils/dom/attribute-editor/index.d.ts +2 -1
  44. package/test-utils/dom/attribute-editor/index.js +6 -5
  45. package/test-utils/dom/attribute-editor/index.js.map +1 -1
  46. package/test-utils/selectors/attribute-editor/index.d.ts +2 -1
  47. package/test-utils/selectors/attribute-editor/index.js +6 -5
  48. package/test-utils/selectors/attribute-editor/index.js.map +1 -1
  49. package/test-utils/tsconfig.tsbuildinfo +1 -1
  50. package/wizard/wizard-form-header.d.ts.map +1 -1
  51. package/wizard/wizard-form-header.js +3 -14
  52. package/wizard/wizard-form-header.js.map +1 -1
@@ -0,0 +1,14 @@
1
+ export interface UseDynamicOverlapProps {
2
+ /**
3
+ * Disables hook if not needed. By default, `false`.
4
+ */
5
+ disabled?: boolean;
6
+ }
7
+ /**
8
+ * Observes the height of an element referenced by the returning ref and sets the value as overlapping
9
+ * height for the surrounding AppLayout component.
10
+ * @param props.disabled disables hook if not applicable
11
+ * @returns ref to be measured as overlapping height
12
+ */
13
+ export declare function useDynamicOverlap(props?: UseDynamicOverlapProps): import("react").Ref<any>;
14
+ //# sourceMappingURL=use-dynamic-overlap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-dynamic-overlap.d.ts","sourceRoot":"","sources":["../../../../../src/app-layout/visual-refresh/hooks/use-dynamic-overlap.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,CAAC,EAAE,sBAAsB,4BAqB/D"}
@@ -0,0 +1,29 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import { useContext, useLayoutEffect } from 'react';
4
+ import { AppLayoutContext } from '../context';
5
+ import { useContainerQuery } from '../../../internal/hooks/container-queries';
6
+ /**
7
+ * Observes the height of an element referenced by the returning ref and sets the value as overlapping
8
+ * height for the surrounding AppLayout component.
9
+ * @param props.disabled disables hook if not applicable
10
+ * @returns ref to be measured as overlapping height
11
+ */
12
+ export function useDynamicOverlap(props) {
13
+ var _a;
14
+ var disabled = (_a = props === null || props === void 0 ? void 0 : props.disabled) !== null && _a !== void 0 ? _a : false;
15
+ var setDynamicOverlapHeight = useContext(AppLayoutContext).setDynamicOverlapHeight;
16
+ var _b = useContainerQuery(function (rect) { return rect.height; }), overlapContainerQuery = _b[0], overlapElementRef = _b[1];
17
+ useLayoutEffect(function handleDynamicOverlapHeight() {
18
+ if (!disabled) {
19
+ setDynamicOverlapHeight(overlapContainerQuery !== null && overlapContainerQuery !== void 0 ? overlapContainerQuery : 0);
20
+ }
21
+ return function () {
22
+ if (!disabled) {
23
+ setDynamicOverlapHeight(0);
24
+ }
25
+ };
26
+ }, [disabled, overlapContainerQuery, setDynamicOverlapHeight]);
27
+ return overlapElementRef;
28
+ }
29
+ //# sourceMappingURL=use-dynamic-overlap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-dynamic-overlap.js","sourceRoot":"","sources":["../../../../../src/app-layout/visual-refresh/hooks/use-dynamic-overlap.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAEpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,2CAA2C,CAAC;AAS9E;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAA8B;;IAC9D,IAAM,QAAQ,GAAG,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,QAAQ,mCAAI,KAAK,CAAC;IAClC,IAAA,uBAAuB,GAAK,UAAU,CAAC,gBAAgB,CAAC,wBAAjC,CAAkC;IAC3D,IAAA,KAA6C,iBAAiB,CAAC,UAAA,IAAI,IAAI,OAAA,IAAI,CAAC,MAAM,EAAX,CAAW,CAAC,EAAlF,qBAAqB,QAAA,EAAE,iBAAiB,QAA0C,CAAC;IAE1F,eAAe,CACb,SAAS,0BAA0B;QACjC,IAAI,CAAC,QAAQ,EAAE;YACb,uBAAuB,CAAC,qBAAqB,aAArB,qBAAqB,cAArB,qBAAqB,GAAI,CAAC,CAAC,CAAC;SACrD;QAED,OAAO;YACL,IAAI,CAAC,QAAQ,EAAE;gBACb,uBAAuB,CAAC,CAAC,CAAC,CAAC;aAC5B;QACH,CAAC,CAAC;IACJ,CAAC,EACD,CAAC,QAAQ,EAAE,qBAAqB,EAAE,uBAAuB,CAAC,CAC3D,CAAC;IAEF,OAAO,iBAAiB,CAAC;AAC3B,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { useContext, useLayoutEffect } from 'react';\n\nimport { AppLayoutContext } from '../context';\nimport { useContainerQuery } from '../../../internal/hooks/container-queries';\n\nexport interface UseDynamicOverlapProps {\n /**\n * Disables hook if not needed. By default, `false`.\n */\n disabled?: boolean;\n}\n\n/**\n * Observes the height of an element referenced by the returning ref and sets the value as overlapping\n * height for the surrounding AppLayout component.\n * @param props.disabled disables hook if not applicable\n * @returns ref to be measured as overlapping height\n */\nexport function useDynamicOverlap(props?: UseDynamicOverlapProps) {\n const disabled = props?.disabled ?? false;\n const { setDynamicOverlapHeight } = useContext(AppLayoutContext);\n const [overlapContainerQuery, overlapElementRef] = useContainerQuery(rect => rect.height);\n\n useLayoutEffect(\n function handleDynamicOverlapHeight() {\n if (!disabled) {\n setDynamicOverlapHeight(overlapContainerQuery ?? 0);\n }\n\n return () => {\n if (!disabled) {\n setDynamicOverlapHeight(0);\n }\n };\n },\n [disabled, overlapContainerQuery, setDynamicOverlapHeight]\n );\n\n return overlapElementRef;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/container/internal.tsx"],"names":[],"mappings":"AAGA,OAAO,KAA8C,MAAM,OAAO,CAAC;AAEnE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAOlF,MAAM,WAAW,sBAAuB,SAAQ,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC,EAAE,0BAA0B;IACzG,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAC9C;;;;;OAKG;IACH,OAAO,CAAC,EAAE,cAAc,CAAC,SAAS,CAAC,GAAG,UAAU,GAAG,WAAW,GAAG,OAAO,CAAC;CAC1E;AAED,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,EACxC,MAAM,EACN,MAAM,EACN,QAAQ,EACR,OAAmB,EACnB,qBAA6B,EAC7B,sBAA8B,EAC9B,cAAc,EACd,cAAsB,EACtB,iBAAwB,EACxB,sBAA8B,EAC9B,uBAA+B,EAC/B,WAAW,EACX,GAAG,SAAS,EACb,EAAE,sBAAsB,eAyExB"}
1
+ {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/container/internal.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAiB,MAAM,OAAO,CAAC;AAEtC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAMlF,MAAM,WAAW,sBAAuB,SAAQ,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC,EAAE,0BAA0B;IACzG,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAC9C;;;;;OAKG;IACH,OAAO,CAAC,EAAE,cAAc,CAAC,SAAS,CAAC,GAAG,UAAU,GAAG,WAAW,GAAG,OAAO,CAAC;CAC1E;AAED,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,EACxC,MAAM,EACN,MAAM,EACN,QAAQ,EACR,OAAmB,EACnB,qBAA6B,EAC7B,sBAA8B,EAC9B,cAAc,EACd,cAAsB,EACtB,iBAAwB,EACxB,sBAA8B,EAC9B,uBAA+B,EAC/B,WAAW,EACX,GAAG,SAAS,EACb,EAAE,sBAAsB,eA0DxB"}
@@ -2,11 +2,10 @@ import { __assign, __rest } from "tslib";
2
2
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  import clsx from 'clsx';
5
- import React, { useContext, useLayoutEffect, useRef } from 'react';
6
- import { AppLayoutContext } from '../app-layout/visual-refresh/context';
5
+ import React, { useRef } from 'react';
6
+ import { useDynamicOverlap } from '../app-layout/visual-refresh/hooks/use-dynamic-overlap';
7
7
  import { getBaseProps } from '../internal/base-component';
8
8
  import { StickyHeaderContext, useStickyHeader } from './use-sticky-header';
9
- import { useContainerQuery } from '../internal/hooks/container-queries';
10
9
  import { useMergeRefs } from '../internal/hooks/use-merge-refs';
11
10
  import { useVisualRefresh } from '../internal/hooks/use-visual-mode';
12
11
  import styles from './styles.css.js';
@@ -16,20 +15,10 @@ export default function InternalContainer(_a) {
16
15
  var baseProps = getBaseProps(restProps);
17
16
  var rootRef = useRef(null);
18
17
  var headerRef = useRef(null);
18
+ var _m = useStickyHeader(rootRef, headerRef, __stickyHeader, __stickyOffset), isSticky = _m.isSticky, isStuck = _m.isStuck, stickyStyles = _m.stickyStyles;
19
19
  var isRefresh = useVisualRefresh(rootRef);
20
20
  var hasDynamicHeight = isRefresh && variant === 'full-page';
21
- var _m = useStickyHeader(rootRef, headerRef, __stickyHeader, __stickyOffset), isSticky = _m.isSticky, isStuck = _m.isStuck, stickyStyles = _m.stickyStyles;
22
- /**
23
- * Observe the dynamic height of the full page container variant in
24
- * visual refresh and update the AppLayout dynamicOverlapHeight property.
25
- */
26
- var setDynamicOverlapHeight = useContext(AppLayoutContext).setDynamicOverlapHeight;
27
- var _o = useContainerQuery(function (rect) { return rect.height; }), overlapContainerQuery = _o[0], overlapElement = _o[1];
28
- useLayoutEffect(function handleDynamicOverlapHeight() {
29
- if (hasDynamicHeight) {
30
- setDynamicOverlapHeight(overlapContainerQuery !== null && overlapContainerQuery !== void 0 ? overlapContainerQuery : 0);
31
- }
32
- }, [hasDynamicHeight, overlapContainerQuery, setDynamicOverlapHeight]);
21
+ var overlapElement = useDynamicOverlap({ disabled: !hasDynamicHeight });
33
22
  var mergedRef = useMergeRefs(rootRef, __internalRootRef);
34
23
  var headerMergedRef = useMergeRefs(headerRef, overlapElement, __headerRef);
35
24
  return (React.createElement("div", __assign({}, baseProps, { className: clsx(baseProps.className, styles.root, styles["variant-".concat(variant)]), ref: mergedRef }),
@@ -1 +1 @@
1
- {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/container/internal.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAExE,OA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jC,GAAC,MAAM,CAAC,eAAe,CAAC,IAAG,CAAC,qBAAqB;wBACjD,IACE,YAAY,IAChB,GAAG,EAAE,eAAe,KAEnB,gBAAgB,CAAC,CAAC,CAAC,CAClB,6BAAK,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,8BAA8B,CAAC,IAAG,MAAM,CAAO,CAC5F,CAAC,CAAC,CAAC,CACF,MAAM,CACP,CACG,CACuB,CAChC;QACD,6BACE,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;gBAC5B,GAAC,MAAM,CAAC,eAAe,CAAC,IAAG,CAAC,sBAAsB;oBAClD,IAED,QAAQ,CACL;QACL,MAAM,IAAI,CACT,6BACE,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM;gBAC3B,GAAC,MAAM,CAAC,cAAc,CAAC,IAAG,CAAC,sBAAsB;gBACjD,GAAC,MAAM,CAAC,eAAe,CAAC,IAAG,CAAC,uBAAuB;oBACnD,IAED,MAAM,CACH,CACP,CACG,CACP,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport clsx from 'clsx';\nimport React, { useContext, useLayoutEffect, useRef } from 'react';\nimport { AppLayoutContext } from '../app-layout/visual-refresh/context';\nimport { ContainerProps } from './interfaces';\nimport { getBaseProps } from '../internal/base-component';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component';\nimport { StickyHeaderContext, useStickyHeader } from './use-sticky-header';\nimport { useContainerQuery } from '../internal/hooks/container-queries';\nimport { useMergeRefs } from '../internal/hooks/use-merge-refs';\nimport { useVisualRefresh } from '../internal/hooks/use-visual-mode';\nimport styles from './styles.css.js';\n\nexport interface InternalContainerProps extends Omit<ContainerProps, 'variant'>, InternalBaseComponentProps {\n __stickyHeader?: boolean;\n __stickyOffset?: number;\n __disableFooterDivider?: boolean;\n __disableFooterPaddings?: boolean;\n __headerRef?: React.RefObject<HTMLDivElement>;\n /**\n * Additional internal variant:\n * * `embedded` - Use this variant within a parent container (such as a modal,\n * expandable section, container or split panel).\n * * `full-page` – Only for internal use in table, cards and other components\n */\n variant?: ContainerProps['variant'] | 'embedded' | 'full-page' | 'cards';\n}\n\nexport default function InternalContainer({\n header,\n footer,\n children,\n variant = 'default',\n disableHeaderPaddings = false,\n disableContentPaddings = false,\n __stickyOffset,\n __stickyHeader = false,\n __internalRootRef = null,\n __disableFooterDivider = false,\n __disableFooterPaddings = false,\n __headerRef,\n ...restProps\n}: InternalContainerProps) {\n const baseProps = getBaseProps(restProps);\n const rootRef = useRef<HTMLDivElement>(null);\n const headerRef = useRef<HTMLDivElement>(null);\n const isRefresh = useVisualRefresh(rootRef);\n const hasDynamicHeight = isRefresh && variant === 'full-page';\n const { isSticky, isStuck, stickyStyles } = useStickyHeader(rootRef, headerRef, __stickyHeader, __stickyOffset);\n\n /**\n * Observe the dynamic height of the full page container variant in\n * visual refresh and update the AppLayout dynamicOverlapHeight property.\n */\n const { setDynamicOverlapHeight } = useContext(AppLayoutContext);\n const [overlapContainerQuery, overlapElement] = useContainerQuery(rect => rect.height);\n\n useLayoutEffect(\n function handleDynamicOverlapHeight() {\n if (hasDynamicHeight) {\n setDynamicOverlapHeight(overlapContainerQuery ?? 0);\n }\n },\n [hasDynamicHeight, overlapContainerQuery, setDynamicOverlapHeight]\n );\n\n const mergedRef = useMergeRefs(rootRef, __internalRootRef);\n const headerMergedRef = useMergeRefs(headerRef, overlapElement, __headerRef);\n\n return (\n <div\n {...baseProps}\n className={clsx(baseProps.className, styles.root, styles[`variant-${variant}`])}\n ref={mergedRef}\n >\n {header && (\n <StickyHeaderContext.Provider value={{ isStuck }}>\n <div\n className={clsx(styles.header, styles[`header-variant-${variant}`], {\n [styles['header-sticky-disabled']]: __stickyHeader && !isSticky,\n [styles['header-sticky-enabled']]: isSticky,\n [styles['header-dynamic-height']]: hasDynamicHeight,\n [styles['header-stuck']]: isStuck,\n [styles['with-paddings']]: !disableHeaderPaddings,\n })}\n {...stickyStyles}\n ref={headerMergedRef}\n >\n {hasDynamicHeight ? (\n <div className={clsx(styles['dark-header'], 'awsui-context-content-header')}>{header}</div>\n ) : (\n header\n )}\n </div>\n </StickyHeaderContext.Provider>\n )}\n <div\n className={clsx(styles.content, {\n [styles['with-paddings']]: !disableContentPaddings,\n })}\n >\n {children}\n </div>\n {footer && (\n <div\n className={clsx(styles.footer, {\n [styles['with-divider']]: !__disableFooterDivider,\n [styles['with-paddings']]: !__disableFooterPaddings,\n })}\n >\n {footer}\n </div>\n )}\n </div>\n );\n}\n"]}
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/container/internal.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wDAAwD,CAAC;AAE3F,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAiBrC,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,EAcjB;;IAbvB,IAAA,MAAM,YAAA,EACN,MAAM,YAAA,EACN,QAAQ,cAAA,EACR,eAAmB,EAAnB,OAAO,mBAAG,SAAS,KAAA,EACnB,6BAA6B,EAA7B,qBAAqB,mBAAG,KAAK,KAAA,EAC7B,8BAA8B,EAA9B,sBAAsB,mBAAG,KAAK,KAAA,EAC9B,cAAc,oBAAA,EACd,sBAAsB,EAAtB,cAAc,mBAAG,KAAK,KAAA,EACtB,yBAAwB,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ChE,GAAC,MAAM,CAAC,wBAAwB,CAAC,IAAG,cAAc,IAAI,CAAC,QAAQ;oBAC/D,GAAC,MAAM,CAAC,uBAAuB,CAAC,IAAG,QAAQ;oBAC3C,GAAC,MAAM,CAAC,uBAAuB,CAAC,IAAG,gBAAgB;oBACnD,GAAC,MAAM,CAAC,cAAc,CAAC,IAAG,OAAO;oBACjC,GAAC,MAAM,CAAC,eAAe,CAAC,IAAG,CAAC,qBAAqB;wBACjD,IACE,YAAY,IAChB,GAAG,EAAE,eAAe,KAEnB,gBAAgB,CAAC,CAAC,CAAC,CAClB,6BAAK,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,8BAA8B,CAAC,IAAG,MAAM,CAAO,CAC5F,CAAC,CAAC,CAAC,CACF,MAAM,CACP,CACG,CACuB,CAChC;QACD,6BACE,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;gBAC5B,GAAC,MAAM,CAAC,eAAe,CAAC,IAAG,CAAC,sBAAsB;oBAClD,IAED,QAAQ,CACL;QACL,MAAM,IAAI,CACT,6BACE,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM;gBAC3B,GAAC,MAAM,CAAC,cAAc,CAAC,IAAG,CAAC,sBAAsB;gBACjD,GAAC,MAAM,CAAC,eAAe,CAAC,IAAG,CAAC,uBAAuB;oBACnD,IAED,MAAM,CACH,CACP,CACG,CACP,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport clsx from 'clsx';\nimport React, { useRef } from 'react';\nimport { useDynamicOverlap } from '../app-layout/visual-refresh/hooks/use-dynamic-overlap';\nimport { ContainerProps } from './interfaces';\nimport { getBaseProps } from '../internal/base-component';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component';\nimport { StickyHeaderContext, useStickyHeader } from './use-sticky-header';\nimport { useMergeRefs } from '../internal/hooks/use-merge-refs';\nimport { useVisualRefresh } from '../internal/hooks/use-visual-mode';\nimport styles from './styles.css.js';\n\nexport interface InternalContainerProps extends Omit<ContainerProps, 'variant'>, InternalBaseComponentProps {\n __stickyHeader?: boolean;\n __stickyOffset?: number;\n __disableFooterDivider?: boolean;\n __disableFooterPaddings?: boolean;\n __headerRef?: React.RefObject<HTMLDivElement>;\n /**\n * Additional internal variant:\n * * `embedded` - Use this variant within a parent container (such as a modal,\n * expandable section, container or split panel).\n * * `full-page` – Only for internal use in table, cards and other components\n */\n variant?: ContainerProps['variant'] | 'embedded' | 'full-page' | 'cards';\n}\n\nexport default function InternalContainer({\n header,\n footer,\n children,\n variant = 'default',\n disableHeaderPaddings = false,\n disableContentPaddings = false,\n __stickyOffset,\n __stickyHeader = false,\n __internalRootRef = null,\n __disableFooterDivider = false,\n __disableFooterPaddings = false,\n __headerRef,\n ...restProps\n}: InternalContainerProps) {\n const baseProps = getBaseProps(restProps);\n const rootRef = useRef<HTMLDivElement>(null);\n const headerRef = useRef<HTMLDivElement>(null);\n const { isSticky, isStuck, stickyStyles } = useStickyHeader(rootRef, headerRef, __stickyHeader, __stickyOffset);\n const isRefresh = useVisualRefresh(rootRef);\n const hasDynamicHeight = isRefresh && variant === 'full-page';\n const overlapElement = useDynamicOverlap({ disabled: !hasDynamicHeight });\n\n const mergedRef = useMergeRefs(rootRef, __internalRootRef);\n const headerMergedRef = useMergeRefs(headerRef, overlapElement, __headerRef);\n\n return (\n <div\n {...baseProps}\n className={clsx(baseProps.className, styles.root, styles[`variant-${variant}`])}\n ref={mergedRef}\n >\n {header && (\n <StickyHeaderContext.Provider value={{ isStuck }}>\n <div\n className={clsx(styles.header, styles[`header-variant-${variant}`], {\n [styles['header-sticky-disabled']]: __stickyHeader && !isSticky,\n [styles['header-sticky-enabled']]: isSticky,\n [styles['header-dynamic-height']]: hasDynamicHeight,\n [styles['header-stuck']]: isStuck,\n [styles['with-paddings']]: !disableHeaderPaddings,\n })}\n {...stickyStyles}\n ref={headerMergedRef}\n >\n {hasDynamicHeight ? (\n <div className={clsx(styles['dark-header'], 'awsui-context-content-header')}>{header}</div>\n ) : (\n header\n )}\n </div>\n </StickyHeaderContext.Provider>\n )}\n <div\n className={clsx(styles.content, {\n [styles['with-paddings']]: !disableContentPaddings,\n })}\n >\n {children}\n </div>\n {footer && (\n <div\n className={clsx(styles.footer, {\n [styles['with-divider']]: !__disableFooterDivider,\n [styles['with-paddings']]: !__disableFooterPaddings,\n })}\n >\n {footer}\n </div>\n )}\n </div>\n );\n}\n"]}
@@ -1,9 +1,8 @@
1
1
  interface HeaderButtonProps {
2
2
  ariaLabel: string;
3
3
  isPrevious: boolean;
4
- focusable: boolean;
5
4
  onChangeMonth: (isPrevious: boolean) => void;
6
5
  }
7
- declare const HeaderButton: ({ ariaLabel, isPrevious, onChangeMonth, focusable }: HeaderButtonProps) => JSX.Element;
6
+ declare const HeaderButton: ({ ariaLabel, isPrevious, onChangeMonth }: HeaderButtonProps) => JSX.Element;
8
7
  export default HeaderButton;
9
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/date-picker/calendar/header/button/index.tsx"],"names":[],"mappings":"AAQA,UAAU,iBAAiB;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,aAAa,EAAE,CAAC,UAAU,EAAE,OAAO,KAAK,IAAI,CAAC;CAC9C;AAED,QAAA,MAAM,YAAY,wDAAyD,iBAAiB,gBAqB3F,CAAC;AAEF,eAAe,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/date-picker/calendar/header/button/index.tsx"],"names":[],"mappings":"AAQA,UAAU,iBAAiB;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;IACpB,aAAa,EAAE,CAAC,UAAU,EAAE,OAAO,KAAK,IAAI,CAAC;CAC9C;AAED,QAAA,MAAM,YAAY,6CAA8C,iBAAiB,gBAoBhF,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -5,11 +5,10 @@ import React from 'react';
5
5
  import { InternalButton } from '../../../../button/internal';
6
6
  import styles from '../../../styles.css.js';
7
7
  var HeaderButton = function (_a) {
8
- var ariaLabel = _a.ariaLabel, isPrevious = _a.isPrevious, onChangeMonth = _a.onChangeMonth, focusable = _a.focusable;
8
+ var ariaLabel = _a.ariaLabel, isPrevious = _a.isPrevious, onChangeMonth = _a.onChangeMonth;
9
9
  var iconName = isPrevious ? 'angle-left' : 'angle-right';
10
10
  var additionalAttributes = {
11
- className: isPrevious ? styles['calendar-prev-month-btn'] : styles['calendar-next-month-btn'],
12
- tabIndex: focusable ? 0 : -1
11
+ className: isPrevious ? styles['calendar-prev-month-btn'] : styles['calendar-next-month-btn']
13
12
  };
14
13
  var onClick = function (e) {
15
14
  e.preventDefault();
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/date-picker/calendar/header/button/index.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,MAAM,MAAM,wBAAwB,CAAC;AAS5C,IAAM,YAAY,GAAG,UAAC,EAAsE;QAApE,SAAS,eAAA,EAAE,UAAU,gBAAA,EAAE,aAAa,mBAAA,EAAE,SAAS,eAAA;IACrE,IAAM,QAAQ,GAAG,UAAU,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,aAAa,CAAC;IAC3D,IAAM,oBAAoB,GAA4C;QACpE,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,yBAAyB,CAAC;QAC7F,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KAC7B,CAAC;IAEF,IAAM,OAAO,GAAoD,UAAA,CAAC;QAChE,CAAC,CAAC,cAAc,EAAE,CAAC;QACnB,aAAa,CAAC,UAAU,CAAC,CAAC;IAC5B,CAAC,CAAC;IAEF,OAAO,CACL,oBAAC,cAAc,eACT,oBAAoB,IACxB,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,IAChB,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React from 'react';\nimport { CancelableEventHandler } from '../../../../internal/events';\nimport { ButtonProps } from '../../../../button/interfaces';\nimport { InternalButton } from '../../../../button/internal';\nimport styles from '../../../styles.css.js';\n\ninterface HeaderButtonProps {\n ariaLabel: string;\n isPrevious: boolean;\n focusable: boolean;\n onChangeMonth: (isPrevious: boolean) => void;\n}\n\nconst HeaderButton = ({ ariaLabel, isPrevious, onChangeMonth, focusable }: HeaderButtonProps) => {\n const iconName = isPrevious ? 'angle-left' : 'angle-right';\n const additionalAttributes: React.HTMLAttributes<HTMLButtonElement> = {\n className: isPrevious ? styles['calendar-prev-month-btn'] : styles['calendar-next-month-btn'],\n tabIndex: focusable ? 0 : -1,\n };\n\n const onClick: CancelableEventHandler<ButtonProps.ClickDetail> = e => {\n e.preventDefault();\n onChangeMonth(isPrevious);\n };\n\n return (\n <InternalButton\n {...additionalAttributes}\n iconName={iconName}\n ariaLabel={ariaLabel}\n variant={'icon'}\n onClick={onClick}\n />\n );\n};\n\nexport default HeaderButton;\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/date-picker/calendar/header/button/index.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,MAAM,MAAM,wBAAwB,CAAC;AAQ5C,IAAM,YAAY,GAAG,UAAC,EAA2D;QAAzD,SAAS,eAAA,EAAE,UAAU,gBAAA,EAAE,aAAa,mBAAA;IAC1D,IAAM,QAAQ,GAAG,UAAU,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,aAAa,CAAC;IAC3D,IAAM,oBAAoB,GAA4C;QACpE,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,yBAAyB,CAAC;KAC9F,CAAC;IAEF,IAAM,OAAO,GAAoD,UAAA,CAAC;QAChE,CAAC,CAAC,cAAc,EAAE,CAAC;QACnB,aAAa,CAAC,UAAU,CAAC,CAAC;IAC5B,CAAC,CAAC;IAEF,OAAO,CACL,oBAAC,cAAc,eACT,oBAAoB,IACxB,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,IAChB,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React from 'react';\nimport { CancelableEventHandler } from '../../../../internal/events';\nimport { ButtonProps } from '../../../../button/interfaces';\nimport { InternalButton } from '../../../../button/internal';\nimport styles from '../../../styles.css.js';\n\ninterface HeaderButtonProps {\n ariaLabel: string;\n isPrevious: boolean;\n onChangeMonth: (isPrevious: boolean) => void;\n}\n\nconst HeaderButton = ({ ariaLabel, isPrevious, onChangeMonth }: HeaderButtonProps) => {\n const iconName = isPrevious ? 'angle-left' : 'angle-right';\n const additionalAttributes: React.HTMLAttributes<HTMLButtonElement> = {\n className: isPrevious ? styles['calendar-prev-month-btn'] : styles['calendar-next-month-btn'],\n };\n\n const onClick: CancelableEventHandler<ButtonProps.ClickDetail> = e => {\n e.preventDefault();\n onChangeMonth(isPrevious);\n };\n\n return (\n <InternalButton\n {...additionalAttributes}\n iconName={iconName}\n ariaLabel={ariaLabel}\n variant={'icon'}\n onClick={onClick}\n />\n );\n};\n\nexport default HeaderButton;\n"]}
@@ -5,8 +5,7 @@ interface CalendarHeaderProps {
5
5
  onChangeMonth: (prev?: boolean) => void;
6
6
  previousMonthLabel: string;
7
7
  nextMonthLabel: string;
8
- calendarHasFocus: boolean;
9
8
  }
10
- declare const CalendarHeader: ({ headerId, baseDate, locale, onChangeMonth, previousMonthLabel, nextMonthLabel, calendarHasFocus, }: CalendarHeaderProps) => JSX.Element;
9
+ declare const CalendarHeader: ({ headerId, baseDate, locale, onChangeMonth, previousMonthLabel, nextMonthLabel, }: CalendarHeaderProps) => JSX.Element;
11
10
  export default CalendarHeader;
12
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/date-picker/calendar/header/index.tsx"],"names":[],"mappings":"AAOA,UAAU,mBAAmB;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,IAAI,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,CAAC,IAAI,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IACxC,kBAAkB,EAAE,MAAM,CAAC;IAC3B,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,OAAO,CAAC;CAC3B;AAED,QAAA,MAAM,cAAc,yGAQjB,mBAAmB,gBAoBrB,CAAC;AAEF,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/date-picker/calendar/header/index.tsx"],"names":[],"mappings":"AAOA,UAAU,mBAAmB;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,IAAI,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,CAAC,IAAI,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IACxC,kBAAkB,EAAE,MAAM,CAAC;IAC3B,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,QAAA,MAAM,cAAc,uFAOjB,mBAAmB,gBAUrB,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -5,11 +5,11 @@ import styles from '../../styles.css.js';
5
5
  import { renderMonthAndYear } from '../utils/intl';
6
6
  import HeaderButton from './button';
7
7
  var CalendarHeader = function (_a) {
8
- var headerId = _a.headerId, baseDate = _a.baseDate, locale = _a.locale, onChangeMonth = _a.onChangeMonth, previousMonthLabel = _a.previousMonthLabel, nextMonthLabel = _a.nextMonthLabel, calendarHasFocus = _a.calendarHasFocus;
8
+ var headerId = _a.headerId, baseDate = _a.baseDate, locale = _a.locale, onChangeMonth = _a.onChangeMonth, previousMonthLabel = _a.previousMonthLabel, nextMonthLabel = _a.nextMonthLabel;
9
9
  return (React.createElement("div", { className: styles['calendar-header'] },
10
- React.createElement(HeaderButton, { ariaLabel: previousMonthLabel, isPrevious: true, onChangeMonth: onChangeMonth, focusable: calendarHasFocus }),
10
+ React.createElement(HeaderButton, { ariaLabel: previousMonthLabel, isPrevious: true, onChangeMonth: onChangeMonth }),
11
11
  React.createElement("div", { className: styles['calendar-header-month'], id: headerId, "aria-live": "polite" }, renderMonthAndYear(locale, baseDate)),
12
- React.createElement(HeaderButton, { ariaLabel: nextMonthLabel, isPrevious: false, onChangeMonth: onChangeMonth, focusable: calendarHasFocus })));
12
+ React.createElement(HeaderButton, { ariaLabel: nextMonthLabel, isPrevious: false, onChangeMonth: onChangeMonth })));
13
13
  };
14
14
  export default CalendarHeader;
15
15
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/date-picker/calendar/header/index.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,MAAM,MAAM,qBAAqB,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,YAAY,MAAM,UAAU,CAAC;AAYpC,IAAM,cAAc,GAAG,UAAC,EAQF;QAPpB,QAAQ,cAAA,EACR,QAAQ,cAAA,EACR,MAAM,YAAA,EACN,aAAa,mBAAA,EACb,kBAAkB,wBAAA,EAClB,cAAc,oBAAA,EACd,gBAAgB,sBAAA;IAEhB,OAAO,CACL,6BAAK,SAAS,EAAE,MAAM,CAAC,iBAAiB,CAAC;QACvC,oBAAC,YAAY,IACX,SAAS,EAAE,kBAAkB,EAC7B,UAAU,EAAE,IAAI,EAChB,aAAa,EAAE,aAAa,EAC5B,SAAS,EAAE,gBAAgB,GAC3B;QACF,6BAAK,SAAS,EAAE,MAAM,CAAC,uBAAuB,CAAC,EAAE,EAAE,EAAE,QAAQ,eAAY,QAAQ,IAC9E,kBAAkB,CAAC,MAAM,EAAE,QAAQ,CAAC,CACjC;QACN,oBAAC,YAAY,IACX,SAAS,EAAE,cAAc,EACzB,UAAU,EAAE,KAAK,EACjB,aAAa,EAAE,aAAa,EAC5B,SAAS,EAAE,gBAAgB,GAC3B,CACE,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,cAAc,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React from 'react';\nimport styles from '../../styles.css.js';\nimport { renderMonthAndYear } from '../utils/intl';\nimport HeaderButton from './button';\n\ninterface CalendarHeaderProps {\n headerId: string;\n baseDate: Date;\n locale: string;\n onChangeMonth: (prev?: boolean) => void;\n previousMonthLabel: string;\n nextMonthLabel: string;\n calendarHasFocus: boolean;\n}\n\nconst CalendarHeader = ({\n headerId,\n baseDate,\n locale,\n onChangeMonth,\n previousMonthLabel,\n nextMonthLabel,\n calendarHasFocus,\n}: CalendarHeaderProps) => {\n return (\n <div className={styles['calendar-header']}>\n <HeaderButton\n ariaLabel={previousMonthLabel}\n isPrevious={true}\n onChangeMonth={onChangeMonth}\n focusable={calendarHasFocus}\n />\n <div className={styles['calendar-header-month']} id={headerId} aria-live=\"polite\">\n {renderMonthAndYear(locale, baseDate)}\n </div>\n <HeaderButton\n ariaLabel={nextMonthLabel}\n isPrevious={false}\n onChangeMonth={onChangeMonth}\n focusable={calendarHasFocus}\n />\n </div>\n );\n};\n\nexport default CalendarHeader;\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/date-picker/calendar/header/index.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,MAAM,MAAM,qBAAqB,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,YAAY,MAAM,UAAU,CAAC;AAWpC,IAAM,cAAc,GAAG,UAAC,EAOF;QANpB,QAAQ,cAAA,EACR,QAAQ,cAAA,EACR,MAAM,YAAA,EACN,aAAa,mBAAA,EACb,kBAAkB,wBAAA,EAClB,cAAc,oBAAA;IAEd,OAAO,CACL,6BAAK,SAAS,EAAE,MAAM,CAAC,iBAAiB,CAAC;QACvC,oBAAC,YAAY,IAAC,SAAS,EAAE,kBAAkB,EAAE,UAAU,EAAE,IAAI,EAAE,aAAa,EAAE,aAAa,GAAI;QAC/F,6BAAK,SAAS,EAAE,MAAM,CAAC,uBAAuB,CAAC,EAAE,EAAE,EAAE,QAAQ,eAAY,QAAQ,IAC9E,kBAAkB,CAAC,MAAM,EAAE,QAAQ,CAAC,CACjC;QACN,oBAAC,YAAY,IAAC,SAAS,EAAE,cAAc,EAAE,UAAU,EAAE,KAAK,EAAE,aAAa,EAAE,aAAa,GAAI,CACxF,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,cAAc,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React from 'react';\nimport styles from '../../styles.css.js';\nimport { renderMonthAndYear } from '../utils/intl';\nimport HeaderButton from './button';\n\ninterface CalendarHeaderProps {\n headerId: string;\n baseDate: Date;\n locale: string;\n onChangeMonth: (prev?: boolean) => void;\n previousMonthLabel: string;\n nextMonthLabel: string;\n}\n\nconst CalendarHeader = ({\n headerId,\n baseDate,\n locale,\n onChangeMonth,\n previousMonthLabel,\n nextMonthLabel,\n}: CalendarHeaderProps) => {\n return (\n <div className={styles['calendar-header']}>\n <HeaderButton ariaLabel={previousMonthLabel} isPrevious={true} onChangeMonth={onChangeMonth} />\n <div className={styles['calendar-header-month']} id={headerId} aria-live=\"polite\">\n {renderMonthAndYear(locale, baseDate)}\n </div>\n <HeaderButton ariaLabel={nextMonthLabel} isPrevious={false} onChangeMonth={onChangeMonth} />\n </div>\n );\n};\n\nexport default CalendarHeader;\n"]}
@@ -1,8 +1,6 @@
1
- import React from 'react';
2
1
  import { BaseComponentProps } from '../../internal/base-component';
3
2
  import { DatePickerProps } from '../interfaces';
4
3
  import { CalendarTypes } from './definitions';
5
- import { DateChangeHandlerNullable } from './grid';
6
4
  export interface DateChangeHandler {
7
5
  (detail: CalendarTypes.DateDetail): void;
8
6
  }
@@ -15,16 +13,13 @@ interface CalendarProps extends BaseComponentProps {
15
13
  startOfWeek: DayIndex;
16
14
  selectedDate: Date | null;
17
15
  displayedDate: Date;
18
- focusedDate?: Date | null;
19
16
  isDateEnabled: DatePickerProps.IsDateEnabledFunction;
20
- calendarHasFocus: boolean;
21
17
  nextMonthLabel: string;
22
18
  previousMonthLabel: string;
23
19
  todayAriaLabel: string;
24
20
  onChangeMonth: MonthChangeHandler;
25
21
  onSelectDate: DateChangeHandler;
26
- onFocusDate: DateChangeHandlerNullable;
27
22
  }
28
- declare const Calendar: React.ForwardRefExoticComponent<CalendarProps & React.RefAttributes<unknown>>;
23
+ declare const Calendar: ({ locale, startOfWeek, displayedDate, todayAriaLabel, selectedDate, isDateEnabled, onChangeMonth, onSelectDate, previousMonthLabel, nextMonthLabel, }: CalendarProps) => JSX.Element;
29
24
  export default Calendar;
30
25
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/date-picker/calendar/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAI3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAEnE,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAa,EAAE,yBAAyB,EAAE,MAAM,QAAQ,CAAC;AAKzD,MAAM,WAAW,iBAAiB;IAChC,CAAC,MAAM,EAAE,aAAa,CAAC,UAAU,GAAG,IAAI,CAAC;CAC1C;AAED,MAAM,WAAW,kBAAkB;IACjC,CAAC,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAC;CACxB;AAED,oBAAY,QAAQ,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAMjD,UAAU,aAAc,SAAQ,kBAAkB;IAChD,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,QAAQ,CAAC;IACtB,YAAY,EAAE,IAAI,GAAG,IAAI,CAAC;IAC1B,aAAa,EAAE,IAAI,CAAC;IACpB,WAAW,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IAC1B,aAAa,EAAE,eAAe,CAAC,qBAAqB,CAAC;IACrD,gBAAgB,EAAE,OAAO,CAAC;IAC1B,cAAc,EAAE,MAAM,CAAC;IACvB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,cAAc,EAAE,MAAM,CAAC;IAEvB,aAAa,EAAE,kBAAkB,CAAC;IAClC,YAAY,EAAE,iBAAiB,CAAC;IAChC,WAAW,EAAE,yBAAyB,CAAC;CACxC;AAED,QAAA,MAAM,QAAQ,+EAkIb,CAAC;AAEF,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/date-picker/calendar/index.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAEnE,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAO9C,MAAM,WAAW,iBAAiB;IAChC,CAAC,MAAM,EAAE,aAAa,CAAC,UAAU,GAAG,IAAI,CAAC;CAC1C;AAED,MAAM,WAAW,kBAAkB;IACjC,CAAC,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAC;CACxB;AAED,oBAAY,QAAQ,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAMjD,UAAU,aAAc,SAAQ,kBAAkB;IAChD,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,QAAQ,CAAC;IACtB,YAAY,EAAE,IAAI,GAAG,IAAI,CAAC;IAC1B,aAAa,EAAE,IAAI,CAAC;IACpB,aAAa,EAAE,eAAe,CAAC,qBAAqB,CAAC;IACrD,cAAc,EAAE,MAAM,CAAC;IACvB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,cAAc,EAAE,MAAM,CAAC;IAEvB,aAAa,EAAE,kBAAkB,CAAC;IAClC,YAAY,EAAE,iBAAiB,CAAC;CACjC;AAED,QAAA,MAAM,QAAQ,0JAWX,aAAa,gBAgIf,CAAC;AAEF,eAAe,QAAQ,CAAC"}
@@ -9,15 +9,16 @@ import CalendarHeader from './header';
9
9
  import Grid from './grid';
10
10
  import moveFocusHandler from './utils/move-focus-handler';
11
11
  import { useUniqueId } from '../../internal/hooks/use-unique-id/index.js';
12
- import { useMergeRefs } from '../../internal/hooks/use-merge-refs/index.js';
13
- var Calendar = React.forwardRef(function (_a, ref) {
14
- var locale = _a.locale, startOfWeek = _a.startOfWeek, displayedDate = _a.displayedDate, _b = _a.focusedDate, focusedDate = _b === void 0 ? null : _b, todayAriaLabel = _a.todayAriaLabel, calendarHasFocus = _a.calendarHasFocus, selectedDate = _a.selectedDate, isDateEnabled = _a.isDateEnabled, onChangeMonth = _a.onChangeMonth, onSelectDate = _a.onSelectDate, onFocusDate = _a.onFocusDate, previousMonthLabel = _a.previousMonthLabel, nextMonthLabel = _a.nextMonthLabel;
12
+ import { formatDate, memoizedDate } from './utils/date.js';
13
+ var Calendar = function (_a) {
14
+ var locale = _a.locale, startOfWeek = _a.startOfWeek, displayedDate = _a.displayedDate, todayAriaLabel = _a.todayAriaLabel, selectedDate = _a.selectedDate, isDateEnabled = _a.isDateEnabled, onChangeMonth = _a.onChangeMonth, onSelectDate = _a.onSelectDate, previousMonthLabel = _a.previousMonthLabel, nextMonthLabel = _a.nextMonthLabel;
15
15
  var focusVisible = useFocusVisible();
16
16
  var headerId = useUniqueId('calendar-dialog-title-');
17
17
  var elementRef = useRef(null);
18
- var calendarRef = useMergeRefs(elementRef, ref);
19
18
  var gridWrapperRef = useRef(null);
20
- var _c = useState(false), gridHasFocus = _c[0], setGridHasFocus = _c[1];
19
+ var _b = useState(false), gridHasFocus = _b[0], setGridHasFocus = _b[1];
20
+ var _c = useState(null), focusedDate = _c[0], setFocusedDate = _c[1];
21
+ var focusedDateMemoized = memoizedDate('focused', focusedDate);
21
22
  var selectFocusedDate = function (selected, baseDate) {
22
23
  if (selected && isDateEnabled(selected) && isSameMonth(selected, baseDate)) {
23
24
  return selected;
@@ -41,25 +42,40 @@ var Calendar = React.forwardRef(function (_a, ref) {
41
42
  var baseDate = getBaseDate(displayedDate);
42
43
  var focusCurrentDate = function () { var _a, _b; return (_b = (_a = elementRef.current) === null || _a === void 0 ? void 0 : _a.querySelector(".".concat(styles['calendar-day-focusable']))) === null || _b === void 0 ? void 0 : _b.focus(); };
43
44
  var onHeaderChangeMonthHandler = function (isPrevious) {
44
- return onChangeMonth(addMonths(baseDate, isPrevious ? -1 : 1));
45
+ onChangeMonth(addMonths(baseDate, isPrevious ? -1 : 1));
46
+ setFocusedDate(null);
47
+ };
48
+ var onGridChangeMonthHandler = function (newMonth) {
49
+ onChangeMonth(newMonth);
50
+ setFocusedDate(null);
51
+ };
52
+ var onGridFocusDateHandler = function (_a) {
53
+ var date = _a.date;
54
+ if (date) {
55
+ var value = formatDate(date);
56
+ setFocusedDate(value);
57
+ }
58
+ };
59
+ var onGridSelectDateHandler = function (detail) {
60
+ onSelectDate(detail);
61
+ setFocusedDate(null);
45
62
  };
46
63
  useEffect(function () {
47
64
  // focus current date if the focus is already inside the calendar grid
48
- if (focusedDate instanceof Date && isSameMonth(focusedDate, baseDate) && gridHasFocus) {
65
+ if (focusedDateMemoized instanceof Date && isSameMonth(focusedDateMemoized, baseDate) && gridHasFocus) {
49
66
  focusCurrentDate();
50
67
  }
51
- }, [baseDate, focusedDate, gridHasFocus]);
68
+ }, [baseDate, focusedDateMemoized, gridHasFocus]);
52
69
  useEffect(function () {
53
70
  var _a, _b;
54
- var calendarShouldHaveFocus = calendarHasFocus;
55
- var calendarActuallyHasFocus = (_a = elementRef.current) === null || _a === void 0 ? void 0 : _a.contains(document.activeElement);
56
- if (calendarShouldHaveFocus && !calendarActuallyHasFocus) {
71
+ var calendarHasFocus = (_a = elementRef.current) === null || _a === void 0 ? void 0 : _a.contains(document.activeElement);
72
+ if (!calendarHasFocus) {
57
73
  (_b = elementRef.current) === null || _b === void 0 ? void 0 : _b.focus();
58
74
  }
59
75
  // When the baseDate or isDateEnabled changes, there might not be a focusable date in the grid anymore
60
- }, [calendarHasFocus, baseDate, isDateEnabled]);
61
- if (calendarHasFocus && !focusedDate) {
62
- focusedDate = selectFocusedDate(selectedDate, baseDate);
76
+ }, [baseDate, isDateEnabled]);
77
+ if (!focusedDate) {
78
+ focusedDateMemoized = selectFocusedDate(selectedDate, baseDate);
63
79
  }
64
80
  var onGridBlur = function (event) {
65
81
  var _a;
@@ -73,11 +89,11 @@ var Calendar = React.forwardRef(function (_a, ref) {
73
89
  setGridHasFocus(true);
74
90
  }
75
91
  };
76
- return (React.createElement("div", __assign({}, focusVisible, { className: styles.calendar, tabIndex: 0, role: "application", "aria-describedby": headerId, ref: calendarRef }),
92
+ return (React.createElement("div", __assign({}, focusVisible, { className: styles.calendar, tabIndex: 0, role: "application", "aria-describedby": headerId, ref: elementRef }),
77
93
  React.createElement("div", { className: styles['calendar-inner'] },
78
- React.createElement(CalendarHeader, { headerId: headerId, baseDate: baseDate, locale: locale, onChangeMonth: onHeaderChangeMonthHandler, previousMonthLabel: previousMonthLabel, nextMonthLabel: nextMonthLabel, calendarHasFocus: calendarHasFocus }),
94
+ React.createElement(CalendarHeader, { headerId: headerId, baseDate: baseDate, locale: locale, onChangeMonth: onHeaderChangeMonthHandler, previousMonthLabel: previousMonthLabel, nextMonthLabel: nextMonthLabel }),
79
95
  React.createElement("div", { onBlur: onGridBlur, onFocus: onGridFocus, ref: gridWrapperRef },
80
- React.createElement(Grid, { locale: locale, baseDate: baseDate, isDateEnabled: isDateEnabled, focusedDate: focusedDate, onSelectDate: onSelectDate, onFocusDate: onFocusDate, onChangeMonth: onChangeMonth, startOfWeek: startOfWeek, todayAriaLabel: todayAriaLabel, selectedDate: selectedDate, handleFocusMove: moveFocusHandler })))));
81
- });
96
+ React.createElement(Grid, { locale: locale, baseDate: baseDate, isDateEnabled: isDateEnabled, focusedDate: focusedDateMemoized, onSelectDate: onGridSelectDateHandler, onFocusDate: onGridFocusDateHandler, onChangeMonth: onGridChangeMonthHandler, startOfWeek: startOfWeek, todayAriaLabel: todayAriaLabel, selectedDate: selectedDate, handleFocusMove: moveFocusHandler })))));
97
+ };
82
98
  export default Calendar;
83
99
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/date-picker/calendar/index.tsx"],"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gBAAgB,CAAC;YACtC,oBAAC,cAAc,IACb,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,0BAA0B,EACzC,kBAAkB,EAAE,kBAAkB,EACtC,cAAc,EAAE,cAAc,EAC9B,gBAAgB,EAAE,gBAAgB,GAClC;YACF,6BAAK,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,cAAc;gBAChE,oBAAC,IAAI,IACH,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,EAClB,aAAa,EAAE,aAAa,EAC5B,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,YAAY,EAC1B,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,aAAa,EAC5B,WAAW,EAAE,WAAW,EACxB,cAAc,EAAE,cAAc,EAC9B,YAAY,EAAE,YAAY,EAC1B,eAAe,EAAE,gBAAgB,GACjC,CACE,CACF,CACF,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,QAAQ,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 { addDays, addMonths, isSameMonth, startOfMonth } from 'date-fns';\nimport styles from '../styles.css.js';\nimport { FocusNextElement } from '../../internal/components/tab-trap';\nimport { BaseComponentProps } from '../../internal/base-component';\nimport useFocusVisible from '../../internal/hooks/focus-visible/index.js';\nimport { DatePickerProps } from '../interfaces';\nimport { CalendarTypes } from './definitions';\nimport CalendarHeader from './header';\nimport Grid, { DateChangeHandlerNullable } from './grid';\nimport moveFocusHandler from './utils/move-focus-handler';\nimport { useUniqueId } from '../../internal/hooks/use-unique-id/index.js';\nimport { useMergeRefs } from '../../internal/hooks/use-merge-refs/index.js';\n\nexport interface DateChangeHandler {\n (detail: CalendarTypes.DateDetail): void;\n}\n\nexport interface MonthChangeHandler {\n (newMonth: Date): void;\n}\n\nexport type DayIndex = 0 | 1 | 2 | 3 | 4 | 5 | 6;\n\ninterface HeaderChangeMonthHandler {\n (isPreviousButtonClick?: boolean): void;\n}\n\ninterface CalendarProps extends BaseComponentProps {\n locale: string;\n startOfWeek: DayIndex;\n selectedDate: Date | null;\n displayedDate: Date;\n focusedDate?: Date | null;\n isDateEnabled: DatePickerProps.IsDateEnabledFunction;\n calendarHasFocus: boolean;\n nextMonthLabel: string;\n previousMonthLabel: string;\n todayAriaLabel: string;\n\n onChangeMonth: MonthChangeHandler;\n onSelectDate: DateChangeHandler;\n onFocusDate: DateChangeHandlerNullable;\n}\n\nconst Calendar = React.forwardRef(\n (\n {\n locale,\n startOfWeek,\n displayedDate,\n focusedDate = null,\n todayAriaLabel,\n calendarHasFocus,\n selectedDate,\n isDateEnabled,\n onChangeMonth,\n onSelectDate,\n onFocusDate,\n previousMonthLabel,\n nextMonthLabel,\n }: CalendarProps,\n ref\n ) => {\n const focusVisible = useFocusVisible();\n const headerId = useUniqueId('calendar-dialog-title-');\n const elementRef = useRef<HTMLDivElement>(null);\n const calendarRef = useMergeRefs(elementRef, ref);\n const gridWrapperRef = useRef<HTMLDivElement>(null);\n const [gridHasFocus, setGridHasFocus] = useState(false);\n\n const selectFocusedDate = (selected: Date | null, baseDate: Date): Date | null => {\n if (selected && isDateEnabled(selected) && isSameMonth(selected, baseDate)) {\n return selected;\n }\n const today = new Date();\n if (isDateEnabled(today) && isSameMonth(today, baseDate)) {\n return today;\n }\n if (isDateEnabled(baseDate)) {\n return baseDate;\n }\n return null;\n };\n\n const getBaseDate = (date: Date) => {\n const startDate = startOfMonth(date);\n if (isDateEnabled(startDate)) {\n return startDate;\n }\n return moveFocusHandler(startDate, isDateEnabled, (date: Date) => addDays(date, 1));\n };\n\n const baseDate: Date = getBaseDate(displayedDate);\n\n const focusCurrentDate: FocusNextElement = () =>\n (elementRef.current?.querySelector(`.${styles['calendar-day-focusable']}`) as HTMLDivElement)?.focus();\n\n const onHeaderChangeMonthHandler: HeaderChangeMonthHandler = isPrevious =>\n onChangeMonth(addMonths(baseDate, isPrevious ? -1 : 1));\n\n useEffect(() => {\n // focus current date if the focus is already inside the calendar grid\n if (focusedDate instanceof Date && isSameMonth(focusedDate, baseDate) && gridHasFocus) {\n focusCurrentDate();\n }\n }, [baseDate, focusedDate, gridHasFocus]);\n\n useEffect(() => {\n const calendarShouldHaveFocus = calendarHasFocus;\n const calendarActuallyHasFocus = elementRef.current?.contains(document.activeElement);\n\n if (calendarShouldHaveFocus && !calendarActuallyHasFocus) {\n elementRef.current?.focus();\n }\n\n // When the baseDate or isDateEnabled changes, there might not be a focusable date in the grid anymore\n }, [calendarHasFocus, baseDate, isDateEnabled]);\n\n if (calendarHasFocus && !focusedDate) {\n focusedDate = selectFocusedDate(selectedDate, baseDate);\n }\n\n const onGridBlur = (event: React.FocusEvent) => {\n const newFocusTargetIsInGrid =\n event.relatedTarget && gridWrapperRef.current?.contains(event.relatedTarget as Node);\n if (!newFocusTargetIsInGrid) {\n setGridHasFocus(false);\n }\n };\n\n const onGridFocus = () => {\n if (!gridHasFocus) {\n setGridHasFocus(true);\n }\n };\n\n return (\n <div\n {...focusVisible}\n className={styles.calendar}\n tabIndex={0}\n role=\"application\"\n aria-describedby={headerId}\n ref={calendarRef}\n >\n <div className={styles['calendar-inner']}>\n <CalendarHeader\n headerId={headerId}\n baseDate={baseDate}\n locale={locale}\n onChangeMonth={onHeaderChangeMonthHandler}\n previousMonthLabel={previousMonthLabel}\n nextMonthLabel={nextMonthLabel}\n calendarHasFocus={calendarHasFocus}\n />\n <div onBlur={onGridBlur} onFocus={onGridFocus} ref={gridWrapperRef}>\n <Grid\n locale={locale}\n baseDate={baseDate}\n isDateEnabled={isDateEnabled}\n focusedDate={focusedDate}\n onSelectDate={onSelectDate}\n onFocusDate={onFocusDate}\n onChangeMonth={onChangeMonth}\n startOfWeek={startOfWeek}\n todayAriaLabel={todayAriaLabel}\n selectedDate={selectedDate}\n handleFocusMove={moveFocusHandler}\n />\n </div>\n </div>\n </div>\n );\n }\n);\n\nexport default Calendar;\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/date-picker/calendar/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,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACzE,OAAO,MAAM,MAAM,kBAAkB,CAAC;AAGtC,OAAO,eAAe,MAAM,6CAA6C,CAAC;AAG1E,OAAO,cAAc,MAAM,UAAU,CAAC;AACtC,OAAO,IAAmC,MAAM,QAAQ,CAAC;AACzD,OAAO,gBAAgB,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,6CAA6C,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AA8B3D,IAAM,QAAQ,GAAG,UAAC,EAWF;QAVd,MAAM,YAAA,EACN,WAAW,iBAAA,EACX,aAAa,mBAAA,EACb,cAAc,oBAAA,EACd,YAAY,kBAAA,EACZ,aAAa,mBAAA,EACb,aAAa,mBAAA,EACb,YAAY,kBAAA,EACZ,kBAAkB,wBAAA,EAClB,cAAc,oBAAA;IAEd,IAAM,YAAY,GAAG,eAAe,EAAE,CAAC;IACvC,IAAM,QAAQ,GAAG,WAAW,CAAC,wBAAwB,CAAC,CAAC;IACvD,IAAM,UAAU,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAChD,IAAM,cAAc,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAC9C,IAAA,KAAkC,QAAQ,CAAC,KAAK,CAAC,EAAhD,YAAY,QAAA,EAAE,eAAe,QAAmB,CAAC;IAClD,IAAA,KAAgC,QAAQ,CAAgB,IAAI,CAAC,E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// SPDX-License-Identifier: Apache-2.0\nimport React, { useEffect, useRef, useState } from 'react';\nimport { addDays, addMonths, isSameMonth, startOfMonth } from 'date-fns';\nimport styles from '../styles.css.js';\nimport { FocusNextElement } from '../../internal/components/tab-trap';\nimport { BaseComponentProps } from '../../internal/base-component';\nimport useFocusVisible from '../../internal/hooks/focus-visible/index.js';\nimport { DatePickerProps } from '../interfaces';\nimport { CalendarTypes } from './definitions';\nimport CalendarHeader from './header';\nimport Grid, { DateChangeHandlerNullable } from './grid';\nimport moveFocusHandler from './utils/move-focus-handler';\nimport { useUniqueId } from '../../internal/hooks/use-unique-id/index.js';\nimport { formatDate, memoizedDate } from './utils/date.js';\n\nexport interface DateChangeHandler {\n (detail: CalendarTypes.DateDetail): void;\n}\n\nexport interface MonthChangeHandler {\n (newMonth: Date): void;\n}\n\nexport type DayIndex = 0 | 1 | 2 | 3 | 4 | 5 | 6;\n\ninterface HeaderChangeMonthHandler {\n (isPreviousButtonClick?: boolean): void;\n}\n\ninterface CalendarProps extends BaseComponentProps {\n locale: string;\n startOfWeek: DayIndex;\n selectedDate: Date | null;\n displayedDate: Date;\n isDateEnabled: DatePickerProps.IsDateEnabledFunction;\n nextMonthLabel: string;\n previousMonthLabel: string;\n todayAriaLabel: string;\n\n onChangeMonth: MonthChangeHandler;\n onSelectDate: DateChangeHandler;\n}\n\nconst Calendar = ({\n locale,\n startOfWeek,\n displayedDate,\n todayAriaLabel,\n selectedDate,\n isDateEnabled,\n onChangeMonth,\n onSelectDate,\n previousMonthLabel,\n nextMonthLabel,\n}: CalendarProps) => {\n const focusVisible = useFocusVisible();\n const headerId = useUniqueId('calendar-dialog-title-');\n const elementRef = useRef<HTMLDivElement>(null);\n const gridWrapperRef = useRef<HTMLDivElement>(null);\n const [gridHasFocus, setGridHasFocus] = useState(false);\n const [focusedDate, setFocusedDate] = useState<string | null>(null);\n let focusedDateMemoized: null | Date = memoizedDate('focused', focusedDate);\n\n const selectFocusedDate = (selected: Date | null, baseDate: Date): Date | null => {\n if (selected && isDateEnabled(selected) && isSameMonth(selected, baseDate)) {\n return selected;\n }\n const today = new Date();\n if (isDateEnabled(today) && isSameMonth(today, baseDate)) {\n return today;\n }\n if (isDateEnabled(baseDate)) {\n return baseDate;\n }\n return null;\n };\n\n const getBaseDate = (date: Date) => {\n const startDate = startOfMonth(date);\n if (isDateEnabled(startDate)) {\n return startDate;\n }\n return moveFocusHandler(startDate, isDateEnabled, (date: Date) => addDays(date, 1));\n };\n\n const baseDate: Date = getBaseDate(displayedDate);\n\n const focusCurrentDate: FocusNextElement = () =>\n (elementRef.current?.querySelector(`.${styles['calendar-day-focusable']}`) as HTMLDivElement)?.focus();\n\n const onHeaderChangeMonthHandler: HeaderChangeMonthHandler = isPrevious => {\n onChangeMonth(addMonths(baseDate, isPrevious ? -1 : 1));\n setFocusedDate(null);\n };\n\n const onGridChangeMonthHandler: MonthChangeHandler = newMonth => {\n onChangeMonth(newMonth);\n setFocusedDate(null);\n };\n\n const onGridFocusDateHandler: DateChangeHandlerNullable = ({ date }) => {\n if (date) {\n const value = formatDate(date);\n setFocusedDate(value);\n }\n };\n\n const onGridSelectDateHandler: DateChangeHandler = detail => {\n onSelectDate(detail);\n setFocusedDate(null);\n };\n\n useEffect(() => {\n // focus current date if the focus is already inside the calendar grid\n if (focusedDateMemoized instanceof Date && isSameMonth(focusedDateMemoized, baseDate) && gridHasFocus) {\n focusCurrentDate();\n }\n }, [baseDate, focusedDateMemoized, gridHasFocus]);\n\n useEffect(() => {\n const calendarHasFocus = elementRef.current?.contains(document.activeElement);\n\n if (!calendarHasFocus) {\n elementRef.current?.focus();\n }\n\n // When the baseDate or isDateEnabled changes, there might not be a focusable date in the grid anymore\n }, [baseDate, isDateEnabled]);\n\n if (!focusedDate) {\n focusedDateMemoized = selectFocusedDate(selectedDate, baseDate);\n }\n\n const onGridBlur = (event: React.FocusEvent) => {\n const newFocusTargetIsInGrid = event.relatedTarget && gridWrapperRef.current?.contains(event.relatedTarget as Node);\n if (!newFocusTargetIsInGrid) {\n setGridHasFocus(false);\n }\n };\n\n const onGridFocus = () => {\n if (!gridHasFocus) {\n setGridHasFocus(true);\n }\n };\n\n return (\n <div\n {...focusVisible}\n className={styles.calendar}\n tabIndex={0}\n role=\"application\"\n aria-describedby={headerId}\n ref={elementRef}\n >\n <div className={styles['calendar-inner']}>\n <CalendarHeader\n headerId={headerId}\n baseDate={baseDate}\n locale={locale}\n onChangeMonth={onHeaderChangeMonthHandler}\n previousMonthLabel={previousMonthLabel}\n nextMonthLabel={nextMonthLabel}\n />\n <div onBlur={onGridBlur} onFocus={onGridFocus} ref={gridWrapperRef}>\n <Grid\n locale={locale}\n baseDate={baseDate}\n isDateEnabled={isDateEnabled}\n focusedDate={focusedDateMemoized}\n onSelectDate={onGridSelectDateHandler}\n onFocusDate={onGridFocusDateHandler}\n onChangeMonth={onGridChangeMonthHandler}\n startOfWeek={startOfWeek}\n todayAriaLabel={todayAriaLabel}\n selectedDate={selectedDate}\n handleFocusMove={moveFocusHandler}\n />\n </div>\n </div>\n </div>\n );\n};\n\nexport default Calendar;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/date-picker/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAA6C,MAAM,OAAO,CAAC;AAGlE,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAwB/C,OAAO,EAAE,eAAe,EAAE,CAAC;AAE3B,QAAA,MAAM,UAAU,6FAmOf,CAAC;AAGF,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/date-picker/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAA6C,MAAM,OAAO,CAAC;AAGlE,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAwB/C,OAAO,EAAE,eAAe,EAAE,CAAC;AAE3B,QAAA,MAAM,UAAU,6FA2Mf,CAAC;AAGF,eAAe,UAAU,CAAC"}
@@ -23,23 +23,20 @@ import { InternalButton } from '../button/internal';
23
23
  import useBaseComponent from '../internal/hooks/use-base-component';
24
24
  import { useUniqueId } from '../internal/hooks/use-unique-id';
25
25
  import { useMergeRefs } from '../internal/hooks/use-merge-refs';
26
- import TabTrap from '../internal/components/tab-trap';
26
+ import FocusLock from '../internal/components/focus-lock';
27
27
  var DatePicker = React.forwardRef(function (_a, ref) {
28
28
  var _b = _a.locale, locale = _b === void 0 ? '' : _b, startOfWeek = _a.startOfWeek, isDateEnabled = _a.isDateEnabled, nextMonthAriaLabel = _a.nextMonthAriaLabel, previousMonthAriaLabel = _a.previousMonthAriaLabel, todayAriaLabel = _a.todayAriaLabel, _c = _a.placeholder, placeholder = _c === void 0 ? '' : _c, _d = _a.value, value = _d === void 0 ? '' : _d, _e = _a.readOnly, readOnly = _e === void 0 ? false : _e, _f = _a.disabled, disabled = _f === void 0 ? false : _f, onBlur = _a.onBlur, _g = _a.autoFocus, autoFocus = _g === void 0 ? false : _g, onChange = _a.onChange, onFocus = _a.onFocus, name = _a.name, ariaLabel = _a.ariaLabel, ariaRequired = _a.ariaRequired, ariaLabelledby = _a.ariaLabelledby, ariaDescribedby = _a.ariaDescribedby, controlId = _a.controlId, invalid = _a.invalid, openCalendarAriaLabel = _a.openCalendarAriaLabel, expandToViewport = _a.expandToViewport, rest = __rest(_a, ["locale", "startOfWeek", "isDateEnabled", "nextMonthAriaLabel", "previousMonthAriaLabel", "todayAriaLabel", "placeholder", "value", "readOnly", "disabled", "onBlur", "autoFocus", "onChange", "onFocus", "name", "ariaLabel", "ariaRequired", "ariaLabelledby", "ariaDescribedby", "controlId", "invalid", "openCalendarAriaLabel", "expandToViewport"]);
29
29
  var __internalRootRef = useBaseComponent('DatePicker').__internalRootRef;
30
30
  var baseProps = getBaseProps(rest);
31
31
  var _h = useState(false), isDropDownOpen = _h[0], setIsDropDownOpen = _h[1];
32
- var _j = useState(false), calendarHasFocus = _j[0], setCalendarHasFocus = _j[1];
33
32
  var normalizedLocale = normalizeLocale('DatePicker', locale !== null && locale !== void 0 ? locale : '');
34
33
  var normalizedStartOfWeek = (typeof startOfWeek === 'number' ? startOfWeek : getWeekStartByLocale(normalizedLocale));
35
34
  var defaultSelectedDate = value.length >= 10 ? value : null;
36
- var _k = useState(defaultSelectedDate), selectedDate = _k[0], setSelectedDate = _k[1];
35
+ var _j = useState(defaultSelectedDate), selectedDate = _j[0], setSelectedDate = _j[1];
37
36
  var defaultDisplayedDate = value.length >= 10 ? value : formatDate(new Date());
38
- var _l = useState(defaultDisplayedDate), displayedDate = _l[0], setDisplayedDate = _l[1];
39
- var _m = useState(null), focusedDate = _m[0], setFocusedDate = _m[1];
37
+ var _k = useState(defaultDisplayedDate), displayedDate = _k[0], setDisplayedDate = _k[1];
40
38
  var internalInputRef = useRef(null);
41
39
  var buttonRef = useRef(null);
42
- var calendarRef = useRef(null);
43
40
  useForwardFocus(ref, internalInputRef);
44
41
  var rootRef = useRef(null);
45
42
  var dropdownId = useUniqueId('calender');
@@ -47,7 +44,6 @@ var DatePicker = React.forwardRef(function (_a, ref) {
47
44
  useFocusTracker({ rootRef: rootRef, onBlur: onBlur, onFocus: onFocus, viewportId: expandToViewport ? dropdownId : '' });
48
45
  var onChangeMonthHandler = function (newMonth) {
49
46
  setDisplayedDate(formatDate(newMonth));
50
- setFocusedDate(null);
51
47
  };
52
48
  var onSelectDateHandler = function (_a) {
53
49
  var _b;
@@ -57,26 +53,15 @@ var DatePicker = React.forwardRef(function (_a, ref) {
57
53
  setIsDropDownOpen(false);
58
54
  setSelectedDate(formattedDate);
59
55
  setDisplayedDate(formattedDate);
60
- setCalendarHasFocus(false);
61
- setFocusedDate(null);
62
56
  fireNonCancelableEvent(onChange, { value: formattedDate });
63
57
  };
64
- var onDateFocusHandler = function (_a) {
65
- var date = _a.date;
66
- if (date) {
67
- var value_1 = formatDate(date);
68
- setFocusedDate(value_1);
69
- }
70
- };
71
58
  var onDropdownCloseHandler = useCallback(function () {
72
59
  setDisplayedDate(defaultDisplayedDate);
73
- setCalendarHasFocus(false);
74
60
  setIsDropDownOpen(false);
75
61
  }, [defaultDisplayedDate]);
76
62
  var onButtonClickHandler = function () {
77
63
  if (!isDropDownOpen) {
78
64
  setIsDropDownOpen(true);
79
- setCalendarHasFocus(true);
80
65
  }
81
66
  };
82
67
  var onWrapperKeyDownHandler = function (event) {
@@ -91,7 +76,7 @@ var DatePicker = React.forwardRef(function (_a, ref) {
91
76
  fireNonCancelableEvent(onChange, { value: isoDateString });
92
77
  };
93
78
  var onInputBlurHandler = function () {
94
- if (!calendarHasFocus) {
79
+ if (!isDropDownOpen) {
95
80
  setDisplayedDate(defaultDisplayedDate);
96
81
  setIsDropDownOpen(false);
97
82
  }
@@ -111,10 +96,9 @@ var DatePicker = React.forwardRef(function (_a, ref) {
111
96
  setSelectedDate(value);
112
97
  }
113
98
  }
114
- var focusCurrentDate = function () { var _a, _b; return (_b = (_a = calendarRef.current) === null || _a === void 0 ? void 0 : _a.querySelector(".".concat(styles['calendar-day-focusable']))) === null || _b === void 0 ? void 0 : _b.focus(); };
115
99
  var DateInputElement = (React.createElement("div", { className: styles['date-picker-trigger'] },
116
100
  React.createElement("div", { className: styles['date-picker-input'] },
117
- React.createElement(DateInput, { name: name, invalid: invalid, controlId: controlId, ariaLabelledby: ariaLabelledby, ariaDescribedby: ariaDescribedby, ariaLabel: ariaLabel, ariaRequired: ariaRequired, value: isoToDisplay(value), autoComplete: false, disableBrowserAutocorrect: true, disableAutocompleteOnBlur: calendarHasFocus, disabled: disabled, readOnly: readOnly, onChange: onInputChangeHandler, onBlur: onInputBlurHandler, placeholder: placeholder, ref: internalInputRef, autoFocus: autoFocus })),
101
+ React.createElement(DateInput, { name: name, invalid: invalid, controlId: controlId, ariaLabelledby: ariaLabelledby, ariaDescribedby: ariaDescribedby, ariaLabel: ariaLabel, ariaRequired: ariaRequired, value: isoToDisplay(value), autoComplete: false, disableBrowserAutocorrect: true, disableAutocompleteOnBlur: isDropDownOpen, disabled: disabled, readOnly: readOnly, onChange: onInputChangeHandler, onBlur: onInputBlurHandler, placeholder: placeholder, ref: internalInputRef, autoFocus: autoFocus })),
118
102
  React.createElement("div", null,
119
103
  React.createElement(InternalButton, { iconName: "calendar", className: styles['open-calendar-button'], onClick: onButtonClickHandler, ref: buttonRef, ariaLabel: openCalendarAriaLabel &&
120
104
  openCalendarAriaLabel(value.length === 10 ? getDateLabel(normalizedLocale, memoizedDate('value', value)) : null), disabled: disabled || readOnly, formAction: "none" }))));
@@ -128,10 +112,8 @@ var DatePicker = React.forwardRef(function (_a, ref) {
128
112
  event.preventDefault();
129
113
  };
130
114
  return (React.createElement("div", __assign({}, baseProps, { ref: mergedRef, onKeyDown: onWrapperKeyDownHandler }),
131
- React.createElement(Dropdown, { stretchWidth: true, stretchHeight: true, open: isDropDownOpen, onDropdownClose: onDropdownCloseHandler, onMouseDown: handleMouseDown, trigger: DateInputElement, expandToViewport: expandToViewport, scrollable: false, dropdownId: dropdownId }, isDropDownOpen && (React.createElement(React.Fragment, null,
132
- calendarHasFocus && React.createElement(TabTrap, { focusNextCallback: focusCurrentDate }),
133
- React.createElement(Calendar, { ref: calendarRef, selectedDate: memoizedDate('value', selectedDate), focusedDate: memoizedDate('focused', focusedDate), displayedDate: memoizedDate('displayed', displayedDate), locale: normalizedLocale, startOfWeek: normalizedStartOfWeek, isDateEnabled: isDateEnabled ? isDateEnabled : function () { return true; }, calendarHasFocus: calendarHasFocus, nextMonthLabel: nextMonthAriaLabel, previousMonthLabel: previousMonthAriaLabel, todayAriaLabel: todayAriaLabel, onChangeMonth: onChangeMonthHandler, onSelectDate: onSelectDateHandler, onFocusDate: onDateFocusHandler }),
134
- calendarHasFocus && React.createElement(TabTrap, { focusNextCallback: function () { var _a; return (_a = calendarRef.current) === null || _a === void 0 ? void 0 : _a.focus(); } }))))));
115
+ React.createElement(Dropdown, { stretchWidth: true, stretchHeight: true, open: isDropDownOpen, onDropdownClose: onDropdownCloseHandler, onMouseDown: handleMouseDown, trigger: DateInputElement, expandToViewport: expandToViewport, scrollable: false, dropdownId: dropdownId }, isDropDownOpen && (React.createElement(FocusLock, null,
116
+ React.createElement(Calendar, { selectedDate: memoizedDate('value', selectedDate), displayedDate: memoizedDate('displayed', displayedDate), locale: normalizedLocale, startOfWeek: normalizedStartOfWeek, isDateEnabled: isDateEnabled ? isDateEnabled : function () { return true; }, nextMonthLabel: nextMonthAriaLabel, previousMonthLabel: previousMonthAriaLabel, todayAriaLabel: todayAriaLabel, onChangeMonth: onChangeMonthHandler, onSelectDate: onSelectDateHandler }))))));
135
117
  });
136
118
  applyDisplayName(DatePicker, 'DatePicker');
137
119
  export default DatePicker;