Skip to content

Commit 83f6b75

Browse files
authored
allow customizing styles (#25)
1 parent cbcd4d1 commit 83f6b75

2 files changed

Lines changed: 326 additions & 55 deletions

File tree

README.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,127 @@ See the [example repo](https://github.com/OneGraph/graphiql-explorer-example) fo
1616
![Preview](https://user-images.githubusercontent.com/476818/51567716-c00dfa00-1e4c-11e9-88f7-6d78b244d534.gif)
1717

1818
[Read the rationale on the OneGraph blog](https://www.onegraph.com/blog/2019/01/24/How_OneGraph_onboards_users_new_to_GraphQL.html).
19+
20+
21+
## Customizing styles
22+
23+
The default styling matches for the Explorer matches the default styling for GraphiQL. If you've customized your GraphiQL styling, you can customize the Explorer's styling to match.
24+
25+
### Customizing colors
26+
27+
The Explorer accepts a `colors` prop as a map of the class names in GraphiQL's css to hex colors. If you've edited the GraphiQL class names that control colors (e.g. `cm-def`, `cm-variable`, `cm-string`, etc.) use those same colors in the colors map. The naming of the keys in the colors map tries to align closely with the names of the class names in GraphiQL's css (note that the Explorer can't just apply the classes because of conflicts with how the css file styles inputs).
28+
29+
Example style map:
30+
31+
```javascript
32+
<Explorer colors={{
33+
keyword: '#B11A04',
34+
// OperationName, FragmentName
35+
def: '#D2054E',
36+
// FieldName
37+
property: '#1F61A0',
38+
// FieldAlias
39+
qualifier: '#1C92A9',
40+
// ArgumentName and ObjectFieldName
41+
attribute: '#8B2BB9',
42+
number: '#2882F9',
43+
string: '#D64292',
44+
// Boolean
45+
builtin: '#D47509',
46+
// Enum
47+
string2: '#0B7FC7',
48+
variable: '#397D13',
49+
// Type
50+
atom: '#CA9800',
51+
}} />
52+
```
53+
54+
### Customizing arrows and checkboxes
55+
56+
The explorer accepts props for setting custom checkboxes (for leaf fields) and arrows (for object fields).
57+
58+
The props are `arrowOpen`, `arrowClosed`, `checkboxChecked`, and `checkboxUnchecked`. You can pass any react node for those props.
59+
60+
The defaults are
61+
62+
arrowOpen
63+
```javascript
64+
<svg width="12" height="9">
65+
<path fill="#666" d="M 0 2 L 9 2 L 4.5 7.5 z" />
66+
</svg>
67+
```
68+
69+
arrowClosed
70+
```javascript
71+
<svg width="12" height="9">
72+
<path fill="#666" d="M 0 0 L 0 9 L 5.5 4.5 z" />
73+
</svg>
74+
```
75+
76+
checkboxChecked
77+
```
78+
<svg
79+
style={{marginRight: '3px', marginLeft: '-3px'}}
80+
width="12"
81+
height="12"
82+
viewBox="0 0 18 18"
83+
fill="none"
84+
xmlns="http://www.w3.org/2000/svg">
85+
<path
86+
d="M16 0H2C0.9 0 0 0.9 0 2V16C0 17.1 0.9 18 2 18H16C17.1 18 18 17.1 18 16V2C18 0.9 17.1 0 16 0ZM16 16H2V2H16V16ZM14.99 6L13.58 4.58L6.99 11.17L4.41 8.6L2.99 10.01L6.99 14L14.99 6Z"
87+
fill="#666"
88+
/>
89+
</svg>
90+
```
91+
92+
checkboxUnchecked
93+
```
94+
<svg
95+
style={{marginRight: '3px', marginLeft: '-3px'}}
96+
width="12"
97+
height="12"
98+
viewBox="0 0 18 18"
99+
fill="none"
100+
xmlns="http://www.w3.org/2000/svg">
101+
<path
102+
d="M16 2V16H2V2H16ZM16 0H2C0.9 0 0 0.9 0 2V16C0 17.1 0.9 18 2 18H16C17.1 18 18 17.1 18 16V2C18 0.9 17.1 0 16 0Z"
103+
fill="#CCC"
104+
/>
105+
</svg>
106+
```
107+
108+
### Customizing the buttons to create new operations
109+
110+
You can modify the styles for the buttons that allow you to create new operations.
111+
112+
Pass the `styles` prop when you create the component. It's an object with two keys, `explorerActionsStyle` and `buttonStyle`.
113+
114+
Example styles map:
115+
```javascript
116+
<Explorer
117+
styles={{
118+
buttonStyle: {
119+
fontSize: '1.2em',
120+
padding: '0px',
121+
backgroundColor: 'white',
122+
border: 'none',
123+
margin: '5px 0px',
124+
height: '40px',
125+
width: '100%',
126+
display: 'block',
127+
maxWidth: 'none',
128+
},
129+
130+
explorerActionsStyle: {
131+
margin: '4px -8px -8px',
132+
paddingLeft: '8px',
133+
bottom: '0px',
134+
width: '100%',
135+
textAlign: 'center',
136+
background: 'none',
137+
borderTop: 'none',
138+
borderBottom: 'none',
139+
},
140+
}}
141+
/>
142+
```

0 commit comments

Comments
 (0)