Skip to content

Commit

Permalink
improvement: Move inline styles to SCSS instead (#5578)
Browse files Browse the repository at this point in the history
* fix: convert propStyle to propClass
  • Loading branch information
tomdegoede authored Jun 10, 2020
1 parent 67627d7 commit fc3ed30
Show file tree
Hide file tree
Showing 30 changed files with 282 additions and 70 deletions.
4 changes: 2 additions & 2 deletions src/core/components/array-model.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { Component } from "react"
import PropTypes from "prop-types"
import ImPropTypes from "react-immutable-proptypes"

const propStyle = { color: "#999", fontStyle: "italic" }
const propClass = "property"

export default class ArrayModel extends Component {
static propTypes = {
Expand Down Expand Up @@ -44,7 +44,7 @@ export default class ArrayModel extends Component {
<ModelCollapse title={titleEl} expanded={ depth <= expandDepth } collapsedContent="[...]">
[
{
properties.size ? properties.entrySeq().map( ( [ key, v ] ) => <Property key={`${key}-${v}`} propKey={ key } propVal={ v } propStyle={ propStyle } />) : null
properties.size ? properties.entrySeq().map( ( [ key, v ] ) => <Property key={`${key}-${v}`} propKey={ key } propVal={ v } propClass={ propClass } />) : null
}
{
!description ? (properties.size ? <div className="markdown"></div> : null) :
Expand Down
4 changes: 2 additions & 2 deletions src/core/components/auth/error.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export default class AuthError extends React.Component {
let source = error.get("source")

return (
<div className="errors" style={{ backgroundColor: "#ffeeee", color: "red", margin: "1em" }}>
<b style={{ textTransform: "capitalize", marginRight: "1em"}} >{ source } { level }</b>
<div className="errors">
<b>{ source } { level }</b>
<span>{ message }</span>
</div>
)
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/curl.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class Curl extends React.Component {
<div>
<h4>Curl</h4>
<div className="copy-paste">
<textarea onFocus={this.handleFocus} readOnly={true} className="curl" style={{ whiteSpace: "normal" }} value={curl}></textarea>
<textarea onFocus={this.handleFocus} readOnly={true} className="curl" value={curl}></textarea>
</div>
</div>
)
Expand Down
8 changes: 4 additions & 4 deletions src/core/components/errors.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ const ThrownErrorItem = ( { error, jumpToLine } ) => {
<h4>{ (error.get("source") && error.get("level")) ?
toTitleCase(error.get("source")) + " " + error.get("level") : "" }
{ error.get("path") ? <small> at {error.get("path")}</small>: null }</h4>
<span style={{ whiteSpace: "pre-line", "maxWidth": "100%" }}>
<span className="message thrown">
{ error.get("message") }
</span>
<div style={{ "text-decoration": "underline", "cursor": "pointer" }}>
<div className="error-line">
{ errorLine && jumpToLine ? <a onClick={jumpToLine.bind(null, errorLine)}>Jump to line { errorLine }</a> : null }
</div>
</div>
Expand All @@ -102,8 +102,8 @@ const SpecErrorItem = ( { error, jumpToLine } ) => {
{ !error ? null :
<div>
<h4>{ toTitleCase(error.get("source")) + " " + error.get("level") }&nbsp;{ locationMessage }</h4>
<span style={{ whiteSpace: "pre-line"}}>{ error.get("message") }</span>
<div style={{ "text-decoration": "underline", "cursor": "pointer" }}>
<span className="message">{ error.get("message") }</span>
<div className="error-line">
{ jumpToLine ? (
<a onClick={jumpToLine.bind(null, error.get("line"))}>Jump to line { error.get("line") }</a>
) : null }
Expand Down
4 changes: 2 additions & 2 deletions src/core/components/headers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react"
import PropTypes from "prop-types"
import Im from "immutable"

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

export default class Headers extends React.Component {
static propTypes = {
Expand Down Expand Up @@ -46,7 +46,7 @@ export default class Headers extends React.Component {
<td className="header-col">{
!description ? null : <Markdown source={ description } />
}</td>
<td className="header-col">{ type } { schemaExample ? <Property propKey={ "Example" } propVal={ schemaExample } propStyle={ propStyle } /> : null }</td>
<td className="header-col">{ type } { schemaExample ? <Property propKey={ "Example" } propVal={ schemaExample } propClass={ propClass } /> : null }</td>
</tr>)
}).toArray()
}
Expand Down
8 changes: 6 additions & 2 deletions src/core/components/layout-utils.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,14 @@ export class Col extends React.Component {
}
}

if (hide) {
classesAr.push("hidden")
}

let classes = xclass(rest.className, ...classesAr)

return (
<section {...rest} style={{display: hide ? "none": null}} className={classes}/>
<section {...rest} className={classes}/>
)
}

Expand Down Expand Up @@ -213,7 +217,7 @@ Link.propTypes = {
className: PropTypes.string
}

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

NoMargin.propTypes = {
children: PropTypes.node
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/layouts/base.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default class BaseLayout extends React.Component {
if (loadingStatus === "failedConfig") {
const lastErr = errSelectors.lastError()
const lastErrMsg = lastErr ? lastErr.get("message") : ""
loadingMessage = <div className="info" style={{ maxWidth: "880px", marginLeft: "auto", marginRight: "auto", textAlign: "center" }}>
loadingMessage = <div className="info failed-config">
<div className="loading-container">
<h4 className="title">Failed to load remote configuration.</h4>
<p>{lastErrMsg}</p>
Expand Down
4 changes: 2 additions & 2 deletions src/core/components/model-collapse.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ export default class ModelCollapse extends Component {

return (
<span className={classes || ""}>
{ title && <span onClick={this.toggleCollapsed} style={{ "cursor": "pointer" }}>{title}</span> }
<span onClick={ this.toggleCollapsed } style={{ "cursor": "pointer" }}>
{ title && <span onClick={this.toggleCollapsed} className="pointer">{title}</span> }
<span onClick={ this.toggleCollapsed } className="pointer">
<span className={ "model-toggle" + ( this.state.expanded ? "" : " collapsed" ) }></span>
</span>
{ this.state.expanded ? this.props.children :this.state.collapsedContent }
Expand Down
6 changes: 1 addition & 5 deletions src/core/components/model.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ export default class Model extends ImmutablePureComponent {
if(!schema) {
return <span className="model model-title">
<span className="model-title__text">{ displayName || name }</span>
<img src={require("core/../img/rolling-load.svg")} height={"20px"} width={"20px"} style={{
marginLeft: "1em",
position: "relative",
bottom: "0px"
}} />
<img src={require("core/../img/rolling-load.svg")} height={"20px"} width={"20px"} />
</span>
}

Expand Down
28 changes: 17 additions & 11 deletions src/core/components/object-model.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ export default class ObjectModel extends Component {
{
<table className="model"><tbody>
{
!description ? null : <tr style={{ color: "#666", fontWeight: "normal" }}>
<td style={{ fontWeight: "bold" }}>description:</td>
!description ? null : <tr className="description">
<td>description:</td>
<td>
<Markdown source={ description } />
</td>
Expand All @@ -91,16 +91,22 @@ export default class ObjectModel extends Component {
([key, value]) => {
let isDeprecated = isOAS3() && value.get("deprecated")
let isRequired = List.isList(requiredProperties) && requiredProperties.contains(key)
let propertyStyle = { verticalAlign: "top", paddingRight: "0.2em" }
if ( isRequired ) {
propertyStyle.fontWeight = "bold"

let classNames = ["property-row"]

if (isDeprecated) {
classNames.push("deprecated")
}

if (isRequired) {
classNames.push("required")
}

return (<tr key={key} className={isDeprecated && "deprecated"}>
<td style={ propertyStyle }>
{ key }{ isRequired && <span style={{ color: "red" }}>*</span> }
return (<tr key={key} className={classNames.join(" ")}>
<td>
{ key }{ isRequired && <span className="star">*</span> }
</td>
<td style={{ verticalAlign: "top" }}>
<td>
<Model key={ `object-${name}-${key}_${value}` } { ...otherProps }
required={ isRequired }
getComponent={ getComponent }
Expand All @@ -126,11 +132,11 @@ export default class ObjectModel extends Component {

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

return (<tr key={key} style={{ color: "#777" }}>
return (<tr key={key} className="extension">
<td>
{ key }
</td>
<td style={{ verticalAlign: "top" }}>
<td>
{ JSON.stringify(normalizedValue) }
</td>
</tr>)
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/online-validator-badge.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default class OnlineValidatorBadge extends React.Component {
return null
}

return (<span style={{ float: "right"}}>
return (<span className="float-right">
<a target="_blank" rel="noopener noreferrer" href={`${ sanitizedValidatorUrl }/debug?url=${ encodeURIComponent(this.state.url) }`}>
<ValidatorImage src={`${ sanitizedValidatorUrl }?url=${ encodeURIComponent(this.state.url) }`} alt="Online validator badge"/>
</a>
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/overview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class OperationLink extends React.Component {
let { id, method, shown, href } = this.props

return (
<Link href={ href } style={{fontWeight: shown ? "bold" : "normal"}} onClick={this.onClick} className="block opblock-link">
<Link href={ href } onClick={this.onClick} className={`block opblock-link ${shown ? "shown" : ""}`}>
<div>
<small className={`bold-label-${method}`}>{method.toUpperCase()}</small>
<span className="bold-label" >{id}</span>
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/parameter-row.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export default class ParameterRow extends Component {
<td className="parameters-col_name">
<div className={required ? "parameter__name required" : "parameter__name"}>
{ param.get("name") }
{ !required ? null : <span style={{color: "red"}}>&nbsp;*</span> }
{ !required ? null : <span>&nbsp;*</span> }
</div>
<div className="parameter__type">
{ type }
Expand Down
10 changes: 5 additions & 5 deletions src/core/components/primitive-model.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { Component } from "react"
import PropTypes from "prop-types"
import { getExtensions } from "core/utils"

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

export default class Primitive extends Component {
static propTypes = {
Expand Down Expand Up @@ -44,19 +44,19 @@ export default class Primitive extends Component {
<span className="prop-type">{ type }</span>
{ format && <span className="prop-format">(${format})</span>}
{
properties.size ? properties.entrySeq().map( ( [ key, v ] ) => <Property key={`${key}-${v}`} propKey={ key } propVal={ v } propStyle={ propStyle } />) : null
properties.size ? properties.entrySeq().map( ( [ key, v ] ) => <Property key={`${key}-${v}`} propKey={ key } propVal={ v } propClass={ propClass } />) : null
}
{
showExtensions && extensions.size ? extensions.entrySeq().map( ( [ key, v ] ) => <Property key={`${key}-${v}`} propKey={ key } propVal={ v } propStyle={ propStyle } />) : null
showExtensions && extensions.size ? extensions.entrySeq().map( ( [ key, v ] ) => <Property key={`${key}-${v}`} propKey={ key } propVal={ v } propClass={ propClass } />) : null
}
{
!description ? null :
<Markdown source={ description } />
}
{
xml && xml.size ? (<span><br /><span style={ propStyle }>xml:</span>
xml && xml.size ? (<span><br /><span className={ propClass }>xml:</span>
{
xml.entrySeq().map( ( [ key, v ] ) => <span key={`${key}-${v}`} style={ propStyle }><br/>&nbsp;&nbsp;&nbsp;{key}: { String(v) }</span>).toArray()
xml.entrySeq().map( ( [ key, v ] ) => <span key={`${key}-${v}`} className={ propClass }><br/>&nbsp;&nbsp;&nbsp;{key}: { String(v) }</span>).toArray()
}
</span>): null
}
Expand Down
6 changes: 3 additions & 3 deletions src/core/components/property.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import React from "react"
import PropTypes from "prop-types"

export const Property = ({ propKey, propVal, propStyle }) => {
export const Property = ({ propKey, propVal, propClass }) => {
return (
<span style={ propStyle }>
<span className={ propClass }>
<br />{ propKey }: { String(propVal) }</span>
)
}
Property.propTypes = {
propKey: PropTypes.string,
propVal: PropTypes.any,
propStyle: PropTypes.object
propClass: PropTypes.string
}

export default Property
2 changes: 1 addition & 1 deletion src/core/components/response-body.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export default class ResponseBody extends React.PureComponent {
if(contentType.includes("svg")) {
bodyEl = <div> { content } </div>
} else {
bodyEl = <img style={{ maxWidth: "100%" }} src={ window.URL.createObjectURL(content) } />
bodyEl = <img className="full-width" src={ window.URL.createObjectURL(content) } />
}

// Audio
Expand Down
6 changes: 1 addition & 5 deletions src/core/components/svg-assets.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import React from "react"
const SvgAssets = () =>
<div>
<svg xmlns="http://www.w3.org/2000/svg" xmlnsXlink="http://www.w3.org/1999/xlink" style={{
position: "absolute",
width: 0,
height: 0
}}>
<svg xmlns="http://www.w3.org/2000/svg" xmlnsXlink="http://www.w3.org/1999/xlink" className="svg-assets">
<defs>
<symbol viewBox="0 0 20 20" id="unlocked">
<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>
Expand Down
10 changes: 5 additions & 5 deletions src/core/containers/filter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ export default class FilterContainer extends React.Component {
const isFailed = specSelectors.loadingStatus() === "failed"
const filter = layoutSelectors.currentFilter()

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

return (
<div>
{filter === null || filter === false ? null :
<div className="filter-container">
<Col className="filter wrapper" mobile={12}>
<input className="operation-filter-input" placeholder="Filter by tag" type="text"
<input className={classNames.join(" ")} placeholder="Filter by tag" type="text"
onChange={this.onFilterChange} value={filter === true || filter === "true" ? "" : filter}
disabled={isLoading} style={inputStyle}/>
disabled={isLoading}/>
</Col>
</div>
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/plugins/oas3/components/operation-link.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class OperationLink extends Component {
let parameters = link.get("parameters") && link.get("parameters").toJS()
let description = link.get("description")

return <div style={{ marginBottom: "1.5em" }}>
<div style={{ marginBottom: ".5em" }}>
return <div className="operation-link">
<div className="description">
<b><code>{name}</code></b>
{ description ? <Markdown source={description}></Markdown> : null }
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/core/plugins/oas3/components/request-body.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const RequestBody = ({
<td className="parameters-col_name">
<div className={required ? "parameter__name required" : "parameter__name"}>
{ key }
{ !required ? null : <span style={{color: "red"}}>&nbsp;*</span> }
{ !required ? null : <span>&nbsp;*</span> }
</div>
<div className="parameter__type">
{ type }
Expand Down
2 changes: 1 addition & 1 deletion src/core/plugins/oas3/wrap-components/version-stamp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default OAS3ComponentWrapFactory((props) => {

return <span>
<Ori {...props} />
<small style={{ backgroundColor: "#89bf04" }}>
<small className="version-stamp">
<pre className="version">OAS3</pre>
</small>
</span>
Expand Down
7 changes: 3 additions & 4 deletions src/core/plugins/view/root-injects.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,9 @@ const createClass = component => class extends Component {
}
}

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

const wrapRender = (component) => {
const isStateless = component => !(component.prototype && component.prototype.isReactComponent)
Expand Down
6 changes: 3 additions & 3 deletions src/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,15 +307,15 @@ export function highlight (el) {
// (some types are highlighted similarly)
el[appendChild](
node = _document.createElement("span")
).setAttribute("style", [
).setAttribute("class", [
// 0: not formatted
"color: #555; font-weight: bold;",
"token-not-formatted",
// 1: keywords
"",
// 2: punctuation
"",
// 3: strings and regexps
"color: #555;",
"token-string",
// 4: comments
""
][
Expand Down
Loading

0 comments on commit fc3ed30

Please sign in to comment.