Skip to content

Commit

Permalink
Merge pull request #1841 from system-ui/vercel-redirects
Browse files Browse the repository at this point in the history
Add redirects back to docs.
  • Loading branch information
hasparus committed Jun 23, 2021
2 parents 0fefcef + 6303a02 commit 9343cf8
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 115 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ coverage
.publish-log.txt
.yarn-error.log


.vercel
7 changes: 2 additions & 5 deletions packages/docs/gatsby-browser.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
// @ts-check
// @see https://www.gatsbyjs.com/docs/reference/config-files/gatsby-browser/

import * as React from 'react'

import { WrapPageElement, setDocSearchComponents } from './src'
import { WrapPageElement } from './src'

export const wrapPageElement = (props) => <WrapPageElement {...props} />

export const onRenderBody = (args) => {
setDocSearchComponents(args)
}
1 change: 1 addition & 0 deletions packages/docs/gatsby-ssr.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @ts-check
// @see https://www.gatsbyjs.com/docs/reference/config-files/gatsby-ssr/

import * as React from 'react'

Expand Down
48 changes: 27 additions & 21 deletions packages/docs/src/components/button.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
/** @jsx jsx */
import { jsx } from 'theme-ui'

export default (props) => (
<button
{...props}
sx={{
appearance: 'none',
fontFamily: 'inherit',
fontSize: 1,
fontWeight: 'bold',
m: 0,
px: 2,
py: 2,
color: 'text',
bg: 'muted',
border: 0,
borderRadius: 2,
}}
/>
)
/** @jsx jsx */
import { jsx } from 'theme-ui'

/**
* @param {React.ComponentPropsWithoutRef<"button">} props
*/
export default function DocsButton(props) {
return (
<button
{...props}
sx={{
appearance: 'none',
fontFamily: 'inherit',
fontSize: 1,
fontWeight: 'bold',
m: 0,
px: 2,
py: 2,
color: 'text',
bg: 'muted',
border: 0,
borderRadius: 2,
cursor: 'pointer',
}}
/>
)
}
138 changes: 69 additions & 69 deletions packages/docs/src/pages/guides/motivation.mdx
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
---
title: Motivation
---

# Motivation

One of the primary motivations behind Theme UI is to make building themeable, constraint-based user interfaces in React as simple and as interoperable as possible.
This library builds upon years of work on various libraries, including [Basscss][], [Tachyons][], [Rebass][], [Styled System][], and various other internal style guides and design systems.
While some of the ideas encapsulated within this library may seem familiar, the intent here is to combine modern CSS tooling into a single "mini-framework" with good guidance on how to fall into the pit of success for creating white-label products, themed component libraries, and even full websites.

[basscss]: https://github.com/basscss/basscss
[tachyons]: https://tachyons.io
[rebass]: https://rebassjs.org
[styled system]: https://styled-system.com

## MDX

MDX has, in my opinion, quickly become one of the best ways to render Markdown in React.
The ability to render custom React components for any Markdown element with the `MDXProvider` is a very powerful API and has the potential to open up how Markdown is leveraged in ways I think we'll continue to see evolve over the coming years.

While the final rendered HTML _can_ be styled using global CSS or a wrapping element with child selectors, there are certainly drawbacks to this approach,
and they can lead to unexpected styling bugs when composing themes together.
Using the `MDXProvider` to render custom styled components in MDX is a great way to avoid this, but the overhead for applying styles in this way can be a lot of work, even with UI component libraries like Rebass or Material UI.
Theme UI includes the `theme.styles` API as a light abstraction on top of this, that hopefully feels familiar to people from diverse backgrounds, even those with little or no experience using MDX.

For examples of previous explorations into this idea, see [Rebass MDX][], [MDX Style][], and [MDX Blocks][].

[rebass mdx]: https://github.com/rebassjs/mdx
[mdx style]: https://github.com/jxnblk/mdx-style
[mdx blocks]: https://github.com/jxnblk/mdx-blocks

## The `css` and `sx` Props

