Skip to content

Commit e9b01c9

Browse files
authored
Merge pull request #237 from graphcool/refactor/to-sc
Work In Progress: Refactor to use Styled Components
2 parents 7528f0a + 7f3b142 commit e9b01c9

File tree

19 files changed

+737
-554
lines changed

19 files changed

+737
-554
lines changed

packages/graphql-playground/.babelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
],
77
"plugins": [
88
"styled-jsx-postcss/babel",
9-
"babel-plugin-styled-components"
9+
"babel-plugin-styled-components",
10+
"babel-plugin-polished"
1011
]
1112
}

packages/graphql-playground/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"babel-cli": "^6.24.1",
4747
"babel-core": "^6.25.0",
4848
"babel-loader": "^6.2.10",
49+
"babel-plugin-polished": "^1.1.0",
4950
"babel-plugin-styled-components": "^1.3.0",
5051
"babel-preset-es2015": "^6.18.0",
5152
"babel-preset-es2016": "^6.16.0",
@@ -71,6 +72,7 @@
7172
"lint-staged": "^4.0.2",
7273
"node-noop": "^1.0.0",
7374
"object-assign": "4.1.0",
75+
"polished": "^1.9.0",
7476
"postcss-cssnext": "^2.9.0",
7577
"postcss-flexbugs-fixes": "^3.2.0",
7678
"postcss-import": "^9.1.0",
@@ -95,6 +97,7 @@
9597
"tslint-graphcool-frontend": "^0.0.3",
9698
"tslint-loader": "^3.5.3",
9799
"typescript": "^2.6.1",
100+
"typescript-styled-plugin": "^0.2.0",
98101
"url-loader": "0.5.7",
99102
"webpack": "^3.8.1",
100103
"webpack-dev-server": "^2.9.3",
@@ -139,6 +142,7 @@
139142
"seamless-immutable": "^7.0.1",
140143
"styled-components": "^2.2.3",
141144
"styled-jsx-postcss": "git+https://github.com/timsuchanek/styled-jsx-postcss#build3",
145+
"styled-theming": "^2.2.0",
142146
"subscriptions-transport-ws": "^0.8.1"
143147
},
144148
"lint-staged": {

packages/graphql-playground/src/components/CodeGenerationPopup/CodeGenerationPopup.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import CodeGenerationPopupClientChooser from './CodeGenerationPopupClientChooser
66
import { modalStyle } from '../../constants'
77
import * as Modal from 'react-modal'
88
import { Environment, GraphQLClient } from '../../types'
9-
import { withTheme, ThemeInterface } from '../Theme'
9+
import { withTheme, LocalThemeInterface } from '../Theme'
1010

1111
export interface Props {
1212
query: string
@@ -21,7 +21,7 @@ export interface State {
2121
}
2222

2323
class CodeGenerationPopup extends React.Component<
24-
Props & ThemeInterface,
24+
Props & LocalThemeInterface,
2525
State
2626
> {
2727
constructor(props) {

packages/graphql-playground/src/components/CodeGenerationPopup/CodeGenerationPopupCode.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as cx from 'classnames'
33
import { $p } from 'graphcool-styles'
44
import { CodeGenerator } from './codeGeneration'
55
import { GraphQLClient, Environment } from '../../types'
6-
import { withTheme, ThemeInterface } from '../Theme'
6+
import { withTheme, LocalThemeInterface } from '../Theme'
77
// tslint:disable-next-line
88
const Codemirror: any = require('react-codemirror')
99

@@ -15,7 +15,7 @@ export interface Props {
1515
}
1616

1717
class CodeGenerationPopupCode extends React.Component<
18-
Props & ThemeInterface,
18+
Props & LocalThemeInterface,
1919
{}
2020
> {
2121
componentWillMount() {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import HistoryItems from './HistoryPopup/HistoryItems'
66
import GraphQLEditor from './Playground/GraphQLEditor'
77
import { $v, Icon } from 'graphcool-styles'
88
import { modalStyle } from '../constants'
9-
import { withTheme, ThemeInterface } from './Theme'
9+
import { withTheme, LocalThemeInterface } from './Theme'
1010
import * as cn from 'classnames'
1111

1212
export interface Props {
@@ -26,7 +26,7 @@ export interface State {
2626
searchTerm: string
2727
}
2828

29-
class HistoryPopup extends React.Component<Props & ThemeInterface, State> {
29+
class HistoryPopup extends React.Component<Props & LocalThemeInterface, State> {
3030
constructor(props) {
3131
super(props)
3232
this.state = {

packages/graphql-playground/src/components/Permissions/NewPermissionTab.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import * as cn from 'classnames'
66
import { PermissionSession, ServiceInformation } from '../../types'
77
import TypeChooser from './TypeChooser'
88
import { Button } from '../Button'
9-
import { ThemeInterface } from '../Theme'
9+
import { LocalThemeInterface } from '../Theme'
1010

11-
export interface Props extends ThemeInterface {
11+
export interface Props extends LocalThemeInterface {
1212
serviceInformation: ServiceInformation
1313
onNewPermissionTab: (permissionTab: PermissionSession) => void
1414
}

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

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import { isEqual, mapValues } from 'lodash'
4141
import Share from './Share'
4242
import NewPermissionTab from './Permissions/NewPermissionTab'
4343
import { serviceInformationQuery } from './constants'
44-
import { ThemeProvider, theme as styledTheme } from '../styled'
44+
import styled, { ThemeProvider, theme as styledTheme } from '../styled'
4545

4646
export type Theme = 'dark' | 'light'
4747
export type Viewer = 'ADMIN' | 'EVERYONE' | 'USER'
@@ -590,44 +590,9 @@ export class Playground extends React.PureComponent<Props & DocsState, State> {
590590
: this.getSimpleEndpoint()
591591
const isGraphcoolUrl = this.isGraphcoolUrl(selectedEndpointUrl)
592592
return (
593-
<ThemeProvider theme={styledTheme}>
593+
<ThemeProvider theme={{ ...styledTheme, mode: theme }}>
594594
<OldThemeProvider theme={this.state.theme}>
595-
<div className={cx('playground')}>
596-
<style jsx={true}>{`
597-
.playground {
598-
@p: .h100, .flex, .flexColumn;
599-
margin: 0;
600-
padding: 0;
601-
overflow: hidden;
602-
font-family: 'Open Sans', sans-serif;
603-
-webkit-font-smoothing: antialiased;
604-
-moz-osx-font-smoothing: grayscale;
605-
color: rgba(0, 0, 0, 0.8);
606-
line-height: 1.5;
607-
letter-spacing: 0.53px;
608-
margin-right: -1px !important;
609-
}
610-
611-
.blur {
612-
filter: blur(5px);
613-
}
614-
615-
.graphiqls-container {
616-
@p: .relative, .overflowHidden;
617-
height: calc(100vh - 57px);
618-
}
619-
620-
.graphiql-wrapper {
621-
@p: .w100, .h100, .relative;
622-
}
623-
624-
.playground :global(a:active),
625-
.playground :global(a:focus),
626-
.playground :global(button:focus),
627-
.playground :global(input:focus) {
628-
outline: none;
629-
}
630-
`}</style>
595+
<PlaygroundWrapper className="playground">
631596
<TabBar
632597
sessions={sessions}
633598
selectedSessionIndex={selectedSessionIndex}
@@ -640,13 +605,13 @@ export class Playground extends React.PureComponent<Props & DocsState, State> {
640605
tether={this.props.tether}
641606
isApp={this.props.isApp}
642607
/>
643-
<div
608+
<GraphiqlsContainer
644609
className={cx('graphiqls-container', {
645610
'docs-graphiql': theme === 'light',
646611
})}
647612
>
648613
{sessions.map((session, index) => (
649-
<div
614+
<GraphiqlWrapper
650615
key={session.id}
651616
className={cx('graphiql-wrapper', {
652617
active: index === selectedSessionIndex,
@@ -696,9 +661,9 @@ export class Playground extends React.PureComponent<Props & DocsState, State> {
696661
serviceInformation={this.state.serviceInformation}
697662
tracingSupported={Boolean(this.state.tracingSupported)}
698663
/>
699-
</div>
664+
</GraphiqlWrapper>
700665
))}
701-
</div>
666+
</GraphiqlsContainer>
702667
<Settings
703668
onToggleTheme={this.toggleTheme}
704669
localTheme={this.state.theme}
@@ -753,7 +718,7 @@ export class Playground extends React.PureComponent<Props & DocsState, State> {
753718
this.renderUserPopup()}
754719
{this.state.codeGenerationPopupOpen &&
755720
this.renderCodeGenerationPopup()}
756-
</div>
721+
</PlaygroundWrapper>
757722
</OldThemeProvider>
758723
</ThemeProvider>
759724
)
@@ -1685,3 +1650,40 @@ function isSharingAuthorization(sharableSessions: Session[]): boolean {
16851650

16861651
return false
16871652
}
1653+
1654+
const PlaygroundWrapper = styled.div`
1655+
display: flex;
1656+
flex-direction: column;
1657+
1658+
height: 100%;
1659+
margin: 0;
1660+
padding: 0;
1661+
overflow: hidden;
1662+
margin-right: -1px !important;
1663+
1664+
line-height: 1.5;
1665+
font-family: 'Open Sans', sans-serif;
1666+
-webkit-font-smoothing: antialiased;
1667+
-moz-osx-font-smoothing: grayscale;
1668+
letter-spacing: 0.53px;
1669+
color: rgba(0, 0, 0, 0.8);
1670+
1671+
a:active,
1672+
a:focus,
1673+
button:focus,
1674+
input:focus {
1675+
outline: none;
1676+
}
1677+
`
1678+
1679+
const GraphiqlsContainer = styled.div`
1680+
height: calc(100vh - 57px);
1681+
position: relative;
1682+
overflow: hidden;
1683+
`
1684+
1685+
const GraphiqlWrapper = styled.div`
1686+
width: 100%;
1687+
height: 100%;
1688+
position: relative;
1689+
`

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import * as React from 'react'
1010
import * as cx from 'classnames'
11-
import { withTheme, ThemeInterface } from '../Theme'
11+
import { withTheme, LocalThemeInterface } from '../Theme'
1212
import * as cn from 'classnames'
1313
import ExecuteButtonOperation from './ExecuteButtonOperation'
1414

@@ -32,7 +32,10 @@ let firstTime = true
3232
* What a nice round shiny button. Shows a drop-down when there are multiple
3333
* queries to run.
3434
*/
35-
class ExecuteButton extends React.Component<Props & ThemeInterface, State> {
35+
class ExecuteButton extends React.Component<
36+
Props & LocalThemeInterface,
37+
State
38+
> {
3639
constructor(props) {
3740
super(props)
3841

packages/graphql-playground/src/components/Playground/TabBar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import * as React from 'react'
22
import * as cx from 'classnames'
33
import { Session } from '../../types'
44
import { Icon } from 'graphcool-styles'
5-
import { withTheme, OptionalThemeInterface } from '../Theme'
5+
import { withTheme, OptionalLocalThemeInterface } from '../Theme'
66
import Tab from './Tab'
77

8-
export interface Props extends OptionalThemeInterface {
8+
export interface Props extends OptionalLocalThemeInterface {
99
sessions: Session[]
1010
selectedSessionIndex: number
1111
onNewSession: any

packages/graphql-playground/src/components/Popup.tsx

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react'
22
import * as Modal from 'react-modal'
3+
import styled from '../styled'
34

45
export interface Props {
56
onRequestClose: () => void
@@ -53,25 +54,10 @@ export default class Popup extends React.Component<Props, {}> {
5354
style={modalStyle}
5455
contentLabel="Popup"
5556
>
56-
<style jsx={true}>{`
57-
.modal {
58-
@p: .br2;
59-
}
60-
.close {
61-
@p: .absolute, .pointer, .pa10;
62-
top: -25px;
63-
right: -25px;
64-
transform: translate(100%, -100%);
65-
}
66-
.close.inside {
67-
@p: .top0, .right0, .pa25;
68-
transform: none;
69-
}
70-
`}</style>
71-
<div className="modal">
72-
{this.props.children}
73-
</div>
57+
<ContentWrapper>{this.props.children}</ContentWrapper>
7458
</Modal>
7559
)
7660
}
7761
}
62+
63+
const ContentWrapper = styled.div``

0 commit comments

Comments
 (0)