Skip to content

Commit

Permalink
feat: implement <WidthQuery> component
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Mar 4, 2018
1 parent 4736203 commit f18bb73
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "libreact",
"version": "0.14.0",
"version": "0.15.0",
"description": "React standard library",
"main": "lib/index.js",
"repository": {
Expand Down
25 changes: 25 additions & 0 deletions src/WidthQuery/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export interface IWidthQueryProps {
width: number,
}

export const WidthQuery: React.SFC<IWidthQueryProps> = ({width, children}) => {
if (process.env.NODE_ENV !== 'production') {
if (!Array.isArray(children)) {
throw new TypeError('<WidthQuery/> expects multiple <View/> children.');
}
}

for (const child of children as any) {
const {maxWidth = Infinity, minWidth = 0} = child.props;

if (maxWidth > width && minWidth <= width) {
return child;
}

if (maxWidth === Infinity && width === Infinity) {
return child;
}
}

return null;
};

0 comments on commit f18bb73

Please sign in to comment.