From 0def48ede8d3366817b12562f018c6f03d5de9e0 Mon Sep 17 00:00:00 2001 From: Ben Schell Date: Mon, 4 Nov 2024 13:57:02 -0500 Subject: [PATCH 01/15] feat: buttonPopover and userProfilePopover components --- .../src/labs/ButtonPopover.tsx | 62 ++++ .../odyssey-react-mui/src/labs/Popover.tsx | 113 +++++++ .../src/labs/TopNav/UserProfile.tsx | 28 +- .../src/labs/TopNav/UserProfilePopover.tsx | 103 ++++++ .../src/labs/TopNav/index.ts | 1 + packages/odyssey-react-mui/src/labs/index.ts | 1 + .../ButtonPopover/ButtonPopover.stories.tsx | 307 ++++++++++++++++++ .../UserProfile/UserProfile.stories.tsx | 106 ++++++ .../UserProfilePopover.stories.tsx | 136 ++++++++ 9 files changed, 855 insertions(+), 2 deletions(-) create mode 100644 packages/odyssey-react-mui/src/labs/ButtonPopover.tsx create mode 100644 packages/odyssey-react-mui/src/labs/Popover.tsx create mode 100644 packages/odyssey-react-mui/src/labs/TopNav/UserProfilePopover.tsx create mode 100644 packages/odyssey-storybook/src/components/odyssey-labs/ButtonPopover/ButtonPopover.stories.tsx create mode 100644 packages/odyssey-storybook/src/components/odyssey-labs/UserProfile/UserProfile.stories.tsx create mode 100644 packages/odyssey-storybook/src/components/odyssey-labs/UserProfilePopover/UserProfilePopover.stories.tsx diff --git a/packages/odyssey-react-mui/src/labs/ButtonPopover.tsx b/packages/odyssey-react-mui/src/labs/ButtonPopover.tsx new file mode 100644 index 0000000000..a02af6733e --- /dev/null +++ b/packages/odyssey-react-mui/src/labs/ButtonPopover.tsx @@ -0,0 +1,62 @@ +/*! + * Copyright (c) 2022-present, Okta, Inc. and/or its affiliates. All rights reserved. + * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") + * + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and limitations under the License. + */ + +import { memo, MouseEventHandler, ReactNode, useCallback, useRef } from "react"; +import { Button, ButtonProps } from "../Button"; +import { NullElement } from "../NullElement"; +import { OpenHandle, Popover, PopoverProps } from "./Popover"; + +export const popoverAlignmentValues = ["left", "right"] as const; + +export type ButtonPopoverProps = { + /** + * The horizontal alignment of the popover. + */ + popoverAlignment?: PopoverProps["popoverAlignment"]; + /** + * The contents of the popover + */ + children: ReactNode | NullElement; +} & ButtonProps; + +const ButtonPopover = (props: ButtonPopoverProps) => { + const { children, popoverAlignment, ...buttonProps } = props; + + // Adding a tooltip to the button means the popover does not get placed in the right location + delete buttonProps.tooltipText; + + const popoverRef = useRef(null); + const openPopover = useCallback>( + (event) => { + popoverRef.current?.openWithElement(event.currentTarget); + }, + [], + ); + + return ( + <> +