├── packages ├── edit │ ├── .npmignore │ ├── .gitignore │ ├── test │ │ ├── __snapshots__ │ │ │ └── index.js.snap │ │ └── index.js │ ├── package.json │ └── README.md ├── jsx │ ├── .npmignore │ ├── src │ │ └── index.js │ ├── package.json │ ├── README.md │ └── test │ │ └── index.js ├── prop-types │ ├── .gitignore │ ├── .npmignore │ ├── test │ │ └── index.js │ ├── README.md │ ├── package.json │ └── src │ │ └── index.js ├── styled-system │ ├── .npmignore │ ├── package.json │ ├── test │ │ ├── shim.js │ │ └── styles.js │ └── src │ │ └── index.js ├── css │ ├── .npmignore │ ├── package.json │ ├── README.md │ └── src │ │ └── index.js ├── theme-get │ ├── src │ │ └── index.js │ ├── package.json │ └── test │ │ └── index.js ├── border │ ├── test │ │ └── index.js │ ├── package.json │ └── src │ │ └── index.js ├── grid │ ├── test │ │ └── index.js │ ├── package.json │ └── src │ │ └── index.js ├── background │ ├── test │ │ └── index.js │ ├── package.json │ └── src │ │ └── index.js ├── color │ ├── test │ │ └── index.js │ ├── src │ │ └── index.js │ └── package.json ├── flexbox │ ├── test │ │ └── index.js │ ├── package.json │ └── src │ │ └── index.js ├── typography │ ├── test │ │ └── index.js │ ├── package.json │ └── src │ │ └── index.js ├── position │ ├── test │ │ └── index.js │ ├── src │ │ └── index.js │ └── package.json ├── shadow │ ├── src │ │ └── index.js │ ├── package.json │ └── test │ │ └── index.js ├── layout │ ├── package.json │ ├── test │ │ └── index.js │ └── src │ │ └── index.js ├── core │ ├── package.json │ ├── test │ │ ├── merge.js │ │ ├── compose.js │ │ ├── get.js │ │ └── system.js │ └── src │ │ └── index.js ├── should-forward-prop │ ├── test │ │ └── index.js │ ├── package.json │ ├── src │ │ └── index.js │ └── README.md ├── space │ ├── package.json │ ├── src │ │ └── index.js │ └── test │ │ └── index.js └── variant │ ├── package.json │ ├── src │ └── index.js │ └── test │ └── index.js ├── .prettierignore ├── docs ├── .gitignore ├── gatsby-browser.js ├── gatsby-ssr.js ├── static │ ├── logo.png │ ├── logo-white.png │ ├── logo.svg │ └── logo-white.svg ├── guides │ ├── exceptions.md │ ├── scale-aliases.md │ ├── index.md │ ├── default-values.md │ ├── component-types.md │ ├── array-props.md │ ├── removing-props-from-html.md │ ├── why-powers-of-two.md │ ├── array-scales.md │ ├── color-modes.md │ └── spacing.md ├── src │ ├── pages │ │ ├── css │ │ │ └── index.js │ │ ├── babel-plugin │ │ │ └── index.js │ │ ├── beep.js │ │ ├── 404.js │ │ ├── demo.js │ │ └── index.js │ ├── example.mdx │ ├── link.js │ ├── components.js │ ├── button.js │ ├── logo │ │ ├── white.js │ │ ├── index.js │ │ └── hex.js │ ├── burger.js │ ├── doc.js │ ├── nav-link.js │ ├── edit-link.js │ ├── sidebar.mdx │ ├── badges.md │ ├── logos.mdx │ ├── sidebar.js │ ├── toc-wrapper.js │ ├── index.js │ ├── pagination.js │ ├── layout.js │ └── theme.js ├── articles.md ├── showcase.md ├── theming.md ├── gatsby-node.js ├── package.json ├── testimonials.md ├── rationale.md ├── how-it-works.md ├── responsive-styles.md ├── variants.md ├── custom-props.md ├── gatsby-config.js └── packages.md ├── README.md ├── examples ├── babel-plugin │ ├── .gitignore │ ├── gatsby-config.js │ ├── .prettierrc │ ├── babel.config.js │ ├── package.json │ └── src │ │ └── pages │ │ └── index.js ├── basic │ ├── README.md │ ├── public │ │ └── index.html │ ├── package.json │ ├── .gitignore │ └── src │ │ └── index.js ├── css │ ├── README.md │ ├── .gitignore │ ├── package.json │ └── src │ │ └── index.js ├── jsx │ ├── README.md │ ├── .gitignore │ ├── package.json │ └── src │ │ └── index.js ├── emotion │ ├── README.md │ ├── public │ │ └── index.html │ ├── .gitignore │ ├── package.json │ └── src │ │ └── index.js ├── responsive-objects │ ├── README.md │ ├── .gitignore │ ├── package.json │ └── src │ │ └── index.js ├── theme-aliases │ ├── README.md │ ├── public │ │ └── index.html │ ├── package.json │ ├── .gitignore │ └── src │ │ └── index.js └── svelte │ ├── index.js │ ├── theme.js │ ├── App.svelte │ ├── package.json │ ├── rollup.config.js │ └── README.md ├── .prettierrc ├── .gitignore ├── lerna.json ├── .npmignore ├── benchmarks ├── package.json ├── README.md └── test.js ├── babel.config.js ├── .circleci └── config.yml ├── LICENSE.md ├── CONTRIBUTING.md ├── package.json └── CODE_OF_CONDUCT.md /packages/edit/.npmignore: -------------------------------------------------------------------------------- 1 | docs 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | .cache 2 | public 3 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | public 2 | .cache 3 | -------------------------------------------------------------------------------- /packages/edit/.gitignore: -------------------------------------------------------------------------------- 1 | dist.js 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | packages/styled-system/README.md -------------------------------------------------------------------------------- /packages/jsx/.npmignore: -------------------------------------------------------------------------------- 1 | test 2 | src 3 | -------------------------------------------------------------------------------- /packages/prop-types/.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | -------------------------------------------------------------------------------- /examples/babel-plugin/.gitignore: -------------------------------------------------------------------------------- 1 | .cache 2 | public 3 | -------------------------------------------------------------------------------- /examples/babel-plugin/gatsby-config.js: -------------------------------------------------------------------------------- 1 | module.exports = {} 2 | -------------------------------------------------------------------------------- /packages/prop-types/.npmignore: -------------------------------------------------------------------------------- 1 | src 2 | test 3 | babel.config.js 4 | -------------------------------------------------------------------------------- /packages/styled-system/.npmignore: -------------------------------------------------------------------------------- 1 | src 2 | test 3 | babel.config.js 4 | -------------------------------------------------------------------------------- /docs/gatsby-browser.js: -------------------------------------------------------------------------------- 1 | export { wrapRootElement, wrapPageElement } from './src' 2 | -------------------------------------------------------------------------------- /docs/gatsby-ssr.js: -------------------------------------------------------------------------------- 1 | export { wrapRootElement, wrapPageElement } from './src' 2 | -------------------------------------------------------------------------------- /packages/css/.npmignore: -------------------------------------------------------------------------------- 1 | test 2 | src 3 | coverage 4 | .nyc_output 5 | babel.config.js 6 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": false, 3 | "singleQuote": true, 4 | "trailingComma": "es5" 5 | } -------------------------------------------------------------------------------- /docs/static/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drFabio/styled-system/master/docs/static/logo.png -------------------------------------------------------------------------------- /examples/basic/README.md: -------------------------------------------------------------------------------- 1 | # Styled System Basic Demo 2 | 3 | ```sh 4 | npm i && npm start 5 | ``` 6 | -------------------------------------------------------------------------------- /examples/css/README.md: -------------------------------------------------------------------------------- 1 | # Styled System CSS Example 2 | 3 | ```sh 4 | npm i && npm start 5 | ``` 6 | -------------------------------------------------------------------------------- /examples/jsx/README.md: -------------------------------------------------------------------------------- 1 | # Styled System JSX Example 2 | 3 | ```sh 4 | npm i && npm start 5 | ``` 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | node_modules 3 | .nyc_output 4 | coverage* 5 | site 6 | public 7 | package-lock.json 8 | -------------------------------------------------------------------------------- /examples/emotion/README.md: -------------------------------------------------------------------------------- 1 | # Styled System Emotion Demo 2 | 3 | ```sh 4 | npm i && npm start 5 | ``` 6 | -------------------------------------------------------------------------------- /docs/static/logo-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drFabio/styled-system/master/docs/static/logo-white.png -------------------------------------------------------------------------------- /examples/babel-plugin/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": false, 3 | "singleQuote": true, 4 | "trailingComma": "es5" 5 | } -------------------------------------------------------------------------------- /examples/responsive-objects/README.md: -------------------------------------------------------------------------------- 1 | # Styled System Basic Demo 2 | 3 | ```sh 4 | npm i && npm start 5 | ``` 6 | -------------------------------------------------------------------------------- /examples/theme-aliases/README.md: -------------------------------------------------------------------------------- 1 | # Styled System Theme Aliases Demo 2 | 3 | ```sh 4 | npm i && npm start 5 | ``` 6 | -------------------------------------------------------------------------------- /examples/svelte/index.js: -------------------------------------------------------------------------------- 1 | import App from "./App.svelte"; 2 | 3 | const app = new App({ 4 | target: document.body 5 | }); 6 | 7 | export default app; 8 | -------------------------------------------------------------------------------- /docs/guides/exceptions.md: -------------------------------------------------------------------------------- 1 | # Exceptions 2 | 3 | This page is a stub. 4 | 5 | 10 | -------------------------------------------------------------------------------- /examples/svelte/theme.js: -------------------------------------------------------------------------------- 1 | export default { 2 | fonts: { 3 | body: 'system-ui, sans-serif', 4 | }, 5 | colors: { 6 | primary: 'tomato', 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /docs/guides/scale-aliases.md: -------------------------------------------------------------------------------- 1 | # Scale Aliases 2 | 3 | This page is a stub. 4 | 5 | 10 | -------------------------------------------------------------------------------- /examples/babel-plugin/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['babel-preset-gatsby', '@emotion/babel-preset-css-prop'], 3 | plugins: ['@styled-system/babel-plugin'], 4 | } 5 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "5.0.5", 3 | "npmClient": "yarn", 4 | "packages": [ 5 | "packages/*" 6 | ], 7 | "create": { 8 | "license": "MIT" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/edit/test/__snapshots__/index.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`renders 1`] = ` 4 |
7 | `; 8 | -------------------------------------------------------------------------------- /packages/theme-get/src/index.js: -------------------------------------------------------------------------------- 1 | import { get } from '@styled-system/core' 2 | 3 | export const themeGet = (path, fallback = null) => props => 4 | get(props.theme, path, fallback) 5 | export default themeGet 6 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .prettierrc 3 | .nyc_output 4 | .travis.yml 5 | coverage 6 | coverage.lcov 7 | bench 8 | docs 9 | src 10 | examples 11 | babel.config.js 12 | test 13 | CONTRIBUTING.md 14 | CODE_OF_CONDUCT.md 15 | -------------------------------------------------------------------------------- /packages/border/test/index.js: -------------------------------------------------------------------------------- 1 | import border from '../src' 2 | 3 | test('returns border styles', () => { 4 | const style = border({ border: '1px solid gold' }) 5 | expect(style).toEqual({ border: '1px solid gold' }) 6 | }) 7 | -------------------------------------------------------------------------------- /examples/basic/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | styled-system sandbox 5 |
6 | -------------------------------------------------------------------------------- /packages/grid/test/index.js: -------------------------------------------------------------------------------- 1 | import grid from '../src' 2 | 3 | test('returns grid styles', () => { 4 | const style = grid({ 5 | gridGap: 32, 6 | }) 7 | expect(style).toEqual({ 8 | gridGap: 32, 9 | }) 10 | }) 11 | -------------------------------------------------------------------------------- /examples/emotion/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | styled-system sandbox 5 |
6 | -------------------------------------------------------------------------------- /examples/theme-aliases/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | styled-system sandbox 5 |
6 | -------------------------------------------------------------------------------- /packages/background/test/index.js: -------------------------------------------------------------------------------- 1 | import background from '../src' 2 | 3 | test('returns background styles', () => { 4 | const style = background({ backgroundImage: 'url(kitten.gif)' }) 5 | expect(style).toEqual({ backgroundImage: 'url(kitten.gif)' }) 6 | }) 7 | -------------------------------------------------------------------------------- /docs/src/pages/css/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Readme from '@styled-system/css/README.md' 3 | import Layout from '../../layout' 4 | 5 | export default props => { 6 | return ( 7 | 8 | 9 | 10 | ) 11 | } 12 | -------------------------------------------------------------------------------- /packages/color/test/index.js: -------------------------------------------------------------------------------- 1 | import color from '../src' 2 | 3 | test('returns colors styles', () => { 4 | const style = color({ 5 | color: 'gold', 6 | bg: 'tomato', 7 | }) 8 | expect(style).toEqual({ 9 | color: 'gold', 10 | backgroundColor: 'tomato', 11 | }) 12 | }) 13 | -------------------------------------------------------------------------------- /docs/src/pages/babel-plugin/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Readme from '@styled-system/babel-plugin/README.md' 3 | import Layout from '../../layout' 4 | 5 | export default props => { 6 | return ( 7 | 8 | 9 | 10 | ) 11 | } 12 | -------------------------------------------------------------------------------- /packages/flexbox/test/index.js: -------------------------------------------------------------------------------- 1 | import flexbox from '../src' 2 | 3 | test('returns flexbox styles', () => { 4 | const style = flexbox({ 5 | alignItems: 'center', 6 | flex: '1 1 auto', 7 | }) 8 | expect(style).toEqual({ 9 | alignItems: 'center', 10 | flex: '1 1 auto', 11 | }) 12 | }) 13 | -------------------------------------------------------------------------------- /packages/typography/test/index.js: -------------------------------------------------------------------------------- 1 | import typography from '../src' 2 | 3 | test('returns typography styles', () => { 4 | const style = typography({ 5 | fontSize: 32, 6 | fontWeight: 'bold', 7 | }) 8 | expect(style).toEqual({ 9 | fontSize: 32, 10 | fontWeight: 'bold', 11 | }) 12 | }) 13 | -------------------------------------------------------------------------------- /examples/basic/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@styled-system/basic-demo", 3 | "version": "5.0.0-7", 4 | "private": true, 5 | "dependencies": { 6 | "react": "^16.8.5", 7 | "react-dom": "^16.8.5", 8 | "styled-components": "^4.2.0", 9 | "styled-system": "5.0.0-8" 10 | }, 11 | "scripts": {} 12 | } 13 | -------------------------------------------------------------------------------- /packages/position/test/index.js: -------------------------------------------------------------------------------- 1 | import position from '../src' 2 | 3 | test('returns position styles', () => { 4 | const style = position({ 5 | position: 'absolute', 6 | top: 0, 7 | right: 0, 8 | }) 9 | expect(style).toEqual({ 10 | position: 'absolute', 11 | top: 0, 12 | right: 0, 13 | }) 14 | }) 15 | -------------------------------------------------------------------------------- /packages/shadow/src/index.js: -------------------------------------------------------------------------------- 1 | import { system } from '@styled-system/core' 2 | 3 | export const shadow = system({ 4 | boxShadow: { 5 | property: 'boxShadow', 6 | scale: 'shadows', 7 | }, 8 | textShadow: { 9 | property: 'textShadow', 10 | scale: 'shadows', 11 | }, 12 | }) 13 | 14 | export default shadow 15 | -------------------------------------------------------------------------------- /examples/theme-aliases/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@styled-system/theme-aliases-example", 3 | "version": "5.0.0-7", 4 | "private": true, 5 | "dependencies": { 6 | "react": "^16.8.5", 7 | "react-dom": "^16.8.5", 8 | "styled-components": "^4.2.0", 9 | "styled-system": "5.0.0-8" 10 | }, 11 | "scripts": {} 12 | } 13 | -------------------------------------------------------------------------------- /docs/src/pages/beep.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { Box } from 'theme-ui' 3 | import Logo from '../logo' 4 | import LogoWhite from '../logo/white' 5 | 6 | export default props => ( 7 | <> 8 | 9 | 10 | 11 | 12 | 13 | 14 | ) 15 | -------------------------------------------------------------------------------- /packages/position/src/index.js: -------------------------------------------------------------------------------- 1 | import { system } from '@styled-system/core' 2 | 3 | const config = { 4 | position: true, 5 | zIndex: { 6 | property: 'zIndex', 7 | scale: 'zIndices', 8 | }, 9 | top: true, 10 | right: true, 11 | bottom: true, 12 | left: true, 13 | } 14 | 15 | export const position = system(config) 16 | 17 | export default position 18 | -------------------------------------------------------------------------------- /docs/src/example.mdx: -------------------------------------------------------------------------------- 1 | 2 | ## Expressive, consistent UI components 3 | 4 | Styled System lets you quickly build custom UI components with constraint-based style props based on your own design system tokens. 5 | 6 | ```jsx 7 | 14 | Hello 15 | 16 | ``` 17 | -------------------------------------------------------------------------------- /benchmarks/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "name": "benchmarks", 4 | "version": "5.0.0-8", 5 | "scripts": { 6 | "test": "node test.js" 7 | }, 8 | "dependencies": { 9 | "@styled-system/css": "5.0.1", 10 | "@xstyled/system": "^1.0.0", 11 | "benchmark": "^2.1.4", 12 | "styled-system": "^5.0.1", 13 | "system-v4": "npm:styled-system@4.2.2" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/basic/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | 6 | # testing 7 | /coverage 8 | 9 | # production 10 | /build 11 | 12 | # misc 13 | .DS_Store 14 | .env.local 15 | .env.development.local 16 | .env.test.local 17 | .env.production.local 18 | 19 | npm-debug.log* 20 | yarn-debug.log* 21 | yarn-error.log* 22 | -------------------------------------------------------------------------------- /examples/css/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | 6 | # testing 7 | /coverage 8 | 9 | # production 10 | /build 11 | 12 | # misc 13 | .DS_Store 14 | .env.local 15 | .env.development.local 16 | .env.test.local 17 | .env.production.local 18 | 19 | npm-debug.log* 20 | yarn-debug.log* 21 | yarn-error.log* 22 | -------------------------------------------------------------------------------- /examples/emotion/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | 6 | # testing 7 | /coverage 8 | 9 | # production 10 | /build 11 | 12 | # misc 13 | .DS_Store 14 | .env.local 15 | .env.development.local 16 | .env.test.local 17 | .env.production.local 18 | 19 | npm-debug.log* 20 | yarn-debug.log* 21 | yarn-error.log* 22 | -------------------------------------------------------------------------------- /examples/jsx/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | 6 | # testing 7 | /coverage 8 | 9 | # production 10 | /build 11 | 12 | # misc 13 | .DS_Store 14 | .env.local 15 | .env.development.local 16 | .env.test.local 17 | .env.production.local 18 | 19 | npm-debug.log* 20 | yarn-debug.log* 21 | yarn-error.log* 22 | -------------------------------------------------------------------------------- /examples/theme-aliases/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | 6 | # testing 7 | /coverage 8 | 9 | # production 10 | /build 11 | 12 | # misc 13 | .DS_Store 14 | .env.local 15 | .env.development.local 16 | .env.test.local 17 | .env.production.local 18 | 19 | npm-debug.log* 20 | yarn-debug.log* 21 | yarn-error.log* 22 | -------------------------------------------------------------------------------- /packages/color/src/index.js: -------------------------------------------------------------------------------- 1 | import { system } from '@styled-system/core' 2 | 3 | const config = { 4 | color: { 5 | property: 'color', 6 | scale: 'colors', 7 | }, 8 | backgroundColor: { 9 | property: 'backgroundColor', 10 | scale: 'colors', 11 | }, 12 | opacity: true, 13 | } 14 | config.bg = config.backgroundColor 15 | 16 | export const color = system(config) 17 | export default color 18 | -------------------------------------------------------------------------------- /examples/responsive-objects/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | 6 | # testing 7 | /coverage 8 | 9 | # production 10 | /build 11 | 12 | # misc 13 | .DS_Store 14 | .env.local 15 | .env.development.local 16 | .env.test.local 17 | .env.production.local 18 | 19 | npm-debug.log* 20 | yarn-debug.log* 21 | yarn-error.log* 22 | -------------------------------------------------------------------------------- /packages/jsx/src/index.js: -------------------------------------------------------------------------------- 1 | import { jsx as emotion } from '@emotion/core' 2 | import css from '@styled-system/css' 3 | 4 | export const jsx = (type, props, ...children) => { 5 | return emotion.apply(undefined, [ 6 | type, 7 | props 8 | ? { 9 | ...props, 10 | css: css(props.css), 11 | } 12 | : null, 13 | ...children, 14 | ]) 15 | } 16 | 17 | export default jsx 18 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [['@babel/env', { loose: true }], '@babel/preset-react'], 3 | // plugins: ['@babel/transform-runtime'], 4 | env: { 5 | esm: { 6 | presets: [ 7 | ['@babel/env', { loose: true, modules: false }], 8 | '@babel/preset-react', 9 | ], 10 | // plugins: [['@babel/transform-runtime', { useESModules: true }]], 11 | }, 12 | }, 13 | } 14 | -------------------------------------------------------------------------------- /packages/color/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@styled-system/color", 3 | "version": "5.0.5", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "author": "Brent Jackson", 7 | "license": "MIT", 8 | "dependencies": { 9 | "@styled-system/core": "^5.0.5" 10 | }, 11 | "publishConfig": { 12 | "access": "public" 13 | }, 14 | "gitHead": "a6feb6009c58f2eb68f0c3120c5672f6cb54294f" 15 | } 16 | -------------------------------------------------------------------------------- /packages/grid/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@styled-system/grid", 3 | "version": "5.0.5", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "author": "Brent Jackson", 7 | "license": "MIT", 8 | "dependencies": { 9 | "@styled-system/core": "^5.0.5" 10 | }, 11 | "publishConfig": { 12 | "access": "public" 13 | }, 14 | "gitHead": "a6feb6009c58f2eb68f0c3120c5672f6cb54294f" 15 | } 16 | -------------------------------------------------------------------------------- /packages/border/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@styled-system/border", 3 | "version": "5.0.5", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "author": "Brent Jackson", 7 | "license": "MIT", 8 | "dependencies": { 9 | "@styled-system/core": "^5.0.5" 10 | }, 11 | "publishConfig": { 12 | "access": "public" 13 | }, 14 | "gitHead": "a6feb6009c58f2eb68f0c3120c5672f6cb54294f" 15 | } 16 | -------------------------------------------------------------------------------- /packages/flexbox/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@styled-system/flexbox", 3 | "version": "5.0.5", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "author": "Brent Jackson", 7 | "license": "MIT", 8 | "dependencies": { 9 | "@styled-system/core": "^5.0.5" 10 | }, 11 | "publishConfig": { 12 | "access": "public" 13 | }, 14 | "gitHead": "a6feb6009c58f2eb68f0c3120c5672f6cb54294f" 15 | } 16 | -------------------------------------------------------------------------------- /packages/layout/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@styled-system/layout", 3 | "version": "5.0.5", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "author": "Brent Jackson", 7 | "license": "MIT", 8 | "dependencies": { 9 | "@styled-system/core": "^5.0.5" 10 | }, 11 | "publishConfig": { 12 | "access": "public" 13 | }, 14 | "gitHead": "a6feb6009c58f2eb68f0c3120c5672f6cb54294f" 15 | } 16 | -------------------------------------------------------------------------------- /packages/shadow/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@styled-system/shadow", 3 | "version": "5.0.5", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "author": "Brent Jackson", 7 | "license": "MIT", 8 | "dependencies": { 9 | "@styled-system/core": "^5.0.5" 10 | }, 11 | "publishConfig": { 12 | "access": "public" 13 | }, 14 | "gitHead": "a6feb6009c58f2eb68f0c3120c5672f6cb54294f" 15 | } 16 | -------------------------------------------------------------------------------- /packages/background/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@styled-system/background", 3 | "version": "5.0.5", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "author": "Brent Jackson", 7 | "license": "MIT", 8 | "dependencies": { 9 | "@styled-system/core": "^5.0.5" 10 | }, 11 | "publishConfig": { 12 | "access": "public" 13 | }, 14 | "gitHead": "a6feb6009c58f2eb68f0c3120c5672f6cb54294f" 15 | } 16 | -------------------------------------------------------------------------------- /packages/position/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@styled-system/position", 3 | "version": "5.0.5", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "author": "Brent Jackson", 7 | "license": "MIT", 8 | "dependencies": { 9 | "@styled-system/core": "^5.0.5" 10 | }, 11 | "publishConfig": { 12 | "access": "public" 13 | }, 14 | "gitHead": "a6feb6009c58f2eb68f0c3120c5672f6cb54294f" 15 | } 16 | -------------------------------------------------------------------------------- /packages/typography/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@styled-system/typography", 3 | "version": "5.0.5", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "author": "Brent Jackson", 7 | "license": "MIT", 8 | "dependencies": { 9 | "@styled-system/core": "^5.0.5" 10 | }, 11 | "publishConfig": { 12 | "access": "public" 13 | }, 14 | "gitHead": "a6feb6009c58f2eb68f0c3120c5672f6cb54294f" 15 | } 16 | -------------------------------------------------------------------------------- /packages/core/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@styled-system/core", 3 | "version": "5.0.5", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "author": "Brent Jackson ", 7 | "license": "MIT", 8 | "gitHead": "a6feb6009c58f2eb68f0c3120c5672f6cb54294f", 9 | "dependencies": { 10 | "object-assign": "^4.1.1" 11 | }, 12 | "publishConfig": { 13 | "access": "public" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/should-forward-prop/test/index.js: -------------------------------------------------------------------------------- 1 | import shouldForwardProp, { props } from '../src' 2 | 3 | test('returns true for valid HTML attributes', () => { 4 | const should = shouldForwardProp('href') 5 | expect(should).toBe(true) 6 | }) 7 | 8 | props.forEach(prop => { 9 | test(`returns false for Styled System ${prop} prop`, () => { 10 | const should = shouldForwardProp(prop) 11 | expect(should).toBe(false) 12 | }) 13 | }) 14 | -------------------------------------------------------------------------------- /packages/space/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@styled-system/space", 3 | "version": "5.0.5", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "author": "Brent Jackson ", 7 | "license": "MIT", 8 | "gitHead": "a6feb6009c58f2eb68f0c3120c5672f6cb54294f", 9 | "dependencies": { 10 | "@styled-system/core": "^5.0.5" 11 | }, 12 | "publishConfig": { 13 | "access": "public" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/variant/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@styled-system/variant", 3 | "version": "5.0.5", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "author": "Brent Jackson ", 7 | "license": "MIT", 8 | "dependencies": { 9 | "@styled-system/core": "^5.0.5" 10 | }, 11 | "gitHead": "a6feb6009c58f2eb68f0c3120c5672f6cb54294f", 12 | "publishConfig": { 13 | "access": "public" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/theme-get/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@styled-system/theme-get", 3 | "version": "5.0.5", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "author": "Brent Jackson ", 7 | "license": "MIT", 8 | "dependencies": { 9 | "@styled-system/core": "^5.0.5" 10 | }, 11 | "gitHead": "a6feb6009c58f2eb68f0c3120c5672f6cb54294f", 12 | "publishConfig": { 13 | "access": "public" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/jsx/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@styled-system/jsx", 3 | "version": "5.0.5", 4 | "description": "", 5 | "type": "module", 6 | "main": "dist/index.js", 7 | "module": "dist/index.esm.js", 8 | "author": "Brent Jackson ", 9 | "license": "MIT", 10 | "dependencies": { 11 | "@emotion/core": "^10.0.10", 12 | "@styled-system/css": "^2.0.0" 13 | }, 14 | "gitHead": "a6feb6009c58f2eb68f0c3120c5672f6cb54294f" 15 | } 16 | -------------------------------------------------------------------------------- /packages/prop-types/test/index.js: -------------------------------------------------------------------------------- 1 | import propTypes from '../src' 2 | import { 3 | space, 4 | color, 5 | } from 'styled-system' 6 | 7 | test('includes prop types for all space prop names', () => { 8 | const types = Object.keys(propTypes.space) 9 | expect(types).toEqual(space.propNames) 10 | }) 11 | 12 | test('includes prop types for all color prop names', () => { 13 | const types = Object.keys(propTypes.color) 14 | expect(types).toEqual(color.propNames) 15 | }) 16 | -------------------------------------------------------------------------------- /docs/src/link.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { Link as GatsbyLink } from 'gatsby' 3 | import isAbsoluteURL from 'is-absolute-url' 4 | 5 | const isHash = str => /^#/.test(str) 6 | 7 | export const Link = ({ href, ...props }) => 8 | isHash(href) || isAbsoluteURL(href) ? ( 9 | // eslint-disable-next-line 10 | 11 | ) : ( 12 | 13 | ) 14 | 15 | export default Link 16 | -------------------------------------------------------------------------------- /docs/src/components.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Link from './link' 3 | import wrapper from './toc-wrapper' 4 | 5 | const heading = Tag => ({ id, ...props }) => ( 6 | 7 | {props.children} 8 | 9 | ) 10 | 11 | export default { 12 | wrapper, 13 | h1: heading('h1'), 14 | h2: heading('h2'), 15 | h3: heading('h3'), 16 | h4: heading('h4'), 17 | h5: heading('h5'), 18 | h6: heading('h6'), 19 | a: Link, 20 | } 21 | -------------------------------------------------------------------------------- /packages/shadow/test/index.js: -------------------------------------------------------------------------------- 1 | import shadow from '../src' 2 | 3 | test('returns shadow styles', () => { 4 | const style = shadow({ 5 | theme: { 6 | shadows: { 7 | small: '0 1px 4px rgba(0, 0, 0, .125)', 8 | }, 9 | }, 10 | textShadow: '0 -1px rgba(255, 255, 255, .25)', 11 | boxShadow: 'small', 12 | }) 13 | expect(style).toEqual({ 14 | textShadow: '0 -1px rgba(255, 255, 255, .25)', 15 | boxShadow: '0 1px 4px rgba(0, 0, 0, .125)', 16 | }) 17 | }) 18 | -------------------------------------------------------------------------------- /docs/src/button.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { css } from 'theme-ui' 3 | import Link from './link' 4 | 5 | export default props => ( 6 | 22 | ) 23 | -------------------------------------------------------------------------------- /packages/prop-types/README.md: -------------------------------------------------------------------------------- 1 | 2 | # @styled-system/prop-types 3 | 4 | Add prop types to components built with Styled System 5 | 6 | ```sh 7 | npm i styled-system @styled-system/prop-types 8 | ``` 9 | 10 | ```js 11 | import styled from 'styled-components' 12 | import { space, color } from 'styled-system' 13 | import propTypes from '@styled-system/prop-types' 14 | 15 | const Box = styled('div')(space, color) 16 | 17 | Box.propTypes = { 18 | ...propTypes.space, 19 | ...propTypes.color, 20 | } 21 | ``` 22 | -------------------------------------------------------------------------------- /docs/src/logo/white.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Logo from './index' 3 | 4 | export default () => ( 5 | 16 | 17 | 18 | 19 | 20 | 21 | ) 22 | -------------------------------------------------------------------------------- /packages/flexbox/src/index.js: -------------------------------------------------------------------------------- 1 | import { system } from '@styled-system/core' 2 | 3 | const config = { 4 | alignItems: true, 5 | alignContent: true, 6 | justifyItems: true, 7 | justifyContent: true, 8 | flexWrap: true, 9 | flexDirection: true, 10 | // item 11 | flex: true, 12 | flexGrow: true, 13 | flexShrink: true, 14 | flexBasis: true, 15 | justifySelf: true, 16 | alignSelf: true, 17 | order: true, 18 | } 19 | 20 | export const flexbox = system(config) 21 | 22 | export default flexbox 23 | -------------------------------------------------------------------------------- /packages/core/test/merge.js: -------------------------------------------------------------------------------- 1 | import { merge } from '../src' 2 | 3 | test('deeply merges', () => { 4 | const result = merge( 5 | { 6 | hello: 'hi', 7 | media: { 8 | howdy: 'ho', 9 | }, 10 | }, 11 | { 12 | beep: 'boop', 13 | media: { 14 | bleep: 'bloop', 15 | }, 16 | } 17 | ) 18 | expect(result).toEqual({ 19 | hello: 'hi', 20 | beep: 'boop', 21 | media: { 22 | howdy: 'ho', 23 | bleep: 'bloop', 24 | }, 25 | }) 26 | }) 27 | -------------------------------------------------------------------------------- /packages/background/src/index.js: -------------------------------------------------------------------------------- 1 | import { system } from '@styled-system/core' 2 | 3 | const config = { 4 | background: true, 5 | backgroundImage: true, 6 | backgroundSize: true, 7 | backgroundPosition: true, 8 | backgroundRepeat: true, 9 | } 10 | 11 | config.bgImage = config.backgroundImage 12 | config.bgSize = config.backgroundSize 13 | config.bgPosition = config.backgroundPosition 14 | config.bgRepeat = config.backgroundRepeat 15 | 16 | export const background = system(config) 17 | 18 | export default background 19 | -------------------------------------------------------------------------------- /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | jobs: 3 | build: 4 | docker: 5 | - image: circleci/node:lts 6 | working_directory: ~/repo 7 | steps: 8 | - checkout 9 | - restore_cache: 10 | keys: 11 | - v2-dependencies-{{ checksum "package.json" }} 12 | - v2-dependencies- 13 | - run: yarn install 14 | - save_cache: 15 | paths: 16 | - node_modules 17 | key: v2-dependencies-{{ checksum "package.json" }} 18 | - run: yarn test --coverage 19 | -------------------------------------------------------------------------------- /docs/guides/index.md: -------------------------------------------------------------------------------- 1 | # Guides 2 | 3 | - [Build a Box](/guides/build-a-box) 4 | - [Spacing](/guides/spacing) 5 | - [Default Values](/guides/default-values) 6 | - [Why Powers of Two](/guides/why-powers-of-two) 7 | - [Removing Props from HTML](/guides/removing-props-from-html) 8 | - [Theming](/guides/theming) 9 | - [Array Scales](/guides/array-scales) 10 | - [Array Props](/guides/array-props) 11 | - [Color Modes](/guides/color-modes) 12 | - [Migrating to v5](/guides/migrating) 13 | - [Scale Aliases](/guides/scale-aliases) 14 | - [Exceptions](/guides/exceptions) 15 | -------------------------------------------------------------------------------- /docs/src/burger.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | export default ({ size = 24 }) => ( 4 | 18 | 25 | 26 | ) 27 | -------------------------------------------------------------------------------- /packages/prop-types/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@styled-system/prop-types", 3 | "version": "5.0.5", 4 | "main": "dist/index.js", 5 | "module": "dist/index.esm.js", 6 | "author": "Brent Jackson", 7 | "license": "MIT", 8 | "peerDependencies": { 9 | "styled-system": "^5.0.0-8" 10 | }, 11 | "devDependencies": { 12 | "styled-system": "^5.0.5" 13 | }, 14 | "dependencies": { 15 | "prop-types": "^15.7.2" 16 | }, 17 | "publishConfig": { 18 | "access": "public" 19 | }, 20 | "gitHead": "a6feb6009c58f2eb68f0c3120c5672f6cb54294f" 21 | } 22 | -------------------------------------------------------------------------------- /docs/articles.md: -------------------------------------------------------------------------------- 1 | # Articles 2 | 3 | - [Component Based Design System With Styled-System](https://varun.ca/styled-system/) 4 | - [Build Better Component Libraries with Styled System](https://medium.com/styled-components/build-better-component-libraries-with-styled-system-4951653d54ee) 5 | - [Building a beautiful, reusable button with Styled System](https://johno.com/styled-system-button) 6 | - [Defining Component APIs in React](http://jxnblk.com/blog/defining-component-apis-in-react/) 7 | - [The Three Tenets of Styled System](https://jxnblk.com/blog/the-three-tenets-of-styled-system/) 8 | -------------------------------------------------------------------------------- /docs/src/doc.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { graphql } from 'gatsby' 3 | import MDXRenderer from 'gatsby-plugin-mdx/mdx-renderer' 4 | import Layout from './layout' 5 | 6 | export const pageQuery = graphql` 7 | query($id: String!) { 8 | mdx(id: { eq: $id }) { 9 | id 10 | fields { 11 | slug 12 | } 13 | body 14 | } 15 | } 16 | ` 17 | 18 | export default props => { 19 | const { body } = props.data.mdx 20 | const children = 21 | 22 | return 23 | } 24 | -------------------------------------------------------------------------------- /docs/static/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 20 | -------------------------------------------------------------------------------- /docs/showcase.md: -------------------------------------------------------------------------------- 1 | # Showcase 2 | 3 | **This page is a stub. If you'd like to add your project to this page, please [Open a PR][].** 4 | 5 | [open a pr]: https://github.com/styled-system/styled-system/blob/master/docs/showcase.md 6 | 7 | - [Primer Components](https://primer.style/components) 8 | - [Priceline Design System](https://pricelinelabs.github.io/design-system/) 9 | - [Cloudflare Design Color](https://cloudflare.design/color/) 10 | - [Styled System HTML](https://johnpolacek.github.io/styled-system-html/) 11 | - [Rebass](https://rebassjs.org) 12 | - [Rebass Grid](https://grid.rebassjs.org) 13 | -------------------------------------------------------------------------------- /packages/css/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@styled-system/css", 3 | "version": "5.0.5", 4 | "description": "Styled System for the `css` prop", 5 | "main": "dist/index.js", 6 | "module": "dist/index.esm.js", 7 | "sideEffects": false, 8 | "keywords": [ 9 | "css", 10 | "css-in-js", 11 | "emotion", 12 | "styled-components", 13 | "style", 14 | "react" 15 | ], 16 | "author": "Brent Jackson ", 17 | "license": "MIT", 18 | "gitHead": "a6feb6009c58f2eb68f0c3120c5672f6cb54294f", 19 | "publishConfig": { 20 | "access": "public" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /docs/theming.md: -------------------------------------------------------------------------------- 1 | # Theming 2 | 3 | One of the core features of Styled System is the ability to quickly reference values defined in a theme in your components' props. 4 | Instead of hard-coding values or importing a theme into other components, 5 | Styled System props hook directly into React context-based themes. 6 | 7 | Given the following colors in a theme: 8 | 9 | ```js 10 | const colors = { 11 | blue: '#07c', 12 | } 13 | 14 | export default { 15 | colors, 16 | } 17 | ``` 18 | 19 | A component with `color` props can pick up the `blue` value: 20 | 21 | ```jsx 22 | 23 | ``` 24 | -------------------------------------------------------------------------------- /examples/svelte/App.svelte: -------------------------------------------------------------------------------- 1 | 15 | 16 | 21 | 22 |
23 |

Hello Svelte

24 |

This example uses Styled System to pull styles from a global theme

25 |
26 | -------------------------------------------------------------------------------- /packages/edit/test/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import renderer from 'react-test-renderer' 3 | import { 4 | EditProvider, 5 | Field, 6 | FieldSet, 7 | ThemeControls, 8 | ResetButton, 9 | } from '../src' 10 | 11 | const theme = { 12 | colors: { 13 | text: 'black', 14 | background: 'white', 15 | }, 16 | fontSizes: [ 12, 14, 16, 20, 24, 32 ], 17 | } 18 | 19 | test('renders', () => { 20 | const json = renderer.create( 21 | 22 | 23 | 24 | ).toJSON() 25 | expect(json).toMatchSnapshot() 26 | }) 27 | -------------------------------------------------------------------------------- /packages/should-forward-prop/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@styled-system/should-forward-prop", 3 | "version": "5.0.5", 4 | "description": "Utility for filtering Styled System props with Emotion's shouldForwardProp option", 5 | "main": "dist/index.js", 6 | "module": "dist/index.esm.js", 7 | "keywords": [], 8 | "author": "Brent Jackson ", 9 | "license": "MIT", 10 | "dependencies": { 11 | "@emotion/is-prop-valid": "^0.7.3", 12 | "@emotion/memoize": "^0.7.1", 13 | "styled-system": "^5.0.5" 14 | }, 15 | "gitHead": "a6feb6009c58f2eb68f0c3120c5672f6cb54294f" 16 | } 17 | -------------------------------------------------------------------------------- /docs/src/nav-link.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { css } from 'theme-ui' 3 | import Link from './link' 4 | 5 | export default props => ( 6 | 9 | css({ 10 | display: 'block', 11 | fontSize: 1, 12 | fontWeight: 'bold', 13 | textDecoration: 'none', 14 | color: 'inherit', 15 | px: 3, 16 | py: 2, 17 | '&:hover': { 18 | color: 'primary', 19 | }, 20 | '&.active': { 21 | color: 'primary', 22 | }, 23 | })({ ...props, theme }) 24 | } 25 | /> 26 | ) 27 | -------------------------------------------------------------------------------- /packages/edit/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@styled-system/edit", 3 | "version": "5.0.5", 4 | "description": "", 5 | "main": "dist/index.js", 6 | "module": "dist/index.esm.js", 7 | "keywords": [], 8 | "author": "Brent Jackson ", 9 | "license": "MIT", 10 | "dependencies": { 11 | "@emotion/core": "^10.0.10", 12 | "color": "^3.1.0", 13 | "lodash.get": "^4.4.2", 14 | "lodash.merge": "^4.6.1", 15 | "lodash.omit": "^4.5.0", 16 | "lodash.set": "^4.3.2" 17 | }, 18 | "publishConfig": { 19 | "access": "public" 20 | }, 21 | "gitHead": "a6feb6009c58f2eb68f0c3120c5672f6cb54294f" 22 | } 23 | -------------------------------------------------------------------------------- /packages/theme-get/test/index.js: -------------------------------------------------------------------------------- 1 | import { themeGet } from '../src' 2 | 3 | const theme = { 4 | colors: { 5 | blue: '#07c', 6 | black: '#111', 7 | }, 8 | } 9 | 10 | test('themeGet returns values from the theme', () => { 11 | const a = themeGet('colors.blue')({ theme }) 12 | expect(a).toBe('#07c') 13 | }) 14 | 15 | test('themeGet does not throw when value doesnt exist', () => { 16 | const a = themeGet('colors.blue.5')({ theme }) 17 | expect(a).toBe(null) 18 | }) 19 | 20 | test('themeGet accepts a fallback', () => { 21 | const a = themeGet('colors.lightblue', '#0cf')({ theme }) 22 | expect(a).toBe('#0cf') 23 | }) 24 | -------------------------------------------------------------------------------- /examples/css/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@styled-system/css-basic-example", 3 | "version": "5.0.0-7", 4 | "private": true, 5 | "dependencies": { 6 | "@emotion/core": "^10.0.9", 7 | "@styled-system/css": "5.0.0-7", 8 | "react": "^16.8.5", 9 | "react-dom": "^16.8.5", 10 | "react-scripts": "^3.0.1" 11 | }, 12 | "scripts": { 13 | "start": "react-scripts start", 14 | "build": "react-scripts build", 15 | "test": "react-scripts test --env=jsdom", 16 | "eject": "react-scripts eject" 17 | }, 18 | "browserslist": [ 19 | ">0.2%", 20 | "not dead", 21 | "not ie <= 11", 22 | "not op_mini all" 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /examples/jsx/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@styled-system/jsx-basic-example", 3 | "version": "5.0.0-7", 4 | "private": true, 5 | "dependencies": { 6 | "@emotion/core": "^10.0.9", 7 | "@styled-system/jsx": "0.0.3", 8 | "react": "^16.8.5", 9 | "react-dom": "^16.8.5", 10 | "react-scripts": "^3.0.1" 11 | }, 12 | "scripts": { 13 | "start": "react-scripts start", 14 | "build": "react-scripts build", 15 | "test": "react-scripts test --env=jsdom", 16 | "eject": "react-scripts eject" 17 | }, 18 | "browserslist": [ 19 | ">0.2%", 20 | "not dead", 21 | "not ie <= 11", 22 | "not op_mini all" 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /packages/core/test/compose.js: -------------------------------------------------------------------------------- 1 | import { system, compose } from '../src' 2 | 3 | const color = system({ 4 | color: true, 5 | bg: { 6 | property: 'backgroundColor', 7 | }, 8 | }) 9 | 10 | const fontSize = system({ 11 | fontSize: true, 12 | }) 13 | 14 | test('compose combines style parsers', () => { 15 | const parser = compose( 16 | color, 17 | fontSize 18 | ) 19 | const styles = parser({ 20 | color: 'tomato', 21 | bg: 'black', 22 | fontSize: 32, 23 | }) 24 | expect(typeof parser).toBe('function') 25 | expect(styles).toEqual({ 26 | fontSize: 32, 27 | color: 'tomato', 28 | backgroundColor: 'black', 29 | }) 30 | }) 31 | -------------------------------------------------------------------------------- /packages/variant/src/index.js: -------------------------------------------------------------------------------- 1 | import { get, createParser } from '@styled-system/core' 2 | 3 | export const variant = ({ 4 | scale, 5 | prop = 'variant', 6 | // shim for v4 API 7 | key, 8 | }) => { 9 | const sx = (value, scale) => { 10 | return get(scale, value, null) 11 | } 12 | sx.scale = scale || key 13 | const config = { 14 | [prop]: sx, 15 | } 16 | const parser = createParser(config) 17 | return parser 18 | } 19 | 20 | export default variant 21 | 22 | export const buttonStyle = variant({ key: 'buttons' }) 23 | export const textStyle = variant({ key: 'textStyles', prop: 'textStyle' }) 24 | export const colorStyle = variant({ key: 'colorStyles', prop: 'colors' }) 25 | -------------------------------------------------------------------------------- /examples/babel-plugin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "name": "@styled-system/babel-plugin-example", 4 | "version": "5.0.0-7", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "gatsby develop" 8 | }, 9 | "author": "Brent Jackson ", 10 | "license": "MIT", 11 | "dependencies": { 12 | "@babel/core": "^7.4.4", 13 | "@babel/preset-env": "^7.4.4", 14 | "@babel/preset-react": "^7.0.0", 15 | "@emotion/babel-preset-css-prop": "^10.0.9", 16 | "@emotion/core": "^10.0.10", 17 | "@styled-system/babel-plugin": "0.0.20", 18 | "babel-preset-gatsby": "^0.1.11", 19 | "gatsby": "^2.3.32", 20 | "react": "^16.8.6", 21 | "react-dom": "^16.8.6" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/emotion/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@styled-system/emotion-demo", 3 | "version": "5.0.0-7", 4 | "private": true, 5 | "dependencies": { 6 | "@emotion/core": "^10.0.9", 7 | "@emotion/styled": "^10.0.9", 8 | "emotion-theming": "^10.0.9", 9 | "react": "^16.8.5", 10 | "react-dom": "^16.8.5", 11 | "react-scripts": "^3.0.1", 12 | "styled-system": "5.0.0-8" 13 | }, 14 | "scripts": { 15 | "start": "react-scripts start", 16 | "build": "react-scripts build", 17 | "test": "react-scripts test --env=jsdom", 18 | "eject": "react-scripts eject" 19 | }, 20 | "browserslist": [ 21 | ">0.2%", 22 | "not dead", 23 | "not ie <= 11", 24 | "not op_mini all" 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /examples/responsive-objects/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@styled-system/responsive-objects-example", 3 | "version": "5.0.0-7", 4 | "private": true, 5 | "dependencies": { 6 | "@emotion/core": "^10.0.10", 7 | "@emotion/styled": "^10.0.10", 8 | "emotion-theming": "^10.0.10", 9 | "react": "^16.8.5", 10 | "react-dom": "^16.8.5", 11 | "react-scripts": "^3.0.0", 12 | "styled-system": "5.0.0-8" 13 | }, 14 | "scripts": { 15 | "start": "react-scripts start" 16 | }, 17 | "browserslist": { 18 | "production": [ 19 | ">0.2%", 20 | "not dead", 21 | "not op_mini all" 22 | ], 23 | "development": [ 24 | "last 1 chrome version", 25 | "last 1 firefox version", 26 | "last 1 safari version" 27 | ] 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /docs/src/edit-link.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { Location } from '@reach/router' 3 | import { css } from 'theme-ui' 4 | 5 | const base = 'https://github.com/styled-system/styled-system/edit/master/docs' 6 | 7 | const getHREF = location => { 8 | if (location.pathname === '/') return base + '/getting-started.md' 9 | return base + location.pathname.replace(/\/+$/, '') + '.md' 10 | } 11 | 12 | export default () => ( 13 | 14 | {({ location }) => ( 15 | 24 | Edit this page on GitHub 25 | 26 | )} 27 | 28 | ) 29 | -------------------------------------------------------------------------------- /packages/layout/test/index.js: -------------------------------------------------------------------------------- 1 | import layout from '../src' 2 | 3 | test('returns layout styles', () => { 4 | const style = layout({ 5 | width: [ 1, 1/2, 1/4 ], 6 | minHeight: 32, 7 | maxWidth: 768, 8 | }) 9 | expect(style).toEqual({ 10 | width: '100%', 11 | maxWidth: 768, 12 | minHeight: 32, 13 | '@media screen and (min-width: 40em)': { 14 | width: '50%', 15 | }, 16 | '@media screen and (min-width: 52em)': { 17 | width: '25%', 18 | }, 19 | }) 20 | }) 21 | 22 | test('returns 0 from theme.sizes', () => { 23 | const style = layout({ 24 | theme: { 25 | sizes: [ 24, 48, 96 ], 26 | }, 27 | width: 0, 28 | height: 0, 29 | }) 30 | expect(style).toEqual({ 31 | width: 24, 32 | height: 24, 33 | }) 34 | }) 35 | -------------------------------------------------------------------------------- /packages/should-forward-prop/src/index.js: -------------------------------------------------------------------------------- 1 | import memoize from '@emotion/memoize' 2 | import isPropValid from '@emotion/is-prop-valid' 3 | import { 4 | compose, 5 | space, 6 | typography, 7 | color, 8 | layout, 9 | flexbox, 10 | border, 11 | background, 12 | position, 13 | grid 14 | } from 'styled-system' 15 | 16 | const all = compose( 17 | space, 18 | typography, 19 | color, 20 | layout, 21 | flexbox, 22 | border, 23 | background, 24 | position, 25 | grid 26 | ) 27 | 28 | export const props = all.propNames 29 | 30 | export const createShouldForwardProp = props => { 31 | const regex = new RegExp(`^(${props.join('|')})$`) 32 | return memoize(prop => isPropValid(prop) && !regex.test(prop)) 33 | } 34 | 35 | export default createShouldForwardProp(props) 36 | -------------------------------------------------------------------------------- /docs/static/logo-white.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 20 | -------------------------------------------------------------------------------- /packages/typography/src/index.js: -------------------------------------------------------------------------------- 1 | import { system } from '@styled-system/core' 2 | 3 | const defaults = { 4 | fontSizes: [12, 14, 16, 20, 24, 32, 48, 64, 72], 5 | } 6 | 7 | const config = { 8 | fontFamily: { 9 | property: 'fontFamily', 10 | scale: 'fonts', 11 | }, 12 | fontSize: { 13 | property: 'fontSize', 14 | scale: 'fontSizes', 15 | defaultScale: defaults.fontSizes, 16 | }, 17 | fontWeight: { 18 | property: 'fontWeight', 19 | scale: 'fontWeights', 20 | }, 21 | lineHeight: { 22 | property: 'lineHeight', 23 | scale: 'lineHeights', 24 | }, 25 | letterSpacing: { 26 | property: 'letterSpacing', 27 | scale: 'letterSpacings', 28 | }, 29 | textAlign: true, 30 | fontStyle: true, 31 | } 32 | 33 | export const typography = system(config) 34 | export default typography 35 | -------------------------------------------------------------------------------- /docs/src/pages/404.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { Link } from 'gatsby' 3 | import { Box } from 'theme-ui' 4 | import Logo from '../logo' 5 | 6 | export default props => ( 7 | 16 | 17 | 25 | 26 | 27 | 28 | 404 29 | 30 | 31 | Page not found 32 | 33 | 34 | 35 | ) 36 | -------------------------------------------------------------------------------- /examples/svelte/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@styled-system/svelte-example", 3 | "private": true, 4 | "version": "5.0.0-7", 5 | "devDependencies": { 6 | "npm-run-all": "^4.1.5", 7 | "rollup": "^1.10.1", 8 | "rollup-plugin-commonjs": "^9.3.4", 9 | "rollup-plugin-node-resolve": "^4.2.3", 10 | "rollup-plugin-svelte": "^5.0.3", 11 | "rollup-plugin-terser": "^4.0.4", 12 | "sirv-cli": "^0.3.1" 13 | }, 14 | "dependencies": { 15 | "@styled-system/css": "5.0.0-7", 16 | "emotion": "^10.0.9", 17 | "styled-system": "5.0.0-8", 18 | "svelte": "^3.0.0" 19 | }, 20 | "scripts": { 21 | "build": "rollup -c", 22 | "autobuild": "rollup -c -w", 23 | "dev": "run-p start:dev autobuild", 24 | "start": "sirv public", 25 | "start:dev": "sirv public --dev" 26 | }, 27 | "keywords": [], 28 | "description": "" 29 | } 30 | -------------------------------------------------------------------------------- /packages/grid/src/index.js: -------------------------------------------------------------------------------- 1 | import { system } from '@styled-system/core' 2 | 3 | const defaults = { 4 | space: [0, 4, 8, 16, 32, 64, 128, 256, 512], 5 | } 6 | 7 | const config = { 8 | gridGap: { 9 | property: 'gridGap', 10 | scale: 'space', 11 | defaultScale: defaults.space, 12 | }, 13 | gridColumnGap: { 14 | property: 'gridColumnGap', 15 | scale: 'space', 16 | defaultScale: defaults.space, 17 | }, 18 | gridRowGap: { 19 | property: 'gridRowGap', 20 | scale: 'space', 21 | defaultScale: defaults.space, 22 | }, 23 | gridColumn: true, 24 | gridRow: true, 25 | gridAutoFlow: true, 26 | gridAutoColumns: true, 27 | gridAutoRows: true, 28 | gridTemplateColumns: true, 29 | gridTemplateRows: true, 30 | gridTemplateAreas: true, 31 | gridArea: true, 32 | } 33 | 34 | export const grid = system(config) 35 | export default grid 36 | -------------------------------------------------------------------------------- /packages/core/test/get.js: -------------------------------------------------------------------------------- 1 | import { get } from '../src' 2 | 3 | test('returns a deeply nested value', () => { 4 | const a = get( 5 | { 6 | colors: { 7 | blue: ['#0cf', '#0be', '#09d', '#07c'], 8 | }, 9 | }, 10 | 'colors.blue.3' 11 | ) 12 | expect(a).toBe('#07c') 13 | }) 14 | 15 | test('supports fallback values', () => { 16 | const a = get({}, 'hi', 'nope') 17 | expect(a).toBe('nope') 18 | }) 19 | 20 | test('handles number values', () => { 21 | const a = get([1, 2, 3], 0) 22 | expect(a).toBe(1) 23 | }) 24 | 25 | test('handles undefined values', () => { 26 | const a = get({}, undefined) 27 | expect(a).toBe(undefined) 28 | }) 29 | 30 | test('handles null values', () => { 31 | const a = get({}, null) 32 | expect(a).toBe(undefined) 33 | }) 34 | 35 | test('returns 0 index items', () => { 36 | const a = get([ 'a', 'b', 'c' ], 0) 37 | expect(a).toBe('a') 38 | }) 39 | -------------------------------------------------------------------------------- /docs/src/sidebar.mdx: -------------------------------------------------------------------------------- 1 | - [Getting Started](/#getting-started) 2 | - [Responsive Styles](/responsive-styles) 3 | - [How it Works](/how-it-works) 4 | - [Custom Props](/custom-props) 5 | - [Variants](/variants) 6 | - [API](/api) 7 | - [Reference Table](/table) 8 | - [Packages](/packages) 9 | - [Theme Specification](/theme-specification) 10 | - [Articles](/articles) 11 | - [Guides](/guides) 12 | - [Build a Box](/guides/build-a-box) 13 | - [Spacing](/guides/spacing) 14 | - [Default Values](/guides/default-values) 15 | - [Why Powers of Two](/guides/why-powers-of-two) 16 | - [Removing Props from HTML](/guides/removing-props-from-html) 17 | - [Theming](/guides/theming) 18 | - [Array Scales](/guides/array-scales) 19 | - [Array Props](/guides/array-props) 20 | - [Color Modes](/guides/color-modes) 21 | - [Migrating to v5](/guides/migrating) 22 | - [Demo](/demo) 23 | - [CSS](/css) 24 | - [Babel Plugin](/babel-plugin) 25 | - [GitHub](https://github.com/styled-system/styled-system) 26 | -------------------------------------------------------------------------------- /packages/layout/src/index.js: -------------------------------------------------------------------------------- 1 | import { system, get } from '@styled-system/core' 2 | 3 | const isNumber = n => typeof n === 'number' && !isNaN(n) 4 | const getWidth = (n, scale) => 5 | get(scale, n, !isNumber(n) || n > 1 ? n : n * 100 + '%') 6 | 7 | const config = { 8 | width: { 9 | property: 'width', 10 | scale: 'sizes', 11 | transform: getWidth, 12 | }, 13 | height: { 14 | property: 'height', 15 | scale: 'sizes', 16 | }, 17 | minWidth: { 18 | property: 'minWidth', 19 | scale: 'sizes', 20 | }, 21 | minHeight: { 22 | property: 'minHeight', 23 | scale: 'sizes', 24 | }, 25 | maxWidth: { 26 | property: 'maxWidth', 27 | scale: 'sizes', 28 | }, 29 | maxHeight: { 30 | property: 'maxHeight', 31 | scale: 'sizes', 32 | }, 33 | size: { 34 | properties: ['width', 'height'], 35 | scale: 'sizes', 36 | }, 37 | overflow: true, 38 | display: true, 39 | verticalAlign: true, 40 | } 41 | 42 | export const layout = system(config) 43 | export default layout 44 | -------------------------------------------------------------------------------- /packages/prop-types/src/index.js: -------------------------------------------------------------------------------- 1 | import PropTypes from 'prop-types' 2 | import { 3 | space, 4 | color, 5 | layout, 6 | typography, 7 | flexbox, 8 | border, 9 | background, 10 | position, 11 | grid, 12 | } from 'styled-system' 13 | 14 | export const propType = PropTypes.oneOfType([ 15 | PropTypes.number, 16 | PropTypes.string, 17 | PropTypes.array, 18 | PropTypes.object, 19 | ]) 20 | 21 | const createPropTypes = props => { 22 | return props.reduce((acc, name) => ({ 23 | ...acc, 24 | [name]: propType, 25 | }), {}) 26 | } 27 | 28 | export default { 29 | space: createPropTypes(space.propNames), 30 | color: createPropTypes(color.propNames), 31 | layout: createPropTypes(layout.propNames), 32 | typography: createPropTypes(typography.propNames), 33 | flexbox: createPropTypes(flexbox.propNames), 34 | border: createPropTypes(border.propNames), 35 | background: createPropTypes(background.propNames), 36 | position: createPropTypes(position.propNames), 37 | grid: createPropTypes(grid.propNames), 38 | } 39 | -------------------------------------------------------------------------------- /benchmarks/README.md: -------------------------------------------------------------------------------- 1 | 2 | ``` 3 | space: v4 x 88,322 ops/sec ±0.83% (85 runs sampled) 4 | space: v5 x 318,570 ops/sec ±0.99% (86 runs sampled) 5 | space: css x 106,737 ops/sec ±1.06% (86 runs sampled) 6 | space: xstyled x 77,831 ops/sec ±1.25% (86 runs sampled) 7 | fontSize: v4 x 1,653,012 ops/sec ±0.43% (85 runs sampled) 8 | fontSize: v5 x 2,628,307 ops/sec ±0.67% (81 runs sampled) 9 | fontSize: css x 442,833 ops/sec ±0.47% (83 runs sampled) 10 | fontSize: xstyled x 2,605,312 ops/sec ±1.20% (85 runs sampled) 11 | fontSize responsive: v4 x 361,625 ops/sec ±0.63% (78 runs sampled) 12 | fontSize responsive: v5 x 689,290 ops/sec ±0.56% (86 runs sampled) 13 | fontSize responsive: css x 117,290 ops/sec ±0.98% (87 runs sampled) 14 | fontSize responsive: xstyled x 176,587 ops/sec ±0.48% (87 runs sampled) 15 | compose: v4 x 67,713 ops/sec ±1.03% (80 runs sampled) 16 | compose: v5 x 238,211 ops/sec ±0.55% (88 runs sampled) 17 | compose: css x 58,918 ops/sec ±1.29% (84 runs sampled) 18 | compose: xstyled x 56,070 ops/sec ±0.57% (84 runs sampled) 19 | ``` 20 | -------------------------------------------------------------------------------- /packages/styled-system/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "styled-system", 3 | "version": "5.0.5", 4 | "description": "Responsive, theme-based style props for building design systems with React", 5 | "main": "dist/index.js", 6 | "module": "dist/index.esm.js", 7 | "keywords": [ 8 | "react", 9 | "css-in-js", 10 | "styled-components", 11 | "emotion" 12 | ], 13 | "author": "Brent Jackson", 14 | "license": "MIT", 15 | "dependencies": { 16 | "@styled-system/background": "^5.0.5", 17 | "@styled-system/border": "^5.0.5", 18 | "@styled-system/color": "^5.0.5", 19 | "@styled-system/core": "^5.0.5", 20 | "@styled-system/flexbox": "^5.0.5", 21 | "@styled-system/grid": "^5.0.5", 22 | "@styled-system/layout": "^5.0.5", 23 | "@styled-system/position": "^5.0.5", 24 | "@styled-system/shadow": "^5.0.5", 25 | "@styled-system/space": "^5.0.5", 26 | "@styled-system/typography": "^5.0.5", 27 | "@styled-system/variant": "^5.0.5", 28 | "object-assign": "^4.1.1" 29 | }, 30 | "gitHead": "a6feb6009c58f2eb68f0c3120c5672f6cb54294f" 31 | } 32 | -------------------------------------------------------------------------------- /docs/gatsby-node.js: -------------------------------------------------------------------------------- 1 | const path = require('path') 2 | const { createFilePath } = require('gatsby-source-filesystem') 3 | 4 | exports.onCreateNode = ({ node, actions, getNode }) => { 5 | if (node.internal.type !== 'Mdx') return 6 | 7 | const value = createFilePath({ node, getNode }) 8 | actions.createNodeField({ 9 | name: 'slug', 10 | node, 11 | value, 12 | }) 13 | } 14 | 15 | exports.createPages = async ({ graphql, actions }) => { 16 | const result = await graphql(` 17 | { 18 | allMdx { 19 | edges { 20 | node { 21 | id 22 | fields { 23 | slug 24 | } 25 | } 26 | } 27 | } 28 | } 29 | `) 30 | if (result.errors) { 31 | console.log(result.errors) 32 | return 33 | } 34 | const pages = result.data.allMdx.edges.map(edge => edge.node) 35 | 36 | pages.forEach(page => { 37 | actions.createPage({ 38 | path: page.fields.slug, 39 | component: require.resolve('./src/doc.js'), 40 | context: { 41 | id: page.id, 42 | }, 43 | }) 44 | }) 45 | } 46 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | 2 | # The MIT License (MIT) 3 | Copyright (c) 2017-2018 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 | -------------------------------------------------------------------------------- /docs/src/badges.md: -------------------------------------------------------------------------------- 1 | [![gh][]][github] 2 | [![stars][]][github] 3 | [![Build Status][circleci-badge]][circleci] 4 | [![Downloads][]][npm] 5 | [![Version][]][npm] 6 | ![size][] 7 | ![MIT License][license] 8 | [![spectrum-badge][]][spectrum] 9 | [![system-ui/theme][system-ui-badge]](https://system-ui.com/theme) 10 | 11 | [circleci]: https://circleci.com/gh/styled-system/styled-system 12 | [circleci-badge]: https://flat.badgen.net/circleci/github/styled-system/styled-system/master 13 | [version]: https://flat.badgen.net/npm/v/styled-system 14 | [downloads]: https://flat.badgen.net/npm/dm/styled-system 15 | [license]: https://flat.badgen.net/badge/license/MIT/blue 16 | [stars]: https://flat.badgen.net/github/stars/styled-system/styled-system 17 | [gh]: https://flat.badgen.net/badge//GitHub/black?icon=github 18 | [size]: https://flat.badgen.net/bundlephobia/minzip/styled-system 19 | [system-ui-badge]: https://flat.badgen.net/badge/system-ui/theme/black 20 | [spectrum-badge]: https://flat.badgen.net/badge/spectrum/community/purple 21 | [npm]: https://npmjs.com/package/styled-system 22 | [github]: https://github.com/styled-system/styled-system 23 | [spectrum]: https://spectrum.chat/styled-system 24 | -------------------------------------------------------------------------------- /packages/border/src/index.js: -------------------------------------------------------------------------------- 1 | import { system } from '@styled-system/core' 2 | 3 | const config = { 4 | border: { 5 | property: 'border', 6 | scale: 'borders', 7 | }, 8 | borderWidth: { 9 | property: 'borderWidth', 10 | scale: 'borderWidths', 11 | }, 12 | borderStyle: { 13 | property: 'borderStyle', 14 | scale: 'borderStyles', 15 | }, 16 | borderColor: { 17 | property: 'borderColor', 18 | scale: 'colors', 19 | }, 20 | borderRadius: { 21 | property: 'borderRadius', 22 | scale: 'radii', 23 | }, 24 | borderTop: { 25 | property: 'borderTop', 26 | scale: 'borders', 27 | }, 28 | borderRight: { 29 | property: 'borderRight', 30 | scale: 'borders', 31 | }, 32 | borderBottom: { 33 | property: 'borderBottom', 34 | scale: 'borders', 35 | }, 36 | borderLeft: { 37 | property: 'borderLeft', 38 | scale: 'borders', 39 | }, 40 | borderX: { 41 | properties: ['borderLeft', 'borderRight'], 42 | scale: 'borders', 43 | }, 44 | borderY: { 45 | properties: ['borderTop', 'borderBottom'], 46 | scale: 'borders', 47 | }, 48 | } 49 | 50 | export const border = system(config) 51 | 52 | export default border 53 | -------------------------------------------------------------------------------- /docs/guides/default-values.md: -------------------------------------------------------------------------------- 1 | # Default Values 2 | 3 | A question that comes up quite often is how do you define defaults for Styled System props. 4 | Luckily, React has a built-in way to set defaults for props with the `defaultProps` object. 5 | 6 | Let's say you have a Card component that nine times out of ten, 7 | has a specific padding, but every once in a while, you need to change it up. 8 | To add a default value for any Styled System prop, use `defaultProps` on your component. 9 | 10 | ```js 11 | // example 12 | import styled from 'styled-components' 13 | import { space, color } from 'styled-system' 14 | 15 | const Card = styled.div( 16 | { 17 | borderRadius: '2px', 18 | boxShadow: '0 2px 4px rgba(0, 0, 0, 0.125)', 19 | }, 20 | space, 21 | color 22 | ) 23 | 24 | Card.defaultProps = { 25 | p: 2, 26 | bg: 'white', 27 | } 28 | 29 | export default Card 30 | ``` 31 | 32 | With the default props above, your Card component will have padding and a white background by default. 33 | You can override these styles when needed by passing a prop to the component. 34 | 35 | ```jsx 36 | // example overriding default styles 37 | 38 | 39 | 40 | 41 | ``` 42 | -------------------------------------------------------------------------------- /packages/should-forward-prop/README.md: -------------------------------------------------------------------------------- 1 | 2 | # @styled-system/should-forward-prop 3 | 4 | Utility for filtering Styled System props with Emotion's shouldForwardProp option 5 | 6 | ```sh 7 | npm i @styled-system/should-forward-prop 8 | ``` 9 | 10 | ```js 11 | import styled from '@emotion/styled' 12 | import { 13 | space, 14 | color, 15 | typography 16 | } from 'styled-system' 17 | import shouldForwardProp from '@styled-system/should-forward-prop' 18 | 19 | const Box = styled('div', { shouldForwardProp })( 20 | space, 21 | color, 22 | typography 23 | ) 24 | ``` 25 | 26 | ## Custom Props 27 | 28 | To exclude other custom props not included in Styled System, use the `createShouldForwardProp` utility. 29 | 30 | ```js 31 | import styled from '@emotion/styled' 32 | import { space, color } from 'styled-system' 33 | import { createShouldForwardProp, props } from '@styled-system/should-forward-prop' 34 | 35 | const shouldForwardProp = createShouldForwardProp([ 36 | ...props, 37 | 'd', 38 | 'x' 39 | ]) 40 | 41 | const Box = styled('div', { 42 | shouldForwardProp 43 | })(props => ({ 44 | display: props.d, 45 | fontWeight: props.x ? 'bold' : null, 46 | }), 47 | space, 48 | color 49 | ) 50 | ``` 51 | 52 | MIT License 53 | -------------------------------------------------------------------------------- /docs/src/logos.mdx: -------------------------------------------------------------------------------- 1 | import { ThemeProvider, Styled, Flex } from 'theme-ui' 2 | 3 | export default props => 4 | 18 | 19 | {props.children} 20 | 21 | 22 | 23 | ### Used by 24 | 25 | 29 | GitHub logo 34 | Artsy logo 39 | Cloudflare logo 44 | Priceline logo 49 | 50 | -------------------------------------------------------------------------------- /examples/babel-plugin/src/pages/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { Global, ThemeContext } from '@emotion/core' 3 | 4 | const theme = { 5 | space: [0, 4, 8, 16, 32, 64, 128, 256], 6 | colors: { 7 | primary: '#33e', 8 | secondary: '#609', 9 | }, 10 | fontSizes: [12, 14, 16, 20, 32, 48, 64, 72, 96], 11 | } 12 | 13 | const styles = ( 14 | 20 | ) 21 | 22 | export default props => { 23 | return ( 24 | 25 | {styles} 26 |
27 |
28 |

