feat(docz-example-styled-components): add new example

This commit is contained in:
Pedro Nauck
2018-09-01 21:38:05 -03:00
parent 1b1305688d
commit 0cef75eca4
6 changed files with 238 additions and 0 deletions

View File

@@ -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"
}
}

View File

@@ -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',
}

View File

@@ -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>

View File

@@ -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,
}

View File

@@ -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>

View File

@@ -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:
- **Its consistent**. The way components are built and managed follows a predictable pattern.
- **Its self-contained**. Your design system is treated as a standalone dependency.
- **Its reusable**. Youve built components so they can be reused in many contexts.
- **Its accessible**. Applications built with your design system are usable by as many people as possible, no matter how they access the web.
- **Its 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.