fix: renamed folder MainMenu->main-menu and support rest props (#6103)

* renamed folder MainMenu -> main-menu

* rename ariaLabel -> aria-label and dataTestId -> data-testid

* allow rest props

* fix

* lint

* add ts check

* ts for div

* fix

* fix

* fix
This commit is contained in:
Aakansha Doshi 2023-01-12 20:40:09 +05:30 committed by GitHub
parent 599a8f3c6f
commit 9d04479f98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 43 additions and 73 deletions

View File

@ -50,7 +50,7 @@ import WelcomeScreen from "./welcome-screen/WelcomeScreen";
import { hostSidebarCountersAtom } from "./Sidebar/Sidebar"; import { hostSidebarCountersAtom } from "./Sidebar/Sidebar";
import { jotaiScope } from "../jotai"; import { jotaiScope } from "../jotai";
import { useAtom } from "jotai"; import { useAtom } from "jotai";
import MainMenu from "./mainMenu/MainMenu"; import MainMenu from "./main-menu/MainMenu";
interface LayerUIProps { interface LayerUIProps {
actionManager: ActionManager; actionManager: ActionManager;

View File

@ -193,7 +193,7 @@ export const LibraryMenuHeader: React.FC<{
<DropdownMenu.Item <DropdownMenu.Item
onSelect={onLibraryImport} onSelect={onLibraryImport}
icon={LoadIcon} icon={LoadIcon}
dataTestId="lib-dropdown--load" data-testid="lib-dropdown--load"
> >
{t("buttons.load")} {t("buttons.load")}
</DropdownMenu.Item> </DropdownMenu.Item>
@ -202,7 +202,7 @@ export const LibraryMenuHeader: React.FC<{
<DropdownMenu.Item <DropdownMenu.Item
onSelect={onLibraryExport} onSelect={onLibraryExport}
icon={ExportIcon} icon={ExportIcon}
dataTestId="lib-dropdown--export" data-testid="lib-dropdown--export"
> >
{t("buttons.export")} {t("buttons.export")}
</DropdownMenu.Item> </DropdownMenu.Item>
@ -219,7 +219,7 @@ export const LibraryMenuHeader: React.FC<{
<DropdownMenu.Item <DropdownMenu.Item
icon={publishIcon} icon={publishIcon}
onSelect={() => setShowPublishLibraryDialog(true)} onSelect={() => setShowPublishLibraryDialog(true)}
dataTestId="lib-dropdown--remove" data-testid="lib-dropdown--remove"
> >
{t("buttons.publishLibrary")} {t("buttons.publishLibrary")}
</DropdownMenu.Item> </DropdownMenu.Item>

View File

@ -9,30 +9,23 @@ const DropdownMenuItem = ({
icon, icon,
onSelect, onSelect,
children, children,
dataTestId,
shortcut, shortcut,
className, className,
style, ...rest
ariaLabel,
}: { }: {
icon?: JSX.Element; icon?: JSX.Element;
onSelect: () => void; onSelect: () => void;
children: React.ReactNode; children: React.ReactNode;
dataTestId?: string;
shortcut?: string; shortcut?: string;
className?: string; className?: string;
style?: React.CSSProperties; } & React.ButtonHTMLAttributes<HTMLButtonElement>) => {
ariaLabel?: string;
}) => {
return ( return (
<button <button
aria-label={ariaLabel} {...rest}
onClick={onSelect} onClick={onSelect}
data-testid={dataTestId}
title={ariaLabel}
type="button" type="button"
className={getDrodownMenuItemClassName(className)} className={getDrodownMenuItemClassName(className)}
style={style} title={rest.title ?? rest["aria-label"]}
> >
<MenuItemContent icon={icon} shortcut={shortcut}> <MenuItemContent icon={icon} shortcut={shortcut}>
{children} {children}

View File

@ -1,19 +1,17 @@
import React from "react";
const DropdownMenuItemCustom = ({ const DropdownMenuItemCustom = ({
children, children,
className = "", className = "",
style, ...rest
dataTestId,
}: { }: {
children: React.ReactNode; children: React.ReactNode;
className?: string; className?: string;
style?: React.CSSProperties; } & React.HTMLAttributes<HTMLDivElement>) => {
dataTestId?: string;
}) => {
return ( return (
<div <div
{...rest}
className={`dropdown-menu-item-base dropdown-menu-item-custom ${className}`.trim()} className={`dropdown-menu-item-base dropdown-menu-item-custom ${className}`.trim()}
style={style}
data-testid={dataTestId}
> >
{children} {children}
</div> </div>

View File

@ -3,33 +3,26 @@ import React from "react";
import { getDrodownMenuItemClassName } from "./DropdownMenuItem"; import { getDrodownMenuItemClassName } from "./DropdownMenuItem";
const DropdownMenuItemLink = ({ const DropdownMenuItemLink = ({
icon, icon,
dataTestId,
shortcut, shortcut,
href, href,
children, children,
className = "", className = "",
style, ...rest
ariaLabel,
}: { }: {
icon?: JSX.Element; icon?: JSX.Element;
children: React.ReactNode; children: React.ReactNode;
dataTestId?: string;
shortcut?: string; shortcut?: string;
className?: string; className?: string;
href: string; href: string;
style?: React.CSSProperties; } & React.AnchorHTMLAttributes<HTMLAnchorElement>) => {
ariaLabel?: string;
}) => {
return ( return (
<a <a
{...rest}
href={href} href={href}
target="_blank" target="_blank"
rel="noreferrer" rel="noreferrer"
className={getDrodownMenuItemClassName(className)} className={getDrodownMenuItemClassName(className)}
style={style} title={rest.title ?? rest["aria-label"]}
data-testid={dataTestId}
title={ariaLabel}
aria-label={ariaLabel}
> >
<MenuItemContent icon={icon} shortcut={shortcut}> <MenuItemContent icon={icon} shortcut={shortcut}>
{children} {children}

View File

@ -46,9 +46,9 @@ export const LoadScene = () => {
<DropdownMenuItem <DropdownMenuItem
icon={LoadIcon} icon={LoadIcon}
onSelect={() => actionManager.executeAction(actionLoadScene)} onSelect={() => actionManager.executeAction(actionLoadScene)}
dataTestId="load-button" data-testid="load-button"
shortcut={getShortcutFromShortcutName("loadScene")} shortcut={getShortcutFromShortcutName("loadScene")}
ariaLabel={t("buttons.load")} aria-label={t("buttons.load")}
> >
{t("buttons.load")} {t("buttons.load")}
</DropdownMenuItem> </DropdownMenuItem>
@ -69,10 +69,10 @@ export const SaveToActiveFile = () => {
return ( return (
<DropdownMenuItem <DropdownMenuItem
shortcut={getShortcutFromShortcutName("saveScene")} shortcut={getShortcutFromShortcutName("saveScene")}
dataTestId="save-button" data-testid="save-button"
onSelect={() => actionManager.executeAction(actionSaveToActiveFile)} onSelect={() => actionManager.executeAction(actionSaveToActiveFile)}
icon={save} icon={save}
ariaLabel={`${t("buttons.save")}`} aria-label={`${t("buttons.save")}`}
>{`${t("buttons.save")}`}</DropdownMenuItem> >{`${t("buttons.save")}`}</DropdownMenuItem>
); );
}; };
@ -86,10 +86,10 @@ export const SaveAsImage = () => {
return ( return (
<DropdownMenuItem <DropdownMenuItem
icon={ExportImageIcon} icon={ExportImageIcon}
dataTestId="image-export-button" data-testid="image-export-button"
onSelect={() => setAppState({ openDialog: "imageExport" })} onSelect={() => setAppState({ openDialog: "imageExport" })}
shortcut={getShortcutFromShortcutName("imageExport")} shortcut={getShortcutFromShortcutName("imageExport")}
ariaLabel={t("buttons.exportImage")} aria-label={t("buttons.exportImage")}
> >
{t("buttons.exportImage")} {t("buttons.exportImage")}
</DropdownMenuItem> </DropdownMenuItem>
@ -106,11 +106,11 @@ export const Help = () => {
return ( return (
<DropdownMenuItem <DropdownMenuItem
dataTestId="help-menu-item" data-testid="help-menu-item"
icon={HelpIcon} icon={HelpIcon}
onSelect={() => actionManager.executeAction(actionShortcuts)} onSelect={() => actionManager.executeAction(actionShortcuts)}
shortcut="?" shortcut="?"
ariaLabel={t("helpDialog.title")} aria-label={t("helpDialog.title")}
> >
{t("helpDialog.title")} {t("helpDialog.title")}
</DropdownMenuItem> </DropdownMenuItem>
@ -136,8 +136,8 @@ export const ClearCanvas = () => {
<DropdownMenuItem <DropdownMenuItem
icon={TrashIcon} icon={TrashIcon}
onSelect={toggleDialog} onSelect={toggleDialog}
dataTestId="clear-canvas-button" data-testid="clear-canvas-button"
ariaLabel={t("buttons.clearReset")} aria-label={t("buttons.clearReset")}
> >
{t("buttons.clearReset")} {t("buttons.clearReset")}
</DropdownMenuItem> </DropdownMenuItem>
@ -175,9 +175,9 @@ export const ToggleTheme = () => {
return actionManager.executeAction(actionToggleTheme); return actionManager.executeAction(actionToggleTheme);
}} }}
icon={appState.theme === "dark" ? SunIcon : MoonIcon} icon={appState.theme === "dark" ? SunIcon : MoonIcon}
dataTestId="toggle-dark-mode" data-testid="toggle-dark-mode"
shortcut={getShortcutFromShortcutName("toggleTheme")} shortcut={getShortcutFromShortcutName("toggleTheme")}
ariaLabel={ aria-label={
appState.theme === "dark" appState.theme === "dark"
? t("buttons.lightMode") ? t("buttons.lightMode")
: t("buttons.darkMode") : t("buttons.darkMode")
@ -222,8 +222,8 @@ export const Export = () => {
onSelect={() => { onSelect={() => {
setAppState({ openDialog: "jsonExport" }); setAppState({ openDialog: "jsonExport" });
}} }}
dataTestId="json-export-button" data-testid="json-export-button"
ariaLabel={t("buttons.export")} aria-label={t("buttons.export")}
> >
{t("buttons.export")} {t("buttons.export")}
</DropdownMenuItem> </DropdownMenuItem>
@ -236,21 +236,21 @@ export const Socials = () => (
<DropdownMenuItemLink <DropdownMenuItemLink
icon={GithubIcon} icon={GithubIcon}
href="https://github.com/excalidraw/excalidraw" href="https://github.com/excalidraw/excalidraw"
ariaLabel="GitHub" aria-label="GitHub"
> >
GitHub GitHub
</DropdownMenuItemLink> </DropdownMenuItemLink>
<DropdownMenuItemLink <DropdownMenuItemLink
icon={DiscordIcon} icon={DiscordIcon}
href="https://discord.gg/UexuTaE" href="https://discord.gg/UexuTaE"
ariaLabel="Discord" aria-label="Discord"
> >
Discord Discord
</DropdownMenuItemLink> </DropdownMenuItemLink>
<DropdownMenuItemLink <DropdownMenuItemLink
icon={TwitterIcon} icon={TwitterIcon}
href="https://twitter.com/excalidraw" href="https://twitter.com/excalidraw"
ariaLabel="Twitter" aria-label="Twitter"
> >
Twitter Twitter
</DropdownMenuItemLink> </DropdownMenuItemLink>
@ -270,7 +270,7 @@ export const LiveCollaboration = ({
const appState = useExcalidrawAppState(); const appState = useExcalidrawAppState();
return ( return (
<DropdownMenuItem <DropdownMenuItem
dataTestId="collab-button" data-testid="collab-button"
icon={UsersIcon} icon={UsersIcon}
className={clsx({ className={clsx({
"active-collab": isCollaborating, "active-collab": isCollaborating,

View File

@ -479,14 +479,10 @@ Use this component to render a menu item.
| Prop | Type | Required | Default | Description | | Prop | Type | Required | Default | Description |
| --- | --- | --- | --- | --- | | --- | --- | --- | --- | --- |
| `onSelect` | `Function` | Yes | | The handler is triggered when the item is selected. | | `onSelect` | `Function` | Yes | `undefined` | The handler is triggered when the item is selected. |
| `children` | `React.ReactNode` | Yes | | The content of the menu item | | `children` | `React.ReactNode` | Yes | `undefined` | The content of the menu item |
| `icon` | `JSX.Element` | No | | The icon used in the menu item | | `icon` | `JSX.Element` | No | `undefined` | The icon used in the menu item |
| `shortcut` | `string` | No | | The keyboard shortcut (label-only, does not affect behavior) | | `shortcut` | `string` | No | | The keyboard shortcut (label-only, does not affect behavior) |
| `className` | `string` | No | | The class names to be added to the menu item |
| `style` | `React.CSSProperties` | No | | The inline styles to be added to the menu item |
| `ariaLabel` | `string` | | No | The `aria-label` to be added to the item for accessibility |
| `dataTestId` | `string` | | No | The `data-testid` to be added to the item. |
**MainMenu.ItemLink** **MainMenu.ItemLink**
@ -510,14 +506,10 @@ const App = () => (
| Prop | Type | Required | Default | Description | | Prop | Type | Required | Default | Description |
| --- | --- | --- | --- | --- | | --- | --- | --- | --- | --- |
| `href` | `string` | Yes | | The `href` attribute to be added to the `anchor` element. | | `href` | `string` | Yes | `undefined` | The `href` attribute to be added to the `anchor` element. |
| `children` | `React.ReactNode` | Yes | | The content of the menu item | | `children` | `React.ReactNode` | Yes | `undefined` | The content of the menu item |
| `icon` | `JSX.Element` | No | | The icon used in the menu item | | `icon` | `JSX.Element` | No | `undefined` | The icon used in the menu item |
| `shortcut` | `string` | No | | The keyboard shortcut (label-only, does not affect behavior) | | `shortcut` | `string` | No | | The keyboard shortcut (label-only, does not affect behavior) |
| `className` | `string` | No | "" | The class names to be added to the menu item |
| `style` | `React.CSSProperties` | No | | The inline styles to be added to the menu item |
| `ariaLabel` | `string` | No | | The `aria-label` to be added to the item for accessibility |
| `dataTestId` | `string` | No | | The `data-testid` to be added to the item. |
**MainMenu.ItemCustom** **MainMenu.ItemCustom**
@ -547,9 +539,6 @@ const App = () => (
| Prop | Type | Required | Default | Description | | Prop | Type | Required | Default | Description |
| --- | --- | --- | --- | --- | | --- | --- | --- | --- | --- |
| `children` | `React.ReactNode` | Yes | `undefined` | The content of the menu item | | `children` | `React.ReactNode` | Yes | `undefined` | The content of the menu item |
| `className` | `string` | No | "" | The class names to be added to the menu item |
| `style` | `React.CSSProperties` | No | `undefined` | The inline styles to be added to the menu item |
| `dataTestId` | `string` | No | `undefined` | The `data-testid` to be added to the item. |
**MainMenu.DefaultItems** **MainMenu.DefaultItems**
@ -595,10 +584,7 @@ const App = () => (
| Prop | Type | Required | Default | Description | | Prop | Type | Required | Default | Description |
| --- | --- | --- | --- | --- | | --- | --- | --- | --- | --- |
| `children ` | `React.ReactNode` | Yes | `undefined` | The content of the `MenuItem Group` | | `children ` | `React.ReactNode` | Yes | `undefined` | The content of the `MainMenu.Group` |
| `title` | `string` | No | `undefined` | The `title` for the grouped items |
| `className` | `string` | No | "" | The `classname` to be added to the group |
| `style` | `React.CSsSProperties` | No | `undefined` | The inline `styles` to be added to the group |
### WelcomeScreen ### WelcomeScreen

View File

@ -12,7 +12,7 @@ import { DEFAULT_UI_OPTIONS } from "../../constants";
import { Provider } from "jotai"; import { Provider } from "jotai";
import { jotaiScope, jotaiStore } from "../../jotai"; import { jotaiScope, jotaiStore } from "../../jotai";
import Footer from "../../components/footer/FooterCenter"; import Footer from "../../components/footer/FooterCenter";
import MainMenu from "../../components/mainMenu/MainMenu"; import MainMenu from "../../components/main-menu/MainMenu";
import WelcomeScreen from "../../components/welcome-screen/WelcomeScreen"; import WelcomeScreen from "../../components/welcome-screen/WelcomeScreen";
const ExcalidrawBase = (props: ExcalidrawProps) => { const ExcalidrawBase = (props: ExcalidrawProps) => {