Skip to content

Commit

Permalink
feat(docz-example-styled-components): add new example
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Sep 2, 2018
1 parent 1b13056 commit 0cef75e
Show file tree
Hide file tree
Showing 6 changed files with 238 additions and 0 deletions.
17 changes: 17 additions & 0 deletions examples/styled-components/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "docz-example-styled-components",
"version": "0.10.3",
"license": "MIT",
"scripts": {
"dev": "docz dev",
"build": "docz build"
},
"dependencies": {
"prop-types": "^15.6.2",
"react": "^16.4.2",
"react-dom": "^16.4.2"
},
"devDependencies": {
"docz": "^0.10.3"
}
}
28 changes: 28 additions & 0 deletions examples/styled-components/src/components/Alert.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React, { Fragment } from 'react'
import styled from 'styled-components'
import t from 'prop-types'

const kinds = {
info: '#5352ED',
positive: '#2ED573',
negative: '#FF4757',
warning: '#FFA502',
}

const AlertStyled = styled('div')`
padding: 15px 20px;
background: white;
border-radius: 3px;
color: white;
background: ${({ kind = 'info' }) => kinds[kind]};
`

export const Alert = props => <AlertStyled {...props} />

Alert.propTypes = {
kind: t.oneOf(['info', 'positive', 'negative', 'warning']),
}

Alert.defaultProps = {
kind: 'info',
}
40 changes: 40 additions & 0 deletions examples/styled-components/src/components/Alert.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
name: Alert
menu: Components
---

import { Playground, PropsTable } from 'docz'
import { Alert } from './Alert'

# Alert

## Properties

<PropsTable of={Alert} />

## Basic usage

<Playground>
<Alert>Some message</Alert>
</Playground>

## Using different kinds

<Playground>
<Alert kind="info">Some message</Alert>
<Alert kind="positive">Some message</Alert>
<Alert kind="negative">Some message</Alert>
<Alert kind="warning">Some message</Alert>
</Playground>

## Use with children as a function

<Playground>
{() => {
const message = 'Hello world'

return (
<Alert>{message}</Alert>
)
}}
</Playground>
75 changes: 75 additions & 0 deletions examples/styled-components/src/components/Button.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import React from 'react'
import styled from 'styled-components'
import t from 'prop-types'

const scales = {
small: `
padding: 5px 10px;
font-size: 14px;
`,
normal: `
padding: 10px 20px;
font-size: 16px;
`,
big: `
padding: 20px 30px;
font-size: 18px;
`,
}

const kind = outline => (bg, color) => {
const boxShadowColor = outline ? bg : 'transparent'
const backgroundColor = outline ? 'transparent' : bg

return `
background: ${backgroundColor};
box-shadow: inset 0 0 0 1px ${boxShadowColor};
color: ${outline ? bg : color};
transition: all .3s;
&:hover {
box-shadow: inset 0 0 0 1000px ${boxShadowColor};
color: ${color};
}
`
}

const kinds = outline => {
const get = kind(outline)

return {
primary: get('#1FB6FF', 'white'),
secondary: get('#5352ED', 'white'),
cancel: get('#FF4949', 'white'),
dark: get('#273444', 'white'),
gray: get('#8492A6', 'white'),
}
}

const getScale = ({ scale = 'normal' }) => scales[scale]
const getKind = ({ kind = 'primary', outline = false }) => kinds(outline)[kind]

const ButtonStyled = styled('button')`
${getKind};
${getScale};
cursor: pointer;
margin: 3px 5px;
border: none;
border-radius: 3px;
`

export const Button = ({ children, ...props }) => (
<ButtonStyled {...props}>{children}</ButtonStyled>
)

Button.propTypes = {
scales: t.oneOf(['small', 'normal', 'big']),
kind: t.oneOf(['primary', 'secondary', 'cancel', 'dark', 'gray']),
outline: t.bool,
}

Button.defaultProps = {
scales: 'normal',
kind: 'primary',
outline: false,
}
57 changes: 57 additions & 0 deletions examples/styled-components/src/components/Button.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
name: Button
menu: Components
---

import { Playground, PropsTable } from 'docz'
import { Button } from './Button'

# Button

Buttons make common actions more obvious and help users more easily perform them. Buttons use labels and sometimes icons to communicate the action that will occur when the user touches them.

### Best practices

- Group buttons logically into sets based on usage and importance.
- Ensure that button actions are clear and consistent.
- The main action of a group set can be a primary button.
- Select a single button variation and do not mix them.

## Properties

<PropsTable of={Button} />

## Basic usage

<Playground>
<Button>Click me</Button>
</Playground>

## With different sizes

<Playground>
<Button scale="small">Click me</Button>
<Button scale="normal">Click me</Button>
<Button scale="big">Click me</Button>
</Playground>

## With different colors

<Playground>
<Button kind="primary">Click me</Button>
<Button kind="secondary">Click me</Button>
<Button kind="cancel">Click me</Button>
<Button kind="dark">Click me</Button>
<Button kind="gray">Click me</Button>
</Playground>

## Outlined

<Playground>
<Button kind="primary" outline>Click me</Button>
<Button kind="secondary" outline>Click me</Button>
<Button kind="cancel" outline>Click me</Button>
<Button kind="dark" outline>Click me</Button>
<Button kind="gray" outline>Click me</Button>
</Playground>

21 changes: 21 additions & 0 deletions examples/styled-components/src/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
name: Getting Started
route: /
order: 1
---

# Getting Started

Design systems enable teams to build better products faster by making design reusable—reusability makes scale possible. This is the heart and primary value of design systems. A design system is a collection of reusable components, guided by clear standards, that can be assembled together to build any number of applications.

Regardless of the technologies and tools behind them, a successful design system follows these guiding principles:

- **It’s consistent**. The way components are built and managed follows a predictable pattern.
- **It’s self-contained**. Your design system is treated as a standalone dependency.
- **It’s reusable**. You’ve built components so they can be reused in many contexts.
- **It’s accessible**. Applications built with your design system are usable by as many people as possible, no matter how they access the web.
- **It’s robust**. No matter the product or platform to which your design system is applied, it should perform with grace and minimal bugs.

## Consistency

Your first, most important task when starting out is to define the rules of your system, document them, and ensure that everyone follows them. When you have clearly documented code standards and best practices in place, designers and developers from across your organization can easily use and, more importantly, contribute to your design system.

0 comments on commit 0cef75e

Please sign in to comment.