The `css` prop is a powerful pattern for styling UI in React.
It works like the built-in `style` prop, but it includes some of the best parts of the CSS language, including media queries and pseudo-classes, and can be authored in native JavaScript object literal syntax.
The `css` prop can be leveraged in a similar way to the `styled` higher-order component, but also offers more flexibility when making one-off, context-specific stylistic changes.
The `css` prop also avoids some of the [pitfalls of mixing CSS properties with HTML attributes](https://github.com/styled-components/styled-components/issues/439).

The `sx` prop is a light abstraction on top of the `css` prop that can serve as a complete replacement and makes it easier to
ensure you use values from your global `theme` object.

## Why Object Literal Syntax

For many, the choice between using object literal syntax for styles versus tagged template literals comes down to personal preference, but in the case of Theme UI, there are some fundamental reasons for using native JavaScript types for styles.

The `theme` object itself is an object, and keeping styles in a similar format helps reduce the API surface area.
Using and parsing strings that represent embedded DSLs introduces overhead when mapping over key-value pairs.
Theme UI avoids this overhead for reasons related to performance, testing, and overall bundle size.
For some of the [same reasons](https://facebook.github.io/jsx/) that React itself uses JSX (i.e. function calls) instead of tagged template literals, Theme UI only includes support for authoring CSS with object literal syntax.
Additionally, using native JavaScript types has many other benefits that are outside of the scope of this document.

## Why Emotion

While there are many different solutions to handling CSS in JavaScript, Styled Components and Emotion have become the most widely-used industry-standard libraries.
If you're building a custom component library, either Styled Components or Emotion should suit your needs just fine.

For Theme UI, the decision was primarily based on these factors:

- Emotion's implementation of the `css` prop and the custom JSX pragma allows for better integration with Theme UI's `sx` prop
- The Emotion API includes more lower-level utilities, like `createEmotion` that could be leveraged when considering how multiple themes could be composed together
- Emotion's theming context is directly available in `@emotion/react`, allowing this library to leverage React's context API in different ways
- In the case of Theme UI internals, the `styled` higher-order component utility is not necessarily the best API for creating components,
and by not including `@emotion/styled` in the core package the bundle size is kept to a minimum – i.e. most of the same things can be achieved with the `css` prop

## How is this different from Styled System

Theme UI's `sx` prop was inspired by Styled System, and it uses the same theme spec that Styled System adheres to. Styled System is a much lower-level API that is not in any way coupled to React or Emotion.
For example, Styled System works with Node.js, Vuejs, Svelte, and many other libraries.
Theme UI is intended to be a higher-level abstraction specifically for use in React applications and includes features that will not likely be added to the core Styled System library.
---
title: Motivation
---

# Motivation

One of the primary motivations behind Theme UI is to make building themeable, constraint-based user interfaces in React as simple and as interoperable as possible.
This library builds upon years of work on various libraries, including [Basscss][], [Tachyons][], [Rebass][], [Styled System][], and various other internal style guides and design systems.
While some of the ideas encapsulated within this library may seem familiar, the intent here is to combine modern CSS tooling into a single "mini-framework" with good guidance on how to fall into the pit of success for creating white-label products, themed component libraries, and even full websites.

[basscss]: https://github.com/basscss/basscss
[tachyons]: https://tachyons.io
[rebass]: https://rebassjs.org
[styled system]: https://styled-system.com

## MDX

MDX has, in my opinion, quickly become one of the best ways to render Markdown in React.
The ability to render custom React components for any Markdown element with the `MDXProvider` is a very powerful API and has the potential to open up how Markdown is leveraged in ways I think we'll continue to see evolve over the coming years.

While the final rendered HTML _can_ be styled using global CSS or a wrapping element with child selectors, there are certainly drawbacks to this approach,
and they can lead to unexpected styling bugs when composing themes together.
Using the `MDXProvider` to render custom styled components in MDX is a great way to avoid this, but the overhead for applying styles in this way can be a lot of work, even with UI component libraries like Rebass or Material UI.
Theme UI includes the `theme.styles` API as a light abstraction on top of this, that hopefully feels familiar to people from diverse backgrounds, even those with little or no experience using MDX.

For examples of previous explorations into this idea, see [Rebass MDX][], [MDX Style][], and [MDX Blocks][].

[rebass mdx]: https://github.com/rebassjs/mdx
[mdx style]: https://github.com/jxnblk/mdx-style
[mdx blocks]: https://github.com/jxnblk/mdx-blocks

## The `css` and `sx` Props

The `css` prop is a powerful pattern for styling UI in React.
It works like the built-in `style` prop, but it includes some of the best parts of the CSS language, including media queries and pseudo-classes, and can be authored in native JavaScript object literal syntax.
The `css` prop can be leveraged in a similar way to the `styled` higher-order component, but also offers more flexibility when making one-off, context-specific stylistic changes.
The `css` prop also avoids some of the [pitfalls of mixing CSS properties with HTML attributes](https://github.com/styled-components/styled-components/issues/439).

The `sx` prop is a light abstraction on top of the `css` prop that can serve as a complete replacement and makes it easier to
ensure you use values from your global `theme` object.

## Why Object Literal Syntax

For many, the choice between using object literal syntax for styles versus tagged template literals comes down to personal preference, but in the case of Theme UI, there are some fundamental reasons for using native JavaScript types for styles.

The `theme` object itself is an object, and keeping styles in a similar format helps reduce the API surface area.
Using and parsing strings that represent embedded DSLs introduces overhead when mapping over key-value pairs.
Theme UI avoids this overhead for reasons related to performance, testing, and overall bundle size.
For some of the [same reasons](https://facebook.github.io/jsx/) that React itself uses JSX (i.e. function calls) instead of tagged template literals, Theme UI only includes support for authoring CSS with object literal syntax.
Additionally, using native JavaScript types has many other benefits that are outside of the scope of this document.

## Why Emotion

While there are many different solutions to handling CSS in JavaScript, Styled Components and Emotion have become the most widely-used industry-standard libraries.
If you're building a custom component library, either Styled Components or Emotion should suit your needs just fine.

For Theme UI, the decision was primarily based on these factors:

- Emotion's implementation of the `css` prop and the custom JSX pragma allows for better integration with Theme UI's `sx` prop
- The Emotion API includes more lower-level utilities, like `createEmotion` that could be leveraged when considering how multiple themes could be composed together
- Emotion's theming context is directly available in `@emotion/react`, allowing this library to leverage React's context API in different ways
- In the case of Theme UI internals, the `styled` higher-order component utility is not necessarily the best API for creating components,
and by not including `@emotion/styled` in the core package the bundle size is kept to a minimum – i.e. most of the same things can be achieved with the `css` prop

## How is this different from Styled System

Theme UI's `sx` prop was inspired by Styled System, and it uses the same theme spec that Styled System adheres to. Styled System is a much lower-level API that is not in any way coupled to React or Emotion.
For example, Styled System works with Node.js, Vue, Svelte, and many other libraries.
Theme UI is intended to be a higher-level abstraction specifically for use in React applications.
20 changes: 0 additions & 20 deletions packages/docs/static/_redirects

This file was deleted.

77 changes: 77 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"redirects": [
{
"source": "/use-theme-ui",
"destination": "/hooks",
"permanent": false
},
{
"source": "/how-it-works",
"destination": "/guides/how-it-works",
"permanent": false
},
{
"source": "/jsx-pragma",
"destination": "/guides/jsx-pragma",
"permanent": false
},
{
"source": "/motivation",
"destination": "/guides/motivation",
"permanent": false
},
{
"source": "/object-styles",
"destination": "/guides/object-styles",
"permanent": false
},
{
"source": "/presets",
"destination": "/packages/presets"
},
{
"source": "/prism",
"destination": "/packages/prism"
},
{
"source": "/color",
"destination": "/packages/color"
},
{
"source": "/style-guide",
"destination": "/packages/style-guide"
},
{
"source": "/editor",
"destination": "/packages/editor"
},
{
"source": "/gatsby-plugin",
"destination": "/packages/gatsby-plugin"
},
{
"source": "/gatsby-theme-ui-blog",
"destination": "/packages/gatsby-theme-ui-blog"
},
{
"source": "/gatsby-theme-style-guide",
"destination": "/packages/gatsby-theme-style-guide"
},
{
"source": "/typography",
"destination": "/packages/typography"
},
{
"source": "/match-media",
"destination": "/packages/match-media"
},
{
"source": "/css/tachyons",
"destination": "/packages/tachyons"
},
{
"source": "/css/tailwind",
"destination": "/packages/tailwind"
}
]
}

1 comment on commit 9343cf8

@vercel
Copy link

@vercel vercel bot commented on 9343cf8 Jun 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.