Skip to content

Commit 9b0d002

Browse files
tomdegoedemattyb678
authored andcommitted
improvement: Move inline styles to SCSS instead (swagger-api#5578)
* fix: convert propStyle to propClass
1 parent c75e4d4 commit 9b0d002

30 files changed

+282
-70
lines changed

src/core/components/array-model.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { Component } from "react"
22
import PropTypes from "prop-types"
33
import ImPropTypes from "react-immutable-proptypes"
44

5-
const propStyle = { color: "#999", fontStyle: "italic" }
5+
const propClass = "property"
66

77
export default class ArrayModel extends Component {
88
static propTypes = {
@@ -44,7 +44,7 @@ export default class ArrayModel extends Component {
4444
<ModelCollapse title={titleEl} expanded={ depth <= expandDepth } collapsedContent="[...]">
4545
[
4646
{
47-
properties.size ? properties.entrySeq().map( ( [ key, v ] ) => <Property key={`${key}-${v}`} propKey={ key } propVal={ v } propStyle={ propStyle } />) : null
47+
properties.size ? properties.entrySeq().map( ( [ key, v ] ) => <Property key={`${key}-${v}`} propKey={ key } propVal={ v } propClass={ propClass } />) : null
4848
}
4949
{
5050
!description ? (properties.size ? <div className="markdown"></div> : null) :

src/core/components/auth/error.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export default class AuthError extends React.Component {
1515
let source = error.get("source")
1616

1717
return (
18-
<div className="errors" style={{ backgroundColor: "#ffeeee", color: "red", margin: "1em" }}>
19-
<b style={{ textTransform: "capitalize", marginRight: "1em"}} >{ source } { level }</b>
18+
<div className="errors">
19+
<b>{ source } { level }</b>
2020
<span>{ message }</span>
2121
</div>
2222
)

src/core/components/curl.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default class Curl extends React.Component {
2020
<div>
2121
<h4>Curl</h4>
2222
<div className="copy-paste">
23-
<textarea onFocus={this.handleFocus} readOnly={true} className="curl" style={{ whiteSpace: "normal" }} value={curl}></textarea>
23+
<textarea onFocus={this.handleFocus} readOnly={true} className="curl" value={curl}></textarea>
2424
</div>
2525
</div>
2626
)

src/core/components/errors.jsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ const ThrownErrorItem = ( { error, jumpToLine } ) => {
7272
<h4>{ (error.get("source") && error.get("level")) ?
7373
toTitleCase(error.get("source")) + " " + error.get("level") : "" }
7474
{ error.get("path") ? <small> at {error.get("path")}</small>: null }</h4>
75-
<span style={{ whiteSpace: "pre-line", "maxWidth": "100%" }}>
75+
<span className="message thrown">
7676
{ error.get("message") }
7777
</span>
78-
<div style={{ "text-decoration": "underline", "cursor": "pointer" }}>
78+
<div className="error-line">
7979
{ errorLine && jumpToLine ? <a onClick={jumpToLine.bind(null, errorLine)}>Jump to line { errorLine }</a> : null }
8080
</div>
8181
</div>
@@ -102,8 +102,8 @@ const SpecErrorItem = ( { error, jumpToLine } ) => {
102102
{ !error ? null :
103103
<div>
104104
<h4>{ toTitleCase(error.get("source")) + " " + error.get("level") }&nbsp;{ locationMessage }</h4>
105-
<span style={{ whiteSpace: "pre-line"}}>{ error.get("message") }</span>
106-
<div style={{ "text-decoration": "underline", "cursor": "pointer" }}>
105+
<span className="message">{ error.get("message") }</span>
106+
<div className="error-line">
107107
{ jumpToLine ? (
108108
<a onClick={jumpToLine.bind(null, error.get("line"))}>Jump to line { error.get("line") }</a>
109109
) : null }

src/core/components/headers.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from "react"
22
import PropTypes from "prop-types"
33
import Im from "immutable"
44

5-
const propStyle = { color: "#999", fontStyle: "italic" }
5+
const propClass = "header-example"
66

77
export default class Headers extends React.Component {
88
static propTypes = {
@@ -46,7 +46,7 @@ export default class Headers extends React.Component {
4646
<td className="header-col">{
4747
!description ? null : <Markdown source={ description } />
4848
}</td>
49-
<td className="header-col">{ type } { schemaExample ? <Property propKey={ "Example" } propVal={ schemaExample } propStyle={ propStyle } /> : null }</td>
49+
<td className="header-col">{ type } { schemaExample ? <Property propKey={ "Example" } propVal={ schemaExample } propClass={ propClass } /> : null }</td>
5050
</tr>)
5151
}).toArray()
5252
}

src/core/components/layout-utils.jsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,14 @@ export class Col extends React.Component {
7373
}
7474
}
7575

76+
if (hide) {
77+
classesAr.push("hidden")
78+
}
79+
7680
let classes = xclass(rest.className, ...classesAr)
7781

7882
return (
79-
<section {...rest} style={{display: hide ? "none": null}} className={classes}/>
83+
<section {...rest} className={classes}/>
8084
)
8185
}
8286

@@ -213,7 +217,7 @@ Link.propTypes = {
213217
className: PropTypes.string
214218
}
215219

216-
const NoMargin = ({children}) => <div style={{height: "auto", border: "none", margin: 0, padding: 0}}> {children} </div>
220+
const NoMargin = ({children}) => <div className="no-margin"> {children} </div>
217221

218222
NoMargin.propTypes = {
219223
children: PropTypes.node

src/core/components/layouts/base.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default class BaseLayout extends React.Component {
5757
if (loadingStatus === "failedConfig") {
5858
const lastErr = errSelectors.lastError()
5959
const lastErrMsg = lastErr ? lastErr.get("message") : ""
60-
loadingMessage = <div className="info" style={{ maxWidth: "880px", marginLeft: "auto", marginRight: "auto", textAlign: "center" }}>
60+
loadingMessage = <div className="info failed-config">
6161
<div className="loading-container">
6262
<h4 className="title">Failed to load remote configuration.</h4>
6363
<p>{lastErrMsg}</p>

src/core/components/model-collapse.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ export default class ModelCollapse extends Component {
7171

7272
return (
7373
<span className={classes || ""}>
74-
{ title && <span onClick={this.toggleCollapsed} style={{ "cursor": "pointer" }}>{title}</span> }
75-
<span onClick={ this.toggleCollapsed } style={{ "cursor": "pointer" }}>
74+
{ title && <span onClick={this.toggleCollapsed} className="pointer">{title}</span> }
75+
<span onClick={ this.toggleCollapsed } className="pointer">
7676
<span className={ "model-toggle" + ( this.state.expanded ? "" : " collapsed" ) }></span>
7777
</span>
7878
{ this.state.expanded ? this.props.children :this.state.collapsedContent }

src/core/components/model.jsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,7 @@ export default class Model extends ImmutablePureComponent {
5353
if(!schema) {
5454
return <span className="model model-title">
5555
<span className="model-title__text">{ displayName || name }</span>
56-
<img src={require("core/../img/rolling-load.svg")} height={"20px"} width={"20px"} style={{
57-
marginLeft: "1em",
58-
position: "relative",
59-
bottom: "0px"
60-
}} />
56+
<img src={require("core/../img/rolling-load.svg")} height={"20px"} width={"20px"} />
6157
</span>
6258
}
6359

src/core/components/object-model.jsx

+17-11
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ export default class ObjectModel extends Component {
7979
{
8080
<table className="model"><tbody>
8181
{
82-
!description ? null : <tr style={{ color: "#666", fontWeight: "normal" }}>
83-
<td style={{ fontWeight: "bold" }}>description:</td>
82+
!description ? null : <tr className="description">
83+
<td>description:</td>
8484
<td>
8585
<Markdown source={ description } />
8686
</td>
@@ -91,16 +91,22 @@ export default class ObjectModel extends Component {
9191
([key, value]) => {
9292
let isDeprecated = isOAS3() && value.get("deprecated")
9393
let isRequired = List.isList(requiredProperties) && requiredProperties.contains(key)
94-
let propertyStyle = { verticalAlign: "top", paddingRight: "0.2em" }
95-
if ( isRequired ) {
96-
propertyStyle.fontWeight = "bold"
94+
95+
let classNames = ["property-row"]
96+
97+
if (isDeprecated) {
98+
classNames.push("deprecated")
99+
}
100+
101+
if (isRequired) {
102+
classNames.push("required")
97103
}
98104

99-
return (<tr key={key} className={isDeprecated && "deprecated"}>
100-
<td style={ propertyStyle }>
101-
{ key }{ isRequired && <span style={{ color: "red" }}>*</span> }
105+
return (<tr key={key} className={classNames.join(" ")}>
106+
<td>
107+
{ key }{ isRequired && <span className="star">*</span> }
102108
</td>
103-
<td style={{ verticalAlign: "top" }}>
109+
<td>
104110
<Model key={ `object-${name}-${key}_${value}` } { ...otherProps }
105111
required={ isRequired }
106112
getComponent={ getComponent }
@@ -126,11 +132,11 @@ export default class ObjectModel extends Component {
126132

127133
const normalizedValue = !value ? null : value.toJS ? value.toJS() : value
128134

129-
return (<tr key={key} style={{ color: "#777" }}>
135+
return (<tr key={key} className="extension">
130136
<td>
131137
{ key }
132138
</td>
133-
<td style={{ verticalAlign: "top" }}>
139+
<td>
134140
{ JSON.stringify(normalizedValue) }
135141
</td>
136142
</tr>)

src/core/components/online-validator-badge.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default class OnlineValidatorBadge extends React.Component {
5353
return null
5454
}
5555

56-
return (<span style={{ float: "right"}}>
56+
return (<span className="float-right">
5757
<a target="_blank" rel="noopener noreferrer" href={`${ sanitizedValidatorUrl }/debug?url=${ encodeURIComponent(this.state.url) }`}>
5858
<ValidatorImage src={`${ sanitizedValidatorUrl }?url=${ encodeURIComponent(this.state.url) }`} alt="Online validator badge"/>
5959
</a>

src/core/components/overview.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export class OperationLink extends React.Component {
9797
let { id, method, shown, href } = this.props
9898

9999
return (
100-
<Link href={ href } style={{fontWeight: shown ? "bold" : "normal"}} onClick={this.onClick} className="block opblock-link">
100+
<Link href={ href } onClick={this.onClick} className={`block opblock-link ${shown ? "shown" : ""}`}>
101101
<div>
102102
<small className={`bold-label-${method}`}>{method.toUpperCase()}</small>
103103
<span className="bold-label" >{id}</span>

src/core/components/parameter-row.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ export default class ParameterRow extends Component {
262262
<td className="parameters-col_name">
263263
<div className={required ? "parameter__name required" : "parameter__name"}>
264264
{ param.get("name") }
265-
{ !required ? null : <span style={{color: "red"}}>&nbsp;*</span> }
265+
{ !required ? null : <span>&nbsp;*</span> }
266266
</div>
267267
<div className="parameter__type">
268268
{ type }

src/core/components/primitive-model.jsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { Component } from "react"
22
import PropTypes from "prop-types"
33
import { getExtensions } from "core/utils"
44

5-
const propStyle = { color: "#6b6b6b", fontStyle: "italic" }
5+
const propClass = "property primitive"
66

77
export default class Primitive extends Component {
88
static propTypes = {
@@ -44,19 +44,19 @@ export default class Primitive extends Component {
4444
<span className="prop-type">{ type }</span>
4545
{ format && <span className="prop-format">(${format})</span>}
4646
{
47-
properties.size ? properties.entrySeq().map( ( [ key, v ] ) => <Property key={`${key}-${v}`} propKey={ key } propVal={ v } propStyle={ propStyle } />) : null
47+
properties.size ? properties.entrySeq().map( ( [ key, v ] ) => <Property key={`${key}-${v}`} propKey={ key } propVal={ v } propClass={ propClass } />) : null
4848
}
4949
{
50-
showExtensions && extensions.size ? extensions.entrySeq().map( ( [ key, v ] ) => <Property key={`${key}-${v}`} propKey={ key } propVal={ v } propStyle={ propStyle } />) : null
50+
showExtensions && extensions.size ? extensions.entrySeq().map( ( [ key, v ] ) => <Property key={`${key}-${v}`} propKey={ key } propVal={ v } propClass={ propClass } />) : null
5151
}
5252
{
5353
!description ? null :
5454
<Markdown source={ description } />
5555
}
5656
{
57-
xml && xml.size ? (<span><br /><span style={ propStyle }>xml:</span>
57+
xml && xml.size ? (<span><br /><span className={ propClass }>xml:</span>
5858
{
59-
xml.entrySeq().map( ( [ key, v ] ) => <span key={`${key}-${v}`} style={ propStyle }><br/>&nbsp;&nbsp;&nbsp;{key}: { String(v) }</span>).toArray()
59+
xml.entrySeq().map( ( [ key, v ] ) => <span key={`${key}-${v}`} className={ propClass }><br/>&nbsp;&nbsp;&nbsp;{key}: { String(v) }</span>).toArray()
6060
}
6161
</span>): null
6262
}

src/core/components/property.jsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import React from "react"
22
import PropTypes from "prop-types"
33

4-
export const Property = ({ propKey, propVal, propStyle }) => {
4+
export const Property = ({ propKey, propVal, propClass }) => {
55
return (
6-
<span style={ propStyle }>
6+
<span className={ propClass }>
77
<br />{ propKey }: { String(propVal) }</span>
88
)
99
}
1010
Property.propTypes = {
1111
propKey: PropTypes.string,
1212
propVal: PropTypes.any,
13-
propStyle: PropTypes.object
13+
propClass: PropTypes.string
1414
}
1515

1616
export default Property

src/core/components/response-body.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export default class ResponseBody extends React.PureComponent {
118118
if(contentType.includes("svg")) {
119119
bodyEl = <div> { content } </div>
120120
} else {
121-
bodyEl = <img style={{ maxWidth: "100%" }} src={ window.URL.createObjectURL(content) } />
121+
bodyEl = <img className="full-width" src={ window.URL.createObjectURL(content) } />
122122
}
123123

124124
// Audio

src/core/components/svg-assets.jsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import React from "react"
22
const SvgAssets = () =>
33
<div>
4-
<svg xmlns="http://www.w3.org/2000/svg" xmlnsXlink="http://www.w3.org/1999/xlink" style={{
5-
position: "absolute",
6-
width: 0,
7-
height: 0
8-
}}>
4+
<svg xmlns="http://www.w3.org/2000/svg" xmlnsXlink="http://www.w3.org/1999/xlink" className="svg-assets">
95
<defs>
106
<symbol viewBox="0 0 20 20" id="unlocked">
117
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V6h2v-.801C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8z"></path>

src/core/containers/filter.jsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ export default class FilterContainer extends React.Component {
2323
const isFailed = specSelectors.loadingStatus() === "failed"
2424
const filter = layoutSelectors.currentFilter()
2525

26-
const inputStyle = {}
27-
if (isFailed) inputStyle.color = "red"
28-
if (isLoading) inputStyle.color = "#aaa"
26+
const classNames = ["operation-filter-input"]
27+
if (isFailed) classNames.push("failed")
28+
if (isLoading) classNames.push("loading")
2929

3030
return (
3131
<div>
3232
{filter === null || filter === false ? null :
3333
<div className="filter-container">
3434
<Col className="filter wrapper" mobile={12}>
35-
<input className="operation-filter-input" placeholder="Filter by tag" type="text"
35+
<input className={classNames.join(" ")} placeholder="Filter by tag" type="text"
3636
onChange={this.onFilterChange} value={filter === true || filter === "true" ? "" : filter}
37-
disabled={isLoading} style={inputStyle}/>
37+
disabled={isLoading}/>
3838
</Col>
3939
</div>
4040
}

src/core/plugins/oas3/components/operation-link.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class OperationLink extends Component {
1212
let parameters = link.get("parameters") && link.get("parameters").toJS()
1313
let description = link.get("description")
1414

15-
return <div style={{ marginBottom: "1.5em" }}>
16-
<div style={{ marginBottom: ".5em" }}>
15+
return <div className="operation-link">
16+
<div className="description">
1717
<b><code>{name}</code></b>
1818
{ description ? <Markdown source={description}></Markdown> : null }
1919
</div>

src/core/plugins/oas3/components/request-body.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ const RequestBody = ({
145145
<td className="parameters-col_name">
146146
<div className={required ? "parameter__name required" : "parameter__name"}>
147147
{ key }
148-
{ !required ? null : <span style={{color: "red"}}>&nbsp;*</span> }
148+
{ !required ? null : <span>&nbsp;*</span> }
149149
</div>
150150
<div className="parameter__type">
151151
{ type }

src/core/plugins/oas3/wrap-components/version-stamp.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default OAS3ComponentWrapFactory((props) => {
66

77
return <span>
88
<Ori {...props} />
9-
<small style={{ backgroundColor: "#89bf04" }}>
9+
<small className="version-stamp">
1010
<pre className="version">OAS3</pre>
1111
</small>
1212
</span>

src/core/plugins/view/root-injects.jsx

+3-4
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,9 @@ const createClass = component => class extends Component {
7676
}
7777
}
7878

79-
const Fallback = ({ name }) => <div style={{ // eslint-disable-line react/prop-types
80-
padding: "1em",
81-
"color": "#aaa"
82-
}}>😱 <i>Could not render { name === "t" ? "this component" : name }, see the console.</i></div>
79+
const Fallback = ({
80+
name // eslint-disable-line react/prop-types
81+
}) => <div className="fallback">😱 <i>Could not render { name === "t" ? "this component" : name }, see the console.</i></div>
8382

8483
const wrapRender = (component) => {
8584
const isStateless = component => !(component.prototype && component.prototype.isReactComponent)

src/core/utils.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -307,15 +307,15 @@ export function highlight (el) {
307307
// (some types are highlighted similarly)
308308
el[appendChild](
309309
node = _document.createElement("span")
310-
).setAttribute("style", [
310+
).setAttribute("class", [
311311
// 0: not formatted
312-
"color: #555; font-weight: bold;",
312+
"token-not-formatted",
313313
// 1: keywords
314314
"",
315315
// 2: punctuation
316316
"",
317317
// 3: strings and regexps
318-
"color: #555;",
318+
"token-string",
319319
// 4: comments
320320
""
321321
][

0 commit comments

Comments
 (0)