Skip to content

Commit

Permalink
Merge pull request #323 from joelgriffith/feature/code-mirror-theme-e…
Browse files Browse the repository at this point in the history
…xposed

Feature/code mirror theme exposed
  • Loading branch information
wincent authored Feb 13, 2017
2 parents a02a76a + fa6ae69 commit c573490
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 7 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ GraphiQL supports customization in UI and behavior by accepting React props and

- `getDefaultFieldNames`: an optional function used to provide default fields to non-leaf fields which invalidly lack a selection set. Accepts a GraphQLType instance and returns an array of field names. If not provided, a default behavior will be used.

- `editorTheme`: an optional string naming a CodeMirror theme to be applied to the `QueryEditor`, `ResultViewer`, and `Variables` panes. Defaults to the `graphiql` theme. See below for full usage.

**Children:**

* `<GraphiQL.Logo>`: Replace the GraphiQL logo with your own.
Expand Down Expand Up @@ -203,6 +205,20 @@ class CustomGraphiQL extends React.Component {
}
```

### Applying an Editor Theme

In order to theme the editor portions of the interface, you can supply a `editorTheme` prop. You'll also need to load the appropriate CSS for the theme (similar to loading the CSS for this project). [See the themes available here](https://codemirror.net/demo/theme.html).


```js
// In your html
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.23.0/theme/solarized.css" />

// In your GraphiQL JSX
<GraphiQL
editorTheme="solarized"
/>
```

### Query Samples

Expand Down
3 changes: 2 additions & 1 deletion css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@
width: 12px;
}

.graphiql-container .result-window .CodeMirror {
/* No `.graphiql-container` here so themes can overwrite */
.result-window .CodeMirror {
background: #f6f7f8;
}

Expand Down
6 changes: 5 additions & 1 deletion src/components/GraphiQL.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ export class GraphiQL extends React.Component {
onEditVariables: PropTypes.func,
onEditOperationName: PropTypes.func,
onToggleDocs: PropTypes.func,
getDefaultFieldNames: PropTypes.func
getDefaultFieldNames: PropTypes.func,
editorTheme: PropTypes.string,
}

constructor(props) {
Expand Down Expand Up @@ -283,6 +284,7 @@ export class GraphiQL extends React.Component {
onHintInformationRender={this.handleHintInformationRender}
onClickReference={this.handleClickReference}
onRunQuery={this.handleEditorRunQuery}
editorTheme={this.props.editorTheme}
/>
<div className="variable-editor" style={variableStyle}>
<div
Expand All @@ -298,6 +300,7 @@ export class GraphiQL extends React.Component {
onEdit={this.handleEditVariables}
onHintInformationRender={this.handleHintInformationRender}
onRunQuery={this.handleEditorRunQuery}
editorTheme={this.props.editorTheme}
/>
</div>
</div>
Expand All @@ -311,6 +314,7 @@ export class GraphiQL extends React.Component {
<ResultViewer
ref={c => { this.resultComponent = c; }}
value={this.state.response}
editorTheme={this.props.editorTheme}
/>
{footer}
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/components/QueryEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class QueryEditor extends React.Component {
onHintInformationRender: PropTypes.func,
onClickReference: PropTypes.func,
onRunQuery: PropTypes.func,
editorTheme: PropTypes.string,
}

constructor(props) {
Expand Down Expand Up @@ -67,7 +68,7 @@ export class QueryEditor extends React.Component {
lineNumbers: true,
tabSize: 2,
mode: 'graphql',
theme: 'graphiql',
theme: this.props.editorTheme || 'graphiql',
keyMap: 'sublime',
autoCloseBrackets: true,
matchBrackets: true,
Expand Down
5 changes: 3 additions & 2 deletions src/components/ResultViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import React, { PropTypes } from 'react';
*/
export class ResultViewer extends React.Component {
static propTypes = {
value: PropTypes.string
value: PropTypes.string,
editorTheme: PropTypes.string,
}

componentDidMount() {
Expand All @@ -38,7 +39,7 @@ export class ResultViewer extends React.Component {
lineWrapping: true,
value: this.props.value || '',
readOnly: true,
theme: 'graphiql',
theme: this.props.editorTheme || 'graphiql',
mode: 'graphql-results',
keyMap: 'sublime',
foldGutter: {
Expand Down
3 changes: 2 additions & 1 deletion src/components/VariableEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class VariableEditor extends React.Component {
onEdit: PropTypes.func,
onHintInformationRender: PropTypes.func,
onRunQuery: PropTypes.func,
editorTheme: PropTypes.string,
}

constructor(props) {
Expand Down Expand Up @@ -61,7 +62,7 @@ export class VariableEditor extends React.Component {
lineNumbers: true,
tabSize: 2,
mode: 'graphql-variables',
theme: 'graphiql',
theme: this.props.editorTheme || 'graphiql',
keyMap: 'sublime',
autoCloseBrackets: true,
matchBrackets: true,
Expand Down
1 change: 0 additions & 1 deletion test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
/* eslint-disable no-console */
import express from 'express';
import path from 'path';
import fs from 'fs';
import browserify from 'browserify';
import browserifyShim from 'browserify-shim';
import watchify from 'watchify';
Expand Down

0 comments on commit c573490

Please sign in to comment.