@canonical/react-ds-global 0.29.1 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -0
- package/dist/esm/lib/_work_in_progress/IconSection/IconSection.js +1 -1
- package/dist/esm/lib/_work_in_progress/IconSection/IconSection.js.map +1 -1
- package/dist/esm/lib/_work_in_progress/index.js +13 -0
- package/dist/esm/lib/_work_in_progress/index.js.map +1 -0
- package/dist/esm/lib/component/Accordion/common/Item/styles.css +73 -56
- package/dist/esm/lib/component/Accordion/styles.css +5 -1
- package/dist/esm/lib/component/Announcement/Announcement.js +5 -3
- package/dist/esm/lib/component/Announcement/Announcement.js.map +1 -1
- package/dist/esm/lib/component/Announcement/index.js +1 -0
- package/dist/esm/lib/component/Announcement/index.js.map +1 -1
- package/dist/esm/lib/component/Announcement/styles.css +60 -36
- package/dist/esm/lib/component/Badge/styles.css +25 -24
- package/dist/esm/lib/component/Breadcrumbs/Breadcrumbs.js +2 -2
- package/dist/esm/lib/component/Breadcrumbs/common/Item/Item.js +13 -3
- package/dist/esm/lib/component/Breadcrumbs/common/Item/Item.js.map +1 -1
- package/dist/esm/lib/component/Breadcrumbs/common/Item/styles.css +17 -5
- package/dist/esm/lib/component/Breadcrumbs/styles.css +3 -0
- package/dist/esm/lib/component/Button/Button.js +13 -6
- package/dist/esm/lib/component/Button/Button.js.map +1 -1
- package/dist/esm/lib/component/Button/styles.css +200 -38
- package/dist/esm/lib/component/Card/Card.js +16 -6
- package/dist/esm/lib/component/Card/Card.js.map +1 -1
- package/dist/esm/lib/component/Card/common/Content/styles.css +8 -4
- package/dist/esm/lib/component/Card/common/Footer/Footer.js +2 -2
- package/dist/esm/lib/component/Card/common/Footer/styles.css +13 -3
- package/dist/esm/lib/component/Card/common/Header/styles.css +1 -1
- package/dist/esm/lib/component/Card/common/index.js +0 -1
- package/dist/esm/lib/component/Card/common/index.js.map +1 -1
- package/dist/esm/lib/component/Card/styles.css +60 -22
- package/dist/esm/lib/component/Chip/styles.css +3 -0
- package/dist/esm/lib/component/ContextualMenu/ContextualMenu.js +96 -0
- package/dist/esm/lib/component/ContextualMenu/ContextualMenu.js.map +1 -0
- package/dist/esm/lib/component/ContextualMenu/common/Item/Item.js +32 -0
- package/dist/esm/lib/component/ContextualMenu/common/Item/Item.js.map +1 -0
- package/dist/esm/lib/component/ContextualMenu/common/Item/index.js +2 -0
- package/dist/esm/lib/component/ContextualMenu/common/Item/index.js.map +1 -0
- package/dist/esm/lib/component/ContextualMenu/common/Item/styles.css +121 -0
- package/dist/esm/lib/component/ContextualMenu/common/Item/types.js.map +1 -0
- package/dist/esm/lib/component/ContextualMenu/common/MenuContext.js +12 -0
- package/dist/esm/lib/component/ContextualMenu/common/MenuContext.js.map +1 -0
- package/dist/esm/lib/component/ContextualMenu/common/SubMenu/SubMenu.js +128 -0
- package/dist/esm/lib/component/ContextualMenu/common/SubMenu/SubMenu.js.map +1 -0
- package/dist/esm/lib/component/ContextualMenu/common/SubMenu/index.js +2 -0
- package/dist/esm/lib/component/ContextualMenu/common/SubMenu/index.js.map +1 -0
- package/dist/esm/lib/component/ContextualMenu/index.js +2 -0
- package/dist/esm/lib/component/ContextualMenu/index.js.map +1 -0
- package/dist/esm/lib/component/ContextualMenu/styles.css +86 -0
- package/dist/esm/lib/component/ContextualMenu/types.js.map +1 -0
- package/dist/esm/lib/component/Popover/Popover.js +50 -0
- package/dist/esm/lib/component/Popover/Popover.js.map +1 -0
- package/dist/esm/lib/component/Popover/index.js +2 -0
- package/dist/esm/lib/component/Popover/index.js.map +1 -0
- package/dist/esm/lib/component/Popover/styles.css +65 -0
- package/dist/esm/lib/component/Popover/types.js +2 -0
- package/dist/esm/lib/component/Popover/types.js.map +1 -0
- package/dist/esm/lib/component/Tabs/Tabs.js +27 -0
- package/dist/esm/lib/component/Tabs/Tabs.js.map +1 -0
- package/dist/esm/lib/component/Tabs/common/Item/Item.js +20 -0
- package/dist/esm/lib/component/Tabs/common/Item/Item.js.map +1 -0
- package/dist/esm/lib/component/Tabs/common/Item/index.js +3 -0
- package/dist/esm/lib/component/Tabs/common/Item/index.js.map +1 -0
- package/dist/esm/lib/component/Tabs/common/Item/styles.css +75 -0
- package/dist/esm/lib/component/Tabs/common/Item/types.js +2 -0
- package/dist/esm/lib/component/Tabs/common/Item/types.js.map +1 -0
- package/dist/esm/lib/component/Tabs/common/index.js +2 -0
- package/dist/esm/lib/component/Tabs/common/index.js.map +1 -0
- package/dist/esm/lib/component/Tabs/index.js +3 -0
- package/dist/esm/lib/component/Tabs/index.js.map +1 -0
- package/dist/esm/lib/component/Tabs/styles.css +37 -0
- package/dist/esm/lib/component/Tabs/types.js +2 -0
- package/dist/esm/lib/component/Tabs/types.js.map +1 -0
- package/dist/esm/lib/component/Tile/Tile.js +6 -1
- package/dist/esm/lib/component/Tile/Tile.js.map +1 -1
- package/dist/esm/lib/component/Tile/common/Content/styles.css +17 -8
- package/dist/esm/lib/component/Tile/common/Header/styles.css +15 -12
- package/dist/esm/lib/component/Tile/styles.css +19 -53
- package/dist/esm/lib/component/Tooltip/Tooltip.js +6 -4
- package/dist/esm/lib/component/Tooltip/Tooltip.js.map +1 -1
- package/dist/esm/lib/component/Tooltip/common/TooltipArea/TooltipArea.js +45 -25
- package/dist/esm/lib/component/Tooltip/common/TooltipArea/TooltipArea.js.map +1 -1
- package/dist/esm/lib/component/Tooltip/styles.css +146 -81
- package/dist/esm/lib/component/Tooltip/withTooltip.js +3 -3
- package/dist/esm/lib/component/Tooltip/withTooltip.js.map +1 -1
- package/dist/esm/lib/component/index.js +17 -0
- package/dist/esm/lib/component/index.js.map +1 -0
- package/dist/esm/lib/group/Cards/Cards.js +49 -0
- package/dist/esm/lib/group/Cards/Cards.js.map +1 -0
- package/dist/esm/lib/group/Cards/index.js +3 -0
- package/dist/esm/lib/group/Cards/index.js.map +1 -0
- package/dist/esm/lib/group/Cards/styles.css +55 -0
- package/dist/esm/lib/group/Cards/types.js +2 -0
- package/dist/esm/lib/group/Cards/types.js.map +1 -0
- package/dist/esm/lib/group/index.js +4 -0
- package/dist/esm/lib/group/index.js.map +1 -0
- package/dist/esm/lib/hooks/index.js +3 -1
- package/dist/esm/lib/hooks/index.js.map +1 -1
- package/dist/esm/lib/hooks/useContextualMenu/index.js +3 -0
- package/dist/esm/lib/hooks/useContextualMenu/index.js.map +1 -0
- package/dist/esm/lib/hooks/useContextualMenu/types.js +2 -0
- package/dist/esm/lib/hooks/useContextualMenu/types.js.map +1 -0
- package/dist/esm/lib/hooks/useContextualMenu/useContextualMenu.js +181 -0
- package/dist/esm/lib/hooks/useContextualMenu/useContextualMenu.js.map +1 -0
- package/dist/esm/lib/hooks/useDisclosure/index.js +3 -0
- package/dist/esm/lib/hooks/useDisclosure/index.js.map +1 -0
- package/dist/esm/lib/hooks/useDisclosure/types.js +2 -0
- package/dist/esm/lib/hooks/useDisclosure/types.js.map +1 -0
- package/dist/esm/lib/hooks/useDisclosure/useDisclosure.js +230 -0
- package/dist/esm/lib/hooks/useDisclosure/useDisclosure.js.map +1 -0
- package/dist/esm/lib/hooks/useIsMounted/index.js +3 -0
- package/dist/esm/lib/hooks/useIsMounted/index.js.map +1 -0
- package/dist/esm/lib/hooks/useIsMounted/types.js +2 -0
- package/dist/esm/lib/hooks/useIsMounted/types.js.map +1 -0
- package/dist/esm/lib/hooks/useIsMounted/useIsMounted.js +21 -0
- package/dist/esm/lib/hooks/useIsMounted/useIsMounted.js.map +1 -0
- package/dist/esm/lib/hooks/useResizeObserver/useResizeObserver.js +37 -7
- package/dist/esm/lib/hooks/useResizeObserver/useResizeObserver.js.map +1 -1
- package/dist/esm/lib/hooks/useWindowDimensions/useWindowDimensions.js +9 -0
- package/dist/esm/lib/hooks/useWindowDimensions/useWindowDimensions.js.map +1 -1
- package/dist/esm/lib/hooks/useWindowFitment/index.js +1 -0
- package/dist/esm/lib/hooks/useWindowFitment/index.js.map +1 -1
- package/dist/esm/lib/hooks/useWindowFitment/readingDirection.js +25 -0
- package/dist/esm/lib/hooks/useWindowFitment/readingDirection.js.map +1 -0
- package/dist/esm/lib/hooks/useWindowFitment/useWindowFitment.js +211 -21
- package/dist/esm/lib/hooks/useWindowFitment/useWindowFitment.js.map +1 -1
- package/dist/esm/lib/index.js +8 -25
- package/dist/esm/lib/index.js.map +1 -1
- package/dist/esm/lib/pattern/index.js +3 -0
- package/dist/esm/lib/pattern/index.js.map +1 -0
- package/dist/esm/lib/subcomponent/Spinner/Spinner.js +35 -0
- package/dist/esm/lib/subcomponent/Spinner/Spinner.js.map +1 -0
- package/dist/esm/lib/subcomponent/Spinner/index.js +2 -0
- package/dist/esm/lib/subcomponent/Spinner/index.js.map +1 -0
- package/dist/esm/lib/subcomponent/Spinner/styles.css +50 -0
- package/dist/esm/lib/subcomponent/Spinner/types.js +2 -0
- package/dist/esm/lib/subcomponent/Spinner/types.js.map +1 -0
- package/dist/esm/lib/subcomponent/index.js +3 -0
- package/dist/esm/lib/subcomponent/index.js.map +1 -0
- package/dist/esm/lib/types/link.js +2 -0
- package/dist/esm/lib/types/link.js.map +1 -0
- package/dist/types/lib/_work_in_progress/Link/types.d.ts +1 -1
- package/dist/types/lib/_work_in_progress/Link/types.d.ts.map +1 -1
- package/dist/types/lib/_work_in_progress/index.d.ts +12 -0
- package/dist/types/lib/_work_in_progress/index.d.ts.map +1 -0
- package/dist/types/lib/component/Announcement/Announcement.d.ts +2 -2
- package/dist/types/lib/component/Announcement/Announcement.d.ts.map +1 -1
- package/dist/types/lib/component/Announcement/index.d.ts.map +1 -1
- package/dist/types/lib/component/Announcement/types.d.ts +17 -6
- package/dist/types/lib/component/Announcement/types.d.ts.map +1 -1
- package/dist/types/lib/component/Breadcrumbs/Breadcrumbs.d.ts +3 -3
- package/dist/types/lib/component/Breadcrumbs/common/Item/Item.d.ts +1 -1
- package/dist/types/lib/component/Breadcrumbs/common/Item/Item.d.ts.map +1 -1
- package/dist/types/lib/component/Breadcrumbs/common/Item/types.d.ts +13 -13
- package/dist/types/lib/component/Breadcrumbs/common/Item/types.d.ts.map +1 -1
- package/dist/types/lib/component/Breadcrumbs/types.d.ts +23 -1
- package/dist/types/lib/component/Breadcrumbs/types.d.ts.map +1 -1
- package/dist/types/lib/component/Button/Button.d.ts +3 -1
- package/dist/types/lib/component/Button/Button.d.ts.map +1 -1
- package/dist/types/lib/component/Button/types.d.ts +12 -6
- package/dist/types/lib/component/Button/types.d.ts.map +1 -1
- package/dist/types/lib/component/Card/Card.d.ts +10 -5
- package/dist/types/lib/component/Card/Card.d.ts.map +1 -1
- package/dist/types/lib/component/Card/common/Footer/Footer.d.ts +2 -2
- package/dist/types/lib/component/Card/common/Footer/types.d.ts +2 -2
- package/dist/types/lib/component/Card/common/Footer/types.d.ts.map +1 -1
- package/dist/types/lib/component/Card/common/index.d.ts +0 -1
- package/dist/types/lib/component/Card/common/index.d.ts.map +1 -1
- package/dist/types/lib/component/ContextualMenu/ContextualMenu.d.ts +15 -0
- package/dist/types/lib/component/ContextualMenu/ContextualMenu.d.ts.map +1 -0
- package/dist/types/lib/component/ContextualMenu/common/Item/Item.d.ts +14 -0
- package/dist/types/lib/component/ContextualMenu/common/Item/Item.d.ts.map +1 -0
- package/dist/types/lib/component/ContextualMenu/common/Item/index.d.ts +3 -0
- package/dist/types/lib/component/ContextualMenu/common/Item/index.d.ts.map +1 -0
- package/dist/types/lib/component/ContextualMenu/common/Item/types.d.ts +11 -0
- package/dist/types/lib/component/ContextualMenu/common/Item/types.d.ts.map +1 -0
- package/dist/types/lib/component/ContextualMenu/common/MenuContext.d.ts +19 -0
- package/dist/types/lib/component/ContextualMenu/common/MenuContext.d.ts.map +1 -0
- package/dist/types/lib/component/ContextualMenu/common/SubMenu/SubMenu.d.ts +15 -0
- package/dist/types/lib/component/ContextualMenu/common/SubMenu/SubMenu.d.ts.map +1 -0
- package/dist/types/lib/component/ContextualMenu/common/SubMenu/index.d.ts +2 -0
- package/dist/types/lib/component/ContextualMenu/common/SubMenu/index.d.ts.map +1 -0
- package/dist/types/lib/component/ContextualMenu/index.d.ts +3 -0
- package/dist/types/lib/component/ContextualMenu/index.d.ts.map +1 -0
- package/dist/types/lib/component/ContextualMenu/types.d.ts +30 -0
- package/dist/types/lib/component/ContextualMenu/types.d.ts.map +1 -0
- package/dist/types/lib/component/Popover/Popover.d.ts +16 -0
- package/dist/types/lib/component/Popover/Popover.d.ts.map +1 -0
- package/dist/types/lib/component/Popover/index.d.ts +3 -0
- package/dist/types/lib/component/Popover/index.d.ts.map +1 -0
- package/dist/types/lib/component/Popover/types.d.ts +24 -0
- package/dist/types/lib/component/Popover/types.d.ts.map +1 -0
- package/dist/types/lib/component/Tabs/Tabs.d.ts +18 -0
- package/dist/types/lib/component/Tabs/Tabs.d.ts.map +1 -0
- package/dist/types/lib/component/Tabs/common/Item/Item.d.ts +15 -0
- package/dist/types/lib/component/Tabs/common/Item/Item.d.ts.map +1 -0
- package/dist/types/lib/component/Tabs/common/Item/index.d.ts +3 -0
- package/dist/types/lib/component/Tabs/common/Item/index.d.ts.map +1 -0
- package/dist/types/lib/component/Tabs/common/Item/types.d.ts +18 -0
- package/dist/types/lib/component/Tabs/common/Item/types.d.ts.map +1 -0
- package/dist/types/lib/component/Tabs/common/index.d.ts +2 -0
- package/dist/types/lib/component/Tabs/common/index.d.ts.map +1 -0
- package/dist/types/lib/component/Tabs/index.d.ts +3 -0
- package/dist/types/lib/component/Tabs/index.d.ts.map +1 -0
- package/dist/types/lib/component/Tabs/types.d.ts +46 -0
- package/dist/types/lib/component/Tabs/types.d.ts.map +1 -0
- package/dist/types/lib/component/Tile/Tile.d.ts +2 -0
- package/dist/types/lib/component/Tile/Tile.d.ts.map +1 -1
- package/dist/types/lib/component/Tile/common/Content/types.d.ts +1 -1
- package/dist/types/lib/component/Tile/common/Header/types.d.ts +1 -1
- package/dist/types/lib/component/Tile/types.d.ts +4 -5
- package/dist/types/lib/component/Tile/types.d.ts.map +1 -1
- package/dist/types/lib/component/Tooltip/Tooltip.d.ts +1 -1
- package/dist/types/lib/component/Tooltip/Tooltip.d.ts.map +1 -1
- package/dist/types/lib/component/Tooltip/common/TooltipArea/TooltipArea.d.ts +1 -1
- package/dist/types/lib/component/Tooltip/common/TooltipArea/TooltipArea.d.ts.map +1 -1
- package/dist/types/lib/component/Tooltip/common/TooltipArea/types.d.ts +14 -2
- package/dist/types/lib/component/Tooltip/common/TooltipArea/types.d.ts.map +1 -1
- package/dist/types/lib/component/Tooltip/types.d.ts +6 -0
- package/dist/types/lib/component/Tooltip/types.d.ts.map +1 -1
- package/dist/types/lib/component/Tooltip/withTooltip.d.ts +10 -3
- package/dist/types/lib/component/Tooltip/withTooltip.d.ts.map +1 -1
- package/dist/types/lib/component/index.d.ts +16 -0
- package/dist/types/lib/component/index.d.ts.map +1 -0
- package/dist/types/lib/group/Cards/Cards.d.ts +40 -0
- package/dist/types/lib/group/Cards/Cards.d.ts.map +1 -0
- package/dist/types/lib/group/Cards/index.d.ts +3 -0
- package/dist/types/lib/group/Cards/index.d.ts.map +1 -0
- package/dist/types/lib/group/Cards/types.d.ts +14 -0
- package/dist/types/lib/group/Cards/types.d.ts.map +1 -0
- package/dist/types/lib/group/index.d.ts +3 -0
- package/dist/types/lib/group/index.d.ts.map +1 -0
- package/dist/types/lib/hooks/index.d.ts +3 -1
- package/dist/types/lib/hooks/index.d.ts.map +1 -1
- package/dist/types/lib/hooks/useContextualMenu/index.d.ts +3 -0
- package/dist/types/lib/hooks/useContextualMenu/index.d.ts.map +1 -0
- package/dist/types/lib/hooks/useContextualMenu/types.d.ts +71 -0
- package/dist/types/lib/hooks/useContextualMenu/types.d.ts.map +1 -0
- package/dist/types/lib/hooks/useContextualMenu/useContextualMenu.d.ts +20 -0
- package/dist/types/lib/hooks/useContextualMenu/useContextualMenu.d.ts.map +1 -0
- package/dist/types/lib/hooks/useDisclosure/index.d.ts +3 -0
- package/dist/types/lib/hooks/useDisclosure/index.d.ts.map +1 -0
- package/dist/types/lib/hooks/useDisclosure/types.d.ts +103 -0
- package/dist/types/lib/hooks/useDisclosure/types.d.ts.map +1 -0
- package/dist/types/lib/hooks/useDisclosure/useDisclosure.d.ts +32 -0
- package/dist/types/lib/hooks/useDisclosure/useDisclosure.d.ts.map +1 -0
- package/dist/types/lib/hooks/useIsMounted/index.d.ts +3 -0
- package/dist/types/lib/hooks/useIsMounted/index.d.ts.map +1 -0
- package/dist/types/lib/hooks/useIsMounted/types.d.ts +6 -0
- package/dist/types/lib/hooks/useIsMounted/types.d.ts.map +1 -0
- package/dist/types/lib/hooks/useIsMounted/useIsMounted.d.ts +15 -0
- package/dist/types/lib/hooks/useIsMounted/useIsMounted.d.ts.map +1 -0
- package/dist/types/lib/hooks/useResizeObserver/useResizeObserver.d.ts +6 -0
- package/dist/types/lib/hooks/useResizeObserver/useResizeObserver.d.ts.map +1 -1
- package/dist/types/lib/hooks/useWindowDimensions/useWindowDimensions.d.ts.map +1 -1
- package/dist/types/lib/hooks/useWindowFitment/index.d.ts +1 -0
- package/dist/types/lib/hooks/useWindowFitment/index.d.ts.map +1 -1
- package/dist/types/lib/hooks/useWindowFitment/readingDirection.d.ts +14 -0
- package/dist/types/lib/hooks/useWindowFitment/readingDirection.d.ts.map +1 -0
- package/dist/types/lib/hooks/useWindowFitment/types.d.ts +75 -4
- package/dist/types/lib/hooks/useWindowFitment/types.d.ts.map +1 -1
- package/dist/types/lib/hooks/useWindowFitment/useWindowFitment.d.ts +44 -2
- package/dist/types/lib/hooks/useWindowFitment/useWindowFitment.d.ts.map +1 -1
- package/dist/types/lib/index.d.ts +5 -25
- package/dist/types/lib/index.d.ts.map +1 -1
- package/dist/types/lib/pattern/index.d.ts +2 -0
- package/dist/types/lib/pattern/index.d.ts.map +1 -0
- package/dist/types/lib/subcomponent/Spinner/Spinner.d.ts +24 -0
- package/dist/types/lib/subcomponent/Spinner/Spinner.d.ts.map +1 -0
- package/dist/types/lib/subcomponent/Spinner/index.d.ts +3 -0
- package/dist/types/lib/subcomponent/Spinner/index.d.ts.map +1 -0
- package/dist/types/lib/subcomponent/Spinner/types.d.ts +17 -0
- package/dist/types/lib/subcomponent/Spinner/types.d.ts.map +1 -0
- package/dist/types/lib/subcomponent/index.d.ts +2 -0
- package/dist/types/lib/subcomponent/index.d.ts.map +1 -0
- package/dist/types/lib/types/index.d.ts +1 -0
- package/dist/types/lib/types/index.d.ts.map +1 -1
- package/dist/types/lib/types/link.d.ts +26 -0
- package/dist/types/lib/types/link.d.ts.map +1 -0
- package/package.json +16 -19
- package/dist/esm/lib/component/Card/common/Thumbnail/Thumbnail.js +0 -21
- package/dist/esm/lib/component/Card/common/Thumbnail/Thumbnail.js.map +0 -1
- package/dist/esm/lib/component/Card/common/Thumbnail/index.js +0 -2
- package/dist/esm/lib/component/Card/common/Thumbnail/index.js.map +0 -1
- package/dist/esm/lib/component/Card/common/Thumbnail/styles.css +0 -39
- package/dist/esm/lib/component/Card/common/Thumbnail/types.js.map +0 -1
- package/dist/esm/lib/hooks/usePopup/index.js +0 -3
- package/dist/esm/lib/hooks/usePopup/index.js.map +0 -1
- package/dist/esm/lib/hooks/usePopup/types.js.map +0 -1
- package/dist/esm/lib/hooks/usePopup/usePopup.js +0 -93
- package/dist/esm/lib/hooks/usePopup/usePopup.js.map +0 -1
- package/dist/esm/storybook/decorators.js +0 -16
- package/dist/esm/storybook/decorators.js.map +0 -1
- package/dist/types/lib/component/Card/common/Thumbnail/Thumbnail.d.ts +0 -23
- package/dist/types/lib/component/Card/common/Thumbnail/Thumbnail.d.ts.map +0 -1
- package/dist/types/lib/component/Card/common/Thumbnail/index.d.ts +0 -3
- package/dist/types/lib/component/Card/common/Thumbnail/index.d.ts.map +0 -1
- package/dist/types/lib/component/Card/common/Thumbnail/types.d.ts +0 -27
- package/dist/types/lib/component/Card/common/Thumbnail/types.d.ts.map +0 -1
- package/dist/types/lib/hooks/usePopup/index.d.ts +0 -3
- package/dist/types/lib/hooks/usePopup/index.d.ts.map +0 -1
- package/dist/types/lib/hooks/usePopup/types.d.ts +0 -65
- package/dist/types/lib/hooks/usePopup/types.d.ts.map +0 -1
- package/dist/types/lib/hooks/usePopup/usePopup.d.ts +0 -19
- package/dist/types/lib/hooks/usePopup/usePopup.d.ts.map +0 -1
- package/dist/types/storybook/decorators.d.ts +0 -15
- package/dist/types/storybook/decorators.d.ts.map +0 -1
- /package/dist/esm/lib/component/{Card/common/Thumbnail → ContextualMenu/common/Item}/types.js +0 -0
- /package/dist/esm/lib/{hooks/usePopup → component/ContextualMenu}/types.js +0 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { getItemId } from "@canonical/utils";
|
|
3
|
+
import { useMemo } from "react";
|
|
4
|
+
import { createPortal } from "react-dom";
|
|
5
|
+
import { MENU_PLACEMENT, useContextualMenu, useIsMounted, } from "../../hooks/index.js";
|
|
6
|
+
import MenuContext from "./common/MenuContext.js";
|
|
7
|
+
import SubMenu from "./common/SubMenu/index.js";
|
|
8
|
+
import "./styles.css";
|
|
9
|
+
const componentCssClassName = "ds contextual-menu";
|
|
10
|
+
/**
|
|
11
|
+
* A contextual menu presents a list of grouped actions anchored to a trigger.
|
|
12
|
+
* It opens on click, positions itself with viewport-fitment, and supports full
|
|
13
|
+
* keyboard navigation including arrow traversal across groups.
|
|
14
|
+
*
|
|
15
|
+
* `import { ContextualMenu } from "@canonical/react-ds-global";`
|
|
16
|
+
*
|
|
17
|
+
* @implements dso:global.component.contextual-menu
|
|
18
|
+
*/
|
|
19
|
+
const ContextualMenu = ({ trigger, groups, label, className, preferredDirections, distance, gutter, maxWidth, autoFit, wrap, onSelect, open, onOpenChange, ...props }) => {
|
|
20
|
+
// A synthetic root holds the groups so the tree is menu -> group -> item.
|
|
21
|
+
// MUST be stable across renders: the hook annotates it (memoised on `root`)
|
|
22
|
+
// and the open effect keys on the annotated root, so a fresh object each
|
|
23
|
+
// render re-fires that effect every render → dispatch → re-render → freeze.
|
|
24
|
+
const root = useMemo(() => ({ key: "contextual-menu-root", items: groups }), [groups]);
|
|
25
|
+
// Portal only after mount so the server and first client render agree —
|
|
26
|
+
// `typeof window` is already truthy on the first client render, which would
|
|
27
|
+
// portal the menu on render 0 and mismatch the inline server output.
|
|
28
|
+
const mounted = useIsMounted();
|
|
29
|
+
const menu = useContextualMenu({
|
|
30
|
+
root,
|
|
31
|
+
isOpen: open,
|
|
32
|
+
// Open toward the trigger's leading edge, top-aligned, flipping side/
|
|
33
|
+
// alignment as space runs out. MENU_PLACEMENT is logical (inline-*), so the
|
|
34
|
+
// hook mirrors it in RTL automatically — no direction read here.
|
|
35
|
+
preferredDirections: preferredDirections ?? MENU_PLACEMENT,
|
|
36
|
+
distance,
|
|
37
|
+
gutter,
|
|
38
|
+
maxWidth,
|
|
39
|
+
autoFit: autoFit ?? true,
|
|
40
|
+
wrap,
|
|
41
|
+
onShow: () => onOpenChange?.(true),
|
|
42
|
+
onHide: () => onOpenChange?.(false),
|
|
43
|
+
});
|
|
44
|
+
const { isOpen, close, targetRef, popupRef, popupPositionStyle, popupId, bestPosition, annotatedRoot, getNodeStatus, highlightItem, getTriggerProps, getMenuProps, getGroupProps, getItemProps, } = menu;
|
|
45
|
+
const triggerProps = getTriggerProps();
|
|
46
|
+
const annotatedGroups = annotatedRoot.items ?? [];
|
|
47
|
+
// The shared menu API threaded to every (nested) level. One state, one
|
|
48
|
+
// highlight path, one keyboard handler — submenus are render-only. Memoised so
|
|
49
|
+
// the context value is stable across renders; an unstable value would re-render
|
|
50
|
+
// every SubMenu (and re-run their positioning) on every commit.
|
|
51
|
+
const menuContextValue = useMemo(() => ({
|
|
52
|
+
getItemProps,
|
|
53
|
+
getMenuProps,
|
|
54
|
+
getGroupProps,
|
|
55
|
+
getNodeStatus,
|
|
56
|
+
highlightItem,
|
|
57
|
+
close,
|
|
58
|
+
onSelectItem: (item) => {
|
|
59
|
+
onSelect?.(item);
|
|
60
|
+
close();
|
|
61
|
+
},
|
|
62
|
+
}), [
|
|
63
|
+
getItemProps,
|
|
64
|
+
getMenuProps,
|
|
65
|
+
getGroupProps,
|
|
66
|
+
getNodeStatus,
|
|
67
|
+
highlightItem,
|
|
68
|
+
close,
|
|
69
|
+
onSelect,
|
|
70
|
+
]);
|
|
71
|
+
// With no explicit `label`, the menu is named by its trigger — so the trigger
|
|
72
|
+
// needs a stable id the menu can point `aria-labelledby` at (pointing at the
|
|
73
|
+
// menu's own id would leave it unnamed).
|
|
74
|
+
const triggerId = `${popupId}-trigger`;
|
|
75
|
+
// getMenuProps returns a generic prop bag from the headless navigation hook
|
|
76
|
+
// (loose event-handler and ref types); it is spread onto the menu container.
|
|
77
|
+
const menuProps = getMenuProps({
|
|
78
|
+
label,
|
|
79
|
+
labelledBy: label ? undefined : triggerId,
|
|
80
|
+
// Compose the positioning ref with the menu's keyboard ref.
|
|
81
|
+
ref: popupRef,
|
|
82
|
+
});
|
|
83
|
+
const menuElement = (_jsx("div", { className: [
|
|
84
|
+
`${componentCssClassName}__surface`,
|
|
85
|
+
"modal",
|
|
86
|
+
bestPosition?.positionName,
|
|
87
|
+
]
|
|
88
|
+
.filter(Boolean)
|
|
89
|
+
.join(" "), id: popupId, "aria-hidden": !isOpen, style: popupPositionStyle, ...menuProps, children: annotatedGroups.map((group) => (_jsx("div", { className: "group", ...getGroupProps({ label: group.label }), children: (group.items ?? []).map((item) => (
|
|
90
|
+
// SubMenu renders the item and, if it is a submenu parent, its
|
|
91
|
+
// nested popup (recursively). Leaves render as a plain item.
|
|
92
|
+
_jsx(SubMenu, { item: item }, getItemId(item)))) }, getItemId(group)))) }));
|
|
93
|
+
return (_jsx(MenuContext.Provider, { value: menuContextValue, children: _jsxs("div", { className: [componentCssClassName, className].filter(Boolean).join(" "), ...props, children: [_jsx("button", { type: "button", id: triggerId, className: "trigger", ref: targetRef, ...triggerProps, children: trigger }), mounted ? createPortal(menuElement, document.body) : menuElement] }) }));
|
|
94
|
+
};
|
|
95
|
+
export default ContextualMenu;
|
|
96
|
+
//# sourceMappingURL=ContextualMenu.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContextualMenu.js","sourceRoot":"","sources":["../../../../../src/lib/component/ContextualMenu/ContextualMenu.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,YAAY,GACb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,WAAW,MAAM,yBAAyB,CAAC;AAClD,OAAO,OAAO,MAAM,2BAA2B,CAAC;AAEhD,OAAO,cAAc,CAAC;AAEtB,MAAM,qBAAqB,GAAG,oBAAoB,CAAC;AAEnD;;;;;;;;GAQG;AACH,MAAM,cAAc,GAAG,CAAC,EACtB,OAAO,EACP,MAAM,EACN,KAAK,EACL,SAAS,EACT,mBAAmB,EACnB,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,OAAO,EACP,IAAI,EACJ,QAAQ,EACR,IAAI,EACJ,YAAY,EACZ,GAAG,KAAK,EACY,EAAsB,EAAE;IAC5C,0EAA0E;IAC1E,4EAA4E;IAC5E,yEAAyE;IACzE,4EAA4E;IAC5E,MAAM,IAAI,GAAG,OAAO,CAClB,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,sBAAsB,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,EACtD,CAAC,MAAM,CAAC,CACT,CAAC;IACF,wEAAwE;IACxE,4EAA4E;IAC5E,qEAAqE;IACrE,MAAM,OAAO,GAAG,YAAY,EAAE,CAAC;IAC/B,MAAM,IAAI,GAAG,iBAAiB,CAAC;QAC7B,IAAI;QACJ,MAAM,EAAE,IAAI;QACZ,sEAAsE;QACtE,4EAA4E;QAC5E,iEAAiE;QACjE,mBAAmB,EAAE,mBAAmB,IAAI,cAAc;QAC1D,QAAQ;QACR,MAAM;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{ jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Icon } from "../../../Icon/index.js";
|
|
3
|
+
import "./styles.css";
|
|
4
|
+
const componentCssClassName = "ds contextual-menu-item";
|
|
5
|
+
/**
|
|
6
|
+
* A single contextual-menu entry. By default it renders an optional leading
|
|
7
|
+
* icon, the label, and an optional right-aligned slot (badge or shortcut). When
|
|
8
|
+
* the item opts into a custom renderer (`displayItemsType: "custom"` with a
|
|
9
|
+
* `Component`), that component owns the item's content instead.
|
|
10
|
+
*
|
|
11
|
+
* @implements dso:global.subcomponent.contextual-menu-item
|
|
12
|
+
*/
|
|
13
|
+
const Item = ({ item, itemProps, onSelect }) => {
|
|
14
|
+
const { label, disabled, slot, icon, className, displayItemsType, Component, items, } = item;
|
|
15
|
+
// An item with children is a submenu trigger; it shows a trailing caret.
|
|
16
|
+
const hasSubmenu = !!items?.length;
|
|
17
|
+
const handleKeyDown = (event) => {
|
|
18
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
19
|
+
event.preventDefault();
|
|
20
|
+
if (!disabled)
|
|
21
|
+
onSelect();
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const content = displayItemsType === "custom" && Component ? (_jsx(Component, { item: item })) : (_jsxs(_Fragment, { children: [icon ? _jsx("span", { className: "icon", children: icon }) : null, _jsx("span", { className: "label", children: label }), slot ? _jsx("span", { className: "slot", children: slot }) : null, hasSubmenu ? (_jsx("span", { className: "caret", "aria-hidden": "true", children: _jsx(Icon, { icon: "chevron-right" }) })) : null] }));
|
|
25
|
+
return (
|
|
26
|
+
// biome-ignore lint/a11y/noStaticElementInteractions: the div carries role="menuitem" (from itemProps) with roving tabindex, the correct WAI-ARIA menu pattern (a <button> cannot be a menuitem)
|
|
27
|
+
_jsx("div", { className: [componentCssClassName, disabled && "disabled", className]
|
|
28
|
+
.filter(Boolean)
|
|
29
|
+
.join(" "), ...itemProps, onClick: disabled ? undefined : onSelect, onKeyDown: handleKeyDown, children: content }));
|
|
30
|
+
};
|
|
31
|
+
export default Item;
|
|
32
|
+
//# sourceMappingURL=Item.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Item.js","sourceRoot":"","sources":["../../../../../../../src/lib/component/ContextualMenu/common/Item/Item.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAE9C,OAAO,cAAc,CAAC;AAEtB,MAAM,qBAAqB,GAAG,yBAAyB,CAAC;AAExD;;;;;;;GAOG;AACH,MAAM,IAAI,GAAG,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAa,EAAsB,EAAE;IAC5E,MAAM,EACJ,KAAK,EACL,QAAQ,EACR,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,gBAAgB,EAChB,SAAS,EACT,KAAK,GACN,GAAG,IAAI,CAAC;IAET,yEAAyE;IACzE,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC;IAEnC,MAAM,aAAa,GAAG,CAAC,KAA0B,EAAE,EAAE;QACnD,IAAI,KAAK,CAAC,GAAG,KAAK,OAAO,IAAI,KAAK,CAAC,GAAG,KAAK,GAAG,EAAE,CAAC;YAC/C,KAAK,CAAC,cAAc,EAAE,CAAC;YACvB,IAAI,CAAC,QAAQ;gBAAE,QAAQ,EAAE,CAAC;QAC5B,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,OAAO,GACX,gBAAgB,KAAK,QAAQ,IAAI,SAAS,CAAC,CAAC,CAAC,CAC3C,KAAC,SAAS,IAAC,IAAI,EAAE,IAAI,GAAI,CAC1B,CAAC,CAAC,CAAC,CACF,8BAEG,IAAI,CAAC,CAAC,CAAC,eAAM,SAAS,EAAC,MAAM,YAAE,IAAI,GAAQ,CAAC,CAAC,CAAC,IAAI,EACnD,eAAM,SAAS,EAAC,OAAO,YAAE,KAAK,GAAQ,EACrC,IAAI,CAAC,CAAC,CAAC,eAAM,SAAS,EAAC,MAAM,YAAE,IAAI,GAAQ,CAAC,CAAC,CAAC,IAAI,EAIlD,UAAU,CAAC,CAAC,CAAC,CACZ,eAAM,SAAS,EAAC,OAAO,iBAAa,MAAM,YACxC,KAAC,IAAI,IAAC,IAAI,EAAC,eAAe,GAAG,GACxB,CACR,CAAC,CAAC,CAAC,IAAI,IACP,CACJ,CAAC;IAEJ,OAAO;IACL,iMAAiM;IACjM,cACE,SAAS,EAAE,CAAC,qBAAqB,EAAE,QAAQ,IAAI,UAAU,EAAE,SAAS,CAAC;aAClE,MAAM,CAAC,OAAO,CAAC;aACf,IAAI,CAAC,GAAG,CAAC,KACR,SAAS,EACb,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,EACxC,SAAS,EAAE,aAAa,YAEvB,OAAO,GACJ,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../src/lib/component/ContextualMenu/common/Item/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/* Component tokens — sourced from @canonical/design-tokens.
|
|
2
|
+
Mapped strictly to the Figma "Contextual menu item" frame:
|
|
3
|
+
px = dimension-200 (16px), py = dimension-050 (4px), gap = dimension-050 (4px)
|
|
4
|
+
between icon<->text and text<->caret, text = color-text (black),
|
|
5
|
+
fills = color-foreground-ghost/-active, line-height 24px.
|
|
6
|
+
No min-height — the item is padding + line-height. */
|
|
7
|
+
:root {
|
|
8
|
+
--contextual-menu-item-color-text: var(--color-text);
|
|
9
|
+
--contextual-menu-item-color-text-disabled: var(--color-text-disabled);
|
|
10
|
+
--contextual-menu-item-color-background: var(--color-foreground-ghost);
|
|
11
|
+
--contextual-menu-item-color-background-hover: var(
|
|
12
|
+
--color-foreground-ghost-hover
|
|
13
|
+
);
|
|
14
|
+
--contextual-menu-item-color-background-active: var(
|
|
15
|
+
--color-foreground-ghost-active
|
|
16
|
+
);
|
|
17
|
+
--contextual-menu-item-padding-block: var(--dimension-050);
|
|
18
|
+
--contextual-menu-item-padding-inline: var(--dimension-200);
|
|
19
|
+
/* 4px gap: icon<->text and text<->caret (per the spec). */
|
|
20
|
+
--contextual-menu-item-gap: var(--dimension-050);
|
|
21
|
+
/* De-emphasised slot text (badge / shortcut) — muted, matching
|
|
22
|
+
KeyboardKey / Tabs. */
|
|
23
|
+
--contextual-menu-item-slot-color: var(--color-text-muted);
|
|
24
|
+
/* Keyboard focus ring (Button precedent) — the semantic focus-ring colour,
|
|
25
|
+
with a currentColor backstop should the theme layer not be loaded. */
|
|
26
|
+
--contextual-menu-item-focus-ring-color: var(--color-focusRing, currentColor);
|
|
27
|
+
--contextual-menu-item-focus-ring-width: var(
|
|
28
|
+
--dimension-stroke-thickness-large
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.ds.contextual-menu-item {
|
|
33
|
+
display: flex;
|
|
34
|
+
/* Icon and first line of text are centre-aligned (Figma annotation). */
|
|
35
|
+
align-items: center;
|
|
36
|
+
gap: var(--contextual-menu-item-gap);
|
|
37
|
+
padding-block: var(--contextual-menu-item-padding-block);
|
|
38
|
+
padding-inline: var(--contextual-menu-item-padding-inline);
|
|
39
|
+
color: var(--contextual-menu-item-color-text);
|
|
40
|
+
background-color: var(--contextual-menu-item-color-background);
|
|
41
|
+
/* The --dimension-300 (24px) fallback is load-bearing: the typography var's
|
|
42
|
+
--number-line-height-* reference is unresolved in the built tokens. */
|
|
43
|
+
line-height: var(--typography-text-primary-line-height, var(--dimension-300));
|
|
44
|
+
cursor: pointer;
|
|
45
|
+
user-select: none;
|
|
46
|
+
|
|
47
|
+
&:hover {
|
|
48
|
+
background-color: var(--contextual-menu-item-color-background-hover);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* The highlighted (roving) item shows the active fill — matching the Figma
|
|
52
|
+
"Active" state. */
|
|
53
|
+
&:focus-visible,
|
|
54
|
+
&[tabindex="0"] {
|
|
55
|
+
background-color: var(--contextual-menu-item-color-background-active);
|
|
56
|
+
outline: none;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/* The active fill alone is ~1.2:1 against the resting item — below the 3:1
|
|
60
|
+
non-text minimum — so keyboard focus additionally draws a ring (WCAG
|
|
61
|
+
1.4.11 / 2.4.13). Inset (negative offset) so the popup surface's
|
|
62
|
+
`overflow-y: auto` never clips it; :focus-visible only, so pointer users
|
|
63
|
+
keep the quiet Figma look. Deliberately diverges from the Figma "Active"
|
|
64
|
+
state, which fails WCAG. */
|
|
65
|
+
&:focus-visible {
|
|
66
|
+
outline: var(--contextual-menu-item-focus-ring-width) solid
|
|
67
|
+
var(--contextual-menu-item-focus-ring-color);
|
|
68
|
+
outline-offset: calc(-1 * var(--contextual-menu-item-focus-ring-width));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
> .label {
|
|
72
|
+
flex: 1 1 auto;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/* The slot (badge / keyboard shortcut) sits right-aligned. */
|
|
76
|
+
> .slot {
|
|
77
|
+
flex: 0 0 auto;
|
|
78
|
+
margin-inline-start: auto;
|
|
79
|
+
color: var(--contextual-menu-item-slot-color);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/* The submenu caret sits on the trailing edge in a fixed icon box (Figma:
|
|
83
|
+
16px chevron in a 24px-tall wrapper). It always follows the reading
|
|
84
|
+
direction — chevron-right in LTR, mirrored to point left in RTL — rather
|
|
85
|
+
than flipping per-item with the side the submenu opens on, so sibling carets
|
|
86
|
+
stay consistent. */
|
|
87
|
+
> .caret {
|
|
88
|
+
flex: 0 0 auto;
|
|
89
|
+
margin-inline-start: auto;
|
|
90
|
+
display: inline-flex;
|
|
91
|
+
align-items: center;
|
|
92
|
+
justify-content: center;
|
|
93
|
+
inline-size: var(--dimension-200);
|
|
94
|
+
block-size: var(--dimension-300);
|
|
95
|
+
|
|
96
|
+
& > svg {
|
|
97
|
+
inline-size: var(--dimension-200, 16px);
|
|
98
|
+
block-size: var(--dimension-200, 16px);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
&.disabled {
|
|
103
|
+
color: var(--contextual-menu-item-color-text-disabled);
|
|
104
|
+
background-color: var(--contextual-menu-item-color-background);
|
|
105
|
+
cursor: not-allowed;
|
|
106
|
+
pointer-events: none;
|
|
107
|
+
|
|
108
|
+
/* The slot follows the disabled text colour instead of staying muted. */
|
|
109
|
+
> .slot {
|
|
110
|
+
color: inherit;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/* Mirror the `›` caret glyph to `‹` for right-to-left reading. Keyed on any
|
|
116
|
+
`[dir="rtl"]` ANCESTOR of the item — which, because the menu is portalled to
|
|
117
|
+
the body, must be `<html>` or `<body>` (a wrapper `<div dir>` is escaped by
|
|
118
|
+
the portal). Set `dir="rtl"` on `<html>` (or `<body>`) and it mirrors. */
|
|
119
|
+
[dir="rtl"] .ds.contextual-menu-item > .caret {
|
|
120
|
+
transform: scaleX(-1);
|
|
121
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../src/lib/component/ContextualMenu/common/Item/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
const MenuContext = createContext(null);
|
|
3
|
+
/** Read the shared menu API. Throws if used outside a ContextualMenu. */
|
|
4
|
+
export const useMenuContext = () => {
|
|
5
|
+
const value = useContext(MenuContext);
|
|
6
|
+
if (!value) {
|
|
7
|
+
throw new Error("useMenuContext must be used within a ContextualMenu.");
|
|
8
|
+
}
|
|
9
|
+
return value;
|
|
10
|
+
};
|
|
11
|
+
export default MenuContext;
|
|
12
|
+
//# sourceMappingURL=MenuContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MenuContext.js","sourceRoot":"","sources":["../../../../../../src/lib/component/ContextualMenu/common/MenuContext.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAyBlD,MAAM,WAAW,GAAG,aAAa,CAA0B,IAAI,CAAC,CAAC;AAEjE,yEAAyE;AACzE,MAAM,CAAC,MAAM,cAAc,GAAG,GAAqB,EAAE;IACnD,MAAM,KAAK,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;IACtC,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;IAC1E,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { getItemId } from "@canonical/utils";
|
|
3
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
4
|
+
import { createPortal } from "react-dom";
|
|
5
|
+
import { MENU_PLACEMENT, useIsMounted, useWindowFitment, } from "../../../../hooks/index.js";
|
|
6
|
+
import Item from "../Item/index.js";
|
|
7
|
+
import { useMenuContext } from "../MenuContext.js";
|
|
8
|
+
/**
|
|
9
|
+
* One node in a (possibly nested) contextual menu. A leaf renders a plain item;
|
|
10
|
+
* a submenu parent renders the item plus a positioned nested popup for its
|
|
11
|
+
* children (see {@link SubMenuParent}). The hook that positions the popup runs
|
|
12
|
+
* ONLY for submenu parents — leaves render a bare item — so a menu of leaves
|
|
13
|
+
* spins up no positioning machinery.
|
|
14
|
+
*/
|
|
15
|
+
const SubMenu = ({ item }) => {
|
|
16
|
+
const { getItemProps, onSelectItem } = useMenuContext();
|
|
17
|
+
if (item.items?.length) {
|
|
18
|
+
return _jsx(SubMenuParent, { item: item });
|
|
19
|
+
}
|
|
20
|
+
return (_jsx(Item, { item: item, itemProps: getItemProps(item), onSelect: () => onSelectItem(item) }));
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* A submenu parent: the item plus its nested `role="menu"` popup. All nodes
|
|
24
|
+
* share the ONE menu state from {@link useMenuContext}; this component only
|
|
25
|
+
* decides the submenu's visibility and position. The submenu is shown when the
|
|
26
|
+
* keyboard path descends through this parent
|
|
27
|
+
* (`getNodeStatus(item).inHighlightedBranch`) or the parent is hovered, and is
|
|
28
|
+
* positioned by its own {@link useWindowFitment} anchored to the parent item —
|
|
29
|
+
* opening to the reading-direction leading edge, top-aligned, flipping side and
|
|
30
|
+
* alignment as space runs out.
|
|
31
|
+
*/
|
|
32
|
+
const SubMenuParent = ({ item }) => {
|
|
33
|
+
const { getItemProps, getMenuProps, getNodeStatus, onSelectItem } = useMenuContext();
|
|
34
|
+
const children = item.items ?? [];
|
|
35
|
+
const status = getNodeStatus(item);
|
|
36
|
+
// The submenu is keyboard-open when the highlight is in a DESCENDANT of this
|
|
37
|
+
// parent — not when the parent itself is the highlighted item. `inHighlighted
|
|
38
|
+
// Branch` is true in both cases, so subtract `highlighted`: otherwise ArrowLeft
|
|
39
|
+
// (which moves the highlight back onto the parent) would leave the submenu open.
|
|
40
|
+
const keyboardOpen = status.inHighlightedBranch && !status.highlighted;
|
|
41
|
+
const [hovered, setHovered] = useState(false);
|
|
42
|
+
const open = keyboardOpen || hovered;
|
|
43
|
+
// Portal only after mount so the server and first client render agree —
|
|
44
|
+
// `typeof window` is already truthy on the first client render.
|
|
45
|
+
const mounted = useIsMounted();
|
|
46
|
+
// MENU_PLACEMENT is a stable module constant and logical, so the hook mirrors
|
|
47
|
+
// it in RTL from this item's own writing direction — no per-submenu dir read.
|
|
48
|
+
const { targetRef, popupRef, popupPositionStyle, bestPosition } = useWindowFitment({ preferredDirections: MENU_PLACEMENT, autoFit: true });
|
|
49
|
+
// A stable, instance-unique id for the submenu surface so the parent item
|
|
50
|
+
// can reference the popup it controls (item keys are only unique within one
|
|
51
|
+
// menu, so useId rather than the item id).
|
|
52
|
+
const submenuId = useId();
|
|
53
|
+
// The item carries both the roving props and the fitment target ref. The
|
|
54
|
+
// tree's getItemProps already returns a `ref` (it registers the node for
|
|
55
|
+
// roving focus); COMPOSE ours with it rather than replacing it, or the
|
|
56
|
+
// submenu parent loses its focus registration.
|
|
57
|
+
const baseItemProps = getItemProps(item);
|
|
58
|
+
const navRef = baseItemProps.ref;
|
|
59
|
+
const itemProps = {
|
|
60
|
+
...baseItemProps,
|
|
61
|
+
// The composed `aria-expanded` (from getMenuItemProps) tracks only the
|
|
62
|
+
// keyboard highlight branch: it reports false for a HOVER-opened submenu
|
|
63
|
+
// and true for a merely-highlighted parent whose popup is not even
|
|
64
|
+
// mounted. Override with the REAL open state (WCAG 4.1.2 name/role/value).
|
|
65
|
+
"aria-expanded": open,
|
|
66
|
+
// Point at the popup only while it exists — the surface is unmounted when
|
|
67
|
+
// closed, and a dangling IDREF is invalid ARIA.
|
|
68
|
+
"aria-controls": open ? submenuId : undefined,
|
|
69
|
+
ref: (node) => {
|
|
70
|
+
targetRef.current = node;
|
|
71
|
+
if (typeof navRef === "function")
|
|
72
|
+
navRef(node);
|
|
73
|
+
else if (navRef)
|
|
74
|
+
navRef.current = node;
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
// On keyboard open, move focus to the submenu's roving tab stop (the newly
|
|
78
|
+
// highlighted child the tree already set tabindex=0 on).
|
|
79
|
+
// @note Impure — moves DOM focus.
|
|
80
|
+
const surfaceRef = useRef(null);
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
if (!open || !keyboardOpen || typeof window === "undefined")
|
|
83
|
+
return;
|
|
84
|
+
const surface = surfaceRef.current;
|
|
85
|
+
if (!surface)
|
|
86
|
+
return;
|
|
87
|
+
const id = requestAnimationFrame(() => requestAnimationFrame(() => {
|
|
88
|
+
surface
|
|
89
|
+
.querySelector('[role="menuitem"][tabindex="0"]')
|
|
90
|
+
?.focus();
|
|
91
|
+
}));
|
|
92
|
+
return () => cancelAnimationFrame(id);
|
|
93
|
+
}, [open, keyboardOpen]);
|
|
94
|
+
const menuProps = getMenuProps({
|
|
95
|
+
label: item.label,
|
|
96
|
+
ref: popupRef,
|
|
97
|
+
});
|
|
98
|
+
// Render the popup ONLY while open. A closed submenu mounts no popup, so its
|
|
99
|
+
// `popupRef` stays null and `useWindowFitment` measures nothing — no
|
|
100
|
+
// ResizeObserver, no reposition, and crucially no measure→reposition→measure
|
|
101
|
+
// feedback across a tree of always-mounted hidden popups (which froze the UI).
|
|
102
|
+
const submenuSurface = open ? (_jsx("div", { className: [
|
|
103
|
+
"ds",
|
|
104
|
+
"contextual-menu__surface",
|
|
105
|
+
"submenu",
|
|
106
|
+
"modal",
|
|
107
|
+
bestPosition?.positionName,
|
|
108
|
+
]
|
|
109
|
+
.filter(Boolean)
|
|
110
|
+
.join(" "), id: submenuId, "aria-hidden": false, "data-positioned": bestPosition ? "true" : undefined, style: popupPositionStyle, ...menuProps,
|
|
111
|
+
// After the spread so this composing callback wins over menuProps.ref
|
|
112
|
+
// (later JSX props override earlier ones): it captures the surface for
|
|
113
|
+
// the keyboard-open focus effect AND forwards to the tree's ref.
|
|
114
|
+
ref: (el) => {
|
|
115
|
+
surfaceRef.current = el;
|
|
116
|
+
if (typeof menuProps.ref === "function")
|
|
117
|
+
menuProps.ref(el);
|
|
118
|
+
else if (menuProps.ref)
|
|
119
|
+
menuProps.ref.current = el;
|
|
120
|
+
}, children: children.map((child) => (
|
|
121
|
+
// Recurse: a submenu child may itself be a submenu parent.
|
|
122
|
+
_jsx(SubMenu, { item: child }, getItemId(child)))) })) : null;
|
|
123
|
+
return (_jsxs("div", { className: "submenu-anchor", onPointerEnter: () => setHovered(true), onPointerLeave: () => setHovered(false), children: [_jsx(Item, { item: item, itemProps: itemProps, onSelect: () => onSelectItem(item) }), submenuSurface && mounted
|
|
124
|
+
? createPortal(submenuSurface, document.body)
|
|
125
|
+
: null] }));
|
|
126
|
+
};
|
|
127
|
+
export default SubMenu;
|
|
128
|
+
//# sourceMappingURL=SubMenu.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SubMenu.js","sourceRoot":"","sources":["../../../../../../../src/lib/component/ContextualMenu/common/SubMenu/SubMenu.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EAAqB,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EACL,cAAc,EACd,YAAY,EACZ,gBAAgB,GACjB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,IAAI,MAAM,kBAAkB,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD;;;;;;GAMG;AACH,MAAM,OAAO,GAAG,CAAC,EAAE,IAAI,EAA6B,EAAgB,EAAE;IACpE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,GAAG,cAAc,EAAE,CAAC;IAExD,IAAI,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC;QACvB,OAAO,KAAC,aAAa,IAAC,IAAI,EAAE,IAAI,GAAI,CAAC;IACvC,CAAC;IAED,OAAO,CACL,KAAC,IAAI,IACH,IAAI,EAAE,IAAI,EACV,SAAS,EAAE,YAAY,CAAC,IAAI,CAAC,EAC7B,QAAQ,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,GAClC,CACH,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,aAAa,GAAG,CAAC,EAAE,IAAI,EAA6B,EAAgB,EAAE;IAC1E,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE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C,MAAM,CAAC,CAAC,CAAC,SAAS,EAClD,KAAK,EAAE,kBAAkB,KACrB,SAAS;QACb,sEAAsE;QACtE,uEAAuE;QACvE,iEAAiE;QACjE,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE;YACV,UAAU,CAAC,OAAO,GAAG,EAAE,CAAC;YACxB,IAAI,OAAO,SAAS,CAAC,GAAG,KAAK,UAAU;gBAAE,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;iBACtD,IAAI,SAAS,CAAC,GAAG;gBACnB,SAAS,CAAC,GAA2C,CAAC,OAAO,GAAG,EAAE,CAAC;QACxE,CAAC,YAEA,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC;QACvB,2DAA2D;QAC3D,KAAC,OAAO,IAAwB,IAAI,EAAE,KAAK,IAA7B,SAAS,CAAC,KAAK,CAAC,CAAiB,CAChD,CAAC,GACE,CACP,CAAC,CAAC,CAAC,IAAI,CAAC;IAET,OAAO,CACL,eACE,SAAS,EAAC,gBAAgB,EAC1B,cAAc,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EACtC,cAAc,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,aAEvC,KAAC,IAAI,IACH,IAAI,EAAE,IAAI,EACV,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,GAClC,EACD,cAAc,IAAI,OAAO;gBACxB,CAAC,CAAC,YAAY,CAAC,cAAc,EAAE,QAAQ,CAAC,IAAI,CAAC;gBAC7C,CAAC,CAAC,IAAI,IACJ,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../src/lib/component/ContextualMenu/common/SubMenu/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/lib/component/ContextualMenu/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/* Component tokens — sourced from @canonical/design-tokens.
|
|
2
|
+
Mapped strictly to the Figma "Contextual Menu" frame: white background
|
|
3
|
+
(color-background) on the modal surface, a drop shadow (no border), and a
|
|
4
|
+
muted 1px divider between groups. */
|
|
5
|
+
:root {
|
|
6
|
+
--contextual-menu-color-divider: var(--color-border-muted);
|
|
7
|
+
--contextual-menu-divider-width: var(--dimension-stroke-thickness-medium);
|
|
8
|
+
--contextual-menu-min-width: 12rem;
|
|
9
|
+
--contextual-menu-max-width: 20rem;
|
|
10
|
+
/* Three-layer drop shadow from the Figma effect. */
|
|
11
|
+
--contextual-menu-shadow:
|
|
12
|
+
0 1px 1px 0 rgba(0, 0, 0, 0.15), 0 2px 2px -1px rgba(0, 0, 0, 0.15),
|
|
13
|
+
0 0 3px 0 rgba(0, 0, 0, 0.2);
|
|
14
|
+
--contextual-menu-motion-duration: 0.12s;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.ds.contextual-menu {
|
|
18
|
+
display: inline-block;
|
|
19
|
+
|
|
20
|
+
> .trigger {
|
|
21
|
+
cursor: pointer;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.ds.contextual-menu__surface {
|
|
26
|
+
position: fixed;
|
|
27
|
+
z-index: var(--z-index-overlay, 100);
|
|
28
|
+
min-width: var(--contextual-menu-min-width);
|
|
29
|
+
max-width: var(--contextual-menu-max-width);
|
|
30
|
+
/* A menu (or submenu) taller than the viewport scrolls INSIDE itself instead
|
|
31
|
+
of overflowing off-screen — otherwise keyboard-navigating to an item below
|
|
32
|
+
the fold would move the highlight to an item that is not visible. The
|
|
33
|
+
highlighted item is scrolled into view on keyboard nav (see Item). */
|
|
34
|
+
max-block-size: calc(100dvh - 2 * var(--dimension-200, 16px));
|
|
35
|
+
overflow-y: auto;
|
|
36
|
+
overscroll-behavior: contain;
|
|
37
|
+
/* Read the surface channel directly on this element so the `.modal` surface
|
|
38
|
+
applied here resolves (a :root intermediate would see it unset). */
|
|
39
|
+
background-color: var(--surface-color-background, var(--color-background));
|
|
40
|
+
box-shadow: var(--contextual-menu-shadow);
|
|
41
|
+
|
|
42
|
+
/* CSS-only enter/exit animation. */
|
|
43
|
+
opacity: 0;
|
|
44
|
+
visibility: hidden;
|
|
45
|
+
transition:
|
|
46
|
+
opacity var(--contextual-menu-motion-duration) ease-in-out,
|
|
47
|
+
visibility var(--contextual-menu-motion-duration) allow-discrete;
|
|
48
|
+
|
|
49
|
+
&[aria-hidden="false"] {
|
|
50
|
+
opacity: 1;
|
|
51
|
+
visibility: visible;
|
|
52
|
+
|
|
53
|
+
@starting-style {
|
|
54
|
+
opacity: 0;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/* A submenu mounts on open but is positioned a frame later; keep it hidden
|
|
59
|
+
until `data-positioned` so it never paints at the fallback top:0/left:0. */
|
|
60
|
+
&.submenu[aria-hidden="false"]:not([data-positioned="true"]) {
|
|
61
|
+
opacity: 0;
|
|
62
|
+
visibility: hidden;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@media (prefers-reduced-motion: reduce) {
|
|
66
|
+
transition: none;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/* Every group reserves a 1px top border so group heights never shift when a
|
|
70
|
+
divider is / isn't drawn (no layout drift). It is transparent by default and
|
|
71
|
+
only coloured between groups, where the muted divider is wanted (Figma:
|
|
72
|
+
group border-top, color-border-muted, stroke-thickness-medium). */
|
|
73
|
+
.group {
|
|
74
|
+
border-block-start: var(--contextual-menu-divider-width, 1px) solid
|
|
75
|
+
transparent;
|
|
76
|
+
}
|
|
77
|
+
.group + .group {
|
|
78
|
+
border-block-start-color: var(--contextual-menu-color-divider);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/* The submenu-anchor wraps a submenu-parent item for hover detection; it must
|
|
82
|
+
not disturb the vertical item flow, so it lays out like the item it wraps. */
|
|
83
|
+
.submenu-anchor {
|
|
84
|
+
display: block;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/lib/component/ContextualMenu/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback } from "react";
|
|
3
|
+
import { OVERLAY_PLACEMENT, useDisclosure } from "../../hooks/index.js";
|
|
4
|
+
import "./styles.css";
|
|
5
|
+
// The popover content sits on the `contrasted` surface so it stands out from
|
|
6
|
+
// the page behind it (dark chip on a light UI, light on a dark UI).
|
|
7
|
+
const componentCssClassName = "ds popover";
|
|
8
|
+
const contentSurfaceClassName = "contrasted";
|
|
9
|
+
/**
|
|
10
|
+
* A popover reveals supplementary content anchored to a trigger. It renders as a
|
|
11
|
+
* native `<details>`/`<summary>` so the toggle works without JavaScript; once
|
|
12
|
+
* hydrated, positioning, outside-click and Escape dismissal are layered on via
|
|
13
|
+
* the disclosure hook.
|
|
14
|
+
*
|
|
15
|
+
* `import { Popover } from "@canonical/react-ds-global";`
|
|
16
|
+
*
|
|
17
|
+
* @implements dso:global.component.popover
|
|
18
|
+
*/
|
|
19
|
+
const Popover = ({ trigger, children, className, open, onOpenChange, preferredDirections, distance, gutter, maxWidth, autoFit, closeOnEscape, closeOnOutsideClick, ...props }) => {
|
|
20
|
+
const { isOpen, targetRef, popupRef, popupPositionStyle, popupId, bestPosition, getToggleProps, getContentProps, } = useDisclosure({
|
|
21
|
+
mode: "click",
|
|
22
|
+
isOpen: open,
|
|
23
|
+
// Auto-fit by default, opening toward the reading direction first.
|
|
24
|
+
// OVERLAY_PLACEMENT is logical (inline-*), so the hook mirrors it in RTL.
|
|
25
|
+
preferredDirections: preferredDirections ?? OVERLAY_PLACEMENT,
|
|
26
|
+
distance,
|
|
27
|
+
gutter,
|
|
28
|
+
maxWidth,
|
|
29
|
+
autoFit: autoFit ?? true,
|
|
30
|
+
closeOnEscape,
|
|
31
|
+
closeOnOutsideClick,
|
|
32
|
+
onShow: () => onOpenChange?.(true),
|
|
33
|
+
onHide: () => onOpenChange?.(false),
|
|
34
|
+
});
|
|
35
|
+
const toggleProps = getToggleProps();
|
|
36
|
+
const contentProps = getContentProps();
|
|
37
|
+
// Once hydrated, the disclosure hook owns the toggle: intercept the summary
|
|
38
|
+
// click so the native <details> toggle does not fight the hook, and drive the
|
|
39
|
+
// open state from the hook instead. Without JS, the native toggle is the
|
|
40
|
+
// baseline and this handler never runs.
|
|
41
|
+
const handleSummaryClick = useCallback((event) => {
|
|
42
|
+
event.preventDefault();
|
|
43
|
+
toggleProps.onClick?.(event);
|
|
44
|
+
}, [toggleProps]);
|
|
45
|
+
return (_jsxs("details", { className: [componentCssClassName, bestPosition?.positionName, className]
|
|
46
|
+
.filter(Boolean)
|
|
47
|
+
.join(" "), open: isOpen, ref: targetRef, ...props, children: [_jsx("summary", { className: "trigger", "aria-controls": toggleProps["aria-controls"], onClick: handleSummaryClick, onKeyDown: toggleProps.onKeyDown, children: trigger }), _jsx("div", { className: ["content", contentSurfaceClassName].join(" "), id: popupId, ref: popupRef, role: "dialog", "aria-hidden": !isOpen, "data-positioned": bestPosition ? "true" : undefined, style: popupPositionStyle, onPointerEnter: contentProps.onPointerEnter, children: children })] }));
|
|
48
|
+
};
|
|
49
|
+
export default Popover;
|
|
50
|
+
//# sourceMappingURL=Popover.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Popover.js","sourceRoot":"","sources":["../../../../../src/lib/component/Popover/Popover.tsx"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