Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/dark theme #200

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ and children.
Accepts a GraphQLType instance and returns an array of field names.
If not provided, a default behavior will be used.

- `theme`: an optional string of the theme you'd like to use for GraphiQL. Currently only `dark`
is available.

**Children:**

* `<GraphiQL.Logo>`: Replace the GraphiQL logo with your own.
Expand All @@ -143,42 +146,44 @@ class CustomGraphiQL extends React.Component {
// REQUIRED:
// `fetcher` must be provided in order for GraphiQL to operate
fetcher: this.props.fetcher,

// OPTIONAL PARAMETERS
// GraphQL artifacts
query: '',
variables: '',
response: '',


// OPTIONAL DARK THEME
theme: 'dark',

// GraphQL Schema
// If `undefined` is provided, an introspection query is executed
// using the fetcher.
schema: undefined,



// Useful to determine which operation to run
// when there are multiple of them.
operationName: null,
storage: null,
defaultQuery: null,

// Custom Event Handlers
onEditQuery: null,
onEditVariables: null,
onEditOperationName: null,

// GraphiQL automatically fills in leaf nodes when the query
// does not provide them. Change this if your GraphQL Definitions
// should behave differently than what's defined here:
// (https://github.com/graphql/graphiql/blob/master/src/utility/fillLeafs.js#L75)
getDefaultFieldNames: null
};
}

_onClickToolbarButton(event) {
alert('Clicked toolbar button!');
}

render() {
return (
<GraphiQL ...this.state>
Expand Down
9 changes: 9 additions & 0 deletions css/dark-theme.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.graphiql-container.dark .topBar,
.graphiql-container.dark .docExplorerShow,
.graphiql-container .execute-button {
background: linear-gradient(#e2e2e2, #f7f7f7);
}
.graphiql-container.dark,
.CodeMirror-hints-wrapper {
filter: invert(90%);
}
12 changes: 10 additions & 2 deletions src/components/GraphiQL.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ import {
* Accepts a GraphQLType instance and returns an array of field names.
* If not provided, a default behavior will be used.
*
* - theme: A theme to use for overall UI, currently only dark is available.
*
* Children:
*
* - <GraphiQL.Logo> Replace the GraphiQL logo with your own.
Expand Down Expand Up @@ -120,7 +122,9 @@ export class GraphiQL extends React.Component {
onEditVariables: PropTypes.func,
onEditOperationName: PropTypes.func,
onToggleDocs: PropTypes.func,
getDefaultFieldNames: PropTypes.func
getDefaultFieldNames: PropTypes.func,
theme: PropTypes.oneOf([ 'dark' ]),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Figured we could keep this open to future theme(s)

syntaxTheme: PropTypes.string
}

constructor(props) {
Expand Down Expand Up @@ -158,12 +162,16 @@ export class GraphiQL extends React.Component {
queryFacts && queryFacts.operations
);

// Determine the UI theme (dark or light)
const theme = props.theme !== undefined ? props.theme : '';

// Initialize state
this.state = {
schema: props.schema,
query,
variables,
operationName,
theme,
response: props.response,
editorFlex: Number(this._storageGet('editorFlex')) || 1,
variableEditorOpen: Boolean(variables),
Expand Down Expand Up @@ -285,7 +293,7 @@ export class GraphiQL extends React.Component {
};

return (
<div className="graphiql-container">
<div className={`graphiql-container ${this.state.theme}`}>
<div className="editorWrap">
<div className="topBarWrap">
<div className="topBar">
Expand Down