)
================================================
FILE: packages/docs/src/components/wrapper.js
================================================
import React from 'react'
import { Styled } from 'theme-ui'
import { Link } from 'gatsby'
import { Helmet } from 'react-helmet'
import { Box, Flex } from 'rebass'
import { globalHistory } from '@reach/router'
const breadcrumbRoutes = [
'guides',
'recipes',
]
export const Breadcrumbs = ({
title,
}) => {
const { location } = globalHistory
const [ n, base, path ] = location.pathname.split('/')
if (!breadcrumbRoutes.includes(base)) return false
if (!path) return false
return (
{base}
/
{title || path}
)
}
export const wrapper = ({
title,
...props
}) => {
const children = React.Children.toArray(props.children)
.reduce((acc, child) => {
const type = child.props.mdxType
if (type !== 'h1') return [ ...acc, child ]
return [
...acc,
child,
,
]
}, [])
return (
<>
{title && (
{title} | Rebass
)}
{children}
>
)
}
================================================
FILE: packages/docs/src/gatsby-plugin-theme-ui/components.js
================================================
import React from 'react'
import code from '../components/code'
import { wrapper } from '../components/wrapper'
const heading = Tag => props => {
if (!props.id) return
return (
{props.children}
)
}
export default {
wrapper,
pre: props => props.children,
code,
h2: heading('h2'),
h3: heading('h3'),
h4: heading('h4'),
h5: heading('h5'),
h6: heading('h6'),
}
================================================
FILE: packages/docs/src/gatsby-plugin-theme-ui/index.js
================================================
import preset from '@rebass/preset'
import merge from 'lodash.merge'
import prism from '@theme-ui/prism/presets/theme-ui'
export default merge(preset, {
initialColorModeName: 'lite',
colors: {
text: '#000',
background: '#fff',
primary: '#33e',
secondary: '#a0c',
accent: '#f0a',
muted: '#f6f6ff',
gray: '#444',
lightgray: '#cfcfd3',
modes: {
dark: {
text: '#fff',
background: '#000',
primary: '#0ff',
secondary: '#b0f',
accent: '#f0b',
muted: '#111',
gray: '#999',
lightgray: '#444',
},
gray: {
text: '#fff',
background: 'hsl(270, 30%, 14%)',
primary: 'hsl(180, 100%, 60%)',
secondary: 'hsl(270, 100%, 60%)',
accent: 'hsl(300, 100%, 60%)',
muted: 'hsl(270, 50%, 8%)',
gray: 'hsl(270, 50%, 70%)',
lightgray: 'hsl(270, 50%, 30%)',
},
hack: {
text: 'hsl(120, 100%, 75%)',
background: 'hsl(120, 20%, 10%)',
primary: 'hsl(120, 100%, 40%)',
secondary: 'hsl(120, 50%, 40%)',
accent: 'hsl(120, 100%, 90%)',
muted: 'hsl(120, 20%, 7%)',
gray: 'hsl(120, 20%, 40%)',
lightgray: 'hsl(120, 20%, 20%)',
},
pink: {
text: 'hsl(350, 80%, 10%)',
background: 'hsl(350, 100%, 90%)',
primary: 'hsl(350, 100%, 50%)',
secondary: 'hsl(280, 100%, 50%)',
accent: 'hsl(280, 100%, 20%)',
muted: 'hsl(350, 100%, 88%)',
gray: 'hsl(350, 40%, 50%)',
lightgray: 'hsl(350, 60%, 80%)',
},
}
},
fontWeights: {
body: 400,
heading: 800,
bold: 700,
},
sizes: {
wide: 1280,
},
shadows: {
small: `0 0 0px 1px rgba(0, 0, 0, 0.25)`,
},
buttons: {
big: {
variant: 'buttons.primary',
px: 4,
py: 3,
fontSize: 3,
},
outline: {
variant: 'buttons.primary',
color: 'primary',
bg: 'transparent',
boxShadow: 'inset 0 0 0 2px'
},
transparent: {
color: 'inherit',
bg: 'transparent',
':hover,:focus': {
color: 'primary',
outline: 'none',
boxShadow: '0 0 0 2px',
}
},
},
links: {
nav: {
display: 'block',
px: 2,
py: 1,
color: 'inherit',
textDecoration: 'none',
fontSize: 1,
fontWeight: 'bold',
},
},
text: {
heading: {
a: {
color: 'inherit',
textDecoration: 'none',
':hover': {
textDecoration: 'underline',
}
}
}
},
variants: {
badge: {
display: 'inline-block',
px: 2,
color: 'background',
bg: 'primary',
borderRadius: 'circle',
},
},
styles: {
a: {
color: 'primary',
transition: 'color .2s ease-out',
':hover,:focus': {
color: 'secondary',
}
},
inlineCode: {
fontFamily: 'monospace',
fontSize: '93.75%',
color: 'secondary',
},
code: {
fontFamily: 'monospace',
color: 'secondary',
},
pre: {
...prism,
fontFamily: 'monospace',
fontSize: 1,
overflowX: 'auto',
bg: 'muted',
p: 3,
borderRadius: 4,
},
blockquote: {
p: 0,
mx: 0,
fontWeight: 'bold',
fontSize: 3,
},
h1: {
variant: 'text.heading',
mt: 0,
fontSize: [5, 6],
},
h2: {
variant: 'text.heading',
fontSize: [4, 5],
},
h3: {
variant: 'text.heading',
fontSize: 3,
},
h4: { variant: 'text.heading', },
h5: { variant: 'text.heading', },
h6: { variant: 'text.heading', },
table: {
width: '100%',
borderCollapse: 'separate',
borderSpacing: 0,
},
th: {
py: 2,
textAlign: 'left',
borderBottom: t => `4px solid ${t.colors.muted}`,
},
td: {
py: 2,
textAlign: 'left',
borderBottom: t => `1px solid ${t.colors.muted}`,
},
},
forms: {
label: {
fontSize: 1,
fontWeight: 'bold',
},
field: {
borderColor: 'lightgray',
':focus': {
borderColor: 'primary',
outline: 'none',
boxShadow: t => `0 0 0 2px ${t.colors.primary}`,
}
},
input: {
variant: 'forms.field',
},
select: {
variant: 'forms.field',
},
textarea: {
variant: 'forms.field',
},
radio: {
},
slider: {
bg: 'lightgray',
},
switch: {
// thumb: {}
}
}
})
================================================
FILE: packages/docs/src/index.js
================================================
import React from 'react'
import Layout from './components/layout'
export { default as Layout } from './components/layout'
export * from './components/blocks'
export { default as DemoProvider } from './components/demo-provider'
export { default as Note } from './components/note'
export { default as Logo } from './components/logo'
export { default as RecipeCard } from './components/recipe-card'
export const wrapPageElement = ({ element, props }) =>
{element}
================================================
FILE: packages/docs/src/pages/404.mdx
================================================
import { Flex } from 'rebass'
# 404
Page not found
================================================
FILE: packages/docs/src/pages/box.mdx
================================================
export const title = 'Box'
# Box
Responsive box-model layout component
```jsx live=true
Box
```
The Box and Flex components are also available in the standalone [Reflexbox](/reflexbox) package.
================================================
FILE: packages/docs/src/pages/button.mdx
================================================
export const title = 'Button'
# Button
Button component with variants
```jsx live=true
```
================================================
FILE: packages/docs/src/pages/card.mdx
================================================
export const title = 'Card'
# Card
Extension of the Box component with card styles
```jsx live=true
Card
```
================================================
FILE: packages/docs/src/pages/demo.mdx
================================================
import {
Box,
Heading,
Text,
Button,
Image,
Card,
} from 'rebass'
import { DemoProvider } from '..'
export const title = 'Demo'
# Demo
```jsx live=true
HelloThis is a demo using presets from Theme UI
```
================================================
FILE: packages/docs/src/pages/extending.mdx
================================================
import Note from '../components/note'
export const title = 'Extending'
# Extending
Rebass components are designed to be used as foundational primitives
for building a custom design system.
By extending these base components, you can quickly start a component library
with a consistent API and styles that are driven by design constraints
that you define in your theme.
To extend a component, pass props through and define custom styles in the `sx` prop.
```jsx
import React from 'react'
import { Box } from 'rebass'
const Container = props =>
```
If you prefer, you can also use `@emotion/styled` to extend components.
It's not recommended to use the `styled` API from `styled-components` due to various issues and unexpected behavior.
## Order of Styles
Because Rebass still uses CSS, you might have to contend with the cascade, depending on how you define your styles,
especially in regards to source order and using shorthand CSS properties.
Rebass components apply styles in the following order:
1. Variant
2. `sx` prop
3. `css` prop
4. Styled System props
### Shorthand CSS Properties
If you're using CSS properties that have shorthand variations, try to use the normal CSS property instead.
```js
// avoid shorthand syntax
sx={{
border: '1px solid tomato',
}}
```
```js
// use regular properties instead
sx={{
borderWidth: '1px',
borderStyle: 'solid',
borderColor: 'tomato',
}}
```
### Conflicting Styles
It's easy to add conflicting styles in two different places and end up with unexpected results.
- If you're intending to use a style prop, don't use it in the `sx` prop or in variants.
- If you're intending to use variants, don't include conflicting styles in the `sx` prop
## Default Props
Instead of using the `defaultProps` property on your component, define defaults inline in the JSX.
The `{...props}` from the outside will override the ones you set on the component.
```jsx
const Container = props =>
```
## Default Variants
To set a default variant, include the variant in your theme.
```js
variants: {
badge: {
color: 'white',
bg: 'tomato',
px: 2,
},
}
```
Then add the default prop in your component.
```jsx
const Badge = props =>
```
## Example Extensions
### Avatar
```jsx
const Avatar = props =>
```
### Embed
```jsx
const Embed = props =>
iframe': {
position: 'absolute',
width: '100%',
height: '100%',
top: 0,
bottom: 0,
left: 0,
border: 0
}
}}
/>
```
### Pre
```jsx
const Pre = props =>
```
### Fixed
```jsx
const Fixed = props =>
```
### Divider
```jsx
const Divider = props =>
```
See the [Recipes](/recipes) page for more examples.
================================================
FILE: packages/docs/src/pages/flex.mdx
================================================
export const title = 'Flex'
# Flex
Responsive flexbox layout component
```jsx live=true
Flex
Box
```
The Box and Flex components are also available in the standalone [Reflexbox](/reflexbox) package.
================================================
FILE: packages/docs/src/pages/forms/checkbox.mdx
================================================
export const title = 'Checkbox'
# Checkbox
Accessible and themeable form checkbox input component.
```js
import { Label, Checkbox } from '@rebass/forms'
```
```jsx live
```
Note that the `Label` component uses `display: flex` by default to make alignment with labels simpler.
================================================
FILE: packages/docs/src/pages/forms/index.mdx
================================================
import { Box, Button } from 'rebass'
export const title = 'Forms'
# Forms
Accessible and themeable form components for use with Rebass or Theme UI.
```sh
npm i @rebass/forms
```
Import and use the form components alongside other Rebass components.
```js
import {
Label,
Input,
Select,
Textarea,
Radio,
Checkbox,
} from '@rebass/forms'
```
```jsx live
e.preventDefault()}
py={3}>
```
## Theming
Each form element can be customized with the `forms` object in your theme.
```js
// example theme
export default {
forms: {
input: {
color: 'primary',
},
select: {
borderRadius: 9999,
},
textarea: {},
label: {},
radio: {},
checkbox: {},
},
}
```
## Variants
Additional component variants can be defined in the theme and applied via props.
```js
// example theme with variants
export default {
forms: {
largeInput: {
fontSize: 3,
px: 3,
py: 2,
}
}
}
```
```jsx
```
================================================
FILE: packages/docs/src/pages/forms/input.mdx
================================================
export const title = 'Input'
# Input
Accessible and themeable form input component.
```js
import { Label, Input } from '@rebass/forms'
```
```jsx live
```
================================================
FILE: packages/docs/src/pages/forms/label.mdx
================================================
export const title = 'Label'
# Label
Accessible and themeable form label component.
```js
import { Label } from '@rebass/forms'
```
```jsx live
```
================================================
FILE: packages/docs/src/pages/forms/radio.mdx
================================================
export const title = 'Radio'
# Radio
Accessible and themeable form radio input component.
```js
import { Label, Radio } from '@rebass/forms'
```
```jsx live
```
Note that the `Label` component uses `display: flex` by default to make alignment with labels simpler.
================================================
FILE: packages/docs/src/pages/forms/select.mdx
================================================
export const title = 'Select'
# Select
Accessible and themeable form select component.
```js
import { Label, Select } from '@rebass/forms'
```
```jsx live
```
================================================
FILE: packages/docs/src/pages/forms/slider.mdx
================================================
export const title = 'Slider'
# Slider
Accessible and themeable form range input component.
```js
import { Label, Slider } from '@rebass/forms'
```
```jsx live
```
================================================
FILE: packages/docs/src/pages/forms/switch.mdx
================================================
export const title = 'Switch'
# Switch
Toggle switch button component
```js
import { Switch } from '@rebass/forms'
```
```jsx live
```
================================================
FILE: packages/docs/src/pages/forms/textarea.mdx
================================================
export const title = 'Textarea'
# Textarea
Accessible and themeable form textarea component.
```js
import { Label, Textarea } from '@rebass/forms'
```
```jsx live
```
================================================
FILE: packages/docs/src/pages/getting-started.mdx
================================================
export const title = 'Getting Started'
# Getting Started
Install the core Rebass library.
```sh
npm i rebass
```
## ThemeProvider
By default, Rebass components are stylistically unopinionated and do not include a theme.
You can add a theme to your application with a `ThemeProvider` component and by providing a theme in context.
For this guide, use the Emotion `ThemeProvider` with the default Rebass preset theme.
```sh
npm i @rebass/preset emotion-theming
```
Wrap your application with the `ThemeProvider` component.
```jsx
import React from 'react'
import { ThemeProvider } from 'emotion-theming'
import theme from '@rebass/preset'
export default props =>
{props.children}
```
Alternatively, if you'd like to use Rebass with [Theme UI][],
you can use the `ThemeProvider` from `theme-ui`, or use [`gatsby-plugin-theme-ui`](https://theme-ui.com/gatsby-plugin).
```sh
import { ThemeProvider } from 'theme-ui'
```
## Composition
You can use Rebass components out-of-the-box to build larger, composite components.
```jsx
import React from 'react'
import {
Box,
Card,
Image,
Heading,
Text
} from 'rebass'
export default ({
image,
title,
description
}) =>
{title}
{description}
```
```jsx live=true
Card Demo
You can edit this code
```
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.
## Extending
You can also use Rebass components as basic building blocks and extend them to create custom UI components,
which is a great way to get started with a new design system without *boiling the ocean*.
```jsx
// custom button example
import React from 'react'
import { Button } from 'rebass'
export default props =>
```
## Theming
Use the default Rebass theme or completely customize the look and feel with a custom theme.
Since Rebass follows the [Theme Specification][], any theme built for use with [Theme UI][] or [Styled System][] will work out-of-the-box.
```jsx
import React from 'react'
import { ThemeProvider } from 'emotion-theming'
const theme = {
fontSizes: [
12, 14, 16, 24, 32, 48, 64
],
colors: {
primary: '#07c',
gray: '#f6f6ff',
},
buttons: {
primary: {
color: 'white',
bg: 'primary',
},
outline: {
color: 'primary',
bg: 'transparent',
boxShadow: 'inset 0 0 0 2px'
},
},
}
export default props =>
{props.children}
```
## Variants
Each component accepts a `variant` prop, giving you multiple styles for buttons, cards, text styles, and more.
You can define custom variants in your own theme or use the defaults from the Rebass preset theme.
```jsx live=true
```
[styled system]: https://styled-system.com
[theme specification]: https://github.com/system-ui/theme-specification
[theme ui]: https://theme-ui.com
================================================
FILE: packages/docs/src/pages/guides/css-grid.mdx
================================================
export const title = 'CSS Grid'
# CSS Grid
Rebass components can be used to create one-off or reusable CSS Grid layout components.
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.
This guide is a work-in-progress.
If you'd like to help make this better,
please open an issue or pull request on [GitHub](https://github.com/rebassjs/rebass).
CSS Grid is great for arranging direct child elements without the need for additional styles applied to the children.
Create an extension of the Box component that can wrap other elements to apply a grid layout.
```jsx
// example grid layout component
import React from 'react'
import { Box } from 'rebass'
export default props =>
```
By using the `sx` prop, CSS properties such as `gridGap` will use values from your theme object.
This can help ensure consistent whitespace throughout your layout.
## Auto Columns
Using the `grid-auto-columns` property, you can quickly lay out child elements in a tile-based grid.
```jsx
// example grid layout component
import React from 'react'
import { Box } from 'rebass'
export default props =>
```
## Demo
Use the live demo below to explore different layouts using CSS Grid.
```jsx live=true
HelloCSS Grid
```
## Resources
There are many resources for learning how to use CSS Grid layout.
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:
**[CSS Grid Layout Module Level 1][spec]**
Once you have a basic grasp of the concepts in the specification, MDN is an excellent resource for learning any web technology:
**[MDN: CSS Grid Layout][mdn]**
Additional resources:
- [Grid by Example][]
- [Jen Simmon's Lab][simmons-lab]
- [CSS Tricks][]
[spec]: https://www.w3.org/TR/css-grid-1/
[mdn]: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout
[css tricks]: https://css-tricks.com/snippets/css/complete-guide-grid/
[grid by example]: https://gridbyexample.com/
[simmons-lab]: https://labs.jensimmons.com/
[learn-css-grid]: https://learncssgrid.com/
================================================
FILE: packages/docs/src/pages/guides/index.mdx
================================================
import { Grid } from '../..'
export const title = 'Guides'
# Guides
- [CSS Grid](/guides/css-grid)
Use the Rebass Box component and `sx` prop to create custom CSS Grid components
- [MDX](/guides/mdx)
Use Rebass components to add styles and layout to MDX documents
- [Using Rebass without Context](/guides/using-rebass-without-context)
Create self-contained components that do not require theming context
- [Server-Side Rendering](/guides/server-side-rendering)
Render Rebass components on the server with zero configuration
- [Styled Components](/guides/styled-components)
Use Rebass with the Styled Components library
================================================
FILE: packages/docs/src/pages/guides/mdx.mdx
================================================
import { Note } from '../..'
import { Box } from 'rebass'
export const title = 'MDX'
# MDX
[MDX][] is a format that allows you to write content in markdown and import and use React components inline.
It's an excellent format for documentation, blogs, or other forms of structured content.
This guide is a work-in-progress.
If you'd like to help make this better,
please open an issue or pull request on [GitHub](https://github.com/rebassjs/rebass).
Rebass components can be imported and used directly in MDX documents,
which lets you apply styles inline to sections of your page.
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.
In the following example, the Box component is used to add a callout style box around its contents.
```md
import { Box } from 'rebass'
# MDX Example
> ”This is an important quote.”
```
You can also use the `sx` prop with child selectors to dramatically change the layout of MDX content.
```md
import { Box } from 'rebass'
# MDX Example
- This is a list
- Displayed in a grid layout
- With custom styles
- Pretty cool, huh?
```
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.
If you'd like to style the markdown elements with the same theme object and a similar API to Rebass,
use the [Theme UI][] library, which includes first-class support for styling MDX content.
[mdx]: https://mdxjs.com
[theme ui]: https://theme-ui.com
================================================
FILE: packages/docs/src/pages/guides/server-side-rendering.mdx
================================================
export const title = 'Server-Side Rendering'
# Server-Side Rendering
Because Rebass uses Emotion, no additional steps are required to support rendering on a server.
Emotion will automatically inline performant, critical CSS without any additional effort required.
See the [Emotion docs](https://emotion.sh/docs/ssr) for more.
================================================
FILE: packages/docs/src/pages/guides/styled-components.mdx
================================================
import { Note } from '../..'
export const title = 'Using Styled Components'
# Using Styled Components
If you'd prefer to use the Styled Components library instead of Emotion, you can import components from `rebass/styled-components`.
```jsx
import React from 'react'
import { Box } from 'rebass/styled-components'
export default props =>
Hello
```
The package will still install Emotion as a dependency, but it will not be included in the module or your application bundle.
================================================
FILE: packages/docs/src/pages/guides/theme-ui.mdx
================================================
import { Note } from '../..'
export const title = 'Theme UI'
# Theme UI
This guide is a work-in-progress.
If you'd like to help make this better,
please open an issue or pull request on [GitHub](https://github.com/rebassjs/rebass).
================================================
FILE: packages/docs/src/pages/guides/using-rebass-without-context.mdx
================================================
import { Note } from '../..'
export const title = 'Using Rebass without Context'
# Using Rebass without Context
If you'd like to use Rebass components without adding a theme to React context,
you can pass a `theme` object as a prop to any of the components.
This guide is a work-in-progress.
If you'd like to help make this better,
please open an issue or pull request on [GitHub](https://github.com/rebassjs/rebass).
```jsx
import React from 'react'
import { Box } from 'rebass'
import theme from './theme'
export default props =>
```
================================================
FILE: packages/docs/src/pages/heading.mdx
================================================
export const title = 'Heading'
# Heading
Extension of the Text component for headings
```jsx live=true
Hello
```
================================================
FILE: packages/docs/src/pages/image.mdx
================================================
export const title = 'Image'
# Image
Responsive image component with variants
```jsx live=true
```
```jsx live=true
```
================================================
FILE: packages/docs/src/pages/index.mdx
================================================
import { Box, Flex, Button } from 'rebass'
import {
Banner,
NavGrid,
Container,
Grid,
LogoGrid,
} from '..'
import Logo from '../components/logo'
# Rebass React primitive UI components built with Styled System
```sh
npm i rebass
```
- [Getting Started](/getting-started)
- [Props](/props)
- [Theming](/theming)
- [Variants](/variants)
- [Extending](/extending)
- [Box](/box)
- [Flex](/flex)
- [Text](/text)
- [Heading](/heading)
- [Button](/button)
- [Link](/link)
- [Image](/image)
- [Card](/card)
- [Forms](/forms)
- [Guides](/guides)
- [Recipes](/recipes)
[![stars][]][github]
[![build status][]][travis]
[![downloads][]][npm]
[![coverage][]][codecov]
[stars]: https://flat.badgen.net/github/stars/rebassjs/rebass?color=33e
[github]: https://github.com/rebassjs/rebass
[build status]: https://flat.badgen.net/travis/rebassjs/rebass/master?color=33e
[travis]: https://travis-ci.org/rebassjs/rebass
[downloads]: https://flat.badgen.net/npm/dm/rebass?color=33e
[npm]: https://npmjs.com/package/rebass
[coverage]: https://flat.badgen.net/codecov/c/github/rebassjs/rebass?color=33e
[codecov]: https://codecov.io/github/rebassjs/rebass
- Start your design system without boiling the ocean
- Build consistent UI with design constraints and user-defined scales
- Best-in-class developer ergonomics with [Styled System][] props
- First-class support for theming &
fully compatible with [Theme UI][]
- Quick, mobile-first responsive styles with array-based syntax
- Flexbox layout with the Box and Flex components
- Flexibility built in for high design & development velocity
- Minimal footprint
```jsx live=true
Hello
```
- > “One of the best React component libs out there”
- [Max Stoiber](https://twitter.com/mxstbr/status/882657561111080960)
- > “Rebass is the Bootstrap of React.”
- [Jori Lallo](https://twitter.com/jorilallo/status/882990343225868289)
- > “A whopper component library built on styled-components. Responsive, systematic, scalable...the business!”
- [Colm Tuite](https://twitter.com/colmtuite/status/882715087936606210)
- > “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.”
- [alttab](https://news.ycombinator.com/item?id=14705579)
## Get Started
[styled system]: https://styled-system.com
[theme ui]: https://theme-ui.com
================================================
FILE: packages/docs/src/pages/layout/index.mdx
================================================
import { Tiles } from '@rebass/layout'
export const title = 'Layout'
# @rebass/layout
Themeable layout components built with Rebass
```sh
npm i @rebass/layout
```
## Tiles
```jsx live
```
```jsx live
```
================================================
FILE: packages/docs/src/pages/link.mdx
================================================
export const title = 'Link'
# Link
Styled link component
```jsx live=true
Link
```
```jsx live=true
Link
```
================================================
FILE: packages/docs/src/pages/migrating.mdx
================================================
export const title = 'Migration'
# Migration Guide
## v4: What's New
- New [`sx` prop](/props/#sx-prop) for theme-based styles
- Use the `css` prop for un-themed, raw CSS values
- No additional Babel configuration required for the `sx` or `css` props
- Use the `sx` prop in MDX documents
- Built-in support for themeable component [variants](/variants)
- Fully compatible with [Theme UI][]
[theme ui]: https://theme-ui.com
## v4: Breaking Changes
- The default package now uses Emotion. To use Rebass with Styled Components, import the components from `rebass/styled-components` instead.
- The undocumented theme keys for `Box`, `Flex`, `Text`, `Heading`, `Link`, `Button`, `Image`, and `Card` are no longer supported. Use variants instead.
- The `@rebass/grid` package has been renamed (back to) `reflexbox`
- Heading: default `fontWeight` is now set to `heading`. Add styles to `theme.fontWeights` to customize the `heading` font weight.
- Button no longer supports the following props. Use the `sx` prop instead.
`border`, `borderColor`, `borderWidth`, `borderStyle`, `borderRadius`, `borderTop`, `borderRight`, `borderBottom`, `borderLeft`, `borderX`, `borderY`
- Image no longer supports the following props. Use the `sx` prop instead.
`border`, `borderColor`, `borderWidth`, `borderStyle`, `borderRadius`, `borderTop`, `borderRight`, `borderBottom`, `borderLeft`, `borderX`, `borderY`
- Link no longer includes default styles. Add styles to `theme.variants.link` to customize link styles.
- Card no longer supports the following props. Use the `sx` prop instead.
`border`, `borderColor`, `borderWidth`, `borderStyle`, `borderRadius`, `borderTop`, `borderRight`, `borderBottom`, `borderLeft`, `borderX`, `borderY`, `boxShadow`, `textShadow`, `background`, `backgroundImage`, `backgroundSize`, `backgroundPosition`, `backgroundRepeat`,
================================================
FILE: packages/docs/src/pages/props.mdx
================================================
export const title = 'Props'
# Props
All Rebass components extend the base [Box](/box) component,
and include [Styled System][] props for ensuring your design constraints are easily accessible,
while allowing you the flexibility to create responsive designs inline in your components.
## `sx` Prop
The `sx` prop accepts a style object, with easy access to values from your theme
and the ability to quickly add responsive styles to any property using arrays as values.
If you've used [Theme UI][] or [Styled System][] before, this will probably seem familiar.
If you've used the Emotion `css` prop before, the `sx` prop works in a similar way,
but allows you to use values from your theme object.
The `sx` prop is built-in and does not require any additional configuration,
which means it will work in any React app, such as Create React App, or in [MDX][] documents.
```jsx live=true
Hello
```
## Nested Selectors
Use nested objects to apply pseudoclasses and other child selectors within the `sx` prop.
```jsx live=true
```
## Responsive Styles
Mobile-first responsive styles based on breakpoints defined in your theme can be quickly applied to
any element using arrays as values in the `sx` prop, or with any of the shorthand style props below.
The first value in the array will apply to all screen widths, and each value after will be applied from that breakpoint and up.
Define breakpoints in your theme using an array of widths.
```js
// example theme
export default {
breakpoints: [ '40em', '52em', '64em' ],
}
```
For any individual CSS property, use an array as a value to quickly apply mobile-first responsive styles for that single property.
```jsx
```
You can also use standard CSS media query syntax for one-off cases or non-mobile-first styles.
```jsx
```
The `sx` prop uses [Styled System CSS](https://styled-system.com/css) to pick up values from your theme
and write responsive styles using the array syntax.
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.
## `as` Prop
The underlying HTML element rendered in any component can be overridden by the `as` prop.
```jsx
Hello
```
## Styled System Props
In addition to the `sx` prop, several [Styled System][] props are provided as ergonomic shortcuts.
These props allow you to quickly modify styles on a per-element basis throughout your application.
This level of flexibility in your UI component API
makes it easy to use values from your design system's constraints
in situations that you might not have accounted for when creating your components.
Because each component is based on the same base Box component,
the props API for your entire design system can stay consistent,
making it easier to *learn once, use everywhere.*
## Colors
Use the `color` and `bg` (or `backgroundColor`) props to add styles based on the `theme.colors` scale.
```jsx live=true
Hello
```
```jsx
// Keys reference values in the color palette object
// Background color can be set with the `bg` prop
// Raw CSS values that do not map to a key in `theme.colors` can be used
```
## Margin and Padding
Margin and padding can be added to any element based on the `theme.space` scale.
The margin and padding props help promote consistency in layout
without the need to add custom margin and padding declarations throughout an application.
The margin and padding props use a shorthand syntax, similar to other OOCSS approaches and many CSS libraries.
```jsx live=true
Hello
```
- `m`: margin
- `mt`: margin-top
- `mr`: margin-right
- `mb`: margin-bottom
- `ml`: margin-left
- `mx`: margin-left and margin-right
- `my`: margin-top and margin-bottom
- `p` : padding
- `pt`: padding-top
- `pr`: padding-right
- `pb`: padding-bottom
- `pl`: padding-left
- `px`: padding-left and padding-right
- `py`: padding-top and padding-bottom
```jsx
// Numbers reference steps on the spacing scale
// e.g. 8px
// Numbers greater than the length of `theme.space.length` are converted to pixels
// Negative values can be used to add negative margins
// Strings can be used for other values
// Arrays can be used for mobile-first responsive styles
```
## Typography
Use the typography props to change text styles based on values defined in your theme.
```jsx live=true
Hello
```
- `fontSize`
- `fontFamily`
- `fontWeight`
- `lineHeight`
- `letterSpacing`
- `textAlign`
- `fontStyle`
## Layout
Use layout props to change the width, height, display and other values on any element.
```jsx live=true
Hello
```
- `width`
- `minWidth`
- `maxWidth`
- `height`
- `minHeight`
- `maxHeight`
- `display`
- `size` (width and height)
- `verticalAlign`
- `overflow`
### Width
The `width` prop includes an additional ergonomic shorthand for applying percentage-based widths.
Any fractional number from `0` to `1` will be converted to a percentage based width,
allowing you to quickly define responsive grid layouts directly in the components where you need them.
```jsx
```
## Flexbox
Use flexbox props to apply layout styles.
```jsx live=true
Beep
Boop
```
- `alignItems`
- `alignContent`
- `justifyItems`
- `justifyContent`
- `flexWrap`
- `flexDirection`
- `flex`
- `flexGrow`
- `flexShrink`
- `flexBasis`
- `justifySelf`
- `alignSelf`
- `order`
For a full reference of available props, see the [Reflexbox docs](/reflexbox#styled-system-props).
[styled system]: https://styled-system.com
[theme ui]: https://theme-ui.com
[space]: https://styled-system.com/
[color]: https://styled-system.com/
[mdx]: https://mdxjs.com
================================================
FILE: packages/docs/src/pages/recipes/avatar.mdx
================================================
export const title = 'Avatar'
# Avatar
```jsx live=true
```
================================================
FILE: packages/docs/src/pages/recipes/background-image-card.mdx
================================================
# Background Image Card
```jsx live=true
Background Image
```
================================================
FILE: packages/docs/src/pages/recipes/badge.mdx
================================================
export const title = 'Badge'
# Badge
```jsx live=true
Badge
```
================================================
FILE: packages/docs/src/pages/recipes/container.mdx
================================================
export const title = 'Container'
# Container
```jsx live=true
Container
```
================================================
FILE: packages/docs/src/pages/recipes/flexbox-align.mdx
================================================
# Flexbox Align
```jsx live=true
Hello
Grid
```
================================================
FILE: packages/docs/src/pages/recipes/flexbox-grid.mdx
================================================
export const title = 'Flexbox Grid'
# Flexbox Grid
```jsx live=true
Half
Half
```
================================================
FILE: packages/docs/src/pages/recipes/flexbox-wrap.mdx
================================================
export const title = 'Flexbox Wrap'
# Flexbox Wrap
```jsx live=true
1/21/21/31/31/31/41/41/41/4
```
================================================
FILE: packages/docs/src/pages/recipes/image-card.mdx
================================================
# Image Card
```jsx live=true
Image Card
```
================================================
FILE: packages/docs/src/pages/recipes/index.mdx
================================================
import { MDXProvider } from '@mdx-js/react'
import { RecipeCard, Grid } from '../..'
import FlexboxGrid from './flexbox-grid.mdx'
import FlexboxWrap from './flexbox-wrap.mdx'
import FlexboxAlign from './flexbox-align.mdx'
import ImageCard from './image-card.mdx'
import BackgroundImageCard from './background-image-card.mdx'
import NavBar from './nav-bar.mdx'
import VideoEmbed from './video-embed.mdx'
import Container from './container.mdx'
import Avatar from './avatar.mdx'
import Badge from './badge.mdx'
import NavLink from './nav-link.mdx'
export const title = 'Recipes'
# Recipes
Quick copy-and-paste code examples using Rebass.
-
-
-
-
-
-
-
-
-
-
-
================================================
FILE: packages/docs/src/pages/recipes/nav-bar.mdx
================================================
# Nav Bar
```jsx live=true
Rebass
Profile
```
================================================
FILE: packages/docs/src/pages/recipes/nav-link.mdx
================================================
export const title = 'Nav Link'
# Nav Link
```jsx live=true
Nav Link
```
================================================
FILE: packages/docs/src/pages/recipes/video-embed.mdx
================================================
# Video Embed
```jsx live=true
iframe': {
position: 'absolute',
width: '100%',
height: '100%',
top: 0,
bottom: 0,
left: 0,
border: 0
}
}}>
```
================================================
FILE: packages/docs/src/pages/reflexbox.mdx
================================================
import Readme from 'reflexbox/README.md'
export const title = 'Reflexbox'
================================================
FILE: packages/docs/src/pages/space.mdx
================================================
import Readme from '@rebass/space/README.md'
export const title = 'Space'
================================================
FILE: packages/docs/src/pages/text.mdx
================================================
export const title = 'Text'
# Text
Responsive typography component
```jsx live=true
Text
```
================================================
FILE: packages/docs/src/pages/theming.mdx
================================================
export const title = 'Theming'
# Theming
Rebass components are built with themeability in mind.
All colors, typographic styles, layout styles, and component variants can be completely customized with theming.
## ThemeProvider
To apply themes to Rebass components, add a [ThemeProvider][] component to the root of your application and pass a `theme` object as a prop.
If you're using Emotion by itself, install the `emotion-theming` package.
If you're using Rebass with [Theme UI][], use its `ThemeProvider` or the `gatsby-plugin-theme-ui` package.
```jsx
import React from 'react'
import theme from './theme'
import { ThemeProvider } from 'emotion-theming'
// or for use with Theme UI:
// import { ThemeProvider } from 'theme-ui'
export default props =>
{props.children}
```
Rebass follows the [Theme Specification][],
which allows you to define thematic values in a more portable format.
Themes created for [Styled System][] or [Theme UI][] will work with Rebass with no additional configuration required.
This also means that themes created for use with Rebass will work in other applications that follow the same specification.
## Example
The following is an example theme, showing *some* of the design constraints that can be defined as scales,
including colors, typography, layouts, and variants.
```js
// example theme.js
export default {
breakpoints: ['40em', '52em', '64em'],
fontSizes: [
12, 14, 16, 20, 24, 32, 48, 64
],
colors: {
blue: '#07c',
lightgray: '#f6f6ff'
},
space: [
0, 4, 8, 16, 32, 64, 128, 256
],
fonts: {
body: 'system-ui, sans-serif',
heading: 'inherit',
monospace: 'Menlo, monospace',
},
fontWeights: {
body: 400,
heading: 700,
bold: 700,
},
lineHeights: {
body: 1.5,
heading: 1.25,
},
shadows: {
small: '0 0 4px rgba(0, 0, 0, .125)',
large: '0 0 24px rgba(0, 0, 0, .125)'
},
variants: {
},
text: {
},
buttons: {
primary: {
color: 'white',
bg: 'primary',
}
}
}
```
## Preset
To quickly get started without creating a custom theme, install the Rebass Preset package and use it in place of a custom theme.
```sh
npm i @rebass/preset
```
```jsx
import React from 'react'
import { ThemeProvider } from 'emotion-theming'
import preset from '@rebass/preset'
export default props =>
{props.children}
```
## Demo
Edit the theme in the demo below to see how colors, space, and typographic scales affect the Button component.
```jsx live=true
```
[theme specification]: https://github.com/system-ui/theme-specification
[ThemeProvider]: https://www.styled-components.com/docs/advanced#theming
[styled system]: https://github.com/jxnblk/styled-system
[theme ui]: https://theme-ui.com
================================================
FILE: packages/docs/src/pages/variants.mdx
================================================
export const title = 'Variants'
# Variants
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.
For example, with the following defined in the theme object:
```js
// example theme with variants
export default {
colors: {
text: 'black',
background: 'white',
primary: 'tomato',
},
shadows: {
card: '0 0 4px rgba(0, 0, 0, 0.125)',
},
variants: {
card: {
p: 2,
bg: 'background',
boxShadow: 'card',
borderRadius: 2,
},
badge: {
display: 'inline-block',
p: 1,
color: 'white',
bg: 'primary',
borderRadius: 2,
}
},
}
```
The `Box` component can use a variant style to render with preset card or badge styles.
```jsx live=true
Card
Badge
```
By default, Rebass components will use style objects defined in `theme.variants`.
The `Text` and `Heading` components use a custom `theme.text` object, and `Button` uses `theme.buttons`.
Component | Theme Key | Default Variant
---|---|---
`Box` | `variants` | N/A
`Flex` | `variants` | N/A
`Text` | `text` | N/A
`Heading` | `text` | `heading`
`Link` | `variants` | `link`
`Button` | `buttons` | `primary`
`Image` | `variants` | N/A
`Card` | `variants` | `card`
Any object in your theme can be used as a variant, and the values use dot notation for deeply nested values.
```jsx
// example variant with dot notation
```
================================================
FILE: packages/docs/static/_redirects
================================================
/Box /box
/Flex /flex
/Text /text
/Heading /heading
/Button /button
/Link /link
/Image /image
/Card /card
/advanced /guides
/grid /reflexbox
================================================
FILE: packages/forms/.gitignore
================================================
styled-components
dist
================================================
FILE: packages/forms/.npmignore
================================================
test
================================================
FILE: packages/forms/README.md
================================================
# @rebass/forms
Accessible and themeable form components for use with Rebass or Theme UI.
```sh
npm i @rebass/forms
```
```jsx
import React from 'react'
import { Box, Flex } from 'rebass'
import {
Label,
Input,
Select,
Textarea,
Radio,
Checkbox,
} from '@rebass/forms'
export default () =>
e.preventDefault()}
py={3}>
```
See https://rebassjs.org/forms for full documentation.
================================================
FILE: packages/forms/package.json
================================================
{
"name": "@rebass/forms",
"version": "4.0.6",
"main": "dist/index.js",
"module": "dist/index.esm.js",
"scripts": {
"prepare": "rebass-bundler"
},
"dependencies": {
"reflexbox": "^4.0.6"
},
"repository": "rebassjs/rebass",
"bugs": {
"url": "https://github.com/rebassjs/rebass/issues"
},
"license": "MIT",
"publishConfig": {
"access": "public"
},
"gitHead": "f0f01843e9fb63ca69112d7e97a1451b27ee9e6c"
}
================================================
FILE: packages/forms/src/index.js
================================================
import React, { forwardRef } from 'react'
import { Box, Flex } from 'reflexbox'
import { props as systemProps } from '@styled-system/should-forward-prop'
const rebassProps = [
...systemProps,
'sx',
'variant',
]
const PRE = new RegExp(`^(${rebassProps.join('|')})$`)
const MRE = /^m[trblxy]?$/
const getProps = (test) => (props) => {
const next = {}
for (const key in props) {
if (test(key || '')) next[key] = props[key]
}
return next
}
const getSystemProps = getProps(k => PRE.test(k))
const getMarginProps = getProps(k => MRE.test(k))
const omitMarginProps = getProps(k => !MRE.test(k))
const SVG = ({ size = 24, ...props }) =>
export const Label = forwardRef((props, ref) =>
)
export const Input = forwardRef((props, ref) =>
)
const DownArrow = props =>
export const Select = forwardRef((props, ref) =>
)
export const Textarea = forwardRef((props, ref) =>
)
const RadioChecked = props =>
const RadioUnchecked = props =>
const RadioIcon = props =>
<>
>
export const Radio = forwardRef(({
className,
sx,
variant = 'radio',
...props
}, ref) => (
))
const CheckboxChecked = props =>
const CheckboxUnchecked = props =>
const CheckboxIcon = props =>
<>
>
export const Checkbox= forwardRef(({
className,
sx,
variant = 'checkbox',
...props
}, ref) =>
)
export const Slider = forwardRef(({
...props
}, ref) =>
)
export const Switch = forwardRef(({
checked,
...props
}, ref) =>
)
================================================
FILE: packages/forms/test/__snapshots__/index.js.snap
================================================
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Checkbox renders 1`] = `
.emotion-3 {
box-sizing: border-box;
margin: 0;
min-width: 0;
}
.emotion-0 {
box-sizing: border-box;
margin: 0;
min-width: 0;
position: absolute;
opacity: 0;
z-index: -1;
width: 1px;
height: 1px;
overflow: hidden;
}
.emotion-1 {
box-sizing: border-box;
margin: 0;
min-width: 0;
display: none;
width: 24px;
height: 24px;
box-sizing: border-box;
margin: 0;
min-width: 0;
margin-right: 8px;
border-radius: 4px;
color: gray;
}
input:checked ~ .emotion-1 {
display: block;
}
input:checked ~ .emotion-1 {
color: primary;
}
input:focus ~ .emotion-1 {
color: primary;
background-color: highlight;
}
.emotion-2 {
box-sizing: border-box;
margin: 0;
min-width: 0;
display: block;
width: 24px;
height: 24px;
box-sizing: border-box;
margin: 0;
min-width: 0;
margin-right: 8px;
border-radius: 4px;
color: gray;
}
input:checked ~ .emotion-2 {
display: none;
}
input:checked ~ .emotion-2 {
color: primary;
}
input:focus ~ .emotion-2 {
color: primary;
background-color: highlight;
}