-
Notifications
You must be signed in to change notification settings - Fork 672
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1877 from system-ui/docs-theme-provider-earlier
Improve documentation
- Loading branch information
Showing
15 changed files
with
186 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,49 @@ | ||
# @theme-ui/css | ||
|
||
Theme UI CSS lets you write style objects with responsive, theme-aware ergonomic shortcuts. | ||
This package powers the `sx` prop in Theme UI. | ||
[![Minified Size on Bundlephobia](https://badgen.net/bundlephobia/minzip/@theme-ui/css)](https://bundlephobia.com/package/@theme-ui/css) | ||
|
||
`@theme-ui/css` contains the framework-agnostic core logic of Theme UI. It lets | ||
you write style objects with responsive, theme-aware ergonomic shortcuts. | ||
|
||
```sh | ||
npm i @theme-ui/css | ||
``` | ||
|
||
https://theme-ui.com | ||
## Usage | ||
|
||
```js | ||
import { css as transformStyleObject } from '@theme-ui/css' | ||
import { css as createClassName } from '@emotion/css' | ||
|
||
const root = document.getElementById('root') | ||
|
||
/** @type {import("@theme-ui/css").Theme} */ | ||
const theme = { | ||
colors: { | ||
text: '#222', | ||
}, | ||
fonts: { | ||
mono: 'monospace', | ||
}, | ||
space: { | ||
sm: '1rem', | ||
md: '2rem', | ||
}, | ||
} | ||
|
||
const styles = transformStyleObject({ | ||
padding: ['sm', 'md'], | ||
border: ({ colors }) => `2px solid ${colors.text}`, | ||
h1: { | ||
fontFamily: 'mono', | ||
color: 'text', | ||
}, | ||
})(theme) | ||
|
||
root.classList.add(createClassName(styles)) | ||
root.innerHTML = ` | ||
<h1>You can use <code>@theme-ui/css</code> in Vanilla JS!</h1> | ||
` | ||
``` | ||
|
||
[See the snippet above on CodeSandbox](https://codesandbox.io/s/theme-ui-css-framework-agnostic-2c0ue?file=/src/index.js) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { | ||
import type { | ||
CSSObject, | ||
ThemeUIStyleObject, | ||
ThemeDerivedStyles, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
declare module '!!raw-loader!*' { | ||
const content: string | ||
export default content | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"compilerOptions": { | ||
"jsx": "preserve" | ||
}, | ||
"exclude": [".cache", "node_modules", "public"], | ||
"include": ["**/*.js", "./declarations.d.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// @ts-check | ||
import React from 'react' | ||
import Snippet from '@theme-ui/prism' | ||
|
||
import themeCreationRaw from '!!raw-loader!./snippets/theme.tsx' | ||
import basicUsageRaw from '!!raw-loader!./snippets/basic-usage.tsx' | ||
|
||
const IntroCodeSamples = { | ||
ThemeCreation() { | ||
return <Snippet className="language-tsx" children={themeCreationRaw} /> | ||
}, | ||
BasicUsage() { | ||
return <Snippet className="language-tsx" children={basicUsageRaw} /> | ||
}, | ||
} | ||
|
||
export default IntroCodeSamples |
15 changes: 15 additions & 0 deletions
15
packages/docs/src/components/intro-code-samples/snippets/basic-usage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** @jsxImportSource theme-ui */ | ||
import { ThemeProvider } from 'theme-ui' | ||
import { theme } from './theme' | ||
|
||
export const App = () => ( | ||
<ThemeProvider theme={theme}> | ||
<h1 | ||
sx={{ | ||
color: 'primary', | ||
fontFamily: 'heading', | ||
}}> | ||
Hello | ||
</h1> | ||
</ThemeProvider> | ||
) |
14 changes: 14 additions & 0 deletions
14
packages/docs/src/components/intro-code-samples/snippets/theme.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { Theme } from 'theme-ui' | ||
|
||
export const theme: Theme = { | ||
fonts: { | ||
body: 'system-ui, sans-serif', | ||
heading: '"Avenir Next", sans-serif', | ||
monospace: 'Menlo, monospace', | ||
}, | ||
colors: { | ||
text: '#000', | ||
background: '#fff', | ||
primary: '#33e', | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.