@cloudscape-design/components 3.0.1081 → 3.0.1083

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/badge/index.d.ts.map +1 -1
  2. package/badge/internal-do-not-use-core.js +1 -1
  3. package/badge/internal-do-not-use-core.js.map +1 -1
  4. package/box/index.js +13 -20
  5. package/box/interfaces.d.ts +14 -0
  6. package/box/interfaces.d.ts.map +1 -1
  7. package/box/interfaces.js.map +1 -1
  8. package/box/internal-do-not-use-core.js +25 -0
  9. package/box/internal.d.ts +1 -0
  10. package/box/internal.d.ts.map +1 -1
  11. package/box/internal.js +3 -5
  12. package/box/internal.js.map +1 -1
  13. package/button/internal.d.ts.map +1 -1
  14. package/button/internal.js +3 -3
  15. package/button/internal.js.map +1 -1
  16. package/button-dropdown/utils/create-items-tree.d.ts +1 -1
  17. package/button-dropdown/utils/create-items-tree.d.ts.map +1 -1
  18. package/button-dropdown/utils/create-items-tree.js +11 -2
  19. package/button-dropdown/utils/create-items-tree.js.map +1 -1
  20. package/button-dropdown/utils/use-button-dropdown.d.ts.map +1 -1
  21. package/button-dropdown/utils/use-button-dropdown.js +14 -7
  22. package/button-dropdown/utils/use-button-dropdown.js.map +1 -1
  23. package/button-dropdown/utils/use-highlighted-menu.d.ts +1 -1
  24. package/button-dropdown/utils/use-highlighted-menu.d.ts.map +1 -1
  25. package/button-dropdown/utils/use-highlighted-menu.js +2 -2
  26. package/button-dropdown/utils/use-highlighted-menu.js.map +1 -1
  27. package/checkbox/internal.d.ts.map +1 -1
  28. package/checkbox/internal.js +1 -1
  29. package/checkbox/internal.js.map +1 -1
  30. package/icon/internal.d.ts.map +1 -1
  31. package/icon/internal.js +3 -3
  32. package/icon/internal.js.map +1 -1
  33. package/internal/base-component/styles.scoped.css +1 -2
  34. package/internal/components/option/index.js +1 -1
  35. package/internal/components/option/index.js.map +1 -1
  36. package/internal/components/option/option-parts.js +1 -1
  37. package/internal/components/option/option-parts.js.map +1 -1
  38. package/internal/components/option/styles.css.js +16 -17
  39. package/internal/components/option/styles.scoped.css +28 -32
  40. package/internal/components/option/styles.selectors.js +16 -17
  41. package/internal/environment.js +2 -2
  42. package/internal/environment.json +2 -2
  43. package/internal/manifest.json +1 -1
  44. package/internal/utils/with-native-attributes.d.ts +1 -0
  45. package/internal/utils/with-native-attributes.d.ts.map +1 -1
  46. package/internal/utils/with-native-attributes.js +2 -2
  47. package/internal/utils/with-native-attributes.js.map +1 -1
  48. package/package.json +1 -1
  49. package/space-between/index.js +13 -12
  50. package/space-between/interfaces.d.ts +14 -0
  51. package/space-between/interfaces.d.ts.map +1 -1
  52. package/space-between/interfaces.js.map +1 -1
  53. package/space-between/internal-do-not-use-core.js +17 -0
  54. package/space-between/internal.d.ts.map +1 -1
  55. package/space-between/internal.js +3 -2
  56. package/space-between/internal.js.map +1 -1
  57. package/spinner/internal.d.ts.map +1 -1
  58. package/spinner/internal.js +1 -1
  59. package/spinner/internal.js.map +1 -1
  60. /package/box/{index.js.map → internal-do-not-use-core.js.map} +0 -0
  61. /package/space-between/{index.js.map → internal-do-not-use-core.js.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/badge/index.tsx"],"names":[],"mappings":";AAUA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAK1C,OAAO,EAAE,UAAU,EAAE,CAAC;AAEtB,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,EAAE,KAAc,EAAE,QAAQ,EAAE,KAAK,EAAE,gBAAgB,EAAE,GAAG,IAAI,EAAE,EAAE,UAAU,eAkBvG"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/badge/index.tsx"],"names":[],"mappings":";AAUA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAK1C,OAAO,EAAE,UAAU,EAAE,CAAC;AAEtB,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,EAAE,KAAc,EAAE,QAAQ,EAAE,KAAK,EAAE,gBAAgB,EAAE,GAAG,IAAI,EAAE,EAAE,UAAU,eAmBvG"}
@@ -15,7 +15,7 @@ export default function Badge(_a) {
15
15
  const { __internalRootRef } = useBaseComponent('Badge', { props: { color } });
16
16
  const baseProps = getBaseProps(rest);
17
17
  const className = clsx(baseProps.className, styles.badge, styles[`badge-color-${color}`]);
18
- return (React.createElement(WithNativeAttributes, Object.assign({}, baseProps, { tag: "span", nativeAttributes: nativeAttributes, className: className, ref: __internalRootRef, style: getBadgeStyles(style) }), children));
18
+ return (React.createElement(WithNativeAttributes, Object.assign({}, baseProps, { tag: "span", componentName: "Badge", nativeAttributes: nativeAttributes, className: className, ref: __internalRootRef, style: getBadgeStyles(style) }), children));
19
19
  }
20
20
  applyDisplayName(Badge, 'Badge');
21
21
  //# sourceMappingURL=internal-do-not-use-core.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/badge/index.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,YAAY,CAAC;;AACb,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,gBAAgB,MAAM,sCAAsC,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,oBAAoB,MAAM,0CAA0C,CAAC;AAE5E,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAIrC,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,EAA0E;QAA1E,EAAE,KAAK,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,gBAAgB,OAAuB,EAAlB,IAAI,cAA5D,kDAA8D,CAAF;IACxF,MAAM,EAAE,iBAAiB,EAAE,GAAG,gBAAgB,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;IAC9E,MAAM,SAAS,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IAErC,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,eAAe,KAAK,EAAE,CAAC,CAAC,CAAC;IAE1F,OAAO,CACL,oBAAC,oBAAoB,oBACf,SAAS,IACb,GAAG,EAAC,MAAM,EACV,gBAAgB,EAAE,gBAAgB,EAClC,SAAS,EAAE,SAAS,EACpB,GAAG,EAAE,iBAAiB,EACtB,KAAK,EAAE,cAAc,CAAC,KAAK,CAAC,KAE3B,QAAQ,CACY,CACxB,CAAC;AACJ,CAAC;AAED,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n'use client';\nimport React from 'react';\nimport clsx from 'clsx';\n\nimport { getBaseProps } from '../internal/base-component';\nimport useBaseComponent from '../internal/hooks/use-base-component';\nimport { applyDisplayName } from '../internal/utils/apply-display-name';\nimport WithNativeAttributes from '../internal/utils/with-native-attributes';\nimport { BadgeProps } from './interfaces';\nimport { getBadgeStyles } from './style';\n\nimport styles from './styles.css.js';\n\nexport { BadgeProps };\n\nexport default function Badge({ color = 'grey', children, style, nativeAttributes, ...rest }: BadgeProps) {\n const { __internalRootRef } = useBaseComponent('Badge', { props: { color } });\n const baseProps = getBaseProps(rest);\n\n const className = clsx(baseProps.className, styles.badge, styles[`badge-color-${color}`]);\n\n return (\n <WithNativeAttributes\n {...baseProps}\n tag=\"span\"\n nativeAttributes={nativeAttributes}\n className={className}\n ref={__internalRootRef}\n style={getBadgeStyles(style)}\n >\n {children}\n </WithNativeAttributes>\n );\n}\n\napplyDisplayName(Badge, 'Badge');\n"]}
1
+ {"version":3,"file":"index.js","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yright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n'use client';\nimport React from 'react';\nimport clsx from 'clsx';\n\nimport { getBaseProps } from '../internal/base-component';\nimport useBaseComponent from '../internal/hooks/use-base-component';\nimport { applyDisplayName } from '../internal/utils/apply-display-name';\nimport WithNativeAttributes from '../internal/utils/with-native-attributes';\nimport { BadgeProps } from './interfaces';\nimport { getBadgeStyles } from './style';\n\nimport styles from './styles.css.js';\n\nexport { BadgeProps };\n\nexport default function Badge({ color = 'grey', children, style, nativeAttributes, ...rest }: BadgeProps) {\n const { __internalRootRef } = useBaseComponent('Badge', { props: { color } });\n const baseProps = getBaseProps(rest);\n\n const className = clsx(baseProps.className, styles.badge, styles[`badge-color-${color}`]);\n\n return (\n <WithNativeAttributes\n {...baseProps}\n tag=\"span\"\n componentName=\"Badge\"\n nativeAttributes={nativeAttributes}\n className={className}\n ref={__internalRootRef}\n style={getBadgeStyles(style)}\n >\n {children}\n </WithNativeAttributes>\n );\n}\n\napplyDisplayName(Badge, 'Badge');\n"]}
package/box/index.js CHANGED
@@ -1,25 +1,18 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- 'use client';
4
- import { __rest } from "tslib";
5
3
  import React from 'react';
6
- import useBaseComponent from '../internal/hooks/use-base-component';
4
+
5
+ import CoreComponent from './internal-do-not-use-core';
7
6
  import { applyDisplayName } from '../internal/utils/apply-display-name';
8
- import InternalBox from './internal';
9
- export default function Box(_a) {
10
- var { variant = 'div', margin = {}, padding = {} } = _a, props = __rest(_a, ["variant", "margin", "padding"]);
11
- const baseComponentProps = useBaseComponent('Box', {
12
- props: {
13
- color: props.color,
14
- display: props.display,
15
- float: props.float,
16
- fontSize: props.fontSize,
17
- fontWeight: props.fontWeight,
18
- textAlign: props.textAlign,
19
- variant,
20
- },
21
- });
22
- return React.createElement(InternalBox, Object.assign({ variant: variant, margin: margin, padding: padding }, props, baseComponentProps));
23
- }
7
+ import { validateProps } from '@cloudscape-design/component-toolkit/internal';
8
+
9
+
10
+
11
+ const Box = (props) => {
12
+ validateProps('Box', props, ["nativeAttributes"], {}, 'console');
13
+ return React.createElement(CoreComponent, props);
14
+ };
15
+
16
+
24
17
  applyDisplayName(Box, 'Box');
25
- //# sourceMappingURL=index.js.map
18
+ export default Box;
@@ -1,5 +1,9 @@
1
1
  /// <reference types="react" />
2
2
  import { BaseComponentProps } from '../internal/base-component';
3
+ /**
4
+ * @awsuiSystem core
5
+ */
6
+
3
7
  export interface BoxProps extends BaseComponentProps {
4
8
  /**
5
9
  * Defines the style of element to display.
@@ -114,6 +118,16 @@ export interface BoxProps extends BaseComponentProps {
114
118
  * @displayname content
115
119
  */
116
120
  children?: React.ReactNode;
121
+ /**
122
+ * Attributes to add to the native element.
123
+ * Some attributes will be automatically combined with internal attribute values:
124
+ * - `className` will be appended.
125
+ * - Event handlers will be chained, unless the default is prevented.
126
+ *
127
+ * We do not support using this attribute to apply custom styling.
128
+ *
129
+ * @awsuiSystem core
130
+ */
117
131
  }
