From 9bdcdc76a88a5981848315be6000cd3a778c2efb Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Fri, 16 Aug 2024 09:40:05 +0300 Subject: [PATCH] docs: redesign help button (#8610) Redesign help button Closes DOCS-817 --- www/apps/book/providers/index.tsx | 3 +- www/apps/resources/providers/index.tsx | 3 +- .../components/HelpButton/Actions/index.tsx | 52 ----------- .../src/components/HelpButton/index.tsx | 86 ------------------- .../src/components/Icons/Github/index.tsx | 22 +++++ .../components/MainNav/HelpButton/index.tsx | 76 ++++++++++++++++ .../docs-ui/src/components/MainNav/index.tsx | 2 + .../src/components/Menu/Action/index.tsx | 4 +- .../src/components/Menu/Item/index.tsx | 4 +- www/packages/docs-ui/src/components/index.ts | 1 - www/packages/docs-ui/src/constants.tsx | 8 +- 11 files changed, 109 insertions(+), 152 deletions(-) delete mode 100644 www/packages/docs-ui/src/components/HelpButton/Actions/index.tsx delete mode 100644 www/packages/docs-ui/src/components/HelpButton/index.tsx create mode 100644 www/packages/docs-ui/src/components/Icons/Github/index.tsx create mode 100644 www/packages/docs-ui/src/components/MainNav/HelpButton/index.tsx diff --git a/www/apps/book/providers/index.tsx b/www/apps/book/providers/index.tsx index 8853af0657..42f375cfc3 100644 --- a/www/apps/book/providers/index.tsx +++ b/www/apps/book/providers/index.tsx @@ -3,7 +3,6 @@ import { AnalyticsProvider, ColorModeProvider, - helpButtonNotification, HooksLoader, LearningPathProvider, MobileProvider, @@ -30,7 +29,7 @@ const Providers = ({ children }: ProvidersProps) => { - + diff --git a/www/apps/resources/providers/index.tsx b/www/apps/resources/providers/index.tsx index b7c29a53d3..58fbeefcc4 100644 --- a/www/apps/resources/providers/index.tsx +++ b/www/apps/resources/providers/index.tsx @@ -3,7 +3,6 @@ import { AnalyticsProvider, ColorModeProvider, - helpButtonNotification, HooksLoader, LearningPathProvider, MobileProvider, @@ -32,7 +31,7 @@ const Providers = ({ children }: ProvidersProps) => { - + diff --git a/www/packages/docs-ui/src/components/HelpButton/Actions/index.tsx b/www/packages/docs-ui/src/components/HelpButton/Actions/index.tsx deleted file mode 100644 index a5e8b2e7cd..0000000000 --- a/www/packages/docs-ui/src/components/HelpButton/Actions/index.tsx +++ /dev/null @@ -1,52 +0,0 @@ -"use client" - -import { Bug, Discord, Github } from "@medusajs/icons" -import clsx from "clsx" -import Link from "next/link" -import React from "react" - -export const HelpButtonActions = () => { - const actions = [ - { - title: "Troubleshooting Guides", - url: "https://docs.medusajs.com/v2/resources/troubleshooting", - icon: , - }, - { - title: "Create a GitHub Issue", - url: "https://github.com/medusajs/medusa/issues/new/choose", - icon: , - }, - { - title: "Get Support on Discord", - url: "https://discord.gg/medusajs", - icon: , - }, - ] - return ( -
- {actions.map((action, index) => ( - - {action.icon} - {action.title} - - ))} -
- ) -} diff --git a/www/packages/docs-ui/src/components/HelpButton/index.tsx b/www/packages/docs-ui/src/components/HelpButton/index.tsx deleted file mode 100644 index a2216e6570..0000000000 --- a/www/packages/docs-ui/src/components/HelpButton/index.tsx +++ /dev/null @@ -1,86 +0,0 @@ -"use client" - -import React, { useEffect, useRef, useState } from "react" -import { Button } from "@/components" -import clsx from "clsx" -import { CSSTransition } from "react-transition-group" -import { HelpButtonActions } from "./Actions" -import { useClickOutside } from "../.." - -export const HelpButton = () => { - const [showText, setShowText] = useState(false) - const [showHelp, setShowHelp] = useState(false) - const ref = useRef(null) - useClickOutside({ - elmRef: ref, - onClickOutside: () => { - setShowHelp(false) - setShowText(false) - }, - }) - - useEffect(() => { - if (showHelp) { - setShowText(true) - } - }, [showHelp]) - - return ( -
- {showHelp && } - -
- ) -} diff --git a/www/packages/docs-ui/src/components/Icons/Github/index.tsx b/www/packages/docs-ui/src/components/Icons/Github/index.tsx new file mode 100644 index 0000000000..d49472ad32 --- /dev/null +++ b/www/packages/docs-ui/src/components/Icons/Github/index.tsx @@ -0,0 +1,22 @@ +import React from "react" +import { IconProps } from "@medusajs/icons/dist/types" + +export const GithubIcon = (props: IconProps) => { + return ( + + + + ) +} diff --git a/www/packages/docs-ui/src/components/MainNav/HelpButton/index.tsx b/www/packages/docs-ui/src/components/MainNav/HelpButton/index.tsx new file mode 100644 index 0000000000..289fcfd045 --- /dev/null +++ b/www/packages/docs-ui/src/components/MainNav/HelpButton/index.tsx @@ -0,0 +1,76 @@ +"use client" + +import React, { useRef, useState } from "react" +import { Button, Kbd, Tooltip } from "@/components" +import { Bug, Discord, QuestionMark } from "@medusajs/icons" +import { Menu, useClickOutside } from "../../.." +import { MenuItem } from "types" +import clsx from "clsx" +import { GithubIcon } from "../../Icons/Github" + +export const MainNavHelpButton = () => { + const [showMenu, setShowMenu] = useState(false) + const ref = useRef(null) + useClickOutside({ + elmRef: ref, + onClickOutside: () => { + setShowMenu(false) + }, + }) + + const menuItems: MenuItem[] = [ + { + type: "link", + title: "Create a GitHub Issue", + link: "https://github.com/medusajs/medusa/issues/new/choose", + icon: , + }, + { + type: "link", + title: "Get Support on Discord", + link: "https://discord.gg/medusajs", + icon: , + }, + { + type: "divider", + }, + { + type: "link", + title: "Troubleshooting Guides", + link: "https://docs.medusajs.com/v2/resources/troubleshooting", + icon: , + }, + ] + + return ( +
+ + Need help? + ? + + } + place="bottom" + hidden={showMenu} + > + + +
+ +
+
+ ) +} diff --git a/www/packages/docs-ui/src/components/MainNav/index.tsx b/www/packages/docs-ui/src/components/MainNav/index.tsx index eaff03740c..a880cac2cc 100644 --- a/www/packages/docs-ui/src/components/MainNav/index.tsx +++ b/www/packages/docs-ui/src/components/MainNav/index.tsx @@ -9,6 +9,7 @@ import { MainNavColorMode } from "./ColorMode" import Link from "next/link" import { MainNavDivider } from "./Divider" import { MainNavSidebarOpener } from "./SidebarOpener" +import { MainNavHelpButton } from "./HelpButton" import { SidebarLeftIcon } from "../Icons/SidebarLeft" export const MainNav = () => { @@ -39,6 +40,7 @@ export const MainNav = () => { Report Issue + diff --git a/www/packages/docs-ui/src/components/Menu/Action/index.tsx b/www/packages/docs-ui/src/components/Menu/Action/index.tsx index c24e6c4d84..dd678299b8 100644 --- a/www/packages/docs-ui/src/components/Menu/Action/index.tsx +++ b/www/packages/docs-ui/src/components/Menu/Action/index.tsx @@ -20,7 +20,9 @@ export const MenuAction = ({ item }: MenuActionProps) => { tabIndex={-1} onClick={item.action} > - {item.icon} + + {item.icon} + {item.title} {item.shortcut && ( diff --git a/www/packages/docs-ui/src/components/Menu/Item/index.tsx b/www/packages/docs-ui/src/components/Menu/Item/index.tsx index fd11c770f5..b5a343a956 100644 --- a/www/packages/docs-ui/src/components/Menu/Item/index.tsx +++ b/www/packages/docs-ui/src/components/Menu/Item/index.tsx @@ -20,7 +20,9 @@ export const MenuItem = ({ item }: MenuItemProps) => { )} href={item.link} > - {item.icon} + + {item.icon} + {item.title} ) diff --git a/www/packages/docs-ui/src/components/index.ts b/www/packages/docs-ui/src/components/index.ts index 2dfcdc759c..f117d941da 100644 --- a/www/packages/docs-ui/src/components/index.ts +++ b/www/packages/docs-ui/src/components/index.ts @@ -22,7 +22,6 @@ export * from "./ExpandableNotice" export * from "./FeatureFlagNotice" export * from "./Feedback" export * from "./Feedback/Solutions" -export * from "./HelpButton" export * from "./HooksLoader" export * from "./Icons" export * from "./InlineIcon" diff --git a/www/packages/docs-ui/src/constants.tsx b/www/packages/docs-ui/src/constants.tsx index 234d71c35c..f5646f46e2 100644 --- a/www/packages/docs-ui/src/constants.tsx +++ b/www/packages/docs-ui/src/constants.tsx @@ -1,8 +1,7 @@ import React from "react" -import { Badge, HelpButton } from "@/components" +import { Badge } from "@/components" import { OptionType } from "@/hooks" import { NavigationDropdownItem, SidebarItem } from "types" -import { NotificationItemType } from "@/providers" import { NavigationDropdownDocIcon } from "./components/Icons/NavigationDropdown/Doc" import { NavigationDropdownStoreIcon } from "./components/Icons/NavigationDropdown/Store" import { NavigationDropdownAdminIcon } from "./components/Icons/NavigationDropdown/Admin" @@ -233,8 +232,3 @@ export const searchFiltersV1: OptionType[] = [ label: "UI", }, ] - -export const helpButtonNotification: NotificationItemType = { - layout: "empty", - children: , -}