Skip to content

Commit

Permalink
Style/lint components (#213)
Browse files Browse the repository at this point in the history
* style: Lint Map Component

* style: Lint TimePicker component

* style: Lint Utilities folder

* style: Lint rest of src
  • Loading branch information
willb335 authored and prehnRA committed May 1, 2018
1 parent 733d66b commit 63b53a5
Show file tree
Hide file tree
Showing 20 changed files with 157 additions and 94 deletions.
4 changes: 2 additions & 2 deletions .eslintrc
Expand Up @@ -103,7 +103,7 @@
"no-octal-escape": 2,
"no-octal": 2,
"no-param-reassign": 0,
"no-process-env": 2,
"no-process-env": 0,
"no-proto": 2,
"no-redeclare": 2,
"no-return-assign": 2,
Expand Down Expand Up @@ -293,7 +293,7 @@
"always"
],
"space-before-function-paren": [
2,
0,
"never"
],
"space-in-parens": [
Expand Down
3 changes: 2 additions & 1 deletion src/Accordion.js
Expand Up @@ -6,6 +6,7 @@ import {omit} from 'lodash'
// Converts string or array of strings to string-to-bool object mapping
// "one" -> {one: true}
// ["one", "two"] -> {one: true, two: true}
/* eslint complexity: [2, 4] */
function activeToObject(active) {
let obj = {}

Expand Down Expand Up @@ -37,7 +38,7 @@ class AccordionItem extends Component {
className: PropTypes.string,
children: PropTypes.node,
}

/* eslint complexity: [2, 5] */
render() {
const {
children,
Expand Down
2 changes: 1 addition & 1 deletion src/BrowserSupportWarning.js
Expand Up @@ -10,7 +10,7 @@ export default class BrowserSupportWarning extends Component {
className: PropTypes.string,
children: PropTypes.node,
}

/* eslint complexity: [2, 5] */
checkIsSupported = () => {
const {minVersions} = this.props
const userAgent =
Expand Down
2 changes: 1 addition & 1 deletion src/Button.js
Expand Up @@ -29,7 +29,7 @@ export default class Button extends Component {
className: PropTypes.string,
children: PropTypes.node,
}

/* eslint complexity: [2, 4] */
render() {
// Extract props that will not pass through.
const {className, children, tag, icon, ...props} = this.props
Expand Down
2 changes: 1 addition & 1 deletion src/Checkbox.js
Expand Up @@ -94,7 +94,7 @@ class CheckboxFieldset extends Component {

valueArray.forEach((val) => (valueLookup[val] = true))
defaultValueArray.forEach((val) => (defaultValueLookup[val] = true))

/* eslint complexity: [2, 4] */
const checkboxes = options.map((option) => {
const props = {
name,
Expand Down
2 changes: 1 addition & 1 deletion src/Form.js
Expand Up @@ -18,7 +18,7 @@ export default class Form extends Component {
methodOverrideInputName: '_method',
method: 'post',
}

/* eslint complexity: [2, 4] */
render() {
const {
className,
Expand Down
7 changes: 4 additions & 3 deletions src/Loader.js
@@ -1,7 +1,8 @@
import React, { Component } from 'react'
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { omit, defaultTo, gt, has, reduce, without } from 'lodash'
import {omit, gt, has, reduce, without} from 'lodash'

/* eslint-disable no-unused-vars */
const PROP_TYPES = {
borderWidth: PropTypes.string,
children: PropTypes.element,
Expand All @@ -12,7 +13,7 @@ const PROP_TYPES = {
medium: PropTypes.bool,
secondaryColor: PropTypes.string,
size: PropTypes.string,
small: PropTypes.bool
small: PropTypes.bool,
}

/*
Expand Down
1 change: 1 addition & 0 deletions src/Map/InfoWindow.js
Expand Up @@ -2,6 +2,7 @@ import {Component} from 'react'
import PropTypes from 'prop-types'

export default class InfoWindow extends Component {
/* eslint complexity: [2, 5] */
componentDidUpdate(prevProps) {
const {visible, marker, map} = this.props

Expand Down
7 changes: 5 additions & 2 deletions src/Map/MapComponent.js
Expand Up @@ -52,7 +52,10 @@ export default class MapComponent extends Component {

initMap = async () => {
// this is added for the examples pruposes
const apiKey = typeof this.props.apiKey === 'string' ? this.props.apiKey : process.env.GATSBY_apiKey
const apiKey =
typeof this.props.apiKey === 'string'
? this.props.apiKey
: process.env.GATSBY_apiKey

await loadJS(`https://maps.googleapis.com/maps/api/js?key=${apiKey}`)
this.loadMap()
Expand Down Expand Up @@ -154,7 +157,7 @@ export default class MapComponent extends Component {
})
})
}

/* eslint complexity: [2, 4] */
render() {
return (
<div>
Expand Down
3 changes: 2 additions & 1 deletion src/Map/MapComponent.test.js
@@ -1,9 +1,10 @@
import React from 'react'
import MapComponent from './MapComponent'
import {MAP_API_KEY} from './Utilities/config'

describe('MapComponent', () => {
it('should render a map with the appropriate design', () => {
const wrapper = shallow(
shallow(
<MapComponent
apiKey={MAP_API_KEY}
small
Expand Down
4 changes: 2 additions & 2 deletions src/Pagination.js
Expand Up @@ -59,7 +59,7 @@ export default class Pagination extends Component {
href: () => '#',
showFirstLast: true,
}

/* eslint complexity: [2, 4] */
getAttributes() {
const {currentPage, totalPages, maxViewPages} = this.props
const attributes = {beginArrows: false, endArrows: false}
Expand Down Expand Up @@ -90,7 +90,7 @@ export default class Pagination extends Component {

return attributes
}

/* eslint complexity: [2, 7] */
getArrowClass(relevant, samePage) {
const {hideArrows} = this.props

Expand Down
2 changes: 1 addition & 1 deletion src/Radio.js
Expand Up @@ -63,7 +63,7 @@ class RadioFieldset extends Component {

const isControlled = !!value
const hasDefault = !!defaultValue

/* eslint complexity: [2, 4] */
const radios = options.map((option) => {
const props = {
name,
Expand Down
110 changes: 71 additions & 39 deletions src/Sticky.js
@@ -1,6 +1,7 @@
import React, {cloneElement, Component, Children} from 'react'
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import classNames from 'classnames'

/* eslint complexity: [2, 4] */
const StickyContent = ({
children,
className,
Expand All @@ -10,13 +11,14 @@ const StickyContent = ({
setRef,
...props
}) => {
/* eslint-disable no-nested-ternary */
const stickyClass = isStuck
? stickToBottom
? 'rev-Sticky-content--stuck-bottom'
: 'rev-Sticky-content--stuck-top'
: isAnchored
? 'rev-Sticky-content--anchored'
: ''
? stickToBottom
? 'rev-Sticky-content--stuck-bottom'
: 'rev-Sticky-content--stuck-top'
: isAnchored
? 'rev-Sticky-content--anchored'
: ''
const itemClassName = classNames(className, 'rev-Sticky-content', stickyClass)

return (
Expand All @@ -26,7 +28,27 @@ const StickyContent = ({
)
}

StickyContent.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
isStuck: PropTypes.bool,
isAnchored: PropTypes.bool,
stickToBottom: PropTypes.bool,
setRef: PropTypes.func,
}

class Sticky extends Component {
static propTypes = {
className: PropTypes.string,
children: PropTypes.node,
contentClassName: PropTypes.string,
isStuck: PropTypes.bool,
isAnchored: PropTypes.bool,
stickToBottom: PropTypes.bool,
setRef: PropTypes.func,
setContentRef: PropTypes.func,
}

render() {
const {
children,
Expand Down Expand Up @@ -59,23 +81,30 @@ class Sticky extends Component {
}

class StatefulSticky extends Component {
static propTypes = {
isOpen: PropTypes.bool,
onBackgroundClick: PropTypes.func,
className: PropTypes.string,
children: PropTypes.node,
stickToBottom: PropTypes.bool,
offset: PropTypes.bool,
}

constructor(props) {
super(props)
this.state = {
isStuck: false,
isAnchored: false
isAnchored: false,
}
}

setContainerRef(container) {
this.stickyContainer = container
}

setContentRef(content) {
this.stickyContent = content
componentDidMount() {
window.addEventListener('scroll', this.setContentState.bind(this))
}

/* eslint complexity: [2, 8] */
setContentState() {
/* eslint-disable no-unused-vars */
const contentTop = this.stickyContent.getBoundingClientRect().top
const contentBottom = this.stickyContent.getBoundingClientRect().bottom

Expand All @@ -86,63 +115,66 @@ class StatefulSticky extends Component {

if (this.props.stickToBottom) {
stickyStart = this.props.offset
? containerBottom - this.parsePxValue(this.props.offset)
- window.innerHeight
: containerBottom - window.innerHeight
stickyStop = containerTop + this.stickyContent.offsetHeight - window.innerHeight
? containerBottom -
this.parsePxValue(this.props.offset) -
window.innerHeight
: containerBottom - window.innerHeight
stickyStop =
containerTop + this.stickyContent.offsetHeight - window.innerHeight
stickyFlag = stickyStart >= 0 && stickyStop <= 0
anchorFlag = stickyStart <= 0
} else {
stickyStart = this.props.offset
? containerTop + this.parsePxValue(this.props.offset)
: containerTop
? containerTop + this.parsePxValue(this.props.offset)
: containerTop
stickyStop = containerBottom - this.stickyContent.offsetHeight
stickyFlag = stickyStart <= 0 && stickyStop >= 0
stickyFlag = stickyStart <= 0 && stickyStop >= 0
anchorFlag = stickyStop <= 0
}

if (stickyFlag) {
const sideBorders = this.parsePxValue(this.stickyContainer.style.borderRightWidth)
+ this.parsePxValue(this.stickyContainer.style.borderLeftWidth)
const sideBorders =
this.parsePxValue(this.stickyContainer.style.borderRightWidth) +
this.parsePxValue(this.stickyContainer.style.borderLeftWidth)

// this is to force the fixed div holding the sticky content
// to not break out of the sticky container since fixed
// positioning breaks elements out of document flow
this.stickyContent.style.width = (this.stickyContainer.offsetWidth - sideBorders).toString() + 'px'
this.stickyContent.style.width = `${(
this.stickyContainer.offsetWidth - sideBorders
).toString()}px`

this.setState({
isStuck: true,
isAnchored: false
isAnchored: false,
})
} else if (anchorFlag) {
this.setState({
isStuck: false,
isAnchored: true
isAnchored: true,
})
} else {
this.setState({
isStuck: false,
isAnchored: false
isAnchored: false,
})
}
}

componentDidMount() {
window.addEventListener('scroll', this.setContentState.bind(this))
parsePxValue(value) {
return parseInt(value.replace('px', ''), 10)
}

parsePxValue(value) {
return parseInt(value.replace('px', ''))
setContainerRef(container) {
this.stickyContainer = container
}

setContentRef(content) {
this.stickyContent = content
}

render() {
const {
children,
className,
offset,
stickToBottom,
...props
} = this.props
const {children, className, offset, stickToBottom, ...props} = this.props

return (
<Sticky
Expand Down

0 comments on commit 63b53a5

Please sign in to comment.