Skip to content

Commit

Permalink
feat(docz-example-typescript): add new example
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed May 28, 2018
1 parent 5b53b07 commit 9052d0f
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 0 deletions.
5 changes: 5 additions & 0 deletions examples/typescript/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"plugins": [
"emotion"
]
}
3 changes: 3 additions & 0 deletions examples/typescript/doczrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
typescript: true,
}
19 changes: 19 additions & 0 deletions examples/typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "docz-example-typescript",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"dev": "docz dev",
"build": "docz build"
},
"dependencies": {
"docz": "^0.0.1",
"emotion": "^9.1.3",
"react": "^16.4.0",
"react-dom": "^16.4.0",
"react-emotion": "^9.1.3"
},
"devDependencies": {
"babel-plugin-emotion": "^9.0.1"
}
}
38 changes: 38 additions & 0 deletions examples/typescript/src/components/Alert.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
name: Alert
menu: Components
---

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

# Alert

<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>
34 changes: 34 additions & 0 deletions examples/typescript/src/components/Alert.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React, { SFC } from 'react'
import styled from 'react-emotion'

export type Kind = 'info' | 'positive' | 'negative' | 'warning'
export type KindMap = Record<Kind, string>

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

export interface AlertProps {
/**
* Set this to change alert kind
* @default info
*/
kind: 'info' | 'positive' | 'negative' | 'warning'
}

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

const Alert: SFC<AlertProps> = ({ kind, ...props }) => (
<AlertStyled {...props} kind={kind} />
)

export default Alert
15 changes: 15 additions & 0 deletions examples/typescript/src/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
name: Getting Started
route: /
order: 1
---

# Getting Started

A design system can help establish a common vocabulary between everyone in an organization. That’s why I’ve spent a great deal of time coming up with structure and naming for Vue Design System that would make sense. To start opening it up, let’s go through each layer in detail and what the terms mean:

- *Principles* are the foundation of the whole system. They form the basis of a good product and help the team with decision making. They are there to guide you and your team when working with the myriad parts of the system and help you do better and more informed decisions.
- *Design* Tokens are the atoms of the system as Salesforce describes them. In Vue Design System they are used instead of hard coded values to ensure a better consistency across any platform.
- *Elements* utilize decisions made on the token level. A simple example of an element would be a button, a link, or an input. Anything that cannot be broken down further. I use the name ‘element’ since everything in Vue and React world is nowadays ‘a component.’ Using that term for anything else would be confusing.
- *Patterns* are UI Patterns that fall on the more complex side of the spectrum. So for example things like a date picker, a data table, or a visualization. Patterns utilize both elements and tokens. If you wonder whether something should be called an element or a pattern, ask yourself this question: “Can this be broken down into smaller pieces?” If the answer is yes, it should most likely be a pattern in Vue Design System.
- *Templates* exist to document the layout and structure of a section. I am not calling these pages since semantically that would be incorrect. While they can be pages, that’s not their only functionality. Templates consist of the three things mentioned above: tokens, elements, and patterns.
12 changes: 12 additions & 0 deletions examples/typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
"declaration": true,
"types": ["node"],
"typeRoots": ["node_modules/@types"]
},
"include": ["src/**/*"],
"exclude": ["node_modules/**"]
}
3 changes: 3 additions & 0 deletions examples/typescript/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../tslint.json"
}

0 comments on commit 9052d0f

Please sign in to comment.