{"id":15705702,"url":"https://github.com/mglagola/style-constraints","last_synced_at":"2025-07-14T09:36:08.770Z","repository":{"id":57373173,"uuid":"125284504","full_name":"mglagola/style-constraints","owner":"mglagola","description":"[Beta] Bringing css media like queries to react \u0026 react-native using javascript","archived":false,"fork":false,"pushed_at":"2018-10-17T14:44:27.000Z","size":246,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-12T20:33:35.247Z","etag":null,"topics":["css","inline-styles","javascript","react","react-native","style"],"latest_commit_sha":null,"homepage":"http://npmjs.com/package/style-constraints","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mglagola.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-14T23:01:04.000Z","updated_at":"2019-06-25T06:12:28.000Z","dependencies_parsed_at":"2022-08-30T00:40:20.355Z","dependency_job_id":null,"html_url":"https://github.com/mglagola/style-constraints","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/mglagola/style-constraints","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mglagola%2Fstyle-constraints","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mglagola%2Fstyle-constraints/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mglagola%2Fstyle-constraints/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mglagola%2Fstyle-constraints/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mglagola","download_url":"https://codeload.github.com/mglagola/style-constraints/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mglagola%2Fstyle-constraints/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265167531,"owners_count":23721461,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["css","inline-styles","javascript","react","react-native","style"],"created_at":"2024-10-03T20:19:14.771Z","updated_at":"2025-07-14T09:36:08.705Z","avatar_url":"https://github.com/mglagola.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Style Constraints\n\n_**Note:** This is in **beta** and the API may change before `v1.0.0` release. Examples and docs may be outdated as well._\n\nThe goal of style constraints is to mimic some of the functionality of [css media queries](https://www.w3schools.com/css/css3_mediaqueries.asp) using javascript.\n\n[![npm](https://img.shields.io/npm/v/style-constraints.svg)](https://npm.im/style-constraints) [![travis](https://travis-ci.org/mglagola/style-constraints.svg?branch=master)](https://travis-ci.org/mglagola/style-constraints)\n\n## Installation\n\nInstall both `style-constraints` and `lodash` as `lodash` is a `peerDependency`.\n\n```\nnpm install --save style-constraints lodash\n```\n\n## Documentation\n\nComing soon.\n\n## Usage Example\n\n![animation](https://cl.ly/1j1E2w3p2T1F/Screen%20Recording%202018-03-21%20at%2012.22%20PM.gif)\n\n```js\nimport React from 'react';\nimport { Text, View } from 'react-native';\nimport styleConstraints from 'style-constraints';\n\n// For the sake of simplicity, omitting on-resize code.\n// For examples of what on-resize.js may look like for both\n// react native and react web, see: https://gist.github.com/mglagola/e4d22b3acb31ccb56642b3bf02f0e814\nimport onResize from './on-resize';\n\nconst Rows = ({\n    deviceSize = { width: 0, height: 0 },\n}) =\u003e {\n    const select = styleConstraints(deviceSize);\n    return (\n        \u003cView style={select(sc.container)}\u003e\n            \u003cText style={select(sc.text)}\u003eRow 1\u003c/Text\u003e\n            \u003cText style={select(sc.text)}\u003eRow 2\u003c/Text\u003e\n            \u003cText style={select(sc.text)}\u003eRow 3\u003c/Text\u003e\n            \u003cText style={select(sc.text)}\u003eRow 4\u003c/Text\u003e\n            \u003cText style={select(sc.text, sc.moreText)}\u003eRow 5\u003c/Text\u003e\n            \u003cText style={select(sc.text, sc.moreText)}\u003eRow 6\u003c/Text\u003e\n            \u003cText style={select(sc.text, sc.moreText)}\u003eRow 7\u003c/Text\u003e\n            \u003cText style={select(sc.text, sc.moreText)}\u003eRow 8\u003c/Text\u003e\n        \u003c/View\u003e\n    );\n};\n\n// \"sc\" is short for \"style constraints\"\nconst sc = {\n    container: [{\n        when: true,\n        style: {\n            flex: 1,\n            backgroundColor: '#aaa',\n            flexDirection: 'row',\n        }\n    }],\n    text: [{\n        when: true,\n        style: {\n            paddingLeft: 10,\n            paddingRight: 10,\n            fontSize: 18,\n            fontWeight: 'bold',\n        },\n    }, {\n        when: 'gte',\n        width: 400,\n        style: {\n            color: 'red',\n        },\n    }],\n    moreText: [{\n        when: 'lte',\n        width: 400,\n        style: {\n            display: 'none',\n        },\n    }],\n};\n\nexport default onResize(Rows);\n```\n\n## Demos\n\n* [React Native](https://github.com/mglagola/style-constraints/tree/master/examples/react-native)\n* React Web - coming soon.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmglagola%2Fstyle-constraints","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmglagola%2Fstyle-constraints","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmglagola%2Fstyle-constraints/lists"}