├── src ├── primitives │ ├── Div │ │ ├── index.js │ │ └── index.native.js │ ├── Span │ │ ├── index.js │ │ └── index.native.js │ ├── Window │ │ ├── index.js │ │ └── index.native.js │ └── index.js ├── introduction.md ├── utilities │ ├── Hidden │ │ ├── style.js │ │ └── index.js │ ├── Visible │ │ ├── style.js │ │ └── index.js │ └── ScreenClassRender │ │ ├── Readme.md │ │ └── index.js ├── config.js ├── index.js ├── context │ ├── ScreenClassResolver │ │ └── index.js │ └── ScreenClassProvider │ │ ├── Readme.md │ │ └── index.js ├── context.md ├── grid │ ├── Container │ │ ├── style.js │ │ └── index.js │ ├── Row │ │ ├── style.js │ │ └── index.js │ └── Col │ │ ├── style.js │ │ └── index.js ├── utils.js ├── utilities.md └── grid.md ├── .gitignore ├── .babelrc.js ├── .prettierrc.json ├── .eslintrc ├── docs ├── index.html └── build │ └── bundle.4b7c0373.js.LICENSE.txt ├── .github └── workflows │ └── node.js.yml ├── styleguide.config.js ├── LICENSE ├── eslint.config.mjs ├── package.json ├── index.d.ts └── README.md /src/primitives/Div/index.js: -------------------------------------------------------------------------------- 1 | export default 'div' 2 | -------------------------------------------------------------------------------- /src/primitives/Span/index.js: -------------------------------------------------------------------------------- 1 | export default 'span' 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | example/build/ 4 | /build 5 | -------------------------------------------------------------------------------- /.babelrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['@babel/preset-react', '@babel/preset-env'], 3 | } 4 | -------------------------------------------------------------------------------- /src/primitives/Span/index.native.js: -------------------------------------------------------------------------------- 1 | import { View } from 'react-native' 2 | 3 | export default View 4 | -------------------------------------------------------------------------------- /src/primitives/Window/index.js: -------------------------------------------------------------------------------- 1 | /* global window */ 2 | 3 | export default typeof window !== 'undefined' ? window : undefined; 4 | -------------------------------------------------------------------------------- /src/primitives/index.js: -------------------------------------------------------------------------------- 1 | export { default as Div } from './Div'; 2 | 3 | export { default as Span } from './Span'; 4 | 5 | export { default as Window } from './Window'; 6 | -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "tabWidth": 2, 3 | "semi": true, 4 | "singleQuote": true, 5 | "printWidth": 200, 6 | "useTabs": false, 7 | "trailingComma": "all", 8 | "bracketSpacing": true, 9 | "arrowParens": "always" 10 | } 11 | -------------------------------------------------------------------------------- /src/introduction.md: -------------------------------------------------------------------------------- 1 | A powerful Bootstrap-like responsive grid system for React. 2 | 3 | For more information on these components, view this project on GitHub: [https://github.com/sealninja/react-grid-system](https://github.com/sealninja/react-grid-system) 4 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "airbnb", 3 | "parser": "@babel/eslint-parser", 4 | "rules": { 5 | "react/jsx-filename-extension": "off", 6 | "react/prefer-stateless-function": "off", 7 | "react/destructuring-assignment": "off" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/primitives/Div/index.native.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { View } from 'react-native' 3 | 4 | export default ({ 5 | children, 6 | style, 7 | ...rest 8 | }) => ( 9 | 13 | {children} 14 | 15 | ) 16 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | React Grid System (v8.2.1) 8 | 9 | 10 |
11 | 12 | 13 | -------------------------------------------------------------------------------- /src/utilities/Hidden/style.js: -------------------------------------------------------------------------------- 1 | export const hidden = ({ 2 | screenClass, xs, sm, md, lg, xl, xxl, xxxl, 3 | }) => { 4 | if (screenClass === 'xxl') return xxl; 5 | if (screenClass === 'xxxl') return xxxl; 6 | if (screenClass === 'xl') return xl; 7 | if (screenClass === 'lg') return lg; 8 | if (screenClass === 'md') return md; 9 | if (screenClass === 'sm') return sm; 10 | return xs; 11 | }; 12 | 13 | export default hidden; 14 | -------------------------------------------------------------------------------- /src/utilities/Visible/style.js: -------------------------------------------------------------------------------- 1 | export const visible = ({ 2 | screenClass, xs, sm, md, lg, xl, xxl, xxxl 3 | }) => { 4 | if (screenClass === 'xxl') return xxl; 5 | if (screenClass === 'xxxl') return xxxl; 6 | if (screenClass === 'xl') return xl; 7 | if (screenClass === 'lg') return lg; 8 | if (screenClass === 'md') return md; 9 | if (screenClass === 'sm') return sm; 10 | return xs; 11 | }; 12 | 13 | export default visible; 14 | -------------------------------------------------------------------------------- /src/utilities/ScreenClassRender/Readme.md: -------------------------------------------------------------------------------- 1 | Example usage, rendering a font size based on the screen class: 2 | 3 | ``` 4 | ( 5 |

6 | Screen class: {screenClass} 7 |

8 | )} /> 9 | 10 | ``` 11 | 12 | Alternatively, the `useScreenClass` hook can be used for rendering a component differently based on the screen class. 13 | -------------------------------------------------------------------------------- /src/config.js: -------------------------------------------------------------------------------- 1 | let configuration = { 2 | breakpoints: [576, 768, 992, 1200, 1600, 1920], 3 | containerWidths: [540, 750, 960, 1140, 1540, 1810], 4 | gutterWidth: 30, 5 | gridColumns: 12, 6 | defaultScreenClass: 'xxl', 7 | maxScreenClass: 'xxl', 8 | }; 9 | 10 | export const getConfiguration = () => configuration; 11 | 12 | export const setConfiguration = (newConfiguration) => { 13 | configuration = { ...configuration, ...newConfiguration }; 14 | }; 15 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | // Grid 2 | export { default as Col } from './grid/Col'; 3 | export { default as Container } from './grid/Container'; 4 | export { default as Row } from './grid/Row'; 5 | 6 | // Utilities 7 | export { default as Hidden } from './utilities/Hidden'; 8 | export { default as Visible } from './utilities/Visible'; 9 | export { default as ScreenClassRender } from './utilities/ScreenClassRender'; 10 | export { default as ScreenClassProvider, ScreenClassContext } from './context/ScreenClassProvider'; 11 | export { setConfiguration } from './config'; 12 | export { useScreenClass } from './utils'; 13 | -------------------------------------------------------------------------------- /src/utilities/ScreenClassRender/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | import ScreenClassResolver from '../../context/ScreenClassResolver'; 4 | 5 | const ScreenClassRender = ({ render }) => ( 6 | 7 | {(screenClass) => render(screenClass)} 8 | 9 | ); 10 | 11 | ScreenClassRender.propTypes = { 12 | /** 13 | * The function which return value will be rendered. 14 | * Will be called with one argument: the screen class. 15 | */ 16 | render: PropTypes.func.isRequired, 17 | }; 18 | 19 | export default ScreenClassRender; 20 | -------------------------------------------------------------------------------- /src/primitives/Window/index.native.js: -------------------------------------------------------------------------------- 1 | import { Dimensions } from 'react-native' 2 | 3 | const WindowRef = { current: null } 4 | 5 | const { width, height } = Dimensions.get('window') 6 | 7 | WindowRef.current = { 8 | innerWidth: width, 9 | innerHeight: height, 10 | addEventListener: (___, callback) => { 11 | Dimensions.addEventListener('change', ({ window }) => { 12 | const { 13 | current: Window 14 | } = WindowRef 15 | Window.innerWidth = window.width 16 | Window.innerHeight = window.height 17 | callback() 18 | }) 19 | }, 20 | removeEventListener: (___, callback) => { 21 | Dimensions.removeEventListener('change', callback) 22 | }, 23 | } 24 | 25 | export default WindowRef.current 26 | -------------------------------------------------------------------------------- /.github/workflows/node.js.yml: -------------------------------------------------------------------------------- 1 | # This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions 3 | 4 | name: Node.js CI 5 | 6 | on: 7 | push: 8 | branches: [master] 9 | pull_request: 10 | branches: [master] 11 | 12 | jobs: 13 | build: 14 | runs-on: ubuntu-latest 15 | 16 | strategy: 17 | matrix: 18 | node-version: [22] 19 | 20 | steps: 21 | - uses: actions/checkout@v2 22 | - name: Use Node.js ${{ matrix.node-version }} 23 | uses: actions/setup-node@v2 24 | with: 25 | node-version: ${{ matrix.node-version }} 26 | - run: yarn --frozen-lockfile 27 | - run: yarn build 28 | - run: yarn lint 29 | - run: yarn docs 30 | -------------------------------------------------------------------------------- /src/context/ScreenClassResolver/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | import ScreenClassProvider, { ScreenClassContext, NO_PROVIDER_FLAG } from '../ScreenClassProvider'; 4 | 5 | const ScreenClassResolver = ({ children }) => ( 6 | 7 | {(screenClassCheck) => { 8 | if (screenClassCheck === NO_PROVIDER_FLAG) { 9 | return ( 10 | 11 | 12 | {(screenClassResolved) => children(screenClassResolved)} 13 | 14 | 15 | ); 16 | } 17 | return children(screenClassCheck); 18 | }} 19 | 20 | ); 21 | 22 | ScreenClassResolver.propTypes = { 23 | children: PropTypes.func.isRequired, 24 | }; 25 | 26 | export default ScreenClassResolver; 27 | -------------------------------------------------------------------------------- /src/context.md: -------------------------------------------------------------------------------- 1 | Internally, every component that requires the current `screenClass` (which is a human-readable string version of the `window.innerWidth` relating to the user's breakpoints) subscribes to a `ScreenClassProvider`. The provider utilizes the [React Context API](https://reactjs.org/docs/context.html) to send down the current `screenClass` as it updates. By default, each instance of every component subscribes to a separate provider, creating `resize` listeners for each. This can cut down renders during a resize event from ~300 to 4 (one for each breakpoint) making the grid much more performant. 2 | 3 | --- 4 | 5 | ### Do I need to change anything in my code? 6 | 7 | This new API is entirely opt-in and current implementations will continue to work. However, for a signficiant performance increase, you will need to add the `ScreenClassProvider` to your application, typically at the highest level in the React node tree (i.e, App.js). 8 | -------------------------------------------------------------------------------- /src/context/ScreenClassProvider/Readme.md: -------------------------------------------------------------------------------- 1 | ```jsx static 2 | import React from 'react'; 3 | import { ScreenClassProvider } from 'react-grid-system'; 4 | 5 | export default function App() { 6 | return ( 7 | 8 |
9 | 10 |