Skip to content

Commit

Permalink
feat: add <WindowWidthQuery> component
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Mar 4, 2018
1 parent 88b6ff8 commit 41e4f3c
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/WidthQuery/__story__/story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,33 @@ storiesOf('UI/WidthQuery', module)
</WidthQuery>
}</WindowSizeSensor>
)
.add('100px increments', () =>
<WindowSizeSensor>{({width}) =>
<WidthQuery width={width}>
<View maxWidth={100}>
Up to 100px
</View>
<View maxWidth={200}>
100px - 200px
</View>
<View maxWidth={300}>
200px - 300px
</View>
<View maxWidth={400}>
300px - 400px
</View>
<View maxWidth={500}>
400px - 500px
</View>
<View maxWidth={600}>
500px - 600px
</View>
<View maxWidth={700}>
600px - 700px
</View>
<View>
700px+
</View>
</WidthQuery>
}</WindowSizeSensor>
)
49 changes: 49 additions & 0 deletions src/WindowWidthQuery/__story__/story.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {Component, createElement as h} from 'react';
import {storiesOf} from '@storybook/react';
import {action} from '@storybook/addon-actions';
import {linkTo} from '@storybook/addon-links';
import {WindowWidthQuery} from '..';
import {View} from '../../View';
import {WindowSizeSensor} from '../../WindowSizeSensor';
import ShowDocs from '../../../.storybook/ShowDocs';

storiesOf('UI/WindowWidthQuery', module)
// .add('Documentation', () => h(ShowDocs, {md: require('../../../docs/en/WindowWidthQuery.md')}))
.add('Example', () =>
<WindowWidthQuery>
<View maxWidth={300}>
Up to 300px
</View>
<View>
More than 300px
</View>
</WindowWidthQuery>
)
.add('100px increments', () =>
<WindowWidthQuery>
<View maxWidth={100}>
Up to 100px
</View>
<View maxWidth={200}>
100px - 200px
</View>
<View maxWidth={300}>
200px - 300px
</View>
<View maxWidth={400}>
300px - 400px
</View>
<View maxWidth={500}>
400px - 500px
</View>
<View maxWidth={600}>
500px - 600px
</View>
<View maxWidth={700}>
600px - 700px
</View>
<View>
700px+
</View>
</WindowWidthQuery>
)
5 changes: 5 additions & 0 deletions src/WindowWidthQuery/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {h} from '../util';
import {WidthQuery} from '../WidthQuery';
import {WindowSizeSensor} from '../WindowSizeSensor';

export const WindowWidthQuery = (props) => h(WindowSizeSensor, null, (state) => h(WidthQuery, state, props.children));

0 comments on commit 41e4f3c

Please sign in to comment.