@cloudscape-design/components-themeable 3.0.724 → 3.0.726

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 (71) hide show
  1. package/lib/internal/manifest.json +1 -1
  2. package/lib/internal/scss/app-layout/visual-refresh-toolbar/skeleton/styles.scss +8 -3
  3. package/lib/internal/scss/button-group/styles.scss +29 -0
  4. package/lib/internal/scss/button-group/test-classes/styles.scss +24 -0
  5. package/lib/internal/template/app-layout/visual-refresh-toolbar/skeleton/styles.css.js +16 -16
  6. package/lib/internal/template/app-layout/visual-refresh-toolbar/skeleton/styles.scoped.css +28 -31
  7. package/lib/internal/template/app-layout/visual-refresh-toolbar/skeleton/styles.selectors.js +16 -16
  8. package/lib/internal/template/app-layout/visual-refresh-toolbar/toolbar/index.d.ts.map +1 -1
  9. package/lib/internal/template/app-layout/visual-refresh-toolbar/toolbar/index.js +20 -1
  10. package/lib/internal/template/app-layout/visual-refresh-toolbar/toolbar/index.js.map +1 -1
  11. package/lib/internal/template/button/internal.d.ts +2 -0
  12. package/lib/internal/template/button/internal.d.ts.map +1 -1
  13. package/lib/internal/template/button/internal.js +2 -2
  14. package/lib/internal/template/button/internal.js.map +1 -1
  15. package/lib/internal/template/button-dropdown/interfaces.d.ts +1 -1
  16. package/lib/internal/template/button-dropdown/interfaces.js.map +1 -1
  17. package/lib/internal/template/button-group/icon-button-item.d.ts +12 -0
  18. package/lib/internal/template/button-group/icon-button-item.d.ts.map +1 -0
  19. package/lib/internal/template/button-group/icon-button-item.js +21 -0
  20. package/lib/internal/template/button-group/icon-button-item.js.map +1 -0
  21. package/lib/internal/template/button-group/index.d.ts +6 -0
  22. package/lib/internal/template/button-group/index.d.ts.map +1 -0
  23. package/lib/internal/template/button-group/index.js +24 -0
  24. package/lib/internal/template/button-group/index.js.map +1 -0
  25. package/lib/internal/template/button-group/interfaces.d.ts +111 -0
  26. package/lib/internal/template/button-group/interfaces.d.ts.map +1 -0
  27. package/lib/internal/template/button-group/interfaces.js +4 -0
  28. package/lib/internal/template/button-group/interfaces.js.map +1 -0
  29. package/lib/internal/template/button-group/internal.d.ts +5 -0
  30. package/lib/internal/template/button-group/internal.d.ts.map +1 -0
  31. package/lib/internal/template/button-group/internal.js +123 -0
  32. package/lib/internal/template/button-group/internal.js.map +1 -0
  33. package/lib/internal/template/button-group/item-element.d.ts +20 -0
  34. package/lib/internal/template/button-group/item-element.d.ts.map +1 -0
  35. package/lib/internal/template/button-group/item-element.js +74 -0
  36. package/lib/internal/template/button-group/item-element.js.map +1 -0
  37. package/lib/internal/template/button-group/menu-dropdown-item.d.ts +13 -0
  38. package/lib/internal/template/button-group/menu-dropdown-item.d.ts.map +1 -0
  39. package/lib/internal/template/button-group/menu-dropdown-item.js +20 -0
  40. package/lib/internal/template/button-group/menu-dropdown-item.js.map +1 -0
  41. package/lib/internal/template/button-group/styles.css.js +9 -0
  42. package/lib/internal/template/button-group/styles.scoped.css +149 -0
  43. package/lib/internal/template/button-group/styles.selectors.js +10 -0
  44. package/lib/internal/template/button-group/test-classes/styles.css.js +10 -0
  45. package/lib/internal/template/button-group/test-classes/styles.scoped.css +23 -0
  46. package/lib/internal/template/button-group/test-classes/styles.selectors.js +11 -0
  47. package/lib/internal/template/index.d.ts +1 -0
  48. package/lib/internal/template/index.d.ts.map +1 -1
  49. package/lib/internal/template/index.js +1 -0
  50. package/lib/internal/template/index.js.map +1 -1
  51. package/lib/internal/template/internal/components/dropdown/interfaces.d.ts +1 -1
  52. package/lib/internal/template/internal/components/dropdown/interfaces.js.map +1 -1
  53. package/lib/internal/template/internal/context/single-tab-stop-navigation-context.js +1 -1
  54. package/lib/internal/template/internal/context/single-tab-stop-navigation-context.js.map +1 -1
  55. package/lib/internal/template/internal/environment.js +1 -1
  56. package/lib/internal/template/internal/environment.json +1 -1
  57. package/lib/internal/template/package.json +1 -0
  58. package/lib/internal/template/test-utils/dom/button-group/index.d.ts +22 -0
  59. package/lib/internal/template/test-utils/dom/button-group/index.js +42 -0
  60. package/lib/internal/template/test-utils/dom/button-group/index.js.map +1 -0
  61. package/lib/internal/template/test-utils/dom/index.d.ts +3 -0
  62. package/lib/internal/template/test-utils/dom/index.js +10 -2
  63. package/lib/internal/template/test-utils/dom/index.js.map +1 -1
  64. package/lib/internal/template/test-utils/selectors/button-group/index.d.ts +22 -0
  65. package/lib/internal/template/test-utils/selectors/button-group/index.js +42 -0
  66. package/lib/internal/template/test-utils/selectors/button-group/index.js.map +1 -0
  67. package/lib/internal/template/test-utils/selectors/index.d.ts +3 -0
  68. package/lib/internal/template/test-utils/selectors/index.js +10 -2
  69. package/lib/internal/template/test-utils/selectors/index.js.map +1 -1
  70. package/lib/internal/template/test-utils/tsconfig.tsbuildinfo +1 -1
  71. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/button-dropdown/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React from 'react';\n\nimport { ButtonProps } from '../button/interfaces';\nimport { IconProps } from '../icon/interfaces';\nimport { BaseComponentProps } from '../internal/base-component';\nimport { ExpandToViewport } from '../internal/components/dropdown/interfaces';\nimport { BaseNavigationDetail, CancelableEventHandler } from '../internal/events';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component';\n\nexport interface ButtonDropdownProps extends BaseComponentProps, ExpandToViewport {\n /**\n * Array of objects with a number of suppoted types.\n *\n * The following properties are supported across all types:\n *\n * - `type` (string) - The type of the item. Can be `action`, `group`, `checkbox`. Defaults to `action` if `items` undefined and `group` otherwise.\n * - `id` (string) - allows to identify the item that the user clicked on. Mandatory for individual items, optional for categories.\n * - `text` (string) - description shown in the menu for this item. Mandatory for individual items, optional for categories.\n * - `lang` (string) - (Optional) The language of the item, provided as a BCP 47 language tag.\n * - `disabled` (boolean) - whether the item is disabled. Disabled items are not clickable, but they can be highlighted with the keyboard to make them accessible.\n * - `disabledReason` (string) - (Optional) Displays text near the `text` property when item is disabled. Use to provide additional context.\n * - `description` (string) - additional data that will be passed to a `data-description` attribute.\n *\n * ### action\n *\n * - `href` (string) - (Optional) Defines the target URL of the menu item, turning it into a link.\n * - `external` (boolean) - Marks a menu item as external by adding an icon after the menu item text. The link will open in a new tab when clicked. Note that this only works when `href` is also provided.\n * - `externalIconAriaLabel` (string) - Adds an `aria-label` to the external icon.\n * - `iconName` (string) - (Optional) Specifies the name of the icon, used with the [icon component](/components/icon/).\n * - `iconAlt` (string) - (Optional) Specifies alternate text for the icon when using `iconUrl`.\n * - `iconUrl` (string) - (Optional) Specifies the URL of a custom icon.\n * - `iconSvg` (ReactNode) - (Optional) Custom SVG icon. Equivalent to the `svg` slot of the [icon component](/components/icon/).\n *\n * ### checkbox\n *\n * When `type` is set to \"checkbox\", the values set to `href`, `external` and `externalIconAriaLabel` will be ignored.\n *\n * - `checked` (boolean) - Controls the state of the checkbox item.\n * - `iconName` (string) - (Optional) Specifies the name of the icon, used with the [icon component](/components/icon/).\n * - `iconAlt` (string) - (Optional) Specifies alternate text for the icon when using `iconUrl`.\n * - `iconUrl` (string) - (Optional) Specifies the URL of a custom icon.\n * - `iconSvg` (ReactNode) - (Optional) Custom SVG icon. Equivalent to the `svg` slot of the [icon component](/components/icon/).\n *\n * ### group\n *\n * - `items` (ReadonlyArray<Item>) - an array of item objects. Items will be rendered as nested menu items but only for the first nesting level, multi-nesting is not supported.\n * An item which belongs to nested group has the following properties: `id`, `text`, `disabled`, and `description`.\n *\n */\n items: ReadonlyArray<ButtonDropdownProps.ItemOrGroup>;\n /**\n * Determines whether the button dropdown is disabled. Users cannot interact with the control if it's disabled.\n */\n disabled?: boolean;\n /**\n * Provides a reason why the button dropdown is disabled (only when `disabled` is `true`).\n * If provided, the disabled button becomes focusable.\n */\n disabledReason?: string;\n /**\n * Renders the button as being in a loading state. It takes precedence over the `disabled` if both are set to `true`.\n * It prevents clicks.\n */\n loading?: boolean;\n /**\n * Specifies the text that screen reader announces when the button dropdown is in a loading state.\n */\n loadingText?: string;\n /** Determines the general styling of the button dropdown.\n * * `primary` for primary buttons\n * * `normal` for secondary buttons\n * * `icon` for icon buttons\n * * `inline-icon` for icon buttons with no outer padding\n */\n variant?: ButtonDropdownProps.Variant;\n /**\n * Controls expandability of the item groups.\n */\n expandableGroups?: boolean;\n /**\n * Adds `aria-label` to the button dropdown trigger.\n * Use this to provide an accessible name for buttons that don't have visible text.\n */\n ariaLabel?: string;\n /**\n * Text displayed in the button dropdown trigger.\n * @displayname text\n */\n children?: React.ReactNode;\n /**\n * Called when the user clicks on an item, and the item is not disabled. The event detail object contains the id of the clicked item.\n */\n onItemClick?: CancelableEventHandler<ButtonDropdownProps.ItemClickDetails>;\n /**\n * Called when the user clicks on an item with the left mouse button without pressing\n * modifier keys (that is, CTRL, ALT, SHIFT, META), and the item has an `href` set.\n */\n onItemFollow?: CancelableEventHandler<ButtonDropdownProps.ItemClickDetails>;\n /**\n * A standalone action that is shown prior to the dropdown trigger.\n * Use it with \"primary\" and \"normal\" variant only.\n *\n * Main action properties:\n * * `text` (string) - Specifies the text shown in the main action.\n * * `external` (boolean) - Marks the main action as external by adding an icon after the text. The link will open in a new tab when clicked. Note that this only works when `href` is also provided.\n * * `externalIconAriaLabel` (string) - Adds an ARIA label to the external icon.\n *\n * The main action also supports the following properties of the [button](/components/button/?tabId=api) component:\n * `ariaLabel`, `disabled`, `loading`, `loadingText`, `href`, `target`, `rel`, `download`, `iconAlt`, `iconName`, `iconUrl`, `iconSvg`, `onClick`, `onFollow`.\n */\n mainAction?: ButtonDropdownProps.MainAction;\n}\n\nexport namespace ButtonDropdownProps {\n export type Variant = 'normal' | 'primary' | 'icon' | 'inline-icon';\n export type ItemType = 'action' | 'group';\n\n export interface MainAction {\n text: string;\n ariaLabel?: string;\n onClick?: CancelableEventHandler<ButtonProps.ClickDetail>;\n onFollow?: CancelableEventHandler<ButtonProps.FollowDetail>;\n disabled?: boolean;\n disabledReason?: string;\n loading?: boolean;\n loadingText?: string;\n href?: string;\n target?: string;\n rel?: string;\n download?: boolean | string;\n external?: boolean;\n externalIconAriaLabel?: string;\n iconAlt?: string;\n iconName?: IconProps.Name;\n iconUrl?: string;\n iconSvg?: React.ReactNode;\n }\n\n export interface Item {\n itemType?: ItemType;\n id: string;\n text: string;\n lang?: string;\n disabled?: boolean;\n disabledReason?: string;\n description?: string;\n href?: string;\n external?: boolean;\n externalIconAriaLabel?: string;\n iconAlt?: string;\n iconName?: IconProps.Name;\n iconUrl?: string;\n iconSvg?: React.ReactNode;\n }\n\n export interface CheckboxItem\n extends Omit<ButtonDropdownProps.Item, 'href' | 'external' | 'externalIconAriaLabel' | 'itemType'> {\n itemType: 'checkbox';\n checked: boolean;\n }\n\n export interface ItemGroup extends Omit<Item, 'id' | 'text' | 'itemType'> {\n itemType?: 'group';\n id?: string;\n text?: string;\n items: Items;\n }\n\n export type ItemOrGroup = Item | CheckboxItem | ItemGroup;\n\n export type Items = ReadonlyArray<ItemOrGroup>;\n\n export interface ItemClickDetails extends BaseNavigationDetail {\n id: string;\n checked?: boolean;\n }\n\n export interface Ref {\n /**\n * Focuses the underlying native button.\n */\n focus(): void;\n }\n}\n\nexport interface ButtonDropdownSettings {\n // this means whether action is required to make group expand\n hasExpandableGroups: boolean;\n // on smaller screens expandable groups are integrated into parent dropdown\n // this changes keyboard navigation, highlight and activation behavior for parent dropdown\n isInRestrictedView?: boolean;\n}\n\nexport interface HighlightProps {\n targetItem: ButtonDropdownProps.ItemOrGroup | null;\n isHighlighted: (item: ButtonDropdownProps.ItemOrGroup) => boolean;\n isKeyboardHighlight: (item: ButtonDropdownProps.ItemOrGroup) => boolean;\n isExpanded: (group: ButtonDropdownProps.ItemGroup) => boolean;\n highlightItem: (item: ButtonDropdownProps.ItemOrGroup) => void;\n}\n\nexport type GroupToggle = (item: ButtonDropdownProps.ItemGroup, event: React.SyntheticEvent) => void;\nexport type ItemActivate = (\n item: ButtonDropdownProps.Item | ButtonDropdownProps.CheckboxItem,\n event: React.MouseEvent | React.KeyboardEvent\n) => void;\n\nexport interface CategoryProps extends HighlightProps {\n item: ButtonDropdownProps.ItemGroup;\n onGroupToggle: GroupToggle;\n onItemActivate: ItemActivate;\n disabled: boolean;\n lastInDropdown: boolean;\n expandToViewport?: boolean;\n variant?: ItemListProps['variant'];\n position?: string;\n}\n\nexport interface ItemListProps extends HighlightProps {\n items: ButtonDropdownProps.Items;\n onGroupToggle: GroupToggle;\n onItemActivate: ItemActivate;\n categoryDisabled?: boolean;\n hasExpandableGroups?: boolean;\n hasCategoryHeader?: boolean;\n lastInDropdown: boolean;\n expandToViewport?: boolean;\n variant?: InternalButtonDropdownProps['variant'];\n position?: string;\n}\n\nexport interface LinkItem extends ButtonDropdownProps.Item {\n href: string;\n}\n\nexport interface ItemProps {\n item: ButtonDropdownProps.Item | ButtonDropdownProps.CheckboxItem | LinkItem;\n disabled: boolean;\n highlighted: boolean;\n onItemActivate: ItemActivate;\n highlightItem: (item: ButtonDropdownProps.ItemOrGroup) => void;\n showDivider: boolean;\n hasCategoryHeader: boolean;\n isKeyboardHighlighted?: boolean;\n variant?: ItemListProps['variant'];\n position?: string;\n}\n\nexport interface InternalItem extends ButtonDropdownProps.Item {\n badge?: boolean;\n}\n\nexport interface InternalItemGroup extends Omit<ButtonDropdownProps.ItemGroup, 'items'> {\n items: InternalItems;\n}\n\nexport type InternalItems = ReadonlyArray<InternalItemOrGroup>;\n\nexport type InternalItemOrGroup = InternalItem | ButtonDropdownProps.CheckboxItem | InternalItemGroup;\n\nexport interface InternalButtonDropdownProps\n extends Omit<ButtonDropdownProps, 'variant' | 'items'>,\n InternalBaseComponentProps {\n customTriggerBuilder?: (props: CustomTriggerProps) => React.ReactNode;\n variant?: ButtonDropdownProps['variant'] | 'navigation';\n items: ReadonlyArray<InternalItemOrGroup>;\n\n /**\n * Optional text that is displayed as the title at the top of the dropdown.\n */\n title?: string;\n\n /**\n * Optional text that is displayed underneath the title at the top of the dropdown.\n */\n description?: string;\n\n /**\n * Determines that the dropdown should preferably be aligned to the center of the trigger\n * instead of dropping left or right.\n */\n preferCenter?: boolean;\n}\n\nexport interface CustomTriggerProps {\n triggerRef: React.Ref<HTMLElement>;\n testUtilsClass: string;\n ariaLabel: string | undefined;\n disabled: boolean;\n disabledReason?: string;\n isOpen: boolean;\n onClick: () => void;\n ariaExpanded: boolean;\n}\n"]}
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/button-dropdown/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React from 'react';\n\nimport { ButtonProps } from '../button/interfaces';\nimport { IconProps } from '../icon/interfaces';\nimport { BaseComponentProps } from '../internal/base-component';\nimport { ExpandToViewport } from '../internal/components/dropdown/interfaces';\nimport { BaseNavigationDetail, CancelableEventHandler } from '../internal/events';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component';\n\nexport interface ButtonDropdownProps extends BaseComponentProps, ExpandToViewport {\n /**\n * Array of objects with a number of supported types.\n *\n * The following properties are supported across all types:\n *\n * - `type` (string) - The type of the item. Can be `action`, `group`, `checkbox`. Defaults to `action` if `items` undefined and `group` otherwise.\n * - `id` (string) - allows to identify the item that the user clicked on. Mandatory for individual items, optional for categories.\n * - `text` (string) - description shown in the menu for this item. Mandatory for individual items, optional for categories.\n * - `lang` (string) - (Optional) The language of the item, provided as a BCP 47 language tag.\n * - `disabled` (boolean) - whether the item is disabled. Disabled items are not clickable, but they can be highlighted with the keyboard to make them accessible.\n * - `disabledReason` (string) - (Optional) Displays text near the `text` property when item is disabled. Use to provide additional context.\n * - `description` (string) - additional data that will be passed to a `data-description` attribute.\n *\n * ### action\n *\n * - `href` (string) - (Optional) Defines the target URL of the menu item, turning it into a link.\n * - `external` (boolean) - Marks a menu item as external by adding an icon after the menu item text. The link will open in a new tab when clicked. Note that this only works when `href` is also provided.\n * - `externalIconAriaLabel` (string) - Adds an `aria-label` to the external icon.\n * - `iconName` (string) - (Optional) Specifies the name of the icon, used with the [icon component](/components/icon/).\n * - `iconAlt` (string) - (Optional) Specifies alternate text for the icon when using `iconUrl`.\n * - `iconUrl` (string) - (Optional) Specifies the URL of a custom icon.\n * - `iconSvg` (ReactNode) - (Optional) Custom SVG icon. Equivalent to the `svg` slot of the [icon component](/components/icon/).\n *\n * ### checkbox\n *\n * When `type` is set to \"checkbox\", the values set to `href`, `external` and `externalIconAriaLabel` will be ignored.\n *\n * - `checked` (boolean) - Controls the state of the checkbox item.\n * - `iconName` (string) - (Optional) Specifies the name of the icon, used with the [icon component](/components/icon/).\n * - `iconAlt` (string) - (Optional) Specifies alternate text for the icon when using `iconUrl`.\n * - `iconUrl` (string) - (Optional) Specifies the URL of a custom icon.\n * - `iconSvg` (ReactNode) - (Optional) Custom SVG icon. Equivalent to the `svg` slot of the [icon component](/components/icon/).\n *\n * ### group\n *\n * - `items` (ReadonlyArray<Item>) - an array of item objects. Items will be rendered as nested menu items but only for the first nesting level, multi-nesting is not supported.\n * An item which belongs to nested group has the following properties: `id`, `text`, `disabled`, and `description`.\n *\n */\n items: ReadonlyArray<ButtonDropdownProps.ItemOrGroup>;\n /**\n * Determines whether the button dropdown is disabled. Users cannot interact with the control if it's disabled.\n */\n disabled?: boolean;\n /**\n * Provides a reason why the button dropdown is disabled (only when `disabled` is `true`).\n * If provided, the disabled button becomes focusable.\n */\n disabledReason?: string;\n /**\n * Renders the button as being in a loading state. It takes precedence over the `disabled` if both are set to `true`.\n * It prevents clicks.\n */\n loading?: boolean;\n /**\n * Specifies the text that screen reader announces when the button dropdown is in a loading state.\n */\n loadingText?: string;\n /** Determines the general styling of the button dropdown.\n * * `primary` for primary buttons\n * * `normal` for secondary buttons\n * * `icon` for icon buttons\n * * `inline-icon` for icon buttons with no outer padding\n */\n variant?: ButtonDropdownProps.Variant;\n /**\n * Controls expandability of the item groups.\n */\n expandableGroups?: boolean;\n /**\n * Adds `aria-label` to the button dropdown trigger.\n * Use this to provide an accessible name for buttons that don't have visible text.\n */\n ariaLabel?: string;\n /**\n * Text displayed in the button dropdown trigger.\n * @displayname text\n */\n children?: React.ReactNode;\n /**\n * Called when the user clicks on an item, and the item is not disabled. The event detail object contains the id of the clicked item.\n */\n onItemClick?: CancelableEventHandler<ButtonDropdownProps.ItemClickDetails>;\n /**\n * Called when the user clicks on an item with the left mouse button without pressing\n * modifier keys (that is, CTRL, ALT, SHIFT, META), and the item has an `href` set.\n */\n onItemFollow?: CancelableEventHandler<ButtonDropdownProps.ItemClickDetails>;\n /**\n * A standalone action that is shown prior to the dropdown trigger.\n * Use it with \"primary\" and \"normal\" variant only.\n *\n * Main action properties:\n * * `text` (string) - Specifies the text shown in the main action.\n * * `external` (boolean) - Marks the main action as external by adding an icon after the text. The link will open in a new tab when clicked. Note that this only works when `href` is also provided.\n * * `externalIconAriaLabel` (string) - Adds an ARIA label to the external icon.\n *\n * The main action also supports the following properties of the [button](/components/button/?tabId=api) component:\n * `ariaLabel`, `disabled`, `loading`, `loadingText`, `href`, `target`, `rel`, `download`, `iconAlt`, `iconName`, `iconUrl`, `iconSvg`, `onClick`, `onFollow`.\n */\n mainAction?: ButtonDropdownProps.MainAction;\n}\n\nexport namespace ButtonDropdownProps {\n export type Variant = 'normal' | 'primary' | 'icon' | 'inline-icon';\n export type ItemType = 'action' | 'group';\n\n export interface MainAction {\n text: string;\n ariaLabel?: string;\n onClick?: CancelableEventHandler<ButtonProps.ClickDetail>;\n onFollow?: CancelableEventHandler<ButtonProps.FollowDetail>;\n disabled?: boolean;\n disabledReason?: string;\n loading?: boolean;\n loadingText?: string;\n href?: string;\n target?: string;\n rel?: string;\n download?: boolean | string;\n external?: boolean;\n externalIconAriaLabel?: string;\n iconAlt?: string;\n iconName?: IconProps.Name;\n iconUrl?: string;\n iconSvg?: React.ReactNode;\n }\n\n export interface Item {\n itemType?: ItemType;\n id: string;\n text: string;\n lang?: string;\n disabled?: boolean;\n disabledReason?: string;\n description?: string;\n href?: string;\n external?: boolean;\n externalIconAriaLabel?: string;\n iconAlt?: string;\n iconName?: IconProps.Name;\n iconUrl?: string;\n iconSvg?: React.ReactNode;\n }\n\n export interface CheckboxItem\n extends Omit<ButtonDropdownProps.Item, 'href' | 'external' | 'externalIconAriaLabel' | 'itemType'> {\n itemType: 'checkbox';\n checked: boolean;\n }\n\n export interface ItemGroup extends Omit<Item, 'id' | 'text' | 'itemType'> {\n itemType?: 'group';\n id?: string;\n text?: string;\n items: Items;\n }\n\n export type ItemOrGroup = Item | CheckboxItem | ItemGroup;\n\n export type Items = ReadonlyArray<ItemOrGroup>;\n\n export interface ItemClickDetails extends BaseNavigationDetail {\n id: string;\n checked?: boolean;\n }\n\n export interface Ref {\n /**\n * Focuses the underlying native button.\n */\n focus(): void;\n }\n}\n\nexport interface ButtonDropdownSettings {\n // this means whether action is required to make group expand\n hasExpandableGroups: boolean;\n // on smaller screens expandable groups are integrated into parent dropdown\n // this changes keyboard navigation, highlight and activation behavior for parent dropdown\n isInRestrictedView?: boolean;\n}\n\nexport interface HighlightProps {\n targetItem: ButtonDropdownProps.ItemOrGroup | null;\n isHighlighted: (item: ButtonDropdownProps.ItemOrGroup) => boolean;\n isKeyboardHighlight: (item: ButtonDropdownProps.ItemOrGroup) => boolean;\n isExpanded: (group: ButtonDropdownProps.ItemGroup) => boolean;\n highlightItem: (item: ButtonDropdownProps.ItemOrGroup) => void;\n}\n\nexport type GroupToggle = (item: ButtonDropdownProps.ItemGroup, event: React.SyntheticEvent) => void;\nexport type ItemActivate = (\n item: ButtonDropdownProps.Item | ButtonDropdownProps.CheckboxItem,\n event: React.MouseEvent | React.KeyboardEvent\n) => void;\n\nexport interface CategoryProps extends HighlightProps {\n item: ButtonDropdownProps.ItemGroup;\n onGroupToggle: GroupToggle;\n onItemActivate: ItemActivate;\n disabled: boolean;\n lastInDropdown: boolean;\n expandToViewport?: boolean;\n variant?: ItemListProps['variant'];\n position?: string;\n}\n\nexport interface ItemListProps extends HighlightProps {\n items: ButtonDropdownProps.Items;\n onGroupToggle: GroupToggle;\n onItemActivate: ItemActivate;\n categoryDisabled?: boolean;\n hasExpandableGroups?: boolean;\n hasCategoryHeader?: boolean;\n lastInDropdown: boolean;\n expandToViewport?: boolean;\n variant?: InternalButtonDropdownProps['variant'];\n position?: string;\n}\n\nexport interface LinkItem extends ButtonDropdownProps.Item {\n href: string;\n}\n\nexport interface ItemProps {\n item: ButtonDropdownProps.Item | ButtonDropdownProps.CheckboxItem | LinkItem;\n disabled: boolean;\n highlighted: boolean;\n onItemActivate: ItemActivate;\n highlightItem: (item: ButtonDropdownProps.ItemOrGroup) => void;\n showDivider: boolean;\n hasCategoryHeader: boolean;\n isKeyboardHighlighted?: boolean;\n variant?: ItemListProps['variant'];\n position?: string;\n}\n\nexport interface InternalItem extends ButtonDropdownProps.Item {\n badge?: boolean;\n}\n\nexport interface InternalItemGroup extends Omit<ButtonDropdownProps.ItemGroup, 'items'> {\n items: InternalItems;\n}\n\nexport type InternalItems = ReadonlyArray<InternalItemOrGroup>;\n\nexport type InternalItemOrGroup = InternalItem | ButtonDropdownProps.CheckboxItem | InternalItemGroup;\n\nexport interface InternalButtonDropdownProps\n extends Omit<ButtonDropdownProps, 'variant' | 'items'>,\n InternalBaseComponentProps {\n customTriggerBuilder?: (props: CustomTriggerProps) => React.ReactNode;\n variant?: ButtonDropdownProps['variant'] | 'navigation';\n items: ReadonlyArray<InternalItemOrGroup>;\n\n /**\n * Optional text that is displayed as the title at the top of the dropdown.\n */\n title?: string;\n\n /**\n * Optional text that is displayed underneath the title at the top of the dropdown.\n */\n description?: string;\n\n /**\n * Determines that the dropdown should preferably be aligned to the center of the trigger\n * instead of dropping left or right.\n */\n preferCenter?: boolean;\n}\n\nexport interface CustomTriggerProps {\n triggerRef: React.Ref<HTMLElement>;\n testUtilsClass: string;\n ariaLabel: string | undefined;\n disabled: boolean;\n disabledReason?: string;\n isOpen: boolean;\n onClick: () => void;\n ariaExpanded: boolean;\n}\n"]}
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import { ButtonProps } from '../button/interfaces.js';
3
+ import { CancelableEventHandler, ClickDetail } from '../internal/events/index.js';
4
+ import { ButtonGroupProps } from './interfaces.js';
5
+ declare const IconButtonItem: React.ForwardRefExoticComponent<{
6
+ item: ButtonGroupProps.IconButton;
7
+ showTooltip: boolean;
8
+ showFeedback: boolean;
9
+ onItemClick?: CancelableEventHandler<ClickDetail> | undefined;
10
+ } & React.RefAttributes<ButtonProps.Ref>>;
11
+ export default IconButtonItem;
12
+ //# sourceMappingURL=icon-button-item.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"icon-button-item.d.ts","sourceRoot":"","sources":["../../../src/button-group/icon-button-item.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAqB,MAAM,OAAO,CAAC;AAK1C,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAItD,OAAO,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAClF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAInD,QAAA,MAAM,cAAc;UAQR,iBAAiB,UAAU;iBACpB,OAAO;kBACN,OAAO;;yCA2C1B,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -0,0 +1,21 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import React, { forwardRef } from 'react';
4
+ import clsx from 'clsx';
5
+ import { warnOnce } from '@cloudscape-design/component-toolkit/internal';
6
+ import { InternalButton } from '../button/internal.js';
7
+ import LiveRegion from '../internal/components/live-region/index.js';
8
+ import Tooltip from '../internal/components/tooltip/index.js';
9
+ import testUtilStyles from './test-classes/styles.css.js';
10
+ const IconButtonItem = forwardRef(({ item, showTooltip, showFeedback, onItemClick, }, ref) => {
11
+ const containerRef = React.useRef(null);
12
+ const hasIcon = item.iconName || item.iconUrl || item.iconSvg;
13
+ if (!hasIcon) {
14
+ warnOnce('ButtonGroup', `Missing icon for item with id: ${item.id}`);
15
+ }
16
+ return (React.createElement("div", { ref: containerRef },
17
+ React.createElement(InternalButton, { variant: "icon", loading: item.loading, loadingText: item.loadingText, disabled: item.disabled, iconName: hasIcon ? item.iconName : 'close', iconAlt: item.text, iconSvg: item.iconSvg, ariaLabel: item.text, onClick: onItemClick, ref: ref, "data-testid": item.id, "data-itemid": item.id, className: clsx(testUtilStyles.item, testUtilStyles['button-group-item']), __title: "" }, item.text),
18
+ showTooltip && !item.disabled && !item.loading && (!showFeedback || item.popoverFeedback) && (React.createElement(Tooltip, { trackRef: containerRef, trackKey: item.id, value: (showFeedback && React.createElement(LiveRegion, { visible: true }, item.popoverFeedback)) || item.text, className: clsx(testUtilStyles.tooltip, testUtilStyles['button-group-tooltip']) }))));
19
+ });
20
+ export default IconButtonItem;
21
+ //# sourceMappingURL=icon-button-item.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"icon-button-item.js","sourceRoot":"","sources":["../../../src/button-group/icon-button-item.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,MAAM,+CAA+C,CAAC;AAGzE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,UAAU,MAAM,6CAA6C,CAAC;AACrE,OAAO,OAAO,MAAM,yCAAyC,CAAC;AAI9D,OAAO,cAAc,MAAM,8BAA8B,CAAC;AAE1D,MAAM,cAAc,GAAG,UAAU,CAC/B,CACE,EACE,IAAI,EACJ,WAAW,EACX,YAAY,EACZ,WAAW,GAMZ,EACD,GAA+B,EAC/B,EAAE;IACF,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,CAAiB,IAAI,CAAC,CAAC;IACxD,M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AAc,CAAC,sBAAsB,CAAC,CAAC,GAC/E,CACH,CACG,CACP,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, { forwardRef } from 'react';\nimport clsx from 'clsx';\n\nimport { warnOnce } from '@cloudscape-design/component-toolkit/internal';\n\nimport { ButtonProps } from '../button/interfaces.js';\nimport { InternalButton } from '../button/internal.js';\nimport LiveRegion from '../internal/components/live-region/index.js';\nimport Tooltip from '../internal/components/tooltip/index.js';\nimport { CancelableEventHandler, ClickDetail } from '../internal/events/index.js';\nimport { ButtonGroupProps } from './interfaces.js';\n\nimport testUtilStyles from './test-classes/styles.css.js';\n\nconst IconButtonItem = forwardRef(\n (\n {\n item,\n showTooltip,\n showFeedback,\n onItemClick,\n }: {\n item: ButtonGroupProps.IconButton;\n showTooltip: boolean;\n showFeedback: boolean;\n onItemClick?: CancelableEventHandler<ClickDetail>;\n },\n ref: React.Ref<ButtonProps.Ref>\n ) => {\n const containerRef = React.useRef<HTMLDivElement>(null);\n const hasIcon = item.iconName || item.iconUrl || item.iconSvg;\n\n if (!hasIcon) {\n warnOnce('ButtonGroup', `Missing icon for item with id: ${item.id}`);\n }\n\n return (\n <div ref={containerRef}>\n <InternalButton\n variant=\"icon\"\n loading={item.loading}\n loadingText={item.loadingText}\n disabled={item.disabled}\n iconName={hasIcon ? item.iconName : 'close'}\n iconAlt={item.text}\n iconSvg={item.iconSvg}\n ariaLabel={item.text}\n onClick={onItemClick}\n ref={ref}\n data-testid={item.id}\n data-itemid={item.id}\n className={clsx(testUtilStyles.item, testUtilStyles['button-group-item'])}\n __title=\"\"\n >\n {item.text}\n </InternalButton>\n {showTooltip && !item.disabled && !item.loading && (!showFeedback || item.popoverFeedback) && (\n <Tooltip\n trackRef={containerRef}\n trackKey={item.id}\n value={(showFeedback && <LiveRegion visible={true}>{item.popoverFeedback}</LiveRegion>) || item.text}\n className={clsx(testUtilStyles.tooltip, testUtilStyles['button-group-tooltip'])}\n />\n )}\n </div>\n );\n }\n);\n\nexport default IconButtonItem;\n"]}
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import { ButtonGroupProps } from './interfaces';
3
+ export { ButtonGroupProps };
4
+ declare const ButtonGroup: React.ForwardRefExoticComponent<ButtonGroupProps & React.RefAttributes<ButtonGroupProps.Ref>>;
5
+ export default ButtonGroup;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/button-group/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAM1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGhD,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAE5B,QAAA,MAAM,WAAW,+FAsBhB,CAAC;AAGF,eAAe,WAAW,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { __rest } from "tslib";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ import React from 'react';
5
+ import { getBaseProps } from '../internal/base-component';
6
+ import useBaseComponent from '../internal/hooks/use-base-component';
7
+ import { applyDisplayName } from '../internal/utils/apply-display-name';
8
+ import { getExternalProps } from '../internal/utils/external-props';
9
+ import InternalButtonGroup from './internal';
10
+ const ButtonGroup = React.forwardRef((_a, ref) => {
11
+ var { variant, dropdownExpandToViewport } = _a, rest = __rest(_a, ["variant", "dropdownExpandToViewport"]);
12
+ const baseProps = getBaseProps(rest);
13
+ const baseComponentProps = useBaseComponent('ButtonGroup', {
14
+ props: {
15
+ variant,
16
+ dropdownExpandToViewport,
17
+ },
18
+ });
19
+ const externalProps = getExternalProps(rest);
20
+ return (React.createElement(InternalButtonGroup, Object.assign({}, baseProps, baseComponentProps, externalProps, { ref: ref, variant: variant, dropdownExpandToViewport: dropdownExpandToViewport })));
21
+ });
22
+ applyDisplayName(ButtonGroup, 'ButtonGroup');
23
+ export default ButtonGroup;
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/button-group/index.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,gBAAgB,MAAM,sCAAsC,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAEpE,OAAO,mBAAmB,MAAM,YAAY,CAAC;AAI7C,MAAM,WAAW,GAAG,KAAK,CAAC,UAAU,CAClC,CAAC,EAAgE,EAAE,GAAoC,EAAE,EAAE;QAA1G,EAAE,OAAO,EAAE,wBAAwB,OAA6B,EAAxB,IAAI,cAA5C,uCAA8C,CAAF;IAC3C,MAAM,SAAS,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,kBAAkB,GAAG,gBAAgB,CAAC,aAAa,EAAE;QACzD,KAAK,EAAE;YACL,OAAO;YACP,wBAAwB;SACzB;KACF,CAAC,CAAC;IAEH,MAAM,aAAa,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAC7C,OAAO,CACL,oBAAC,mBAAmB,oBACd,SAAS,EACT,kBAAkB,EAClB,aAAa,IACjB,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,OAAO,EAChB,wBAAwB,EAAE,wBAAwB,IAClD,CACH,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,gBAAgB,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;AAC7C,eAAe,WAAW,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 { getBaseProps } from '../internal/base-component';\nimport useBaseComponent from '../internal/hooks/use-base-component';\nimport { applyDisplayName } from '../internal/utils/apply-display-name';\nimport { getExternalProps } from '../internal/utils/external-props';\nimport { ButtonGroupProps } from './interfaces';\nimport InternalButtonGroup from './internal';\n\nexport { ButtonGroupProps };\n\nconst ButtonGroup = React.forwardRef(\n ({ variant, dropdownExpandToViewport, ...rest }: ButtonGroupProps, ref: React.Ref<ButtonGroupProps.Ref>) => {\n const baseProps = getBaseProps(rest);\n const baseComponentProps = useBaseComponent('ButtonGroup', {\n props: {\n variant,\n dropdownExpandToViewport,\n },\n });\n\n const externalProps = getExternalProps(rest);\n return (\n <InternalButtonGroup\n {...baseProps}\n {...baseComponentProps}\n {...externalProps}\n ref={ref}\n variant={variant}\n dropdownExpandToViewport={dropdownExpandToViewport}\n />\n );\n }\n);\n\napplyDisplayName(ButtonGroup, 'ButtonGroup');\nexport default ButtonGroup;\n"]}
@@ -0,0 +1,111 @@
1
+ /// <reference types="react" />
2
+ import { ButtonDropdownProps } from '../button-dropdown/interfaces';
3
+ import { IconProps } from '../icon/interfaces';
4
+ import { BaseComponentProps } from '../internal/base-component';
5
+ import { NonCancelableEventHandler } from '../internal/events';
6
+ import { InternalBaseComponentProps } from '../internal/hooks/use-base-component';
7
+ export interface ButtonGroupProps extends BaseComponentProps {
8
+ /**
9
+ * Adds `aria-label` to the button group toolbar element.
10
+ * Use this to provide a unique accessible name for each button group on the page.
11
+ */
12
+ ariaLabel?: string;
13
+ /**
14
+ * Determines the general styling of the button dropdown.
15
+ * * `icon` for icon buttons.
16
+ */
17
+ variant: ButtonGroupProps.Variant;
18
+ /**
19
+ * Use this property to determine dropdown placement strategy for all menu dropdown items.
20
+ *
21
+ * By default, the dropdown height is constrained to fit inside the height of its next scrollable container element.
22
+ * Enabling this property will allow the dropdown to extend beyond that container by using fixed positioning and
23
+ * [React Portals](https://reactjs.org/docs/portals.html).
24
+ *
25
+ * Set this property if the dropdown would otherwise be constrained by a scrollable container,
26
+ * for example inside table and split view layouts.
27
+ *
28
+ * We recommend you use discretion, and don't enable this property unless necessary
29
+ * because fixed positioning results in a slight, visible lag when scrolling complex pages.
30
+ */
31
+ dropdownExpandToViewport?: boolean;
32
+ /**
33
+ * Array of objects with a number of supported types.
34
+ *
35
+ * ### icon-button
36
+ *
37
+ * * `id` (string) - The unique identifier of the button, used as detail in `onItemClick` handler and to focus the button using `ref.focus(id)`.
38
+ * * `text` (string) - The name shown as a tooltip or menu text for this button.
39
+ * * `disabled` (optional, boolean) - The disabled state indication for the button.
40
+ * * `loading` (optional, boolean) - The loading state indication for the button.
41
+ * * `loadingText` (optional, string) - The loading text announced to screen readers.
42
+ * * `iconName` (optional, string) - Specifies the name of the icon, used with the [icon component](/components/icon/).
43
+ * * `iconAlt` (optional, string) - Specifies alternate text for the icon when using `iconUrl`.
44
+ * * `iconUrl` (optional, string) - Specifies the URL of a custom icon.
45
+ * * `iconSvg` (optional, ReactNode) - Custom SVG icon. Equivalent to the `svg` slot of the [icon component](/components/icon/).
46
+ * * `popoverFeedback` (optional, string) - Text that appears when the user clicks the button. Use to provide feedback to the user.
47
+ *
48
+ * ### menu-dropdown
49
+ *
50
+ * * `id` (string) - The unique identifier of the button, used as detail in `onItemClick`.
51
+ * * `text` (string) - The name of the menu button shown as a tooltip.
52
+ * * `disabled` (optional, boolean) - The disabled state indication for the menu button.
53
+ * * `loading` (optional, boolean) - The loading state indication for the menu button.
54
+ * * `loadingText` (optional, string) - The loading text announced to screen readers.
55
+ * * `items` (ButtonDropdownProps.ItemOrGroup[]) - The array of dropdown items that belong to this menu.
56
+ *
57
+ * group
58
+ *
59
+ * * `text` (string) - The name of the group rendered as ARIA label for this group.
60
+ * * `items` ((ButtonGroupProps.IconButton | ButtonGroupProps.MenuDropdown)[]) - The array of items that belong to this group.
61
+ */
62
+ items: ReadonlyArray<ButtonGroupProps.ItemOrGroup>;
63
+ /**
64
+ * Called when the user clicks on an item, and the item is not disabled. The event detail object contains the id of the clicked item.
65
+ */
66
+ onItemClick?: NonCancelableEventHandler<ButtonGroupProps.ItemClickDetails>;
67
+ }
68
+ export interface InternalButtonGroupProps extends ButtonGroupProps, InternalBaseComponentProps {
69
+ }
70
+ export declare namespace ButtonGroupProps {
71
+ type Variant = 'icon';
72
+ type ItemOrGroup = Item | Group;
73
+ type Item = IconButton | MenuDropdown;
74
+ interface IconButton {
75
+ type: 'icon-button';
76
+ id: string;
77
+ text: string;
78
+ disabled?: boolean;
79
+ loading?: boolean;
80
+ loadingText?: string;
81
+ iconName?: IconProps.Name;
82
+ iconAlt?: string;
83
+ iconUrl?: string;
84
+ iconSvg?: React.ReactNode;
85
+ popoverFeedback?: React.ReactNode;
86
+ }
87
+ interface MenuDropdown {
88
+ type: 'menu-dropdown';
89
+ id: string;
90
+ text: string;
91
+ disabled?: boolean;
92
+ loading?: boolean;
93
+ loadingText?: string;
94
+ items: ReadonlyArray<ButtonDropdownProps.ItemOrGroup>;
95
+ }
96
+ interface Group {
97
+ type: 'group';
98
+ text: string;
99
+ items: ReadonlyArray<ButtonGroupProps.Item>;
100
+ }
101
+ interface ItemClickDetails {
102
+ id: string;
103
+ }
104
+ interface Ref {
105
+ /**
106
+ * Focuses button group item by id.
107
+ */
108
+ focus(itemId: string): void;
109
+ }
110
+ }
111
+ //# sourceMappingURL=interfaces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../src/button-group/interfaces.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAElF,MAAM,WAAW,gBAAiB,SAAQ,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ClB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,KAAK,EAAE,aAAa,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC;KACvD;IAED,UAAiB,KAAK;QACpB,IAAI,EAAE,OAAO,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,aAAa,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;KAC7C;IAED,UAAiB,gBAAgB;QAC/B,EAAE,EAAE,MAAM,CAAC;KACZ;IAED,UAAiB,GAAG;QAClB;;WAEG;QACH,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;KAC7B;CACF"}
@@ -0,0 +1,4 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ export {};
4
+ //# sourceMappingURL=interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/button-group/interfaces.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { ButtonDropdownProps } from '../button-dropdown/interfaces';\nimport { IconProps } from '../icon/interfaces';\nimport { BaseComponentProps } from '../internal/base-component';\nimport { NonCancelableEventHandler } from '../internal/events';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component';\n\nexport interface ButtonGroupProps extends BaseComponentProps {\n /**\n * Adds `aria-label` to the button group toolbar element.\n * Use this to provide a unique accessible name for each button group on the page.\n */\n ariaLabel?: string;\n /**\n * Determines the general styling of the button dropdown.\n * * `icon` for icon buttons.\n */\n variant: ButtonGroupProps.Variant;\n /**\n * Use this property to determine dropdown placement strategy for all menu dropdown items.\n *\n * By default, the dropdown height is constrained to fit inside the height of its next scrollable container element.\n * Enabling this property will allow the dropdown to extend beyond that container by using fixed positioning and\n * [React Portals](https://reactjs.org/docs/portals.html).\n *\n * Set this property if the dropdown would otherwise be constrained by a scrollable container,\n * for example inside table and split view layouts.\n *\n * We recommend you use discretion, and don't enable this property unless necessary\n * because fixed positioning results in a slight, visible lag when scrolling complex pages.\n */\n dropdownExpandToViewport?: boolean;\n /**\n * Array of objects with a number of supported types.\n *\n * ### icon-button\n *\n * * `id` (string) - The unique identifier of the button, used as detail in `onItemClick` handler and to focus the button using `ref.focus(id)`.\n * * `text` (string) - The name shown as a tooltip or menu text for this button.\n * * `disabled` (optional, boolean) - The disabled state indication for the button.\n * * `loading` (optional, boolean) - The loading state indication for the button.\n * * `loadingText` (optional, string) - The loading text announced to screen readers.\n * * `iconName` (optional, string) - Specifies the name of the icon, used with the [icon component](/components/icon/).\n * * `iconAlt` (optional, string) - Specifies alternate text for the icon when using `iconUrl`.\n * * `iconUrl` (optional, string) - Specifies the URL of a custom icon.\n * * `iconSvg` (optional, ReactNode) - Custom SVG icon. Equivalent to the `svg` slot of the [icon component](/components/icon/).\n * * `popoverFeedback` (optional, string) - Text that appears when the user clicks the button. Use to provide feedback to the user.\n *\n * ### menu-dropdown\n *\n * * `id` (string) - The unique identifier of the button, used as detail in `onItemClick`.\n * * `text` (string) - The name of the menu button shown as a tooltip.\n * * `disabled` (optional, boolean) - The disabled state indication for the menu button.\n * * `loading` (optional, boolean) - The loading state indication for the menu button.\n * * `loadingText` (optional, string) - The loading text announced to screen readers.\n * * `items` (ButtonDropdownProps.ItemOrGroup[]) - The array of dropdown items that belong to this menu.\n *\n * group\n *\n * * `text` (string) - The name of the group rendered as ARIA label for this group.\n * * `items` ((ButtonGroupProps.IconButton | ButtonGroupProps.MenuDropdown)[]) - The array of items that belong to this group.\n */\n items: ReadonlyArray<ButtonGroupProps.ItemOrGroup>;\n /**\n * Called when the user clicks on an item, and the item is not disabled. The event detail object contains the id of the clicked item.\n */\n onItemClick?: NonCancelableEventHandler<ButtonGroupProps.ItemClickDetails>;\n}\n\nexport interface InternalButtonGroupProps extends ButtonGroupProps, InternalBaseComponentProps {}\n\nexport namespace ButtonGroupProps {\n export type Variant = 'icon';\n\n export type ItemOrGroup = Item | Group;\n export type Item = IconButton | MenuDropdown;\n\n export interface IconButton {\n type: 'icon-button';\n id: string;\n text: string;\n disabled?: boolean;\n loading?: boolean;\n loadingText?: string;\n iconName?: IconProps.Name;\n iconAlt?: string;\n iconUrl?: string;\n iconSvg?: React.ReactNode;\n popoverFeedback?: React.ReactNode;\n }\n\n export interface MenuDropdown {\n type: 'menu-dropdown';\n id: string;\n text: string;\n disabled?: boolean;\n loading?: boolean;\n loadingText?: string;\n items: ReadonlyArray<ButtonDropdownProps.ItemOrGroup>;\n }\n\n export interface Group {\n type: 'group';\n text: string;\n items: ReadonlyArray<ButtonGroupProps.Item>;\n }\n\n export interface ItemClickDetails {\n id: string;\n }\n\n export interface Ref {\n /**\n * Focuses button group item by id.\n */\n focus(itemId: string): void;\n }\n}\n"]}
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import { ButtonGroupProps, InternalButtonGroupProps } from './interfaces';
3
+ declare const InternalButtonGroup: React.ForwardRefExoticComponent<InternalButtonGroupProps & React.RefAttributes<ButtonGroupProps.Ref>>;
4
+ export default InternalButtonGroup;
5
+ //# sourceMappingURL=internal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/button-group/internal.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAuE,MAAM,OAAO,CAAC;AAiB5F,OAAO,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAM1E,QAAA,MAAM,mBAAmB,uGAoKxB,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
@@ -0,0 +1,123 @@
1
+ import { __rest } from "tslib";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react';
5
+ import clsx from 'clsx';
6
+ import { warnOnce } from '@cloudscape-design/component-toolkit/internal';
7
+ import { getBaseProps } from '../internal/base-component';
8
+ import { getAllFocusables } from '../internal/components/focus-lock/utils';
9
+ import { SingleTabStopNavigationProvider, } from '../internal/context/single-tab-stop-navigation-context';
10
+ import { hasModifierKeys } from '../internal/events';
11
+ import { useMergeRefs } from '../internal/hooks/use-merge-refs';
12
+ import { KeyCode } from '../internal/keycode';
13
+ import { circleIndex } from '../internal/utils/circle-index';
14
+ import handleKey from '../internal/utils/handle-key';
15
+ import ItemElement from './item-element.js';
16
+ import styles from './styles.css.js';
17
+ import testUtilStyles from './test-classes/styles.css.js';
18
+ const InternalButtonGroup = forwardRef((_a, ref) => {
19
+ var { items = [], onItemClick, ariaLabel, dropdownExpandToViewport, __internalRootRef = null } = _a, props = __rest(_a, ["items", "onItemClick", "ariaLabel", "dropdownExpandToViewport", "__internalRootRef"]);
20
+ const baseProps = getBaseProps(props);
21
+ const focusedIdRef = useRef(null);
22
+ const navigationAPI = useRef(null);
23
+ const containerObjectRef = useRef(null);
24
+ const containerRef = useMergeRefs(containerObjectRef, __internalRootRef);
25
+ const itemsRef = useRef({});
26
+ const [tooltip, setTooltip] = useState(null);
27
+ useImperativeHandle(ref, () => ({
28
+ focus: id => {
29
+ var _a;
30
+ (_a = itemsRef.current[id]) === null || _a === void 0 ? void 0 : _a.focus();
31
+ },
32
+ }));
33
+ function getNextFocusTarget() {
34
+ var _a, _b;
35
+ if (containerObjectRef.current) {
36
+ const buttons = Array.from(containerObjectRef.current.querySelectorAll(`.${testUtilStyles.item}`));
37
+ const activeButtons = buttons.filter(button => !button.disabled);
38
+ return (_b = (_a = activeButtons.find(button => button.dataset.itemid === focusedIdRef.current)) !== null && _a !== void 0 ? _a : activeButtons[0]) !== null && _b !== void 0 ? _b : null;
39
+ }
40
+ return null;
41
+ }
42
+ function onUnregisterActive(focusableElement) {
43
+ var _a;
44
+ // Only refocus when the node is actually removed (no such ID anymore).
45
+ const target = (_a = navigationAPI.current) === null || _a === void 0 ? void 0 : _a.getFocusTarget();
46
+ if (target && target.dataset.itemid !== focusableElement.dataset.itemid) {
47
+ target.focus();
48
+ }
49
+ }
50
+ useEffect(() => {
51
+ var _a;
52
+ (_a = navigationAPI.current) === null || _a === void 0 ? void 0 : _a.updateFocusTarget();
53
+ });
54
+ function onFocus(event) {
55
+ var _a;
56
+ if (event.target instanceof HTMLElement && event.target.dataset.itemid) {
57
+ focusedIdRef.current = event.target.dataset.itemid;
58
+ }
59
+ (_a = navigationAPI.current) === null || _a === void 0 ? void 0 : _a.updateFocusTarget();
60
+ }
61
+ function onBlur() {
62
+ var _a;
63
+ (_a = navigationAPI.current) === null || _a === void 0 ? void 0 : _a.updateFocusTarget();
64
+ }
65
+ function onKeyDown(event) {
66
+ var _a;
67
+ const focusTarget = (_a = navigationAPI.current) === null || _a === void 0 ? void 0 : _a.getFocusTarget();
68
+ const specialKeys = [KeyCode.right, KeyCode.left, KeyCode.end, KeyCode.home, KeyCode.pageUp, KeyCode.pageDown];
69
+ if (hasModifierKeys(event) || specialKeys.indexOf(event.keyCode) === -1) {
70
+ return;
71
+ }
72
+ if (!containerObjectRef.current || !focusTarget) {
73
+ return;
74
+ }
75
+ // Ignore navigation when the focused element is not an item.
76
+ if (document.activeElement && !document.activeElement.matches(`.${testUtilStyles.item}`)) {
77
+ return;
78
+ }
79
+ event.preventDefault();
80
+ const focusables = getFocusablesFrom(containerObjectRef.current);
81
+ const activeIndex = focusables.indexOf(focusTarget);
82
+ handleKey(event, {
83
+ onHome: () => focusElement(focusables[0]),
84
+ onEnd: () => focusElement(focusables[focusables.length - 1]),
85
+ onInlineStart: () => focusElement(focusables[circleIndex(activeIndex - 1, [0, focusables.length - 1])]),
86
+ onInlineEnd: () => focusElement(focusables[circleIndex(activeIndex + 1, [0, focusables.length - 1])]),
87
+ });
88
+ }
89
+ function focusElement(element) {
90
+ element.focus();
91
+ }
92
+ // List all non-disabled and registered focusables: those are eligible for keyboard navigation.
93
+ function getFocusablesFrom(target) {
94
+ function isElementRegistered(element) {
95
+ var _a, _b;
96
+ return (_b = (_a = navigationAPI.current) === null || _a === void 0 ? void 0 : _a.isRegistered(element)) !== null && _b !== void 0 ? _b : false;
97
+ }
98
+ function isElementDisabled(element) {
99
+ if (element instanceof HTMLButtonElement) {
100
+ return element.disabled;
101
+ }
102
+ return false;
103
+ }
104
+ return getAllFocusables(target).filter(el => isElementRegistered(el) && !isElementDisabled(el));
105
+ }
106
+ return (React.createElement("div", Object.assign({}, baseProps, { className: clsx(styles.root, testUtilStyles['button-group'], baseProps.className), ref: containerRef, role: "toolbar", "aria-label": ariaLabel, onFocus: onFocus, onBlur: onBlur, onKeyDown: onKeyDown }),
107
+ React.createElement(SingleTabStopNavigationProvider, { ref: navigationAPI, navigationActive: true, getNextFocusTarget: getNextFocusTarget, onUnregisterActive: onUnregisterActive }, items.map((itemOrGroup, index) => {
108
+ var _a;
109
+ const itemContent = (item) => (React.createElement(ItemElement, { key: item.id, item: item, dropdownExpandToViewport: dropdownExpandToViewport, tooltip: tooltip, setTooltip: setTooltip, onItemClick: onItemClick, ref: element => (itemsRef.current[item.id] = element) }));
110
+ const isGroupBefore = ((_a = items[index - 1]) === null || _a === void 0 ? void 0 : _a.type) === 'group';
111
+ const currentItem = items[index];
112
+ const isGroupNow = (currentItem === null || currentItem === void 0 ? void 0 : currentItem.type) === 'group';
113
+ const shouldAddDivider = isGroupBefore || (!isGroupBefore && isGroupNow && index !== 0);
114
+ if (isGroupNow && currentItem.items.length === 0) {
115
+ warnOnce('ButtonGroup', 'Empty group detected. Empty groups are not allowed.');
116
+ }
117
+ return (React.createElement(React.Fragment, { key: itemOrGroup.type === 'group' ? index : itemOrGroup.id },
118
+ shouldAddDivider && React.createElement("div", { className: styles.divider }),
119
+ itemOrGroup.type === 'group' ? (React.createElement("div", { key: index, role: "group", "aria-label": itemOrGroup.text, className: styles.group }, itemOrGroup.items.map(item => itemContent(item)))) : (itemContent(itemOrGroup))));
120
+ }))));
121
+ });
122
+ export default InternalButtonGroup;
123
+ //# sourceMappingURL=internal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/button-group/internal.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5F,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,MAAM,+CAA+C,CAAC;AAGzE,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAC3E,OAAO,EAEL,+BAA+B,GAChC,MAAM,wDAAwD,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,SAAS,MAAM,8BAA8B,CAAC;AAErD,OAAO,WAAW,MAAM,mBAAmB,CAAC;AAE5C,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,cAAc,MAAM,8BAA8B,CAAC;AAE1D,MAAM,mBAAmB,GAAG,UAAU,CACpC,CACE,EAO2B,EAC3B,GAAoC,EACpC,EAAE;QATF,EACE,KAAK,GAAG,EAAE,EACV,WAAW,EACX,SAAS,EACT,wBAAwB,EACxB,iBAAiB,GAAG,IAAI,OAEC,EADtB,KAAK,cANV,sFAOC,CADS;IAIV,MAAM,SAAS,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;IACtC,MAAM,YAAY,GAAG,MAAM,CAAgB,IAAI,CAAC,CAAC;IACjD,MAAM,aAAa,GAAG,MAAM,CAA6B,I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KAAK,KAAK,CAAC,CAAC,CAAC;YAExF,IAAI,UAAU,IAAI,WAAW,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;gBAChD,QAAQ,CAAC,aAAa,EAAE,qDAAqD,CAAC,CAAC;aAChF;YAED,OAAO,CACL,oBAAC,KAAK,CAAC,QAAQ,IAAC,GAAG,EAAE,WAAW,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,EAAE;gBACvE,gBAAgB,IAAI,6BAAK,SAAS,EAAE,MAAM,CAAC,OAAO,GAAI;gBACtD,WAAW,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,CAC9B,6BAAK,GAAG,EAAE,KAAK,EAAE,IAAI,EAAC,OAAO,gBAAa,WAAW,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,CAAC,KAAK,IAChF,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAC7C,CACP,CAAC,CAAC,CAAC,CACF,WAAW,CAAC,WAAW,CAAC,CACzB,CACc,CAClB,CAAC;QACJ,CAAC,CAAC,CAC8B,CAC9B,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,mBAAmB,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react';\nimport clsx from 'clsx';\n\nimport { warnOnce } from '@cloudscape-design/component-toolkit/internal';\n\nimport { ButtonProps } from '../button/interfaces';\nimport { getBaseProps } from '../internal/base-component';\nimport { getAllFocusables } from '../internal/components/focus-lock/utils';\nimport {\n SingleTabStopNavigationAPI,\n SingleTabStopNavigationProvider,\n} from '../internal/context/single-tab-stop-navigation-context';\nimport { hasModifierKeys } from '../internal/events';\nimport { useMergeRefs } from '../internal/hooks/use-merge-refs';\nimport { KeyCode } from '../internal/keycode';\nimport { circleIndex } from '../internal/utils/circle-index';\nimport handleKey from '../internal/utils/handle-key';\nimport { ButtonGroupProps, InternalButtonGroupProps } from './interfaces';\nimport ItemElement from './item-element.js';\n\nimport styles from './styles.css.js';\nimport testUtilStyles from './test-classes/styles.css.js';\n\nconst InternalButtonGroup = forwardRef(\n (\n {\n items = [],\n onItemClick,\n ariaLabel,\n dropdownExpandToViewport,\n __internalRootRef = null,\n ...props\n }: InternalButtonGroupProps,\n ref: React.Ref<ButtonGroupProps.Ref>\n ) => {\n const baseProps = getBaseProps(props);\n const focusedIdRef = useRef<null | string>(null);\n const navigationAPI = useRef<SingleTabStopNavigationAPI>(null);\n const containerObjectRef = useRef<HTMLDivElement>(null);\n const containerRef = useMergeRefs(containerObjectRef, __internalRootRef);\n const itemsRef = useRef<Record<string, ButtonProps.Ref | null>>({});\n const [tooltip, setTooltip] = useState<null | { item: string; feedback: boolean }>(null);\n\n useImperativeHandle(ref, () => ({\n focus: id => {\n itemsRef.current[id]?.focus();\n },\n }));\n\n function getNextFocusTarget(): null | HTMLElement {\n if (containerObjectRef.current) {\n const buttons: HTMLButtonElement[] = Array.from(\n containerObjectRef.current.querySelectorAll(`.${testUtilStyles.item}`)\n );\n const activeButtons = buttons.filter(button => !button.disabled);\n return activeButtons.find(button => button.dataset.itemid === focusedIdRef.current) ?? activeButtons[0] ?? null;\n }\n return null;\n }\n\n function onUnregisterActive(focusableElement: HTMLElement) {\n // Only refocus when the node is actually removed (no such ID anymore).\n const target = navigationAPI.current?.getFocusTarget();\n\n if (target && target.dataset.itemid !== focusableElement.dataset.itemid) {\n target.focus();\n }\n }\n\n useEffect(() => {\n navigationAPI.current?.updateFocusTarget();\n });\n\n function onFocus(event: React.FocusEvent) {\n if (event.target instanceof HTMLElement && event.target.dataset.itemid) {\n focusedIdRef.current = event.target.dataset.itemid;\n }\n\n navigationAPI.current?.updateFocusTarget();\n }\n\n function onBlur() {\n navigationAPI.current?.updateFocusTarget();\n }\n\n function onKeyDown(event: React.KeyboardEvent) {\n const focusTarget = navigationAPI.current?.getFocusTarget();\n const specialKeys = [KeyCode.right, KeyCode.left, KeyCode.end, KeyCode.home, KeyCode.pageUp, KeyCode.pageDown];\n if (hasModifierKeys(event) || specialKeys.indexOf(event.keyCode) === -1) {\n return;\n }\n if (!containerObjectRef.current || !focusTarget) {\n return;\n }\n // Ignore navigation when the focused element is not an item.\n if (document.activeElement && !document.activeElement.matches(`.${testUtilStyles.item}`)) {\n return;\n }\n event.preventDefault();\n\n const focusables = getFocusablesFrom(containerObjectRef.current);\n const activeIndex = focusables.indexOf(focusTarget);\n handleKey(event as any, {\n onHome: () => focusElement(focusables[0]),\n onEnd: () => focusElement(focusables[focusables.length - 1]),\n onInlineStart: () => focusElement(focusables[circleIndex(activeIndex - 1, [0, focusables.length - 1])]),\n onInlineEnd: () => focusElement(focusables[circleIndex(activeIndex + 1, [0, focusables.length - 1])]),\n });\n }\n\n function focusElement(element: HTMLElement) {\n element.focus();\n }\n\n // List all non-disabled and registered focusables: those are eligible for keyboard navigation.\n function getFocusablesFrom(target: HTMLElement) {\n function isElementRegistered(element: HTMLElement) {\n return navigationAPI.current?.isRegistered(element) ?? false;\n }\n\n function isElementDisabled(element: HTMLElement) {\n if (element instanceof HTMLButtonElement) {\n return element.disabled;\n }\n\n return false;\n }\n\n return getAllFocusables(target).filter(el => isElementRegistered(el) && !isElementDisabled(el));\n }\n\n return (\n <div\n {...baseProps}\n className={clsx(styles.root, testUtilStyles['button-group'], baseProps.className)}\n ref={containerRef}\n role=\"toolbar\"\n aria-label={ariaLabel}\n onFocus={onFocus}\n onBlur={onBlur}\n onKeyDown={onKeyDown}\n >\n <SingleTabStopNavigationProvider\n ref={navigationAPI}\n navigationActive={true}\n getNextFocusTarget={getNextFocusTarget}\n onUnregisterActive={onUnregisterActive}\n >\n {items.map((itemOrGroup, index) => {\n const itemContent = (item: ButtonGroupProps.Item) => (\n <ItemElement\n key={item.id}\n item={item}\n dropdownExpandToViewport={dropdownExpandToViewport}\n tooltip={tooltip}\n setTooltip={setTooltip}\n onItemClick={onItemClick}\n ref={element => (itemsRef.current[item.id] = element)}\n />\n );\n\n const isGroupBefore = items[index - 1]?.type === 'group';\n const currentItem = items[index];\n const isGroupNow = currentItem?.type === 'group';\n const shouldAddDivider = isGroupBefore || (!isGroupBefore && isGroupNow && index !== 0);\n\n if (isGroupNow && currentItem.items.length === 0) {\n warnOnce('ButtonGroup', 'Empty group detected. Empty groups are not allowed.');\n }\n\n return (\n <React.Fragment key={itemOrGroup.type === 'group' ? index : itemOrGroup.id}>\n {shouldAddDivider && <div className={styles.divider} />}\n {itemOrGroup.type === 'group' ? (\n <div key={index} role=\"group\" aria-label={itemOrGroup.text} className={styles.group}>\n {itemOrGroup.items.map(item => itemContent(item))}\n </div>\n ) : (\n itemContent(itemOrGroup)\n )}\n </React.Fragment>\n );\n })}\n </SingleTabStopNavigationProvider>\n </div>\n );\n }\n);\n\nexport default InternalButtonGroup;\n"]}
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+ import { ButtonProps } from '../button/interfaces.js';
3
+ import { NonCancelableEventHandler } from '../internal/events';
4
+ import { ButtonGroupProps } from './interfaces';
5
+ interface ItemElementProps {
6
+ item: ButtonGroupProps.Item;
7
+ dropdownExpandToViewport?: boolean;
8
+ tooltip: null | {
9
+ item: string;
10
+ feedback: boolean;
11
+ };
12
+ setTooltip: (tooltip: null | {
13
+ item: string;
14
+ feedback: boolean;
15
+ }) => void;
16
+ onItemClick?: NonCancelableEventHandler<ButtonGroupProps.ItemClickDetails> | undefined;
17
+ }
18
+ declare const ItemElement: React.ForwardRefExoticComponent<ItemElementProps & React.RefAttributes<ButtonProps.Ref>>;
19
+ export default ItemElement;
20
+ //# sourceMappingURL=item-element.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"item-element.d.ts","sourceRoot":"","sources":["../../../src/button-group/item-element.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA6D,MAAM,OAAO,CAAC;AAElF,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAoC,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAGjG,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAKhD,UAAU,gBAAgB;IACxB,IAAI,EAAE,gBAAgB,CAAC,IAAI,CAAC;IAC5B,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,OAAO,EAAE,IAAI,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,OAAO,CAAA;KAAE,CAAC;IACpD,UAAU,EAAE,CAAC,OAAO,EAAE,IAAI,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;IAC1E,WAAW,CAAC,EAAE,yBAAyB,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,GAAG,SAAS,CAAC;CACxF;AAED,QAAA,MAAM,WAAW,0FA4GhB,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -0,0 +1,74 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import React, { forwardRef, useEffect, useImperativeHandle, useRef } from 'react';
4
+ import { fireCancelableEvent } from '../internal/events';
5
+ import { nodeBelongs } from '../internal/utils/node-belongs';
6
+ import IconButtonItem from './icon-button-item';
7
+ import MenuDropdownItem from './menu-dropdown-item';
8
+ import styles from './styles.css.js';
9
+ const ItemElement = forwardRef(({ item, dropdownExpandToViewport, tooltip, setTooltip, onItemClick }, ref) => {
10
+ const containerRef = useRef(null);
11
+ const buttonRef = useRef(null);
12
+ useImperativeHandle(ref, () => ({
13
+ focus: () => {
14
+ var _a;
15
+ (_a = buttonRef.current) === null || _a === void 0 ? void 0 : _a.focus();
16
+ },
17
+ }));
18
+ useEffect(() => {
19
+ if ((tooltip === null || tooltip === void 0 ? void 0 : tooltip.item) !== item.id) {
20
+ return;
21
+ }
22
+ const close = () => {
23
+ setTooltip(null);
24
+ };
25
+ const handlePointerDownEvent = (event) => {
26
+ var _a;
27
+ if (event.target && ((_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.contains(event.target))) {
28
+ return;
29
+ }
30
+ close();
31
+ };
32
+ const handleKeyDownEvent = (event) => {
33
+ if (event.key === 'Escape') {
34
+ close();
35
+ }
36
+ };
37
+ window.addEventListener('pointerdown', handlePointerDownEvent);
38
+ window.addEventListener('keydown', handleKeyDownEvent);
39
+ return () => {
40
+ window.removeEventListener('pointerdown', handlePointerDownEvent);
41
+ window.removeEventListener('keydown', handleKeyDownEvent);
42
+ };
43
+ }, [item.id, tooltip, setTooltip]);
44
+ const onShowTooltipSoft = (show) => {
45
+ if (!(tooltip === null || tooltip === void 0 ? void 0 : tooltip.feedback)) {
46
+ setTooltip(show ? { item: item.id, feedback: false } : null);
47
+ }
48
+ };
49
+ const onShowTooltipHard = (show) => {
50
+ if (!show && item.id !== (tooltip === null || tooltip === void 0 ? void 0 : tooltip.item)) {
51
+ return;
52
+ }
53
+ setTooltip(show ? { item: item.id, feedback: false } : null);
54
+ };
55
+ const onClickHandler = (event) => {
56
+ const hasPopoverFeedback = 'popoverFeedback' in item && item.popoverFeedback;
57
+ if (hasPopoverFeedback) {
58
+ setTooltip({ item: item.id, feedback: true });
59
+ }
60
+ fireCancelableEvent(onItemClick, { id: 'id' in event.detail ? event.detail.id : item.id }, event);
61
+ };
62
+ return (React.createElement("div", { key: item.id, className: styles['item-wrapper'], ref: containerRef, onPointerEnter: () => onShowTooltipSoft(true), onPointerLeave: () => onShowTooltipSoft(false), onFocus: event => {
63
+ // Showing no tooltip when the focus comes from inside the container.
64
+ // This is needed to prevent the tooltip after a menu closes with item selection or Escape.
65
+ if (event && event.relatedTarget && nodeBelongs(containerRef.current, event.relatedTarget)) {
66
+ return;
67
+ }
68
+ onShowTooltipHard(true);
69
+ }, onBlur: () => onShowTooltipHard(false) },
70
+ item.type === 'icon-button' && (React.createElement(IconButtonItem, { ref: buttonRef, item: item, onItemClick: onClickHandler, showTooltip: (tooltip === null || tooltip === void 0 ? void 0 : tooltip.item) === item.id, showFeedback: !!(tooltip === null || tooltip === void 0 ? void 0 : tooltip.feedback) })),
71
+ item.type === 'menu-dropdown' && (React.createElement(MenuDropdownItem, { ref: buttonRef, item: item, showTooltip: (tooltip === null || tooltip === void 0 ? void 0 : tooltip.item) === item.id, onItemClick: onClickHandler, expandToViewport: dropdownExpandToViewport }))));
72
+ });
73
+ export default ItemElement;
74
+ //# sourceMappingURL=item-element.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"item-element.js","sourceRoot":"","sources":["../../../src/button-group/item-element.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAGlF,OAAO,EAAe,mBAAmB,EAA6B,MAAM,oBAAoB,CAAC;AACjG,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,cAAc,MAAM,oBAAoB,CAAC;AAEhD,OAAO,gBAAgB,MAAM,sBAAsB,CAAC;AAEpD,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAUrC,MAAM,WAAW,GAAG,UAAU,CAC5B,CACE,EAAE,IAAI,EAAE,wBAAwB,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAoB,EACtF,GAA+B,EAC/B,EAAE;IACF,MAAM,YAAY,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAClD,MAAM,SAAS,GAAG,MAAM,CAAoB,IAAI,CAAC,CAAC;IAElD,mBAAmB,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;QAC9B,KAAK,EAAE,GAAG,EAAE;;YACV,MAAA,SAAS,CAAC,OAAO,0CAAE,KAAK,EAAE,CAAC;QAC7B,CA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AAK,IAAI,KAAK,CAAC,aAAa,IAAI,WAAW,CAAC,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC,aAAa,CAAC,EAAE;gBAC1F,OAAO;aACR;YACD,iBAAiB,CAAC,IAAI,CAAC,CAAC;QAC1B,CAAC,EACD,MAAM,EAAE,GAAG,EAAE,CAAC,iBAAiB,CAAC,KAAK,CAAC;QAErC,IAAI,CAAC,IAAI,KAAK,aAAa,IAAI,CAC9B,oBAAC,cAAc,IACb,GAAG,EAAE,SAAS,EACd,IAAI,EAAE,IAAI,EACV,WAAW,EAAE,cAAc,EAC3B,WAAW,EAAE,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,MAAK,IAAI,CAAC,EAAE,EACtC,YAAY,EAAE,CAAC,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,CAAA,GACjC,CACH;QACA,IAAI,CAAC,IAAI,KAAK,eAAe,IAAI,CAChC,oBAAC,gBAAgB,IACf,GAAG,EAAE,SAAS,EACd,IAAI,EAAE,IAAI,EACV,WAAW,EAAE,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,MAAK,IAAI,CAAC,EAAE,EACtC,WAAW,EAAE,cAAc,EAC3B,gBAAgB,EAAE,wBAAwB,GAC1C,CACH,CACG,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,WAAW,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { forwardRef, useEffect, useImperativeHandle, useRef } from 'react';\n\nimport { ButtonProps } from '../button/interfaces.js';\nimport { ClickDetail, fireCancelableEvent, NonCancelableEventHandler } from '../internal/events';\nimport { nodeBelongs } from '../internal/utils/node-belongs';\nimport IconButtonItem from './icon-button-item';\nimport { ButtonGroupProps } from './interfaces';\nimport MenuDropdownItem from './menu-dropdown-item';\n\nimport styles from './styles.css.js';\n\ninterface ItemElementProps {\n item: ButtonGroupProps.Item;\n dropdownExpandToViewport?: boolean;\n tooltip: null | { item: string; feedback: boolean };\n setTooltip: (tooltip: null | { item: string; feedback: boolean }) => void;\n onItemClick?: NonCancelableEventHandler<ButtonGroupProps.ItemClickDetails> | undefined;\n}\n\nconst ItemElement = forwardRef(\n (\n { item, dropdownExpandToViewport, tooltip, setTooltip, onItemClick }: ItemElementProps,\n ref: React.Ref<ButtonProps.Ref>\n ) => {\n const containerRef = useRef<HTMLDivElement>(null);\n const buttonRef = useRef<HTMLButtonElement>(null);\n\n useImperativeHandle(ref, () => ({\n focus: () => {\n buttonRef.current?.focus();\n },\n }));\n\n useEffect(() => {\n if (tooltip?.item !== item.id) {\n return;\n }\n\n const close = () => {\n setTooltip(null);\n };\n\n const handlePointerDownEvent = (event: PointerEvent) => {\n if (event.target && containerRef.current?.contains(event.target as HTMLElement)) {\n return;\n }\n\n close();\n };\n\n const handleKeyDownEvent = (event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n close();\n }\n };\n\n window.addEventListener('pointerdown', handlePointerDownEvent);\n window.addEventListener('keydown', handleKeyDownEvent);\n\n return () => {\n window.removeEventListener('pointerdown', handlePointerDownEvent);\n window.removeEventListener('keydown', handleKeyDownEvent);\n };\n }, [item.id, tooltip, setTooltip]);\n\n const onShowTooltipSoft = (show: boolean) => {\n if (!tooltip?.feedback) {\n setTooltip(show ? { item: item.id, feedback: false } : null);\n }\n };\n\n const onShowTooltipHard = (show: boolean) => {\n if (!show && item.id !== tooltip?.item) {\n return;\n }\n\n setTooltip(show ? { item: item.id, feedback: false } : null);\n };\n\n const onClickHandler = (event: CustomEvent<ButtonGroupProps.ItemClickDetails | ClickDetail>) => {\n const hasPopoverFeedback = 'popoverFeedback' in item && item.popoverFeedback;\n\n if (hasPopoverFeedback) {\n setTooltip({ item: item.id, feedback: true });\n }\n\n fireCancelableEvent(onItemClick, { id: 'id' in event.detail ? event.detail.id : item.id }, event);\n };\n\n return (\n <div\n key={item.id}\n className={styles['item-wrapper']}\n ref={containerRef}\n onPointerEnter={() => onShowTooltipSoft(true)}\n onPointerLeave={() => onShowTooltipSoft(false)}\n onFocus={event => {\n // Showing no tooltip when the focus comes from inside the container.\n // This is needed to prevent the tooltip after a menu closes with item selection or Escape.\n if (event && event.relatedTarget && nodeBelongs(containerRef.current, event.relatedTarget)) {\n return;\n }\n onShowTooltipHard(true);\n }}\n onBlur={() => onShowTooltipHard(false)}\n >\n {item.type === 'icon-button' && (\n <IconButtonItem\n ref={buttonRef}\n item={item}\n onItemClick={onClickHandler}\n showTooltip={tooltip?.item === item.id}\n showFeedback={!!tooltip?.feedback}\n />\n )}\n {item.type === 'menu-dropdown' && (\n <MenuDropdownItem\n ref={buttonRef}\n item={item}\n showTooltip={tooltip?.item === item.id}\n onItemClick={onClickHandler}\n expandToViewport={dropdownExpandToViewport}\n />\n )}\n </div>\n );\n }\n);\n\nexport default ItemElement;\n"]}
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import { ButtonDropdownProps } from '../button-dropdown/interfaces';
3
+ import { CancelableEventHandler } from '../internal/events';
4
+ import { ButtonGroupProps } from './interfaces';
5
+ interface MenuDropdownItemProps {
6
+ item: ButtonGroupProps.MenuDropdown;
7
+ showTooltip: boolean;
8
+ onItemClick?: CancelableEventHandler<ButtonGroupProps.ItemClickDetails>;
9
+ expandToViewport?: boolean;
10
+ }
11
+ declare const MenuDropdownItem: React.ForwardRefExoticComponent<MenuDropdownItemProps & React.RefAttributes<ButtonDropdownProps.Ref>>;
12
+ export default MenuDropdownItem;
13
+ //# sourceMappingURL=menu-dropdown-item.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"menu-dropdown-item.d.ts","sourceRoot":"","sources":["../../../src/button-group/menu-dropdown-item.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAGpE,OAAO,EAAE,sBAAsB,EAAuB,MAAM,oBAAoB,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAIhD,UAAU,qBAAqB;IAC7B,IAAI,EAAE,gBAAgB,CAAC,YAAY,CAAC;IACpC,WAAW,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,sBAAsB,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;IACxE,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,QAAA,MAAM,gBAAgB,uGAiDrB,CAAC;AAEF,eAAe,gBAAgB,CAAC"}