diff --git a/packages/react-components/src/components/ProductSwitcher/ProductSwitcher.module.scss b/packages/react-components/src/components/ProductSwitcher/ProductSwitcher.module.scss index f3d487f2a..0714afaaf 100644 --- a/packages/react-components/src/components/ProductSwitcher/ProductSwitcher.module.scss +++ b/packages/react-components/src/components/ProductSwitcher/ProductSwitcher.module.scss @@ -1,7 +1,12 @@ +@import '../../utils/StackingContextLevel'; $base-class: 'product-switcher'; .#{$base-class} { gap: 16px; + z-index: $stacking-context-level-popover; + border-radius: var(--radius-3); + box-shadow: var(--shadow-pop-over); + background-color: var(--popover-background); padding: var(--spacing-3); width: 270px; diff --git a/packages/react-components/src/components/ProductSwitcher/ProductSwitcher.tsx b/packages/react-components/src/components/ProductSwitcher/ProductSwitcher.tsx index 66592b4fd..454c15171 100644 --- a/packages/react-components/src/components/ProductSwitcher/ProductSwitcher.tsx +++ b/packages/react-components/src/components/ProductSwitcher/ProductSwitcher.tsx @@ -1,10 +1,22 @@ import { FC, MouseEvent } from 'react'; import * as React from 'react'; +import { + FloatingNode, + FloatingTree, + offset, + useClick, + useDismiss, + useFloating, + useFloatingNodeId, + useFloatingParentNodeId, + useInteractions, + useRole, + useTransitionStyles, +} from '@floating-ui/react'; import { TextLogoFull } from '@livechat/design-system-icons'; import { Icon } from '../Icon'; -import { Popover } from '../Popover'; import { Tooltip } from '../Tooltip'; import { Text } from '../Typography'; @@ -20,6 +32,32 @@ export const ProductSwitcher: FC = ({ productOptions, mainProductId, }) => { + const [isOpen, setIsOpen] = React.useState(false); + const parentId = useFloatingParentNodeId(); + const nodeId = useFloatingNodeId(); + + const { refs, context, floatingStyles } = useFloating({ + nodeId, + strategy: 'fixed', + placement: 'right-start', + open: isOpen, + onOpenChange: setIsOpen, + middleware: [offset({ mainAxis: 10 })], + }); + + const click = useClick(context); + const role = useRole(context); + const dismiss = useDismiss(context); + const { isMounted, styles: transitionStyles } = useTransitionStyles(context, { + initial: { opacity: 0, transform: 'translateX(-80%)' }, + }); + + const { getReferenceProps, getFloatingProps } = useInteractions([ + click, + dismiss, + role, + ]); + const mainProduct = productOptions.find( (product) => product.id === mainProductId ); @@ -37,13 +75,11 @@ export const ProductSwitcher: FC = ({ 0 ); - return ( - +
= ({ > Switch product - } - > - <> -
- {productOptions.map((product) => ( - - ))} -
-
- - powered by - - +
+ +
+ {isMounted && ( +
+
+ {productOptions.map((product) => ( + + ))} +
+ +
+ )}
- - +
+ ); + + if (parentId === null) { + return {ProductSwitcherComponent}; + } + + return ProductSwitcherComponent; };