diff --git a/.changeset/neat-peaches-roll.md b/.changeset/neat-peaches-roll.md new file mode 100644 index 000000000..75e943af8 --- /dev/null +++ b/.changeset/neat-peaches-roll.md @@ -0,0 +1,5 @@ +--- +"@cloudoperators/juno-ui-components": minor +--- + +Migrate the ContextMenu component to TypeScript diff --git a/packages/ui-components/src/components/ContextMenu/ContextMenu.component.js b/packages/ui-components/src/components/ContextMenu/ContextMenu.component.tsx similarity index 70% rename from packages/ui-components/src/components/ContextMenu/ContextMenu.component.js rename to packages/ui-components/src/components/ContextMenu/ContextMenu.component.tsx index 1f649b536..e625f6ac5 100644 --- a/packages/ui-components/src/components/ContextMenu/ContextMenu.component.js +++ b/packages/ui-components/src/components/ContextMenu/ContextMenu.component.tsx @@ -4,11 +4,11 @@ */ import React, { useState, useEffect } from "react" -import PropTypes from "prop-types" -import { Icon } from "../../deprecated_js/Icon/index.js" import { Menu } from "@headlessui/react" import { Float } from "@headlessui-float/react" -import { autoPlacement, offset, shift, size } from "@floating-ui/react-dom" +import { autoPlacement, offset, shift, size, Boundary } from "@floating-ui/react-dom" + +import { Icon, KnownIcons } from "../Icon/Icon.component" /* TODO: @@ -32,26 +32,33 @@ const menuStyles = ` ` const toggleStyles = ` - hover:jn-text-theme-accent - active:jn-text-theme-accent + hover:jn-text-theme-accent + active:jn-text-theme-accent ` const toggleOpenStyle = ` - jn-text-theme-accent + jn-text-theme-accent ` -/** A context menu with a toggle. */ +export interface ContextMenuProps { + className?: string + children?: React.ReactNode + icon?: KnownIcons + open?: boolean +} -export const ContextMenu = ({ +/** A context menu with a toggle. */ +export const ContextMenu: React.FC = ({ /*icon,*/ /*className,*/ children = null, open = false, /*...props*/ }) => { - const [isOpen, setIsOpen] = useState(false) + const [isOpen, setIsOpen] = useState(false) - const handleClick = (_event) => { + // eslint-disable-next-line no-unused-vars + const handleClick = (event: React.MouseEvent) => { setIsOpen(!isOpen) } @@ -66,7 +73,7 @@ export const ContextMenu = ({ allowedPlacements: ["top-start", "top-end", "bottom-start", "bottom-end"], }), size({ - boundary: "viewport", + boundary: "viewport" as Boundary, apply({ availableWidth, availableHeight, elements }) { Object.assign(elements.floating.style, { maxWidth: `${availableWidth}px`, @@ -84,10 +91,10 @@ export const ContextMenu = ({ @@ -96,10 +103,3 @@ export const ContextMenu = ({ ) } - -ContextMenu.propTypes = { - className: PropTypes.string, - children: PropTypes.node, - icon: PropTypes.any, - open: PropTypes.bool, -} diff --git a/packages/ui-components/src/components/ContextMenu/ContextMenu.stories.js b/packages/ui-components/src/components/ContextMenu/ContextMenu.stories.js deleted file mode 100644 index e8b5d7913..000000000 --- a/packages/ui-components/src/components/ContextMenu/ContextMenu.stories.js +++ /dev/null @@ -1,175 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Juno contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -import React from "react" -import PropTypes from "prop-types" -import { ContextMenu } from "./index.js" -import { MenuItem } from "../MenuItem/MenuItem.component" -import { Button } from "../../deprecated_js/Button/index" -import { PortalProvider } from "../../deprecated_js/PortalProvider/PortalProvider.component" - -export default { - title: "WiP/ContextMenu/ContextMenu", - component: ContextMenu, - argTypes: { - children: { - control: false, - }, - }, - decorators: [ - (Story) => ( -
- - - -
- ), - ], -} - -const Template = ({ children, ...args }) => {children} - -Template.propTypes = { - children: PropTypes.node, -} - -const PortalTemplate = ({ children, ...args }) => ( - - - {children} - - -) - -PortalTemplate.propTypes = { - children: PropTypes.node, -} - -const CustomPortalTemplate = ({ parentStyles, children, ...args }) => ( -
- {children} -
-) - -CustomPortalTemplate.propTypes = { - parentStyles: PropTypes.object, - children: PropTypes.node, -} - -export const Default = { - render: Template, - - args: { - children: [ - , - , - , - -