Skip to content

Commit 4950dec

Browse files
authored
fix: adjust command palette width, border and remove box-shadow (#4081)
* feat: add loader for initial loading of operation editor fix: adjust command palette `width`, `border` and remove `box-shadow` feat: add short cut `Cmd/Ctrl + ,` for opening GraphiQL settings dialog * feat: add loader for initial loading of operation editor fix: adjust command palette `width`, `border` and remove `box-shadow` feat: add short cut `Cmd/Ctrl + ,` for opening GraphiQL settings dialog * prettier
1 parent 2634924 commit 4950dec

File tree

5 files changed

+56
-10
lines changed

5 files changed

+56
-10
lines changed

.changeset/shaggy-panthers-grin.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@graphiql/react': patch
3+
'graphiql': minor
4+
---
5+
6+
feat: add loader for initial loading of operation editor
7+
fix: adjust command palette `width`, `border` and remove `box-shadow`
8+
feat: add short cut `Cmd/Ctrl + ,` for opening GraphiQL settings dialog

packages/graphiql-react/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,19 @@ React hooks.
9696
The `useGraphiQLActions` hook **exposes all actions** across store slices.
9797
The `useGraphiQL` hook **provides access to the following store slices**:
9898

99-
| Store Slice | Responsibilities |
100-
| ----------- | --------------------------------------------------------------------------------------------------------- |
101-
| `storage` | Provides a storage API that can be used to persist state in the browser (by default using `localStorage`) |
102-
| `editor` | Manages **query**, **variables**, **headers**, and **response** editors and tabs |
103-
| `execution` | Handles the execution of GraphQL requests |
104-
| `plugin` | Manages plugins and the currently active plugin |
105-
| `schema` | Fetches, validates, and stores the GraphQL schema |
106-
| `theme` | Manages the current theme and provides a method to update it |
99+
| Store Slice | Responsibilities |
100+
| ---------------------------------------- | --------------------------------------------------------------------------------------------------------- |
101+
| [`storage`](./src/stores/storage.ts) | Provides a storage API that can be used to persist state in the browser (by default using `localStorage`) |
102+
| [`editor`](./src/stores/editor.ts) | Manages **query**, **variables**, **headers**, and **response** editors and tabs |
103+
| [`execution`](./src/stores/execution.ts) | Handles the execution of GraphQL requests |
104+
| [`plugin`](./src/stores/plugin.ts) | Manages plugins and the currently active plugin |
105+
| [`schema`](./src/stores/schema.ts) | Fetches, validates, and stores the GraphQL schema |
106+
| [`theme`](./src/stores/theme.ts) | Manages the current theme and provides a method to update it |
107107

108108
### Usage Example
109109

110110
```js
111-
import { useGraphiQL, useGraphiQLActions, useTheme } from '@graphiql/react';
111+
import { useGraphiQL, useGraphiQLActions } from '@graphiql/react';
112112

113113
// Get an action to fetch the schema and an action to change theme
114114
const { introspect, setTheme } = useGraphiQLActions();

packages/graphiql-react/src/style/editor.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,22 @@
1919
.highlight {
2020
color: hsl(var(--color-primary)) !important;
2121
}
22+
2223
input:focus-visible {
2324
outline-color: hsl(var(--color-primary));
2425
}
26+
27+
/* Command pallet F1 styles */
28+
.overflow-guard {
29+
overflow: unset !important;
30+
}
31+
32+
.quick-input-widget {
33+
min-width: min(500px, 70vw) !important;
34+
box-shadow: none !important;
35+
/* Make quick input widget border same as editor hover widget */
36+
--vscode-widget-border: var(--vscode-editorHoverWidget-border);
37+
}
2538
}
2639

2740
/* Make hover contents be dynamic */

packages/graphiql/src/GraphiQL.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
EditorProps,
3333
cn,
3434
useGraphiQLActions,
35+
useMonaco,
3536
} from '@graphiql/react';
3637
import { HistoryStore, HISTORY_PLUGIN } from '@graphiql/plugin-history';
3738
import {
@@ -221,6 +222,7 @@ export const GraphiQLInterface: FC<GraphiQLInterfaceProps> = ({
221222
'visiblePlugin',
222223
),
223224
);
225+
const hasMonaco = useMonaco(state => Boolean(state.monaco));
224226

225227
const PluginContent = visiblePlugin?.content;
226228

@@ -353,7 +355,15 @@ export const GraphiQLInterface: FC<GraphiQLInterfaceProps> = ({
353355
aria-label="Operation Editor"
354356
ref={editorToolsResize.firstRef}
355357
>
356-
<QueryEditor onClickReference={onClickReference} onEdit={onEditQuery} />
358+
{hasMonaco ? (
359+
<QueryEditor
360+
onClickReference={onClickReference}
361+
onEdit={onEditQuery}
362+
/>
363+
) : (
364+
<Spinner />
365+
)}
366+
357367
<div
358368
className="graphiql-toolbar"
359369
role="toolbar"

packages/graphiql/src/ui/sidebar.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
ButtonGroup,
55
cn,
66
Dialog,
7+
isMacOs,
78
KEY_MAP,
89
KeyboardShortcutIcon,
910
pick,
@@ -87,6 +88,20 @@ export const Sidebar: FC<SidebarProps> = ({
8788
'success' | 'error' | undefined
8889
>();
8990

91+
useEffect(() => {
92+
function openSettings(event: KeyboardEvent) {
93+
if ((isMacOs ? event.metaKey : event.ctrlKey) && event.key === ',') {
94+
event.preventDefault(); // prevent default browser settings dialog
95+
setShowDialog(prev => (prev === 'settings' ? null : 'settings'));
96+
}
97+
}
98+
99+
window.addEventListener('keydown', openSettings);
100+
return () => {
101+
window.removeEventListener('keydown', openSettings);
102+
};
103+
}, []);
104+
90105
function handleOpenShortKeysDialog(isOpen: boolean) {
91106
if (!isOpen) {
92107
setShowDialog(null);

0 commit comments

Comments
 (0)