Skip to content

Commit

Permalink
chore(ui): migrate ContextMenu component to Typescript (#596)
Browse files Browse the repository at this point in the history
* chore(ui): convert contextmenu to Typescript

* chore(ui): convert story to ts

* chore(ui): fix test

* chore(ui): eslint ignore and update imports

* chore(ui): update knownicons type and improve casting

* chore(ui): improve story types
  • Loading branch information
guoda-puidokaite authored Nov 11, 2024
1 parent c9108c0 commit b1a5eb1
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 205 deletions.
5 changes: 5 additions & 0 deletions .changeset/neat-peaches-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cloudoperators/juno-ui-components": minor
---

Migrate the ContextMenu component to TypeScript
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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<ContextMenuProps> = ({
/*icon,*/
/*className,*/
children = null,
open = false,
/*...props*/
}) => {
const [isOpen, setIsOpen] = useState(false)
const [isOpen, setIsOpen] = useState<boolean>(false)

const handleClick = (_event) => {
// eslint-disable-next-line no-unused-vars
const handleClick = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
setIsOpen(!isOpen)
}

Expand All @@ -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`,
Expand All @@ -84,10 +91,10 @@ export const ContextMenu = ({
<Menu.Button
onClick={handleClick}
className={`
juno-contextmenu-toggle
${toggleStyles}
${isOpen ? toggleOpenStyle : ""}
`}
juno-contextmenu-toggle
${toggleStyles}
${isOpen ? toggleOpenStyle : ""}
`}
>
<Icon icon="moreVert" />
</Menu.Button>
Expand All @@ -96,10 +103,3 @@ export const ContextMenu = ({
</Menu>
)
}

ContextMenu.propTypes = {
className: PropTypes.string,
children: PropTypes.node,
icon: PropTypes.any,
open: PropTypes.bool,
}

This file was deleted.

Loading

0 comments on commit b1a5eb1

Please sign in to comment.