From 15b640a3f297a6a4d6e187751d7cbcd0d75eefa3 Mon Sep 17 00:00:00 2001 From: filantrop Date: Mon, 15 Aug 2022 15:18:18 +0300 Subject: [PATCH] DropDownMenu without Storybook --- src/components/drop-down-menu/ContextMenu.tsx | 116 ++++++++++++++++++ .../drop-down-menu/ContextMenuAction.tsx | 36 ++++++ .../drop-down-menu/ContextMenuItem.tsx | 27 ++++ src/components/drop-down-menu/MenuIcons.tsx | 101 +++++++++++++++ 4 files changed, 280 insertions(+) create mode 100644 src/components/drop-down-menu/ContextMenu.tsx create mode 100644 src/components/drop-down-menu/ContextMenuAction.tsx create mode 100644 src/components/drop-down-menu/ContextMenuItem.tsx create mode 100644 src/components/drop-down-menu/MenuIcons.tsx diff --git a/src/components/drop-down-menu/ContextMenu.tsx b/src/components/drop-down-menu/ContextMenu.tsx new file mode 100644 index 0000000..16b7c0c --- /dev/null +++ b/src/components/drop-down-menu/ContextMenu.tsx @@ -0,0 +1,116 @@ +/* -------------------------------------------------------------------------- */ +/* Imports */ +/* -------------------------------------------------------------------------- */ +import React, { Fragment } from "react"; +import { Menu, Transition } from "@headlessui/react"; +import { PropsPartion } from "./ContextMenuItem"; +import classNames from "classnames"; +import { ReactComponent as SelectIcon } from "assets/svg/select-arrow.svg"; +type ChildType = React.ReactElement; +type ChildrenType = ChildType[] | ChildType; + +/* -------------------------------------------------------------------------- */ +/* Component props */ +/* -------------------------------------------------------------------------- */ + +type MenuProps = { + emphasis?: "high" | "low"; + disabled?: boolean; + className?: string | undefined; + button: React.ReactNode; + children: ChildrenType; +}; +/* -------------------------------------------------------------------------- */ +/* Styles */ +/* -------------------------------------------------------------------------- */ + +const MenuButtonStyle = ` +inline-flex +justify-center w-full +cursor-default +rounded +border border-gray-100 +outline-8 +bg-white +py-2 +pl-4 +pr-1 +text-base`; + +const MenuItemStyle = ` +absolute +left-0 +mt-2 w-60 +origin-top-left +rounded +bg-white +shadow-lg +focus:outline-none +py-2 px-4 sm:text-sm`; + +/* -------------------------------------------------------------------------- */ +/* Component implementation */ +/* -------------------------------------------------------------------------- */ +/** +* Use width ContextMenuAction.tsx , for example: +* +* alert('click')} +* > +* ... +* +*/ +export default function ContextMenu({ + button, + children, + className, + emphasis = "low", +}: MenuProps) { + return ( + + {({ open }) => ( + <> + + {button} + + + + + {children} + + + + )} + + ); +} diff --git a/src/components/drop-down-menu/ContextMenuAction.tsx b/src/components/drop-down-menu/ContextMenuAction.tsx new file mode 100644 index 0000000..2023fb1 --- /dev/null +++ b/src/components/drop-down-menu/ContextMenuAction.tsx @@ -0,0 +1,36 @@ +import classNames from "classnames"; +import React from "react"; + + +type Props = { + action: Function; + caption: string; + disabled?: boolean; + icon?: React.ReactNode; + className?: string | undefined; +}; + +export default function ContextMenuAction({ + action, + caption, + disabled, + icon, + className, +}: Props) { + return ( + + + ); +} + diff --git a/src/components/drop-down-menu/ContextMenuItem.tsx b/src/components/drop-down-menu/ContextMenuItem.tsx new file mode 100644 index 0000000..eb444b6 --- /dev/null +++ b/src/components/drop-down-menu/ContextMenuItem.tsx @@ -0,0 +1,27 @@ +import {Menu} from '@headlessui/react'; +import React from 'react'; + +export type PropsPartion = { + disabled?: boolean | undefined; + active?: boolean | undefined; +}; + +type Props = { + children: React.ReactElement< + any & PropsPartion + >; +} & PropsPartion; + +/** + * Context menu item component + * @return {JSX.Element} + */ +export default function ContextMenuItem({children, ...props}: Props) { + return ( + + {(params) => { + return React.cloneElement(children, params); + }} + + ); +} diff --git a/src/components/drop-down-menu/MenuIcons.tsx b/src/components/drop-down-menu/MenuIcons.tsx new file mode 100644 index 0000000..5a1c794 --- /dev/null +++ b/src/components/drop-down-menu/MenuIcons.tsx @@ -0,0 +1,101 @@ +import React from "react"; + + +/* -------------------------------------------------------------------------- */ +/* Icons for header menu as our disign */ +/* -------------------------------------------------------------------------- */ + + +export const Publications = ( + + + + + +); + +export const MyFavorite = ( + + + +); +export const MyCollection = ( + + + + + +); + +export const RecentViewed = ( + + + + +);