diff --git a/.changeset/five-pillows-fail.md b/.changeset/five-pillows-fail.md index cc268cd2f79..d7f6afeef25 100644 --- a/.changeset/five-pillows-fail.md +++ b/.changeset/five-pillows-fail.md @@ -3,7 +3,7 @@ --- Add new components: -- UI components (`Button`, `ButtonGroup`, `Dialog`, `Dropdown`, `Spinner`, `Tab`, `Tabs`, `UnStyledButton` and lots of icon components) +- UI components (`Button`, `ButtonGroup`, `Dialog`, `Menu`, `Spinner`, `Tab`, `Tabs`, `UnStyledButton` and lots of icon components) - Editor components (`QueryEditor`, `VariableEditor`, `HeaderEditor` and `ResponseEditor`) - Toolbar components (`ExecuteButton` and `ToolbarButton`) - Docs components (`Argument`, `DefaultValue`, `DeprecationReason`, `Directive`, `DocExplorer`, `ExplorerSection`, `FieldDocumentation`, `FieldLink`, `SchemaDocumentation`, `Search`, `TypeDocumentation` and `TypeLink`) diff --git a/packages/graphiql-react/package.json b/packages/graphiql-react/package.json index a43f7677da5..a9f77a3efc8 100644 --- a/packages/graphiql-react/package.json +++ b/packages/graphiql-react/package.json @@ -40,6 +40,7 @@ "@graphiql/toolkit": "^1.0.0-next.1", "@reach/combobox": "^0.17.0", "@reach/dialog": "^0.17.0", + "@reach/menu-button": "^0.17.0", "@reach/visually-hidden": "^0.17.0", "codemirror": "^5.65.3", "codemirror-graphql": "^2.0.0-next.1", diff --git a/packages/graphiql-react/src/toolbar/execute.tsx b/packages/graphiql-react/src/toolbar/execute.tsx index 56023651996..5d34d282e36 100644 --- a/packages/graphiql-react/src/toolbar/execute.tsx +++ b/packages/graphiql-react/src/toolbar/execute.tsx @@ -1,10 +1,7 @@ -import { OperationDefinitionNode } from 'graphql'; -import { useState } from 'react'; - import { useEditorContext } from '../editor'; import { useExecutionContext } from '../execution'; import { PlayIcon, StopIcon } from '../icons'; -import { Dropdown } from '../ui'; +import { Menu } from '../ui'; import './execute.css'; @@ -17,101 +14,56 @@ export function ExecuteButton() { nonNull: true, caller: ExecuteButton, }); - const [optionsOpen, setOptionsOpen] = useState(false); - const [highlight, setHighlight] = useState( - null, - ); const operations = queryEditor?.operations || []; const hasOptions = operations.length > 1 && typeof operationName !== 'string'; - return ( -
- - {hasOptions && optionsOpen ? ( - - {operations.map((operation, i) => { - const opName = operation.name - ? operation.name.value - : ``; - return ( - setHighlight(operation)} - onMouseOut={() => setHighlight(null)} - onMouseUp={() => { - setOptionsOpen(false); - const selectedOperationName = operation.name?.value; - if ( - queryEditor && - selectedOperationName && - selectedOperationName !== queryEditor.operationName - ) { - setOperationName(selectedOperationName); - } - run(); - }} - > - {opName} - - ); - })} - - ) : null} -
+ }} + /> ); } diff --git a/packages/graphiql-react/src/ui/dropdown.css b/packages/graphiql-react/src/ui/dropdown.css deleted file mode 100644 index 400bb09bd79..00000000000 --- a/packages/graphiql-react/src/ui/dropdown.css +++ /dev/null @@ -1,30 +0,0 @@ -.graphiql-dropdown { - background-color: var(--color-neutral-0); - box-shadow: var(--box-shadow); - border-radius: var(--border-radius-8); - margin: 0; - max-width: 250px; - min-width: 100px; - padding: 0; - position: absolute; - z-index: 1; -} - -.graphiql-dropdown-item { - border-radius: var(--border-radius-4); - cursor: pointer; - margin: var(--px-4); - overflow: hidden; - padding: var(--px-6) var(--px-8); - text-overflow: ellipsis; - white-space: nowrap; -} - -.graphiql-dropdown-item:active, -.graphiql-dropdown-item:hover { - background-color: var(--color-neutral-7); -} - -.graphiql-dropdown-item:not(:first-child) { - margin-top: 0; -} diff --git a/packages/graphiql-react/src/ui/dropdown.tsx b/packages/graphiql-react/src/ui/dropdown.tsx deleted file mode 100644 index 043eb7a5d26..00000000000 --- a/packages/graphiql-react/src/ui/dropdown.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import './dropdown.css'; - -export function Dropdown(props: JSX.IntrinsicElements['ul']) { - return ( -