Hello

29 |

30 | This example is using the @styled-system/babel-plugin{' '} 31 | to add styles based on props. 32 |

33 |
34 |
35 |

36 | These style props work on any JSX element and don't require 37 | the use of custom styled components. 38 |

39 |
40 |
41 |
42 | ) 43 | } 44 | -------------------------------------------------------------------------------- /docs/src/logo/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { hex, inner } from './hex' 3 | 4 | const Logo = ({ size = 512 }) => ( 5 | 18 | 19 | 20 | 21 | 22 | 23 | ) 24 | 25 | Logo.defaultProps = { 26 | ignore: true, 27 | } 28 | 29 | export default Logo 30 | 31 | /* 32 | // generate a hexagon 33 | const radius = 12 34 | const rad = a => Math.PI * a / 180 35 | const round = n => Math.round(n * 1000) / 1000 36 | const rx = (r, a) => round(r * Math.cos(rad(a))) 37 | const ry = (r, a) => round(r * Math.sin(rad(a))) 38 | const num = n => (n < 0.0000001) ? 0 : n 39 | 40 | const offset = 90 41 | const getPoints = length => Array.from({ length }) 42 | .map((n, i) => { 43 | const a = 360 / length * i - offset 44 | const x = rx(radius, a) 45 | const y = ry(radius, a) 46 | return { x, y } 47 | }) 48 | 49 | const points = getPoints(6) 50 | 51 | const [ a, b, c, d, e, f ] = points 52 | */ 53 | -------------------------------------------------------------------------------- /docs/src/logo/hex.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | export const hex = ` 4 | M0 -16 5 | L-14 -8 6 | L -14 8 7 | L 0 16 8 | L 14 8 9 | L 14 -8 10 | L 0 -16 11 | z 12 | ` 13 | export const inner = ` 14 | M0 -16 15 | L 0 0 16 | M-14 8 17 | L0 0 18 | L14 8 19 | ` 20 | 21 | const pattern = ( 22 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | ) 41 | 42 | export default ({ width = 1024, height = 512 }) => ( 43 |
49 | 57 | {pattern} 58 | 59 | 60 |
61 | ) 62 | -------------------------------------------------------------------------------- /examples/svelte/rollup.config.js: -------------------------------------------------------------------------------- 1 | // this file will not afect the sandbox but will 2 | // afect the deployment and dowload 3 | 4 | import svelte from "rollup-plugin-svelte"; 5 | import resolve from "rollup-plugin-node-resolve"; 6 | import commonjs from "rollup-plugin-commonjs"; 7 | import { terser } from "rollup-plugin-terser"; 8 | 9 | const production = !process.env.ROLLUP_WATCH; 10 | 11 | export default { 12 | input: "index.js", 13 | output: { 14 | sourcemap: true, 15 | format: "iife", 16 | name: "app", 17 | file: "public/bundle.js" 18 | }, 19 | plugins: [ 20 | svelte({ 21 | // enable run-time checks when not in production 22 | dev: !production, 23 | // we'll extract any component CSS out into 24 | // a separate file — better for performance 25 | css: css => { 26 | css.write("public/bundle.css"); 27 | } 28 | }), 29 | 30 | // If you have external dependencies installed from 31 | // npm, you'll most likely need these plugins. In 32 | // some cases you'll need additional configuration — 33 | // consult the documentation for details: 34 | // https://github.com/rollup/rollup-plugin-commonjs 35 | resolve(), 36 | commonjs(), 37 | 38 | // If we're building for production (npm run build 39 | // instead of npm run dev), minify 40 | production && terser() 41 | ] 42 | }; 43 | -------------------------------------------------------------------------------- /docs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "name": "@styled-system/docs", 4 | "version": "5.0.0-8", 5 | "scripts": { 6 | "start": "gatsby develop", 7 | "build": "gatsby build", 8 | "clean": "gatsby clean" 9 | }, 10 | "dependencies": { 11 | "@emotion/core": "^10.0.10", 12 | "@emotion/styled": "^10.0.11", 13 | "@mdx-js/mdx": "^1.0.19", 14 | "@mdx-js/react": "^1.0.16", 15 | "@styled-system/babel-plugin": "0.0.20", 16 | "@styled-system/css": "^5.0.0-7", 17 | "@styled-system/edit": "5.0.1", 18 | "@styled-system/should-forward-prop": "5.0.1", 19 | "gatsby": "^2.4.6", 20 | "gatsby-plugin-emotion": "^4.0.6", 21 | "gatsby-plugin-google-analytics": "^2.0.20", 22 | "gatsby-plugin-mdx": "^1.0.5", 23 | "gatsby-plugin-react-helmet": "^3.0.12", 24 | "gatsby-plugin-theme-ui": "^0.0.17", 25 | "gatsby-remark-prismjs": "^3.2.9", 26 | "gatsby-source-filesystem": "^2.0.35", 27 | "is-absolute-url": "^3.0.0", 28 | "lodash.get": "^4.4.2", 29 | "lodash.merge": "^4.6.1", 30 | "prismjs": "^1.16.0", 31 | "react": "^16.8.6", 32 | "react-dom": "^16.8.6", 33 | "react-helmet": "^6.0.0-beta", 34 | "remark-slug": "^5.1.1", 35 | "remark-unwrap-images": "^0.2.0", 36 | "styled-system": "^5.0.0-8", 37 | "theme-ui": "^0.0.17", 38 | "typography-theme-lincoln": "^0.16.19" 39 | }, 40 | "devDependencies": {} 41 | } 42 | -------------------------------------------------------------------------------- /docs/testimonials.md: -------------------------------------------------------------------------------- 1 | > "This is honestly my favourite way to build UI components right now ![party parrot][party-parrot]" 2 | > 3 | > – [Varun Vachhar][varun-post] 4 | 5 | [party-parrot]: https://github.com/jmhobbs/cultofthepartyparrot.com/raw/master/parrots/parrot.gif 6 | 7 | 12 | 13 | > "The future of css-in-js is going to look something like styled-system with its responsive values."
14 | > 15 | > – [Kye Hohenberger](https://mobile.twitter.com/tkh44/status/905474043729416192) 16 | 17 | > "Coming from @tachyons_css, the styled-system utilities from @jxnblk is the missing link I’ve been looking for."
18 | > 19 | > – [Nathan Young](https://mobile.twitter.com/nathanyoung/status/891353221880360960) 20 | 21 | > "If you make websites/apps with React check out Styled System if you haven't already. You will be amazed at how much faster you can build." 22 | > 23 | > – [David Yeiser][david-tweet] 24 | 25 | [dalgleish]: https://mobile.twitter.com/markdalgleish/status/913191186944241665 26 | [mrmrs]: https://mobile.twitter.com/mrmrs_/status/913189805055401984 27 | [varun-post]: https://varun.ca/styled-system/ 28 | [david-tweet]: https://mobile.twitter.com/davidyeiser/status/965920740582285312 29 | -------------------------------------------------------------------------------- /docs/src/sidebar.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import styled from '@emotion/styled' 3 | import { ThemeProvider, Box, css } from 'theme-ui' 4 | import NavLink from './nav-link' 5 | import Content from './sidebar.mdx' 6 | 7 | const components = { 8 | a: NavLink, 9 | } 10 | 11 | const styles = { 12 | ul: { 13 | listStyle: 'none', 14 | px: 0, 15 | my: 0, 16 | }, 17 | li: { 18 | '& > ul': { 19 | pl: 16, 20 | }, 21 | }, 22 | a: { 23 | color: 'inherit', 24 | '&:hover': { 25 | color: 'primary', 26 | }, 27 | }, 28 | } 29 | 30 | const Root = styled(Box)( 31 | css({ 32 | minWidth: 0, 33 | flex: 'none', 34 | overflowY: 'auto', 35 | WebkitOverflowScrolling: 'touch', 36 | position: 'sticky', 37 | top: 0, 38 | alignSelf: 'flex-start', 39 | maxHeight: '100vh', 40 | color: 'text', 41 | bg: 'background', 42 | }), 43 | props => ({ 44 | '@media screen and (max-width: 40em)': { 45 | position: 'fixed', 46 | top: '64px', 47 | minHeight: 0, 48 | maxHeight: props.open ? 'calc(100vh - 64px)' : 0, 49 | height: 'auto', 50 | transition: 'max-height .2s ease-out', 51 | boxShadow: `0 2px 8px rgba(0, 0, 0, .25)`, 52 | }, 53 | }) 54 | // block('sidebar') 55 | ) 56 | 57 | export default props => ( 58 | 59 | 60 | 61 | 62 | 63 | ) 64 | -------------------------------------------------------------------------------- /docs/rationale.md: -------------------------------------------------------------------------------- 1 | From [spectrum](https://spectrum.chat/thread/b9afb6f3-a675-4f97-bc78-66411292fab1) 2 | 3 | I'm sure Styled System isn't for everyone, but here's some of the thinking behind it. 4 | Styled System is meant to: 5 | - Help ensure you're using scales and values consistently across your app 6 | - Help ensure that if you *do* want to use style props, that there is some across-the-board consistency with the prop naming conventions, e.g. `px={2}` works the same for all components that use the `space` utility 7 | - Allow for setting single properties, such as width or font-size, responsively without needing to handle media queries 8 | - Write less CSS, e.g. Styled System is an abstraction built on top that gives you flexibility where needed 9 | - From my experience, many developers do not want to write CSS or end up writing a lot of duplicative code. Other developers like to write CSS, and that's also completely fine, but this library probably isn't necessary for teams of fewer than 10 people where most have a good understanding of CSS. 10 | - With styled-components and other libraries, you can still escape into low-level CSS using things like the `.extend()` method 11 | When I first released Basscss, people hated it. When I first introduced Rebass, people hated it. Some ideas like this take time to gain traction, but I've received a surprising amount of positive feedback around the library so far, and I suspect that there's some value in approaches like this 12 | -------------------------------------------------------------------------------- /examples/svelte/README.md: -------------------------------------------------------------------------------- 1 | # svelte app 2 | 3 | This is a project template for [Svelte](https://svelte.technology) apps. It lives at https://github.com/sveltejs/template. 4 | 5 | To create a new project based on this template using [degit](https://github.com/Rich-Harris/degit): 6 | 7 | ```bash 8 | npm install -g degit # you only need to do this once 9 | 10 | degit sveltejs/template svelte-app 11 | cd svelte-app 12 | ``` 13 | 14 | *Note that you will need to have [Node.js](https://nodejs.org) installed.* 15 | 16 | 17 | ## Get started 18 | 19 | Install the dependencies... 20 | 21 | ```bash 22 | cd svelte-app 23 | npm install 24 | ``` 25 | 26 | ...then start [Rollup](https://rollupjs.org): 27 | 28 | ```bash 29 | npm run dev 30 | ``` 31 | 32 | Navigate to [localhost:5000](http://localhost:5000). You should see your app running. Edit a component file in `src`, save it, and reload the page to see your changes. 33 | 34 | 35 | ## Deploying to the web 36 | 37 | ### With [now](https://zeit.co/now) 38 | 39 | Install `now` if you haven't already: 40 | 41 | ```bash 42 | npm install -g now 43 | ``` 44 | 45 | Then, from within your project folder: 46 | 47 | ```bash 48 | now 49 | ``` 50 | 51 | As an alternative, use the [Now desktop client](https://zeit.co/download) and simply drag the unzipped project folder to the taskbar icon. 52 | 53 | ### With [surge](https://surge.sh/) 54 | 55 | Install `surge` if you haven't already: 56 | 57 | ```bash 58 | npm install -g surge 59 | ``` 60 | 61 | Then, from within your project folder: 62 | 63 | ```bash 64 | npm run build 65 | surge public 66 | ``` 67 | -------------------------------------------------------------------------------- /docs/src/toc-wrapper.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { Box, Styled } from 'theme-ui' 3 | 4 | const headings = ['h2', 'h3'] 5 | const getLinks = children => 6 | React.Children.toArray(children).reduce((a, child) => { 7 | if (!headings.includes(child.props.mdxType)) return a 8 | const item = { 9 | text: child.props.children, 10 | href: '#' + child.props.id, 11 | } 12 | const level = headings.indexOf(child.props.mdxType) 13 | if (level === 0) { 14 | return [...a, item] 15 | } 16 | const previous = a[a.length - 1] 17 | if (Array.isArray(previous)) { 18 | return [...a.slice(0, a.length - 1), [...previous, item]] 19 | } 20 | return [...a, [item]] 21 | }, []) 22 | 23 | const List = ({ links }) => ( 24 | 30 | {links.map((link, i) => 31 | Array.isArray(link) ? ( 32 | 33 | ) : ( 34 | 35 | {link.text} 36 | 37 | ) 38 | )} 39 | 40 | ) 41 | 42 | const TOC = ({ links }) => ( 43 | 51 | 52 | 53 | ) 54 | 55 | export default props => { 56 | if (!props.toc) return <>{props.children} 57 | 58 | const links = getLinks(props.children) 59 | return ( 60 | <> 61 | 62 | {props.children} 63 | 64 | ) 65 | } 66 | -------------------------------------------------------------------------------- /docs/how-it-works.md: -------------------------------------------------------------------------------- 1 | # How it Works 2 | 3 | Most CSS-in-JS libraries accept functions as arguments to create dynamic styles based on props. 4 | For example, the following sets color dynamically in styled-components based on the `color` prop: 5 | 6 | ```js 7 | import styled from 'styled-components' 8 | 9 | const Box = styled.div` 10 | color: ${props => props.color}; 11 | ` 12 | ``` 13 | 14 | Beyond just passing a dynamic value, an entire style declaration can be returned in functions like this. 15 | 16 | ```js 17 | import styled from 'styled-components' 18 | 19 | const getColor = props => `color: ${props.color};` 20 | 21 | const Box = styled.div` 22 | ${getColor} 23 | ` 24 | ``` 25 | 26 | Style object can also be returned, which is a much simpler way to handle dynamic values in JavaScript. 27 | 28 | ```js 29 | import styled from 'styled-components' 30 | 31 | // works exactly the same as the previous function 32 | const getColor = props => ({ 33 | color: props.color, 34 | }) 35 | 36 | const Box = styled.div` 37 | ${getColor} 38 | ` 39 | ``` 40 | 41 | By using style objects instead of embedded CSS strings, Styled System is compatible with a wide range of CSS-in-JS libraries. 42 | 43 | The core utilities in Styled System are built on this pattern and consist of functions that take `props` as an argument 44 | and return style objects, 45 | while making it simpler to use values from a theme and apply styles responsively across breakpoints. 46 | 47 | These style functions can be written on a one-off basis, but Styled System is meant to help **reduce boilerplate**, ensure a **consistent styling API**, and speed the development of component-based design systems. 48 | -------------------------------------------------------------------------------- /docs/src/pages/demo.js: -------------------------------------------------------------------------------- 1 | import React, { useContext } from 'react' 2 | import { EditProvider, EditContext, ThemeControls } from '@styled-system/edit' 3 | import { Global } from '@emotion/core' 4 | import Layout from '../layout' 5 | import { css, ThemeProvider, Styled } from 'theme-ui' 6 | import GettingStarted from '../../getting-started.md' 7 | 8 | const WrappedProvider = props => { 9 | const context = useContext(EditContext) 10 | return ( 11 | 12 | 14 | css({ 15 | body: { 16 | fontFamily: 'body', 17 | color: 'text', 18 | bg: 'background', 19 | }, 20 | })(theme) 21 | } 22 | /> 23 | {props.children} 24 | 25 | ) 26 | } 27 | 28 | export default props => ( 29 | 30 | 31 | 40 | Demo 41 | 42 | This is a demonstration of some of the theming capabilities in Styled 43 | System. Use the controls to the right to adjust this page’s theme in 44 | real-time. 45 | 46 | 47 | Demo content below 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | ) 56 | -------------------------------------------------------------------------------- /docs/guides/component-types.md: -------------------------------------------------------------------------------- 1 | # Component Types 2 | 3 | Some teams that have adopted Styled System take an approach to organizing UI components by type, 4 | creating separate layout, typography, flexbox, and other categories when adding style props. 5 | This means that each _layout_ component type is guaranteed to have the same props API as the others. 6 | For an example of this approach, see [Primer Components](https://primer.style/components/docs/system-props). 7 | 8 | To create your own component types, use the `compose` utility 9 | to create custom style functions that each new component can use. 10 | 11 | ## Creating a Layout component type 12 | 13 | To group these shared Styled System props together, create a new module that will include these style functions. 14 | 15 | ```js 16 | // custom styled-system groupings 17 | import { compose, space, color, display, width, maxWidth } from 'styled-system' 18 | 19 | export const layout = compose( 20 | space, 21 | display, 22 | width, 23 | maxWidth, 24 | color 25 | ) 26 | ``` 27 | 28 | To add these props to a component, import the composed `layout` function and pass it to the `styled` function. 29 | 30 | ```js 31 | // example component definition 32 | import styled from 'styled-components' 33 | import { layout } from './style-props' 34 | 35 | export const Box = styled('div')(layout) 36 | ``` 37 | 38 | ## Creating other component types 39 | 40 | Be sure to discuss with your team to figure out what makes sense as a component type. 41 | The following is a list of commonly used component types as a guide. 42 | 43 | - `layout`; used for page layout, grid systems, and spacing 44 | - `typography`: headings, paragraphs, labels, etc. 45 | - `content`: images, videos, diagrams, etc. 46 | - `position`: position, z-index, etc. 47 | - `flexbox`: flexbox-related styles 48 | - `border`: border colors, widths, styles, and radii 49 | -------------------------------------------------------------------------------- /examples/jsx/src/index.js: -------------------------------------------------------------------------------- 1 | /** @jsx jsx */ 2 | import jsx from '@styled-system/jsx' 3 | import { Global, ThemeContext } from '@emotion/core' 4 | import React from 'react' 5 | import { render } from 'react-dom' 6 | 7 | const theme = { 8 | fonts: { 9 | body: 'system-ui, sans-serif', 10 | heading: 'inherit', 11 | monospace: 'Menlo, monospace', 12 | }, 13 | fontSizes: [12, 14, 16, 24, 32, 48, 64, 96, 128], 14 | lineHeights: { 15 | body: 1.5, 16 | heading: 1.25, 17 | }, 18 | space: [ 19 | // margin and padding 20 | 0, 21 | 4, 22 | 8, 23 | 16, 24 | 32, 25 | 64, 26 | 128, 27 | 256, 28 | ], 29 | colors: { 30 | primary: '#07c', 31 | secondard: '#05a', 32 | highlight: '#e10', 33 | } 34 | } 35 | 36 | const Root = props => 37 |
45 | 46 | const Heading = props => 47 |

55 | 56 | export const App = props => { 57 | return ( 58 | 59 | 60 | 68 | 69 | @styled-system/jsx 70 | example 71 | 72 |
77 |           npm i @styled-system/css
78 |         
79 |
80 |
81 | ) 82 | } 83 | 84 | render(, document.getElementById('root')) 85 | -------------------------------------------------------------------------------- /examples/css/src/index.js: -------------------------------------------------------------------------------- 1 | /** @jsx jsx */ 2 | import { jsx, Global, ThemeContext } from '@emotion/core' 3 | import React from 'react' 4 | import { render } from 'react-dom' 5 | import css from '@styled-system/css' 6 | 7 | const theme = { 8 | fonts: { 9 | body: 'system-ui, sans-serif', 10 | heading: 'inherit', 11 | monospace: 'Menlo, monospace', 12 | }, 13 | fontSizes: [12, 14, 16, 24, 32, 48, 64, 96, 128], 14 | lineHeights: { 15 | body: 1.5, 16 | heading: 1.25, 17 | }, 18 | space: [ 19 | // margin and padding 20 | 0, 21 | 4, 22 | 8, 23 | 16, 24 | 32, 25 | 64, 26 | 128, 27 | 256, 28 | ], 29 | colors: { 30 | primary: '#07c', 31 | secondard: '#05a', 32 | highlight: '#e10', 33 | } 34 | } 35 | 36 | const Root = props => 37 |
45 | 46 | const Heading = props => 47 |

55 | 56 | export const App = props => { 57 | return ( 58 | 59 | 60 | 68 | 69 | @styled-system/css 70 | example 71 | 72 |
77 |           npm i @styled-system/css
78 |         
79 |
80 |
81 | ) 82 | } 83 | 84 | render(, document.getElementById('root')) 85 | -------------------------------------------------------------------------------- /examples/theme-aliases/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import ReactDOM from 'react-dom' 3 | import styled, { ThemeProvider, injectGlobal } from 'styled-components' 4 | import { 5 | space, 6 | color, 7 | fontSize, 8 | width, 9 | fontWeight, 10 | lineHeight, 11 | } from 'styled-system' 12 | 13 | injectGlobal` 14 | body{margin:0;} 15 | ` 16 | 17 | const theme = { 18 | fontSizes: [12, 14, 16, 24, 32, 48, 64, 96, 128], 19 | space: [0, 4, 8, 16, 32, 64, 128, 256], 20 | colors: { 21 | blue: '#07c', 22 | red: '#e10', 23 | }, 24 | } 25 | 26 | // aliases 27 | // currently a bug - numbers should be converted to px 28 | theme.space.big = theme.space[5] + 'px' 29 | theme.space['2.5'] = '12px' 30 | theme.fontSizes.big = 96 31 | 32 | const Root = styled.div` 33 | font-family: system-ui, sans-serif; 34 | line-height: 1.5; 35 | ` 36 | 37 | const Box = styled.div` 38 | ${space} 39 | ${width} 40 | ${fontSize} 41 | ${color} 42 | ` 43 | Box.propTypes = { 44 | ...space.propTypes, 45 | ...width.propTypes, 46 | ...fontSize.propTypes, 47 | ...color.propTypes, 48 | } 49 | 50 | const Text = styled.div` 51 | ${space} 52 | ${fontSize} 53 | ${fontWeight} 54 | ${lineHeight} 55 | ${color} 56 | ` 57 | Text.propTypes = { 58 | ...space.propTypes, 59 | ...fontSize.propTypes, 60 | ...fontWeight.propTypes, 61 | ...lineHeight.propTypes, 62 | ...color.propTypes, 63 | } 64 | 65 | const Heading = Text.withComponent('h1') 66 | 67 | Heading.defaultProps = { 68 | fontSize: 5, 69 | lineHeight: 1.5, 70 | m: 0, 71 | } 72 | 73 | class App extends React.Component { 74 | render() { 75 | return ( 76 | 77 | 78 | 79 | styled-system 80 | Basic demo 81 | 82 | 83 | 84 | ) 85 | } 86 | } 87 | 88 | ReactDOM.render(, document.getElementById('root')) 89 | -------------------------------------------------------------------------------- /examples/basic/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import ReactDOM from 'react-dom' 3 | import styled, { ThemeProvider, createGlobalStyle } from 'styled-components' 4 | import { 5 | space, 6 | color, 7 | fontSize, 8 | width, 9 | fontWeight, 10 | lineHeight, 11 | } from 'styled-system' 12 | 13 | const Style = createGlobalStyle` 14 | * { box-sizing: border-box; } 15 | body{ margin:0; } 16 | ` 17 | 18 | const theme = { 19 | fontSizes: [12, 14, 16, 24, 32, 48, 64, 96, 128], 20 | space: [ 21 | // margin and padding 22 | 0, 23 | 4, 24 | 8, 25 | 16, 26 | 32, 27 | 64, 28 | 128, 29 | 256, 30 | ], 31 | colors: { 32 | blue: '#07c', 33 | red: '#e10', 34 | }, 35 | } 36 | 37 | const Root = styled.div` 38 | font-family: system-ui, sans-serif; 39 | line-height: 1.5; 40 | ` 41 | 42 | const Box = styled.div` 43 | ${space} 44 | ${width} 45 | ${fontSize} 46 | ${color} 47 | ` 48 | Box.propTypes = { 49 | ...space.propTypes, 50 | ...width.propTypes, 51 | ...fontSize.propTypes, 52 | ...color.propTypes, 53 | } 54 | 55 | const Text = styled.div` 56 | ${space} 57 | ${fontSize} 58 | ${fontWeight} 59 | ${lineHeight} 60 | ${color} 61 | ` 62 | Text.propTypes = { 63 | ...space.propTypes, 64 | ...fontSize.propTypes, 65 | ...fontWeight.propTypes, 66 | ...lineHeight.propTypes, 67 | ...color.propTypes, 68 | } 69 | 70 | const Heading = Text.withComponent('h1') 71 | 72 | Heading.defaultProps = { 73 | fontSize: 5, 74 | lineHeight: 1.5, 75 | m: 0, 76 | } 77 | 78 | class App extends React.Component { 79 | render() { 80 | return ( 81 | 82 | 83 |