@cloudscape-design/components 3.0.1381 → 3.0.1383
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/button-dropdown/interfaces.d.ts +5 -0
- package/button-dropdown/interfaces.d.ts.map +1 -1
- package/button-dropdown/interfaces.js.map +1 -1
- package/button-dropdown/internal-interfaces.d.ts +1 -1
- package/button-dropdown/internal-interfaces.d.ts.map +1 -1
- package/button-dropdown/internal-interfaces.js.map +1 -1
- package/button-dropdown/internal.js +2 -2
- package/button-dropdown/internal.js.map +1 -1
- package/button-dropdown/items-list.d.ts +1 -1
- package/button-dropdown/items-list.d.ts.map +1 -1
- package/button-dropdown/items-list.js +2 -2
- package/button-dropdown/items-list.js.map +1 -1
- package/button-dropdown/utils/move-highlight.d.ts +4 -2
- package/button-dropdown/utils/move-highlight.d.ts.map +1 -1
- package/button-dropdown/utils/move-highlight.js +13 -21
- package/button-dropdown/utils/move-highlight.js.map +1 -1
- package/button-dropdown/utils/use-button-dropdown.d.ts +1 -1
- package/button-dropdown/utils/use-button-dropdown.d.ts.map +1 -1
- package/button-dropdown/utils/use-button-dropdown.js +8 -6
- package/button-dropdown/utils/use-button-dropdown.js.map +1 -1
- package/button-dropdown/utils/use-highlighted-menu.d.ts +2 -2
- package/button-dropdown/utils/use-highlighted-menu.d.ts.map +1 -1
- package/button-dropdown/utils/use-highlighted-menu.js +14 -4
- package/button-dropdown/utils/use-highlighted-menu.js.map +1 -1
- package/button-dropdown/utils/utils.d.ts +1 -0
- package/button-dropdown/utils/utils.d.ts.map +1 -1
- package/button-dropdown/utils/utils.js +1 -0
- package/button-dropdown/utils/utils.js.map +1 -1
- package/calendar/interfaces.d.ts +2 -1
- package/calendar/interfaces.d.ts.map +1 -1
- package/calendar/interfaces.js.map +1 -1
- package/calendar/internal.d.ts.map +1 -1
- package/calendar/internal.js +3 -1
- package/calendar/internal.js.map +1 -1
- package/checkbox/internal.d.ts +6 -0
- package/checkbox/internal.d.ts.map +1 -1
- package/checkbox/internal.js +2 -2
- package/checkbox/internal.js.map +1 -1
- package/checkbox/styles.css.js +7 -3
- package/checkbox/styles.scoped.css +72 -16
- package/checkbox/styles.selectors.js +7 -3
- package/date-range-picker/index.d.ts.map +1 -1
- package/date-range-picker/index.js +3 -2
- package/date-range-picker/index.js.map +1 -1
- package/date-range-picker/interfaces.d.ts +2 -1
- package/date-range-picker/interfaces.d.ts.map +1 -1
- package/date-range-picker/interfaces.js.map +1 -1
- package/dialog/index.d.ts +3 -0
- package/dialog/index.d.ts.map +1 -0
- package/dialog/index.js +21 -0
- package/dialog/index.js.map +1 -0
- package/dialog/interfaces.d.ts +40 -0
- package/dialog/interfaces.d.ts.map +1 -0
- package/dialog/interfaces.js +2 -0
- package/dialog/interfaces.js.map +1 -0
- package/dialog/internal.d.ts +13 -0
- package/dialog/internal.d.ts.map +1 -0
- package/dialog/internal.js +39 -0
- package/dialog/internal.js.map +1 -0
- package/dialog/styles.css.js +13 -0
- package/dialog/styles.scoped.css +126 -0
- package/dialog/styles.selectors.js +14 -0
- package/dialog/test-classes/styles.css.js +11 -0
- package/dialog/test-classes/styles.scoped.css +12 -0
- package/dialog/test-classes/styles.selectors.js +12 -0
- package/dialog/use-focus-restore.d.ts +5 -0
- package/dialog/use-focus-restore.d.ts.map +1 -0
- package/dialog/use-focus-restore.js +34 -0
- package/dialog/use-focus-restore.js.map +1 -0
- package/expandable-section/expandable-section-header.d.ts.map +1 -1
- package/expandable-section/expandable-section-header.js +9 -2
- package/expandable-section/expandable-section-header.js.map +1 -1
- package/expandable-section/styles.css.js +44 -43
- package/expandable-section/styles.scoped.css +92 -88
- package/expandable-section/styles.selectors.js +44 -43
- package/i18n/messages/all.all.js +1 -1
- package/i18n/messages/all.all.json +1 -1
- package/i18n/messages/all.de.js +1 -1
- package/i18n/messages/all.de.json +1 -1
- package/i18n/messages/all.en-GB.js +1 -1
- package/i18n/messages/all.en-GB.json +1 -1
- package/i18n/messages/all.en.js +1 -1
- package/i18n/messages/all.en.json +1 -1
- package/i18n/messages/all.es.js +1 -1
- package/i18n/messages/all.es.json +1 -1
- package/i18n/messages/all.fr.js +1 -1
- package/i18n/messages/all.fr.json +1 -1
- package/i18n/messages/all.id.js +1 -1
- package/i18n/messages/all.id.json +1 -1
- package/i18n/messages/all.it.js +1 -1
- package/i18n/messages/all.it.json +1 -1
- package/i18n/messages/all.ja.js +1 -1
- package/i18n/messages/all.ja.json +1 -1
- package/i18n/messages/all.ko.js +1 -1
- package/i18n/messages/all.ko.json +1 -1
- package/i18n/messages/all.pt-BR.js +1 -1
- package/i18n/messages/all.pt-BR.json +1 -1
- package/i18n/messages/all.tr.js +1 -1
- package/i18n/messages/all.tr.json +1 -1
- package/i18n/messages/all.zh-CN.js +1 -1
- package/i18n/messages/all.zh-CN.json +1 -1
- package/i18n/messages/all.zh-TW.js +1 -1
- package/i18n/messages/all.zh-TW.json +1 -1
- package/i18n/messages-types.d.ts +3 -0
- package/i18n/messages-types.d.ts.map +1 -1
- package/i18n/messages-types.js.map +1 -1
- package/icon/internal.d.ts +3 -0
- package/icon/internal.d.ts.map +1 -1
- package/icon/internal.js +10 -2
- package/icon/internal.js.map +1 -1
- package/icon/styles.css.js +43 -42
- package/icon/styles.scoped.css +126 -98
- package/icon/styles.selectors.js +43 -42
- package/icon-provider/context.d.ts +3 -1
- package/icon-provider/context.d.ts.map +1 -1
- package/icon-provider/context.js +2 -0
- package/icon-provider/context.js.map +1 -1
- package/icon-provider/interfaces.d.ts +39 -1
- package/icon-provider/interfaces.d.ts.map +1 -1
- package/icon-provider/interfaces.js.map +1 -1
- package/icon-provider/internal.d.ts +2 -1
- package/icon-provider/internal.d.ts.map +1 -1
- package/icon-provider/internal.js +17 -3
- package/icon-provider/internal.js.map +1 -1
- package/icon-provider/use-component-icons.d.ts +3 -0
- package/icon-provider/use-component-icons.d.ts.map +1 -0
- package/icon-provider/use-component-icons.js +9 -0
- package/icon-provider/use-component-icons.js.map +1 -0
- package/index.d.ts +1 -0
- package/index.d.ts.map +1 -1
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/internal/base-component/styles.scoped.css +1 -1
- package/internal/base-theme/styles.scoped.css +24 -0
- package/internal/components/abstract-switch/index.d.ts +4 -0
- package/internal/components/abstract-switch/index.d.ts.map +1 -1
- package/internal/components/abstract-switch/index.js +5 -3
- package/internal/components/abstract-switch/index.js.map +1 -1
- package/internal/components/checkbox-icon/index.d.ts.map +1 -1
- package/internal/components/checkbox-icon/index.js +8 -2
- package/internal/components/checkbox-icon/index.js.map +1 -1
- package/internal/components/checkbox-icon/styles.css.js +9 -9
- package/internal/components/checkbox-icon/styles.scoped.css +18 -18
- package/internal/components/checkbox-icon/styles.selectors.js +9 -9
- package/internal/components/customizable-icon/index.d.ts +22 -0
- package/internal/components/customizable-icon/index.d.ts.map +1 -0
- package/internal/components/customizable-icon/index.js +12 -0
- package/internal/components/customizable-icon/index.js.map +1 -0
- package/internal/components/expand-toggle-button/index.d.ts +4 -0
- package/internal/components/expand-toggle-button/index.d.ts.map +1 -1
- package/internal/components/expand-toggle-button/index.js +6 -3
- package/internal/components/expand-toggle-button/index.js.map +1 -1
- package/internal/environment.js +2 -2
- package/internal/environment.json +2 -2
- package/internal/generated/styles/tokens.d.ts +11 -0
- package/internal/generated/styles/tokens.js +11 -0
- package/internal/generated/theming/index.cjs +157 -1
- package/internal/generated/theming/index.cjs.d.ts +582 -5
- package/internal/generated/theming/index.d.cts +4308 -0
- package/internal/generated/theming/index.d.ts +99 -0
- package/internal/generated/theming/index.js +157 -1
- package/internal/manifest.json +1 -1
- package/internal/utils/locale/normalize-locale.js +8 -5
- package/internal/utils/locale/normalize-locale.js.map +1 -1
- package/manifest.json +2 -2
- package/package.json +4 -1
- package/split-panel/bottom.d.ts +2 -1
- package/split-panel/bottom.d.ts.map +1 -1
- package/split-panel/bottom.js.map +1 -1
- package/split-panel/content-props.d.ts +16 -0
- package/split-panel/content-props.d.ts.map +1 -0
- package/split-panel/content-props.js +2 -0
- package/split-panel/content-props.js.map +1 -0
- package/split-panel/interfaces.d.ts +0 -13
- package/split-panel/interfaces.d.ts.map +1 -1
- package/split-panel/interfaces.js.map +1 -1
- package/split-panel/side.d.ts +2 -1
- package/split-panel/side.d.ts.map +1 -1
- package/split-panel/side.js.map +1 -1
- package/table/body-cell/td-element.d.ts.map +1 -1
- package/table/body-cell/td-element.js +3 -1
- package/table/body-cell/td-element.js.map +1 -1
- package/table/header-cell/index.d.ts.map +1 -1
- package/table/header-cell/index.js +8 -2
- package/table/header-cell/index.js.map +1 -1
- package/table/internal.js +1 -1
- package/table/internal.js.map +1 -1
- package/test-utils/dom/dialog/index.d.ts +25 -0
- package/test-utils/dom/dialog/index.js +43 -0
- package/test-utils/dom/dialog/index.js.map +1 -0
- package/test-utils/dom/index.d.ts +28 -0
- package/test-utils/dom/index.js +21 -2
- package/test-utils/dom/index.js.map +1 -1
- package/test-utils/selectors/dialog/index.d.ts +25 -0
- package/test-utils/selectors/dialog/index.js +43 -0
- package/test-utils/selectors/dialog/index.js.map +1 -0
- package/test-utils/selectors/index.d.ts +18 -0
- package/test-utils/selectors/index.js +16 -2
- package/test-utils/selectors/index.js.map +1 -1
- package/tree-view/interfaces.d.ts +3 -0
- package/tree-view/interfaces.d.ts.map +1 -1
- package/tree-view/interfaces.js.map +1 -1
- package/tree-view/tree-item/index.d.ts.map +1 -1
- package/tree-view/tree-item/index.js +3 -1
- package/tree-view/tree-item/index.js.map +1 -1
|
@@ -27,7 +27,7 @@ interface UseButtonDropdownApi extends HighlightProps {
|
|
|
27
27
|
filteringValue: string;
|
|
28
28
|
setFilteringValue: (value: string) => void;
|
|
29
29
|
filteredItems: ButtonDropdownProps.Items;
|
|
30
|
-
|
|
30
|
+
isExpandable: (item: ButtonDropdownProps.ItemOrGroup) => boolean;
|
|
31
31
|
}
|
|
32
32
|
export declare function useButtonDropdown({
|
|
33
33
|
items,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-button-dropdown.d.ts","sourceRoot":"","sources":["../../../../src/button-dropdown/utils/use-button-dropdown.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"use-button-dropdown.d.ts","sourceRoot":"","sources":["../../../../src/button-dropdown/utils/use-button-dropdown.ts"],"names":[],"mappings":"AAEA,OAAO,KAA4D,MAAM,OAAO,CAAC;AAOjF,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AACtF,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,WAAW,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAKvH,KAAK,uBAAuB,GAAG,wBAAwB,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,QAAQ,GAAG,eAAe,CAAC,CAAC,CAAC;AAE5G,UAAU,wBAAyB,SAAQ,sBAAsB;IAC/D,KAAK,EAAE,mBAAmB,CAAC,KAAK,CAAC;IACjC,WAAW,CAAC,EAAE,sBAAsB,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,CAAC;IAC3E,YAAY,CAAC,EAAE,sBAAsB,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,CAAC;IAC5E,aAAa,EAAE,MAAM,IAAI,CAAC;IAE1B,gBAAgB,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC;IAChD,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,YAAY,EAAE,OAAO,CAAC;CACvB;AAED,UAAU,oBAAqB,SAAQ,cAAc;IACnD,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,aAAa,KAAK,IAAI,CAAC;IAChD,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,aAAa,KAAK,IAAI,CAAC;IAC9C,cAAc,EAAE,YAAY,CAAC;IAC7B,aAAa,EAAE,WAAW,CAAC;IAC3B,oBAAoB,EAAE,CAAC,KAAK,EAAE,uBAAuB,KAAK,IAAI,CAAC;IAC/D,cAAc,EAAE,MAAM,IAAI,CAAC;IAC3B,cAAc,EAAE,CAAC,OAAO,CAAC,EAAE;QAAE,mBAAmB,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;IACtE,aAAa,EAAE,MAAM,IAAI,CAAC;IAC1B,eAAe,EAAE,CAAC,YAAY,EAAE,OAAO,KAAK,IAAI,CAAC;IACjD,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,aAAa,EAAE,mBAAmB,CAAC,KAAK,CAAC;IACzC,YAAY,EAAE,CAAC,IAAI,EAAE,mBAAmB,CAAC,WAAW,KAAK,OAAO,CAAC;CAClE;AAED,wBAAgB,iBAAiB,CAAC,EAChC,KAAK,EACL,WAAW,EACX,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACnB,kBAA0B,EAC1B,gBAAwB,EACxB,YAAY,GACb,EAAE,wBAAwB,GAAG,oBAAoB,CA4QjD"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
4
4
|
import { useOpenState } from '../../internal/components/options-list/utils/use-open-state';
|
|
5
5
|
import { fireCancelableEvent, isPlainLeftClick } from '../../internal/events';
|
|
6
6
|
import { KeyCode } from '../../internal/keycode';
|
|
@@ -8,14 +8,16 @@ import { isElement } from '../../internal/utils/dom';
|
|
|
8
8
|
import { isKeyboardInteraction } from '../../internal/utils/focus-visible';
|
|
9
9
|
import { filterItems } from './filter-items';
|
|
10
10
|
import useHighlightedMenu from './use-highlighted-menu';
|
|
11
|
-
import { getItemTarget, isCheckboxItem, isItemGroup, isLinkItem } from './utils';
|
|
11
|
+
import { getItemTarget, isCheckboxItem, isGroupExpandable, isItemGroup, isLinkItem } from './utils';
|
|
12
12
|
export function useButtonDropdown({ items, onItemClick, onItemFollow, onReturnFocus, isTriggerElement, hasExpandableGroups, isInRestrictedView = false, expandToViewport = false, hasFiltering, }) {
|
|
13
13
|
const [filteringValue, setFilteringValue] = useState('');
|
|
14
14
|
const filteredItems = useMemo(() => (hasFiltering && filteringValue ? filterItems(items, filteringValue) : items), [hasFiltering, filteringValue, items]);
|
|
15
|
-
|
|
15
|
+
// an active filter flattens every group; otherwise a group's own `expandable` flag wins, falling
|
|
16
|
+
// back to the dropdown-level `expandableGroups` default
|
|
17
|
+
const isExpandable = useCallback((item) => !filteringValue && isGroupExpandable(item, hasExpandableGroups), [filteringValue, hasExpandableGroups]);
|
|
16
18
|
const { targetItem, isHighlighted, isKeyboardHighlight, isExpanded, highlightItem, moveHighlight, expandGroup, collapseGroup, reset, setIsUsingMouse, } = useHighlightedMenu({
|
|
17
19
|
items: filteredItems,
|
|
18
|
-
|
|
20
|
+
isExpandable,
|
|
19
21
|
isInRestrictedView,
|
|
20
22
|
});
|
|
21
23
|
// If the filtering input changes, the options list also changes,
|
|
@@ -182,7 +184,7 @@ export function useButtonDropdown({ items, onItemClick, onItemFollow, onReturnFo
|
|
|
182
184
|
if (targetItem && !targetItem.disabled && isItemGroup(targetItem) && !isExpanded(targetItem)) {
|
|
183
185
|
expandGroup();
|
|
184
186
|
}
|
|
185
|
-
else
|
|
187
|
+
else {
|
|
186
188
|
collapseGroup();
|
|
187
189
|
}
|
|
188
190
|
event.preventDefault();
|
|
@@ -243,7 +245,7 @@ export function useButtonDropdown({ items, onItemClick, onItemFollow, onReturnFo
|
|
|
243
245
|
filteringValue,
|
|
244
246
|
setFilteringValue,
|
|
245
247
|
filteredItems,
|
|
246
|
-
|
|
248
|
+
isExpandable,
|
|
247
249
|
};
|
|
248
250
|
}
|
|
249
251
|
//# sourceMappingURL=use-button-dropdown.js.map
|
|
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ACtC,IAAI,YAAY,EAAE,CAAC;oBACjB,MAAM;gBACR,CAAC;gBACD,gFAAgF;gBAChF,8CAA8C;gBAC9C,IAAI,gBAAgB,EAAE,CAAC;oBACrB,aAAa,EAAE,CAAC;gBAClB,CAAC;gBACD,aAAa,EAAE,CAAC;gBAChB,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC,CAAC;IACF,MAAM,OAAO,GAAG,CAAC,KAA0B,EAAE,EAAE;QAC7C,wFAAwF;QACxF,0FAA0F;QAC1F,oFAAoF;QACpF,2DAA2D;QAC3D,IAAI,KAAK,CAAC,OAAO,KAAK,OAAO,CAAC,KAAK,IAAI,CAAC,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,QAAQ,CAAA,IAAI,CAAC,YAAY,EAAE,CAAC;YAC9E,QAAQ,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,MAAM;QACN,UAAU;QACV,aAAa;QACb,mBAAmB;QACnB,UAAU;QACV,aAAa;QACb,SAAS;QACT,OAAO;QACP,cAAc;QACd,aAAa;QACb,oBAAoB;QACpB,cAAc;QACd,cAAc;QACd,aAAa;QACb,eAAe;QACf,cAAc;QACd,iBAAiB;QACjB,aAAa;QACb,oBAAoB;KACrB,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useEffect, useMemo, useRef, useState } from 'react';\n\nimport { useOpenState } from '../../internal/components/options-list/utils/use-open-state';\nimport { fireCancelableEvent, isPlainLeftClick } from '../../internal/events';\nimport { KeyCode } from '../../internal/keycode';\nimport { isElement } from '../../internal/utils/dom';\nimport { isKeyboardInteraction } from '../../internal/utils/focus-visible';\nimport { CancelableEventHandler, NonCancelableCustomEvent } from '../../types/events';\nimport { ButtonDropdownProps, ButtonDropdownSettings, GroupToggle, HighlightProps, ItemActivate } from '../interfaces';\nimport { filterItems } from './filter-items';\nimport useHighlightedMenu from './use-highlighted-menu';\nimport { getItemTarget, isCheckboxItem, isItemGroup, isLinkItem } from './utils';\n\ntype DropdownFocusLeaveEvent = NonCancelableCustomEvent<Pick<React.FocusEvent, 'target' | 'relatedTarget'>>;\n\ninterface UseButtonDropdownOptions extends ButtonDropdownSettings {\n items: ButtonDropdownProps.Items;\n onItemClick?: CancelableEventHandler<ButtonDropdownProps.ItemClickDetails>;\n onItemFollow?: CancelableEventHandler<ButtonDropdownProps.ItemClickDetails>;\n onReturnFocus: () => void;\n // Returns whether the given element is (or is inside) the dropdown trigger.\n isTriggerElement: (element: Element) => boolean;\n expandToViewport?: boolean;\n hasFiltering: boolean;\n}\n\ninterface UseButtonDropdownApi extends HighlightProps {\n isOpen: boolean;\n onKeyDown: (event: React.KeyboardEvent) => void;\n onKeyUp: (event: React.KeyboardEvent) => void;\n onItemActivate: ItemActivate;\n onGroupToggle: GroupToggle;\n onDropdownFocusLeave: (event: DropdownFocusLeaveEvent) => void;\n onDropdownBlur: () => void;\n toggleDropdown: (options?: { moveHighlightOnOpen?: boolean }) => void;\n closeDropdown: () => void;\n setIsUsingMouse: (isUsingMouse: boolean) => void;\n filteringValue: string;\n setFilteringValue: (value: string) => void;\n filteredItems: ButtonDropdownProps.Items;\n showExpandableGroups: boolean;\n}\n\nexport function useButtonDropdown({\n items,\n onItemClick,\n onItemFollow,\n onReturnFocus,\n isTriggerElement,\n hasExpandableGroups,\n isInRestrictedView = false,\n expandToViewport = false,\n hasFiltering,\n}: UseButtonDropdownOptions): UseButtonDropdownApi {\n const [filteringValue, setFilteringValue] = useState('');\n\n const filteredItems = useMemo(\n () => (hasFiltering && filteringValue ? filterItems(items, filteringValue) : items),\n [hasFiltering, filteringValue, items]\n );\n\n const showExpandableGroups = hasExpandableGroups && !filteringValue;\n\n const {\n targetItem,\n isHighlighted,\n isKeyboardHighlight,\n isExpanded,\n highlightItem,\n moveHighlight,\n expandGroup,\n collapseGroup,\n reset,\n setIsUsingMouse,\n } = useHighlightedMenu({\n items: filteredItems,\n hasExpandableGroups: showExpandableGroups,\n isInRestrictedView,\n });\n\n // If the filtering input changes, the options list also changes,\n // so the highlight isn't valid anymore.\n const prevFilteringValue = useRef(filteringValue);\n useEffect(() => {\n if (prevFilteringValue.current !== filteringValue) {\n prevFilteringValue.current = filteringValue;\n reset();\n }\n }, [filteringValue, reset]);\n\n const { isOpen, closeDropdown: closeDropdownState, ...openStateProps } = useOpenState({ onClose: reset });\n\n const closeDropdown = () => {\n setFilteringValue('');\n closeDropdownState();\n };\n\n const toggleDropdown = (options: { moveHighlightOnOpen?: boolean } = {}) => {\n const moveHighlightOnOpen = options.moveHighlightOnOpen ?? true;\n if (!isOpen && moveHighlightOnOpen && !hasFiltering) {\n moveHighlight(1);\n }\n if (isOpen) {\n setFilteringValue('');\n }\n openStateProps.toggleDropdown();\n };\n\n const onDropdownFocusLeave = (event: DropdownFocusLeaveEvent) => {\n if (hasFiltering && isOpen) {\n const { relatedTarget } = event.detail;\n // When focus moves from the filter input to the trigger via a mouse click, the trigger's\n // own click handler already closes the dropdown.\n const clickedTrigger =\n !!relatedTarget &&\n isElement(relatedTarget) &&\n isTriggerElement(relatedTarget) &&\n !isKeyboardInteraction(relatedTarget);\n if (clickedTrigger) {\n return;\n }\n if (expandToViewport) {\n // When expanded to viewport the focus can't move naturally to the next element.\n // Returning the focus to the trigger instead.\n onReturnFocus();\n }\n closeDropdown();\n }\n };\n\n // Close when focus leaves the entire widget (trigger and menu), for example when focus\n // moves to an app layout drawer or an element in a different frame. The filtering variant\n // keeps focus inside the dropdown content and closes via onDropdownFocusLeave instead.\n const onDropdownBlur = () => {\n if (isOpen && !hasFiltering) {\n closeDropdown();\n }\n };\n\n const onGroupToggle: GroupToggle = item => (!isExpanded(item) ? expandGroup(item) : collapseGroup());\n\n const onItemActivate: ItemActivate = (item, event) => {\n const isCheckbox = isCheckboxItem(item);\n const isLink = isLinkItem(item);\n const details = {\n id: item.id || 'undefined',\n href: isLink ? item.href : undefined,\n external: isLink ? item.external : undefined,\n target: isLink ? getItemTarget(item) : undefined,\n checked: isCheckbox ? !item.checked : undefined,\n };\n onReturnFocus();\n if (onItemFollow && isLink && isPlainLeftClick(event)) {\n fireCancelableEvent(onItemFollow, details, event);\n }\n if (onItemClick) {\n fireCancelableEvent(onItemClick, details, event);\n }\n closeDropdown();\n };\n\n const openAndSelectFirst = (event: React.KeyboardEvent) => {\n toggleDropdown();\n event.preventDefault();\n };\n\n const actOnParentDropdown = (event: React.KeyboardEvent) => {\n // if there is no highlighted item we act on the trigger by opening or closing dropdown\n if (!targetItem) {\n if (isOpen && !isInRestrictedView) {\n toggleDropdown();\n } else {\n openAndSelectFirst(event);\n }\n } else {\n if (isItemGroup(targetItem)) {\n onGroupToggle(targetItem, event);\n } else {\n onItemActivate(targetItem, event);\n }\n }\n };\n\n const activate = (event: React.KeyboardEvent, isEnter?: boolean) => {\n setIsUsingMouse(false);\n\n // if item is a link we rely on default behavior of an anchor, no need to prevent\n if (targetItem && isLinkItem(targetItem) && isEnter) {\n return;\n }\n\n event.preventDefault();\n actOnParentDropdown(event);\n };\n\n const onKeyDown = (event: React.KeyboardEvent) => {\n setIsUsingMouse(false);\n switch (event.keyCode) {\n case KeyCode.down: {\n if (!isOpen) {\n toggleDropdown();\n if (!hasFiltering) {\n moveHighlight(1, true);\n }\n } else {\n moveHighlight(1);\n }\n event.preventDefault();\n break;\n }\n case KeyCode.up: {\n if (!isOpen) {\n toggleDropdown();\n if (!hasFiltering) {\n moveHighlight(-1, true);\n }\n } else {\n moveHighlight(-1);\n }\n event.preventDefault();\n break;\n }\n case KeyCode.space: {\n // Prevent scrolling the list of items and highlighting the trigger when filtering\n // isn't active. Hitting space when filtering is active should just type a space\n // character into the input, or activate the clear button.\n if (!hasFiltering && !isOpen) {\n event.preventDefault();\n }\n break;\n }\n case KeyCode.enter: {\n // While filtering, pressing Enter without a highlighted item should not select\n // any item or close the dropdown.\n if (isOpen && hasFiltering && !targetItem) {\n break;\n }\n if (!targetItem?.disabled) {\n activate(event, true);\n }\n break;\n }\n case KeyCode.left:\n case KeyCode.right: {\n // When filtering is enabled and there's text in the filter input, left/right\n // arrow keys should move the caret between the characters.\n if (hasFiltering && filteringValue) {\n break;\n }\n if (targetItem && !targetItem.disabled && isItemGroup(targetItem) && !isExpanded(targetItem)) {\n expandGroup();\n } else if (hasExpandableGroups) {\n collapseGroup();\n }\n\n event.preventDefault();\n break;\n }\n case KeyCode.escape: {\n onReturnFocus();\n closeDropdown();\n event.preventDefault();\n if (isOpen) {\n event.stopPropagation();\n }\n break;\n }\n case KeyCode.tab: {\n // In filtering mode the dropdown contains multiple focusable elements (the filter\n // input and its clear button). Tabbing between them must not close the dropdown, so\n // closing on Tab is handled by onDropdownFocusLeave instead, which only fires once\n // focus actually leaves the dropdown.\n if (hasFiltering) {\n break;\n }\n // When expanded to viewport the focus can't move naturally to the next element.\n // Returning the focus to the trigger instead.\n if (expandToViewport) {\n onReturnFocus();\n }\n closeDropdown();\n break;\n }\n }\n };\n const onKeyUp = (event: React.KeyboardEvent) => {\n // When using a roving tabindex (filtering disabled), we need to handle activating items\n // with Space separately because there is a bug in Firefox where changing the focus during\n // a Space keydown event it will trigger unexpected click events on the new element.\n // See https://bugzilla.mozilla.org/show_bug.cgi?id=1220143\n if (event.keyCode === KeyCode.space && !targetItem?.disabled && !hasFiltering) {\n activate(event);\n }\n };\n\n return {\n isOpen,\n targetItem,\n isHighlighted,\n isKeyboardHighlight,\n isExpanded,\n highlightItem,\n onKeyDown,\n onKeyUp,\n onItemActivate,\n onGroupToggle,\n onDropdownFocusLeave,\n onDropdownBlur,\n toggleDropdown,\n closeDropdown,\n setIsUsingMouse,\n filteringValue,\n setFilteringValue,\n filteredItems,\n showExpandableGroups,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"use-button-dropdown.js","sourceRoot":"","sources":["../../../../src/button-dropdown/utils/use-button-dropdown.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAs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,YAAY,EAAE,CAAC;oBACjB,MAAM;gBACR,CAAC;gBACD,gFAAgF;gBAChF,8CAA8C;gBAC9C,IAAI,gBAAgB,EAAE,CAAC;oBACrB,aAAa,EAAE,CAAC;gBAClB,CAAC;gBACD,aAAa,EAAE,CAAC;gBAChB,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC,CAAC;IACF,MAAM,OAAO,GAAG,CAAC,KAA0B,EAAE,EAAE;QAC7C,wFAAwF;QACxF,0FAA0F;QAC1F,oFAAoF;QACpF,2DAA2D;QAC3D,IAAI,KAAK,CAAC,OAAO,KAAK,OAAO,CAAC,KAAK,IAAI,CAAC,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,QAAQ,CAAA,IAAI,CAAC,YAAY,EAAE,CAAC;YAC9E,QAAQ,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,MAAM;QACN,UAAU;QACV,aAAa;QACb,mBAAmB;QACnB,UAAU;QACV,aAAa;QACb,SAAS;QACT,OAAO;QACP,cAAc;QACd,aAAa;QACb,oBAAoB;QACpB,cAAc;QACd,cAAc;QACd,aAAa;QACb,eAAe;QACf,cAAc;QACd,iBAAiB;QACjB,aAAa;QACb,YAAY;KACb,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';\n\nimport { useOpenState } from '../../internal/components/options-list/utils/use-open-state';\nimport { fireCancelableEvent, isPlainLeftClick } from '../../internal/events';\nimport { KeyCode } from '../../internal/keycode';\nimport { isElement } from '../../internal/utils/dom';\nimport { isKeyboardInteraction } from '../../internal/utils/focus-visible';\nimport { CancelableEventHandler, NonCancelableCustomEvent } from '../../types/events';\nimport { ButtonDropdownProps, ButtonDropdownSettings, GroupToggle, HighlightProps, ItemActivate } from '../interfaces';\nimport { filterItems } from './filter-items';\nimport useHighlightedMenu from './use-highlighted-menu';\nimport { getItemTarget, isCheckboxItem, isGroupExpandable, isItemGroup, isLinkItem } from './utils';\n\ntype DropdownFocusLeaveEvent = NonCancelableCustomEvent<Pick<React.FocusEvent, 'target' | 'relatedTarget'>>;\n\ninterface UseButtonDropdownOptions extends ButtonDropdownSettings {\n items: ButtonDropdownProps.Items;\n onItemClick?: CancelableEventHandler<ButtonDropdownProps.ItemClickDetails>;\n onItemFollow?: CancelableEventHandler<ButtonDropdownProps.ItemClickDetails>;\n onReturnFocus: () => void;\n // Returns whether the given element is (or is inside) the dropdown trigger.\n isTriggerElement: (element: Element) => boolean;\n expandToViewport?: boolean;\n hasFiltering: boolean;\n}\n\ninterface UseButtonDropdownApi extends HighlightProps {\n isOpen: boolean;\n onKeyDown: (event: React.KeyboardEvent) => void;\n onKeyUp: (event: React.KeyboardEvent) => void;\n onItemActivate: ItemActivate;\n onGroupToggle: GroupToggle;\n onDropdownFocusLeave: (event: DropdownFocusLeaveEvent) => void;\n onDropdownBlur: () => void;\n toggleDropdown: (options?: { moveHighlightOnOpen?: boolean }) => void;\n closeDropdown: () => void;\n setIsUsingMouse: (isUsingMouse: boolean) => void;\n filteringValue: string;\n setFilteringValue: (value: string) => void;\n filteredItems: ButtonDropdownProps.Items;\n isExpandable: (item: ButtonDropdownProps.ItemOrGroup) => boolean;\n}\n\nexport function useButtonDropdown({\n items,\n onItemClick,\n onItemFollow,\n onReturnFocus,\n isTriggerElement,\n hasExpandableGroups,\n isInRestrictedView = false,\n expandToViewport = false,\n hasFiltering,\n}: UseButtonDropdownOptions): UseButtonDropdownApi {\n const [filteringValue, setFilteringValue] = useState('');\n\n const filteredItems = useMemo(\n () => (hasFiltering && filteringValue ? filterItems(items, filteringValue) : items),\n [hasFiltering, filteringValue, items]\n );\n\n // an active filter flattens every group; otherwise a group's own `expandable` flag wins, falling\n // back to the dropdown-level `expandableGroups` default\n const isExpandable = useCallback(\n (item: ButtonDropdownProps.ItemOrGroup) => !filteringValue && isGroupExpandable(item, hasExpandableGroups),\n [filteringValue, hasExpandableGroups]\n );\n\n const {\n targetItem,\n isHighlighted,\n isKeyboardHighlight,\n isExpanded,\n highlightItem,\n moveHighlight,\n expandGroup,\n collapseGroup,\n reset,\n setIsUsingMouse,\n } = useHighlightedMenu({\n items: filteredItems,\n isExpandable,\n isInRestrictedView,\n });\n\n // If the filtering input changes, the options list also changes,\n // so the highlight isn't valid anymore.\n const prevFilteringValue = useRef(filteringValue);\n useEffect(() => {\n if (prevFilteringValue.current !== filteringValue) {\n prevFilteringValue.current = filteringValue;\n reset();\n }\n }, [filteringValue, reset]);\n\n const { isOpen, closeDropdown: closeDropdownState, ...openStateProps } = useOpenState({ onClose: reset });\n\n const closeDropdown = () => {\n setFilteringValue('');\n closeDropdownState();\n };\n\n const toggleDropdown = (options: { moveHighlightOnOpen?: boolean } = {}) => {\n const moveHighlightOnOpen = options.moveHighlightOnOpen ?? true;\n if (!isOpen && moveHighlightOnOpen && !hasFiltering) {\n moveHighlight(1);\n }\n if (isOpen) {\n setFilteringValue('');\n }\n openStateProps.toggleDropdown();\n };\n\n const onDropdownFocusLeave = (event: DropdownFocusLeaveEvent) => {\n if (hasFiltering && isOpen) {\n const { relatedTarget } = event.detail;\n // When focus moves from the filter input to the trigger via a mouse click, the trigger's\n // own click handler already closes the dropdown.\n const clickedTrigger =\n !!relatedTarget &&\n isElement(relatedTarget) &&\n isTriggerElement(relatedTarget) &&\n !isKeyboardInteraction(relatedTarget);\n if (clickedTrigger) {\n return;\n }\n if (expandToViewport) {\n // When expanded to viewport the focus can't move naturally to the next element.\n // Returning the focus to the trigger instead.\n onReturnFocus();\n }\n closeDropdown();\n }\n };\n\n // Close when focus leaves the entire widget (trigger and menu), for example when focus\n // moves to an app layout drawer or an element in a different frame. The filtering variant\n // keeps focus inside the dropdown content and closes via onDropdownFocusLeave instead.\n const onDropdownBlur = () => {\n if (isOpen && !hasFiltering) {\n closeDropdown();\n }\n };\n\n const onGroupToggle: GroupToggle = item => (!isExpanded(item) ? expandGroup(item) : collapseGroup());\n\n const onItemActivate: ItemActivate = (item, event) => {\n const isCheckbox = isCheckboxItem(item);\n const isLink = isLinkItem(item);\n const details = {\n id: item.id || 'undefined',\n href: isLink ? item.href : undefined,\n external: isLink ? item.external : undefined,\n target: isLink ? getItemTarget(item) : undefined,\n checked: isCheckbox ? !item.checked : undefined,\n };\n onReturnFocus();\n if (onItemFollow && isLink && isPlainLeftClick(event)) {\n fireCancelableEvent(onItemFollow, details, event);\n }\n if (onItemClick) {\n fireCancelableEvent(onItemClick, details, event);\n }\n closeDropdown();\n };\n\n const openAndSelectFirst = (event: React.KeyboardEvent) => {\n toggleDropdown();\n event.preventDefault();\n };\n\n const actOnParentDropdown = (event: React.KeyboardEvent) => {\n // if there is no highlighted item we act on the trigger by opening or closing dropdown\n if (!targetItem) {\n if (isOpen && !isInRestrictedView) {\n toggleDropdown();\n } else {\n openAndSelectFirst(event);\n }\n } else {\n if (isItemGroup(targetItem)) {\n onGroupToggle(targetItem, event);\n } else {\n onItemActivate(targetItem, event);\n }\n }\n };\n\n const activate = (event: React.KeyboardEvent, isEnter?: boolean) => {\n setIsUsingMouse(false);\n\n // if item is a link we rely on default behavior of an anchor, no need to prevent\n if (targetItem && isLinkItem(targetItem) && isEnter) {\n return;\n }\n\n event.preventDefault();\n actOnParentDropdown(event);\n };\n\n const onKeyDown = (event: React.KeyboardEvent) => {\n setIsUsingMouse(false);\n switch (event.keyCode) {\n case KeyCode.down: {\n if (!isOpen) {\n toggleDropdown();\n if (!hasFiltering) {\n moveHighlight(1, true);\n }\n } else {\n moveHighlight(1);\n }\n event.preventDefault();\n break;\n }\n case KeyCode.up: {\n if (!isOpen) {\n toggleDropdown();\n if (!hasFiltering) {\n moveHighlight(-1, true);\n }\n } else {\n moveHighlight(-1);\n }\n event.preventDefault();\n break;\n }\n case KeyCode.space: {\n // Prevent scrolling the list of items and highlighting the trigger when filtering\n // isn't active. Hitting space when filtering is active should just type a space\n // character into the input, or activate the clear button.\n if (!hasFiltering && !isOpen) {\n event.preventDefault();\n }\n break;\n }\n case KeyCode.enter: {\n // While filtering, pressing Enter without a highlighted item should not select\n // any item or close the dropdown.\n if (isOpen && hasFiltering && !targetItem) {\n break;\n }\n if (!targetItem?.disabled) {\n activate(event, true);\n }\n break;\n }\n case KeyCode.left:\n case KeyCode.right: {\n // When filtering is enabled and there's text in the filter input, left/right\n // arrow keys should move the caret between the characters.\n if (hasFiltering && filteringValue) {\n break;\n }\n if (targetItem && !targetItem.disabled && isItemGroup(targetItem) && !isExpanded(targetItem)) {\n expandGroup();\n } else {\n collapseGroup();\n }\n\n event.preventDefault();\n break;\n }\n case KeyCode.escape: {\n onReturnFocus();\n closeDropdown();\n event.preventDefault();\n if (isOpen) {\n event.stopPropagation();\n }\n break;\n }\n case KeyCode.tab: {\n // In filtering mode the dropdown contains multiple focusable elements (the filter\n // input and its clear button). Tabbing between them must not close the dropdown, so\n // closing on Tab is handled by onDropdownFocusLeave instead, which only fires once\n // focus actually leaves the dropdown.\n if (hasFiltering) {\n break;\n }\n // When expanded to viewport the focus can't move naturally to the next element.\n // Returning the focus to the trigger instead.\n if (expandToViewport) {\n onReturnFocus();\n }\n closeDropdown();\n break;\n }\n }\n };\n const onKeyUp = (event: React.KeyboardEvent) => {\n // When using a roving tabindex (filtering disabled), we need to handle activating items\n // with Space separately because there is a bug in Firefox where changing the focus during\n // a Space keydown event it will trigger unexpected click events on the new element.\n // See https://bugzilla.mozilla.org/show_bug.cgi?id=1220143\n if (event.keyCode === KeyCode.space && !targetItem?.disabled && !hasFiltering) {\n activate(event);\n }\n };\n\n return {\n isOpen,\n targetItem,\n isHighlighted,\n isKeyboardHighlight,\n isExpanded,\n highlightItem,\n onKeyDown,\n onKeyUp,\n onItemActivate,\n onGroupToggle,\n onDropdownFocusLeave,\n onDropdownBlur,\n toggleDropdown,\n closeDropdown,\n setIsUsingMouse,\n filteringValue,\n setFilteringValue,\n filteredItems,\n isExpandable,\n };\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ButtonDropdownProps, HighlightProps } from '../interfaces';
|
|
2
2
|
interface UseHighlightedMenuOptions {
|
|
3
3
|
items: ButtonDropdownProps.Items;
|
|
4
|
-
|
|
4
|
+
isExpandable: (item: ButtonDropdownProps.ItemOrGroup) => boolean;
|
|
5
5
|
isInRestrictedView?: boolean;
|
|
6
6
|
}
|
|
7
7
|
interface UseHighlightedMenuApi extends HighlightProps {
|
|
@@ -13,7 +13,7 @@ interface UseHighlightedMenuApi extends HighlightProps {
|
|
|
13
13
|
}
|
|
14
14
|
export default function useHighlightedMenu({
|
|
15
15
|
items,
|
|
16
|
-
|
|
16
|
+
isExpandable,
|
|
17
17
|
isInRestrictedView
|
|
18
18
|
}: UseHighlightedMenuOptions): UseHighlightedMenuApi;
|
|
19
19
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-highlighted-menu.d.ts","sourceRoot":"","sources":["../../../../src/button-dropdown/utils/use-highlighted-menu.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAKpE,UAAU,yBAAyB;IACjC,KAAK,EAAE,mBAAmB,CAAC,KAAK,CAAC;IACjC,
|
|
1
|
+
{"version":3,"file":"use-highlighted-menu.d.ts","sourceRoot":"","sources":["../../../../src/button-dropdown/utils/use-highlighted-menu.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAKpE,UAAU,yBAAyB;IACjC,KAAK,EAAE,mBAAmB,CAAC,KAAK,CAAC;IACjC,YAAY,EAAE,CAAC,IAAI,EAAE,mBAAmB,CAAC,WAAW,KAAK,OAAO,CAAC;IACjE,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,UAAU,qBAAsB,SAAQ,cAAc;IACpD,aAAa,EAAE,CAAC,SAAS,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IAC3D,WAAW,EAAE,CAAC,KAAK,CAAC,EAAE,mBAAmB,CAAC,SAAS,KAAK,IAAI,CAAC;IAC7D,aAAa,EAAE,MAAM,IAAI,CAAC;IAC1B,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,eAAe,EAAE,CAAC,YAAY,EAAE,OAAO,KAAK,IAAI,CAAC;CAClD;AAED,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,EACzC,KAAK,EACL,YAAY,EACZ,kBAA0B,GAC3B,EAAE,yBAAyB,GAAG,qBAAqB,CA2HnD"}
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
import { useCallback, useMemo, useState } from 'react';
|
|
4
4
|
import createItemsTree from './create-items-tree';
|
|
5
5
|
import moveHighlightOneStep from './move-highlight';
|
|
6
|
-
import { indexEquals, indexIncludes } from './utils';
|
|
7
|
-
export default function useHighlightedMenu({ items,
|
|
6
|
+
import { indexEquals, indexIncludes, isItemGroup } from './utils';
|
|
7
|
+
export default function useHighlightedMenu({ items, isExpandable, isInRestrictedView = false, }) {
|
|
8
8
|
const [targetIndex, setTargetIndex] = useState([]);
|
|
9
9
|
const [expandedIndex, setExpandedIndex] = useState([]);
|
|
10
10
|
const [isUsingMouse, setIsUsingMouse] = useState(true);
|
|
@@ -23,6 +23,15 @@ export default function useHighlightedMenu({ items, hasExpandableGroups, isInRes
|
|
|
23
23
|
const index = getItemIndex(group);
|
|
24
24
|
return indexIncludes(index, expandedIndex);
|
|
25
25
|
}, [expandedIndex, getItemIndex]);
|
|
26
|
+
// an index's navigable plane: an expandable group's children form its plane, everything else is top plane
|
|
27
|
+
const planeOf = useCallback((index) => {
|
|
28
|
+
if (index.length <= 1) {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
const parentIndex = index.slice(0, -1);
|
|
32
|
+
const parent = getItem(parentIndex);
|
|
33
|
+
return parent && isItemGroup(parent) && isExpandable(parent) ? parentIndex : [];
|
|
34
|
+
}, [getItem, isExpandable]);
|
|
26
35
|
const moveHighlight = useCallback((direction, loop) => {
|
|
27
36
|
const getNext = (index) => {
|
|
28
37
|
const nextIndex = getSequentialIndex(index, direction, loop);
|
|
@@ -38,13 +47,14 @@ export default function useHighlightedMenu({ items, hasExpandableGroups, isInRes
|
|
|
38
47
|
startIndex: targetIndex,
|
|
39
48
|
expandedIndex,
|
|
40
49
|
getNext,
|
|
41
|
-
|
|
50
|
+
isExpandable,
|
|
51
|
+
planeOf,
|
|
42
52
|
isInRestrictedView,
|
|
43
53
|
});
|
|
44
54
|
if (nextIndex) {
|
|
45
55
|
setTargetIndex(nextIndex);
|
|
46
56
|
}
|
|
47
|
-
}, [targetIndex, expandedIndex, getItem, getSequentialIndex, getParentIndex,
|
|
57
|
+
}, [targetIndex, expandedIndex, getItem, getSequentialIndex, getParentIndex, isExpandable, planeOf, isInRestrictedView]);
|
|
48
58
|
const highlightItem = useCallback((item) => {
|
|
49
59
|
setTargetIndex(getItemIndex(item));
|
|
50
60
|
}, [getItemIndex]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-highlighted-menu.js","sourceRoot":"","sources":["../../../../src/button-dropdown/utils/use-highlighted-menu.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGvD,OAAO,eAA8B,MAAM,qBAAqB,CAAC;AACjE,OAAO,oBAAoB,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"use-highlighted-menu.js","sourceRoot":"","sources":["../../../../src/button-dropdown/utils/use-highlighted-menu.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,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Aa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC7B,cAAc,CAAC,aAAa,CAAC,CAAC;YAC9B,gBAAgB,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;IAEpB,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE;QAC7B,cAAc,CAAC,EAAE,CAAC,CAAC;QACnB,gBAAgB,CAAC,EAAE,CAAC,CAAC;IACvB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACL,UAAU;QACV,aAAa;QACb,mBAAmB;QACnB,UAAU;QACV,aAAa;QACb,aAAa;QACb,WAAW;QACX,aAAa;QACb,KAAK;QACL,eAAe;KAChB,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { useCallback, useMemo, useState } from 'react';\n\nimport { ButtonDropdownProps, HighlightProps } from '../interfaces';\nimport createItemsTree, { TreeIndex } from './create-items-tree';\nimport moveHighlightOneStep from './move-highlight';\nimport { indexEquals, indexIncludes, isItemGroup } from './utils';\n\ninterface UseHighlightedMenuOptions {\n items: ButtonDropdownProps.Items;\n isExpandable: (item: ButtonDropdownProps.ItemOrGroup) => boolean;\n isInRestrictedView?: boolean;\n}\n\ninterface UseHighlightedMenuApi extends HighlightProps {\n moveHighlight: (direction: -1 | 1, loop?: boolean) => void;\n expandGroup: (group?: ButtonDropdownProps.ItemGroup) => void;\n collapseGroup: () => void;\n reset: () => void;\n setIsUsingMouse: (isUsingMouse: boolean) => void;\n}\n\nexport default function useHighlightedMenu({\n items,\n isExpandable,\n isInRestrictedView = false,\n}: UseHighlightedMenuOptions): UseHighlightedMenuApi {\n const [targetIndex, setTargetIndex] = useState<TreeIndex>([]);\n const [expandedIndex, setExpandedIndex] = useState<TreeIndex>([]);\n const [isUsingMouse, setIsUsingMouse] = useState<boolean>(true);\n\n const { getItem, getItemIndex, getSequentialIndex, getParentIndex } = useMemo(() => createItemsTree(items), [items]);\n\n const targetItem = useMemo(() => getItem(targetIndex), [targetIndex, getItem]);\n\n const isHighlighted = useCallback(\n (item: ButtonDropdownProps.ItemOrGroup) => {\n const index = getItemIndex(item);\n return indexIncludes(index, targetIndex);\n },\n [targetIndex, getItemIndex]\n );\n\n // check if keyboard focus is on the element\n const isKeyboardHighlight = useCallback(\n (item: ButtonDropdownProps.ItemOrGroup) => {\n const index = getItemIndex(item);\n return !isUsingMouse && indexEquals(index, targetIndex);\n },\n [targetIndex, getItemIndex, isUsingMouse]\n );\n\n const isExpanded = useCallback(\n (group: ButtonDropdownProps.ItemGroup) => {\n const index = getItemIndex(group);\n\n return indexIncludes(index, expandedIndex);\n },\n [expandedIndex, getItemIndex]\n );\n\n // an index's navigable plane: an expandable group's children form its plane, everything else is top plane\n const planeOf = useCallback(\n (index: TreeIndex): TreeIndex => {\n if (index.length <= 1) {\n return [];\n }\n const parentIndex = index.slice(0, -1);\n const parent = getItem(parentIndex);\n return parent && isItemGroup(parent) && isExpandable(parent) ? parentIndex : [];\n },\n [getItem, isExpandable]\n );\n\n const moveHighlight = useCallback(\n (direction: -1 | 1, loop?: boolean) => {\n const getNext = (index: TreeIndex) => {\n const nextIndex = getSequentialIndex(index, direction, loop);\n const item = getItem(nextIndex || [-1]);\n\n if (!nextIndex || !item) {\n return null;\n }\n\n const parentIndex = getParentIndex(item);\n const parentItem = parentIndex && getItem(parentIndex);\n\n return { index: nextIndex, item, parent: parentItem || undefined };\n };\n\n const nextIndex = moveHighlightOneStep({\n startIndex: targetIndex,\n expandedIndex,\n getNext,\n isExpandable,\n planeOf,\n isInRestrictedView,\n });\n\n if (nextIndex) {\n setTargetIndex(nextIndex);\n }\n },\n [targetIndex, expandedIndex, getItem, getSequentialIndex, getParentIndex, isExpandable, planeOf, isInRestrictedView]\n );\n\n const highlightItem = useCallback(\n (item: ButtonDropdownProps.ItemOrGroup) => {\n setTargetIndex(getItemIndex(item));\n },\n [getItemIndex]\n );\n\n const expandGroup = useCallback(\n (group?: ButtonDropdownProps.ItemGroup) => {\n const groupIndex = group ? getItemIndex(group) : targetIndex;\n const firstChildIndex = [...groupIndex, 0];\n\n // move to the first child item unless in restricted mode\n setTargetIndex(isInRestrictedView ? groupIndex : firstChildIndex);\n setExpandedIndex(groupIndex);\n },\n [targetIndex, getItemIndex, isInRestrictedView]\n );\n\n const collapseGroup = useCallback(() => {\n if (expandedIndex.length > 0) {\n setTargetIndex(expandedIndex);\n setExpandedIndex(expandedIndex.slice(0, -1));\n }\n }, [expandedIndex]);\n\n const reset = useCallback(() => {\n setTargetIndex([]);\n setExpandedIndex([]);\n }, []);\n\n return {\n targetItem,\n isHighlighted,\n isKeyboardHighlight,\n isExpanded,\n moveHighlight,\n highlightItem,\n expandGroup,\n collapseGroup,\n reset,\n setIsUsingMouse,\n };\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ButtonDropdownProps, LinkItem } from '../interfaces';
|
|
2
2
|
export declare const isItemGroup: (item: ButtonDropdownProps.ItemOrGroup) => item is ButtonDropdownProps.ItemGroup;
|
|
3
|
+
export declare const isGroupExpandable: (item: ButtonDropdownProps.ItemOrGroup, expandableGroupsDefault: boolean) => boolean;
|
|
3
4
|
export declare const isLinkItem: (item: LinkItem | ButtonDropdownProps.ItemOrGroup) => item is LinkItem;
|
|
4
5
|
export declare const isCheckboxItem: (item: ButtonDropdownProps.ItemOrGroup) => item is ButtonDropdownProps.CheckboxItem;
|
|
5
6
|
export declare const getItemTarget: (item: ButtonDropdownProps.Item) => "_blank" | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/button-dropdown/utils/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AA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AAC,YACvB,CAAC;AAE7E,eAAO,MAAM,aAAa,GAAI,MAAM,mBAAmB,CAAC,IAAI,yBAA2C,CAAC;AAExG,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,WAQ/D;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,WAY1D;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,mBAAmB,CAAC,KAAK,WAQhE;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,mBAAmB,CAAC,KAAK,WAQtE"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { traverseItems } from './create-items-tree';
|
|
2
2
|
export const isItemGroup = (item) => item && item.items !== undefined;
|
|
3
|
+
export const isGroupExpandable = (item, expandableGroupsDefault) => { var _a; return isItemGroup(item) && ((_a = item.expandable) !== null && _a !== void 0 ? _a : expandableGroupsDefault); };
|
|
3
4
|
export const isLinkItem = (item) => item && item.href !== undefined;
|
|
4
5
|
export const isCheckboxItem = (item) => item && item.itemType === 'checkbox';
|
|
5
6
|
export const getItemTarget = (item) => (item.external ? '_blank' : undefined);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/button-dropdown/utils/utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAqC,EAAyC,EAAE,CAC1G,IAAI,IAAK,IAAsC,CAAC,KAAK,KAAK,SAAS,CAAC;AAEtE,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAgD,EAAoB,EAAE,CAC/F,IAAI,IAAK,IAAiB,CAAC,IAAI,KAAK,SAAS,CAAC;AAEhD,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,IAAqC,EAA4C,EAAE,CAChH,IAAI,I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,CAAC,KAAgC;IACrE,IAAI,kBAAkB,GAAG,KAAK,CAAC;IAC/B,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE;QAC1B,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,kBAAkB,GAAG,IAAI,CAAC;QAC5B,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,kBAAkB,CAAC;AAC5B,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { ButtonDropdownProps, LinkItem } from '../interfaces';\nimport { traverseItems } from './create-items-tree';\n\nexport const isItemGroup = (item: ButtonDropdownProps.ItemOrGroup): item is ButtonDropdownProps.ItemGroup =>\n item && (item as ButtonDropdownProps.ItemGroup).items !== undefined;\n\nexport const isLinkItem = (item: LinkItem | ButtonDropdownProps.ItemOrGroup): item is LinkItem =>\n item && (item as LinkItem).href !== undefined;\n\nexport const isCheckboxItem = (item: ButtonDropdownProps.ItemOrGroup): item is ButtonDropdownProps.CheckboxItem =>\n item && (item as ButtonDropdownProps.CheckboxItem).itemType === 'checkbox';\n\nexport const getItemTarget = (item: ButtonDropdownProps.Item) => (item.external ? '_blank' : undefined);\n\nexport function indexIncludes(source: number[], target: number[]) {\n for (let index = 0; index < source.length; index++) {\n if (source[index] !== target[index]) {\n return false;\n }\n }\n\n return true;\n}\n\nexport function indexEquals(left: number[], right: number[]) {\n if (left.length !== right.length) {\n return false;\n }\n\n for (let index = 0; index < left.length; index++) {\n if (left[index] !== right[index]) {\n return false;\n }\n }\n\n return true;\n}\n\nexport function hasCheckboxItems(items: ButtonDropdownProps.Items) {\n let hasCheckboxItems = false;\n traverseItems(items, item => {\n if (item.itemType === 'checkbox') {\n hasCheckboxItems = true;\n }\n });\n return hasCheckboxItems;\n}\n\nexport function hasDisabledReasonItems(items: ButtonDropdownProps.Items) {\n let hasDisabledReasons = false;\n traverseItems(items, item => {\n if (item.disabledReason) {\n hasDisabledReasons =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,KAAe;IACzD,IAAI,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,EAAE,CAAC;QACjC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QACjD,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;YACjC,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAgC;IAC/D,IAAI,gBAAgB,GAAG,KAAK,CAAC;IAC7B,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE;QAC1B,IAAI,IAAI,CAAC,QAAQ,KAAK,UAAU,EAAE,CAAC;YACjC,gBAAgB,GAAG,IAAI,CAAC;QAC1B,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,KAAgC;IACrE,IAAI,kBAAkB,GAAG,KAAK,CAAC;IAC/B,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE;QAC1B,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,kBAAkB,GAAG,IAAI,CAAC;QAC5B,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,kBAAkB,CAAC;AAC5B,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { ButtonDropdownProps, LinkItem } from '../interfaces';\nimport { traverseItems } from './create-items-tree';\n\nexport const isItemGroup = (item: ButtonDropdownProps.ItemOrGroup): item is ButtonDropdownProps.ItemGroup =>\n item && (item as ButtonDropdownProps.ItemGroup).items !== undefined;\n\nexport const isGroupExpandable = (item: ButtonDropdownProps.ItemOrGroup, expandableGroupsDefault: boolean): boolean =>\n isItemGroup(item) && (item.expandable ?? expandableGroupsDefault);\n\nexport const isLinkItem = (item: LinkItem | ButtonDropdownProps.ItemOrGroup): item is LinkItem =>\n item && (item as LinkItem).href !== undefined;\n\nexport const isCheckboxItem = (item: ButtonDropdownProps.ItemOrGroup): item is ButtonDropdownProps.CheckboxItem =>\n item && (item as ButtonDropdownProps.CheckboxItem).itemType === 'checkbox';\n\nexport const getItemTarget = (item: ButtonDropdownProps.Item) => (item.external ? '_blank' : undefined);\n\nexport function indexIncludes(source: number[], target: number[]) {\n for (let index = 0; index < source.length; index++) {\n if (source[index] !== target[index]) {\n return false;\n }\n }\n\n return true;\n}\n\nexport function indexEquals(left: number[], right: number[]) {\n if (left.length !== right.length) {\n return false;\n }\n\n for (let index = 0; index < left.length; index++) {\n if (left[index] !== right[index]) {\n return false;\n }\n }\n\n return true;\n}\n\nexport function hasCheckboxItems(items: ButtonDropdownProps.Items) {\n let hasCheckboxItems = false;\n traverseItems(items, item => {\n if (item.itemType === 'checkbox') {\n hasCheckboxItems = true;\n }\n });\n return hasCheckboxItems;\n}\n\nexport function hasDisabledReasonItems(items: ButtonDropdownProps.Items) {\n let hasDisabledReasons = false;\n traverseItems(items, item => {\n if (item.disabledReason) {\n hasDisabledReasons = true;\n }\n });\n return hasDisabledReasons;\n}\n"]}
|
package/calendar/interfaces.d.ts
CHANGED
|
@@ -22,7 +22,8 @@ export interface CalendarProps extends BaseComponentProps {
|
|
|
22
22
|
dateDisabledReason?: CalendarProps.DateDisabledReasonFunction;
|
|
23
23
|
/**
|
|
24
24
|
* Specifies the locale to use to render month names and determine the starting day of the week.
|
|
25
|
-
* If you don't provide this, the locale is determined by the
|
|
25
|
+
* If you don't provide this, the locale is determined by the locale of the surrounding I18nProvider,
|
|
26
|
+
* or the page and browser locales otherwise.
|
|
26
27
|
* Supported values and formats are listed in the
|
|
27
28
|
* [JavaScript Intl API specification](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation).
|
|
28
29
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../src/calendar/interfaces.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAE5D,MAAM,WAAW,aAAc,SAAQ,kBAAkB;IACvD;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC,qBAAqB,CAAC;IAEpD;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,aAAa,CAAC,0BAA0B,CAAC;IAE9D
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../src/calendar/interfaces.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAE5D,MAAM,WAAW,aAAc,SAAQ,kBAAkB;IACvD;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC,qBAAqB,CAAC;IAEpD;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,aAAa,CAAC,0BAA0B,CAAC;IAE9D;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B;;;OAGG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAEhC;;;OAGG;IACH,QAAQ,CAAC,EAAE,yBAAyB,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;IAEjE;;;;OAIG;IACH,WAAW,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC;IAExC;;;QAGI;IACJ,WAAW,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC;CACzC;AAED,yBAAiB,aAAa,CAAC;IAC7B,UAAiB,YAAY;QAC3B;;WAEG;QACH,KAAK,EAAE,MAAM,CAAC;KACf;IAED,UAAiB,qBAAqB;QACpC,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC;KACvB;IAED,UAAiB,0BAA0B;QACzC,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAAC;KACtB;IAED,KAAY,WAAW,GAAG,eAAe,CAAC;IAE1C,UAAiB,WAAW;QAC1B;;WAEG;QACH,cAAc,CAAC,EAAE,MAAM,CAAC;QAExB;;WAEG;QACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;QAE5B;;WAEG;QACH,sBAAsB,CAAC,EAAE,MAAM,CAAC;QAEhC;;;WAGG;QACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;QAE/B;;;WAGG;QACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAE3B;;;WAGG;QACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;KAChC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/calendar/interfaces.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { BaseComponentProps } from '../types/base-component';\nimport { DateGranularity } from '../types/date-time';\nimport { NonCancelableEventHandler } from '../types/events';\n\nexport interface CalendarProps extends BaseComponentProps {\n /**\n * The current input value, in YYYY-MM-DD format.\n */\n value: string;\n\n /**\n * Defines whether a particular date is enabled in the calendar or not.\n * If you disable a date in the calendar, users can still enter this date using a keyboard.\n * We recommend that you also validate these constraints on the client-side and server-side\n * as you would for other form elements.\n * @param date\n */\n isDateEnabled?: CalendarProps.IsDateEnabledFunction;\n\n /**\n * Provides a reason why a particular date in the calendar is not enabled (only when `isDateEnabled` returns `false`).\n * If provided, the date becomes focusable.\n * @param date\n */\n dateDisabledReason?: CalendarProps.DateDisabledReasonFunction;\n\n /**\n * Specifies the locale to use to render month names and determine the starting day of the week.\n * If you don't provide this, the locale is determined by the page and browser locales.\n * Supported values and formats are listed in the\n * [JavaScript Intl API specification](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation).\n */\n locale?: string;\n\n /**\n * Determines the starting day of the week. The values 0-6 map to Sunday-Saturday.\n * By default the starting day of the week is defined by the locale, but you can use this property to override it.\n */\n startOfWeek?: number;\n\n /**\n * Adds an `aria-label` to the calendar.\n */\n ariaLabel?: string;\n\n /**\n * Adds `aria-labelledby` to the calendar.\n */\n ariaLabelledby?: string;\n\n /**\n * Adds `aria-describedby` to the calendar.\n */\n ariaDescribedby?: string;\n\n /**\n * Used as part of the `aria-label` for today's date in the calendar.\n * @deprecated Use `i18nString.todayAriaLabel` instead.\n */\n todayAriaLabel?: string;\n\n /**\n * Specifies an `aria-label` for the 'next month' button.\n * @deprecated Use `i18nStrings.nextMonthAriaLabel` instead.\n */\n nextMonthAriaLabel?: string;\n\n /**\n * Specifies an `aria-label` for the 'previous month' button.\n * @deprecated Use `i18nStrings.previousMonthAriaLabel` instead.\n */\n previousMonthAriaLabel?: string;\n\n /**\n * Called whenever a user changes the input value (by typing, pasting, or selecting a value).\n * The event `detail` contains the current value of the field.\n */\n onChange?: NonCancelableEventHandler<CalendarProps.ChangeDetail>;\n\n /**\n * An object containing all the necessary localized strings required by\n * the component.\n * @i18n\n */\n i18nStrings?: CalendarProps.I18nStrings;\n\n /**\n * Specifies the granularity at which users will be able to select a date.\n * Defaults to `day`.\n **/\n granularity?: CalendarProps.Granularity;\n}\n\nexport namespace CalendarProps {\n export interface ChangeDetail {\n /**\n * The new value of this component.\n */\n value: string;\n }\n\n export interface IsDateEnabledFunction {\n (date: Date): boolean;\n }\n\n export interface DateDisabledReasonFunction {\n (date: Date): string;\n }\n\n export type Granularity = DateGranularity;\n\n export interface I18nStrings {\n /**\n * Used as part of the `aria-label` for today's date in the calendar.\n */\n todayAriaLabel?: string;\n\n /**\n * Specifies an `aria-label` for the 'next month' button.\n */\n nextMonthAriaLabel?: string;\n\n /**\n * Specifies an `aria-label` for the 'previous month' button.\n */\n previousMonthAriaLabel?: string;\n\n /**\n * Used as part of the `aria-label` for the current month in the calendar.\n * @i18n\n */\n currentMonthAriaLabel?: string;\n\n /**\n * Specifies an `aria-label` for the 'next year' button.\n * @i18n\n */\n nextYearAriaLabel?: string;\n\n /**\n * Specifies an `aria-label` for the 'previous year' button.\n * @i18n\n */\n previousYearAriaLabel?: string;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/calendar/interfaces.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { BaseComponentProps } from '../types/base-component';\nimport { DateGranularity } from '../types/date-time';\nimport { NonCancelableEventHandler } from '../types/events';\n\nexport interface CalendarProps extends BaseComponentProps {\n /**\n * The current input value, in YYYY-MM-DD format.\n */\n value: string;\n\n /**\n * Defines whether a particular date is enabled in the calendar or not.\n * If you disable a date in the calendar, users can still enter this date using a keyboard.\n * We recommend that you also validate these constraints on the client-side and server-side\n * as you would for other form elements.\n * @param date\n */\n isDateEnabled?: CalendarProps.IsDateEnabledFunction;\n\n /**\n * Provides a reason why a particular date in the calendar is not enabled (only when `isDateEnabled` returns `false`).\n * If provided, the date becomes focusable.\n * @param date\n */\n dateDisabledReason?: CalendarProps.DateDisabledReasonFunction;\n\n /**\n * Specifies the locale to use to render month names and determine the starting day of the week.\n * If you don't provide this, the locale is determined by the locale of the surrounding I18nProvider,\n * or the page and browser locales otherwise.\n * Supported values and formats are listed in the\n * [JavaScript Intl API specification](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation).\n */\n locale?: string;\n\n /**\n * Determines the starting day of the week. The values 0-6 map to Sunday-Saturday.\n * By default the starting day of the week is defined by the locale, but you can use this property to override it.\n */\n startOfWeek?: number;\n\n /**\n * Adds an `aria-label` to the calendar.\n */\n ariaLabel?: string;\n\n /**\n * Adds `aria-labelledby` to the calendar.\n */\n ariaLabelledby?: string;\n\n /**\n * Adds `aria-describedby` to the calendar.\n */\n ariaDescribedby?: string;\n\n /**\n * Used as part of the `aria-label` for today's date in the calendar.\n * @deprecated Use `i18nString.todayAriaLabel` instead.\n */\n todayAriaLabel?: string;\n\n /**\n * Specifies an `aria-label` for the 'next month' button.\n * @deprecated Use `i18nStrings.nextMonthAriaLabel` instead.\n */\n nextMonthAriaLabel?: string;\n\n /**\n * Specifies an `aria-label` for the 'previous month' button.\n * @deprecated Use `i18nStrings.previousMonthAriaLabel` instead.\n */\n previousMonthAriaLabel?: string;\n\n /**\n * Called whenever a user changes the input value (by typing, pasting, or selecting a value).\n * The event `detail` contains the current value of the field.\n */\n onChange?: NonCancelableEventHandler<CalendarProps.ChangeDetail>;\n\n /**\n * An object containing all the necessary localized strings required by\n * the component.\n * @i18n\n */\n i18nStrings?: CalendarProps.I18nStrings;\n\n /**\n * Specifies the granularity at which users will be able to select a date.\n * Defaults to `day`.\n **/\n granularity?: CalendarProps.Granularity;\n}\n\nexport namespace CalendarProps {\n export interface ChangeDetail {\n /**\n * The new value of this component.\n */\n value: string;\n }\n\n export interface IsDateEnabledFunction {\n (date: Date): boolean;\n }\n\n export interface DateDisabledReasonFunction {\n (date: Date): string;\n }\n\n export type Granularity = DateGranularity;\n\n export interface I18nStrings {\n /**\n * Used as part of the `aria-label` for today's date in the calendar.\n */\n todayAriaLabel?: string;\n\n /**\n * Specifies an `aria-label` for the 'next month' button.\n */\n nextMonthAriaLabel?: string;\n\n /**\n * Specifies an `aria-label` for the 'previous month' button.\n */\n previousMonthAriaLabel?: string;\n\n /**\n * Used as part of the `aria-label` for the current month in the calendar.\n * @i18n\n */\n currentMonthAriaLabel?: string;\n\n /**\n * Specifies an `aria-label` for the 'next year' button.\n * @i18n\n */\n nextYearAriaLabel?: string;\n\n /**\n * Specifies an `aria-label` for the 'previous year' button.\n * @i18n\n */\n previousYearAriaLabel?: string;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/calendar/internal.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/calendar/internal.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,0BAA0B,EAAE,MAAM,+CAA+C,CAAC;AAS3F,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAOhD,KAAK,qBAAqB,GAAG,aAAa,GAAG,0BAA0B,GAAG;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAElG,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,EAC/B,KAAK,EACL,MAAW,EACX,WAAW,EACX,aAA0B,EAC1B,kBAA6B,EAC7B,SAAS,EACT,cAAc,EACd,eAAe,EACf,QAAQ,EACR,iBAAiB,EACjB,WAAW,EACX,WAAmB,EACnB,UAAU,EACV,sBAAsB,EACtB,kBAAkB,EAClB,cAAc,EACd,GAAG,IAAI,EACR,EAAE,qBAAqB,eAwJvB"}
|
package/calendar/internal.js
CHANGED
|
@@ -4,6 +4,7 @@ import React, { useEffect, useRef, useState } from 'react';
|
|
|
4
4
|
import clsx from 'clsx';
|
|
5
5
|
import { addMonths, addYears, isSameDay, isSameMonth, isSameYear } from 'date-fns';
|
|
6
6
|
import { useUniqueId } from '@cloudscape-design/component-toolkit/internal';
|
|
7
|
+
import { useLocale } from '../i18n/context.js';
|
|
7
8
|
import { getBaseProps } from '../internal/base-component';
|
|
8
9
|
import { fireNonCancelableEvent } from '../internal/events/index.js';
|
|
9
10
|
import checkControlled from '../internal/hooks/check-controlled/index.js';
|
|
@@ -22,7 +23,8 @@ import styles from './styles.css.js';
|
|
|
22
23
|
export default function Calendar({ value, locale = '', startOfWeek, isDateEnabled = () => true, dateDisabledReason = () => '', ariaLabel, ariaLabelledby, ariaDescribedby, onChange, __internalRootRef, i18nStrings, granularity = 'day', referrerId, previousMonthAriaLabel, nextMonthAriaLabel, todayAriaLabel, ...rest }) {
|
|
23
24
|
checkControlled('Calendar', 'value', value, 'onChange', onChange);
|
|
24
25
|
const baseProps = getBaseProps(rest);
|
|
25
|
-
const
|
|
26
|
+
const contextLocale = useLocale();
|
|
27
|
+
const normalizedLocale = normalizeLocale('Calendar', locale || contextLocale);
|
|
26
28
|
const gridWrapperRef = useRef(null);
|
|
27
29
|
const [focusedDate, setFocusedDate] = useState(null);
|
|
28
30
|
const valueDateCache = useDateCache();
|
package/calendar/internal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/calendar/internal.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC3D,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,M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AAC,MAAM,EAAE,gBAAgB,EAAE,IAAI,EAAE,QAAQ,GAAI,EAC/F,IAAI,EAAE,QAAQ,EACd,aAAa,EAAE,aAAa,EAC5B,UAAU,EAAE,UAAU,EACtB,sBAAsB,EAAE,sBAAsB,EAC9C,UAAU,EAAE,UAAU,EACtB,oBAAoB,EAAE,oBAAoB,EAC1C,UAAU,EAAE,UAAU,GACtB,CACE,CACF,CACF,CACP,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport React, { useEffect, useRef, useState } from 'react';\nimport clsx from 'clsx';\nimport { addMonths, addYears, isSameDay, isSameMonth, isSameYear } from 'date-fns';\n\nimport { useUniqueId } from '@cloudscape-design/component-toolkit/internal';\n\nimport { getBaseProps } from '../internal/base-component';\nimport { fireNonCancelableEvent } from '../internal/events/index.js';\nimport checkControlled from '../internal/hooks/check-controlled/index.js';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component/index.js';\nimport { useDateCache } from '../internal/hooks/use-date-cache/index.js';\nimport { formatDate, parseDate } from '../internal/utils/date-time';\nimport { normalizeLocale } from '../internal/utils/locale';\nimport Grid from './grid';\nimport CalendarGridHeader from './grid/calendar-grid-header';\nimport useCalendarGridKeyboardNavigation from './grid/use-calendar-grid-keyboard-navigation';\nimport useCalendarGridRows from './grid/use-calendar-grid-rows';\nimport CalendarHeader from './header';\nimport { CalendarProps } from './interfaces.js';\nimport useCalendarLabels from './use-calendar-labels';\nimport { getBaseDay } from './utils/navigation-day';\nimport { getBaseMonth } from './utils/navigation-month';\n\nimport styles from './styles.css.js';\n\ntype InternalCalendarProps = CalendarProps & InternalBaseComponentProps & { referrerId?: string };\n\nexport default function Calendar({\n value,\n locale = '',\n startOfWeek,\n isDateEnabled = () => true,\n dateDisabledReason = () => '',\n ariaLabel,\n ariaLabelledby,\n ariaDescribedby,\n onChange,\n __internalRootRef,\n i18nStrings,\n granularity = 'day',\n referrerId,\n previousMonthAriaLabel,\n nextMonthAriaLabel,\n todayAriaLabel,\n ...rest\n}: InternalCalendarProps) {\n checkControlled('Calendar', 'value', value, 'onChange', onChange);\n\n const baseProps = getBaseProps(rest);\n const normalizedLocale = normalizeLocale('Calendar', locale);\n\n const gridWrapperRef = useRef<HTMLDivElement>(null);\n const [focusedDate, setFocusedDate] = useState<Date | null>(null);\n\n const valueDateCache = useDateCache();\n const focusedDateCache = useDateCache();\n\n // Set displayed date to value if defined or to current date otherwise.\n const parsedValue = value && value.length >= 4 ? parseDate(value) : null;\n const memoizedValue = parsedValue && !isNaN(parsedValue.getDate()) ? valueDateCache(parsedValue) : null;\n const defaultDisplayedDate = memoizedValue ?? new Date();\n const [displayedDate, setDisplayedDate] = useState(defaultDisplayedDate);\n\n const headingId = useUniqueId('calendar-heading');\n\n const isMonthPicker = granularity === 'month';\n\n const isDateFocusable = (date: Date) => isDateEnabled(date) || (!isDateEnabled(date) && !!dateDisabledReason(date));\n\n const baseDate = isMonthPicker\n ? getBaseMonth(displayedDate, isDateEnabled)\n : getBaseDay(displayedDate, isDateEnabled);\n\n const isSameDate = isMonthPicker ? isSameMonth : isSameDay;\n const isSamePage = isMonthPicker ? isSameYear : isSameMonth;\n const isCurrentPage = (date: Date) => isMonthPicker || isSameMonth(date, baseDate);\n\n const { previousButtonLabel, nextButtonLabel, renderDate, renderDateAnnouncement, renderHeaderText } =\n useCalendarLabels({\n granularity,\n i18nStrings,\n locale: normalizedLocale,\n previousMonthAriaLabel,\n nextMonthAriaLabel,\n todayAriaLabel,\n });\n\n const gridRows = useCalendarGridRows({ baseDate, granularity, startOfWeek, locale: normalizedLocale });\n\n // Update displayed date if value changes.\n useEffect(() => {\n if (memoizedValue) {\n setDisplayedDate(prev => (prev.getTime() !== memoizedValue.getTime() ? memoizedValue : prev));\n }\n }, [memoizedValue]);\n\n const selectFocusedDate = (selected: Date | null, baseDate: Date): Date | null => {\n if (selected && isDateFocusable(selected) && isSamePage(selected, baseDate)) {\n return selected;\n }\n const today = new Date();\n if (isDateFocusable(today) && isSamePage(today, baseDate)) {\n return today;\n }\n if (isDateFocusable(baseDate)) {\n return baseDate;\n }\n return null;\n };\n\n const focusableDate = focusedDate || selectFocusedDate(memoizedValue, baseDate);\n\n const onHeaderChangePageHandler = (amount: number) => {\n const movePage = isMonthPicker ? addYears : addMonths;\n const newDate = movePage(baseDate, amount);\n onChangePageHandler(newDate);\n };\n\n const onChangePageHandler = (newDate: Date) => {\n setDisplayedDate(newDate);\n setFocusedDate(null);\n };\n\n const onGridFocusDateHandler = (date: null | Date) => {\n if (date) {\n setFocusedDate(date ? focusedDateCache(date) : null);\n }\n };\n\n const onGridSelectDateHandler = (date: Date) => {\n fireNonCancelableEvent(onChange, { value: formatDate(date, granularity) });\n setFocusedDate(null);\n };\n\n const onGridBlur = (event: React.FocusEvent) => {\n const newFocusTargetIsInGrid = event.relatedTarget && gridWrapperRef.current?.contains(event.relatedTarget as Node);\n if (!newFocusTargetIsInGrid) {\n setFocusedDate(null);\n }\n };\n\n const onGridKeyDownHandler = useCalendarGridKeyboardNavigation({\n baseDate,\n focusableDate,\n granularity,\n isDateEnabled,\n isDateFocusable,\n onChangePage: onChangePageHandler,\n onFocusDate: onGridFocusDateHandler,\n onSelectDate: onGridSelectDateHandler,\n });\n\n const headerText = renderHeaderText(baseDate);\n\n return (\n <div\n ref={__internalRootRef}\n {...baseProps}\n role=\"group\"\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledby}\n aria-describedby={ariaDescribedby}\n className={clsx(styles.root, styles.calendar, baseProps.className)}\n >\n <div className={styles['calendar-inner']}>\n <CalendarHeader\n formattedDate={headerText}\n onChange={onHeaderChangePageHandler}\n previousLabel={previousButtonLabel}\n nextLabel={nextButtonLabel}\n headingId={headingId}\n />\n <div onBlur={onGridBlur} ref={gridWrapperRef}>\n <Grid\n isDateEnabled={isDateEnabled}\n dateDisabledReason={dateDisabledReason}\n focusedDate={focusedDate}\n focusableDate={focusableDate}\n onSelectDate={onGridSelectDateHandler}\n onFocusDate={onGridFocusDateHandler}\n onChangePage={onChangePageHandler}\n selectedDate={memoizedValue}\n ariaLabelledby={headingId}\n header={isMonthPicker ? null : <CalendarGridHeader locale={normalizedLocale} rows={gridRows} />}\n rows={gridRows}\n isCurrentPage={isCurrentPage}\n renderDate={renderDate}\n renderDateAnnouncement={renderDateAnnouncement}\n isSameDate={isSameDate}\n onGridKeyDownHandler={onGridKeyDownHandler}\n referrerId={referrerId}\n />\n </div>\n </div>\n </div>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/calendar/internal.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC3D,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEnF,OAAO,EAAE,WAAW,EAAE,MAAM,+CAA+C,CAAC;AAE5E,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,eAAe,MAAM,6CAA6C,CAAC;AAE1E,OAAO,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,IAAI,MAAM,QAAQ,CAAC;AAC1B,OAAO,kBAAkB,MAAM,6BAA6B,CAAC;AAC7D,OAAO,iCAAiC,MAAM,8CAA8C,CAAC;AAC7F,OAAO,mBAAmB,MAAM,+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EACb,IAAI,EAAC,OAAO,gBACA,SAAS,qBACJ,cAAc,sBACb,eAAe,EACjC,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,SAAS,CAAC;QAElE,6BAAK,SAAS,EAAE,MAAM,CAAC,gBAAgB,CAAC;YACtC,oBAAC,cAAc,IACb,aAAa,EAAE,UAAU,EACzB,QAAQ,EAAE,yBAAyB,EACnC,aAAa,EAAE,mBAAmB,EAClC,SAAS,EAAE,eAAe,EAC1B,SAAS,EAAE,SAAS,GACpB;YACF,6BAAK,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,cAAc;gBAC1C,oBAAC,IAAI,IACH,aAAa,EAAE,aAAa,EAC5B,kBAAkB,EAAE,kBAAkB,EACtC,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,uBAAuB,EACrC,WAAW,EAAE,sBAAsB,EACnC,YAAY,EAAE,mBAAmB,EACjC,YAAY,EAAE,aAAa,EAC3B,cAAc,EAAE,SAAS,EACzB,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,oBAAC,kBAAkB,IAAC,MAAM,EAAE,gBAAgB,EAAE,IAAI,EAAE,QAAQ,GAAI,EAC/F,IAAI,EAAE,QAAQ,EACd,aAAa,EAAE,aAAa,EAC5B,UAAU,EAAE,UAAU,EACtB,sBAAsB,EAAE,sBAAsB,EAC9C,UAAU,EAAE,UAAU,EACtB,oBAAoB,EAAE,oBAAoB,EAC1C,UAAU,EAAE,UAAU,GACtB,CACE,CACF,CACF,CACP,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport React, { useEffect, useRef, useState } from 'react';\nimport clsx from 'clsx';\nimport { addMonths, addYears, isSameDay, isSameMonth, isSameYear } from 'date-fns';\n\nimport { useUniqueId } from '@cloudscape-design/component-toolkit/internal';\n\nimport { useLocale } from '../i18n/context.js';\nimport { getBaseProps } from '../internal/base-component';\nimport { fireNonCancelableEvent } from '../internal/events/index.js';\nimport checkControlled from '../internal/hooks/check-controlled/index.js';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component/index.js';\nimport { useDateCache } from '../internal/hooks/use-date-cache/index.js';\nimport { formatDate, parseDate } from '../internal/utils/date-time';\nimport { normalizeLocale } from '../internal/utils/locale';\nimport Grid from './grid';\nimport CalendarGridHeader from './grid/calendar-grid-header';\nimport useCalendarGridKeyboardNavigation from './grid/use-calendar-grid-keyboard-navigation';\nimport useCalendarGridRows from './grid/use-calendar-grid-rows';\nimport CalendarHeader from './header';\nimport { CalendarProps } from './interfaces.js';\nimport useCalendarLabels from './use-calendar-labels';\nimport { getBaseDay } from './utils/navigation-day';\nimport { getBaseMonth } from './utils/navigation-month';\n\nimport styles from './styles.css.js';\n\ntype InternalCalendarProps = CalendarProps & InternalBaseComponentProps & { referrerId?: string };\n\nexport default function Calendar({\n value,\n locale = '',\n startOfWeek,\n isDateEnabled = () => true,\n dateDisabledReason = () => '',\n ariaLabel,\n ariaLabelledby,\n ariaDescribedby,\n onChange,\n __internalRootRef,\n i18nStrings,\n granularity = 'day',\n referrerId,\n previousMonthAriaLabel,\n nextMonthAriaLabel,\n todayAriaLabel,\n ...rest\n}: InternalCalendarProps) {\n checkControlled('Calendar', 'value', value, 'onChange', onChange);\n\n const baseProps = getBaseProps(rest);\n const contextLocale = useLocale();\n const normalizedLocale = normalizeLocale('Calendar', locale || contextLocale);\n\n const gridWrapperRef = useRef<HTMLDivElement>(null);\n const [focusedDate, setFocusedDate] = useState<Date | null>(null);\n\n const valueDateCache = useDateCache();\n const focusedDateCache = useDateCache();\n\n // Set displayed date to value if defined or to current date otherwise.\n const parsedValue = value && value.length >= 4 ? parseDate(value) : null;\n const memoizedValue = parsedValue && !isNaN(parsedValue.getDate()) ? valueDateCache(parsedValue) : null;\n const defaultDisplayedDate = memoizedValue ?? new Date();\n const [displayedDate, setDisplayedDate] = useState(defaultDisplayedDate);\n\n const headingId = useUniqueId('calendar-heading');\n\n const isMonthPicker = granularity === 'month';\n\n const isDateFocusable = (date: Date) => isDateEnabled(date) || (!isDateEnabled(date) && !!dateDisabledReason(date));\n\n const baseDate = isMonthPicker\n ? getBaseMonth(displayedDate, isDateEnabled)\n : getBaseDay(displayedDate, isDateEnabled);\n\n const isSameDate = isMonthPicker ? isSameMonth : isSameDay;\n const isSamePage = isMonthPicker ? isSameYear : isSameMonth;\n const isCurrentPage = (date: Date) => isMonthPicker || isSameMonth(date, baseDate);\n\n const { previousButtonLabel, nextButtonLabel, renderDate, renderDateAnnouncement, renderHeaderText } =\n useCalendarLabels({\n granularity,\n i18nStrings,\n locale: normalizedLocale,\n previousMonthAriaLabel,\n nextMonthAriaLabel,\n todayAriaLabel,\n });\n\n const gridRows = useCalendarGridRows({ baseDate, granularity, startOfWeek, locale: normalizedLocale });\n\n // Update displayed date if value changes.\n useEffect(() => {\n if (memoizedValue) {\n setDisplayedDate(prev => (prev.getTime() !== memoizedValue.getTime() ? memoizedValue : prev));\n }\n }, [memoizedValue]);\n\n const selectFocusedDate = (selected: Date | null, baseDate: Date): Date | null => {\n if (selected && isDateFocusable(selected) && isSamePage(selected, baseDate)) {\n return selected;\n }\n const today = new Date();\n if (isDateFocusable(today) && isSamePage(today, baseDate)) {\n return today;\n }\n if (isDateFocusable(baseDate)) {\n return baseDate;\n }\n return null;\n };\n\n const focusableDate = focusedDate || selectFocusedDate(memoizedValue, baseDate);\n\n const onHeaderChangePageHandler = (amount: number) => {\n const movePage = isMonthPicker ? addYears : addMonths;\n const newDate = movePage(baseDate, amount);\n onChangePageHandler(newDate);\n };\n\n const onChangePageHandler = (newDate: Date) => {\n setDisplayedDate(newDate);\n setFocusedDate(null);\n };\n\n const onGridFocusDateHandler = (date: null | Date) => {\n if (date) {\n setFocusedDate(date ? focusedDateCache(date) : null);\n }\n };\n\n const onGridSelectDateHandler = (date: Date) => {\n fireNonCancelableEvent(onChange, { value: formatDate(date, granularity) });\n setFocusedDate(null);\n };\n\n const onGridBlur = (event: React.FocusEvent) => {\n const newFocusTargetIsInGrid = event.relatedTarget && gridWrapperRef.current?.contains(event.relatedTarget as Node);\n if (!newFocusTargetIsInGrid) {\n setFocusedDate(null);\n }\n };\n\n const onGridKeyDownHandler = useCalendarGridKeyboardNavigation({\n baseDate,\n focusableDate,\n granularity,\n isDateEnabled,\n isDateFocusable,\n onChangePage: onChangePageHandler,\n onFocusDate: onGridFocusDateHandler,\n onSelectDate: onGridSelectDateHandler,\n });\n\n const headerText = renderHeaderText(baseDate);\n\n return (\n <div\n ref={__internalRootRef}\n {...baseProps}\n role=\"group\"\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledby}\n aria-describedby={ariaDescribedby}\n className={clsx(styles.root, styles.calendar, baseProps.className)}\n >\n <div className={styles['calendar-inner']}>\n <CalendarHeader\n formattedDate={headerText}\n onChange={onHeaderChangePageHandler}\n previousLabel={previousButtonLabel}\n nextLabel={nextButtonLabel}\n headingId={headingId}\n />\n <div onBlur={onGridBlur} ref={gridWrapperRef}>\n <Grid\n isDateEnabled={isDateEnabled}\n dateDisabledReason={dateDisabledReason}\n focusedDate={focusedDate}\n focusableDate={focusableDate}\n onSelectDate={onGridSelectDateHandler}\n onFocusDate={onGridFocusDateHandler}\n onChangePage={onChangePageHandler}\n selectedDate={memoizedValue}\n ariaLabelledby={headingId}\n header={isMonthPicker ? null : <CalendarGridHeader locale={normalizedLocale} rows={gridRows} />}\n rows={gridRows}\n isCurrentPage={isCurrentPage}\n renderDate={renderDate}\n renderDateAnnouncement={renderDateAnnouncement}\n isSameDate={isSameDate}\n onGridKeyDownHandler={onGridKeyDownHandler}\n referrerId={referrerId}\n />\n </div>\n </div>\n </div>\n );\n}\n"]}
|
package/checkbox/internal.d.ts
CHANGED
|
@@ -4,7 +4,13 @@ import { CheckboxProps } from './interfaces';
|
|
|
4
4
|
interface InternalProps extends CheckboxProps, InternalBaseComponentProps {
|
|
5
5
|
tabIndex?: -1;
|
|
6
6
|
showOutline?: boolean;
|
|
7
|
+
styleClassNames?: StyleClassNames;
|
|
7
8
|
__injectAnalyticsComponentMetadata?: boolean;
|
|
8
9
|
}
|
|
10
|
+
interface StyleClassNames {
|
|
11
|
+
control?: string;
|
|
12
|
+
label?: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
}
|
|
9
15
|
declare const InternalCheckbox: React.ForwardRefExoticComponent<InternalProps & React.RefAttributes<CheckboxProps.Ref>>;
|
|
10
16
|
export default InternalCheckbox;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/checkbox/internal.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAejD,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAGlF,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAK7C,UAAU,aAAc,SAAQ,aAAa,EAAE,0BAA0B;IACvE,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;IACd,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,kCAAkC,CAAC,EAAE,OAAO,CAAC;CAC9C;AAED,QAAA,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/checkbox/internal.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAejD,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAGlF,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAK7C,UAAU,aAAc,SAAQ,aAAa,EAAE,0BAA0B;IACvE,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;IACd,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,kCAAkC,CAAC,EAAE,OAAO,CAAC;CAC9C;AAGD,UAAU,eAAe;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,QAAA,MAAM,gBAAgB,yFAwHrB,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
package/checkbox/internal.js
CHANGED
|
@@ -13,7 +13,7 @@ import useForwardFocus from '../internal/hooks/forward-focus';
|
|
|
13
13
|
import WithNativeAttributes from '../internal/utils/with-native-attributes';
|
|
14
14
|
import { getAbstractSwitchStyles, getCheckboxIconStyles } from './style';
|
|
15
15
|
import styles from './styles.css.js';
|
|
16
|
-
const InternalCheckbox = React.forwardRef(({ controlId, name, checked, disabled, readOnly, ariaRequired, indeterminate, children, description, ariaLabel, onFocus, onBlur, onChange, tabIndex: explicitTabIndex, showOutline, ariaControls, style, nativeInputAttributes, __internalRootRef, __injectAnalyticsComponentMetadata = false, ...rest }, ref) => {
|
|
16
|
+
const InternalCheckbox = React.forwardRef(({ controlId, name, checked, disabled, readOnly, ariaRequired, indeterminate, children, description, ariaLabel, onFocus, onBlur, onChange, tabIndex: explicitTabIndex, showOutline, ariaControls, style, styleClassNames, nativeInputAttributes, __internalRootRef, __injectAnalyticsComponentMetadata = false, ...rest }, ref) => {
|
|
17
17
|
const { ariaDescribedby, ariaLabelledby } = useFormFieldContext(rest);
|
|
18
18
|
const baseProps = getBaseProps(rest);
|
|
19
19
|
const checkboxRef = useRef(null);
|
|
@@ -38,7 +38,7 @@ const InternalCheckbox = React.forwardRef(({ controlId, name, checked, disabled,
|
|
|
38
38
|
if (!disabled && !readOnly) {
|
|
39
39
|
analyticsMetadata.action = !checked ? 'select' : 'deselect';
|
|
40
40
|
}
|
|
41
|
-
return (React.createElement(AbstractSwitch, { ...baseProps, className: clsx(styles.root, baseProps.className), controlClassName: styles['checkbox-control'], outlineClassName: styles.outline, controlId: controlId, disabled: disabled, readOnly: readOnly, label: children, description: description, descriptionBottomPadding: true, ariaLabel: ariaLabel, ariaLabelledby: ariaLabelledby, ariaDescribedby: ariaDescribedby, ariaControls: ariaControls, showOutline: showOutline, nativeControl: nativeControlProps => (React.createElement(WithNativeAttributes, { ...nativeControlProps, tag: "input", componentName: "Checkbox", nativeAttributes: nativeInputAttributes, ref: checkboxRef, type: "checkbox", checked: checked, name: name, "aria-required": ariaRequired ? 'true' : undefined, "aria-disabled": readOnly && !disabled ? 'true' : undefined, tabIndex: tabIndex, onFocus: () => fireNonCancelableEvent(onFocus), onBlur: () => fireNonCancelableEvent(onBlur),
|
|
41
|
+
return (React.createElement(AbstractSwitch, { ...baseProps, className: clsx(styles.root, baseProps.className), controlClassName: clsx(styleClassNames === null || styleClassNames === void 0 ? void 0 : styleClassNames.control, styles['checkbox-control']), outlineClassName: styles.outline, controlId: controlId, disabled: disabled, readOnly: readOnly, label: children, labelClassName: clsx(styleClassNames === null || styleClassNames === void 0 ? void 0 : styleClassNames.label, styles.label, disabled && styles['label-disabled']), description: description, descriptionClassName: clsx(styleClassNames === null || styleClassNames === void 0 ? void 0 : styleClassNames.description, styles.description, disabled && styles['description-disabled']), descriptionBottomPadding: true, ariaLabel: ariaLabel, ariaLabelledby: ariaLabelledby, ariaDescribedby: ariaDescribedby, ariaControls: ariaControls, showOutline: showOutline, nativeControl: nativeControlProps => (React.createElement(WithNativeAttributes, { ...nativeControlProps, tag: "input", componentName: "Checkbox", nativeAttributes: nativeInputAttributes, ref: checkboxRef, type: "checkbox", checked: checked, name: name, "aria-required": ariaRequired ? 'true' : undefined, "aria-disabled": readOnly && !disabled ? 'true' : undefined, tabIndex: tabIndex, onFocus: () => fireNonCancelableEvent(onFocus), onBlur: () => fireNonCancelableEvent(onBlur),
|
|
42
42
|
// empty handler to suppress React controllability warning
|
|
43
43
|
onChange: () => { } })), onClick: () => {
|
|
44
44
|
var _a;
|
package/checkbox/internal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/checkbox/internal.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACjD,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,0BAA0B,EAAE,MAAM,+CAA+C,CAAC;AAC3F,OAAO,EAEL,6BAA6B,GAC9B,MAAM,kEAAkE,CAAC;AAE1E,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,cAAc,MAAM,wCAAwC,CAAC;AACpE,OAAO,YAAY,MAAM,sCAAsC,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAC7E,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,eAAe,MAAM,iCAAiC,CAAC;AAE9D,OAAO,oBAAoB,MAAM,0CAA0C,CAAC;AAG5E,OAAO,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAEzE,OAAO,MAAM,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/checkbox/internal.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACjD,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,0BAA0B,EAAE,MAAM,+CAA+C,CAAC;AAC3F,OAAO,EAEL,6BAA6B,GAC9B,MAAM,kEAAkE,CAAC;AAE1E,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,cAAc,MAAM,wCAAwC,CAAC;AACpE,OAAO,YAAY,MAAM,sCAAsC,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAA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AO,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,CAAC,EACjF,iBAAiB,EAAE,iBAAiB,KAChC,6BAA6B,CAAC,iBAAiB,CAAC,GACpD,CACH,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\nimport React, { useEffect, useRef } from 'react';\nimport clsx from 'clsx';\n\nimport { useSingleTabStopNavigation } from '@cloudscape-design/component-toolkit/internal';\nimport {\n GeneratedAnalyticsMetadataFragment,\n getAnalyticsMetadataAttribute,\n} from '@cloudscape-design/component-toolkit/internal/analytics-metadata';\n\nimport { getBaseProps } from '../internal/base-component';\nimport AbstractSwitch from '../internal/components/abstract-switch';\nimport CheckboxIcon from '../internal/components/checkbox-icon';\nimport { useFormFieldContext } from '../internal/context/form-field-context';\nimport { fireNonCancelableEvent } from '../internal/events';\nimport useForwardFocus from '../internal/hooks/forward-focus';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component';\nimport WithNativeAttributes from '../internal/utils/with-native-attributes';\nimport { GeneratedAnalyticsMetadataCheckboxComponent } from './analytics-metadata/interfaces';\nimport { CheckboxProps } from './interfaces';\nimport { getAbstractSwitchStyles, getCheckboxIconStyles } from './style';\n\nimport styles from './styles.css.js';\n\ninterface InternalProps extends CheckboxProps, InternalBaseComponentProps {\n tabIndex?: -1;\n showOutline?: boolean;\n styleClassNames?: StyleClassNames;\n __injectAnalyticsComponentMetadata?: boolean;\n}\n\n// Style API v2\ninterface StyleClassNames {\n control?: string;\n label?: string;\n description?: string;\n}\n\nconst InternalCheckbox = React.forwardRef<CheckboxProps.Ref, InternalProps>(\n (\n {\n controlId,\n name,\n checked,\n disabled,\n readOnly,\n ariaRequired,\n indeterminate,\n children,\n description,\n ariaLabel,\n onFocus,\n onBlur,\n onChange,\n tabIndex: explicitTabIndex,\n showOutline,\n ariaControls,\n style,\n styleClassNames,\n nativeInputAttributes,\n __internalRootRef,\n __injectAnalyticsComponentMetadata = false,\n ...rest\n },\n ref\n ) => {\n const { ariaDescribedby, ariaLabelledby } = useFormFieldContext(rest);\n const baseProps = getBaseProps(rest);\n const checkboxRef = useRef<HTMLInputElement>(null);\n useForwardFocus(ref, checkboxRef);\n useEffect(() => {\n if (checkboxRef.current) {\n checkboxRef.current.indeterminate = Boolean(indeterminate);\n }\n });\n\n const { tabIndex } = useSingleTabStopNavigation(checkboxRef, { tabIndex: explicitTabIndex });\n\n const analyticsMetadata: GeneratedAnalyticsMetadataFragment = {};\n const analyticsComponentMetadata: GeneratedAnalyticsMetadataCheckboxComponent = {\n name: 'awsui.Checkbox',\n label: { root: 'self' },\n properties: {\n checked: `${!!checked}`,\n },\n };\n if (__injectAnalyticsComponentMetadata) {\n analyticsMetadata.component = analyticsComponentMetadata;\n }\n if (!disabled && !readOnly) {\n analyticsMetadata.action = !checked ? 'select' : 'deselect';\n }\n\n return (\n <AbstractSwitch\n {...baseProps}\n className={clsx(styles.root, baseProps.className)}\n controlClassName={clsx(styleClassNames?.control, styles['checkbox-control'])}\n outlineClassName={styles.outline}\n controlId={controlId}\n disabled={disabled}\n readOnly={readOnly}\n label={children}\n labelClassName={clsx(styleClassNames?.label, styles.label, disabled && styles['label-disabled'])}\n description={description}\n descriptionClassName={clsx(\n styleClassNames?.description,\n styles.description,\n disabled && styles['description-disabled']\n )}\n descriptionBottomPadding={true}\n ariaLabel={ariaLabel}\n ariaLabelledby={ariaLabelledby}\n ariaDescribedby={ariaDescribedby}\n ariaControls={ariaControls}\n showOutline={showOutline}\n nativeControl={nativeControlProps => (\n <WithNativeAttributes<HTMLInputElement, React.InputHTMLAttributes<HTMLInputElement>>\n {...nativeControlProps}\n tag=\"input\"\n componentName=\"Checkbox\"\n nativeAttributes={nativeInputAttributes}\n ref={checkboxRef}\n type=\"checkbox\"\n checked={checked}\n name={name}\n aria-required={ariaRequired ? 'true' : undefined}\n aria-disabled={readOnly && !disabled ? 'true' : undefined}\n tabIndex={tabIndex}\n onFocus={() => fireNonCancelableEvent(onFocus)}\n onBlur={() => fireNonCancelableEvent(onBlur)}\n // empty handler to suppress React controllability warning\n onChange={() => {}}\n />\n )}\n onClick={() => {\n checkboxRef.current?.focus();\n fireNonCancelableEvent(\n onChange,\n // for deterministic transitions \"indeterminate\" -> \"checked\" -> \"unchecked\"\n indeterminate ? { checked: true, indeterminate: false } : { checked: !checked, indeterminate: false }\n );\n }}\n styledControl={\n <CheckboxIcon\n checked={checked}\n indeterminate={indeterminate}\n disabled={disabled}\n readOnly={readOnly}\n style={getCheckboxIconStyles(style, checked, disabled, readOnly, indeterminate)}\n />\n }\n style={getAbstractSwitchStyles(style, checked, disabled, readOnly, indeterminate)}\n __internalRootRef={__internalRootRef}\n {...getAnalyticsMetadataAttribute(analyticsMetadata)}\n />\n );\n }\n);\n\nexport default InternalCheckbox;\n"]}
|
package/checkbox/styles.css.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
import './styles.scoped.css';
|
|
3
3
|
export default {
|
|
4
|
-
"root": "
|
|
5
|
-
"checkbox-control": "awsui_checkbox-
|
|
6
|
-
"outline": "
|
|
4
|
+
"root": "awsui_root_k2y2q_vvlo6_44",
|
|
5
|
+
"checkbox-control": "awsui_checkbox-control_k2y2q_vvlo6_77",
|
|
6
|
+
"outline": "awsui_outline_k2y2q_vvlo6_93",
|
|
7
|
+
"label": "awsui_label_k2y2q_vvlo6_115",
|
|
8
|
+
"label-disabled": "awsui_label-disabled_k2y2q_vvlo6_118",
|
|
9
|
+
"description": "awsui_description_k2y2q_vvlo6_122",
|
|
10
|
+
"description-disabled": "awsui_description-disabled_k2y2q_vvlo6_125"
|
|
7
11
|
};
|
|
8
12
|
|