Skip to content

Commit 8e81102

Browse files
dimaMachinaTallTed
andcommitted
prefer localStorage over window.localStorage (graphql#3646)
add `packageManager` field in `package.json` (graphql#3654) [graphiql] add `className` prop. Additional class names which will be appended to the GraphiQL container element (graphql#3643) disable shrinking while changing the operation name Update packages/graphiql-react/src/ui/tabs.css Co-authored-by: Ted Thibodeau Jr <[email protected]>
1 parent 2583302 commit 8e81102

File tree

11 files changed

+364
-134
lines changed

11 files changed

+364
-134
lines changed

.changeset/lazy-beers-confess.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"graphiql": minor
3+
---
4+
5+
add `className` prop. Additional class names which will be appended to the GraphiQL container element

.changeset/light-geckos-vanish.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@graphiql/toolkit": patch
3+
---
4+
5+
prefer `localStorage` over `window.localStorage`

.eslintrc.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,14 @@ module.exports = {
133133
'no-octal-escape': 'error',
134134
'no-param-reassign': 'error',
135135
'no-proto': 'error',
136-
'no-restricted-properties': 'off',
136+
'no-restricted-properties': [
137+
'error',
138+
{
139+
object: 'window',
140+
property: 'localStorage',
141+
message: 'Use `localStorage` instead',
142+
},
143+
],
137144
'no-return-assign': 'error',
138145
'no-return-await': 'error',
139146
'no-script-url': 'error',

package.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@
2929
"pre-commit": "lint-staged"
3030
}
3131
},
32-
"engines": {
33-
"npm": "please_use_yarn_instead"
34-
},
32+
"packageManager": "[email protected]",
3533
"scripts": {
3634
"build": "yarn build-clean && yarn tsc && yarn build:nontsc",
3735
"build-bundles": "yarn prebuild-bundles && yarn wsrun:noexamples --stages build-bundles",

packages/graphiql-react/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"codemirror": "^5.65.3",
6060
"codemirror-graphql": "^2.0.12",
6161
"copy-to-clipboard": "^3.2.0",
62-
"framer-motion": "^6.5.1",
62+
"framer-motion": "^11.0.0",
6363
"graphql-language-service": "^5.2.1",
6464
"markdown-it": "^14.1.0",
6565
"set-value": "^4.1.0"

packages/graphiql-react/src/ui/tabs.css

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
gap: var(--px-8);
55
padding: var(--px-8) 0;
66
margin: 0 var(--px-8)
7-
/* when using padding while scrolling tab items will overflow to padding area */;
7+
/* when using padding while scrolling, tab items will overflow to padding area */;
88
overflow-x: auto;
99
list-style: none;
1010
}
@@ -17,6 +17,11 @@
1717
.graphiql-tab {
1818
background: hsla(var(--color-neutral), var(--alpha-background-light));
1919

20+
/* disable shrinking while changing the operation name */
21+
&:not(:focus-within) {
22+
transform: none !important;
23+
}
24+
2025
.graphiql-tab-wrapper {
2126
position: relative;
2227
display: flex;

packages/graphiql-toolkit/src/storage/base.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ export class StorageAPI {
6464
this.storage = null;
6565
} else {
6666
this.storage = {
67-
getItem: window.localStorage.getItem.bind(window.localStorage),
68-
setItem: window.localStorage.setItem.bind(window.localStorage),
69-
removeItem: window.localStorage.removeItem.bind(window.localStorage),
67+
getItem: localStorage.getItem.bind(localStorage),
68+
setItem: localStorage.setItem.bind(localStorage),
69+
removeItem: localStorage.removeItem.bind(localStorage),
7070

7171
get length() {
7272
let keys = 0;
73-
for (const key in window.localStorage) {
73+
for (const key in localStorage) {
7474
if (key.indexOf(`${STORAGE_NAMESPACE}:`) === 0) {
7575
keys += 1;
7676
}
@@ -80,9 +80,9 @@ export class StorageAPI {
8080

8181
clear() {
8282
// We only want to clear the namespaced items
83-
for (const key in window.localStorage) {
83+
for (const key in localStorage) {
8484
if (key.indexOf(`${STORAGE_NAMESPACE}:`) === 0) {
85-
window.localStorage.removeItem(key);
85+
localStorage.removeItem(key);
8686
}
8787
}
8888
},

packages/graphiql-toolkit/src/storage/custom.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function createLocalStorage({
2525
removeItem: key => localStorage.removeItem(getStorageKey(key)),
2626
get length() {
2727
let keys = 0;
28-
for (const key in window.localStorage) {
28+
for (const key in localStorage) {
2929
if (key.indexOf(storageKeyPrefix) === 0) {
3030
keys += 1;
3131
}
@@ -35,9 +35,9 @@ export function createLocalStorage({
3535

3636
clear() {
3737
// We only want to clear the namespaced items
38-
for (const key in window.localStorage) {
38+
for (const key in localStorage) {
3939
if (key.indexOf(storageKeyPrefix) === 0) {
40-
window.localStorage.removeItem(key);
40+
localStorage.removeItem(key);
4141
}
4242
}
4343
},

packages/graphiql/src/components/GraphiQL.tsx

+10-1
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ export type GraphiQLInterfaceProps = WriteableEditorProps &
225225
* rendered with a specific theme
226226
*/
227227
forcedTheme?: (typeof THEMES)[number];
228+
/**
229+
* Additional class names which will be appended to the container element.
230+
*/
231+
className?: string;
228232
};
229233

230234
const THEMES = ['light', 'dark', 'system'] as const;
@@ -454,9 +458,14 @@ export function GraphiQLInterface(props: GraphiQLInterfaceProps) {
454458

455459
const hasMultipleTabs = editorContext.tabs.length > 1;
456460

461+
const className = props.className ? ` ${props.className}` : '';
462+
457463
return (
458464
<Tooltip.Provider>
459-
<div data-testid="graphiql-container" className="graphiql-container">
465+
<div
466+
data-testid="graphiql-container"
467+
className={`graphiql-container${className}`}
468+
>
460469
<div className="graphiql-sidebar">
461470
<div className="graphiql-sidebar-section">
462471
{pluginContext?.plugins.map((plugin, index) => {

packages/graphiql/src/components/__tests__/GraphiQL.spec.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const simpleIntrospection = {
2929
};
3030

3131
beforeEach(() => {
32-
window.localStorage.clear();
32+
localStorage.clear();
3333
});
3434

3535
describe('GraphiQL', () => {

0 commit comments

Comments
 (0)