Skip to content

Commit

Permalink
add prettier and fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
renatorib committed Dec 1, 2017
1 parent 60e3c0e commit db40564
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 61 deletions.
11 changes: 11 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"requirePragma": false,
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"trailingComma": "es5",
"bracketSpacing": true,
"jsxBracketSameLine": false
}
12 changes: 6 additions & 6 deletions .storybook/components/Block.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import React from 'react'

const wrapperStyle = {
paddingBottom: '20px',
};
}

const titleStyle = {
textTransform: 'uppercase',
Expand All @@ -12,17 +12,17 @@ const titleStyle = {
color: '#999',
paddingBottom: '5px',
fontWeight: 'bold',
};
}

const contentStyle = {
border: '1px solid #DDD',
};
}

const Block = ({ children, title }) => (
<div style={wrapperStyle}>
<div style={titleStyle}>{title}</div>
<div style={contentStyle}>{children}</div>
</div>
);
)

export default Block;
export default Block
12 changes: 6 additions & 6 deletions .storybook/components/Code.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react';
import SyntaxHighlighter from 'react-syntax-highlighter';
import { github as theme } from 'react-syntax-highlighter/dist/styles';
import Block from './Block';
import React from 'react'
import SyntaxHighlighter from 'react-syntax-highlighter'
import { github as theme } from 'react-syntax-highlighter/dist/styles'
import Block from './Block'

const Code = ({ children }) => (
<Block title="Code">
<SyntaxHighlighter language="jsx" style={theme} customStyle={{ margin: 0 }}>
{children}
</SyntaxHighlighter>
</Block>
);
)

export default Code;
export default Code
17 changes: 10 additions & 7 deletions .storybook/components/MobileBreakpoint.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import React from 'react';
import withSizes from '../../src/withSizes';
import React from 'react'
import withSizes from '../../src/withSizes'

const MobileBreakpoint = ({ isMobile, breakpoint, width }) => (
<div>
<div>breakpoint: {breakpoint} | width: {width}</div>
<div>
breakpoint: {breakpoint} | width: {width}
</div>
<div>{isMobile ? 'Is Mobile' : 'Is Not Mobile'}</div>
<br /><br />
<br />
<br />
</div>
);
)

const mapSizesToProps = ({ width }, { breakpoint }) => ({
isMobile: width < breakpoint,
width,
});
})

export default withSizes(mapSizesToProps)(MobileBreakpoint);
export default withSizes(mapSizesToProps)(MobileBreakpoint)
12 changes: 4 additions & 8 deletions .storybook/components/Result.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import React from 'react';
import Block from './Block';
import React from 'react'
import Block from './Block'

const Result = ({ children }) => (
<Block title="Result">
{children}
</Block>
);
const Result = ({ children }) => <Block title="Result">{children}</Block>

export default Result;
export default Result
6 changes: 3 additions & 3 deletions .storybook/components/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export Block from './Block';
export Code from './Code';
export Result from './Result';
export Block from './Block'
export Code from './Code'
export Result from './Result'
21 changes: 11 additions & 10 deletions .storybook/stories/index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
import React from 'react';
import { storiesOf, action, linkTo } from '@kadira/storybook';
import { Code, Result } from '../components';
import MobileBreakpoint from '../components/MobileBreakpoint';
import withSizes from '../../src/withSizes';
import React from 'react'
import { storiesOf, action, linkTo } from '@kadira/storybook'
import { Code, Result } from '../components'
import MobileBreakpoint from '../components/MobileBreakpoint'
import withSizes from '../../src/withSizes'

const mapSizesToProps = sizes => ({
backgroundColor: sizes.width > 800 ? 'green' : 'blue',
isMobile: withSizes.isMobile(sizes),
isTablet: withSizes.isTablet(sizes),
isDesktop: withSizes.isDesktop(sizes),
});
})

