├── .circleci
└── config.yml
├── .eslintignore
├── .gitignore
├── .npmignore
├── .travis.yml
├── CHANGELOG.md
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE.md
├── README.md
├── babel.config.js
├── examples
├── sandbox
│ ├── README.md
│ ├── package.json
│ └── src
│ │ └── index.js
└── styled-components
│ ├── .env
│ ├── README.md
│ ├── package.json
│ └── src
│ └── index.js
├── lerna.json
├── package.json
├── packages
├── bundler
│ ├── index.js
│ └── package.json
├── docs
│ ├── .eslintrc.js
│ ├── gatsby-browser.js
│ ├── gatsby-config.js
│ ├── gatsby-ssr.js
│ ├── package.json
│ ├── src
│ │ ├── components
│ │ │ ├── blocks.js
│ │ │ ├── code.js
│ │ │ ├── demo-provider.js
│ │ │ ├── edit-link.js
│ │ │ ├── footer.js
│ │ │ ├── head.js
│ │ │ ├── header.js
│ │ │ ├── icon.js
│ │ │ ├── layout.js
│ │ │ ├── logo.js
│ │ │ ├── nav.mdx
│ │ │ ├── note.js
│ │ │ ├── recipe-card.js
│ │ │ ├── skip-link.js
│ │ │ ├── twitter-card.js
│ │ │ └── wrapper.js
│ │ ├── gatsby-plugin-theme-ui
│ │ │ ├── components.js
│ │ │ └── index.js
│ │ ├── index.js
│ │ └── pages
│ │ │ ├── 404.mdx
│ │ │ ├── box.mdx
│ │ │ ├── button.mdx
│ │ │ ├── card.mdx
│ │ │ ├── demo.mdx
│ │ │ ├── extending.mdx
│ │ │ ├── flex.mdx
│ │ │ ├── forms
│ │ │ ├── checkbox.mdx
│ │ │ ├── index.mdx
│ │ │ ├── input.mdx
│ │ │ ├── label.mdx
│ │ │ ├── radio.mdx
│ │ │ ├── select.mdx
│ │ │ ├── slider.mdx
│ │ │ ├── switch.mdx
│ │ │ └── textarea.mdx
│ │ │ ├── getting-started.mdx
│ │ │ ├── guides
│ │ │ ├── css-grid.mdx
│ │ │ ├── index.mdx
│ │ │ ├── mdx.mdx
│ │ │ ├── server-side-rendering.mdx
│ │ │ ├── styled-components.mdx
│ │ │ ├── theme-ui.mdx
│ │ │ └── using-rebass-without-context.mdx
│ │ │ ├── heading.mdx
│ │ │ ├── image.mdx
│ │ │ ├── index.mdx
│ │ │ ├── layout
│ │ │ └── index.mdx
│ │ │ ├── link.mdx
│ │ │ ├── migrating.mdx
│ │ │ ├── props.mdx
│ │ │ ├── recipes
│ │ │ ├── avatar.mdx
│ │ │ ├── background-image-card.mdx
│ │ │ ├── badge.mdx
│ │ │ ├── container.mdx
│ │ │ ├── flexbox-align.mdx
│ │ │ ├── flexbox-grid.mdx
│ │ │ ├── flexbox-wrap.mdx
│ │ │ ├── image-card.mdx
│ │ │ ├── index.mdx
│ │ │ ├── nav-bar.mdx
│ │ │ ├── nav-link.mdx
│ │ │ └── video-embed.mdx
│ │ │ ├── reflexbox.mdx
│ │ │ ├── space.mdx
│ │ │ ├── text.mdx
│ │ │ ├── theming.mdx
│ │ │ └── variants.mdx
│ └── static
│ │ ├── _redirects
│ │ ├── card.png
│ │ ├── icon.png
│ │ └── logo.svg
├── forms
│ ├── .gitignore
│ ├── .npmignore
│ ├── README.md
│ ├── package.json
│ ├── src
│ │ └── index.js
│ └── test
│ │ ├── __snapshots__
│ │ └── index.js.snap
│ │ └── index.js
├── layout
│ ├── .gitignore
│ ├── .npmignore
│ ├── README.md
│ ├── package.json
│ └── src
│ │ └── index.js
├── preset-material
│ ├── LICENSE.md
│ ├── README.md
│ ├── package.json
│ ├── src
│ │ └── index.js
│ └── test
│ │ ├── __snapshots__
│ │ └── index.js.snap
│ │ └── index.js
├── preset
│ ├── LICENSE.md
│ ├── README.md
│ ├── package.json
│ ├── src
│ │ └── index.js
│ └── test
│ │ ├── __snapshots__
│ │ └── index.js.snap
│ │ └── index.js
├── rebass
│ ├── .gitignore
│ ├── .npmignore
│ ├── README.md
│ ├── package.json
│ ├── src
│ │ └── index.js
│ └── test
│ │ └── index.js
├── reflexbox
│ ├── .gitignore
│ ├── .npmignore
│ ├── LICENSE.md
│ ├── README.md
│ ├── babel.config.js
│ ├── package.json
│ ├── src
│ │ └── index.js
│ └── test
│ │ └── index.js
└── space
│ ├── README.md
│ ├── package.json
│ ├── src
│ └── index.js
│ └── test
│ ├── __snapshots__
│ └── index.js.snap
│ └── index.js
└── yarn.lock
/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | # Javascript Node CircleCI 2.0 configuration file
2 | #
3 | # Check https://circleci.com/docs/2.0/language-javascript/ for more details
4 | #
5 | version: 2
6 | jobs:
7 | build:
8 | docker:
9 | # specify the version you desire here
10 | - image: circleci/node:10
11 |
12 | # Specify service dependencies here if necessary
13 | # CircleCI maintains a library of pre-built images
14 | # documented at https://circleci.com/docs/2.0/circleci-images/
15 | # - image: circleci/mongo:3.4.4
16 |
17 | working_directory: ~/repo
18 |
19 | steps:
20 | - checkout
21 |
22 | # Download and cache dependencies
23 | - restore_cache:
24 | keys:
25 | - v1-dependencies-{{ checksum "package.json" }}
26 | # fallback to using the latest cache if no exact match is found
27 | - v1-dependencies-
28 |
29 | - run: yarn install
30 |
31 | - save_cache:
32 | paths:
33 | - node_modules
34 | key: v1-dependencies-{{ checksum "package.json" }}
35 |
36 | # run tests!
37 | - run: yarn test
38 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | dist
3 | build
4 | .next
5 | artifacts
6 | .cache
7 | public
8 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | dist
3 | coverage
4 | .cache
5 | public
6 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | src
2 | test
3 | babel.config.js
4 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - 10
4 | script:
5 | - yarn test --coverage
6 | after_success:
7 | - yarn cover
8 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 |
2 | # Changelog
3 |
4 | ## Unreleased
5 |
6 | - Update dependencies
7 |
8 | ## 4.0.7 2019-10-28
9 |
10 | - Add missing `heading` variant to `Heading` #754
11 |
12 | ## 4.0.6 2019-09-21
13 |
14 | - Update dependencies
15 | - Add layout package
16 | - Add Slider and Switch to forms package
17 |
18 | ## 4.0.5 2019-08-21
19 |
20 | - Fix publish
21 |
22 | ## 4.0.4 2019-08-21
23 |
24 | - Add bundler setup & build for `@rebass/forms/styled-system`
25 |
26 | ## 4.0.3 2019-08-18
27 |
28 | - Add forms package
29 | - Update dependencies
30 |
31 | ## 4.0.2 2019-08-07
32 | ## 4.0.1 2019-08-06
33 |
34 | - Fix ignore files
35 | - Adjust build
36 | - Update dependencies
37 |
38 | ## 4.0.0 2019-08-04
39 |
40 | - New [`sx` prop](https://rebassjs.org/props/#sx-prop) for theme-based styles
41 | - Use the `css` prop for un-themed, raw CSS values
42 | - No additional Babel configuration required for the `sx` or `css` props
43 | - Use the `sx` prop in MDX documents
44 | - Built-in support for themeable component [variants](https://rebassjs.org/variants)
45 | - Fully compatible with [Theme UI](https://theme-ui.com)
46 |
47 | ### Breaking Changes
48 |
49 | - The default package now uses Emotion. To use Rebass with Styled Components, import the components from `rebass/styled-components` instead.
50 | - The undocumented theme keys for `Box`, `Flex`, `Text`, `Heading`, `Link`, `Button`, `Image`, and `Card` are no longer supported. Use variants instead.
51 | - The `@rebass/grid` package has been renamed (back to) `reflexbox`
52 | - Heading: default `fontWeight` is now set to `heading`. Add styles to `theme.fontWeights` to customize the `heading` font weight.
53 | - Button no longer supports the following props. Use the `sx` prop instead.
54 | `border`, `borderColor`, `borderWidth`, `borderStyle`, `borderRadius`, `borderTop`, `borderRight`, `borderBottom`, `borderLeft`, `borderX`, `borderY`
55 | - Image no longer supports the following props. Use the `sx` prop instead.
56 | `border`, `borderColor`, `borderWidth`, `borderStyle`, `borderRadius`, `borderTop`, `borderRight`, `borderBottom`, `borderLeft`, `borderX`, `borderY`
57 | - Link no longer includes default styles. Add styles to `theme.variants.link` to customize link styles.
58 | - Card no longer supports the following props. Use the `sx` prop instead.
59 | `border`, `borderColor`, `borderWidth`, `borderStyle`, `borderRadius`, `borderTop`, `borderRight`, `borderBottom`, `borderLeft`, `borderX`, `borderY`, `boxShadow`, `textShadow`, `background`, `backgroundImage`, `backgroundSize`, `backgroundPosition`, `backgroundRepeat`,
60 |
61 |
62 | ## [3.1.0] 2019-03-23
63 |
64 | - Update to Styled System v4
65 |
66 | ## [3.0.1] 2019-01-18
67 |
68 | - Update styled-system #555
69 |
70 | ## [3.0.0] 2018-12-01
71 |
72 | - Reduced package size
73 | - Reduced number of components to 8
74 | - Updated for Styled Components v4 and Emotion v10
75 | - Reduced dependencies
76 | - Removed default theme and colors
77 | - Removed Provider component
78 | - Added variant theme support for Button and Card components
79 | - Removed `is` prop in favor of Styled Components' and Emotion's `as` prop
80 | - Uses Box component as base for all other components
81 | - Removed `css` prop in favor of Styled Components' and Emotion's implementations
82 |
83 | ## [3.0.0-12] 2018-11-29
84 |
85 | - Removes `css` prop in favor of babel-plugin-styled-components
86 | - Adds build setup for Emotion 10
87 |
88 | ## [3.0.0-11] 2018-11-13
89 |
90 | - Update dependencies
91 |
92 | ## [3.0.0-10] 2018-11-12
93 |
94 | - Sets `box-sizing: border-box` on base Box component
95 |
96 | ## [3.0.0-9] 2018-09-22
97 |
98 | - Adds flexbox props back to Box component
99 |
100 | ## [3.0.0-6] 2018-09-13
101 |
102 | - Adds emotion package
103 |
104 | ## [3.0.0-2] 2018-09-11
105 |
106 | - Update styled-system
107 | - Update docs
108 |
109 | ## [3.0.0-1] 2018-09-10
110 |
111 | - Update docs for v3
112 |
113 | ## [3.0.0-0] 2018-09-08
114 |
115 | - Smaller package
116 | - Reduced number of components to 8
117 | - Upgraded for styled-components v4
118 | - Reduced dependencies to one
119 | - Removed default theme and colors
120 | - Removed Rebass Provider component
121 | - Added variant theme support to Button and Card
122 | - Removed `is` prop in favor of styled-components `as` prop
123 | - Uses Box component as the base for all other components
124 |
125 | ## [2.3.2] 2018-09-08
126 |
127 | - Update repo in package.json
128 | - Update readme
129 |
130 | ## [2.3.1] 2018-09-08
131 |
132 | - Fix bad prepublish build
133 |
134 | ## [2.3.0] 2018-09-08
135 |
136 | - Upgrade to @rebass/components, @rebass/grid, and styled-system v3
137 |
138 | ## [2.2.0] 2018-09-08
139 |
140 | - Use `polished` for color manipulation instead of `chroma-js`
141 |
142 | ## [2.1.1] 2018-09-08
143 |
144 | - Support `width` prop on Card
145 | - Update docs
146 |
147 | ## [2.1.0] 2018-08-14
148 |
149 | - Add Hide component
150 |
151 | ## [2.0.1] 2018-06-30
152 |
153 | - Add `fontFamily` to Heading and Text components
154 | - Update docs
155 |
156 | ## [2.0.0] 2018-06-24
157 |
158 | ### Added
159 |
160 | - Support for [emotion][emotion]
161 |
162 | ### Changed
163 |
164 | - [styled-system](https://github.com/jxnblk/styled-system) v2
165 | - [grid-styled](https://github.com/jxnblk/grid-styled) v4
166 | - Moves components to separate modules
167 | - Uses [system-components](https://github.com/jxnblk/styled-system/tree/master/system-components)
168 | - Updates docs site
169 |
170 | #### Breaking
171 |
172 | - Renamed components
173 | - TabItem -> Tab
174 | - DotButton -> Dot
175 | - PanelHeader -> Panel.Header
176 | - PanelFooter -> Panel.Footer
177 | - Default theme (changed to match styled-system)
178 | - The `colors` object no longer uses Palx
179 | - Array color values have been removed
180 | - `radius` has been replaced with `radii`
181 | - `font` has been replaced with `fonts`
182 | - `monospace` has been removed
183 | - Theme fields are no longer exposed as exports
184 | - Props
185 | - `width` is only available on Flex and Box
186 | - `fontSize` is only available on typographic components
187 | - `direction` is now `flexDirection`
188 | - Flex `align` is now `alignItems`
189 | - Flex `justify` is now `justifyContent`
190 | - Flex `wrap` is now `flexWrap`
191 | - Arrow `up` is now `direction='up'`
192 | - `active` props have been removed in favor of custom styles
193 | - Border now uses [styled-system border props](https://github.com/jxnblk/styled-system#borders)
194 | - Banner `image` is now `backgroundImage`
195 | - Absolute, Fixed, Relative, and Sticky now require values for `top`, `right`, `bottom`, and `left` props
196 | - Drawer `position` prop has been renamed to `side`
197 | - Drawer `size` prop has been replaced with `width` and `height` props
198 |
199 | ### Removed
200 |
201 | - Custom HOC `hoc`
202 | - `createLibrary` function
203 | - `util`
204 | - `createComponent`
205 | - Palx dependency
206 | - ScrollCarousel component
207 | - CarouselSlide component
208 | - Star comonent
209 |
210 |
211 | [emotion]: https://github.com/emotion-js/emotion
212 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6 |
7 | ## Our Standards
8 |
9 | Examples of behavior that contributes to creating a positive environment include:
10 |
11 | * Using welcoming and inclusive language
12 | * Being respectful of differing viewpoints and experiences
13 | * Gracefully accepting constructive criticism
14 | * Focusing on what is best for the community
15 | * Showing empathy towards other community members
16 |
17 | Examples of unacceptable behavior by participants include:
18 |
19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances
20 | * Trolling, insulting/derogatory comments, and personal or political attacks
21 | * Public or private harassment
22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission
23 | * Other conduct which could reasonably be considered inappropriate in a professional setting
24 |
25 | ## Our Responsibilities
26 |
27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28 |
29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30 |
31 | ## Scope
32 |
33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34 |
35 | ## Enforcement
36 |
37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at jxnblk@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38 |
39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40 |
41 | ## Attribution
42 |
43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44 |
45 | [homepage]: http://contributor-covenant.org
46 | [version]: http://contributor-covenant.org/version/1/4/
47 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 |
2 | # Contributing
3 |
4 | Issues and pull requests are welcome.
5 |
6 | Please **be nice** and read the following before contributing.
7 |
8 | - Test before submitting pull requests - `npm test`
9 |
10 | ## Codebase Overview
11 |
12 | Folders:
13 | - `/src` source code
14 | - `/tests` tests, including snapshots
15 |
16 | Be sure to familiarize yourself with [styled-system](https://github.com/jxnblk/styled-system) before making changes.
17 |
18 | Please ensure to test any new code added, and update snapshots when relevant.
19 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 |
2 | # The MIT License (MIT)
3 | Copyright (c) 2015 – 2019 Brent Jackson
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10 |
11 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | packages/rebass/README.md
--------------------------------------------------------------------------------
/babel.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | presets: [
3 | '@babel/preset-env',
4 | '@babel/preset-react'
5 | ],
6 | env: {
7 | esm: {
8 | presets: [
9 | [
10 | '@babel/preset-env',
11 | {
12 | modules: false,
13 | }
14 | ]
15 | ],
16 | },
17 | styled: {
18 | plugins: [
19 | [
20 | 'transform-rename-import', {
21 | original: '^reflexbox$',
22 | replacement: 'reflexbox/styled-components',
23 | }
24 | ]
25 | ]
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/examples/sandbox/README.md:
--------------------------------------------------------------------------------
1 |
2 | Open in [Code Sandbox](https://codesandbox.io/s/github/rebassjs/rebass/tree/master/examples/sandbox)
3 |
--------------------------------------------------------------------------------
/examples/sandbox/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "rebass-sandbox",
3 | "private": true,
4 | "version": "4.0.7",
5 | "main": "index.js",
6 | "license": "MIT",
7 | "scripts": {
8 | "start": "react-scripts start"
9 | },
10 | "dependencies": {
11 | "@rebass/preset": "^4.0.5",
12 | "emotion-theming": "^10.0.14",
13 | "react": "^16.9.0",
14 | "react-dom": "^16.9.0",
15 | "rebass": "^4.0.7",
16 | "styled-components": "^4.3.2"
17 | },
18 | "browserslist": {
19 | "production": [
20 | ">0.2%",
21 | "not dead",
22 | "not op_mini all"
23 | ],
24 | "development": [
25 | "last 1 chrome version",
26 | "last 1 firefox version",
27 | "last 1 safari version"
28 | ]
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/examples/sandbox/src/index.js:
--------------------------------------------------------------------------------
1 | /* eslint no-unused-vars: 0 */
2 | import React from 'react'
3 | import { render } from 'react-dom'
4 | import preset from '@rebass/preset'
5 | import { ThemeProvider } from 'emotion-theming'
6 | // OR import { ThemeProvider } from 'styled-components'
7 | import {
8 | Box,
9 | Flex,
10 | Heading,
11 | Text,
12 | Button,
13 | Link,
14 | Image,
15 | Card,
16 | } from 'rebass'
17 | // OR use 'rebass/styled-components'
18 |
19 | const theme = {
20 | ...preset,
21 | }
22 |
23 | const App = props => {
24 | return (
25 |
26 |
27 |
28 | Rebass Sandbox
29 |
30 |
33 |
36 |
37 |
38 | )
39 | }
40 |
41 | render(, root) // eslint-disable-line no-undef
42 |
--------------------------------------------------------------------------------
/examples/styled-components/.env:
--------------------------------------------------------------------------------
1 | SKIP_PREFLIGHT_CHECK=true
2 |
--------------------------------------------------------------------------------
/examples/styled-components/README.md:
--------------------------------------------------------------------------------
1 |
2 | Open in [Code Sandbox](https://codesandbox.io/s/github/rebassjs/rebass/tree/master/examples/styled-components)
3 |
--------------------------------------------------------------------------------
/examples/styled-components/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@rebass/styled-components-example",
3 | "private": true,
4 | "version": "4.0.7",
5 | "main": "index.js",
6 | "license": "MIT",
7 | "scripts": {
8 | "start": "react-scripts start"
9 | },
10 | "dependencies": {
11 | "@rebass/preset": "^4.0.5",
12 | "react": "^16.9.0",
13 | "react-dom": "^16.9.0",
14 | "react-scripts": "^3.1.1",
15 | "rebass": "^4.0.7",
16 | "styled-components": "^4.3.2"
17 | },
18 | "browserslist": {
19 | "production": [
20 | ">0.2%",
21 | "not dead",
22 | "not op_mini all"
23 | ],
24 | "development": [
25 | "last 1 chrome version",
26 | "last 1 firefox version",
27 | "last 1 safari version"
28 | ]
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/examples/styled-components/src/index.js:
--------------------------------------------------------------------------------
1 | /* eslint no-unused-vars: 0 */
2 | import React from 'react'
3 | import { render } from 'react-dom'
4 | import preset from '@rebass/preset'
5 | import { ThemeProvider } from 'styled-components'
6 | import {
7 | Box,
8 | Flex,
9 | Heading,
10 | Text,
11 | Button,
12 | Link,
13 | Image,
14 | Card,
15 | } from 'rebass/styled-components'
16 |
17 | const theme = {
18 | ...preset,
19 | }
20 |
21 | const App = props => {
22 | return (
23 |
24 |
25 |
26 | Rebass Sandbox
27 |
28 |
31 |
34 |
35 |
36 | )
37 | }
38 |
39 | render(, root) // eslint-disable-line no-undef
40 |
--------------------------------------------------------------------------------
/lerna.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "4.0.7",
3 | "npmClient": "yarn",
4 | "useWorkspaces": true,
5 | "packages": [
6 | "packages/*"
7 | ]
8 | }
9 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "private": true,
3 | "workspaces": [
4 | "packages/*",
5 | "examples/*"
6 | ],
7 | "scripts": {
8 | "prepare": "lerna run prepare",
9 | "start": "yarn workspace docs start",
10 | "build": "yarn workspace docs build",
11 | "test": "jest",
12 | "cover": "npx codecov"
13 | },
14 | "devDependencies": {
15 | "@babel/cli": "^7.5.5",
16 | "@babel/core": "^7.5.5",
17 | "@babel/preset-env": "^7.5.5",
18 | "@babel/preset-react": "^7.0.0",
19 | "@testing-library/react": "^10.0.4",
20 | "jest": "^25.2.4",
21 | "jest-emotion": "^10.0.14",
22 | "jest-styled-components": "^6.3.3",
23 | "lerna": "^3.16.4",
24 | "react": "^16.8.6",
25 | "react-dom": "^16.8.6",
26 | "react-test-renderer": "^16.8.6"
27 | },
28 | "resolutions": {
29 | "@mdx-js/react": "^1.5.5"
30 | },
31 | "jest": {
32 | "testMatch": [
33 | "**/packages/**/test/*.js"
34 | ],
35 | "testPathIgnorePatterns": [
36 | "/node_modules/"
37 | ],
38 | "coverageReporters": [
39 | "lcov",
40 | "text",
41 | "html"
42 | ],
43 | "collectCoverageFrom": [
44 | "packages/**/src/*.js",
45 | "!packages/docs/**/*.js"
46 | ],
47 | "coverageThreshold": {
48 | "global": {
49 | "branches": 90,
50 | "functions": 90,
51 | "lines": 90,
52 | "statements": 90
53 | }
54 | },
55 | "setupFilesAfterEnv": [],
56 | "snapshotSerializers": [
57 | "jest-emotion"
58 | ]
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/packages/bundler/index.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | const execa = require('execa')
3 |
4 | const babel = (env, ...args) => {
5 | return execa('babel', [
6 | '--verbose',
7 | ...args.filter(Boolean),
8 | '--root-mode=upward',
9 | ], {
10 | stdio: 'inherit',
11 | env: {
12 | NODE_ENV: env,
13 | }
14 | })
15 | }
16 |
17 | babel(null, 'src', '-d', 'dist')
18 | babel('esm', 'src', '-o', 'dist/index.esm.js')
19 | babel('styled', 'src', '-d', 'styled-components')
20 |
--------------------------------------------------------------------------------
/packages/bundler/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@rebass/bundler",
3 | "version": "4.0.5",
4 | "bin": {
5 | "rebass-bundler": "./index.js"
6 | },
7 | "main": "index.js",
8 | "license": "MIT",
9 | "dependencies": {
10 | "@babel/cli": "^7.5.5",
11 | "@babel/core": "^7.5.5",
12 | "@babel/preset-env": "^7.5.5",
13 | "@babel/preset-react": "^7.0.0"
14 | },
15 | "gitHead": "f0f01843e9fb63ca69112d7e97a1451b27ee9e6c",
16 | "publishConfig": {
17 | "access": "public"
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/packages/docs/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | globals: {
3 | __PATH_PREFIX__: true,
4 | },
5 | extends: 'react-app',
6 | }
7 |
--------------------------------------------------------------------------------
/packages/docs/gatsby-browser.js:
--------------------------------------------------------------------------------
1 | export { wrapPageElement } from './src'
2 |
--------------------------------------------------------------------------------
/packages/docs/gatsby-config.js:
--------------------------------------------------------------------------------
1 | const remarkPlugins = [
2 | require('remark-slug'),
3 | ]
4 |
5 | module.exports = {
6 | plugins: [
7 | {
8 | resolve: 'gatsby-plugin-mdx',
9 | options: {
10 | extensions: ['.mdx', '.md'],
11 | remarkPlugins,
12 | }
13 | },
14 | 'gatsby-plugin-catch-links',
15 | 'gatsby-plugin-theme-ui',
16 | 'gatsby-plugin-react-helmet',
17 | ],
18 | }
19 |
--------------------------------------------------------------------------------
/packages/docs/gatsby-ssr.js:
--------------------------------------------------------------------------------
1 | export { wrapPageElement } from './src'
2 |
--------------------------------------------------------------------------------
/packages/docs/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "private": true,
3 | "name": "docs",
4 | "version": "4.0.7",
5 | "main": "index.js",
6 | "license": "MIT",
7 | "scripts": {
8 | "start": "gatsby develop",
9 | "clean": "gatsby clean",
10 | "build": "gatsby build",
11 | "serve": "gatsby serve",
12 | "icon": "npx repng src/components/icon.js -d static -f icon.png -w 512 -h 512",
13 | "card": "npx repng src/components/twitter-card.js -d static -f card.png -w 1024 -h 512"
14 | },
15 | "dependencies": {
16 | "@jxnblk/react-live": "^2.1.2-1",
17 | "@mdx-js/mdx": "^1.1.4",
18 | "@rebass/forms": "^4.0.6",
19 | "@rebass/layout": "^4.0.6",
20 | "@rebass/preset": "^4.0.5",
21 | "@rebass/preset-material": "^4.0.5",
22 | "@rebass/space": "^4.0.5",
23 | "@theme-ui/presets": "^0.3.0",
24 | "@theme-ui/prism": "^0.3.0",
25 | "@theme-ui/sidenav": "^0.3.1",
26 | "countries-list": "^2.4.3",
27 | "deepmerge": "^4.0.0",
28 | "gatsby": "^2.13.48",
29 | "gatsby-plugin-catch-links": "^2.1.2",
30 | "gatsby-plugin-mdx": "^1.0.22",
31 | "gatsby-plugin-react-helmet": "^3.1.3",
32 | "gatsby-plugin-theme-ui": "^0.3.0",
33 | "react": "^16.8.6",
34 | "react-dom": "^16.8.6",
35 | "react-helmet": "^6.0.0",
36 | "rebass": "^4.0.7",
37 | "remark-slug": "^5.1.2",
38 | "theme-ui": "^0.3.1"
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/packages/docs/src/components/blocks.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { Box } from 'rebass'
3 |
4 | export const Container = props =>
5 |
13 |
14 | export const Banner = props =>
15 |
21 |
41 | {props.children}
42 |
43 |
44 |
45 | export const LogoGrid = props =>
46 |
59 |
60 | export const Grid = ({
61 | width = 256,
62 | gap = 4,
63 | ...props
64 | }) =>
65 |
81 |
82 | export const NavGrid = props =>
83 |
124 |
125 |
--------------------------------------------------------------------------------
/packages/docs/src/components/code.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import styled from '@emotion/styled'
3 | import {
4 | LiveProvider,
5 | LivePreview,
6 | LiveEditor,
7 | LiveError,
8 | } from '@jxnblk/react-live'
9 | import { ThemeProvider } from 'theme-ui'
10 | import Prism from '@theme-ui/prism'
11 | import * as Rebass from 'rebass'
12 | import * as RebassForms from '@rebass/forms'
13 | import * as RebassLayout from '@rebass/layout'
14 | import { Flex, Box } from 'rebass'
15 | import { countries } from 'countries-list'
16 |
17 | const scope = {
18 | ...Rebass,
19 | ...RebassForms,
20 | ...RebassLayout,
21 | ThemeProvider,
22 | props: {
23 | image: 'https://images.unsplash.com/photo-1462331940025-496dfbfc7564?w=2048&q=20',
24 | countries,
25 | }
26 | }
27 |
28 | scope.Switch = props => {
29 | const [active, setActive] = React.useState(true)
30 | const toggle = () => setActive(!active)
31 |
32 | return (
33 |
38 | )
39 | }
40 |
41 | const transformCode = code => `<>${code}>`
42 |
43 | const Preview = ({ fullwidth, ...props }) =>
44 |
51 |
52 | const Editor = props =>
53 |
63 |
64 | const Err = props =>
65 |
77 |
78 | export default ({
79 | className,
80 | ...props
81 | }) => {
82 | const lang = 'jsx'
83 |
84 | if (props.preview) {
85 | const code = props.children
86 | return (
87 |
92 |
93 |
94 | )
95 | }
96 |
97 | if (props.live) {
98 | const code = props.children
99 | return (
100 | `1px solid ${t.colors.muted}`,
104 | borderRadius: 2,
105 | }}>
106 |
111 |
112 |
116 |
119 |
120 |
132 | Live Demo
133 |
134 |
135 |
136 |
137 | )
138 | }
139 |
140 | return (
141 |
145 | )
146 | }
147 |
--------------------------------------------------------------------------------
/packages/docs/src/components/demo-provider.js:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react'
2 | import { ThemeProvider } from 'theme-ui'
3 | import { Helmet } from 'react-helmet'
4 | import { Box, Flex } from 'rebass'
5 | import * as themeui from '@theme-ui/presets'
6 | import merge from 'lodash.merge'
7 | import rebass from '@rebass/preset'
8 | import material from '@rebass/preset-material'
9 |
10 | const presets = {
11 | ...themeui,
12 | rebass,
13 | material,
14 | }
15 |
16 | const themes = [
17 | 'rebass',
18 | 'material',
19 | ...Object.keys(presets)
20 | ]
21 |
22 | export default props => {
23 | const [ theme, setTheme ] = useState('preset')
24 |
25 | const demoTheme = merge({}, rebass, presets[theme])
26 |
27 | return (
28 |
29 | {demoTheme.googleFonts && (
30 |
31 |
32 |
33 | )}
34 |
35 |
36 | Theme:
37 | {' '}
38 |
49 |
50 |
51 |
52 | {props.children}
53 |
54 |
55 | )
56 | }
57 |
--------------------------------------------------------------------------------
/packages/docs/src/components/edit-link.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { Location } from '@reach/router'
3 | import { Link } from 'rebass'
4 |
5 | const base = 'https://github.com/rebassjs/rebass/edit/master/packages/docs/src/pages'
6 |
7 | const getHREF = (location) => {
8 | if (location.pathname === '/') return false
9 | return base + location.pathname.replace(/\/+$/, '') + '.mdx'
10 | }
11 |
12 | export default props =>
13 | {
15 | const href = getHREF(location)
16 | if (!href) return false
17 |
18 | return (
19 |
28 | )
29 | }}
30 | />
31 |
--------------------------------------------------------------------------------
/packages/docs/src/components/footer.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import {
3 | Box,
4 | Flex,
5 | Link,
6 | } from 'rebass'
7 |
8 | export default props =>
9 |
15 |
21 | Rebass
22 | Reflexbox
23 | Docs
24 | GitHub
25 |
26 |
27 |
--------------------------------------------------------------------------------
/packages/docs/src/components/head.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { Helmet } from 'react-helmet'
3 | import pkg from 'rebass/package.json'
4 |
5 | export default props => {
6 | const title = [props.title, 'Rebass'].filter(Boolean).join(' | ')
7 |
8 | return (
9 |
13 | {title}
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | )
23 | }
24 |
--------------------------------------------------------------------------------
/packages/docs/src/components/header.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import {
3 | Flex,
4 | Box,
5 | Link,
6 | Button,
7 | } from 'rebass'
8 | import { useColorMode } from 'theme-ui'
9 |
10 | const modes = [
11 | 'lite',
12 | 'dark',
13 | 'gray',
14 | 'hack',
15 | 'pink',
16 | ]
17 |
18 | const Burger = ({ size = 24 }) => (
19 |
30 |
31 |
32 | )
33 |
34 | const Dot = props =>
35 |
59 |
60 | export default ({
61 | nav,
62 | menu,
63 | setMenu,
64 | fullwidth,
65 | }) => {
66 | const [ mode, setMode ] = useColorMode()
67 |
68 | const cycleMode = e => {
69 | const i = (modes.indexOf(mode) + 1) % modes.length
70 | setMode(modes[i])
71 | }
72 |
73 | return (
74 |
80 | {!fullwidth && (
81 |
98 | )}
99 | Rebass
100 |
101 |
105 | GitHub
106 |
107 |
119 |
120 | )
121 | }
122 |
--------------------------------------------------------------------------------
/packages/docs/src/components/icon.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import Logo from './Logo'
3 |
4 | export default props => (
5 |
16 |
24 |
25 | )
26 |
--------------------------------------------------------------------------------
/packages/docs/src/components/layout.js:
--------------------------------------------------------------------------------
1 | import React, { useState, useRef } from 'react'
2 | import { Box, Flex } from 'rebass'
3 | import { Pagination } from '@theme-ui/sidenav'
4 | import Head from './head'
5 | import SkipLink from './skip-link'
6 | import Header from './header'
7 | import Footer from './footer'
8 | import Nav from './nav'
9 | import EditLink from './edit-link'
10 |
11 | const Sidebar = props =>
12 |
13 | {
17 | props.setMenu(false)
18 | }}
19 | onBlur={e => {
20 | props.setMenu(false)
21 | }}
22 | onFocus={e => {
23 | props.setMenu(true)
24 | }}
25 | style={{
26 | transform: props.open ? 'translateX(0)' : 'translateX(-100%)',
27 | }}
28 | sx={{
29 | position: [ 'fixed', 'sticky' ],
30 | zIndex: 1,
31 | top: 0,
32 | left: 0,
33 | bottom: [0, 'auto'],
34 | width: [ 256, 256, 320 ],
35 | minWidth: 0,
36 | maxHeight: ['100vh', 'none'],
37 | overflowY: 'auto',
38 | WebkitOverflowScrolling: 'touch',
39 | flex: 'none',
40 | px: 3,
41 | mt: [64, 0],
42 | pb: 3,
43 | bg: ['background', 'transparent'],
44 | transition: 'transform .2s ease-out',
45 | transform: [, 'none !important'],
46 | ul: {
47 | listStyle: 'none',
48 | padding: 0,
49 | },
50 | a: {
51 | variant: 'links.nav',
52 | },
53 | 'li > ul > li > a': {
54 | pl: '24px',
55 | }
56 | }}>
57 |
58 |
59 |
69 | {props.children}
70 |
71 | Edit this page on GitHub
72 |
73 |
79 |
80 |
81 |
82 | export default (props) => {
83 | const fullwidth = props.location.pathname === '/'
84 | const [ menu, setMenu ] = useState(false)
85 | const nav = useRef(null)
86 |
87 | return (
88 |
89 |
90 |
91 |
97 | {!fullwidth ? (
98 |
103 |
104 | {props.children}
105 |
106 |
107 | ) : (
108 |
109 | {props.children}
110 |
111 | )}
112 |
113 |
114 | )
115 | }
116 |
--------------------------------------------------------------------------------
/packages/docs/src/components/logo.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import styled from '@emotion/styled'
3 | import { keyframes } from '@emotion/core'
4 | import { useThemeUI } from 'theme-ui'
5 | import { layout } from 'styled-system'
6 |
7 | const Svg = styled(({
8 | width,
9 | height,
10 | ...props
11 | }) => )`
12 | transform: rotate3d(1, 1, 1, 0deg);
13 | ${layout}
14 | `
15 |
16 | const spin1 = keyframes`
17 | 50% { transform: rotate3d(0, 2, 1, 180deg) }
18 | 100% { transform: rotate3d(0, 2, 1, 360deg) }
19 | `
20 | const spin2 = keyframes`
21 | 50% { transform: rotate3d(2, 0, 1, 180deg) }
22 | 100% { transform: rotate3d(2, 0, 1, 360deg) }
23 | `
24 |
25 | const fade1 = keyframes`
26 | 0% { stroke: magenta }
27 | 33% { stroke: cyan }
28 | 66% { stroke: yellow }
29 | 100% { stroke: magenta }
30 | `
31 |
32 | const a = '4s'
33 | const b = '7s'
34 | const c = '8s'
35 |
36 | const Electron1 = styled('circle')`
37 | transform-origin: 50% 50%;
38 | animation-name: ${spin1}, ${fade1};
39 | animation-duration: ${a}, ${b};
40 | animation-timing-function: linear;
41 | animation-iteration-count: infinite;
42 | `
43 |
44 | const Electron2 = styled('circle')`
45 | transform-origin: 50% 50%;
46 | animation-name: ${spin2}, ${fade1};
47 | animation-duration: ${a}, ${c};
48 | animation-timing-function: linear;
49 | animation-iteration-count: infinite;
50 | `
51 |
52 | const ElectronStatic1 = styled('circle')`
53 | transform-origin: 50% 50%;
54 | transform: rotate3d(0, 2, 1, 190deg);
55 | `
56 |
57 | const ElectronStatic2 = styled('circle')`
58 | transform-origin: 50% 50%;
59 | transform: rotate3d(2, 0, 1, 190deg);
60 | `
61 |
62 | const Logo = props => {
63 | const electronProps = {
64 | cx: 32,
65 | cy: 32,
66 | r: 24,
67 | strokeWidth: props.strokeWidth,
68 | vectorEffect: 'non-scaling-stroke'
69 | }
70 |
71 | const electrons = props.static
72 | ? (
73 |
74 |
75 |
76 |
77 | )
78 | : (
79 |
80 |
81 |
82 |
83 | )
84 |
85 | return (
86 |
145 | )
146 | }
147 |
148 | Logo.defaultProps = {
149 | initial: false,
150 | color: 'white',
151 | bg: 'transparent',
152 | strokeWidth: 2,
153 | size: 256
154 | }
155 |
156 | export default Logo
157 |
--------------------------------------------------------------------------------
/packages/docs/src/components/nav.mdx:
--------------------------------------------------------------------------------
1 | - [Getting Started](/getting-started)
2 | - [Props](/props)
3 | - [Theming](/theming)
4 | - [Variants](/variants)
5 | - [Extending](/extending)
6 | - [Box](/box)
7 | - [Flex](/flex)
8 | - [Text](/text)
9 | - [Heading](/heading)
10 | - [Button](/button)
11 | - [Link](/link)
12 | - [Image](/image)
13 | - [Card](/card)
14 | - [Forms](/forms)
15 | - [Label](/forms/label)
16 | - [Input](/forms/input)
17 | - [Select](/forms/select)
18 | - [Textarea](/forms/textarea)
19 | - [Radio](/forms/radio)
20 | - [Checkbox](/forms/checkbox)
21 | - [Slider](/forms/slider)
22 | - [Switch](/forms/switch)
23 | - [Layout](/layout)
24 | - [Guides](/guides)
25 | - [CSS Grid](/guides/css-grid)
26 | - [MDX](/guides/mdx)
27 | - [Using Rebass without Context](/guides/using-rebass-without-context)
28 | - [Server- Side Rendering](/guides/server-side-rendering)
29 | - [Styled Components](/guides/styled-components)
30 | - [Demo](/demo)
31 | - [Recipes](/recipes)
32 | - [Flexbox Grid](/recipes/flexbox-grid)
33 | - [Flexbox Wrap](/recipes/flexbox-wrap)
34 | - [Nav Bar](/recipes/nav-bar)
35 | - [Image Card](/recipes/image-card)
36 | - [Background Image Card](/recipes/background-image-card)
37 | - [Video Embed](/recipes/video-embed)
38 | - [Container](/recipes/container)
39 | - [Avatar](/recipes/avatar)
40 | - [Badge](/recipes/badge)
41 | - [NavLink](/recipes/nav-link)
42 |
--------------------------------------------------------------------------------
/packages/docs/src/components/note.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { Box } from 'rebass'
3 |
4 | export default props =>
5 | `8px solid ${t.colors.primary}`,
16 | }}
17 | />
18 |
--------------------------------------------------------------------------------
/packages/docs/src/components/recipe-card.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { Link } from 'gatsby'
3 | import { Box, Card } from 'rebass'
4 |
5 | export default props => {
6 | const children = React.Children.toArray(props.children)
7 | const title = children.find(child => child.type === 'h1' || child.props.mdxType === 'h1')
8 | const example = children.find(child =>
9 | child.type === 'pre' || child.props.mdxType === 'pre')
10 |
11 | const [ pre ] = React.Children.toArray(example.props.children)
12 | const preview = React.cloneElement(pre, {
13 | preview: true
14 | })
15 |
16 | return (
17 |
27 |
32 | {preview}
33 |
34 |
37 | {title.props.children}
38 |
39 |
40 | )
41 | }
42 |
--------------------------------------------------------------------------------
/packages/docs/src/components/skip-link.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { Link } from 'rebass'
3 |
4 | export default props => (
5 |
34 | )
35 |
--------------------------------------------------------------------------------
/packages/docs/src/components/twitter-card.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import Logo from './Logo'
3 |
4 | const photo = 'https://images.unsplash.com/photo-1462331940025-496dfbfc7564?w=2048&q=20'
5 |
6 | export default props => (
7 |
16 |
23 |
24 | )
25 |
--------------------------------------------------------------------------------
/packages/docs/src/components/wrapper.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { Styled } from 'theme-ui'
3 | import { Link } from 'gatsby'
4 | import { Helmet } from 'react-helmet'
5 | import { Box, Flex } from 'rebass'
6 | import { globalHistory } from '@reach/router'
7 |
8 | const breadcrumbRoutes = [
9 | 'guides',
10 | 'recipes',
11 | ]
12 |
13 |
14 | export const Breadcrumbs = ({
15 | title,
16 | }) => {
17 | const { location } = globalHistory
18 | const [ n, base, path ] = location.pathname.split('/')
19 | if (!breadcrumbRoutes.includes(base)) return false
20 | if (!path) return false
21 |
22 | return (
23 |
29 |
32 | {base}
33 |
34 |
35 | /
36 |
37 |
38 | {title || path}
39 |
40 |
41 | )
42 | }
43 |
44 |
45 | export const wrapper = ({
46 | title,
47 | ...props
48 | }) => {
49 | const children = React.Children.toArray(props.children)
50 | .reduce((acc, child) => {
51 | const type = child.props.mdxType
52 | if (type !== 'h1') return [ ...acc, child ]
53 | return [
54 | ...acc,
55 | child,
56 | ,
57 | ]
58 | }, [])
59 |
60 | return (
61 | <>
62 | {title && (
63 |
64 | {title} | Rebass
65 |
66 | )}
67 | {children}
68 | >
69 | )
70 | }
71 |
--------------------------------------------------------------------------------
/packages/docs/src/gatsby-plugin-theme-ui/components.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import code from '../components/code'
3 | import { wrapper } from '../components/wrapper'
4 |
5 | const heading = Tag => props => {
6 | if (!props.id) return
7 |
8 | return (
9 |
10 |
11 | {props.children}
12 |
13 |
14 | )
15 | }
16 |
17 | export default {
18 | wrapper,
19 | pre: props => props.children,
20 | code,
21 | h2: heading('h2'),
22 | h3: heading('h3'),
23 | h4: heading('h4'),
24 | h5: heading('h5'),
25 | h6: heading('h6'),
26 | }
27 |
--------------------------------------------------------------------------------
/packages/docs/src/gatsby-plugin-theme-ui/index.js:
--------------------------------------------------------------------------------
1 | import preset from '@rebass/preset'
2 | import merge from 'lodash.merge'
3 | import prism from '@theme-ui/prism/presets/theme-ui'
4 |
5 | export default merge(preset, {
6 | initialColorModeName: 'lite',
7 | colors: {
8 | text: '#000',
9 | background: '#fff',
10 | primary: '#33e',
11 | secondary: '#a0c',
12 | accent: '#f0a',
13 | muted: '#f6f6ff',
14 | gray: '#444',
15 | lightgray: '#cfcfd3',
16 | modes: {
17 | dark: {
18 | text: '#fff',
19 | background: '#000',
20 | primary: '#0ff',
21 | secondary: '#b0f',
22 | accent: '#f0b',
23 | muted: '#111',
24 | gray: '#999',
25 | lightgray: '#444',
26 | },
27 | gray: {
28 | text: '#fff',
29 | background: 'hsl(270, 30%, 14%)',
30 | primary: 'hsl(180, 100%, 60%)',
31 | secondary: 'hsl(270, 100%, 60%)',
32 | accent: 'hsl(300, 100%, 60%)',
33 | muted: 'hsl(270, 50%, 8%)',
34 | gray: 'hsl(270, 50%, 70%)',
35 | lightgray: 'hsl(270, 50%, 30%)',
36 | },
37 | hack: {
38 | text: 'hsl(120, 100%, 75%)',
39 | background: 'hsl(120, 20%, 10%)',
40 | primary: 'hsl(120, 100%, 40%)',
41 | secondary: 'hsl(120, 50%, 40%)',
42 | accent: 'hsl(120, 100%, 90%)',
43 | muted: 'hsl(120, 20%, 7%)',
44 | gray: 'hsl(120, 20%, 40%)',
45 | lightgray: 'hsl(120, 20%, 20%)',
46 | },
47 | pink: {
48 | text: 'hsl(350, 80%, 10%)',
49 | background: 'hsl(350, 100%, 90%)',
50 | primary: 'hsl(350, 100%, 50%)',
51 | secondary: 'hsl(280, 100%, 50%)',
52 | accent: 'hsl(280, 100%, 20%)',
53 | muted: 'hsl(350, 100%, 88%)',
54 | gray: 'hsl(350, 40%, 50%)',
55 | lightgray: 'hsl(350, 60%, 80%)',
56 | },
57 | }
58 | },
59 | fontWeights: {
60 | body: 400,
61 | heading: 800,
62 | bold: 700,
63 | },
64 | sizes: {
65 | wide: 1280,
66 | },
67 | shadows: {
68 | small: `0 0 0px 1px rgba(0, 0, 0, 0.25)`,
69 | },
70 | buttons: {
71 | big: {
72 | variant: 'buttons.primary',
73 | px: 4,
74 | py: 3,
75 | fontSize: 3,
76 | },
77 | outline: {
78 | variant: 'buttons.primary',
79 | color: 'primary',
80 | bg: 'transparent',
81 | boxShadow: 'inset 0 0 0 2px'
82 | },
83 | transparent: {
84 | color: 'inherit',
85 | bg: 'transparent',
86 | ':hover,:focus': {
87 | color: 'primary',
88 | outline: 'none',
89 | boxShadow: '0 0 0 2px',
90 | }
91 | },
92 | },
93 | links: {
94 | nav: {
95 | display: 'block',
96 | px: 2,
97 | py: 1,
98 | color: 'inherit',
99 | textDecoration: 'none',
100 | fontSize: 1,
101 | fontWeight: 'bold',
102 | },
103 | },
104 | text: {
105 | heading: {
106 | a: {
107 | color: 'inherit',
108 | textDecoration: 'none',
109 | ':hover': {
110 | textDecoration: 'underline',
111 | }
112 | }
113 | }
114 | },
115 | variants: {
116 | badge: {
117 | display: 'inline-block',
118 | px: 2,
119 | color: 'background',
120 | bg: 'primary',
121 | borderRadius: 'circle',
122 | },
123 | },
124 | styles: {
125 | a: {
126 | color: 'primary',
127 | transition: 'color .2s ease-out',
128 | ':hover,:focus': {
129 | color: 'secondary',
130 | }
131 | },
132 | inlineCode: {
133 | fontFamily: 'monospace',
134 | fontSize: '93.75%',
135 | color: 'secondary',
136 | },
137 | code: {
138 | fontFamily: 'monospace',
139 | color: 'secondary',
140 | },
141 | pre: {
142 | ...prism,
143 | fontFamily: 'monospace',
144 | fontSize: 1,
145 | overflowX: 'auto',
146 | bg: 'muted',
147 | p: 3,
148 | borderRadius: 4,
149 | },
150 | blockquote: {
151 | p: 0,
152 | mx: 0,
153 | fontWeight: 'bold',
154 | fontSize: 3,
155 | },
156 | h1: {
157 | variant: 'text.heading',
158 | mt: 0,
159 | fontSize: [5, 6],
160 | },
161 | h2: {
162 | variant: 'text.heading',
163 | fontSize: [4, 5],
164 | },
165 | h3: {
166 | variant: 'text.heading',
167 | fontSize: 3,
168 | },
169 | h4: { variant: 'text.heading', },
170 | h5: { variant: 'text.heading', },
171 | h6: { variant: 'text.heading', },
172 | table: {
173 | width: '100%',
174 | borderCollapse: 'separate',
175 | borderSpacing: 0,
176 | },
177 | th: {
178 | py: 2,
179 | textAlign: 'left',
180 | borderBottom: t => `4px solid ${t.colors.muted}`,
181 | },
182 | td: {
183 | py: 2,
184 | textAlign: 'left',
185 | borderBottom: t => `1px solid ${t.colors.muted}`,
186 | },
187 | },
188 | forms: {
189 | label: {
190 | fontSize: 1,
191 | fontWeight: 'bold',
192 | },
193 | field: {
194 | borderColor: 'lightgray',
195 | ':focus': {
196 | borderColor: 'primary',
197 | outline: 'none',
198 | boxShadow: t => `0 0 0 2px ${t.colors.primary}`,
199 | }
200 | },
201 | input: {
202 | variant: 'forms.field',
203 | },
204 | select: {
205 | variant: 'forms.field',
206 | },
207 | textarea: {
208 | variant: 'forms.field',
209 | },
210 | radio: {
211 | },
212 | slider: {
213 | bg: 'lightgray',
214 | },
215 | switch: {
216 | // thumb: {}
217 | }
218 | }
219 | })
220 |
--------------------------------------------------------------------------------
/packages/docs/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import Layout from './components/layout'
3 |
4 | export { default as Layout } from './components/layout'
5 | export * from './components/blocks'
6 | export { default as DemoProvider } from './components/demo-provider'
7 | export { default as Note } from './components/note'
8 | export { default as Logo } from './components/logo'
9 | export { default as RecipeCard } from './components/recipe-card'
10 |
11 | export const wrapPageElement = ({ element, props }) =>
12 |
13 | {element}
14 |
15 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/404.mdx:
--------------------------------------------------------------------------------
1 | import { Flex } from 'rebass'
2 |
3 |
4 |
9 |
10 |
11 | # 404
12 |
13 | Page not found
14 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/box.mdx:
--------------------------------------------------------------------------------
1 | export const title = 'Box'
2 |
3 | # Box
4 |
5 | Responsive box-model layout component
6 |
7 | ```jsx live=true
8 |
14 | Box
15 |
16 | ```
17 |
18 | The Box and Flex components are also available in the standalone [Reflexbox](/reflexbox) package.
19 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/button.mdx:
--------------------------------------------------------------------------------
1 | export const title = 'Button'
2 |
3 | # Button
4 |
5 | Button component with variants
6 |
7 | ```jsx live=true
8 |
9 |
10 |
11 | ```
12 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/card.mdx:
--------------------------------------------------------------------------------
1 | export const title = 'Card'
2 |
3 | # Card
4 |
5 | Extension of the Box component with card styles
6 |
7 | ```jsx live=true
8 |
9 |
10 | Card
11 |
12 | ```
13 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/demo.mdx:
--------------------------------------------------------------------------------
1 | import {
2 | Box,
3 | Heading,
4 | Text,
5 | Button,
6 | Image,
7 | Card,
8 | } from 'rebass'
9 | import { DemoProvider } from '..'
10 |
11 | export const title = 'Demo'
12 |
13 | # Demo
14 |
15 |
16 |
17 | ```jsx live=true
18 |
27 | Hello
28 | This is a demo using presets from Theme UI
29 |
32 |
35 |
36 | ```
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/extending.mdx:
--------------------------------------------------------------------------------
1 | import Note from '../components/note'
2 | export const title = 'Extending'
3 |
4 | # Extending
5 |
6 | Rebass components are designed to be used as foundational primitives
7 | for building a custom design system.
8 | By extending these base components, you can quickly start a component library
9 | with a consistent API and styles that are driven by design constraints
10 | that you define in your theme.
11 |
12 | To extend a component, pass props through and define custom styles in the `sx` prop.
13 |
14 | ```jsx
15 | import React from 'react'
16 | import { Box } from 'rebass'
17 |
18 | const Container = props =>
19 |
27 | ```
28 |
29 | If you prefer, you can also use `@emotion/styled` to extend components.
30 |
31 |
32 |
33 | It's not recommended to use the `styled` API from `styled-components` due to various issues and unexpected behavior.
34 |
35 |
36 |
37 | ## Order of Styles
38 |
39 | Because Rebass still uses CSS, you might have to contend with the cascade, depending on how you define your styles,
40 | especially in regards to source order and using shorthand CSS properties.
41 |
42 | Rebass components apply styles in the following order:
43 |
44 | 1. Variant
45 | 2. `sx` prop
46 | 3. `css` prop
47 | 4. Styled System props
48 |
49 | ### Shorthand CSS Properties
50 |
51 | If you're using CSS properties that have shorthand variations, try to use the normal CSS property instead.
52 |
53 | ```js
54 | // avoid shorthand syntax
55 | sx={{
56 | border: '1px solid tomato',
57 | }}
58 | ```
59 | ```js
60 | // use regular properties instead
61 | sx={{
62 | borderWidth: '1px',
63 | borderStyle: 'solid',
64 | borderColor: 'tomato',
65 | }}
66 | ```
67 |
68 | ### Conflicting Styles
69 |
70 | It's easy to add conflicting styles in two different places and end up with unexpected results.
71 |
72 | - If you're intending to use a style prop, don't use it in the `sx` prop or in variants.
73 | - If you're intending to use variants, don't include conflicting styles in the `sx` prop
74 |
75 | ## Default Props
76 |
77 | Instead of using the `defaultProps` property on your component, define defaults inline in the JSX.
78 | The `{...props}` from the outside will override the ones you set on the component.
79 |
80 | ```jsx
81 | const Container = props =>
82 |
88 | ```
89 |
90 | ## Default Variants
91 |
92 | To set a default variant, include the variant in your theme.
93 |
94 | ```js
95 | variants: {
96 | badge: {
97 | color: 'white',
98 | bg: 'tomato',
99 | px: 2,
100 | },
101 | }
102 | ```
103 |
104 | Then add the default prop in your component.
105 |
106 | ```jsx
107 | const Badge = props =>
108 |
112 | ```
113 |
114 | ## Example Extensions
115 |
116 | ### Avatar
117 |
118 | ```jsx
119 | const Avatar = props =>
120 |
128 | ```
129 |
130 | ### Embed
131 |
132 | ```jsx
133 | const Embed = props =>
134 | iframe': {
143 | position: 'absolute',
144 | width: '100%',
145 | height: '100%',
146 | top: 0,
147 | bottom: 0,
148 | left: 0,
149 | border: 0
150 | }
151 | }}
152 | />
153 | ```
154 |
155 | ### Pre
156 |
157 | ```jsx
158 | const Pre = props =>
159 |
170 | ```
171 |
172 | ### Fixed
173 |
174 | ```jsx
175 | const Fixed = props =>
176 |
182 | ```
183 |
184 | ### Divider
185 |
186 | ```jsx
187 | const Divider = props =>
188 |
197 | ```
198 |
199 |
216 |
217 | See the [Recipes](/recipes) page for more examples.
218 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/flex.mdx:
--------------------------------------------------------------------------------
1 | export const title = 'Flex'
2 |
3 | # Flex
4 |
5 | Responsive flexbox layout component
6 |
7 | ```jsx live=true
8 |
9 |
14 | Flex
15 |
16 |
21 | Box
22 |
23 |
24 | ```
25 |
26 | The Box and Flex components are also available in the standalone [Reflexbox](/reflexbox) package.
27 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/forms/checkbox.mdx:
--------------------------------------------------------------------------------
1 | export const title = 'Checkbox'
2 |
3 | # Checkbox
4 |
5 | Accessible and themeable form checkbox input component.
6 |
7 | ```js
8 | import { Label, Checkbox } from '@rebass/forms'
9 | ```
10 |
11 | ```jsx live
12 |
13 |
20 |
21 | ```
22 |
23 | Note that the `Label` component uses `display: flex` by default to make alignment with labels simpler.
24 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/forms/index.mdx:
--------------------------------------------------------------------------------
1 | import { Box, Button } from 'rebass'
2 | export const title = 'Forms'
3 |
4 | # Forms
5 |
6 | Accessible and themeable form components for use with Rebass or Theme UI.
7 |
8 | ```sh
9 | npm i @rebass/forms
10 | ```
11 |
12 | Import and use the form components alongside other Rebass components.
13 |
14 | ```js
15 | import {
16 | Label,
17 | Input,
18 | Select,
19 | Textarea,
20 | Radio,
21 | Checkbox,
22 | } from '@rebass/forms'
23 | ```
24 |
25 | ```jsx live
26 | e.preventDefault()}
29 | py={3}>
30 |
31 |
32 |
33 |
38 |
39 |
40 |
41 |
51 |
52 |
53 |
54 |
63 |
71 |
78 |
79 |
82 |
83 |
84 |
85 | ```
86 |
87 | ## Theming
88 |
89 | Each form element can be customized with the `forms` object in your theme.
90 |
91 | ```js
92 | // example theme
93 | export default {
94 | forms: {
95 | input: {
96 | color: 'primary',
97 | },
98 | select: {
99 | borderRadius: 9999,
100 | },
101 | textarea: {},
102 | label: {},
103 | radio: {},
104 | checkbox: {},
105 | },
106 | }
107 | ```
108 |
109 | ## Variants
110 |
111 | Additional component variants can be defined in the theme and applied via props.
112 |
113 | ```js
114 | // example theme with variants
115 | export default {
116 | forms: {
117 | largeInput: {
118 | fontSize: 3,
119 | px: 3,
120 | py: 2,
121 | }
122 | }
123 | }
124 | ```
125 |
126 | ```jsx
127 |
128 | ```
129 |
130 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/forms/input.mdx:
--------------------------------------------------------------------------------
1 | export const title = 'Input'
2 |
3 | # Input
4 |
5 | Accessible and themeable form input component.
6 |
7 | ```js
8 | import { Label, Input } from '@rebass/forms'
9 | ```
10 |
11 | ```jsx live
12 |
13 |
14 |
20 |
21 | ```
22 |
23 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/forms/label.mdx:
--------------------------------------------------------------------------------
1 | export const title = 'Label'
2 |
3 | # Label
4 |
5 | Accessible and themeable form label component.
6 |
7 | ```js
8 | import { Label } from '@rebass/forms'
9 | ```
10 |
11 | ```jsx live
12 |
13 | ```
14 |
15 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/forms/radio.mdx:
--------------------------------------------------------------------------------
1 | export const title = 'Radio'
2 |
3 | # Radio
4 |
5 | Accessible and themeable form radio input component.
6 |
7 | ```js
8 | import { Label, Radio } from '@rebass/forms'
9 | ```
10 |
11 | ```jsx live
12 |
13 |
21 |
29 |
37 |
38 | ```
39 |
40 | Note that the `Label` component uses `display: flex` by default to make alignment with labels simpler.
41 |
42 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/forms/select.mdx:
--------------------------------------------------------------------------------
1 | export const title = 'Select'
2 |
3 | # Select
4 |
5 | Accessible and themeable form select component.
6 |
7 | ```js
8 | import { Label, Select } from '@rebass/forms'
9 | ```
10 |
11 | ```jsx live
12 |
13 |
14 |
25 |
26 | ```
27 |
28 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/forms/slider.mdx:
--------------------------------------------------------------------------------
1 | export const title = 'Slider'
2 |
3 | # Slider
4 |
5 | Accessible and themeable form range input component.
6 |
7 | ```js
8 | import { Label, Slider } from '@rebass/forms'
9 | ```
10 |
11 | ```jsx live
12 |
13 |
14 |
19 |
20 | ```
21 |
22 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/forms/switch.mdx:
--------------------------------------------------------------------------------
1 | export const title = 'Switch'
2 |
3 | # Switch
4 |
5 | Toggle switch button component
6 |
7 | ```js
8 | import { Switch } from '@rebass/forms'
9 | ```
10 |
11 | ```jsx live
12 |
13 | ```
14 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/forms/textarea.mdx:
--------------------------------------------------------------------------------
1 | export const title = 'Textarea'
2 |
3 | # Textarea
4 |
5 | Accessible and themeable form textarea component.
6 |
7 | ```js
8 | import { Label, Textarea } from '@rebass/forms'
9 | ```
10 |
11 | ```jsx live
12 |
13 |
14 |
18 |
19 | ```
20 |
21 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/getting-started.mdx:
--------------------------------------------------------------------------------
1 | export const title = 'Getting Started'
2 |
3 | # Getting Started
4 |
5 | Install the core Rebass library.
6 |
7 | ```sh
8 | npm i rebass
9 | ```
10 |
11 | ## ThemeProvider
12 |
13 | By default, Rebass components are stylistically unopinionated and do not include a theme.
14 | You can add a theme to your application with a `ThemeProvider` component and by providing a theme in context.
15 | For this guide, use the Emotion `ThemeProvider` with the default Rebass preset theme.
16 |
17 | ```sh
18 | npm i @rebass/preset emotion-theming
19 | ```
20 |
21 | Wrap your application with the `ThemeProvider` component.
22 |
23 | ```jsx
24 | import React from 'react'
25 | import { ThemeProvider } from 'emotion-theming'
26 | import theme from '@rebass/preset'
27 |
28 | export default props =>
29 |
30 | {props.children}
31 |
32 | ```
33 |
34 | Alternatively, if you'd like to use Rebass with [Theme UI][],
35 | you can use the `ThemeProvider` from `theme-ui`, or use [`gatsby-plugin-theme-ui`](https://theme-ui.com/gatsby-plugin).
36 |
37 | ```sh
38 | import { ThemeProvider } from 'theme-ui'
39 | ```
40 |
41 | ## Composition
42 |
43 | You can use Rebass components out-of-the-box to build larger, composite components.
44 |
45 | ```jsx
46 | import React from 'react'
47 | import {
48 | Box,
49 | Card,
50 | Image,
51 | Heading,
52 | Text
53 | } from 'rebass'
54 |
55 | export default ({
56 | image,
57 | title,
58 | description
59 | }) =>
60 |
61 |
67 |
68 |
69 |
70 | {title}
71 |
72 |
73 | {description}
74 |
75 |
76 |
77 |
78 | ```
79 |
80 | ```jsx live=true
81 |
82 |
88 |
89 |
90 |
91 | Card Demo
92 |
93 |
94 | You can edit this code
95 |
96 |
97 |
98 |
99 | ```
100 |
101 | All components in Rebass are extensions of the base [Box](/box) component, which includes an `sx` prop for theme-based styling as well as a standard set of [Styled System][] style props.
102 |
103 | ## Extending
104 |
105 | You can also use Rebass components as basic building blocks and extend them to create custom UI components,
106 | which is a great way to get started with a new design system without *boiling the ocean*.
107 |
108 | ```jsx
109 | // custom button example
110 | import React from 'react'
111 | import { Button } from 'rebass'
112 |
113 | export default props =>
114 |
122 | ```
123 |
124 | ## Theming
125 |
126 | Use the default Rebass theme or completely customize the look and feel with a custom theme.
127 | Since Rebass follows the [Theme Specification][], any theme built for use with [Theme UI][] or [Styled System][] will work out-of-the-box.
128 |
129 | ```jsx
130 | import React from 'react'
131 | import { ThemeProvider } from 'emotion-theming'
132 |
133 | const theme = {
134 | fontSizes: [
135 | 12, 14, 16, 24, 32, 48, 64
136 | ],
137 | colors: {
138 | primary: '#07c',
139 | gray: '#f6f6ff',
140 | },
141 | buttons: {
142 | primary: {
143 | color: 'white',
144 | bg: 'primary',
145 | },
146 | outline: {
147 | color: 'primary',
148 | bg: 'transparent',
149 | boxShadow: 'inset 0 0 0 2px'
150 | },
151 | },
152 | }
153 |
154 | export default props =>
155 |
156 | {props.children}
157 |
158 | ```
159 |
160 | ## Variants
161 |
162 | Each component accepts a `variant` prop, giving you multiple styles for buttons, cards, text styles, and more.
163 | You can define custom variants in your own theme or use the defaults from the Rebass preset theme.
164 |
165 | ```jsx live=true
166 |
167 |
168 | ```
169 |
170 | [styled system]: https://styled-system.com
171 | [theme specification]: https://github.com/system-ui/theme-specification
172 | [theme ui]: https://theme-ui.com
173 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/guides/css-grid.mdx:
--------------------------------------------------------------------------------
1 | export const title = 'CSS Grid'
2 |
3 | # CSS Grid
4 |
5 | Rebass components can be used to create one-off or reusable CSS Grid layout components.
6 | While the entirety of what's possible with CSS Grid is outside the scope of this guide, the following should demonstrate how to apply any CSS Grid layout using Rebass.
7 |
8 |
9 |
10 | This guide is a work-in-progress.
11 | If you'd like to help make this better,
12 | please open an issue or pull request on [GitHub](https://github.com/rebassjs/rebass).
13 |
14 |
15 |
16 | CSS Grid is great for arranging direct child elements without the need for additional styles applied to the children.
17 | Create an extension of the Box component that can wrap other elements to apply a grid layout.
18 |
19 | ```jsx
20 | // example grid layout component
21 | import React from 'react'
22 | import { Box } from 'rebass'
23 |
24 | export default props =>
25 |
32 | ```
33 |
34 | By using the `sx` prop, CSS properties such as `gridGap` will use values from your theme object.
35 | This can help ensure consistent whitespace throughout your layout.
36 |
37 | ## Auto Columns
38 |
39 | Using the `grid-auto-columns` property, you can quickly lay out child elements in a tile-based grid.
40 |
41 | ```jsx
42 | // example grid layout component
43 | import React from 'react'
44 | import { Box } from 'rebass'
45 |
46 | export default props =>
47 |
55 | ```
56 |
57 | ## Demo
58 |
59 | Use the live demo below to explore different layouts using CSS Grid.
60 |
61 | ```jsx live=true
62 |
68 | Hello
69 | CSS Grid
70 |
71 | ```
72 |
73 | ## Resources
74 |
75 | There are many resources for learning how to use CSS Grid layout.
76 | To fully understand any API in CSS, I *highly* recommend reading the specification, since it is the authoritative source for how CSS is intended to work:
77 |
78 | **[CSS Grid Layout Module Level 1][spec]**
79 |
80 | Once you have a basic grasp of the concepts in the specification, MDN is an excellent resource for learning any web technology:
81 |
82 | **[MDN: CSS Grid Layout][mdn]**
83 |
84 | Additional resources:
85 |
86 | - [Grid by Example][]
87 | - [Jen Simmon's Lab][simmons-lab]
88 | - [CSS Tricks][]
89 |
90 | [spec]: https://www.w3.org/TR/css-grid-1/
91 | [mdn]: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout
92 | [css tricks]: https://css-tricks.com/snippets/css/complete-guide-grid/
93 | [grid by example]: https://gridbyexample.com/
94 | [simmons-lab]: https://labs.jensimmons.com/
95 |
96 |
97 | [learn-css-grid]: https://learncssgrid.com/
98 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/guides/index.mdx:
--------------------------------------------------------------------------------
1 | import { Grid } from '../..'
2 | export const title = 'Guides'
3 |
4 | # Guides
5 |
6 |
15 |
16 | - [CSS Grid](/guides/css-grid)
17 | Use the Rebass Box component and `sx` prop to create custom CSS Grid components
18 | - [MDX](/guides/mdx)
19 | Use Rebass components to add styles and layout to MDX documents
20 | - [Using Rebass without Context](/guides/using-rebass-without-context)
21 | Create self-contained components that do not require theming context
22 | - [Server-Side Rendering](/guides/server-side-rendering)
23 | Render Rebass components on the server with zero configuration
24 | - [Styled Components](/guides/styled-components)
25 | Use Rebass with the Styled Components library
26 |
27 |
28 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/guides/mdx.mdx:
--------------------------------------------------------------------------------
1 | import { Note } from '../..'
2 | import { Box } from 'rebass'
3 | export const title = 'MDX'
4 |
5 | # MDX
6 |
7 | [MDX][] is a format that allows you to write content in markdown and import and use React components inline.
8 | It's an excellent format for documentation, blogs, or other forms of structured content.
9 |
10 |
11 |
12 | This guide is a work-in-progress.
13 | If you'd like to help make this better,
14 | please open an issue or pull request on [GitHub](https://github.com/rebassjs/rebass).
15 |
16 |
17 |
18 | Rebass components can be imported and used directly in MDX documents,
19 | which lets you apply styles inline to sections of your page.
20 | Since the `sx` prop is built into the components, this can be a quick way to apply one off styles or create custom components like callouts and note boxes.
21 |
22 | In the following example, the Box component is used to add a callout style box around its contents.
23 |
24 | ```md
25 | import { Box } from 'rebass'
26 |
27 | # MDX Example
28 |
29 |
35 |
36 | > ”This is an important quote.”
37 |
38 |
39 | ```
40 |
41 | You can also use the `sx` prop with child selectors to dramatically change the layout of MDX content.
42 |
43 | ```md
44 | import { Box } from 'rebass'
45 |
46 | # MDX Example
47 |
48 |
61 |
62 | - This is a list
63 | - Displayed in a grid layout
64 | - With custom styles
65 | - Pretty cool, huh?
66 |
67 |
68 | ```
69 |
70 | If you make repeated use of a particular layout block, consider moving it to its own component that can be imported in multiple MDX documents.
71 |
72 |
73 |
74 | If you'd like to style the markdown elements with the same theme object and a similar API to Rebass,
75 | use the [Theme UI][] library, which includes first-class support for styling MDX content.
76 |
77 |
78 |
79 | [mdx]: https://mdxjs.com
80 | [theme ui]: https://theme-ui.com
81 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/guides/server-side-rendering.mdx:
--------------------------------------------------------------------------------
1 | export const title = 'Server-Side Rendering'
2 |
3 | # Server-Side Rendering
4 |
5 | Because Rebass uses Emotion, no additional steps are required to support rendering on a server.
6 | Emotion will automatically inline performant, critical CSS without any additional effort required.
7 |
8 | See the [Emotion docs](https://emotion.sh/docs/ssr) for more.
9 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/guides/styled-components.mdx:
--------------------------------------------------------------------------------
1 | import { Note } from '../..'
2 | export const title = 'Using Styled Components'
3 |
4 | # Using Styled Components
5 |
6 | If you'd prefer to use the Styled Components library instead of Emotion, you can import components from `rebass/styled-components`.
7 |
8 | ```jsx
9 | import React from 'react'
10 | import { Box } from 'rebass/styled-components'
11 |
12 | export default props =>
13 |
14 | Hello
15 |
16 | ```
17 |
18 |
19 | The package will still install Emotion as a dependency, but it will not be included in the module or your application bundle.
20 |
21 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/guides/theme-ui.mdx:
--------------------------------------------------------------------------------
1 | import { Note } from '../..'
2 | export const title = 'Theme UI'
3 |
4 | # Theme UI
5 |
6 |
7 |
8 | This guide is a work-in-progress.
9 | If you'd like to help make this better,
10 | please open an issue or pull request on [GitHub](https://github.com/rebassjs/rebass).
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/guides/using-rebass-without-context.mdx:
--------------------------------------------------------------------------------
1 | import { Note } from '../..'
2 | export const title = 'Using Rebass without Context'
3 |
4 | # Using Rebass without Context
5 |
6 | If you'd like to use Rebass components without adding a theme to React context,
7 | you can pass a `theme` object as a prop to any of the components.
8 |
9 |
10 |
11 | This guide is a work-in-progress.
12 | If you'd like to help make this better,
13 | please open an issue or pull request on [GitHub](https://github.com/rebassjs/rebass).
14 |
15 |
16 |
17 | ```jsx
18 | import React from 'react'
19 | import { Box } from 'rebass'
20 | import theme from './theme'
21 |
22 | export default props =>
23 |
27 | ```
28 |
29 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/heading.mdx:
--------------------------------------------------------------------------------
1 | export const title = 'Heading'
2 |
3 | # Heading
4 |
5 | Extension of the Text component for headings
6 |
7 | ```jsx live=true
8 |
11 | Hello
12 |
13 | ```
14 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/image.mdx:
--------------------------------------------------------------------------------
1 | export const title = 'Image'
2 |
3 | # Image
4 |
5 | Responsive image component with variants
6 |
7 | ```jsx live=true
8 |
15 | ```
16 |
17 | ```jsx live=true
18 |
22 | ```
23 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/index.mdx:
--------------------------------------------------------------------------------
1 | import { Box, Flex, Button } from 'rebass'
2 | import {
3 | Banner,
4 | NavGrid,
5 | Container,
6 | Grid,
7 | LogoGrid,
8 | } from '..'
9 | import Logo from '../components/logo'
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | # Rebass
React primitive UI components
built with Styled System
18 |
19 | ```sh
20 | npm i rebass
21 | ```
22 |
23 |
24 |
25 |
26 |
27 |
28 | - [Getting Started](/getting-started)
29 | - [Props](/props)
30 | - [Theming](/theming)
31 | - [Variants](/variants)
32 | - [Extending](/extending)
33 | - [Box](/box)
34 | - [Flex](/flex)
35 | - [Text](/text)
36 | - [Heading](/heading)
37 | - [Button](/button)
38 | - [Link](/link)
39 | - [Image](/image)
40 | - [Card](/card)
41 | - [Forms](/forms)
42 | - [Guides](/guides)
43 | - [Recipes](/recipes)
44 |
45 |
46 |
47 |
48 |
49 |
50 | [![stars][]][github]
51 | [![build status][]][travis]
52 | [![downloads][]][npm]
53 | [![coverage][]][codecov]
54 |
55 | [stars]: https://flat.badgen.net/github/stars/rebassjs/rebass?color=33e
56 | [github]: https://github.com/rebassjs/rebass
57 | [build status]: https://flat.badgen.net/travis/rebassjs/rebass/master?color=33e
58 | [travis]: https://travis-ci.org/rebassjs/rebass
59 | [downloads]: https://flat.badgen.net/npm/dm/rebass?color=33e
60 | [npm]: https://npmjs.com/package/rebass
61 | [coverage]: https://flat.badgen.net/codecov/c/github/rebassjs/rebass?color=33e
62 | [codecov]: https://codecov.io/github/rebassjs/rebass
63 |
64 |
65 |
66 | - Start your design system without boiling the ocean
67 | - Build consistent UI with design constraints and user-defined scales
68 | - Best-in-class developer ergonomics with [Styled System][] props
69 | - First-class support for theming &
70 | fully compatible with [Theme UI][]
71 | - Quick, mobile-first responsive styles with array-based syntax
72 | - Flexbox layout with the Box and Flex components
73 | - Flexibility built in for high design & development velocity
74 | - Minimal footprint
75 |
76 |
77 |
78 | ```jsx live=true
79 |
84 | Hello
85 |
86 |
87 |
88 |
89 | ```
90 |
91 |
92 |
93 | - > “One of the best React component libs out there”
94 |
95 | - [Max Stoiber](https://twitter.com/mxstbr/status/882657561111080960)
96 |
97 | - > “Rebass is the Bootstrap of React.”
98 |
99 | - [Jori Lallo](https://twitter.com/jorilallo/status/882990343225868289)
100 |
101 | - > “A whopper component library built on styled-components. Responsive, systematic, scalable...the business!”
102 |
103 | - [Colm Tuite](https://twitter.com/colmtuite/status/882715087936606210)
104 |
105 | - > “Why the hell are we now putting CSS in Javascript? I’m losing my mind with web developers trying to control everything in the world with client-side javascript. What a mess.”
106 |
107 | - [alttab](https://news.ycombinator.com/item?id=14705579)
108 |
109 |
110 |
111 | ## Get Started
112 |
113 |
118 |
119 |
120 |
121 |
122 | [styled system]: https://styled-system.com
123 | [theme ui]: https://theme-ui.com
124 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/layout/index.mdx:
--------------------------------------------------------------------------------
1 | import { Tiles } from '@rebass/layout'
2 | export const title = 'Layout'
3 |
4 | # @rebass/layout
5 |
6 | Themeable layout components built with Rebass
7 |
8 | ```sh
9 | npm i @rebass/layout
10 | ```
11 |
12 | ## Tiles
13 |
14 | ```jsx live
15 |
16 |
17 |
18 |
19 |
20 |
21 | ```
22 |
23 | ```jsx live
24 |
25 |
26 |
27 |
28 |
29 |
30 | ```
31 |
32 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/link.mdx:
--------------------------------------------------------------------------------
1 | export const title = 'Link'
2 |
3 | # Link
4 |
5 | Styled link component
6 |
7 | ```jsx live=true
8 | Link
9 | ```
10 | ```jsx live=true
11 | Link
12 | ```
13 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/migrating.mdx:
--------------------------------------------------------------------------------
1 | export const title = 'Migration'
2 |
3 | # Migration Guide
4 |
5 | ## v4: What's New
6 |
7 | - New [`sx` prop](/props/#sx-prop) for theme-based styles
8 | - Use the `css` prop for un-themed, raw CSS values
9 | - No additional Babel configuration required for the `sx` or `css` props
10 | - Use the `sx` prop in MDX documents
11 | - Built-in support for themeable component [variants](/variants)
12 | - Fully compatible with [Theme UI][]
13 |
14 | [theme ui]: https://theme-ui.com
15 |
16 | ## v4: Breaking Changes
17 |
18 | - The default package now uses Emotion. To use Rebass with Styled Components, import the components from `rebass/styled-components` instead.
19 | - The undocumented theme keys for `Box`, `Flex`, `Text`, `Heading`, `Link`, `Button`, `Image`, and `Card` are no longer supported. Use variants instead.
20 | - The `@rebass/grid` package has been renamed (back to) `reflexbox`
21 | - Heading: default `fontWeight` is now set to `heading`. Add styles to `theme.fontWeights` to customize the `heading` font weight.
22 | - Button no longer supports the following props. Use the `sx` prop instead.
23 | `border`, `borderColor`, `borderWidth`, `borderStyle`, `borderRadius`, `borderTop`, `borderRight`, `borderBottom`, `borderLeft`, `borderX`, `borderY`
24 | - Image no longer supports the following props. Use the `sx` prop instead.
25 | `border`, `borderColor`, `borderWidth`, `borderStyle`, `borderRadius`, `borderTop`, `borderRight`, `borderBottom`, `borderLeft`, `borderX`, `borderY`
26 | - Link no longer includes default styles. Add styles to `theme.variants.link` to customize link styles.
27 | - Card no longer supports the following props. Use the `sx` prop instead.
28 | `border`, `borderColor`, `borderWidth`, `borderStyle`, `borderRadius`, `borderTop`, `borderRight`, `borderBottom`, `borderLeft`, `borderX`, `borderY`, `boxShadow`, `textShadow`, `background`, `backgroundImage`, `backgroundSize`, `backgroundPosition`, `backgroundRepeat`,
29 |
30 |
31 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/props.mdx:
--------------------------------------------------------------------------------
1 | export const title = 'Props'
2 |
3 | # Props
4 |
5 | All Rebass components extend the base [Box](/box) component,
6 | and include [Styled System][] props for ensuring your design constraints are easily accessible,
7 | while allowing you the flexibility to create responsive designs inline in your components.
8 |
9 | ## `sx` Prop
10 |
11 | The `sx` prop accepts a style object, with easy access to values from your theme
12 | and the ability to quickly add responsive styles to any property using arrays as values.
13 | If you've used [Theme UI][] or [Styled System][] before, this will probably seem familiar.
14 | If you've used the Emotion `css` prop before, the `sx` prop works in a similar way,
15 | but allows you to use values from your theme object.
16 |
17 | The `sx` prop is built-in and does not require any additional configuration,
18 | which means it will work in any React app, such as Create React App, or in [MDX][] documents.
19 |
20 | ```jsx live=true
21 |
27 | Hello
28 |
29 | ```
30 |
31 | ## Nested Selectors
32 |
33 | Use nested objects to apply pseudoclasses and other child selectors within the `sx` prop.
34 |
35 | ```jsx live=true
36 |
44 | ```
45 |
46 | ## Responsive Styles
47 |
48 | Mobile-first responsive styles based on breakpoints defined in your theme can be quickly applied to
49 | any element using arrays as values in the `sx` prop, or with any of the shorthand style props below.
50 | The first value in the array will apply to all screen widths, and each value after will be applied from that breakpoint and up.
51 |
52 | Define breakpoints in your theme using an array of widths.
53 |
54 | ```js
55 | // example theme
56 | export default {
57 | breakpoints: [ '40em', '52em', '64em' ],
58 | }
59 | ```
60 |
61 | For any individual CSS property, use an array as a value to quickly apply mobile-first responsive styles for that single property.
62 |
63 | ```jsx
64 |
69 | ```
70 |
71 | You can also use standard CSS media query syntax for one-off cases or non-mobile-first styles.
72 |
73 | ```jsx
74 |
82 | ```
83 |
84 | The `sx` prop uses [Styled System CSS](https://styled-system.com/css) to pick up values from your theme
85 | and write responsive styles using the array syntax.
86 |
87 | If you ever need to add styles that do not use values from your theme, use the `css` prop, which is available on all components, without the need for additional configuration.
88 |
89 | ## `as` Prop
90 |
91 | The underlying HTML element rendered in any component can be overridden by the `as` prop.
92 |
93 | ```jsx
94 | Hello
95 | ```
96 |
97 |
98 | ## Styled System Props
99 |
100 | In addition to the `sx` prop, several [Styled System][] props are provided as ergonomic shortcuts.
101 | These props allow you to quickly modify styles on a per-element basis throughout your application.
102 | This level of flexibility in your UI component API
103 | makes it easy to use values from your design system's constraints
104 | in situations that you might not have accounted for when creating your components.
105 |
106 | Because each component is based on the same base Box component,
107 | the props API for your entire design system can stay consistent,
108 | making it easier to *learn once, use everywhere.*
109 |
110 | ## Colors
111 |
112 | Use the `color` and `bg` (or `backgroundColor`) props to add styles based on the `theme.colors` scale.
113 |
114 | ```jsx live=true
115 |
116 | Hello
117 |
118 | ```
119 |
120 | ```jsx
121 | // Keys reference values in the color palette object
122 |
123 |
124 | // Background color can be set with the `bg` prop
125 |
126 |
127 | // Raw CSS values that do not map to a key in `theme.colors` can be used
128 |
129 | ```
130 |
131 | ## Margin and Padding
132 |
133 | Margin and padding can be added to any element based on the `theme.space` scale.
134 | The margin and padding props help promote consistency in layout
135 | without the need to add custom margin and padding declarations throughout an application.
136 | The margin and padding props use a shorthand syntax, similar to other OOCSS approaches and many CSS libraries.
137 |
138 | ```jsx live=true
139 |
145 | Hello
146 |
147 | ```
148 |
149 | - `m`: margin
150 | - `mt`: margin-top
151 | - `mr`: margin-right
152 | - `mb`: margin-bottom
153 | - `ml`: margin-left
154 | - `mx`: margin-left and margin-right
155 | - `my`: margin-top and margin-bottom
156 | - `p` : padding
157 | - `pt`: padding-top
158 | - `pr`: padding-right
159 | - `pb`: padding-bottom
160 | - `pl`: padding-left
161 | - `px`: padding-left and padding-right
162 | - `py`: padding-top and padding-bottom
163 |
164 | ```jsx
165 | // Numbers reference steps on the spacing scale
166 | // e.g. 8px
167 |
168 |
169 | // Numbers greater than the length of `theme.space.length` are converted to pixels
170 |
171 |
172 | // Negative values can be used to add negative margins
173 |
174 |
175 | // Strings can be used for other values
176 |
177 |
178 | // Arrays can be used for mobile-first responsive styles
179 |
180 | ```
181 |
182 | ## Typography
183 |
184 | Use the typography props to change text styles based on values defined in your theme.
185 |
186 | ```jsx live=true
187 |
192 | Hello
193 |
194 | ```
195 |
196 | - `fontSize`
197 | - `fontFamily`
198 | - `fontWeight`
199 | - `lineHeight`
200 | - `letterSpacing`
201 | - `textAlign`
202 | - `fontStyle`
203 |
204 | ## Layout
205 |
206 | Use layout props to change the width, height, display and other values on any element.
207 |
208 | ```jsx live=true
209 |
216 | Hello
217 |
218 | ```
219 |
220 | - `width`
221 | - `minWidth`
222 | - `maxWidth`
223 | - `height`
224 | - `minHeight`
225 | - `maxHeight`
226 | - `display`
227 | - `size` (width and height)
228 | - `verticalAlign`
229 | - `overflow`
230 |
231 | ### Width
232 |
233 | The `width` prop includes an additional ergonomic shorthand for applying percentage-based widths.
234 | Any fractional number from `0` to `1` will be converted to a percentage based width,
235 | allowing you to quickly define responsive grid layouts directly in the components where you need them.
236 |
237 | ```jsx
238 |
246 | ```
247 |
248 | ## Flexbox
249 |
250 | Use flexbox props to apply layout styles.
251 |
252 | ```jsx live=true
253 |
254 |
259 | Beep
260 |
261 |
262 | Boop
263 |
264 |
265 | ```
266 |
267 | - `alignItems`
268 | - `alignContent`
269 | - `justifyItems`
270 | - `justifyContent`
271 | - `flexWrap`
272 | - `flexDirection`
273 | - `flex`
274 | - `flexGrow`
275 | - `flexShrink`
276 | - `flexBasis`
277 | - `justifySelf`
278 | - `alignSelf`
279 | - `order`
280 |
281 | For a full reference of available props, see the [Reflexbox docs](/reflexbox#styled-system-props).
282 |
283 | [styled system]: https://styled-system.com
284 | [theme ui]: https://theme-ui.com
285 | [space]: https://styled-system.com/
286 | [color]: https://styled-system.com/
287 | [mdx]: https://mdxjs.com
288 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/recipes/avatar.mdx:
--------------------------------------------------------------------------------
1 | export const title = 'Avatar'
2 |
3 | # Avatar
4 |
5 | ```jsx live=true
6 |
14 | ```
15 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/recipes/background-image-card.mdx:
--------------------------------------------------------------------------------
1 |
2 | # Background Image Card
3 |
4 | ```jsx live=true
5 |
15 |
18 | Background Image
19 |
20 |
21 | ```
22 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/recipes/badge.mdx:
--------------------------------------------------------------------------------
1 | export const title = 'Badge'
2 |
3 | # Badge
4 |
5 | ```jsx live=true
6 |
15 | Badge
16 |
17 | ```
18 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/recipes/container.mdx:
--------------------------------------------------------------------------------
1 | export const title = 'Container'
2 |
3 | # Container
4 |
5 | ```jsx live=true
6 |
12 | Container
13 |
14 | ```
15 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/recipes/flexbox-align.mdx:
--------------------------------------------------------------------------------
1 |
2 | # Flexbox Align
3 |
4 | ```jsx live=true
5 |
6 |
7 |
12 | Hello
13 |
14 |
15 |
16 | Grid
17 |
18 |
19 | ```
20 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/recipes/flexbox-grid.mdx:
--------------------------------------------------------------------------------
1 | export const title = 'Flexbox Grid'
2 |
3 | # Flexbox Grid
4 |
5 | ```jsx live=true
6 |
7 |
8 |
9 | Half
10 |
11 |
12 |
13 |
14 | Half
15 |
16 |
17 |
18 | ```
19 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/recipes/flexbox-wrap.mdx:
--------------------------------------------------------------------------------
1 | export const title = 'Flexbox Wrap'
2 |
3 | # Flexbox Wrap
4 |
5 | ```jsx live=true
6 |
7 |
8 | 1/2
9 |
10 |
11 | 1/2
12 |
13 |
14 | 1/3
15 |
16 |
17 | 1/3
18 |
19 |
20 | 1/3
21 |
22 |
23 | 1/4
24 |
25 |
26 | 1/4
27 |
28 |
29 | 1/4
30 |
31 |
32 | 1/4
33 |
34 |
35 | ```
36 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/recipes/image-card.mdx:
--------------------------------------------------------------------------------
1 |
2 | # Image Card
3 |
4 | ```jsx live=true
5 |
6 |
7 |
8 |
9 | Image Card
10 |
11 |
12 |
13 | ```
14 |
15 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/recipes/index.mdx:
--------------------------------------------------------------------------------
1 | import { MDXProvider } from '@mdx-js/react'
2 | import { RecipeCard, Grid } from '../..'
3 | import FlexboxGrid from './flexbox-grid.mdx'
4 | import FlexboxWrap from './flexbox-wrap.mdx'
5 | import FlexboxAlign from './flexbox-align.mdx'
6 | import ImageCard from './image-card.mdx'
7 | import BackgroundImageCard from './background-image-card.mdx'
8 | import NavBar from './nav-bar.mdx'
9 | import VideoEmbed from './video-embed.mdx'
10 | import Container from './container.mdx'
11 |
12 | import Avatar from './avatar.mdx'
13 | import Badge from './badge.mdx'
14 | import NavLink from './nav-link.mdx'
15 |
16 | export const title = 'Recipes'
17 |
18 | # Recipes
19 |
20 | Quick copy-and-paste code examples using Rebass.
21 |
22 |
26 |
27 |
28 | -
29 | -
30 | -
31 | -
32 | -
33 | -
34 | -
35 | -
36 | -
37 | -
38 | -
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/recipes/nav-bar.mdx:
--------------------------------------------------------------------------------
1 |
2 | # Nav Bar
3 |
4 | ```jsx live=true
5 |
10 | Rebass
11 |
12 |
13 | Profile
14 |
15 |
16 | ```
17 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/recipes/nav-link.mdx:
--------------------------------------------------------------------------------
1 | export const title = 'Nav Link'
2 |
3 | # Nav Link
4 |
5 | ```jsx live=true
6 |
14 | Nav Link
15 |
16 | ```
17 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/recipes/video-embed.mdx:
--------------------------------------------------------------------------------
1 |
2 | # Video Embed
3 |
4 | ```jsx live=true
5 | iframe': {
13 | position: 'absolute',
14 | width: '100%',
15 | height: '100%',
16 | top: 0,
17 | bottom: 0,
18 | left: 0,
19 | border: 0
20 | }
21 | }}>
22 |
29 |
30 | ```
31 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/reflexbox.mdx:
--------------------------------------------------------------------------------
1 | import Readme from 'reflexbox/README.md'
2 |
3 | export const title = 'Reflexbox'
4 |
5 |
6 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/space.mdx:
--------------------------------------------------------------------------------
1 | import Readme from '@rebass/space/README.md'
2 | export const title = 'Space'
3 |
4 |
5 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/text.mdx:
--------------------------------------------------------------------------------
1 | export const title = 'Text'
2 |
3 | # Text
4 |
5 | Responsive typography component
6 |
7 | ```jsx live=true
8 |
12 | Text
13 |
14 | ```
15 |
16 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/theming.mdx:
--------------------------------------------------------------------------------
1 | export const title = 'Theming'
2 |
3 | # Theming
4 |
5 | Rebass components are built with themeability in mind.
6 | All colors, typographic styles, layout styles, and component variants can be completely customized with theming.
7 |
8 | ## ThemeProvider
9 |
10 | To apply themes to Rebass components, add a [ThemeProvider][] component to the root of your application and pass a `theme` object as a prop.
11 |
12 | If you're using Emotion by itself, install the `emotion-theming` package.
13 | If you're using Rebass with [Theme UI][], use its `ThemeProvider` or the `gatsby-plugin-theme-ui` package.
14 |
15 | ```jsx
16 | import React from 'react'
17 | import theme from './theme'
18 | import { ThemeProvider } from 'emotion-theming'
19 | // or for use with Theme UI:
20 | // import { ThemeProvider } from 'theme-ui'
21 |
22 | export default props =>
23 |
24 | {props.children}
25 |
26 | ```
27 |
28 | Rebass follows the [Theme Specification][],
29 | which allows you to define thematic values in a more portable format.
30 | Themes created for [Styled System][] or [Theme UI][] will work with Rebass with no additional configuration required.
31 | This also means that themes created for use with Rebass will work in other applications that follow the same specification.
32 |
33 | ## Example
34 |
35 | The following is an example theme, showing *some* of the design constraints that can be defined as scales,
36 | including colors, typography, layouts, and variants.
37 |
38 | ```js
39 | // example theme.js
40 | export default {
41 | breakpoints: ['40em', '52em', '64em'],
42 | fontSizes: [
43 | 12, 14, 16, 20, 24, 32, 48, 64
44 | ],
45 | colors: {
46 | blue: '#07c',
47 | lightgray: '#f6f6ff'
48 | },
49 | space: [
50 | 0, 4, 8, 16, 32, 64, 128, 256
51 | ],
52 | fonts: {
53 | body: 'system-ui, sans-serif',
54 | heading: 'inherit',
55 | monospace: 'Menlo, monospace',
56 | },
57 | fontWeights: {
58 | body: 400,
59 | heading: 700,
60 | bold: 700,
61 | },
62 | lineHeights: {
63 | body: 1.5,
64 | heading: 1.25,
65 | },
66 | shadows: {
67 | small: '0 0 4px rgba(0, 0, 0, .125)',
68 | large: '0 0 24px rgba(0, 0, 0, .125)'
69 | },
70 | variants: {
71 | },
72 | text: {
73 | },
74 | buttons: {
75 | primary: {
76 | color: 'white',
77 | bg: 'primary',
78 | }
79 | }
80 | }
81 | ```
82 |
83 | ## Preset
84 |
85 | To quickly get started without creating a custom theme, install the Rebass Preset package and use it in place of a custom theme.
86 |
87 | ```sh
88 | npm i @rebass/preset
89 | ```
90 |
91 | ```jsx
92 | import React from 'react'
93 | import { ThemeProvider } from 'emotion-theming'
94 | import preset from '@rebass/preset'
95 |
96 | export default props =>
97 |
98 | {props.children}
99 |
100 | ```
101 |
102 | ## Demo
103 |
104 | Edit the theme in the demo below to see how colors, space, and typographic scales affect the Button component.
105 |
106 | ```jsx live=true
107 |
119 |
120 |
121 | ```
122 |
123 | [theme specification]: https://github.com/system-ui/theme-specification
124 | [ThemeProvider]: https://www.styled-components.com/docs/advanced#theming
125 | [styled system]: https://github.com/jxnblk/styled-system
126 | [theme ui]: https://theme-ui.com
127 |
--------------------------------------------------------------------------------
/packages/docs/src/pages/variants.mdx:
--------------------------------------------------------------------------------
1 | export const title = 'Variants'
2 |
3 | # Variants
4 |
5 | All Rebass components accept a `variant` prop, which allows you to define stylistic variations in your theme and apply the styles on a per-element basis.
6 |
7 | For example, with the following defined in the theme object:
8 |
9 | ```js
10 | // example theme with variants
11 | export default {
12 | colors: {
13 | text: 'black',
14 | background: 'white',
15 | primary: 'tomato',
16 | },
17 | shadows: {
18 | card: '0 0 4px rgba(0, 0, 0, 0.125)',
19 | },
20 | variants: {
21 | card: {
22 | p: 2,
23 | bg: 'background',
24 | boxShadow: 'card',
25 | borderRadius: 2,
26 | },
27 | badge: {
28 | display: 'inline-block',
29 | p: 1,
30 | color: 'white',
31 | bg: 'primary',
32 | borderRadius: 2,
33 | }
34 | },
35 | }
36 | ```
37 |
38 | The `Box` component can use a variant style to render with preset card or badge styles.
39 |
40 | ```jsx live=true
41 |
42 | Card
43 |
44 | Badge
45 |
46 |
47 | ```
48 |
49 | By default, Rebass components will use style objects defined in `theme.variants`.
50 | The `Text` and `Heading` components use a custom `theme.text` object, and `Button` uses `theme.buttons`.
51 |
52 | Component | Theme Key | Default Variant
53 | ---|---|---
54 | `Box` | `variants` | N/A
55 | `Flex` | `variants` | N/A
56 | `Text` | `text` | N/A
57 | `Heading` | `text` | `heading`
58 | `Link` | `variants` | `link`
59 | `Button` | `buttons` | `primary`
60 | `Image` | `variants` | N/A
61 | `Card` | `variants` | `card`
62 |
63 | Any object in your theme can be used as a variant, and the values use dot notation for deeply nested values.
64 |
65 | ```jsx
66 | // example variant with dot notation
67 |
68 | ```
69 |
--------------------------------------------------------------------------------
/packages/docs/static/_redirects:
--------------------------------------------------------------------------------
1 | /Box /box
2 | /Flex /flex
3 | /Text /text
4 | /Heading /heading
5 | /Button /button
6 | /Link /link
7 | /Image /image
8 | /Card /card
9 | /advanced /guides
10 | /grid /reflexbox
11 |
--------------------------------------------------------------------------------
/packages/docs/static/card.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rebassjs/rebass/31726a00fc81371b5cde9eb35fd01cabc5a21a58/packages/docs/static/card.png
--------------------------------------------------------------------------------
/packages/docs/static/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rebassjs/rebass/31726a00fc81371b5cde9eb35fd01cabc5a21a58/packages/docs/static/icon.png
--------------------------------------------------------------------------------
/packages/docs/static/logo.svg:
--------------------------------------------------------------------------------
1 |
2 |
4 |
17 |
--------------------------------------------------------------------------------
/packages/forms/.gitignore:
--------------------------------------------------------------------------------
1 | styled-components
2 | dist
3 |
--------------------------------------------------------------------------------
/packages/forms/.npmignore:
--------------------------------------------------------------------------------
1 | test
2 |
--------------------------------------------------------------------------------
/packages/forms/README.md:
--------------------------------------------------------------------------------
1 |
2 | # @rebass/forms
3 |
4 | Accessible and themeable form components for use with Rebass or Theme UI.
5 |
6 | ```sh
7 | npm i @rebass/forms
8 | ```
9 |
10 | ```jsx
11 | import React from 'react'
12 | import { Box, Flex } from 'rebass'
13 | import {
14 | Label,
15 | Input,
16 | Select,
17 | Textarea,
18 | Radio,
19 | Checkbox,
20 | } from '@rebass/forms'
21 |
22 | export default () =>
23 | e.preventDefault()}
26 | py={3}>
27 |
28 |
29 |
30 |
35 |
36 |
37 |
38 |
48 |
49 |
50 |
51 |
60 |
68 |
75 |
76 |
79 |
80 |
81 |
82 | ```
83 |
84 | See https://rebassjs.org/forms for full documentation.
85 |
86 |
--------------------------------------------------------------------------------
/packages/forms/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@rebass/forms",
3 | "version": "4.0.6",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "scripts": {
7 | "prepare": "rebass-bundler"
8 | },
9 | "dependencies": {
10 | "reflexbox": "^4.0.6"
11 | },
12 | "repository": "rebassjs/rebass",
13 | "bugs": {
14 | "url": "https://github.com/rebassjs/rebass/issues"
15 | },
16 | "license": "MIT",
17 | "publishConfig": {
18 | "access": "public"
19 | },
20 | "gitHead": "f0f01843e9fb63ca69112d7e97a1451b27ee9e6c"
21 | }
22 |
--------------------------------------------------------------------------------
/packages/forms/src/index.js:
--------------------------------------------------------------------------------
1 | import React, { forwardRef } from 'react'
2 | import { Box, Flex } from 'reflexbox'
3 | import { props as systemProps } from '@styled-system/should-forward-prop'
4 |
5 | const rebassProps = [
6 | ...systemProps,
7 | 'sx',
8 | 'variant',
9 | ]
10 |
11 | const PRE = new RegExp(`^(${rebassProps.join('|')})$`)
12 | const MRE = /^m[trblxy]?$/
13 |
14 | const getProps = (test) => (props) => {
15 | const next = {}
16 | for (const key in props) {
17 | if (test(key || '')) next[key] = props[key]
18 | }
19 | return next
20 | }
21 |
22 | const getSystemProps = getProps(k => PRE.test(k))
23 | const getMarginProps = getProps(k => MRE.test(k))
24 | const omitMarginProps = getProps(k => !MRE.test(k))
25 |
26 | const SVG = ({ size = 24, ...props }) =>
27 |
36 |
37 | export const Label = forwardRef((props, ref) =>
38 |
48 | )
49 |
50 | export const Input = forwardRef((props, ref) =>
51 |
71 | )
72 |
73 | const DownArrow = props =>
74 |
77 |
78 | export const Select = forwardRef((props, ref) =>
79 |
80 |
99 |
106 |
107 | )
108 |
109 | export const Textarea = forwardRef((props, ref) =>
110 |
129 | )
130 |
131 | const RadioChecked = props =>
132 |
135 |
136 | const RadioUnchecked = props =>
137 |
140 |
141 | const RadioIcon = props =>
142 | <>
143 |
152 |
161 | >
162 |
163 | export const Radio = forwardRef(({
164 | className,
165 | sx,
166 | variant = 'radio',
167 | ...props
168 | }, ref) => (
169 |
170 |
184 |
204 |
205 | ))
206 |
207 | const CheckboxChecked = props =>
208 |
211 |
212 | const CheckboxUnchecked = props =>
213 |
216 |
217 | const CheckboxIcon = props =>
218 | <>
219 |
228 |
237 | >
238 |
239 | export const Checkbox= forwardRef(({
240 | className,
241 | sx,
242 | variant = 'checkbox',
243 | ...props
244 | }, ref) =>
245 |
246 |
260 |
281 |
282 | )
283 |
284 | export const Slider = forwardRef(({
285 | ...props
286 | }, ref) =>
287 |
319 | )
320 |
321 | export const Switch = forwardRef(({
322 | checked,
323 | ...props
324 | }, ref) =>
325 |
353 |
373 |
374 | )
375 |
--------------------------------------------------------------------------------
/packages/forms/test/__snapshots__/index.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`Checkbox renders 1`] = `
4 | .emotion-3 {
5 | box-sizing: border-box;
6 | margin: 0;
7 | min-width: 0;
8 | }
9 |
10 | .emotion-0 {
11 | box-sizing: border-box;
12 | margin: 0;
13 | min-width: 0;
14 | position: absolute;
15 | opacity: 0;
16 | z-index: -1;
17 | width: 1px;
18 | height: 1px;
19 | overflow: hidden;
20 | }
21 |
22 | .emotion-1 {
23 | box-sizing: border-box;
24 | margin: 0;
25 | min-width: 0;
26 | display: none;
27 | width: 24px;
28 | height: 24px;
29 | box-sizing: border-box;
30 | margin: 0;
31 | min-width: 0;
32 | margin-right: 8px;
33 | border-radius: 4px;
34 | color: gray;
35 | }
36 |
37 | input:checked ~ .emotion-1 {
38 | display: block;
39 | }
40 |
41 | input:checked ~ .emotion-1 {
42 | color: primary;
43 | }
44 |
45 | input:focus ~ .emotion-1 {
46 | color: primary;
47 | background-color: highlight;
48 | }
49 |
50 | .emotion-2 {
51 | box-sizing: border-box;
52 | margin: 0;
53 | min-width: 0;
54 | display: block;
55 | width: 24px;
56 | height: 24px;
57 | box-sizing: border-box;
58 | margin: 0;
59 | min-width: 0;
60 | margin-right: 8px;
61 | border-radius: 4px;
62 | color: gray;
63 | }
64 |
65 | input:checked ~ .emotion-2 {
66 | display: none;
67 | }
68 |
69 | input:checked ~ .emotion-2 {
70 | color: primary;
71 | }
72 |
73 | input:focus ~ .emotion-2 {
74 | color: primary;
75 | background-color: highlight;
76 | }
77 |
78 |
81 |
85 |
96 |
107 |
108 | `;
109 |
110 | exports[`Input renders 1`] = `
111 | .emotion-0 {
112 | box-sizing: border-box;
113 | margin: 0;
114 | min-width: 0;
115 | display: block;
116 | width: 100%;
117 | padding: 8px;
118 | -webkit-appearance: none;
119 | -moz-appearance: none;
120 | appearance: none;
121 | font-size: inherit;
122 | line-height: inherit;
123 | border: 1px solid;
124 | border-radius: default;
125 | color: inherit;
126 | background-color: transparent;
127 | }
128 |
129 |
133 | `;
134 |
135 | exports[`Label renders 1`] = `
136 | .emotion-0 {
137 | box-sizing: border-box;
138 | margin: 0;
139 | min-width: 0;
140 | width: 100%;
141 | display: -webkit-box;
142 | display: -webkit-flex;
143 | display: -ms-flexbox;
144 | display: flex;
145 | }
146 |
147 |
150 | `;
151 |
152 | exports[`Radio renders 1`] = `
153 | .emotion-3 {
154 | box-sizing: border-box;
155 | margin: 0;
156 | min-width: 0;
157 | }
158 |
159 | .emotion-0 {
160 | box-sizing: border-box;
161 | margin: 0;
162 | min-width: 0;
163 | position: absolute;
164 | opacity: 0;
165 | z-index: -1;
166 | width: 1px;
167 | height: 1px;
168 | overflow: hidden;
169 | }
170 |
171 | .emotion-1 {
172 | box-sizing: border-box;
173 | margin: 0;
174 | min-width: 0;
175 | display: none;
176 | width: 24px;
177 | height: 24px;
178 | box-sizing: border-box;
179 | margin: 0;
180 | min-width: 0;
181 | margin-right: 8px;
182 | border-radius: 9999px;
183 | color: gray;
184 | }
185 |
186 | input:checked ~ .emotion-1 {
187 | display: block;
188 | }
189 |
190 | input:checked ~ .emotion-1 {
191 | color: primary;
192 | }
193 |
194 | input:focus ~ .emotion-1 {
195 | background-color: highlight;
196 | }
197 |
198 | .emotion-2 {
199 | box-sizing: border-box;
200 | margin: 0;
201 | min-width: 0;
202 | display: block;
203 | width: 24px;
204 | height: 24px;
205 | box-sizing: border-box;
206 | margin: 0;
207 | min-width: 0;
208 | margin-right: 8px;
209 | border-radius: 9999px;
210 | color: gray;
211 | }
212 |
213 | input:checked ~ .emotion-2 {
214 | display: none;
215 | }
216 |
217 | input:checked ~ .emotion-2 {
218 | color: primary;
219 | }
220 |
221 | input:focus ~ .emotion-2 {
222 | background-color: highlight;
223 | }
224 |
225 |
228 |
232 |
243 |
254 |
255 | `;
256 |
257 | exports[`Select renders 1`] = `
258 | .emotion-0 {
259 | box-sizing: border-box;
260 | margin: 0;
261 | min-width: 0;
262 | display: block;
263 | width: 100%;
264 | padding: 8px;
265 | -webkit-appearance: none;
266 | -moz-appearance: none;
267 | appearance: none;
268 | font-size: inherit;
269 | line-height: inherit;
270 | border: 1px solid;
271 | border-radius: default;
272 | color: inherit;
273 | background-color: transparent;
274 | }
275 |
276 | .emotion-2 {
277 | box-sizing: border-box;
278 | margin: 0;
279 | min-width: 0;
280 | display: -webkit-box;
281 | display: -webkit-flex;
282 | display: -ms-flexbox;
283 | display: flex;
284 | }
285 |
286 | .emotion-1 {
287 | box-sizing: border-box;
288 | margin: 0;
289 | min-width: 0;
290 | margin-left: -28px;
291 | -webkit-align-self: center;
292 | -ms-flex-item-align: center;
293 | align-self: center;
294 | pointer-events: none;
295 | width: 24px;
296 | height: 24px;
297 | }
298 |
299 |
302 |
305 |
315 |
316 | `;
317 |
318 | exports[`Textarea renders 1`] = `
319 | .emotion-0 {
320 | box-sizing: border-box;
321 | margin: 0;
322 | min-width: 0;
323 | display: block;
324 | width: 100%;
325 | padding: 8px;
326 | -webkit-appearance: none;
327 | -moz-appearance: none;
328 | appearance: none;
329 | font-size: inherit;
330 | line-height: inherit;
331 | border: 1px solid;
332 | border-radius: default;
333 | color: inherit;
334 | background-color: transparent;
335 | }
336 |
337 |
340 | `;
341 |
--------------------------------------------------------------------------------
/packages/forms/test/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import renderer from 'react-test-renderer'
3 | import { render } from '@testing-library/react'
4 | import { matchers } from 'jest-emotion'
5 | import {
6 | Label,
7 | Input,
8 | Select,
9 | Textarea,
10 | Radio,
11 | Checkbox
12 | } from '../src'
13 |
14 | expect.extend(matchers)
15 |
16 | const renderJSON = el => renderer.create(el).toJSON()
17 |
18 | describe('Label', () => {
19 | test('renders', () => {
20 | const json = renderJSON(
21 |
22 | )
23 | expect(json).toMatchSnapshot()
24 | })
25 | test('passes ref', () => {
26 | const ref = React.createRef(null)
27 | render(
28 |
29 | )
30 | expect(ref.current.tagName).toBe('LABEL')
31 | })
32 | })
33 |
34 | describe('Input', () => {
35 | test('renders', () => {
36 | const json = renderJSON(
37 |
38 | )
39 | expect(json).toMatchSnapshot()
40 | })
41 | test('passes ref', () => {
42 | const ref = React.createRef(null)
43 | render(
44 |
45 | )
46 | expect(ref.current.tagName).toBe('INPUT')
47 | })
48 | })
49 |
50 | describe('Select', () => {
51 | test('renders', () => {
52 | const json = renderJSON(
53 |
54 | )
55 | expect(json).toMatchSnapshot()
56 | })
57 | test('passes ref', () => {
58 | const ref = React.createRef(null)
59 | render(
60 |
61 | )
62 | expect(ref.current.tagName).toBe('SELECT')
63 | })
64 |
65 | test('margin props are applied to the wrapping element', () => {
66 | const json = renderJSON(
67 |
68 | )
69 | expect(json).toHaveStyleRule('margin-top', '8px')
70 | expect(json).toHaveStyleRule('margin-bottom', '16px')
71 | })
72 | })
73 |
74 | describe('Textarea', () => {
75 | test('renders', () => {
76 | const json = renderJSON(
77 |
78 | )
79 | expect(json).toMatchSnapshot()
80 | })
81 | test('passes ref', () => {
82 | const ref = React.createRef(null)
83 | render(
84 |
85 | )
86 | expect(ref.current.tagName).toBe('TEXTAREA')
87 | })
88 | })
89 |
90 | describe('Radio', () => {
91 | test('renders', () => {
92 | const json = renderJSON(
93 |
94 | )
95 | expect(json).toMatchSnapshot()
96 | })
97 | test('passes ref', () => {
98 | const ref = React.createRef(null)
99 | render(
100 |
101 | )
102 | expect(ref.current.tagName).toBe('INPUT')
103 | expect(ref.current.type).toBe('radio')
104 | })
105 | })
106 |
107 | describe('Checkbox', () => {
108 | test('renders', () => {
109 | const json = renderJSON(
110 |
111 | )
112 | expect(json).toMatchSnapshot()
113 | })
114 | test('passes ref', () => {
115 | const ref = React.createRef(null)
116 | render(
117 |
118 | )
119 | expect(ref.current.tagName).toBe('INPUT')
120 | expect(ref.current.type).toBe('checkbox')
121 | })
122 | })
123 |
--------------------------------------------------------------------------------
/packages/layout/.gitignore:
--------------------------------------------------------------------------------
1 | dist
2 | styled-components
3 |
--------------------------------------------------------------------------------
/packages/layout/.npmignore:
--------------------------------------------------------------------------------
1 | test
2 | babel.config.js
3 |
--------------------------------------------------------------------------------
/packages/layout/README.md:
--------------------------------------------------------------------------------
1 |
2 | @rebass/layout
3 |
4 | https://rebassjs.org/layout
5 |
--------------------------------------------------------------------------------
/packages/layout/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@rebass/layout",
3 | "version": "4.0.6",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "scripts": {
7 | "prepare": "rebass-bundler"
8 | },
9 | "dependencies": {
10 | "reflexbox": "^4.0.6"
11 | },
12 | "repository": "rebassjs/rebass",
13 | "license": "MIT",
14 | "publishConfig": {
15 | "access": "public"
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/packages/layout/src/index.js:
--------------------------------------------------------------------------------
1 | import React, { forwardRef } from 'react'
2 | import { Box } from 'reflexbox'
3 |
4 | const px = n => typeof n === 'number' ? n + 'px' : n
5 |
6 | const widthToColumns = width => Array.isArray(width)
7 | ? width.map(widthToColumns)
8 | : !!width && `repeat(auto-fit, minmax(${px(width)}, 1fr))`
9 |
10 | const countToColumns = n => Array.isArray(n)
11 | ? n.map(countToColumns)
12 | : !!n && `repeat(${n}, 1fr)`
13 |
14 | export const Tiles = forwardRef(({
15 | width,
16 | columns,
17 | gap = 3,
18 | ...props
19 | }, ref) => {
20 | const gridTemplateColumns = !!width
21 | ? widthToColumns(width)
22 | : countToColumns(columns)
23 | return (
24 |
35 | )
36 | })
37 |
--------------------------------------------------------------------------------
/packages/preset-material/LICENSE.md:
--------------------------------------------------------------------------------
1 | # The MIT License (MIT)
2 | Copyright (c) 2015 – 2019 Brent Jackson
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 |
6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 |
8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 |
10 |
--------------------------------------------------------------------------------
/packages/preset-material/README.md:
--------------------------------------------------------------------------------
1 |
2 | # @rebass/preset-material
3 |
4 | Material Design theme preset for use with [Rebass][]
5 |
6 | ```sh
7 | npm i @rebass/preset-material
8 | ```
9 |
10 | ## Usage
11 |
12 | For general usage with [Emotion][], pass the theme preset to Emotion's `ThemeProvider` component at the root of your application.
13 |
14 | ```jsx
15 | import React from 'react'
16 | import { ThemeProvider } from 'emotion-theming'
17 | import theme from '@rebass/preset-material'
18 |
19 | export default props =>
20 |
21 | {props.children}
22 |
23 | ```
24 |
25 | For use with [Theme UI][], import the `ThemeProvider` from `theme-ui`.
26 |
27 | ```jsx
28 | import { ThemeProvider } from 'theme-ui'
29 | ```
30 |
31 | Or, if you're using `gatsby-plugin-theme-ui`, export the theme from `src/gatsby-plugin-theme-ui/index.js`.
32 |
33 | ```js
34 | // src/gatsby-plugin-theme-ui/index.js
35 | import preset from '@rebass/preset-material'
36 |
37 | export default {
38 | ...preset
39 | }
40 | ```
41 |
42 | [MIT License](LICENSE.md)
43 |
44 | [rebass]: https://rebassjs.org
45 | [emotion]: https://emotion.sh
46 | [theme ui]: https://theme-ui.com
47 |
--------------------------------------------------------------------------------
/packages/preset-material/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@rebass/preset-material",
3 | "version": "4.0.5",
4 | "description": "Material Design theme preset for use with Rebass",
5 | "main": "dist/index.js",
6 | "scripts": {
7 | "prepare": "babel src -d dist --root-mode upward",
8 | "watch": "babel src -d dist --watch --root-mode upward"
9 | },
10 | "keywords": [
11 | "react",
12 | "react-component",
13 | "ui",
14 | "design-system",
15 | "styled-system",
16 | "emotion",
17 | "theming",
18 | "material-design",
19 | "theme-ui"
20 | ],
21 | "author": "Brent Jackson",
22 | "repository": "rebassjs/rebass",
23 | "license": "MIT",
24 | "publishConfig": {
25 | "access": "public"
26 | },
27 | "gitHead": "f0f01843e9fb63ca69112d7e97a1451b27ee9e6c"
28 | }
29 |
--------------------------------------------------------------------------------
/packages/preset-material/src/index.js:
--------------------------------------------------------------------------------
1 | // material theme preset
2 | // work-in-progress
3 |
4 | // references
5 | // - https://material.io/design/typography/the-type-system.html#type-scale
6 |
7 | export const preset = {
8 | googleFonts: 'https://fonts.googleapis.com/css?family=Roboto+Mono|Roboto:400,700&display=swap',
9 | colors: {
10 | text: '#000',
11 | background: '#fff',
12 | primary: '#6200ee',
13 | secondary: '#03dac6',
14 | muted: '#f6f6f6',
15 | gray: '#555',
16 | },
17 | fonts: {
18 | body: 'Roboto, sans-serif',
19 | heading: 'inherit',
20 | monospace: '"Roboto Mono", monospace',
21 | },
22 | fontSizes: [
23 | 10, 12, 14, 16, 20, 24, 34, 48, 60, 96
24 | ],
25 | fontWeights: {
26 | body: 400,
27 | heading: 400,
28 | bold: 700,
29 | },
30 | lineHeights: {
31 | body: 1.5,
32 | heading: 1.2,
33 | },
34 | space: [0, 4, 8, 16, 32, 64, 128, 256, 512],
35 | sizes: {
36 | icon: 24,
37 | avatar: 48,
38 | },
39 | radii: {
40 | default: 4,
41 | circle: 99999,
42 | },
43 | shadows: {
44 | // source: https://medium.com/@Florian/freebie-google-material-design-shadow-helper-2a0501295a2d
45 | 1: '0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24)',
46 | 2: '0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23)',
47 | 3: '0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23)',
48 | 4: '0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22)',
49 | 5: '0 19px 38px rgba(0,0,0,0.30), 0 15px 12px rgba(0,0,0,0.22)',
50 | },
51 | // rebass variants
52 | text: {
53 | heading: {
54 | fontFamily: 'heading',
55 | lineHeight: 'heading',
56 | fontWeight: 'heading',
57 | },
58 | display: {
59 | fontFamily: 'heading',
60 | fontWeight: 'heading',
61 | lineHeight: 'heading',
62 | fontSize: [ 6, 7 ],
63 | },
64 | caps: {
65 | textTransform: 'uppercase',
66 | letterSpacing: '0.1em',
67 | },
68 | },
69 | variants: {
70 | avatar: {
71 | width: 'avatar',
72 | height: 'avatar',
73 | borderRadius: 'circle',
74 | },
75 | card: {
76 | p: 2,
77 | bg: 'background',
78 | boxShadow: 2,
79 | },
80 | link: {
81 | color: 'primary',
82 | },
83 | nav: {
84 | variant: 'text.caps',
85 | fontSize: 1,
86 | fontWeight: 'bold',
87 | display: 'inline-block',
88 | p: 2,
89 | color: 'inherit',
90 | textDecoration: 'none',
91 | ':hover,:focus,.active': {
92 | color: 'primary',
93 | }
94 | },
95 | },
96 | buttons: {
97 | primary: {
98 | variant: 'text.caps',
99 | fontSize: 2,
100 | fontWeight: 'body',
101 | color: 'background',
102 | bg: 'primary',
103 | borderRadius: 'default',
104 | },
105 | outline: {
106 | variant: 'buttons.primary',
107 | color: 'primary',
108 | bg: 'transparent',
109 | boxShadow: 'inset 0 0 2px',
110 | },
111 | secondary: {
112 | variant: 'buttons.primary',
113 | color: 'background',
114 | bg: 'secondary',
115 | },
116 | },
117 | styles: {
118 | root: {
119 | fontFamily: 'body',
120 | fontWeight: 'body',
121 | lineHeight: 'body',
122 | },
123 | },
124 | }
125 |
126 | export default preset
127 |
--------------------------------------------------------------------------------
/packages/preset-material/test/__snapshots__/index.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`snapshot 1`] = `
4 | Object {
5 | "buttons": Object {
6 | "outline": Object {
7 | "bg": "transparent",
8 | "boxShadow": "inset 0 0 2px",
9 | "color": "primary",
10 | "variant": "buttons.primary",
11 | },
12 | "primary": Object {
13 | "bg": "primary",
14 | "borderRadius": "default",
15 | "color": "background",
16 | "fontSize": 2,
17 | "fontWeight": "body",
18 | "variant": "text.caps",
19 | },
20 | "secondary": Object {
21 | "bg": "secondary",
22 | "color": "background",
23 | "variant": "buttons.primary",
24 | },
25 | },
26 | "colors": Object {
27 | "background": "#fff",
28 | "gray": "#555",
29 | "muted": "#f6f6f6",
30 | "primary": "#6200ee",
31 | "secondary": "#03dac6",
32 | "text": "#000",
33 | },
34 | "fontSizes": Array [
35 | 10,
36 | 12,
37 | 14,
38 | 16,
39 | 20,
40 | 24,
41 | 34,
42 | 48,
43 | 60,
44 | 96,
45 | ],
46 | "fontWeights": Object {
47 | "body": 400,
48 | "bold": 700,
49 | "heading": 400,
50 | },
51 | "fonts": Object {
52 | "body": "Roboto, sans-serif",
53 | "heading": "inherit",
54 | "monospace": "\\"Roboto Mono\\", monospace",
55 | },
56 | "googleFonts": "https://fonts.googleapis.com/css?family=Roboto+Mono|Roboto:400,700&display=swap",
57 | "lineHeights": Object {
58 | "body": 1.5,
59 | "heading": 1.2,
60 | },
61 | "radii": Object {
62 | "circle": 99999,
63 | "default": 4,
64 | },
65 | "shadows": Object {
66 | "1": "0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24)",
67 | "2": "0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23)",
68 | "3": "0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23)",
69 | "4": "0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22)",
70 | "5": "0 19px 38px rgba(0,0,0,0.30), 0 15px 12px rgba(0,0,0,0.22)",
71 | },
72 | "sizes": Object {
73 | "avatar": 48,
74 | "icon": 24,
75 | },
76 | "space": Array [
77 | 0,
78 | 4,
79 | 8,
80 | 16,
81 | 32,
82 | 64,
83 | 128,
84 | 256,
85 | 512,
86 | ],
87 | "styles": Object {
88 | "root": Object {
89 | "fontFamily": "body",
90 | "fontWeight": "body",
91 | "lineHeight": "body",
92 | },
93 | },
94 | "text": Object {
95 | "caps": Object {
96 | "letterSpacing": "0.1em",
97 | "textTransform": "uppercase",
98 | },
99 | "display": Object {
100 | "fontFamily": "heading",
101 | "fontSize": Array [
102 | 6,
103 | 7,
104 | ],
105 | "fontWeight": "heading",
106 | "lineHeight": "heading",
107 | },
108 | "heading": Object {
109 | "fontFamily": "heading",
110 | "fontWeight": "heading",
111 | "lineHeight": "heading",
112 | },
113 | },
114 | "variants": Object {
115 | "avatar": Object {
116 | "borderRadius": "circle",
117 | "height": "avatar",
118 | "width": "avatar",
119 | },
120 | "card": Object {
121 | "bg": "background",
122 | "boxShadow": 2,
123 | "p": 2,
124 | },
125 | "link": Object {
126 | "color": "primary",
127 | },
128 | "nav": Object {
129 | ":hover,:focus,.active": Object {
130 | "color": "primary",
131 | },
132 | "color": "inherit",
133 | "display": "inline-block",
134 | "fontSize": 1,
135 | "fontWeight": "bold",
136 | "p": 2,
137 | "textDecoration": "none",
138 | "variant": "text.caps",
139 | },
140 | },
141 | }
142 | `;
143 |
--------------------------------------------------------------------------------
/packages/preset-material/test/index.js:
--------------------------------------------------------------------------------
1 | import preset from '../src'
2 |
3 | test('snapshot', () => {
4 | expect(preset).toMatchSnapshot()
5 | })
6 |
--------------------------------------------------------------------------------
/packages/preset/LICENSE.md:
--------------------------------------------------------------------------------
1 | # The MIT License (MIT)
2 | Copyright (c) 2015 – 2019 Brent Jackson
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 |
6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 |
8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 |
10 |
--------------------------------------------------------------------------------
/packages/preset/README.md:
--------------------------------------------------------------------------------
1 |
2 | # @rebass/preset
3 |
4 | Base theme preset for use with [Rebass][]
5 |
6 | ```sh
7 | npm i @rebass/preset
8 | ```
9 |
10 | ## Usage
11 |
12 | For general usage with [Emotion][], pass the theme preset to Emotion's `ThemeProvider` component at the root of your application.
13 |
14 | ```jsx
15 | import React from 'react'
16 | import { ThemeProvider } from 'emotion-theming'
17 | import theme from '@rebass/preset'
18 |
19 | export default props =>
20 |
21 | {props.children}
22 |
23 | ```
24 |
25 | For use with [Theme UI][], import the `ThemeProvider` from `theme-ui`.
26 |
27 | ```jsx
28 | import { ThemeProvider } from 'theme-ui'
29 | ```
30 |
31 | Or, if you're using `gatsby-plugin-theme-ui`, export the theme from `src/gatsby-plugin-theme-ui/index.js`.
32 |
33 | ```js
34 | // src/gatsby-plugin-theme-ui/index.js
35 | import preset from '@rebass/preset'
36 |
37 | export default {
38 | ...preset
39 | }
40 | ```
41 |
42 | ## Customizing
43 |
44 | The base theme object can be customized by using either `deepmerge` or `lodash.merge` to deeply merge objects.
45 |
46 | ```js
47 | import merge from 'lodash.merge'
48 | import preset from '@rebass/preset'
49 |
50 | export default merge(preset, {
51 | colors: {
52 | // custom primary color
53 | primary: 'tomato',
54 | }
55 | })
56 | ```
57 |
58 | [MIT License](LICENSE.md)
59 |
60 | [rebass]: https://rebassjs.org
61 | [emotion]: https://emotion.sh
62 | [theme ui]: https://theme-ui.com
63 |
--------------------------------------------------------------------------------
/packages/preset/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@rebass/preset",
3 | "version": "4.0.5",
4 | "description": "Base theme preset for use with Rebass",
5 | "main": "dist/index.js",
6 | "scripts": {
7 | "prepare": "babel src -d dist --root-mode upward",
8 | "watch": "babel src -d dist --watch --root-mode upward"
9 | },
10 | "keywords": [
11 | "react",
12 | "react-component",
13 | "ui",
14 | "design-system",
15 | "styled-system",
16 | "styled-components",
17 | "emotion",
18 | "theming",
19 | "theme-ui"
20 | ],
21 | "author": "Brent Jackson",
22 | "repository": "rebassjs/rebass",
23 | "license": "MIT",
24 | "publishConfig": {
25 | "access": "public"
26 | },
27 | "gitHead": "f0f01843e9fb63ca69112d7e97a1451b27ee9e6c"
28 | }
29 |
--------------------------------------------------------------------------------
/packages/preset/src/index.js:
--------------------------------------------------------------------------------
1 | // default theme preset
2 |
3 | export const preset = {
4 | colors: {
5 | text: '#000',
6 | background: '#fff',
7 | primary: '#07c',
8 | secondary: '#30c',
9 | muted: '#f6f6f9',
10 | gray: '#dddddf',
11 | highlight: 'hsla(205, 100%, 40%, 0.125)',
12 | },
13 | fonts: {
14 | body: 'system-ui, sans-serif',
15 | heading: 'inherit',
16 | monospace: 'Menlo, monospace',
17 | },
18 | fontSizes: [
19 | 12, 14, 16, 20, 24, 32, 48, 64, 96
20 | ],
21 | fontWeights: {
22 | body: 400,
23 | heading: 700,
24 | bold: 700,
25 | },
26 | lineHeights: {
27 | body: 1.5,
28 | heading: 1.25,
29 | },
30 | space: [0, 4, 8, 16, 32, 64, 128, 256, 512],
31 | sizes: {
32 | avatar: 48,
33 | },
34 | radii: {
35 | default: 4,
36 | circle: 99999,
37 | },
38 | shadows: {
39 | card: '0 0 4px rgba(0, 0, 0, .125)',
40 | },
41 | // rebass variants
42 | text: {
43 | heading: {
44 | fontFamily: 'heading',
45 | lineHeight: 'heading',
46 | fontWeight: 'heading',
47 | },
48 | display: {
49 | fontFamily: 'heading',
50 | fontWeight: 'heading',
51 | lineHeight: 'heading',
52 | fontSize: [ 5, 6, 7 ],
53 | },
54 | caps: {
55 | textTransform: 'uppercase',
56 | letterSpacing: '0.1em',
57 | },
58 | },
59 | variants: {
60 | avatar: {
61 | width: 'avatar',
62 | height: 'avatar',
63 | borderRadius: 'circle',
64 | },
65 | card: {
66 | p: 2,
67 | bg: 'background',
68 | boxShadow: 'card',
69 | },
70 | link: {
71 | color: 'primary',
72 | },
73 | nav: {
74 | fontSize: 1,
75 | fontWeight: 'bold',
76 | display: 'inline-block',
77 | p: 2,
78 | color: 'inherit',
79 | textDecoration: 'none',
80 | ':hover,:focus,.active': {
81 | color: 'primary',
82 | }
83 | },
84 | },
85 | buttons: {
86 | primary: {
87 | fontSize: 2,
88 | fontWeight: 'bold',
89 | color: 'background',
90 | bg: 'primary',
91 | borderRadius: 'default',
92 | },
93 | outline: {
94 | variant: 'buttons.primary',
95 | color: 'primary',
96 | bg: 'transparent',
97 | boxShadow: 'inset 0 0 2px',
98 | },
99 | secondary: {
100 | variant: 'buttons.primary',
101 | color: 'background',
102 | bg: 'secondary',
103 | },
104 | },
105 | styles: {
106 | root: {
107 | fontFamily: 'body',
108 | fontWeight: 'body',
109 | lineHeight: 'body',
110 | },
111 | },
112 | }
113 |
114 | export default preset
115 |
--------------------------------------------------------------------------------
/packages/preset/test/__snapshots__/index.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`snapshot 1`] = `
4 | Object {
5 | "buttons": Object {
6 | "outline": Object {
7 | "bg": "transparent",
8 | "boxShadow": "inset 0 0 2px",
9 | "color": "primary",
10 | "variant": "buttons.primary",
11 | },
12 | "primary": Object {
13 | "bg": "primary",
14 | "borderRadius": "default",
15 | "color": "background",
16 | "fontSize": 2,
17 | "fontWeight": "bold",
18 | },
19 | "secondary": Object {
20 | "bg": "secondary",
21 | "color": "background",
22 | "variant": "buttons.primary",
23 | },
24 | },
25 | "colors": Object {
26 | "background": "#fff",
27 | "gray": "#dddddf",
28 | "highlight": "hsla(205, 100%, 40%, 0.125)",
29 | "muted": "#f6f6f9",
30 | "primary": "#07c",
31 | "secondary": "#30c",
32 | "text": "#000",
33 | },
34 | "fontSizes": Array [
35 | 12,
36 | 14,
37 | 16,
38 | 20,
39 | 24,
40 | 32,
41 | 48,
42 | 64,
43 | 96,
44 | ],
45 | "fontWeights": Object {
46 | "body": 400,
47 | "bold": 700,
48 | "heading": 700,
49 | },
50 | "fonts": Object {
51 | "body": "system-ui, sans-serif",
52 | "heading": "inherit",
53 | "monospace": "Menlo, monospace",
54 | },
55 | "lineHeights": Object {
56 | "body": 1.5,
57 | "heading": 1.25,
58 | },
59 | "radii": Object {
60 | "circle": 99999,
61 | "default": 4,
62 | },
63 | "shadows": Object {
64 | "card": "0 0 4px rgba(0, 0, 0, .125)",
65 | },
66 | "sizes": Object {
67 | "avatar": 48,
68 | },
69 | "space": Array [
70 | 0,
71 | 4,
72 | 8,
73 | 16,
74 | 32,
75 | 64,
76 | 128,
77 | 256,
78 | 512,
79 | ],
80 | "styles": Object {
81 | "root": Object {
82 | "fontFamily": "body",
83 | "fontWeight": "body",
84 | "lineHeight": "body",
85 | },
86 | },
87 | "text": Object {
88 | "caps": Object {
89 | "letterSpacing": "0.1em",
90 | "textTransform": "uppercase",
91 | },
92 | "display": Object {
93 | "fontFamily": "heading",
94 | "fontSize": Array [
95 | 5,
96 | 6,
97 | 7,
98 | ],
99 | "fontWeight": "heading",
100 | "lineHeight": "heading",
101 | },
102 | "heading": Object {
103 | "fontFamily": "heading",
104 | "fontWeight": "heading",
105 | "lineHeight": "heading",
106 | },
107 | },
108 | "variants": Object {
109 | "avatar": Object {
110 | "borderRadius": "circle",
111 | "height": "avatar",
112 | "width": "avatar",
113 | },
114 | "card": Object {
115 | "bg": "background",
116 | "boxShadow": "card",
117 | "p": 2,
118 | },
119 | "link": Object {
120 | "color": "primary",
121 | },
122 | "nav": Object {
123 | ":hover,:focus,.active": Object {
124 | "color": "primary",
125 | },
126 | "color": "inherit",
127 | "display": "inline-block",
128 | "fontSize": 1,
129 | "fontWeight": "bold",
130 | "p": 2,
131 | "textDecoration": "none",
132 | },
133 | },
134 | }
135 | `;
136 |
--------------------------------------------------------------------------------
/packages/preset/test/index.js:
--------------------------------------------------------------------------------
1 | import preset from '../src'
2 |
3 | test('snapshot', () => {
4 | expect(preset).toMatchSnapshot()
5 | })
6 |
--------------------------------------------------------------------------------
/packages/rebass/.gitignore:
--------------------------------------------------------------------------------
1 | styled-components
2 | dist
3 |
--------------------------------------------------------------------------------
/packages/rebass/.npmignore:
--------------------------------------------------------------------------------
1 | test
2 |
--------------------------------------------------------------------------------
/packages/rebass/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | # Rebass
5 |
6 | React primitive UI components built with [Styled System][].
7 | https://rebassjs.org
8 |
9 | [![Build Status][badge]][travis]
10 | [![Coverage][coverage-badge]][coverage]
11 | [![Downloads][downloads-badge]][npm]
12 | [![Version][version-badge]][npm]
13 | [![MIT License][license-badge]](LICENSE.md)
14 |
15 | [badge]: https://flat.badgen.net/travis/rebassjs/rebass/master
16 | [travis]: https://travis-ci.org/rebassjs/rebass
17 | [coverage-badge]: https://flat.badgen.net/codecov/c/github/rebassjs/rebass
18 | [coverage]: https://codecov.io/github/rebassjs/rebass
19 |
20 | [downloads-badge]: https://flat.badgen.net/npm/dw/rebass
21 | [version-badge]: https://flat.badgen.net/npm/v/rebass
22 | [license-badge]: https://flat.badgen.net/badge/license/MIT/blue
23 | [npm]: https://npmjs.com/package/rebass
24 |
25 | ```sh
26 | npm i rebass
27 | ```
28 |
29 | ## Getting Started
30 |
31 | ```jsx
32 | import React from 'react'
33 | import { Box, Heading, Button } from 'rebass'
34 |
35 | export default props =>
36 |
37 | Hello
38 |
39 |
40 | ```
41 | ## Features
42 |
43 | - Start your design system without boiling the ocean
44 | - Build consistent UI with design constraints and user-defined scales
45 | - Best-in-class developer ergonomics with [Styled System][] props
46 | - First-class support for theming &
47 | fully compatible with [Theme UI][]
48 | - Quick, mobile-first responsive styles with array-based syntax
49 | - Flexbox layout with the Box and Flex components
50 | - Flexibility built in for high design & development velocity
51 | - Minimal footprint at about 4KB
52 |
53 |
54 | [reflexbox]: https://rebassjs.org/reflexbox
55 |
56 | > "One of the best React component libs out there"
57 | >
58 | > – [Max Stoiber](https://twitter.com/mxstbr/status/882657561111080960)
59 |
60 | > "Rebass is the Bootstrap of React."
61 | >
62 | > – [Jori Lallo](https://twitter.com/jorilallo/status/882990343225868289)
63 |
64 | > "A whopper component library built on styled-components. Responsive, systematic, scalable...the business!"
65 | >
66 | > – [Colm Tuite](https://twitter.com/colmtuite/status/882715087936606210)
67 |
68 | ## Principles
69 |
70 | Rebass is intended to be:
71 |
72 | - **Minimal**
73 | - **Useful**
74 | - **Unopinionated**
75 | - **Flexible**
76 | - **Consistent**
77 | - **Extensible**
78 | - **Themeable**
79 |
80 | > Do one thing, and do it well
81 | >
82 | > – [Unix philosophy](https://en.wikipedia.org/wiki/Unix_philosophy#Do_One_Thing_and_Do_It_Well)
83 |
84 | See [Patterns for Style Composition in React](http://jxnblk.com/writing/patterns-for-style-composition-in-react/)
85 | for more on some of the thought behind Rebass.
86 |
87 | ## Documentation
88 |
89 | - [Docs](https://rebassjs.org)
90 | - [Getting Started](https://rebassjs.org/getting-started)
91 | - [Props](https://rebassjs.org/props)
92 | - [Extending](https://rebassjs.org/extending)
93 | - [Theming](https://rebassjs.org/theming)
94 | - [Reflexbox](https://rebassjs.org/reflexbox)
95 | - [Text](https://rebassjs.org/Text)
96 | - [Heading](https://rebassjs.org/Heading)
97 | - [Button](https://rebassjs.org/Button)
98 | - [Link](https://rebassjs.org/Link)
99 | - [Image](https://rebassjs.org/Image)
100 | - [Card](https://rebassjs.org/Card)
101 |
102 | ## CodeSandbox
103 |
104 | Try it out:
105 | https://codesandbox.io/s/github/rebassjs/rebass/tree/master/examples/sandbox
106 |
107 |
108 | ### Related
109 |
110 | - [Styled System][]
111 | - [Theme UI][]
112 | - [Emotion][]
113 | - [Styled Components][]
114 |
115 | [styled system]: https://styled-system.com
116 | [styled components]: https://github.com/styled-components/styled-components
117 | [emotion]: https://github.com/emotion-js/emotion
118 | [theme ui]: https://theme-ui.com
119 |
120 | ### Upgrading from v3
121 |
122 | See the [Migration Guide](https://rebassjs.org/migrating/).
123 |
124 | #### Previous Versions
125 |
126 | - [v3.2.2](https://github.com/rebassjs/rebass/tree/v3.2.2) – [v3 Docs](https://rebass-v3.now.sh)
127 | - [v2.3.2](https://github.com/rebassjs/rebass/tree/v2) – [Docs for Rebass v2](https://rebass-v2.now.sh)
128 | - [v1.0.7](https://github.com/rebassjs/rebass/tree/v1.0.7)
129 |
130 | ---
131 |
132 | [Contributing](CONTRIBUTING.md) | [MIT License](LICENSE.md)
133 |
134 |
--------------------------------------------------------------------------------
/packages/rebass/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "rebass",
3 | "version": "4.0.7",
4 | "description": "React primitive UI components built with Styled System",
5 | "main": "dist/index.js",
6 | "module": "dist/index.esm.js",
7 | "scripts": {
8 | "prepare": "rebass-bundler"
9 | },
10 | "keywords": [
11 | "components",
12 | "react",
13 | "react-component",
14 | "ui",
15 | "design-system",
16 | "styled-system",
17 | "styled-components",
18 | "emotion",
19 | "theming",
20 | "presentational",
21 | "stateless",
22 | "functional"
23 | ],
24 | "author": "Brent Jackson",
25 | "license": "MIT",
26 | "dependencies": {
27 | "reflexbox": "^4.0.6"
28 | },
29 | "repository": "rebassjs/rebass",
30 | "bugs": {
31 | "url": "https://github.com/rebassjs/rebass/issues"
32 | },
33 | "gitHead": "f0f01843e9fb63ca69112d7e97a1451b27ee9e6c"
34 | }
35 |
--------------------------------------------------------------------------------
/packages/rebass/src/index.js:
--------------------------------------------------------------------------------
1 | import React, { forwardRef } from 'react'
2 | import { Box, Flex } from 'reflexbox'
3 |
4 | export { Box, Flex }
5 |
6 | export const Text = forwardRef((props, ref) =>
7 |
12 | )
13 |
14 | export const Heading = forwardRef((props, ref) =>
15 |
28 | )
29 |
30 | export const Link = forwardRef((props, ref) =>
31 |
37 | )
38 |
39 | export const Button = forwardRef((props, ref) =>
40 |
61 | )
62 |
63 | export const Image = forwardRef((props, ref) =>
64 |
73 | )
74 |
75 | export const Card = forwardRef((props, ref) =>
76 |
81 | )
82 |
--------------------------------------------------------------------------------
/packages/rebass/test/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import renderer from 'react-test-renderer'
3 | import { matchers } from 'jest-emotion'
4 | import {
5 | Text,
6 | Heading,
7 | Button,
8 | Link,
9 | Image,
10 | Card,
11 | } from '../src'
12 |
13 | expect.extend(matchers)
14 |
15 | const render = el => renderer.create(el).toJSON()
16 |
17 | describe('Text', () => {
18 | test('renders', () => {
19 | const json = render(
20 |
21 | )
22 | expect(json.type).toBe('div')
23 | expect(json).toHaveStyleRule('text-align', 'center')
24 | expect(json).toHaveStyleRule('font-weight', 'bold')
25 | expect(json).toHaveStyleRule('font-style', 'italic')
26 | })
27 |
28 | test('renders with text variants', () => {
29 | const json = render(
30 |
41 | )
42 | expect(json).toHaveStyleRule('text-transform', 'uppercase')
43 | expect(json).toHaveStyleRule('letter-spacing', '0.2em')
44 | })
45 | })
46 |
47 | describe('Heading', () => {
48 | test('renders', () => {
49 | const json = render(
50 |
51 | )
52 | expect(json.type).toBe('h2')
53 | expect(json).toHaveStyleRule('font-size', '24px')
54 | expect(json).toHaveStyleRule('font-weight', 'heading')
55 | })
56 |
57 | test('renders with text variants', () => {
58 | const json = render(
59 |
70 | )
71 | expect(json).toHaveStyleRule('font-size', '64px')
72 | expect(json).toHaveStyleRule('font-weight', '900')
73 | })
74 | })
75 |
76 | describe('Button', () => {
77 | test('renders', () => {
78 | const json = render(
79 |
80 | )
81 | expect(json.type).toBe('button')
82 | expect(json).toHaveStyleRule('color', 'white')
83 | expect(json).toHaveStyleRule('background-color', 'primary')
84 | })
85 |
86 | test('renders as ', () => {
87 | const json = render(
88 |
89 | )
90 | expect(json.type).toBe('a')
91 | })
92 | })
93 |
94 | describe('Link', () => {
95 | test('renders', () => {
96 | const json = render(
97 |
98 | )
99 | expect(json.type).toBe('a')
100 | })
101 |
102 | test('renders with theme', () => {
103 | const json = render(
104 |
113 | )
114 | expect(json).toHaveStyleRule('color', 'primary')
115 | })
116 | })
117 |
118 | describe('Image', () => {
119 | test('renders', () => {
120 | const json = render(
121 |
122 | )
123 | expect(json.type).toBe('img')
124 | expect(json).toHaveStyleRule('max-width', '100%')
125 | })
126 | })
127 |
128 | describe('Card', () => {
129 | test('renders', () => {
130 | const json = render(
131 |
139 | )
140 | expect(json.type).toBe('div')
141 | expect(json).toHaveStyleRule('padding', '16px')
142 | expect(json).toHaveStyleRule('background-color', 'tomato')
143 | expect(json).toHaveStyleRule('border-radius', '8px')
144 | expect(json).toHaveStyleRule('box-shadow', '0 0 48px tomato')
145 | })
146 |
147 | test('renders with default variant', () => {
148 | const json = render(
149 |
160 | )
161 | expect(json).toHaveStyleRule('padding', '16px')
162 | expect(json).toHaveStyleRule('background-color', 'tomato')
163 | expect(json).toHaveStyleRule('border-radius', '4px')
164 | })
165 | })
166 |
--------------------------------------------------------------------------------
/packages/reflexbox/.gitignore:
--------------------------------------------------------------------------------
1 | dist
2 | styled-components
3 |
--------------------------------------------------------------------------------
/packages/reflexbox/.npmignore:
--------------------------------------------------------------------------------
1 | test
2 | babel.config.js
3 |
--------------------------------------------------------------------------------
/packages/reflexbox/LICENSE.md:
--------------------------------------------------------------------------------
1 | # The MIT License (MIT)
2 | Copyright (c) 2015 – 2019 Brent Jackson
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 |
6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 |
8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 |
10 |
--------------------------------------------------------------------------------
/packages/reflexbox/README.md:
--------------------------------------------------------------------------------
1 |
2 | # Reflexbox
3 |
4 | 📦 Ergonomic, responsive React layout and grid system.
5 | The original *Box* component™ since 2015
6 |
7 | [![Build Status][badge]][travis]
8 | [![Downloads][downloads-badge]][npm]
9 | [![Version][version-badge]][npm]
10 | [![MIT License][license-badge]](LICENSE.md)
11 | [](https://system-ui.com/theme)
12 |
13 | [badge]: https://flat.badgen.net/travis/rebassjs/rebass/master
14 | [travis]: https://travis-ci.org/rebassjs/rebass
15 | [downloads-badge]: https://flat.badgen.net/npm/dw/reflexbox
16 | [version-badge]: https://flat.badgen.net/npm/v/reflexbox
17 | [license-badge]: https://flat.badgen.net/badge/license/MIT/blue
18 | [npm]: https://npmjs.com/package/reflexbox
19 |
20 | - Primitive styled components for all your layout needs
21 | - Customize styles inline with the `sx` prop
22 | - Ergonomic responsive array-based values
23 | - Support for component variants
24 | - [Styled System][] props
25 | - Themeable and compatible with the [Theme Specification][]
26 | - Built with [Styled System][]
27 | - Works with [Theme UI][]
28 | - Built with Emotion, with support for Styled Components
29 |
30 | ## Getting Started
31 |
32 | ```sh
33 | npm i reflexbox
34 | ```
35 |
36 | ```jsx
37 | import React from 'react'
38 | import { Flex, Box } from 'reflexbox'
39 |
40 | export default props =>
41 |
42 |
45 | Reflex
46 |
47 |
50 | Box
51 |
52 |
53 | ```
54 |
55 | ### `sx` Prop
56 |
57 | The `Box` and `Flex` components both accept a `sx` prop that works with no additional setup required.
58 | The `sx` prop is similar to Emotion's `css` prop, but allows you to use values derived from the theme object.
59 |
60 | Reflexbox follows the [Theme Specification][], which means that any theme created for use with [Theme UI][], [Styled System][], or other similar libraries will work out-of-the-box.
61 | This allows you to share design constraints for typography, color, and layout throughout your application using a theming context.
62 |
63 | ```jsx
64 |
70 | ```
71 |
72 | Note: to opt-out of theme-based styles, use the `css` prop instead, which will not transform values.
73 |
74 | ## Theming
75 |
76 | Because Reflexbox follows the [Theme Specification][], all themes built for use with [Styled System][], [Theme UI][], or other related libraries are compatible with Reflexbox.
77 |
78 | To add a theme to an application, import the `ThemeProvider` component from `emotion-theming` and pass a custom theme object in.
79 |
80 | ```sh
81 | npm i emotion-theming
82 | ```
83 |
84 | ```jsx
85 | import React from 'react'
86 | import { ThemeProvider } from 'emotion-theming'
87 | import { Flex, Box } from 'reflexbox'
88 |
89 | const theme = {
90 | breakpoints: [
91 | '40em', '52em', '64em',
92 | ],
93 | colors: {
94 | text: '#000',
95 | background: '#fff',
96 | primary: '#07c',
97 | },
98 | space: [
99 | 0, 4, 8, 16, 32, 64, 128, 256,
100 | ],
101 | }
102 |
103 | export default props =>
104 |
105 |
110 | Hello
111 |
112 |
113 | ```
114 |
115 | For use with [Theme UI][], use `gatsby-plugin-theme-ui` or import the Theme UI `ThemeProvider` instead.
116 |
117 | ```js
118 | import { ThemeProvider } from 'theme-ui'
119 | ```
120 |
121 | ## Variants
122 |
123 | Reflexbox components also accept a `variant` prop, which allows you to define commonly used styles,
124 | such as cards, badges, and CSS grid layouts, in your theme object for reuse.
125 |
126 | Add a `variants` object to your theme and include any variants as style objects. These styles can reference other values in your theme such as colors, typographic styles, and more.
127 |
128 | ```js
129 | // example theme
130 | export default {
131 | colors: {
132 | text: '#000',
133 | background: '#fff',
134 | primary: '#07c',
135 | },
136 | radii: {
137 | default: 4,
138 | },
139 | shadows: {
140 | card: '0 0 4px rgba(0, 0, 0, .125)',
141 | },
142 | variants: {
143 | card: {
144 | p: 3,
145 | borderRadius: 'default',
146 | bg: 'white',
147 | boxShadow: 'card',
148 | },
149 | badge: {
150 | color: 'white',
151 | bg: 'primary',
152 | p: 1,
153 | borderRadius: 'default',
154 | },
155 | },
156 | }
157 | ```
158 |
159 | To apply a variant to your component, pass the name to the `variant` prop.
160 |
161 | ```jsx
162 | Card
163 | Badge
164 | ```
165 |
166 | ## Responsive Styles
167 |
168 | Use array values to quickly and ergonomically add mobile-first responsive styles to specific properties.
169 | This works on all style props and the `sx` prop.
170 | See the [Styled System][] docs for more.
171 |
172 | ```jsx
173 | // 100% width at the smallest viewport width
174 | // 50% width at the next breakpoint
175 | // 25% width at the next breakpoint
176 |
177 | ```
178 |
179 | You can customize the widths used for each breakpoint by defining a `theme.breakpoints` array in your theme.
180 |
181 | ## Styled System Props
182 |
183 | Reflexbox conforms to the [Theme Specification][] and includes many common [Styled System][] props.
184 | The `Box` and `Flex` components accept the following props:
185 |
186 | ### Space Props
187 |
188 | Prop | Theme Key
189 | ---|---
190 | `margin`, `m` | `space`
191 | `marginTop`, `mt` | `space`
192 | `marginRight`, `mr` | `space`
193 | `marginBottom`, `mb` | `space`
194 | `marginLeft`, `ml` | `space`
195 | `marginX`, `mx` | `space`
196 | `marginY`, `my` | `space`
197 | `padding`, `p` | `space`
198 | `paddingTop`, `pt` | `space`
199 | `paddingRight`, `pr` | `space`
200 | `paddingBottom`, `pb` | `space`
201 | `paddingLeft`, `pl` | `space`
202 | `paddingX`, `px` | `space`
203 | `paddingY`, `py` | `space`
204 |
205 | ### Layout Props
206 |
207 | Prop | Theme Key
208 | ---|---
209 | `width` | `sizes`
210 | `height` | `sizes`
211 | `minWidth` | `sizes`
212 | `maxWidth` | `sizes`
213 | `minHeight` | `sizes`
214 | `maxHeight` | `sizes`
215 |
216 | ### Typography Props
217 |
218 | Prop | Theme Key
219 | ---|---
220 | `fontFamily` | `fonts`
221 | `fontSize` | `fontSizes`
222 | `fontWeight` | `fontWeights`
223 | `lineHeight` | `lineHeights`
224 | `letterSpacing` | `letterSpacings`
225 | `fontStyle` | N/A
226 | `textAlign` | N/A
227 |
228 | ### Color Props
229 |
230 | Prop | Theme Key
231 | ---|---
232 | `color` | `colors`
233 | `backgroundColor`, `bg` | `colors`
234 | `opacity` | N/A
235 |
236 | ### Flexbox Props
237 |
238 | Prop | Theme Key
239 | ---|---
240 | `alignItems` | N/A
241 | `alignContent` | N/A
242 | `justifyItems` | N/A
243 | `justifyContent` | N/A
244 | `flexWrap` | N/A
245 | `flexDirection` | N/A
246 | `flex` | N/A
247 | `flexGrow` | N/A
248 | `flexShrink` | N/A
249 | `flexBasis` | N/A
250 | `justifySelf` | N/A
251 | `alignSelf` | N/A
252 | `order` | N/A
253 |
254 | ## Styled Components
255 |
256 | To use Reflexbox with Styled Components, import components from `reflexbox/styled-components`.
257 |
258 | ```js
259 | import { Flex, Box } from 'reflexbox/styled-components'
260 | ```
261 |
262 | ## About
263 |
264 | This library is the result of consolidating APIs and ergonomics from the original Reflexbox library, Grid Styled, and Rebass Grid.
265 | Reflexbox originally appeared with the original version of Rebass in 2015.
266 |
267 | [MIT License](LICENSE.md)
268 |
269 | [theme specification]: https://github.com/system-ui/theme-specification
270 | [styled system]: https://styled-system.com
271 | [theme ui]: https://theme-ui.com
272 | [emotion]: https://emotion.sh
273 | [styled components]: https://styled-components.com
274 |
275 |
--------------------------------------------------------------------------------
/packages/reflexbox/babel.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | presets: [ '@babel/preset-env' ],
3 | env: {
4 | styled: {
5 | plugins: [
6 | [
7 | 'transform-rename-import', {
8 | original: '@emotion/styled',
9 | replacement: 'styled-components',
10 | }
11 | ]
12 | ]
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/packages/reflexbox/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "reflexbox",
3 | "version": "4.0.6",
4 | "description": "Responsive React grid system built with Styled System, with support for Emotion and Styled Components",
5 | "main": "dist/index.js",
6 | "keywords": [
7 | "reflexbox",
8 | "flexbox",
9 | "grid-styled",
10 | "rebass",
11 | "rebass-grid",
12 | "layout",
13 | "emotion",
14 | "css",
15 | "style"
16 | ],
17 | "scripts": {
18 | "prepare": "babel src -d dist && yarn styled-components",
19 | "styled-components": "NODE_ENV=styled babel src -d styled-components"
20 | },
21 | "dependencies": {
22 | "@emotion/core": "^10.0.0",
23 | "@emotion/styled": "^10.0.0",
24 | "@styled-system/css": "^5.0.0",
25 | "@styled-system/should-forward-prop": "^5.0.0",
26 | "styled-system": "^5.0.0"
27 | },
28 | "peerDependencies": {
29 | "react": "^16.8.6"
30 | },
31 | "author": "Brent Jackson",
32 | "license": "MIT",
33 | "repository": "rebassjs/rebass",
34 | "devDependencies": {
35 | "babel-plugin-transform-rename-import": "^2.3.0"
36 | },
37 | "gitHead": "f0f01843e9fb63ca69112d7e97a1451b27ee9e6c"
38 | }
39 |
--------------------------------------------------------------------------------
/packages/reflexbox/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import styled from '@emotion/styled'
3 | import {
4 | compose,
5 | space,
6 | layout,
7 | typography,
8 | color,
9 | flexbox,
10 | } from 'styled-system'
11 | import css, { get } from '@styled-system/css'
12 | import shouldForwardProp from '@styled-system/should-forward-prop'
13 |
14 | const sx = props => css(props.sx)(props.theme)
15 | const base = props => css(props.__css)(props.theme)
16 | const variant = ({
17 | theme,
18 | variant,
19 | tx = 'variants',
20 | }) =>
21 | css(
22 | get(theme, tx + '.' + variant,
23 | get(theme, variant)
24 | )
25 | )(theme)
26 |
27 | export const Box = styled('div', {
28 | shouldForwardProp
29 | })({
30 | boxSizing: 'border-box',
31 | margin: 0,
32 | minWidth: 0,
33 | },
34 | base,
35 | variant,
36 | sx,
37 | props => props.css,
38 | compose(
39 | space,
40 | layout,
41 | typography,
42 | color,
43 | flexbox,
44 | ),
45 | )
46 |
47 | export const Flex = styled(Box)({
48 | display: 'flex'
49 | })
50 |
--------------------------------------------------------------------------------
/packages/reflexbox/test/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import renderer from 'react-test-renderer'
3 | import { matchers } from 'jest-emotion'
4 | import {
5 | Box,
6 | Flex,
7 | } from '../src'
8 |
9 | expect.extend(matchers)
10 |
11 | const render = el => renderer.create(el).toJSON()
12 |
13 | describe('Box', () => {
14 | test('renders', () => {
15 | const json = render(
16 |
17 | )
18 | expect(json.type).toBe('div')
19 | })
20 |
21 | test('renders with as prop', () => {
22 | const json = render(
23 |
24 | )
25 | expect(json.type).toBe('header')
26 | })
27 |
28 | test('renders with style props', () => {
29 | const json = render(
30 |
31 | )
32 | expect(json).toHaveStyleRule('width', '100%')
33 | })
34 |
35 | test('renders with layout props', () => {
36 | const json = render(
37 |
42 | )
43 | expect(json).toHaveStyleRule('display', 'inline-block')
44 | expect(json).toHaveStyleRule('height', '256px')
45 | expect(json).toHaveStyleRule('max-width', '768px')
46 | })
47 |
48 | test('renders with color props', () => {
49 | const json = render(
50 |
54 | )
55 | expect(json).toHaveStyleRule('color', 'tomato')
56 | expect(json).toHaveStyleRule('background-color', 'black')
57 | })
58 |
59 | test('renders with typography props', () => {
60 | const json = render(
61 |
67 | )
68 | expect(json).toHaveStyleRule('font-size', '20px')
69 | expect(json).toHaveStyleRule('line-height', '1.5')
70 | expect(json).toHaveStyleRule('font-weight', 'bold')
71 | expect(json).toHaveStyleRule('letter-spacing', '0.2em')
72 | })
73 |
74 | test('renders with flexbox props', () => {
75 | const json = render(
76 |
80 | )
81 | expect(json).toHaveStyleRule('flex', '1 1 auto')
82 | expect(json).toHaveStyleRule('align-self', 'flex-start')
83 | })
84 |
85 | test('renders with box-sizing', () => {
86 | const json = render(
87 |
88 | )
89 | expect(json).toHaveStyleRule('box-sizing', 'border-box')
90 | })
91 |
92 | test('renders with sx prop', () => {
93 | const json = render(
94 |
100 | )
101 | expect(json).toHaveStyleRule('border-radius', '2px')
102 | expect(json).toHaveStyleRule('border', '1px solid cyan')
103 | })
104 |
105 | test('renders with css prop', () => {
106 | const json = render(
107 |
114 | )
115 | expect(json).toHaveStyleRule('margin', '4px')
116 | expect(json).toHaveStyleRule('padding', '16px')
117 | expect(json).toHaveStyleRule('color', 'tomato')
118 | })
119 |
120 | test('removes style props', () => {
121 | const json = render(
122 |
127 | )
128 | expect(Object.keys(json.props)).toEqual([
129 | 'className'
130 | ])
131 | })
132 |
133 | test('renders with variants', () => {
134 | const json = render(
135 |
147 | )
148 | expect(json).toHaveStyleRule('padding', '32px')
149 | expect(json).toHaveStyleRule('border', '1px solid tomato')
150 | expect(json).toHaveStyleRule('border-radius', '2px')
151 | })
152 |
153 | test('renders with keyed variants', () => {
154 | const json = render(
155 |
167 | )
168 | expect(json).toHaveStyleRule('color', 'white')
169 | expect(json).toHaveStyleRule('background-color', 'tomato')
170 | })
171 |
172 | })
173 |
174 | describe('Flex', () => {
175 | test('renders with display flex', () => {
176 | const json = render(
177 |
178 | )
179 | expect(json).toHaveStyleRule('display', 'flex')
180 | })
181 |
182 | test('renders with Box props', () => {
183 | const json = render(
184 |
185 | )
186 | expect(json).toHaveStyleRule('color', 'tomato')
187 | })
188 |
189 | test('as prop does not break Box props', () => {
190 | const json = render(
191 |
197 | )
198 | expect(json.type).toBe('footer')
199 | expect(json).toHaveStyleRule('width', '50%')
200 | expect(json).toHaveStyleRule('font-size', '20px')
201 | expect(json).toHaveStyleRule('color', 'tomato')
202 | })
203 | })
204 |
--------------------------------------------------------------------------------
/packages/space/README.md:
--------------------------------------------------------------------------------
1 |
2 | # @rebass/space
3 |
4 | React component for applying responsive margin and padding to child elements without a wrapping HTML container.
5 | Built with [Styled System][].
6 |
7 | ```sh
8 | npm i @rebass/space
9 | ```
10 |
11 | ```js
12 | import React from 'react'
13 | import Space from '@rebass/space'
14 |
15 | // Apply margin to child components without a wrapping
16 | const App = props => (
17 |
18 | Hello
19 | Hi
20 |
21 |
22 | )
23 | ```
24 |
25 | ## Props
26 |
27 | The Space component uses [Styled System's][styled system] `space` utility to add margin and padding props.
28 |
29 | Prop | Description | Type
30 | ---|---|---
31 | `m` | margin | number, string, or array
32 | `mt` | margin-top | number, string, or array
33 | `mr` | margin-right | number, string, or array
34 | `mb` | margin-bottom | number, string, or array
35 | `ml` | margin-left | number, string, or array
36 | `mx` | margin x-axis (left and right) | number, string, or array
37 | `my` | margin y-axis (top and bottom) | number, string, or array
38 | `p` | padding | number, string, or array
39 | `pt` | padding-top | number, string, or array
40 | `pr` | padding-right | number, string, or array
41 | `pb` | padding-bottom | number, string, or array
42 | `pl` | padding-left | number, string, or array
43 | `px` | padding x-axis (left and right) | number, string, or array
44 | `py` | padding y-axis (top and bottom) | number, string, or array
45 |
46 | MIT License
47 |
48 | [styled system]: https://styled-system.com
49 |
--------------------------------------------------------------------------------
/packages/space/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@rebass/space",
3 | "version": "4.0.5",
4 | "description": "React component for applying responsive margin and padding to child elements without a wrapping HTML container. Built with Styled System.",
5 | "main": "dist/index.js",
6 | "scripts": {
7 | "prepare": "babel src -d dist --root-mode upward"
8 | },
9 | "keywords": [
10 | "rebass",
11 | "styled-system",
12 | "style",
13 | "css",
14 | "layout",
15 | "margin",
16 | "padding"
17 | ],
18 | "author": "Brent Jackson",
19 | "license": "MIT",
20 | "repository": "rebassjs/rebass",
21 | "dependencies": {
22 | "@emotion/core": "^10.0.0",
23 | "@emotion/styled": "^10.0.0",
24 | "styled-system": ">=5.0.0"
25 | },
26 | "gitHead": "f0f01843e9fb63ca69112d7e97a1451b27ee9e6c"
27 | }
28 |
--------------------------------------------------------------------------------
/packages/space/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import styled from '@emotion/styled'
3 | import { space } from 'styled-system'
4 |
5 | const classnames = (...args) => args.join(' ')
6 | const getClassName = el => (el.props && el.props.className) || ''
7 |
8 | export const StyledChildren = ({
9 | className,
10 | children,
11 | ...props
12 | }) => {
13 | const styledChildren = React.Children.toArray(children)
14 | .map(child => React.cloneElement(child, {
15 | className: classnames(getClassName(child), className)
16 | }))
17 | return (
18 | <>
19 | {styledChildren}
20 | >
21 | )
22 | }
23 |
24 | const Space = styled(StyledChildren)(space)
25 |
26 | export default Space
27 |
--------------------------------------------------------------------------------
/packages/space/test/__snapshots__/index.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`renders 1`] = `null`;
4 |
5 | exports[`renders children 1`] = `
6 | Array [
7 |
10 | Hello
11 |
,
12 |
15 | hi
16 |
,
17 | ]
18 | `;
19 |
--------------------------------------------------------------------------------
/packages/space/test/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import renderer from 'react-test-renderer'
3 | import Space from '../src'
4 |
5 | const render = el => renderer.create(el).toJSON()
6 |
7 | test('renders', () => {
8 | const json = render(
)
9 | expect(json).toMatchSnapshot()
10 | })
11 |
12 | test('renders children', () => {
13 | const json = render(
14 |
15 | Hello
16 | hi
17 |
18 | )
19 | expect(json).toMatchSnapshot()
20 | })
21 |
22 | test('adds classNames to children', () => {
23 | const json = render(
24 |
25 | Hello
26 | hi
27 |
28 | )
29 | const { className } = json[0].props
30 | expect(json[0].props.className.length).toBeGreaterThan(0)
31 | expect(json[1].props.className).toBe(className)
32 | })
33 |
34 | test('merges with existing child classNames', () => {
35 | const json = render(
36 |
37 | Hello
38 | hi
39 |
40 | )
41 | const { className } = json[0].props
42 | expect(className).toMatch(/^beep\s/)
43 | })
44 |
--------------------------------------------------------------------------------