From f0925e2524e57b0e96b03f4af530355ad67fa40b Mon Sep 17 00:00:00 2001 From: Thomas Heyenbrock Date: Tue, 2 Aug 2022 09:49:13 +0200 Subject: [PATCH] add a dialog that shows all available shortkeys (#2601) * add a dialog that shows all available shortkeys * use table in short key dialog * add shortkey for introspection * add link to codemirror keymaps --- .changeset/green-mayflies-notice.md | 5 + packages/graphiql-react/src/style/root.css | 40 ++++-- packages/graphiql/src/components/GraphiQL.tsx | 132 ++++++++++++++++-- packages/graphiql/src/style.css | 16 +++ 4 files changed, 167 insertions(+), 26 deletions(-) create mode 100644 .changeset/green-mayflies-notice.md diff --git a/.changeset/green-mayflies-notice.md b/.changeset/green-mayflies-notice.md new file mode 100644 index 00000000000..36a12e6399a --- /dev/null +++ b/.changeset/green-mayflies-notice.md @@ -0,0 +1,5 @@ +--- +'graphiql': major +--- + +BREAKING: The `GraphiQL` component does no longer set a property `g` on the `window` object. diff --git a/packages/graphiql-react/src/style/root.css b/packages/graphiql-react/src/style/root.css index 06f26543c3b..676d0bd5c9d 100644 --- a/packages/graphiql-react/src/style/root.css +++ b/packages/graphiql-react/src/style/root.css @@ -111,21 +111,31 @@ body.graphiql-dark reach-portal { .graphiql-container, .CodeMirror-info, .CodeMirror-lint-tooltip, -reach-portal, -.graphiql-container:is(button) { - color: var(--color-neutral-100); - font-family: var(--font-family); - font-size: var(--font-size-body); - font-weight: var(----font-weight-regular); - line-height: var(--line-height); -} +reach-portal { + &, + &:is(button) { + color: var(--color-neutral-100); + font-family: var(--font-family); + font-size: var(--font-size-body); + font-weight: var(----font-weight-regular); + line-height: var(--line-height); + } -.graphiql-container input { - color: var(--color-neutral-100); - font-family: var(--font-family); - font-size: var(--font-size-caption); -} + & input { + color: var(--color-neutral-100); + font-family: var(--font-family); + font-size: var(--font-size-caption); -.graphiql-container input::placeholder { - color: var(--color-neutral-60); + &::placeholder { + color: var(--color-neutral-60); + } + } + + & a { + color: var(--color-pink); + + &:visited { + color: var(--color-pink-dark); + } + } } diff --git a/packages/graphiql/src/components/GraphiQL.tsx b/packages/graphiql/src/components/GraphiQL.tsx index f681146e4ef..7115f172756 100644 --- a/packages/graphiql/src/components/GraphiQL.tsx +++ b/packages/graphiql/src/components/GraphiQL.tsx @@ -96,10 +96,6 @@ if (majorVersion < 16) { ); } -declare namespace window { - export let g: GraphiQL; -} - export type GraphiQLToolbarConfig = { additionalContent?: React.ReactNode; }; @@ -318,12 +314,6 @@ export class GraphiQL extends React.Component { super(props); } - componentDidMount() { - if (typeof window !== 'undefined') { - window.g = this; - } - } - render() { return ( Cmd + ) : ( + Ctrl + ); + return (
@@ -786,7 +785,11 @@ class GraphiQLWithContext extends React.Component< } /> - + { + this.setState({ showShortKeys: true }); + }} + >
+ { + this.setState({ showShortKeys: false }); + }} + > +
+
Short Keys
+ { + this.setState({ showShortKeys: false }); + }} + /> +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Short keyFunction
+ {modifier} + {' + '} + F + Search in editor
+ {modifier} + {' + '} + K + Search in documentation
+ {modifier} + {' + '} + Enter + Execute query
+ Ctrl + {' + '} + Shift + {' + '} + P + Prettify editors
+ Ctrl + {' + '} + Shift + {' + '} + M + + Merge fragments definitions into operation definition +
+ Ctrl + {' + '} + Shift + {' + '} + C + Copy query
+ Ctrl + {' + '} + Shift + {' + '} + R + Re-fetch schema using introspection
+

+ The editors use{' '} + + CodeMirror Key Maps + {' '} + that add more short keys. This instance of GraphiQL + uses {this.props.keyMap || 'sublime'}. +

+
+
+
{ diff --git a/packages/graphiql/src/style.css b/packages/graphiql/src/style.css index ca343d9d817..37c5d9042ed 100644 --- a/packages/graphiql/src/style.css +++ b/packages/graphiql/src/style.css @@ -269,3 +269,19 @@ reach-portal .graphiql-dialog-section-title { reach-portal .graphiql-dialog-section-caption { color: var(--color-neutral-60); } + +reach-portal .graphiql-table { + border-collapse: collapse; + width: 100%; +} +reach-portal .graphiql-table :is(th, td) { + border: 1px solid var(--color-neutral-15); + padding: var(--px-8) var(--px-12); +} + +/* A single key the short-key dialog */ +reach-portal .graphiql-key { + background-color: var(--color-neutral-10); + border-radius: var(--border-radius-4); + padding: var(--px-4); +}