Skip to content

Commit dbc23cf

Browse files
huv1ktimsuchanek
authored andcommitted
Dynamic themes for playground (#733)
* New styles * Almost finished * Tabs * Finished dynamic styling
1 parent 8556bd2 commit dbc23cf

20 files changed

+419
-3710
lines changed
Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11
{
2-
"presets": [
3-
"es2015",
4-
"es2016",
5-
"react"
6-
],
7-
"plugins": [
8-
"styled-jsx-postcss/babel",
9-
"babel-plugin-styled-components",
10-
"babel-plugin-polished"
11-
]
2+
"presets": ["es2015", "es2016", "react"],
3+
"plugins": ["styled-jsx-postcss/babel", "babel-plugin-styled-components"]
124
}

packages/graphql-playground-react/package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
"babel-cli": "6.26.0",
5151
"babel-core": "6.26.3",
5252
"babel-loader": "7.1.4",
53-
"babel-plugin-polished": "1.1.0",
5453
"babel-plugin-styled-components": "1.5.1",
5554
"babel-preset-es2015": "6.24.1",
5655
"babel-preset-es2016": "6.24.1",
@@ -137,7 +136,6 @@
137136
"lodash.debounce": "^4.0.8",
138137
"markdown-it": "^8.4.1",
139138
"marked": "^0.3.19",
140-
"polished": "^1.9.0",
141139
"postcss-modules": "^1.1.0",
142140
"prettier": "^1.13.0",
143141
"prop-types": "^15.6.0",
@@ -164,10 +162,9 @@
164162
"redux-saga": "^0.16.0",
165163
"reselect": "^3.0.1",
166164
"seamless-immutable": "^7.0.1",
167-
"styled-components": "^3.1.6",
165+
"styled-components": "^3.3.2",
168166
"styled-jsx": "^2.2.1",
169167
"styled-jsx-postcss": "timsuchanek/styled-jsx-postcss#build3",
170-
"styled-theming": "^2.2.0",
171168
"subscriptions-transport-ws": "^0.9.5",
172169
"utility-types": "^1.0.0",
173170
"webpack-bundle-analyzer": "^2.9.2",

packages/graphql-playground-react/src/components/FileEditor.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as React from 'react'
22
import { styled } from '../styled'
3-
import * as theme from 'styled-theming'
43
import { QueryEditor } from './Playground/QueryEditor'
54
import { createStructuredSelector } from 'reselect'
65
import { getFile } from '../state/sessions/selectors'
@@ -41,13 +40,8 @@ export default connect(
4140
{ onChange: editFile },
4241
)(FileEditor)
4342

44-
const backgroundColor = theme('mode', {
45-
light: p => p.theme.colours.darkBlue10,
46-
dark: p => p.theme.colours.darkBlue,
47-
})
48-
4943
const Wrapper = styled.div`
50-
background: ${backgroundColor};
44+
background: ${p => p.theme.editorColours.resultBackground};
5145
position: relative;
5246
.variable-editor {
5347
height: 100% !important;

packages/graphql-playground-react/src/components/HistoryPopup.tsx

Lines changed: 18 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ import { HistoryFilter } from '../types'
55
import HistoryItems from './HistoryPopup/HistoryItems'
66
import { Icon } from 'graphcool-styles'
77
import { modalStyle } from '../constants'
8-
import { withTheme, LocalThemeInterface } from './Theme'
9-
import * as cn from 'classnames'
108
import { QueryEditor } from './Playground/QueryEditor'
119
import { styled } from '../styled'
12-
import * as theme from 'styled-theming'
1310
import { connect } from 'react-redux'
1411
import { createStructuredSelector } from 'reselect'
1512
import { getHistory } from '../state/history/selectors'
@@ -35,11 +32,8 @@ export interface State {
3532
searchTerm: string
3633
}
3734

38-
class HistoryPopup extends React.Component<
39-
ReduxProps & LocalThemeInterface,
40-
State
41-
> {
42-
constructor(props: ReduxProps & LocalThemeInterface) {
35+
class HistoryPopup extends React.Component<ReduxProps, State> {
36+
constructor(props: ReduxProps) {
4337
super(props)
4438
const selectedItemIndex = props.items.keySeq().first() || ''
4539
this.state = {
@@ -50,7 +44,6 @@ class HistoryPopup extends React.Component<
5044
}
5145
render() {
5246
const { searchTerm, selectedFilter } = this.state
53-
const { localTheme } = this.props
5447
const items = this.props.items.filter(item => {
5548
return selectedFilter === 'STARRED'
5649
? item.starred
@@ -65,25 +58,15 @@ class HistoryPopup extends React.Component<
6558
) as any
6659
selectedItem =
6760
selectedItem && selectedItem.toJS ? selectedItem.toJS() : undefined
68-
let customModalStyle = modalStyle
69-
if (localTheme === 'light') {
70-
customModalStyle = {
71-
...modalStyle,
72-
overlay: {
73-
...modalStyle.overlay,
74-
backgroundColor: 'rgba(255,255,255,0.9)',
75-
},
76-
}
77-
}
7861

7962
return (
8063
<Modal
8164
isOpen={this.props.isOpen}
8265
onRequestClose={this.props.closeHistory}
8366
contentLabel="GraphiQL Session History"
84-
style={customModalStyle}
67+
style={modalStyle}
8568
>
86-
<Wrapper className={localTheme}>
69+
<Wrapper>
8770
<Left>
8871
<HistoryHeader
8972
onSelectFilter={this.handleSelectFilter}
@@ -113,16 +96,8 @@ class HistoryPopup extends React.Component<
11396
/>
11497
</Use>
11598
</RightHeader>
116-
<Big
117-
className={cn({
118-
'docs-graphiql': localTheme === 'light',
119-
})}
120-
>
121-
<GraphiqlWrapper
122-
className={cn({
123-
'graphiql-wrapper': localTheme === 'light',
124-
})}
125-
>
99+
<Big>
100+
<GraphiqlWrapper>
126101
<Container>
127102
<QueryWrap>
128103
<QueryEditor value={selectedItem.query} />
@@ -168,17 +143,15 @@ const mapStateToProps = createStructuredSelector({
168143
isOpen: getHistoryOpen,
169144
})
170145

171-
export default withTheme<{}>(
172-
connect(
173-
mapStateToProps,
174-
{
175-
closeHistory,
176-
openHistory,
177-
duplicateSession,
178-
toggleHistoryItemStarring,
179-
},
180-
)(HistoryPopup),
181-
)
146+
export default connect(
147+
mapStateToProps,
148+
{
149+
closeHistory,
150+
openHistory,
151+
duplicateSession,
152+
toggleHistoryItemStarring,
153+
},
154+
)(HistoryPopup)
182155

183156
const Wrapper = styled.div`
184157
display: flex;
@@ -196,11 +169,6 @@ const Right = styled.div`
196169
z-index: 2;
197170
`
198171

199-
const rightBackgroundColor = theme('mode', {
200-
light: '#f6f7f7',
201-
dark: p => p.theme.colours.darkBlue,
202-
})
203-
204172
const RightHeader = styled.div`
205173
display: flex;
206174
justify-content: space-between;
@@ -211,7 +179,7 @@ const RightHeader = styled.div`
211179
padding-top: 20px;
212180
padding-bottom: 20px;
213181
214-
background: ${rightBackgroundColor};
182+
background: ${p => p.theme.editorColours.resultBackground};
215183
`
216184

217185
const RightEmpty = styled.div`
@@ -220,17 +188,12 @@ const RightEmpty = styled.div`
220188
justify-content: center;
221189
align-items: center;
222190
223-
background: ${rightBackgroundColor};
191+
background: ${p => p.theme.editorColours.resultBackground};
224192
`
225193

226-
const color = theme('mode', {
227-
dark: p => p.theme.colours.white60,
228-
light: p => p.theme.colours.darkBlue60,
229-
})
230-
231194
const RightEmptyText = styled.div`
232195
font-size: 16px;
233-
color: ${color};
196+
color: ${p => p.theme.editorColours.text};
234197
`
235198

236199
const View = styled.div`

packages/graphql-playground-react/src/components/Playground/ExecuteButton.tsx

Lines changed: 17 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@
77
*/
88

99
import * as React from 'react'
10-
import * as cx from 'classnames'
11-
import { withTheme, LocalThemeInterface } from '../Theme'
1210
import ExecuteButtonOperation from './ExecuteButtonOperation'
1311
import { withProps, styled } from '../../styled'
14-
import * as theme from 'styled-theming'
15-
import { mix, lighten } from 'polished'
1612
import { connect } from 'react-redux'
1713
import { runQuery, stopQuery } from '../../state/sessions/actions'
1814
import { createStructuredSelector } from 'reselect'
@@ -44,10 +40,7 @@ let firstTime = true
4440
* What a nice round shiny button. Shows a drop-down when there are multiple
4541
* queries to run.
4642
*/
47-
class ExecuteButton extends React.Component<
48-
LocalThemeInterface & ReduxProps,
49-
State
50-
> {
43+
class ExecuteButton extends React.Component<ReduxProps, State> {
5144
constructor(props) {
5245
super(props)
5346

@@ -102,10 +95,9 @@ class ExecuteButton extends React.Component<
10295
)
10396

10497
return (
105-
<Wrapper className={this.props.localTheme}>
98+
<Wrapper>
10699
<Button
107-
className={cx(this.props.localTheme)}
108-
isRunning={String(this.props.queryRunning)}
100+
isRunning={this.props.queryRunning}
109101
onMouseDown={onMouseDown}
110102
onClick={onClick}
111103
title="Execute Query (Ctrl-Enter)"
@@ -193,12 +185,10 @@ const mapStateToProps = createStructuredSelector({
193185
sessionId: getSelectedSessionIdFromRoot,
194186
})
195187

196-
export default withTheme<{}>(
197-
connect(
198-
mapStateToProps,
199-
{ runQuery, stopQuery },
200-
)(toJS(ExecuteButton)),
201-
)
188+
export default connect(
189+
mapStateToProps,
190+
{ runQuery, stopQuery },
191+
)(toJS(ExecuteButton))
202192

203193
const Wrapper = styled.div`
204194
position: absolute;
@@ -208,35 +198,8 @@ const Wrapper = styled.div`
208198
margin: 0 14px 0 28px;
209199
`
210200

211-
const buttonBackground = theme.variants('mode', 'isRunning', {
212-
true: {
213-
light: p => p.theme.colours.red,
214-
dark: p => p.theme.colours.red,
215-
},
216-
false: {
217-
dark: 'rgb(185, 191, 196)',
218-
light: p => mix(0.6, p.theme.colours.darkBlue, 'white'),
219-
},
220-
})
221-
222-
const buttonBackgroundHover = theme.variants('mode', 'isRunning', {
223-
true: {
224-
light: p => lighten(0.1, p.theme.colours.red),
225-
dark: p => lighten(0.1, p.theme.colours.red),
226-
},
227-
false: {
228-
dark: 'rgb(195, 201, 206)',
229-
light: p => mix(0.8, p.theme.colours.darkBlue, 'white'),
230-
},
231-
})
232-
233-
const buttonBorderColor = theme('mode', {
234-
light: '#eeeff0',
235-
dark: 'rgb(11, 20, 28)',
236-
})
237-
238201
interface ButtonProps {
239-
isRunning: string
202+
isRunning: boolean
240203
}
241204

242205
const Button = withProps<ButtonProps>()(styled.div)`
@@ -249,16 +212,22 @@ const Button = withProps<ButtonProps>()(styled.div)`
249212
250213
border-radius: 100%;
251214
transition: background-color 100ms;
252-
background-color: ${buttonBackground};
253-
border: 6px solid ${buttonBorderColor};
215+
background-color: ${p =>
216+
p.isRunning
217+
? p.theme.editorColours.executeButtonSubscription
218+
: p.theme.editorColours.executeButton};
219+
border: 6px solid ${p => p.theme.editorColours.executeButtonBorder};
254220
cursor: pointer;
255221
256222
svg {
257223
fill: ${p => (p.theme.mode === 'light' ? 'white' : 'inherit')};
258224
}
259225
260226
&:hover {
261-
background-color: ${buttonBackgroundHover};
227+
background-color:${p =>
228+
p.isRunning
229+
? p.theme.editorColours.executeButtonSubscriptionHover
230+
: p.theme.editorColours.executeButtonHover};
262231
}
263232
`
264233

packages/graphql-playground-react/src/components/Playground/GraphQLEditor.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,9 @@ const VariableEditorSubtitle = withProps<TitleProps>()(styled.span)`
715715
margin-right: 10px;
716716
cursor: pointer;
717717
color: ${p =>
718-
p.isOpen ? p.theme.colours.text : p.theme.colours.textInactive};
718+
p.isOpen
719+
? p.theme.editorColours.drawerText
720+
: p.theme.editorColours.drawerTextInactive};
719721
`
720722

721723
const ResponseTracking = styled(BottomDrawer)`
@@ -728,7 +730,7 @@ const ResponseTrackingTitle = withProps<TitleProps>()(
728730
text-align: right;
729731
background: ${p => p.theme.editorColours.rightDrawerBackground};
730732
cursor: ${props => (props.isOpen ? 's-resize' : 'n-resize')};
731-
color: ${p => p.theme.colours.textInactive};
733+
color: ${p => p.theme.editorColours.drawerTextInactive};
732734
`
733735

734736
interface QueryProps {
@@ -760,7 +762,7 @@ const Intro = styled.div`
760762
const Listening = styled.div`
761763
position: absolute;
762764
bottom: 0;
763-
color: ${p => p.theme.colours.text};
765+
color: ${p => p.theme.editorColours.text};
764766
background: ${p => p.theme.editorColours.resultBackground};
765767
font-size: ${p => p.theme.sizes.small16};
766768
font-family: ${p => p.theme.settings['editor.fontFamily']};

packages/graphql-playground-react/src/components/Playground/ResponseTracing.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import * as React from 'react'
2-
import { $v } from 'graphcool-styles'
32
import TracingRow from './TracingRow'
4-
import * as theme from 'styled-theming'
53
import styled from '../../styled/styled'
64
import { createStructuredSelector } from 'reselect'
75
import {
@@ -38,16 +36,11 @@ export interface ReduxProps {
3836
queryRunning: boolean
3937
}
4038

41-
const textColor = theme('mode', {
42-
light: p => p.theme.colours.darkBlue60,
43-
dark: p => p.theme.colours.white,
44-
})
45-
4639
const TracingWrapper = styled.div`
4740
padding-top: 16px;
4841
padding-left: 25px;
4942
padding-right: 25px;
50-
color: ${textColor};
43+
color: ${p => p.theme.editorColours.text};
5144
overflow: auto;
5245
position: relative;
5346
height: 100%;
@@ -58,7 +51,7 @@ const ReRun = styled.div`
5851
`
5952
const NotSupported = styled.div`
6053
font-size: 14px;
61-
color: ${$v.lightOrange};
54+
color: rgba(241, 143, 1, 1);
6255
`
6356

6457
const TracingRows = styled.div`

0 commit comments

Comments
 (0)