118
132
  export declare namespace BoxProps {
119
133
  type Variant = 'div' | 'span' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'p' | 'strong' | 'small' | 'code' | 'pre' | 'samp' | 'awsui-key-label' | 'awsui-gen-ai-label' | 'awsui-value-large';
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../src/box/interfaces.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAEhE,MAAM,WAAW,QAAS,SAAQ,kBAAkB;IAClD;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC;IAC3B;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;;;;;OASG;IACH,OAAO,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC;IAC3B;;;;;;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BAAkB,GAClB,sBAAsB,GACtB,qBAAqB,CAAC;IAC1B,KAAY,WAAW,GAAG,GAAG,GAAG,MAAM,GAAG,KAAK,GAAG,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,KAAK,GAAG,MAAM,CAAC;IAChG,UAAiB,OAAO;QACtB,GAAG,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC;QAC3B,KAAK,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC;QAC7B,MAAM,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC;QAC9B,IAAI,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC;QAC5B,UAAU,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC;QAClC,QAAQ,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC;KACjC;CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/box/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { BaseComponentProps } from '../internal/base-component';\n\nexport interface BoxProps extends BaseComponentProps {\n /**\n * Defines the style of element to display.\n *\n * - If you set it to `'div'`, `'span'`, `'h1'`, `'h2'`, `'h3'`, `'h4'`, `'h5'`, `'p'`, `'strong'`, `'small'`, `'code'`, `'pre'`, or `'samp'`, the variant is also used as the HTML tag name.\n * - If you set it to `awsui-key-label`, the component will render a `div`,\n * styled for use as a key label in key-value pairs.\n * - If you set it to `awsui-gen-ai-label`, the component will render a `div`,\n * styled for use as a label indicating that content is produced by generative AI.\n * - If you set it to `awsui-value-large`, the component will render a `span`,\n * styled using \"Display large light\" typography.\n *\n * Override the HTML tag by using property `tagOverride`.\n */\n variant?: BoxProps.Variant;\n /**\n * Overrides the default HTML tag provided by the variant.\n */\n tagOverride?: string;\n /**\n * Overrides the display of the element. You can set it to the following values:\n *\n * - `block` - Specifies block display.\n * - `inline` - Specifies inline display.\n * - `inline-block` - Specifies inline-block display.\n * - `none` - Hides the box.\n *\n * Note: If you don't set it, the display depends on the variant.\n */\n display?: BoxProps.Display;\n /**\n * Adds margins to the element. It can be the following:\n *\n * - A single string with a size. This applies the same margin to all sides (that is, top, right, bottom, left).\n * - An object specifying the size of the margin per side. The object has the following format:\n * ```\n * {\n * top: \"size of top margin\",\n * right: \"size of right margin\",\n * bottom: \"size of bottom margin\",\n * left: \"size of left margin\",\n * horizontal: \"size of left and right margin\",\n * vertical: \"size of top and bottom margin\",\n * }\n * ```\n *\n * The size can be `n`, `xxxs`, `xxs`, `xs`, `s`, `m`, `l`, `xl`, `xxl`, `xxxl`, where `n` stands for none.\n * Sizes are automatically scaled down in compact mode.\n *\n * For example, `margin=\"s\"` adds a small margin to all sides.\n * `margin={{ right: \"l\", bottom: \"s\" }}` adds a small margin to the bottom and a large margin to the right.\n */\n margin?: BoxProps.SpacingSize | BoxProps.Spacing;\n /**\n * Adds padding to the element. It can be the following:\n *\n * - A single string with a size. This applies the same padding to all sides (that is, top, right, bottom, left).\n * - An object specifying the size of padding per side. The object has the following format:\n * ```\n * {\n * top: \"size of top padding\",\n * right: \"size of right padding\",\n * bottom: \"size of bottom padding\",\n * left: \"size of left padding\",\n * horizontal: \"size of left and right padding\",\n * vertical: \"size of top and bottom padding\",\n * }\n * ```\n *\n * The size can be `n`, `xxxs`, `xxs`, `xs`, `s`, `m`, `l`, `xl`, `xxl`, `xxxl`, where `n` stands for none.\n * Sizes are automatically scaled down in compact mode.\n *\n * For example, `padding=\"s\"` adds small padding to all sides.\n * `padding={{ right: \"l\", bottom: \"s\" }}` adds small padding to the bottom and large padding to the right.\n */\n padding?: BoxProps.SpacingSize | BoxProps.Spacing;\n /**\n * Defines the text alignment within the element. You can set it to `left`, `center`, or `right`.\n */\n textAlign?: BoxProps.TextAlign;\n /**\n * Defines the floating behavior. You can set it to `left` or `right`.\n */\n float?: BoxProps.Float;\n /**\n * Overrides the font size and line height. If not set, the font size and line height depend on the variant.\n */\n fontSize?: BoxProps.FontSize;\n /**\n * Overrides the font weight. If not set, the value depends on the variant.\n * @visualrefresh 'heavy'\n */\n fontWeight?: BoxProps.FontWeight;\n /**\n * Overrides the text color. You can set it to the following values:\n *\n * - `inherit` - Inherits the color from the parent element. For example, use this to style content\n * in Flashbars and to style the `empty` and `noMatch` slots of the Table and Cards components.\n * - `text-label` - Specifies the text color for non-form labels. For example, use it for the key in key/value pairs.\n * - `text-body-secondary` - Specifies the color for secondary text.\n * - `text-status-error` - Specifies the color for error text and icons.\n * - `text-status-success` - Specifies the color for success text and icons.\n * - `text-status-info` - Specifies the color for info text and icon.\n * - `text-status-inactive` - Specifies the color for inactive and loading text and icons.\n * - `text-status-warning` - Specifies the color for warning text and icons.\n *\n * Note: If you don't set it, the text color depends on the variant.\n */\n color?: BoxProps.Color;\n /**\n * Content of the box.\n * @displayname content\n */\n children?: React.ReactNode;\n}\n\nexport namespace BoxProps {\n export type Variant =\n | 'div'\n | 'span'\n | 'h1'\n | 'h2'\n | 'h3'\n | 'h4'\n | 'h5'\n | 'p'\n | 'strong'\n | 'small'\n | 'code'\n | 'pre'\n | 'samp'\n | 'awsui-key-label'\n | 'awsui-gen-ai-label'\n | 'awsui-value-large';\n\n export type Display = 'block' | 'inline' | 'inline-block' | 'none';\n export type TextAlign = 'left' | 'center' | 'right';\n export type Float = 'left' | 'right';\n export type FontSize =\n | 'body-s'\n | 'body-m'\n | 'heading-xs'\n | 'heading-s'\n | 'heading-m'\n | 'heading-l'\n | 'heading-xl'\n | 'display-l';\n export type FontWeight = 'light' | 'normal' | 'bold' | 'heavy';\n export type Color =\n | 'inherit'\n | 'text-label'\n | 'text-body-secondary'\n | 'text-status-error'\n | 'text-status-success'\n | 'text-status-info'\n | 'text-status-inactive'\n | 'text-status-warning';\n export type SpacingSize = 'n' | 'xxxs' | 'xxs' | 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl' | 'xxxl';\n export interface Spacing {\n top?: BoxProps.SpacingSize;\n right?: BoxProps.SpacingSize;\n bottom?: BoxProps.SpacingSize;\n left?: BoxProps.SpacingSize;\n horizontal?: BoxProps.SpacingSize;\n vertical?: BoxProps.SpacingSize;\n }\n}\n"]}
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/box/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { BaseComponentProps } from '../internal/base-component';\n/**\n * @awsuiSystem core\n */\nimport { NativeAttributes } from '../internal/utils/with-native-attributes';\n\nexport interface BoxProps extends BaseComponentProps {\n /**\n * Defines the style of element to display.\n *\n * - If you set it to `'div'`, `'span'`, `'h1'`, `'h2'`, `'h3'`, `'h4'`, `'h5'`, `'p'`, `'strong'`, `'small'`, `'code'`, `'pre'`, or `'samp'`, the variant is also used as the HTML tag name.\n * - If you set it to `awsui-key-label`, the component will render a `div`,\n * styled for use as a key label in key-value pairs.\n * - If you set it to `awsui-gen-ai-label`, the component will render a `div`,\n * styled for use as a label indicating that content is produced by generative AI.\n * - If you set it to `awsui-value-large`, the component will render a `span`,\n * styled using \"Display large light\" typography.\n *\n * Override the HTML tag by using property `tagOverride`.\n */\n variant?: BoxProps.Variant;\n /**\n * Overrides the default HTML tag provided by the variant.\n */\n tagOverride?: string;\n /**\n * Overrides the display of the element. You can set it to the following values:\n *\n * - `block` - Specifies block display.\n * - `inline` - Specifies inline display.\n * - `inline-block` - Specifies inline-block display.\n * - `none` - Hides the box.\n *\n * Note: If you don't set it, the display depends on the variant.\n */\n display?: BoxProps.Display;\n /**\n * Adds margins to the element. It can be the following:\n *\n * - A single string with a size. This applies the same margin to all sides (that is, top, right, bottom, left).\n * - An object specifying the size of the margin per side. The object has the following format:\n * ```\n * {\n * top: \"size of top margin\",\n * right: \"size of right margin\",\n * bottom: \"size of bottom margin\",\n * left: \"size of left margin\",\n * horizontal: \"size of left and right margin\",\n * vertical: \"size of top and bottom margin\",\n * }\n * ```\n *\n * The size can be `n`, `xxxs`, `xxs`, `xs`, `s`, `m`, `l`, `xl`, `xxl`, `xxxl`, where `n` stands for none.\n * Sizes are automatically scaled down in compact mode.\n *\n * For example, `margin=\"s\"` adds a small margin to all sides.\n * `margin={{ right: \"l\", bottom: \"s\" }}` adds a small margin to the bottom and a large margin to the right.\n */\n margin?: BoxProps.SpacingSize | BoxProps.Spacing;\n /**\n * Adds padding to the element. It can be the following:\n *\n * - A single string with a size. This applies the same padding to all sides (that is, top, right, bottom, left).\n * - An object specifying the size of padding per side. The object has the following format:\n * ```\n * {\n * top: \"size of top padding\",\n * right: \"size of right padding\",\n * bottom: \"size of bottom padding\",\n * left: \"size of left padding\",\n * horizontal: \"size of left and right padding\",\n * vertical: \"size of top and bottom padding\",\n * }\n * ```\n *\n * The size can be `n`, `xxxs`, `xxs`, `xs`, `s`, `m`, `l`, `xl`, `xxl`, `xxxl`, where `n` stands for none.\n * Sizes are automatically scaled down in compact mode.\n *\n * For example, `padding=\"s\"` adds small padding to all sides.\n * `padding={{ right: \"l\", bottom: \"s\" }}` adds small padding to the bottom and large padding to the right.\n */\n padding?: BoxProps.SpacingSize | BoxProps.Spacing;\n /**\n * Defines the text alignment within the element. You can set it to `left`, `center`, or `right`.\n */\n textAlign?: BoxProps.TextAlign;\n /**\n * Defines the floating behavior. You can set it to `left` or `right`.\n */\n float?: BoxProps.Float;\n /**\n * Overrides the font size and line height. If not set, the font size and line height depend on the variant.\n */\n fontSize?: BoxProps.FontSize;\n /**\n * Overrides the font weight. If not set, the value depends on the variant.\n * @visualrefresh 'heavy'\n */\n fontWeight?: BoxProps.FontWeight;\n /**\n * Overrides the text color. You can set it to the following values:\n *\n * - `inherit` - Inherits the color from the parent element. For example, use this to style content\n * in Flashbars and to style the `empty` and `noMatch` slots of the Table and Cards components.\n * - `text-label` - Specifies the text color for non-form labels. For example, use it for the key in key/value pairs.\n * - `text-body-secondary` - Specifies the color for secondary text.\n * - `text-status-error` - Specifies the color for error text and icons.\n * - `text-status-success` - Specifies the color for success text and icons.\n * - `text-status-info` - Specifies the color for info text and icon.\n * - `text-status-inactive` - Specifies the color for inactive and loading text and icons.\n * - `text-status-warning` - Specifies the color for warning text and icons.\n *\n * Note: If you don't set it, the text color depends on the variant.\n */\n color?: BoxProps.Color;\n /**\n * Content of the box.\n * @displayname content\n */\n children?: React.ReactNode;\n\n /**\n * Attributes to add to the native element.\n * Some attributes will be automatically combined with internal attribute values:\n * - `className` will be appended.\n * - Event handlers will be chained, unless the default is prevented.\n *\n * We do not support using this attribute to apply custom styling.\n *\n * @awsuiSystem core\n */\n nativeAttributes?: NativeAttributes<React.HTMLAttributes<HTMLElement>>;\n}\n\nexport namespace BoxProps {\n export type Variant =\n | 'div'\n | 'span'\n | 'h1'\n | 'h2'\n | 'h3'\n | 'h4'\n | 'h5'\n | 'p'\n | 'strong'\n | 'small'\n | 'code'\n | 'pre'\n | 'samp'\n | 'awsui-key-label'\n | 'awsui-gen-ai-label'\n | 'awsui-value-large';\n\n export type Display = 'block' | 'inline' | 'inline-block' | 'none';\n export type TextAlign = 'left' | 'center' | 'right';\n export type Float = 'left' | 'right';\n export type FontSize =\n | 'body-s'\n | 'body-m'\n | 'heading-xs'\n | 'heading-s'\n | 'heading-m'\n | 'heading-l'\n | 'heading-xl'\n | 'display-l';\n export type FontWeight = 'light' | 'normal' | 'bold' | 'heavy';\n export type Color =\n | 'inherit'\n | 'text-label'\n | 'text-body-secondary'\n | 'text-status-error'\n | 'text-status-success'\n | 'text-status-info'\n | 'text-status-inactive'\n | 'text-status-warning';\n export type SpacingSize = 'n' | 'xxxs' | 'xxs' | 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl' | 'xxxl';\n export interface Spacing {\n top?: BoxProps.SpacingSize;\n right?: BoxProps.SpacingSize;\n bottom?: BoxProps.SpacingSize;\n left?: BoxProps.SpacingSize;\n horizontal?: BoxProps.SpacingSize;\n vertical?: BoxProps.SpacingSize;\n }\n}\n"]}
@@ -0,0 +1,25 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ 'use client';
4
+ import { __rest } from "tslib";
5
+ import React from 'react';
6
+ import useBaseComponent from '../internal/hooks/use-base-component';
7
+ import { applyDisplayName } from '../internal/utils/apply-display-name';
8
+ import InternalBox from './internal';
9
+ export default function Box(_a) {
10
+ var { variant = 'div', margin = {}, padding = {} } = _a, props = __rest(_a, ["variant", "margin", "padding"]);
11
+ const baseComponentProps = useBaseComponent('Box', {
12
+ props: {
13
+ color: props.color,
14
+ display: props.display,
15
+ float: props.float,
16
+ fontSize: props.fontSize,
17
+ fontWeight: props.fontWeight,
18
+ textAlign: props.textAlign,
19
+ variant,
20
+ },
21
+ });
22
+ return React.createElement(InternalBox, Object.assign({ variant: variant, margin: margin, padding: padding }, props, baseComponentProps));
23
+ }
24
+ applyDisplayName(Box, 'Box');
25
+ //# sourceMappingURL=internal-do-not-use-core.js.map
package/box/internal.d.ts CHANGED
@@ -14,6 +14,7 @@ export default function InternalBox({
14
14
  fontWeight,
15
15
  color,
16
16
  children,
17
+ nativeAttributes,
17
18
  __internalRootRef,
18
19
  ...props
19
20
  }: InternalBoxProps): JSX.Element;
@@ -1 +1 @@
1
- {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/box/internal.tsx"],"names":[],"mappings":";AAMA,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAClF,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAIxC,KAAK,gBAAgB,GAAG,QAAQ,GAAG,0BAA0B,CAAC;AAE9D,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,EAClC,OAAe,EACf,WAAW,EACX,MAAW,EACX,OAAY,EACZ,OAAO,EACP,SAAS,EACT,KAAK,EACL,QAAQ,EACR,UAAU,EACV,KAAK,EACL,QAAQ,EACR,iBAAiB,EACjB,GAAG,KAAK,EACT,EAAE,gBAAgB,eA4BlB"}
1
+ {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/box/internal.tsx"],"names":[],"mappings":";AAMA,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAElF,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAIxC,KAAK,gBAAgB,GAAG,QAAQ,GAAG,0BAA0B,CAAC;AAE9D,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,EAClC,OAAe,EACf,WAAW,EACX,MAAW,EACX,OAAY,EACZ,OAAO,EACP,SAAS,EACT,KAAK,EACL,QAAQ,EACR,UAAU,EACV,KAAK,EACL,QAAQ,EACR,gBAAgB,EAChB,iBAAiB,EACjB,GAAG,KAAK,EACT,EAAE,gBAAgB,eAgClB"}
package/box/internal.js CHANGED
@@ -4,17 +4,15 @@ import { __rest } from "tslib";
4
4
  import React from 'react';
5
5
  import clsx from 'clsx';
6
6
  import { getBaseProps } from '../internal/base-component';
7
+ import WithNativeAttributes from '../internal/utils/with-native-attributes';
7
8
  import styles from './styles.css.js';
8
9
  export default function InternalBox(_a) {
9
- var { variant = 'div', tagOverride, margin = {}, padding = {}, display, textAlign, float, fontSize, fontWeight, color, children, __internalRootRef } = _a, props = __rest(_a, ["variant", "tagOverride", "margin", "padding", "display", "textAlign", "float", "fontSize", "fontWeight", "color", "children", "__internalRootRef"]);
10
+ var { variant = 'div', tagOverride, margin = {}, padding = {}, display, textAlign, float, fontSize, fontWeight, color, children, nativeAttributes, __internalRootRef } = _a, props = __rest(_a, ["variant", "tagOverride", "margin", "padding", "display", "textAlign", "float", "fontSize", "fontWeight", "color", "children", "nativeAttributes", "__internalRootRef"]);
10
11
  const baseProps = getBaseProps(props);
11
12
  const marginsClassNamesSuffices = getClassNamesSuffixes(margin);
12
13
  const paddingsClassNamesSuffices = getClassNamesSuffixes(padding);
13
- // This can be any arbitrary string if passed into tagOverride.
14
- // We appease the compiler with an incorrect type.
15
- const Tag = getTag(variant, tagOverride);
16
14
  const className = clsx(baseProps.className, styles.root, styles.box, styles[`${variant.replace(/^awsui-/, '')}-variant`], marginsClassNamesSuffices.map(suffix => styles[`m-${suffix}`]), paddingsClassNamesSuffices.map(suffix => styles[`p-${suffix}`]), styles[`d-${display}`], styles[`f-${float}`], styles[`color-${color || 'default'}`], styles[`font-size-${fontSize || 'default'}`], styles[`font-weight-${fontWeight || 'default'}`], styles[`t-${textAlign}`]);
17
- return (React.createElement(Tag, Object.assign({}, baseProps, { className: className, ref: __internalRootRef }), children));
15
+ return (React.createElement(WithNativeAttributes, Object.assign({}, baseProps, { tag: getTag(variant, tagOverride), componentName: "Box", nativeAttributes: nativeAttributes, className: className, ref: __internalRootRef }), children));
18
16
  }
19
17
  const getClassNamesSuffixes = (value) => {
20
18
  if (typeof value === 'string') {
@@ -1 +1 @@
1
- {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/box/internal.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAI1D,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAIrC,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,EAcjB;QAdiB,EAClC,OAAO,GAAG,KAAK,EACf,WAAW,EACX,MAAM,GAAG,EAAE,EACX,OAAO,GAAG,EAAE,EACZ,OAAO,EACP,SAAS,EACT,KAAK,EACL,QAAQ,EACR,UAAU,EACV,KAAK,EACL,QAAQ,EACR,iBAAiB,OAEA,EADd,KAAK,cAb0B,oJAcnC,CADS;IAER,MAAM,SAAS,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;IACtC,MAAM,yBAAyB,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;IAChE,MAAM,0BAA0B,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;IAClE,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KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACnF,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,CAAC,OAAyB,EAAE,WAAoC,EAAE,EAAE;IACjF,IAAI,WAAW,EAAE;QACf,OAAO,WAAW,CAAC;KACpB;IAED,IAAI,OAAO,KAAK,mBAAmB,EAAE;QACnC,OAAO,MAAM,CAAC;KACf;IAED,IAAI,OAAO,KAAK,iBAAiB,IAAI,OAAO,KAAK,oBAAoB,EAAE;QACrE,OAAO,KAAK,CAAC;KACd;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React from 'react';\nimport clsx from 'clsx';\n\nimport { getBaseProps } from '../internal/base-component';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component';\nimport { BoxProps } from './interfaces';\n\nimport styles from './styles.css.js';\n\ntype InternalBoxProps = BoxProps & InternalBaseComponentProps;\n\nexport default function InternalBox({\n variant = 'div',\n tagOverride,\n margin = {},\n padding = {},\n display,\n textAlign,\n float,\n fontSize,\n fontWeight,\n color,\n children,\n __internalRootRef,\n ...props\n}: InternalBoxProps) {\n const baseProps = getBaseProps(props);\n const marginsClassNamesSuffices = getClassNamesSuffixes(margin);\n const paddingsClassNamesSuffices = getClassNamesSuffixes(padding);\n // This can be any arbitrary string if passed into tagOverride.\n // We appease the compiler with an incorrect type.\n const Tag = getTag(variant, tagOverride) as 'div';\n\n const className = clsx(\n baseProps.className,\n styles.root,\n styles.box,\n styles[`${variant.replace(/^awsui-/, '')}-variant`],\n marginsClassNamesSuffices.map(suffix => styles[`m-${suffix}`]),\n paddingsClassNamesSuffices.map(suffix => styles[`p-${suffix}`]),\n styles[`d-${display}`],\n styles[`f-${float}`],\n styles[`color-${color || 'default'}`],\n styles[`font-size-${fontSize || 'default'}`],\n styles[`font-weight-${fontWeight || 'default'}`],\n styles[`t-${textAlign}`]\n );\n\n return (\n <Tag {...baseProps} className={className} ref={__internalRootRef}>\n {children}\n </Tag>\n );\n}\n\nconst getClassNamesSuffixes = (value: BoxProps.SpacingSize | BoxProps.Spacing) => {\n if (typeof value === 'string') {\n return [value];\n }\n const sides = ['top', 'right', 'bottom', 'left', 'horizontal', 'vertical'] as const;\n return sides.filter(side => !!value[side]).map(side => `${side}-${value[side]}`);\n};\n\nconst getTag = (variant: BoxProps.Variant, tagOverride: BoxProps['tagOverride']) => {\n if (tagOverride) {\n return tagOverride;\n }\n\n if (variant === 'awsui-value-large') {\n return 'span';\n }\n\n if (variant === 'awsui-key-label' || variant === 'awsui-gen-ai-label') {\n return 'div';\n }\n\n return variant;\n};\n"]}
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/box/internal.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,OAAO,oBAAoB,MAAM,0CAA0C,CAAC;AAG5E,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAIrC,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,EAejB;QAfiB,EAClC,OAAO,GAAG,KAAK,EACf,WAAW,EACX,MAAM,GAAG,EAAE,EACX,OAAO,GAAG,EAAE,EACZ,OAAO,EACP,SAAS,EACT,KAAK,EACL,QAAQ,EACR,UAAU,EACV,KAAK,EACL,QAAQ,EACR,gBAAgB,EAChB,iBAAiB,OAEA,EADd,KAAK,cAd0B,wKAenC,CADS;IAER,MAAM,SAAS,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;IACtC,MAAM,yBAAyB,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;IACh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IACpF,OAAO,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACnF,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,CAAC,OAAyB,EAAE,WAAoC,EAAE,EAAE;IACjF,IAAI,WAAW,EAAE;QACf,OAAO,WAAW,CAAC;KACpB;IAED,IAAI,OAAO,KAAK,mBAAmB,EAAE;QACnC,OAAO,MAAM,CAAC;KACf;IAED,IAAI,OAAO,KAAK,iBAAiB,IAAI,OAAO,KAAK,oBAAoB,EAAE;QACrE,OAAO,KAAK,CAAC;KACd;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React from 'react';\nimport clsx from 'clsx';\n\nimport { getBaseProps } from '../internal/base-component';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component';\nimport WithNativeAttributes from '../internal/utils/with-native-attributes';\nimport { BoxProps } from './interfaces';\n\nimport styles from './styles.css.js';\n\ntype InternalBoxProps = BoxProps & InternalBaseComponentProps;\n\nexport default function InternalBox({\n variant = 'div',\n tagOverride,\n margin = {},\n padding = {},\n display,\n textAlign,\n float,\n fontSize,\n fontWeight,\n color,\n children,\n nativeAttributes,\n __internalRootRef,\n ...props\n}: InternalBoxProps) {\n const baseProps = getBaseProps(props);\n const marginsClassNamesSuffices = getClassNamesSuffixes(margin);\n const paddingsClassNamesSuffices = getClassNamesSuffixes(padding);\n\n const className = clsx(\n baseProps.className,\n styles.root,\n styles.box,\n styles[`${variant.replace(/^awsui-/, '')}-variant`],\n marginsClassNamesSuffices.map(suffix => styles[`m-${suffix}`]),\n paddingsClassNamesSuffices.map(suffix => styles[`p-${suffix}`]),\n styles[`d-${display}`],\n styles[`f-${float}`],\n styles[`color-${color || 'default'}`],\n styles[`font-size-${fontSize || 'default'}`],\n styles[`font-weight-${fontWeight || 'default'}`],\n styles[`t-${textAlign}`]\n );\n\n return (\n <WithNativeAttributes\n {...baseProps}\n tag={getTag(variant, tagOverride)}\n componentName=\"Box\"\n nativeAttributes={nativeAttributes}\n className={className}\n ref={__internalRootRef}\n >\n {children}\n </WithNativeAttributes>\n );\n}\n\nconst getClassNamesSuffixes = (value: BoxProps.SpacingSize | BoxProps.Spacing) => {\n if (typeof value === 'string') {\n return [value];\n }\n const sides = ['top', 'right', 'bottom', 'left', 'horizontal', 'vertical'] as const;\n return sides.filter(side => !!value[side]).map(side => `${side}-${value[side]}`);\n};\n\nconst getTag = (variant: BoxProps.Variant, tagOverride: BoxProps['tagOverride']) => {\n if (tagOverride) {\n return tagOverride;\n }\n\n if (variant === 'awsui-value-large') {\n return 'span';\n }\n\n if (variant === 'awsui-key-label' || variant === 'awsui-gen-ai-label') {\n return 'div';\n }\n\n return variant;\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/button/internal.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAwB3D,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AASlF,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAO3C,MAAM,MAAM,mBAAmB,GAAG,IAAI,CAAC,WAAW,EAAE,SAAS,CAAC,GAAG;IAC/D,OAAO,CAAC,EACJ,WAAW,CAAC,SAAS,CAAC,GACtB,eAAe,GACf,kBAAkB,GAClB,cAAc,GACd,eAAe,GACf,4BAA4B,CAAC;IACjC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,kCAAk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GAClB,cAAc,GACd,eAAe,GACf,4BAA4B;;;;;;;;;;sEA2TjC,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -161,15 +161,15 @@ export const InternalButton = React.forwardRef((_a, ref) => {
161
161
  return buttonProps.tabIndex;
162
162
  };
163
163
  return (React.createElement(React.Fragment, null,
164
- React.createElement(WithNativeAttributes, Object.assign({ tag: "a", nativeAttributes: nativeAnchorAttributes, skipWarnings: __skipNativeAttributesWarnings }, buttonProps, { href: isNotInteractive ? undefined : href, role: isNotInteractive ? 'link' : undefined, tabIndex: getAnchorTabIndex(), target: target,
164
+ React.createElement(WithNativeAttributes, Object.assign({}, buttonProps, disabledReasonProps, { tag: "a", componentName: "Button", nativeAttributes: nativeAnchorAttributes, skipWarnings: __skipNativeAttributesWarnings, href: isNotInteractive ? undefined : href, role: isNotInteractive ? 'link' : undefined, tabIndex: getAnchorTabIndex(), target: target,
165
165
  // security recommendation: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#target
166
- rel: rel !== null && rel !== void 0 ? rel : (target === '_blank' ? 'noopener noreferrer' : undefined), "aria-disabled": isNotInteractive ? true : undefined, download: download }, disabledReasonProps, { style: stylePropertiesAndVariables }),
166
+ rel: rel !== null && rel !== void 0 ? rel : (target === '_blank' ? 'noopener noreferrer' : undefined), "aria-disabled": isNotInteractive ? true : undefined, download: download, style: stylePropertiesAndVariables }),
167
167
  buttonContent,
168
168
  isDisabledWithReason && disabledReasonContent),
169
169
  loading && loadingText && (React.createElement(InternalLiveRegion, { tagName: "span", hidden: true }, loadingText))));
170
170
  }
171
171
  return (React.createElement(React.Fragment, null,
172
- React.createElement(WithNativeAttributes, Object.assign({ tag: "button", nativeAttributes: nativeButtonAttributes, skipWarnings: __skipNativeAttributesWarnings }, buttonProps, { type: formAction === 'none' ? 'button' : 'submit', disabled: disabled && !__focusable && !isDisabledWithReason, "aria-disabled": hasAriaDisabled ? true : undefined }, disabledReasonProps, { style: stylePropertiesAndVariables }),
172
+ React.createElement(WithNativeAttributes, Object.assign({}, buttonProps, disabledReasonProps, { tag: "button", componentName: "Button", nativeAttributes: nativeButtonAttributes, skipWarnings: __skipNativeAttributesWarnings, type: formAction === 'none' ? 'button' : 'submit', disabled: disabled && !__focusable && !isDisabledWithReason, "aria-disabled": hasAriaDisabled ? true : undefined, style: stylePropertiesAndVariables }),
173
173
  buttonContent,
174
174
  isDisabledWithReason && disabledReasonContent),
175
175
  loading && loadingText && (React.createElement(InternalLiveRegion, { tagName: "span", hidden: true }, loadingText))));
@@ -1 +1 @@
1
- {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/button/internal.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC3D,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,+CAA+C,CAAC;AACpG,OAAO,EAAE,0BAA0B,EAAE,MAAM,+CAA+C,CAAC;AAC3F,OAAO,EACL,0BAA0B,EAC1B,6BAA6B,GAC9B,MAAM,kEAAkE,CAAC;AAE1E,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,IAAI,MAAM,kBAAkB,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AACpG,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,iCAAiC,CAAC;AACzC,OAAO,OAAO,MAAM,yCAAyC,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3E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B,EAAE,EAC7B,MAAM,EAAE,MAAM;gBACd,8FAA8F;gBAC9F,GAAG,EAAE,GAAG,aAAH,GAAG,cAAH,GAAG,GAAI,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,SAAS,CAAC,mBACtD,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,EAClD,QAAQ,EAAE,QAAQ,IACd,mBAAmB,IACvB,KAAK,EAAE,2BAA2B;gBAEjC,aAAa;gBACb,oBAAoB,IAAI,qBAAqB,CACzB;YACtB,OAAO,IAAI,WAAW,IAAI,CACzB,oBAAC,kBAAkB,IAAC,OAAO,EAAC,MAAM,EAAC,MAAM,EAAE,IAAI,IAC5C,WAAW,CACO,CACtB,CACA,CACJ,CAAC;KACH;IAED,OAAO,CACL;QACE,oBAAC,oBAAoB,kBACnB,GAAG,EAAC,QAAQ,EACZ,gBAAgB,EAAE,sBAAsB,EACxC,YAAY,EAAE,8BAA8B,IACxC,WAAW,IACf,IAAI,EAAE,UAAU,KAAK,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,EACjD,QAAQ,EAAE,QAAQ,IAAI,CAAC,WAAW,IAAI,CAAC,oBAAoB,mBAC5C,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,IAC7C,mBAAmB,IACvB,KAAK,EAAE,2BAA2B;YAEjC,aAAa;YACb,oBAAoB,IAAI,qBAAqB,CACzB;QACtB,OAAO,IAAI,WAAW,IAAI,CACzB,oBAAC,kBAAkB,IAAC,OAAO,EAAC,MAAM,EAAC,MAAM,EAAE,IAAI,IAC5C,WAAW,CACO,CACtB,CACA,CACJ,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,cAAc,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useEffect, useRef, useState } from 'react';\nimport clsx from 'clsx';\n\nimport { useMergeRefs, useUniqueId, warnOnce } from '@cloudscape-design/component-toolkit/internal';\nimport { useSingleTabStopNavigation } from '@cloudscape-design/component-toolkit/internal';\nimport {\n getAnalyticsLabelAttribute,\n getAnalyticsMetadataAttribute,\n} from '@cloudscape-design/component-toolkit/internal/analytics-metadata';\n\nimport { useInternalI18n } from '../i18n/context';\nimport Icon from '../icon/internal';\nimport { FunnelMetrics } from '../internal/analytics';\nimport { useFunnel, useFunnelStep, useFunnelSubStep } from '../internal/analytics/hooks/use-funnel';\nimport {\n DATA_ATTR_FUNNEL_VALUE,\n getFunnelValueSelector,\n getSubStepAllSelector,\n getTextFromSelector,\n} from '../internal/analytics/selectors';\nimport Tooltip from '../internal/components/tooltip/index.js';\nimport { useButtonContext } from '../internal/context/button-context';\nimport { fireCancelableEvent, isPlainLeftClick } from '../internal/events';\nimport useForwardFocus from '../internal/hooks/forward-focus';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component';\nimport useHiddenDescription from '../internal/hooks/use-hidden-description';\nimport { useModalContextLoadingButtonComponent } from '../internal/hooks/use-modal-component-analytics';\nimport { usePerformanceMarks } from '../internal/hooks/use-performance-marks';\nimport { checkSafeUrl } from '../internal/utils/check-safe-url';\nimport WithNativeAttributes from '../internal/utils/with-native-attributes';\nimport InternalLiveRegion from '../live-region/internal';\nimport { GeneratedAnalyticsMetadataButtonFragment } from './analytics-metadata/interfaces';\nimport { ButtonIconProps, LeftIcon, RightIcon } from './icon-helper';\nimport { ButtonProps } from './interfaces';\nimport { getButtonStyles } from './style';\n\nimport analyticsSelectors from './analytics-metadata/styles.css.js';\nimport styles from './styles.css.js';\nimport testUtilStyles from './test-classes/styles.css.js';\n\nexport type InternalButtonProps = Omit<ButtonProps, 'variant'> & {\n variant?:\n | ButtonProps['variant']\n | 'flashbar-icon'\n | 'breadcrumb-group'\n | 'menu-trigger'\n | 'modal-dismiss'\n | 'inline-icon-pointer-target';\n badge?: boolean;\n analyticsAction?: string;\n __iconClass?: string;\n __focusable?: boolean;\n __injectAnalyticsComponentMetadata?: boolean;\n __title?: string;\n __emitPerformanceMarks?: boolean;\n __skipNativeAttributesWarnings?: boolean;\n __hideFromTestUtils?: boolean;\n} & InternalBaseComponentProps;\n\nexport const InternalButton = React.forwardRef(\n (\n {\n children,\n iconName,\n __iconClass,\n onClick,\n onFollow,\n iconAlign = 'left',\n iconUrl,\n iconSvg,\n iconAlt,\n variant = 'normal',\n loading = false,\n loadingText,\n disabled = false,\n disabledReason,\n wrapText = true,\n href,\n external,\n target: targetOverride,\n rel,\n download,\n formAction = 'submit',\n ariaLabel,\n ariaDescribedby,\n ariaExpanded,\n ariaControls,\n fullWidth,\n badge,\n i18nStrings,\n style,\n nativeButtonAttributes,\n nativeAnchorAttributes,\n __internalRootRef,\n __focusable = false,\n __injectAnalyticsComponentMetadata = false,\n __title,\n __emitPerformanceMarks = true,\n __skipNativeAttributesWarnings,\n __hideFromTestUtils = false,\n analyticsAction = 'click',\n ...props\n }: InternalButtonProps,\n ref: React.Ref<ButtonProps.Ref>\n ) => {\n const [showTooltip, setShowTooltip] = useState(false);\n\n checkSafeUrl('Button', href);\n const isAnchor = Boolean(href);\n const target = targetOverride ?? (external ? '_blank' : undefined);\n const isNotInteractive = loading || disabled;\n const isDisabledWithReason =\n (variant === 'normal' || variant === 'primary' || variant === 'icon') && !!disabledReason && disabled;\n\n const hasAriaDisabled = (loading && !disabled) || (disabled && __focusable) || isDisabledWithReason;\n const shouldHaveContent =\n children &&\n ['icon', 'inline-icon', 'flashbar-icon', 'modal-dismiss', 'inline-icon-pointer-target'].indexOf(variant) === -1;\n\n if ((iconName || iconUrl || iconSvg) && iconAlign === 'right' && external) {\n warnOnce('Button', 'A right-aligned icon should not be combined with an external icon.');\n }\n\n const buttonRef = useRef<HTMLElement>(null);\n useForwardFocus(ref, buttonRef);\n\n const buttonContext = useButtonContext();\n const i18n = useInternalI18n('button');\n\n const uniqueId = useUniqueId('button');\n const { funnelInteractionId } = useFunnel();\n const { stepNumber, stepNameSelector } = useFunnelStep();\n const { subStepSelector, subStepNameSelector } = useFunnelSubStep();\n\n const performanceMarkAttributes = usePerformanceMarks(\n 'primaryButton',\n () => variant === 'primary' && __emitPerformanceMarks && !loading && !disabled,\n buttonRef,\n () => ({\n loading,\n disabled,\n text: buttonRef.current?.innerText,\n }),\n [loading, disabled]\n );\n useModalContextLoadingButtonComponent(variant === 'primary', loading);\n\n const { targetProps, descriptionEl } = useHiddenDescription(disabledReason);\n\n const handleClick = (event: React.MouseEvent) => {\n if (isNotInteractive) {\n return event.preventDefault();\n }\n\n if (isAnchor && isPlainLeftClick(event)) {\n fireCancelableEvent(onFollow, { href, target }, event);\n\n if ((iconName === 'external' || target === '_blank') && funnelInteractionId) {\n const stepName = getTextFromSelector(stepNameSelector);\n const subStepName = getTextFromSelector(subStepNameSelector);\n\n FunnelMetrics.externalLinkInteracted({\n funnelInteractionId,\n stepNumber,\n stepName,\n stepNameSelector,\n subStepSelector,\n subStepName,\n subStepNameSelector,\n elementSelector: getFunnelValueSelector(uniqueId),\n subStepAllSelector: getSubStepAllSelector(),\n });\n }\n }\n\n const { altKey, button, ctrlKey, metaKey, shiftKey } = event;\n fireCancelableEvent(onClick, { altKey, button, ctrlKey, metaKey, shiftKey }, event);\n buttonContext.onClick({ variant });\n };\n\n const buttonClass = clsx(props.className, styles.button, styles[`variant-${variant}`], {\n [testUtilStyles.button]: !__hideFromTestUtils,\n [styles.disabled]: isNotInteractive,\n [styles['disabled-with-reason']]: isDisabledWithReason,\n [styles['button-no-wrap']]: !wrapText,\n [styles['button-no-text']]: !shouldHaveContent,\n [styles['full-width']]: shouldHaveContent && fullWidth,\n [styles.link]: isAnchor,\n });\n\n const explicitTabIndex = nativeButtonAttributes?.tabIndex ?? nativeAnchorAttributes?.tabIndex;\n const { tabIndex } = useSingleTabStopNavigation(buttonRef, {\n tabIndex: isAnchor && isNotInteractive && !isDisabledWithReason ? -1 : explicitTabIndex,\n });\n\n const analyticsMetadata: GeneratedAnalyticsMetadataButtonFragment = disabled\n ? {}\n : {\n action: analyticsAction,\n detail: { label: { root: 'self' } },\n };\n if (__injectAnalyticsComponentMetadata) {\n analyticsMetadata.component = {\n name: 'awsui.Button',\n label: { root: 'self' },\n properties: { variant, disabled: `${disabled}` },\n };\n }\n\n const buttonProps = {\n ...props,\n ...performanceMarkAttributes,\n tabIndex,\n // https://github.com/microsoft/TypeScript/issues/36659\n ref: useMergeRefs(buttonRef, __internalRootRef),\n 'aria-label': ariaLabel,\n 'aria-describedby': ariaDescribedby,\n 'aria-expanded': ariaExpanded,\n 'aria-controls': ariaControls,\n // add ariaLabel as `title` as visible hint text\n title: __title ?? ariaLabel,\n className: buttonClass,\n onClick: handleClick,\n [DATA_ATTR_FUNNEL_VALUE]: uniqueId,\n ...getAnalyticsMetadataAttribute(analyticsMetadata),\n ...getAnalyticsLabelAttribute(shouldHaveContent ? `.${analyticsSelectors.label}` : ''),\n } as const;\n\n const iconProps: ButtonIconProps = {\n loading,\n iconName,\n iconAlign,\n iconUrl,\n iconSvg,\n iconAlt,\n variant,\n badge,\n iconClass: __iconClass,\n iconSize: variant === 'modal-dismiss' ? 'medium' : 'normal',\n };\n const buttonContent = (\n <>\n <LeftIcon {...iconProps} />\n {shouldHaveContent && (\n <>\n <span className={clsx(testUtilStyles.content, analyticsSelectors.label)}>{children}</span>\n {external && (\n <>\n &nbsp;\n <Icon\n name=\"external\"\n className={testUtilStyles['external-icon']}\n ariaLabel={i18n('i18nStrings.externalIconAriaLabel', i18nStrings?.externalIconAriaLabel)}\n />\n </>\n )}\n </>\n )}\n <RightIcon {...iconProps} />\n </>\n );\n\n const { loadingButtonCount } = useFunnel();\n useEffect(() => {\n if (loading) {\n loadingButtonCount.current++;\n return () => {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n loadingButtonCount.current--;\n };\n }\n }, [loading, loadingButtonCount]);\n\n const disabledReasonProps = {\n onFocus: isDisabledWithReason ? () => setShowTooltip(true) : undefined,\n onBlur: isDisabledWithReason ? () => setShowTooltip(false) : undefined,\n onMouseEnter: isDisabledWithReason ? () => setShowTooltip(true) : undefined,\n onMouseLeave: isDisabledWithReason ? () => setShowTooltip(false) : undefined,\n ...(isDisabledWithReason ? targetProps : {}),\n };\n const disabledReasonContent = (\n <>\n {descriptionEl}\n {showTooltip && (\n <Tooltip\n className={testUtilStyles['disabled-reason-tooltip']}\n trackRef={buttonRef}\n value={disabledReason!}\n onDismiss={() => setShowTooltip(false)}\n />\n )}\n </>\n );\n\n const stylePropertiesAndVariables = getButtonStyles(style);\n\n if (isAnchor) {\n const getAnchorTabIndex = () => {\n if (isNotInteractive) {\n // If disabled with a reason, make it focusable so users can access the tooltip\n // Otherwise, resolve to the default button props tabIndex.\n return disabledReason ? 0 : buttonProps.tabIndex;\n }\n return buttonProps.tabIndex;\n };\n\n return (\n <>\n <WithNativeAttributes<HTMLAnchorElement, React.AnchorHTMLAttributes<HTMLAnchorElement>>\n tag=\"a\"\n nativeAttributes={nativeAnchorAttributes}\n skipWarnings={__skipNativeAttributesWarnings}\n {...buttonProps}\n href={isNotInteractive ? undefined : href}\n role={isNotInteractive ? 'link' : undefined}\n tabIndex={getAnchorTabIndex()}\n target={target}\n // security recommendation: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#target\n rel={rel ?? (target === '_blank' ? 'noopener noreferrer' : undefined)}\n aria-disabled={isNotInteractive ? true : undefined}\n download={download}\n {...disabledReasonProps}\n style={stylePropertiesAndVariables}\n >\n {buttonContent}\n {isDisabledWithReason && disabledReasonContent}\n </WithNativeAttributes>\n {loading && loadingText && (\n <InternalLiveRegion tagName=\"span\" hidden={true}>\n {loadingText}\n </InternalLiveRegion>\n )}\n </>\n );\n }\n\n return (\n <>\n <WithNativeAttributes<HTMLButtonElement, React.ButtonHTMLAttributes<HTMLButtonElement>>\n tag=\"button\"\n nativeAttributes={nativeButtonAttributes}\n skipWarnings={__skipNativeAttributesWarnings}\n {...buttonProps}\n type={formAction === 'none' ? 'button' : 'submit'}\n disabled={disabled && !__focusable && !isDisabledWithReason}\n aria-disabled={hasAriaDisabled ? true : undefined}\n {...disabledReasonProps}\n style={stylePropertiesAndVariables}\n >\n {buttonContent}\n {isDisabledWithReason && disabledReasonContent}\n </WithNativeAttributes>\n {loading && loadingText && (\n <InternalLiveRegion tagName=\"span\" hidden={true}>\n {loadingText}\n </InternalLiveRegion>\n )}\n </>\n );\n }\n);\n\nexport default InternalButton;\n"]}
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/button/internal.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC3D,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,+CAA+C,CAAC;AACpG,OAAO,EAAE,0BAA0B,EAAE,MAAM,+CAA+C,CAAC;AAC3F,OAAO,EACL,0BAA0B,EAC1B,6BAA6B,GAC9B,MAAM,kEAAkE,CAAC;AAE1E,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,IAAI,MAAM,kBAAkB,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AACpG,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,iCAAiC,CAAC;AACzC,OAAO,OAAO,MAAM,yCAAyC,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,eAAe,MAAM,iCAAiC,CAAC;AAE9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iB,EAAE,EAC7B,MAAM,EAAE,MAAM;gBACd,8FAA8F;gBAC9F,GAAG,EAAE,GAAG,aAAH,GAAG,cAAH,GAAG,GAAI,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,SAAS,CAAC,mBACtD,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,EAClD,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,2BAA2B;gBAEjC,aAAa;gBACb,oBAAoB,IAAI,qBAAqB,CACzB;YACtB,OAAO,IAAI,WAAW,IAAI,CACzB,oBAAC,kBAAkB,IAAC,OAAO,EAAC,MAAM,EAAC,MAAM,EAAE,IAAI,IAC5C,WAAW,CACO,CACtB,CACA,CACJ,CAAC;KACH;IAED,OAAO,CACL;QACE,oBAAC,oBAAoB,oBACf,WAAW,EACX,mBAAmB,IACvB,GAAG,EAAC,QAAQ,EACZ,aAAa,EAAC,QAAQ,EACtB,gBAAgB,EAAE,sBAAsB,EACxC,YAAY,EAAE,8BAA8B,EAC5C,IAAI,EAAE,UAAU,KAAK,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,EACjD,QAAQ,EAAE,QAAQ,IAAI,CAAC,WAAW,IAAI,CAAC,oBAAoB,mBAC5C,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,EACjD,KAAK,EAAE,2BAA2B;YAEjC,aAAa;YACb,oBAAoB,IAAI,qBAAqB,CACzB;QACtB,OAAO,IAAI,WAAW,IAAI,CACzB,oBAAC,kBAAkB,IAAC,OAAO,EAAC,MAAM,EAAC,MAAM,EAAE,IAAI,IAC5C,WAAW,CACO,CACtB,CACA,CACJ,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,cAAc,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useEffect, useRef, useState } from 'react';\nimport clsx from 'clsx';\n\nimport { useMergeRefs, useUniqueId, warnOnce } from '@cloudscape-design/component-toolkit/internal';\nimport { useSingleTabStopNavigation } from '@cloudscape-design/component-toolkit/internal';\nimport {\n getAnalyticsLabelAttribute,\n getAnalyticsMetadataAttribute,\n} from '@cloudscape-design/component-toolkit/internal/analytics-metadata';\n\nimport { useInternalI18n } from '../i18n/context';\nimport Icon from '../icon/internal';\nimport { FunnelMetrics } from '../internal/analytics';\nimport { useFunnel, useFunnelStep, useFunnelSubStep } from '../internal/analytics/hooks/use-funnel';\nimport {\n DATA_ATTR_FUNNEL_VALUE,\n getFunnelValueSelector,\n getSubStepAllSelector,\n getTextFromSelector,\n} from '../internal/analytics/selectors';\nimport Tooltip from '../internal/components/tooltip/index.js';\nimport { useButtonContext } from '../internal/context/button-context';\nimport { fireCancelableEvent, isPlainLeftClick } from '../internal/events';\nimport useForwardFocus from '../internal/hooks/forward-focus';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component';\nimport useHiddenDescription from '../internal/hooks/use-hidden-description';\nimport { useModalContextLoadingButtonComponent } from '../internal/hooks/use-modal-component-analytics';\nimport { usePerformanceMarks } from '../internal/hooks/use-performance-marks';\nimport { checkSafeUrl } from '../internal/utils/check-safe-url';\nimport WithNativeAttributes from '../internal/utils/with-native-attributes';\nimport InternalLiveRegion from '../live-region/internal';\nimport { GeneratedAnalyticsMetadataButtonFragment } from './analytics-metadata/interfaces';\nimport { ButtonIconProps, LeftIcon, RightIcon } from './icon-helper';\nimport { ButtonProps } from './interfaces';\nimport { getButtonStyles } from './style';\n\nimport analyticsSelectors from './analytics-metadata/styles.css.js';\nimport styles from './styles.css.js';\nimport testUtilStyles from './test-classes/styles.css.js';\n\nexport type InternalButtonProps = Omit<ButtonProps, 'variant'> & {\n variant?:\n | ButtonProps['variant']\n | 'flashbar-icon'\n | 'breadcrumb-group'\n | 'menu-trigger'\n | 'modal-dismiss'\n | 'inline-icon-pointer-target';\n badge?: boolean;\n analyticsAction?: string;\n __iconClass?: string;\n __focusable?: boolean;\n __injectAnalyticsComponentMetadata?: boolean;\n __title?: string;\n __emitPerformanceMarks?: boolean;\n __skipNativeAttributesWarnings?: boolean;\n __hideFromTestUtils?: boolean;\n} & InternalBaseComponentProps;\n\nexport const InternalButton = React.forwardRef(\n (\n {\n children,\n iconName,\n __iconClass,\n onClick,\n onFollow,\n iconAlign = 'left',\n iconUrl,\n iconSvg,\n iconAlt,\n variant = 'normal',\n loading = false,\n loadingText,\n disabled = false,\n disabledReason,\n wrapText = true,\n href,\n external,\n target: targetOverride,\n rel,\n download,\n formAction = 'submit',\n ariaLabel,\n ariaDescribedby,\n ariaExpanded,\n ariaControls,\n fullWidth,\n badge,\n i18nStrings,\n style,\n nativeButtonAttributes,\n nativeAnchorAttributes,\n __internalRootRef,\n __focusable = false,\n __injectAnalyticsComponentMetadata = false,\n __title,\n __emitPerformanceMarks = true,\n __skipNativeAttributesWarnings,\n __hideFromTestUtils = false,\n analyticsAction = 'click',\n ...props\n }: InternalButtonProps,\n ref: React.Ref<ButtonProps.Ref>\n ) => {\n const [showTooltip, setShowTooltip] = useState(false);\n\n checkSafeUrl('Button', href);\n const isAnchor = Boolean(href);\n const target = targetOverride ?? (external ? '_blank' : undefined);\n const isNotInteractive = loading || disabled;\n const isDisabledWithReason =\n (variant === 'normal' || variant === 'primary' || variant === 'icon') && !!disabledReason && disabled;\n\n const hasAriaDisabled = (loading && !disabled) || (disabled && __focusable) || isDisabledWithReason;\n const shouldHaveContent =\n children &&\n ['icon', 'inline-icon', 'flashbar-icon', 'modal-dismiss', 'inline-icon-pointer-target'].indexOf(variant) === -1;\n\n if ((iconName || iconUrl || iconSvg) && iconAlign === 'right' && external) {\n warnOnce('Button', 'A right-aligned icon should not be combined with an external icon.');\n }\n\n const buttonRef = useRef<HTMLElement>(null);\n useForwardFocus(ref, buttonRef);\n\n const buttonContext = useButtonContext();\n const i18n = useInternalI18n('button');\n\n const uniqueId = useUniqueId('button');\n const { funnelInteractionId } = useFunnel();\n const { stepNumber, stepNameSelector } = useFunnelStep();\n const { subStepSelector, subStepNameSelector } = useFunnelSubStep();\n\n const performanceMarkAttributes = usePerformanceMarks(\n 'primaryButton',\n () => variant === 'primary' && __emitPerformanceMarks && !loading && !disabled,\n buttonRef,\n () => ({\n loading,\n disabled,\n text: buttonRef.current?.innerText,\n }),\n [loading, disabled]\n );\n useModalContextLoadingButtonComponent(variant === 'primary', loading);\n\n const { targetProps, descriptionEl } = useHiddenDescription(disabledReason);\n\n const handleClick = (event: React.MouseEvent) => {\n if (isNotInteractive) {\n return event.preventDefault();\n }\n\n if (isAnchor && isPlainLeftClick(event)) {\n fireCancelableEvent(onFollow, { href, target }, event);\n\n if ((iconName === 'external' || target === '_blank') && funnelInteractionId) {\n const stepName = getTextFromSelector(stepNameSelector);\n const subStepName = getTextFromSelector(subStepNameSelector);\n\n FunnelMetrics.externalLinkInteracted({\n funnelInteractionId,\n stepNumber,\n stepName,\n stepNameSelector,\n subStepSelector,\n subStepName,\n subStepNameSelector,\n elementSelector: getFunnelValueSelector(uniqueId),\n subStepAllSelector: getSubStepAllSelector(),\n });\n }\n }\n\n const { altKey, button, ctrlKey, metaKey, shiftKey } = event;\n fireCancelableEvent(onClick, { altKey, button, ctrlKey, metaKey, shiftKey }, event);\n buttonContext.onClick({ variant });\n };\n\n const buttonClass = clsx(props.className, styles.button, styles[`variant-${variant}`], {\n [testUtilStyles.button]: !__hideFromTestUtils,\n [styles.disabled]: isNotInteractive,\n [styles['disabled-with-reason']]: isDisabledWithReason,\n [styles['button-no-wrap']]: !wrapText,\n [styles['button-no-text']]: !shouldHaveContent,\n [styles['full-width']]: shouldHaveContent && fullWidth,\n [styles.link]: isAnchor,\n });\n\n const explicitTabIndex = nativeButtonAttributes?.tabIndex ?? nativeAnchorAttributes?.tabIndex;\n const { tabIndex } = useSingleTabStopNavigation(buttonRef, {\n tabIndex: isAnchor && isNotInteractive && !isDisabledWithReason ? -1 : explicitTabIndex,\n });\n\n const analyticsMetadata: GeneratedAnalyticsMetadataButtonFragment = disabled\n ? {}\n : {\n action: analyticsAction,\n detail: { label: { root: 'self' } },\n };\n if (__injectAnalyticsComponentMetadata) {\n analyticsMetadata.component = {\n name: 'awsui.Button',\n label: { root: 'self' },\n properties: { variant, disabled: `${disabled}` },\n };\n }\n\n const buttonProps = {\n ...props,\n ...performanceMarkAttributes,\n tabIndex,\n // https://github.com/microsoft/TypeScript/issues/36659\n ref: useMergeRefs(buttonRef, __internalRootRef),\n 'aria-label': ariaLabel,\n 'aria-describedby': ariaDescribedby,\n 'aria-expanded': ariaExpanded,\n 'aria-controls': ariaControls,\n // add ariaLabel as `title` as visible hint text\n title: __title ?? ariaLabel,\n className: buttonClass,\n onClick: handleClick,\n [DATA_ATTR_FUNNEL_VALUE]: uniqueId,\n ...getAnalyticsMetadataAttribute(analyticsMetadata),\n ...getAnalyticsLabelAttribute(shouldHaveContent ? `.${analyticsSelectors.label}` : ''),\n } as const;\n\n const iconProps: ButtonIconProps = {\n loading,\n iconName,\n iconAlign,\n iconUrl,\n iconSvg,\n iconAlt,\n variant,\n badge,\n iconClass: __iconClass,\n iconSize: variant === 'modal-dismiss' ? 'medium' : 'normal',\n };\n const buttonContent = (\n <>\n <LeftIcon {...iconProps} />\n {shouldHaveContent && (\n <>\n <span className={clsx(testUtilStyles.content, analyticsSelectors.label)}>{children}</span>\n {external && (\n <>\n &nbsp;\n <Icon\n name=\"external\"\n className={testUtilStyles['external-icon']}\n ariaLabel={i18n('i18nStrings.externalIconAriaLabel', i18nStrings?.externalIconAriaLabel)}\n />\n </>\n )}\n </>\n )}\n <RightIcon {...iconProps} />\n </>\n );\n\n const { loadingButtonCount } = useFunnel();\n useEffect(() => {\n if (loading) {\n loadingButtonCount.current++;\n return () => {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n loadingButtonCount.current--;\n };\n }\n }, [loading, loadingButtonCount]);\n\n const disabledReasonProps = {\n onFocus: isDisabledWithReason ? () => setShowTooltip(true) : undefined,\n onBlur: isDisabledWithReason ? () => setShowTooltip(false) : undefined,\n onMouseEnter: isDisabledWithReason ? () => setShowTooltip(true) : undefined,\n onMouseLeave: isDisabledWithReason ? () => setShowTooltip(false) : undefined,\n ...(isDisabledWithReason ? targetProps : {}),\n };\n const disabledReasonContent = (\n <>\n {descriptionEl}\n {showTooltip && (\n <Tooltip\n className={testUtilStyles['disabled-reason-tooltip']}\n trackRef={buttonRef}\n value={disabledReason!}\n onDismiss={() => setShowTooltip(false)}\n />\n )}\n </>\n );\n\n const stylePropertiesAndVariables = getButtonStyles(style);\n\n if (isAnchor) {\n const getAnchorTabIndex = () => {\n if (isNotInteractive) {\n // If disabled with a reason, make it focusable so users can access the tooltip\n // Otherwise, resolve to the default button props tabIndex.\n return disabledReason ? 0 : buttonProps.tabIndex;\n }\n return buttonProps.tabIndex;\n };\n\n return (\n <>\n <WithNativeAttributes<HTMLAnchorElement, React.AnchorHTMLAttributes<HTMLAnchorElement>>\n {...buttonProps}\n {...disabledReasonProps}\n tag=\"a\"\n componentName=\"Button\"\n nativeAttributes={nativeAnchorAttributes}\n skipWarnings={__skipNativeAttributesWarnings}\n href={isNotInteractive ? undefined : href}\n role={isNotInteractive ? 'link' : undefined}\n tabIndex={getAnchorTabIndex()}\n target={target}\n // security recommendation: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#target\n rel={rel ?? (target === '_blank' ? 'noopener noreferrer' : undefined)}\n aria-disabled={isNotInteractive ? true : undefined}\n download={download}\n style={stylePropertiesAndVariables}\n >\n {buttonContent}\n {isDisabledWithReason && disabledReasonContent}\n </WithNativeAttributes>\n {loading && loadingText && (\n <InternalLiveRegion tagName=\"span\" hidden={true}>\n {loadingText}\n </InternalLiveRegion>\n )}\n </>\n );\n }\n\n return (\n <>\n <WithNativeAttributes<HTMLButtonElement, React.ButtonHTMLAttributes<HTMLButtonElement>>\n {...buttonProps}\n {...disabledReasonProps}\n tag=\"button\"\n componentName=\"Button\"\n nativeAttributes={nativeButtonAttributes}\n skipWarnings={__skipNativeAttributesWarnings}\n type={formAction === 'none' ? 'button' : 'submit'}\n disabled={disabled && !__focusable && !isDisabledWithReason}\n aria-disabled={hasAriaDisabled ? true : undefined}\n style={stylePropertiesAndVariables}\n >\n {buttonContent}\n {isDisabledWithReason && disabledReasonContent}\n </WithNativeAttributes>\n {loading && loadingText && (\n <InternalLiveRegion tagName=\"span\" hidden={true}>\n {loadingText}\n </InternalLiveRegion>\n )}\n </>\n );\n }\n);\n\nexport default InternalButton;\n"]}
@@ -3,7 +3,7 @@ export type TreeIndex = number[];
3
3
  interface ItemsTreeApi {
4
4
  getItem: (index: TreeIndex) => ButtonDropdownProps.ItemOrGroup | null;
5
5
  getItemIndex: (item: ButtonDropdownProps.ItemOrGroup) => TreeIndex;
6
- getSequentialIndex: (index: TreeIndex, direction: -1 | 1) => TreeIndex | null;
6
+ getSequentialIndex: (index: TreeIndex, direction: -1 | 1, loop?: boolean) => TreeIndex | null;
7
7
  getParentIndex: (item: ButtonDropdownProps.ItemOrGroup) => TreeIndex | null;
8
8
  }
9
9
  export default function createItemsTree(items: ButtonDropdownProps.Items): ItemsTreeApi;
@@ -1 +1 @@
1
- {"version":3,"file":"create-items-tree.d.ts","sourceRoot":"","sources":["../../../../src/button-dropdown/utils/create-items-tree.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAOpD,MAAM,MAAM,SAAS,GAAG,MAAM,EAAE,CAAC;AAEjC,UAAU,YAAY;IAEpB,OAAO,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,mBAAmB,CAAC,WAAW,GAAG,IAAI,CAAC;IAGtE,YAAY,EAAE,CAAC,IAAI,EAAE,mBAAmB,CAAC,WAAW,KAAK,SAAS,CAAC;IAEnE,kBAAkB,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,SAAS,GAAG,IAAI,CAAC;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IAAI,EACtE,WAAW,GAAE,SAAc,QAU5B"}
@@ -21,10 +21,19 @@ export default function createItemsTree(items) {
21
21
  }
22
22
  return parseIndex(indexKey);
23
23
  },
24
- getSequentialIndex: (index, direction) => {
24
+ getSequentialIndex: (index, direction, loop = false) => {
25
25
  const indexKey = stringifyIndex(index);
26
26
  const position = flatIndices.indexOf(indexKey);
27
- const nextIndexKey = flatIndices[position + direction];
27
+ let nextIndex = position + direction;
28
+ if (loop) {
29
+ if (nextIndex < 0) {
30
+ nextIndex = flatIndices.length - 1;
31
+ }
32
+ else if (nextIndex >= flatIndices.length) {
33
+ nextIndex = 0;
34
+ }
35
+ }
36
+ const nextIndexKey = flatIndices[nextIndex];
28
37
  if (!nextIndexKey) {
29
38
  return null;
30
39
  }
@@ -1 +1 @@
1
- {"version":3,"file":"create-items-tree.js","sourceRoot":"","sources":["../../../../src/button-dropdown/utils/create-items-tree.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAoBtC,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,KAAgC;IACtE,MAAM,WAAW,GAAG,IAAI,GAAG,EAA2C,CAAC;IACvE,MAAM,WAAW,GAAG,IAAI,GAAG,EAA2C,CAAC;IACvE,MAAM,WAAW,GAAa,EAAE,CAAC;IAEjC,aAAa,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QACnC,MAAM,QAAQ,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;QACvC,WAAW,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAChC,WAAW,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAChC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,OAAO,EAAE,CAAC,KAAgB,EAA0C,EAAE;YACpE,MAAM,QAAQ,GAAG,cAAc,CAAC,KAAK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,GAAsE,EACtE,cAAyB,EAAE;IAE3B,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QAC5B,MAAM,SAAS,GAAG,CAAC,GAAG,WAAW,EAAE,KAAK,CAAC,CAAC;QAC1C,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QAErB,IAAI,WAAW,CAAC,IAAI,CAAC,EAAE;YACrB,aAAa,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC;SAC3C;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,cAAc,CAAC,KAAgB;IACtC,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC;AAED,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;AAClD,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { ButtonDropdownProps } from '../interfaces';\nimport { isItemGroup } from './utils';\n\n// The function turns a tree of items into a structure optimized for lookup of\n// items and corresponding indices as well as iteration on indices in the given order.\n\n// As trees are multidimensional, the index is represented as an array\nexport type TreeIndex = number[];\n\ninterface ItemsTreeApi {\n // Returns an item for the given tree index or null if not found\n getItem: (index: TreeIndex) => ButtonDropdownProps.ItemOrGroup | null;\n // Returns the tree index of the given item. The item must be present\n // in the tree (referential comparison), or an error will be thrown\n getItemIndex: (item: ButtonDropdownProps.ItemOrGroup) => TreeIndex;\n // Returns the index of next or previous sequential node or null if out of bounds\n getSequentialIndex: (index: TreeIndex, direction: -1 | 1) => TreeIndex | null;\n // Returns parent tree index of a given item or null if no parent is present\n getParentIndex: (item: ButtonDropdownProps.ItemOrGroup) => TreeIndex | null;\n}\n\nexport default function createItemsTree(items: ButtonDropdownProps.Items): ItemsTreeApi {\n const itemToIndex = new Map<ButtonDropdownProps.ItemOrGroup, string>();\n const indexToItem = new Map<string, ButtonDropdownProps.ItemOrGroup>();\n const flatIndices: string[] = [];\n\n traverseItems(items, (item, index) => {\n const indexKey = stringifyIndex(index);\n itemToIndex.set(item, indexKey);\n indexToItem.set(indexKey, item);\n flatIndices.push(indexKey);\n });\n\n return {\n getItem: (index: TreeIndex): ButtonDropdownProps.ItemOrGroup | null => {\n const indexKey = stringifyIndex(index);\n\n return indexToItem.get(indexKey) || null;\n },\n getItemIndex: (item: ButtonDropdownProps.ItemOrGroup): TreeIndex => {\n const indexKey = itemToIndex.get(item);\n\n if (!indexKey) {\n throw new Error('Invariant violation: item is not found.');\n }\n\n return parseIndex(indexKey);\n },\n getSequentialIndex: (index: TreeIndex, direction: -1 | 1): TreeIndex | null => {\n const indexKey = stringifyIndex(index);\n const position = flatIndices.indexOf(indexKey);\n\n const nextIndexKey = flatIndices[position + direction];\n\n if (!nextIndexKey) {\n return null;\n }\n\n return parseIndex(nextIndexKey);\n },\n getParentIndex: (item: ButtonDropdownProps.ItemOrGroup): TreeIndex | null => {\n const indexKey = itemToIndex.get(item);\n\n if (!indexKey) {\n throw new Error('Invariant violation: item is not found.');\n }\n\n const index = parseIndex(indexKey);\n\n // No parent\n if (index.length === 1) {\n return null;\n }\n\n return index.slice(0, index.length - 1);\n },\n };\n}\n\nexport function traverseItems(\n items: ButtonDropdownProps.Items,\n act: (item: ButtonDropdownProps.ItemOrGroup, index: TreeIndex) => void,\n parentIndex: TreeIndex = []\n) {\n items.forEach((item, index) => {\n const itemIndex = [...parentIndex, index];\n act(item, itemIndex);\n\n if (isItemGroup(item)) {\n traverseItems(item.items, act, itemIndex);\n }\n });\n}\n\nfunction stringifyIndex(index: TreeIndex): string {\n return index.join('-');\n}\n\nfunction parseIndex(index: string): TreeIndex {\n return index.split('-').map(it => parseInt(it));\n}\n"]}
1
+ {"version":3,"file":"create-items-tree.js","s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C,EAAE;YACrB,aAAa,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC;SAC3C;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,cAAc,CAAC,KAAgB;IACtC,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC;AAED,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;AAClD,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { ButtonDropdownProps } from '../interfaces';\nimport { isItemGroup } from './utils';\n\n// The function turns a tree of items into a structure optimized for lookup of\n// items and corresponding indices as well as iteration on indices in the given order.\n\n// As trees are multidimensional, the index is represented as an array\nexport type TreeIndex = number[];\n\ninterface ItemsTreeApi {\n // Returns an item for the given tree index or null if not found\n getItem: (index: TreeIndex) => ButtonDropdownProps.ItemOrGroup | null;\n // Returns the tree index of the given item. The item must be present\n // in the tree (referential comparison), or an error will be thrown\n getItemIndex: (item: ButtonDropdownProps.ItemOrGroup) => TreeIndex;\n // Returns the index of next or previous sequential node or null if out of bounds\n getSequentialIndex: (index: TreeIndex, direction: -1 | 1, loop?: boolean) => TreeIndex | null;\n // Returns parent tree index of a given item or null if no parent is present\n getParentIndex: (item: ButtonDropdownProps.ItemOrGroup) => TreeIndex | null;\n}\n\nexport default function createItemsTree(items: ButtonDropdownProps.Items): ItemsTreeApi {\n const itemToIndex = new Map<ButtonDropdownProps.ItemOrGroup, string>();\n const indexToItem = new Map<string, ButtonDropdownProps.ItemOrGroup>();\n const flatIndices: string[] = [];\n\n traverseItems(items, (item, index) => {\n const indexKey = stringifyIndex(index);\n itemToIndex.set(item, indexKey);\n indexToItem.set(indexKey, item);\n flatIndices.push(indexKey);\n });\n\n return {\n getItem: (index: TreeIndex): ButtonDropdownProps.ItemOrGroup | null => {\n const indexKey = stringifyIndex(index);\n\n return indexToItem.get(indexKey) || null;\n },\n getItemIndex: (item: ButtonDropdownProps.ItemOrGroup): TreeIndex => {\n const indexKey = itemToIndex.get(item);\n\n if (!indexKey) {\n throw new Error('Invariant violation: item is not found.');\n }\n\n return parseIndex(indexKey);\n },\n getSequentialIndex: (index: TreeIndex, direction: -1 | 1, loop = false): TreeIndex | null => {\n const indexKey = stringifyIndex(index);\n const position = flatIndices.indexOf(indexKey);\n\n let nextIndex = position + direction;\n if (loop) {\n if (nextIndex < 0) {\n nextIndex = flatIndices.length - 1;\n } else if (nextIndex >= flatIndices.length) {\n nextIndex = 0;\n }\n }\n const nextIndexKey = flatIndices[nextIndex];\n\n if (!nextIndexKey) {\n return null;\n }\n\n return parseIndex(nextIndexKey);\n },\n getParentIndex: (item: ButtonDropdownProps.ItemOrGroup): TreeIndex | null => {\n const indexKey = itemToIndex.get(item);\n\n if (!indexKey) {\n throw new Error('Invariant violation: item is not found.');\n }\n\n const index = parseIndex(indexKey);\n\n // No parent\n if (index.length === 1) {\n return null;\n }\n\n return index.slice(0, index.length - 1);\n },\n };\n}\n\nexport function traverseItems(\n items: ButtonDropdownProps.Items,\n act: (item: ButtonDropdownProps.ItemOrGroup, index: TreeIndex) => void,\n parentIndex: TreeIndex = []\n) {\n items.forEach((item, index) => {\n const itemIndex = [...parentIndex, index];\n act(item, itemIndex);\n\n if (isItemGroup(item)) {\n traverseItems(item.items, act, itemIndex);\n }\n });\n}\n\nfunction stringifyIndex(index: TreeIndex): string {\n return index.join('-');\n}\n\nfunction parseIndex(index: string): TreeIndex {\n return index.split('-').map(it => parseInt(it));\n}\n"]}
@@ -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,KAAK,MAAM,OAAO,CAA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erticalNavigation = (direction) => {
43
- if (isOpen) {
44
- moveHighlight(direction);
45
- }
46
- };
47
42
  const openAndSelectFirst = (event) => {
48
43
  toggleDropdown();
49
44
  event.preventDefault();
@@ -80,12 +75,24 @@ export function useButtonDropdown({ items, onItemClick, onItemFollow, onReturnFo
80
75
  setIsUsingMouse(false);
81
76
  switch (event.keyCode) {
82
77
  case KeyCode.down: {
83
- doVerticalNavigation(1);
78
+ if (!isOpen) {
79
+ toggleDropdown();
80
+ moveHighlight(1, true);
81
+ }
82
+ else {
83
+ moveHighlight(1);
84
+ }
84
85
  event.preventDefault();
85
86
  break;
86
87
  }
87
88
  case KeyCode.up: {
88
- doVerticalNavigation(-1);
89
+ if (!isOpen) {
90
+ toggleDropdown();
91
+ moveHighlight(-1, true);
92
+ }
93
+ else {
94
+ moveHighlight(-1);
95
+ }
89
96
  event.preventDefault();
90
97
  break;
91
98
  }
@@ -1 +1 @@
1
- {"version":3,"file":"use-button-dropdown.js","sourceRoot":"","sources":["../../../../src/button-dropdown/utils/use-button-dropdown.ts"],"names":[],"mappings":";AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,6DAA6D,CAAC;AAC3F,OAAO,EAA0B,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACtG,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEjD,OAAO,kBAAkB,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAqBjF,MAAM,UAAU,iBAAiB,CAAC,EAChC,KAAK,EACL,WAAW,EACX,YAAY,EACZ,aAAa,EACb,mBAAmB,EACnB,kBAAkB,GAAG,KAAK,EAC1B,gBAAgB,GAAG,KAAK,GACC;IACzB,MAAM,EACJ,UAAU,EACV,aAAa,EACb,mBAAmB,EACnB,UAAU,EACV,aAAa,EACb,aAAa,EACb,WAAW,EACX,aAAa,EACb,KAAK,EACL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gBAChB,KAAK,CAAC,cAAc,EAAE,CAAC;gBACvB,IAAI,MAAM,EAAE;oBACV,KAAK,CAAC,eAAe,EAAE,CAAC;iBACzB;gBACD,MAAM;aACP;YACD,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;gBAChB,gFAAgF;gBAChF,8CAA8C;gBAC9C,IAAI,gBAAgB,EAAE;oBACpB,aAAa,EAAE,CAAC;iBACjB;gBACD,aAAa,EAAE,CAAC;gBAChB,MAAM;aACP;SACF;IACH,CAAC,CAAC;IACF,MAAM,OAAO,GAAG,CAAC,KAA0B,EAAE,EAAE;QAC7C,kFAAkF;QAClF,mFAAmF;QACnF,mGAAmG;QACnG,IAAI,KAAK,CAAC,OAAO,KAAK,OAAO,CAAC,KAAK,IAAI,CAAC,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,QAAQ,CAAA,EAAE;YAC5D,QAAQ,CAAC,KAAK,CAAC,CAAC;SACjB;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,cAAc;QACd,aAAa;QACb,eAAe;KAChB,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React from 'react';\n\nimport { useOpenState } from '../../internal/components/options-list/utils/use-open-state';\nimport { CancelableEventHandler, fireCancelableEvent, isPlainLeftClick } from '../../internal/events';\nimport { KeyCode } from '../../internal/keycode';\nimport { ButtonDropdownProps, ButtonDropdownSettings, GroupToggle, HighlightProps, ItemActivate } from '../interfaces';\nimport useHighlightedMenu from './use-highlighted-menu';\nimport { getItemTarget, isCheckboxItem, isItemGroup, isLinkItem } from './utils';\n\ninterface UseButtonDropdownOptions extends ButtonDropdownSettings {\n items: ButtonDropdownProps.Items;\n onItemClick?: CancelableEventHandler<ButtonDropdownProps.ItemClickDetails>;\n onItemFollow?: CancelableEventHandler<ButtonDropdownProps.ItemClickDetails>;\n onReturnFocus: () => void;\n expandToViewport?: 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 toggleDropdown: (options?: { moveHighlightOnOpen?: boolean }) => void;\n closeDropdown: () => void;\n setIsUsingMouse: (isUsingMouse: boolean) => void;\n}\n\nexport function useButtonDropdown({\n items,\n onItemClick,\n onItemFollow,\n onReturnFocus,\n hasExpandableGroups,\n isInRestrictedView = false,\n expandToViewport = false,\n}: UseButtonDropdownOptions): UseButtonDropdownApi {\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,\n hasExpandableGroups,\n isInRestrictedView,\n });\n\n const { isOpen, closeDropdown, ...openStateProps } = useOpenState({ onClose: reset });\n const toggleDropdown = (options: { moveHighlightOnOpen?: boolean } = {}) => {\n const moveHighlightOnOpen = options.moveHighlightOnOpen ?? true;\n if (!isOpen && moveHighlightOnOpen) {\n moveHighlight(1);\n }\n openStateProps.toggleDropdown();\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 doVerticalNavigation = (direction: -1 | 1) => {\n if (isOpen) {\n moveHighlight(direction);\n }\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 doVerticalNavigation(1);\n event.preventDefault();\n break;\n }\n case KeyCode.up: {\n doVerticalNavigation(-1);\n event.preventDefault();\n break;\n }\n case KeyCode.space: {\n // Prevent scrolling the list of items and highlighting the trigger\n event.preventDefault();\n break;\n }\n case KeyCode.enter: {\n if (!targetItem?.disabled) {\n activate(event, true);\n }\n break;\n }\n case KeyCode.left:\n case KeyCode.right: {\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 // 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 // We need to handle activating items with Space separately because there is a bug\n // in Firefox where changing the focus during a Space keydown event it will trigger\n // unexpected click events on the new element: https://bugzilla.mozilla.org/show_bug.cgi?id=1220143\n if (event.keyCode === KeyCode.space && !targetItem?.disabled) {\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 toggleDropdown,\n closeDropdown,\n setIsUsingMouse,\n };\n}\n"]}
1
+ {"version":3,"file":"use-button-dropdown.js","sourceRoot":"","sources":["../../../../src/button-dropdown/utils/use-button-dropdown.ts"],"names":[],"mappings":";AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,6DAA6D,CAAC;AAC3F,OAAO,EAA0B,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACtG,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEjD,OAAO,kBAAkB,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAqBjF,MAAM,UAAU,iBAAiB,CAAC,EAChC,KAAK,EACL,WAAW,EACX,YAAY,EACZ,aAAa,EACb,mBAAmB,EACnB,kBAAkB,GAAG,KAAK,EAC1B,gBAAgB,GAAG,KAAK,GACC;IACzB,MAAM,EACJ,UAAU,EACV,aAAa,EACb,mBAAmB,EACnB,UAAU,EACV,aAAa,EACb,aAAa,EACb,WAAW,EACX,aAAa,EACb,KAAK,EACL,eAAe,GAChB,GAAG,kBAAkB,CAAC;QACrB,KAAK;QACL,mBAAmB;QACnB,kBAAkB;KACnB,CAAC,CAAC;IAEH,MAAM,KAA+C,YAAY,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,EAA/E,EAAE,MAAM,EAAE,aAAa,OAAwD,EAAnD,cAAc,cAA1C,2BAA4C,CAAmC,CAAC;IAC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KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;gBAChB,gFAAgF;gBAChF,8CAA8C;gBAC9C,IAAI,gBAAgB,EAAE;oBACpB,aAAa,EAAE,CAAC;iBACjB;gBACD,aAAa,EAAE,CAAC;gBAChB,MAAM;aACP;SACF;IACH,CAAC,CAAC;IACF,MAAM,OAAO,GAAG,CAAC,KAA0B,EAAE,EAAE;QAC7C,kFAAkF;QAClF,mFAAmF;QACnF,mGAAmG;QACnG,IAAI,KAAK,CAAC,OAAO,KAAK,OAAO,CAAC,KAAK,IAAI,CAAC,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,QAAQ,CAAA,EAAE;YAC5D,QAAQ,CAAC,KAAK,CAAC,CAAC;SACjB;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,cAAc;QACd,aAAa;QACb,eAAe;KAChB,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React from 'react';\n\nimport { useOpenState } from '../../internal/components/options-list/utils/use-open-state';\nimport { CancelableEventHandler, fireCancelableEvent, isPlainLeftClick } from '../../internal/events';\nimport { KeyCode } from '../../internal/keycode';\nimport { ButtonDropdownProps, ButtonDropdownSettings, GroupToggle, HighlightProps, ItemActivate } from '../interfaces';\nimport useHighlightedMenu from './use-highlighted-menu';\nimport { getItemTarget, isCheckboxItem, isItemGroup, isLinkItem } from './utils';\n\ninterface UseButtonDropdownOptions extends ButtonDropdownSettings {\n items: ButtonDropdownProps.Items;\n onItemClick?: CancelableEventHandler<ButtonDropdownProps.ItemClickDetails>;\n onItemFollow?: CancelableEventHandler<ButtonDropdownProps.ItemClickDetails>;\n onReturnFocus: () => void;\n expandToViewport?: 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 toggleDropdown: (options?: { moveHighlightOnOpen?: boolean }) => void;\n closeDropdown: () => void;\n setIsUsingMouse: (isUsingMouse: boolean) => void;\n}\n\nexport function useButtonDropdown({\n items,\n onItemClick,\n onItemFollow,\n onReturnFocus,\n hasExpandableGroups,\n isInRestrictedView = false,\n expandToViewport = false,\n}: UseButtonDropdownOptions): UseButtonDropdownApi {\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,\n hasExpandableGroups,\n isInRestrictedView,\n });\n\n const { isOpen, closeDropdown, ...openStateProps } = useOpenState({ onClose: reset });\n const toggleDropdown = (options: { moveHighlightOnOpen?: boolean } = {}) => {\n const moveHighlightOnOpen = options.moveHighlightOnOpen ?? true;\n if (!isOpen && moveHighlightOnOpen) {\n moveHighlight(1);\n }\n openStateProps.toggleDropdown();\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 moveHighlight(1, true);\n } else {\n moveHighlight(1);\n }\n event.preventDefault();\n break;\n }\n case KeyCode.up: {\n if (!isOpen) {\n toggleDropdown();\n moveHighlight(-1, true);\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\n event.preventDefault();\n break;\n }\n case KeyCode.enter: {\n if (!targetItem?.disabled) {\n activate(event, true);\n }\n break;\n }\n case KeyCode.left:\n case KeyCode.right: {\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 // 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 // We need to handle activating items with Space separately because there is a bug\n // in Firefox where changing the focus during a Space keydown event it will trigger\n // unexpected click events on the new element: https://bugzilla.mozilla.org/show_bug.cgi?id=1220143\n if (event.keyCode === KeyCode.space && !targetItem?.disabled) {\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 toggleDropdown,\n closeDropdown,\n setIsUsingMouse,\n };\n}\n"]}
@@ -5,7 +5,7 @@ interface UseHighlightedMenuOptions {
5
5
  isInRestrictedView?: boolean;
6
6
  }
7
7
  interface UseHighlightedMenuApi extends HighlightProps {
8
- moveHighlight: (direction: -1 | 1) => void;
8
+ moveHighlight: (direction: -1 | 1, loop?: boolean) => void;
9
9
  expandGroup: (group?: ButtonDropdownProps.ItemGroup) => void;
10
10
  collapseGroup: () => void;
11
11
  reset: () => void;
@@ -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,mBAAmB,EAAE,OAAO,CAAC;IAC7B,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,UAAU,qBAAsB,SAAQ,cAAc;IACpD,aAAa,EAAE,CAAC,SAAS,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC;IAC3C,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,mBAAmB,EACnB,kBAA0B,GAC3B,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