const ExampleSizedComponent = withSizes(mapSizesToProps)(
({ isMobile, isTablet, isDesktop, backgroundColor }) => (
<div style={{ backgroundColor, color: 'white', padding: '30px' }}>
<div><strong>Resize your window</strong></div>
<div>
<strong>Resize your window</strong>
</div>
{isMobile && 'isMobile '}
{isTablet && 'isTablet '}
{isDesktop && 'isDesktop '}
</div>
)
);
)

storiesOf('Sizes', module)
.add('default behavior', () => (
Expand All @@ -29,7 +31,7 @@ storiesOf('Sizes', module)
<ExampleSizedComponent />
</Result>
<Code>
{`import React from 'react';
{`import React from 'react';
import withSizes from 'react-sizes';
const mapSizesToProps = sizes => ({
Expand Down Expand Up @@ -60,4 +62,3 @@ const ExampleSizedComponent = withSizes(mapSizesToProps)(
<MobileBreakpoint breakpoint={700} />
</div>
))
;
7 changes: 4 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import withSizes from './withSizes'
import * as presets from './presets'

export default Object.assign(withSizes, presets)
import createSizedComponent from './createSizedComponent'
import presets from './presets'

export { createSizedComponent, presets, withSizes }
export default withSizes
13 changes: 6 additions & 7 deletions src/presets.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ export const isMobile = ({ width }) => width < 480
export const isTablet = ({ width }) => width >= 480 && width < 1024
export const isDesktop = ({ width }) => width >= 1024

export const isGtMobile = (sizes) => !isMobile(sizes)
export const isGtTablet = (sizes) => isDesktop(sizes)
export const isGtMobile = sizes => !isMobile(sizes)
export const isGtTablet = sizes => isDesktop(sizes)

export const isStTablet = (sizes) => isMobile(sizes)
export const isStDesktop = (sizes) => !isDesktop(sizes)

export const isTabletAndGreater = (sizes) => !isMobile(sizes)
export const isTabletAndSmaller = (sizes) => !isStDesktop(sizes)
export const isStTablet = sizes => isMobile(sizes)
export const isStDesktop = sizes => !isDesktop(sizes)

export const isTabletAndGreater = sizes => !isMobile(sizes)
export const isTabletAndSmaller = sizes => !isStDesktop(sizes)
3 changes: 1 addition & 2 deletions src/utils/getDisplayName.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const getDisplayName = (Component) => (
const getDisplayName = Component =>
Component.displayName ||
Component.name ||
(typeof Component === 'string' && Component.length > 0
? Component
: 'Unknown')
)

export default getDisplayName
4 changes: 2 additions & 2 deletions src/utils/getWindowSizes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const getSizes = () => {
const getWindowSizes = () => {
const canUseDOM = typeof window !== 'undefined'

return {
Expand All @@ -8,4 +8,4 @@ const getSizes = () => {
}
}

export default getSizes
export default getWindowSizes
13 changes: 6 additions & 7 deletions src/withSizes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import getDisplayName from './utils/getDisplayName'
import shallowDiff from './utils/shallowDiff'
import getWindowSizes from './utils/getWindowSizes'

const debug = process && process.env &&
process.env.NODE_ENV === 'debug'
import * as presets from './presets'

const withSizes = (...mappedSizesToProps) => (WrappedComponent) => {
const debug = process && process.env && process.env.NODE_ENV === 'debug'

const withSizes = (...mappedSizesToProps) => WrappedComponent => {
const parseMappedSizesToProps = (dimensions, props) =>
mappedSizesToProps
.map(check => check(dimensions, props))
Expand All @@ -34,9 +35,7 @@ const withSizes = (...mappedSizesToProps) => (WrappedComponent) => {
}
}

throttledDispatchSizes = (
throttle(this.dispatchSizes, 200)
)
throttledDispatchSizes = throttle(this.dispatchSizes, 200)

/* Lifecycles */

Expand All @@ -60,4 +59,4 @@ const withSizes = (...mappedSizesToProps) => (WrappedComponent) => {
}
}

export default withSizes
export default Object.assign(withSizes, { ...presets })

0 comments on commit db40564

Please sign in to comment.