Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: renatorib/react-sizes
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.1.2
Choose a base ref
...
head repository: renatorib/react-sizes
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Loading
4 changes: 0 additions & 4 deletions .babelrc

This file was deleted.

4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
dist
es
lib
35 changes: 35 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"parser": "babel-eslint",
"extends": [
"eslint:recommended",
"plugin:import/recommended",
"plugin:react/recommended"
],
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true,
"experimentalObjectRestSpread": true
}
},
"env": {
"browser": true,
"node": true
},
"rules": {
"valid-jsdoc": 2,
"react/prop-types": 0,
"react/jsx-uses-react": 1,
"react/jsx-no-undef": 2,
"import/no-unresolved": ["error", { "ignore": ["^react$"] }],
"comma-dangle": ["error", "always-multiline"],
"semi": ["error", "never"],
"no-trailing-spaces": ["error", { "skipBlankLines": true }],
"no-unused-vars": ["error", { "ignoreRestSiblings": true }]
},
"plugins": [
"import",
"react"
]
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
es
dist
node_modules
lib
.DS_Store
*.log
.vscode
7 changes: 7 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
node_modules
src
.storybook
.editorconfig
.eslintrc
.eslintignore
.prettierrc
logo.png
rollup.config.js
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package.json
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',
@@ -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/dist/prism'
import { prism as theme } from 'react-syntax-highlighter/dist/styles/prism'
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 '../../lib/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 { default as Block } from './Block'
export { default as Code } from './Code'
export { default as Result } from './Result'
2 changes: 1 addition & 1 deletion .storybook/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { configure } from '@kadira/storybook';
import { configure } from '@storybook/react';

function loadStories() {
require('./stories');
51 changes: 40 additions & 11 deletions .storybook/stories/index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,56 @@
import React from 'react';
import { storiesOf, action, linkTo } from '@kadira/storybook';
import { Code, Result } from '../components';
import MobileBreakpoint from '../components/MobileBreakpoint';
import withSizes from '../../lib/withSizes';
import React from 'react'
import { storiesOf } from '@storybook/react'
import { Code, Result } from '../components'
import MobileBreakpoint from '../components/MobileBreakpoint'
import withSizes from '../../src/withSizes'
import SizesProvider from '../../src/SizesProvider'

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>
)
);
)

class ForceFallbackExample extends React.Component {
state = {
forceFallback: true,
}

componentDidMount() {
setTimeout(() => {
this.setState({ forceFallback: false })
}, 5000)
}

render() {
const { forceFallback } = this.state

return (
<SizesProvider
config={{ fallbackHeight: 640, fallbackWidth: 280, forceFallback }}
>
<Result>
{forceFallback && <p>Forcing fallback to mobile</p>}
<ExampleSizedComponent />
</Result>
</SizesProvider>
)
}
}

storiesOf('Sizes', module)
.add('default behavior', () => (
@@ -29,7 +59,7 @@ storiesOf('Sizes', module)
<ExampleSizedComponent />
</Result>
<Code>
{`import React from 'react';
{`import React from 'react';
import withSizes from 'react-sizes';
const mapSizesToProps = sizes => ({
@@ -52,12 +82,11 @@ const ExampleSizedComponent = withSizes(mapSizesToProps)(
</Code>
</div>
))

.add('mobileBreakpoint', () => (
<div>
<MobileBreakpoint breakpoint={300} />
<MobileBreakpoint breakpoint={500} />
<MobileBreakpoint breakpoint={700} />
</div>
))
;
.add('force fallback', () => <ForceFallbackExample />)
Loading