Skip to content

Commit

Permalink
feat: add native support for react-native
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Dec 4, 2018
1 parent a70dc7d commit f998874
Show file tree
Hide file tree
Showing 13 changed files with 446 additions and 483 deletions.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,13 @@ Documenting our things is one of the most important and heavy processes when you
## 🎛   Plugins

- **[css](https://github.com/pedronauck/docz-plugin-css)** - Parse css files inside your documents
- **[babel6](https://github.com/pedronauck/docz/blob/master/packages/docz-plugin-babel6)** - Use this plugin to use older babel version **[DEPRECATED]** ⚠️
- **[netlify](https://github.com/nicholasess/docz-plugin-netlify)** - Deploy your documentation to [Netlify](http://netlify.com/)
- **[react-native](https://github.com/pedronauck/docz-plugin-react-native)** - Allow you to use docz with React Native
- **[postcss](https://github.com/andreasonny83/docz-plugin-postcss)** - Use Docz with PostCSS

## 🗃   Examples

- **[basic](https://github.com/pedronauck/docz/tree/master/examples/basic)** - Some basic example
- **[babel 6](https://github.com/pedronauck/docz/tree/master/examples/babel6)** - Using docz with Babel@6 **[DEPRECATED]** ⚠️
- **[react native](https://github.com/pedronauck/docz-plugin-react-native/tree/master/example)** - Using in a React Native project
- **[react native](https://github.com/pedronauck/docz/tree/master/examples/react-native)** - Using in a React Native project
- **[with typescript](https://github.com/pedronauck/docz/tree/master/examples/typescript)** - Using docz with Typescript
- **[with flow](https://github.com/pedronauck/docz/tree/master/examples/flow)** - Using docz with Flow
- **[with sass](https://github.com/pedronauck/docz-plugin-css/tree/master/examples/css-sass)** - Using docz parsing css with Sass
Expand All @@ -116,7 +113,7 @@ npx babel-upgrade --write
```
## 📟   Install and Usage

Simplicity is one of our core principles. Therefore, getting started with **docz** is something really easy and quick. First of all, you will need to install **docz** on your project using some package managers
Simplicity is one of our core principles. Therefore, getting started with **docz** is something really easy and quick. First of all, you will need to install **docz** on your project using your favorite package manager (we'll asume yarn for this example):

```bash
$ yarn add docz --dev
Expand Down Expand Up @@ -144,7 +141,7 @@ import Button from './'
</Playground>
```

Now just run your dev server:
Now, just run your dev server:

```bash
$ yarn docz dev
Expand Down
2 changes: 1 addition & 1 deletion examples/flow/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@babel/preset-flow": "^7.0.0",
"babel-plugin-emotion": "^9.2.11",
"docz": "^0.12.14",
"flow-bin": "^0.86.0",
"flow-bin": "^0.87.0",
"flow-typed": "^2.5.1"
}
}
31 changes: 29 additions & 2 deletions examples/react-native/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
# ⚠️ &nbsp; [MOVED REPO](https://github.com/pedronauck/docz-plugin-react-native/tree/master/example)
## Docz React Native

To avoid some performances issues, we move this example to a new repo!
Use your React Native components inside docz

> We're using [react-native-web](https://github.com/necolas/react-native-web) to make this integration possible. So, maybe you can have some caveats.
## Instalation

These packages are required to use React Native with docz:

```bash
$ yarn add react-native-web react-art
```

Then, just set the `--native` argument with docz script:

```bash
$ docz dev --native
$ docz build --native
```

Or you can set directly on your `doczrc.js`:

```js
export default {
native: true
}
```

That's it 🙌🏻
4 changes: 4 additions & 0 deletions examples/react-native/doczrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default {
title: 'React Native',
native: true,
}
21 changes: 21 additions & 0 deletions examples/react-native/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "docz-example-react-native",
"version": "0.11.0",
"license": "MIT",
"scripts": {
"dev": "docz dev",
"build": "docz build"
},
"dependencies": {
"prop-types": "^15.6.2",
"react": "^16.6.3",
"react-art": "^16.6.3",
"react-dom": "^16.6.3",
"react-native-web": "^0.9.8",
"styled-components": "^4.1.2"
},
"devDependencies": {
"@babel/core": "^7.2.0",
"docz": "^0.12.14"
}
}
34 changes: 34 additions & 0 deletions examples/react-native/src/components/Alert.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React, { Fragment } from 'react'
import { Text as BaseText } from 'react-native'
import styled from 'styled-components/native'
import * as t from 'prop-types'

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

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

export const Text = styled(BaseText)`
color: white;
`

export const Alert = ({ kind = 'info', ...props }) => (
<AlertStyled {...props} kind={kind} />
)

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

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

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

# Alert

## Properties

<PropsTable of={Alert} />

## Basic usage

<Playground>
<Alert>
<Text>Hello world</Text>
</Alert>
</Playground>

## Using different kinds

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


## Use with children as a function

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

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

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

const kind = (bg, color) => `
background: ${bg};
border-color: red;
color: ${color};
transition: all .3s;
`

const kinds = {
primary: kind('#1FB6FF', 'white'),
secondary: kind('#5352ED', 'white'),
cancel: kind('#FF4949', 'white'),
dark: kind('#273444', 'white'),
gray: kind('#8492A6', 'white'),
}

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

const ButtonStyled = styled.TouchableOpacity`
${getKind};
${getScale};
cursor: pointer;
margin: 3px 5px;
border: 0;
border-radius: 3px;
`

const Text = styled.Text`
${getScale};
width: 100%;
padding: 0;
color: white;
text-align: center;
color: ${p => kinds[p.outline]};
`

export const Button = ({
scale = 'normal',
kind = 'primary',
outline = false,
children,
}) => (
<ButtonStyled scale={scale} kind={kind} outline={outline}>
<Text scale={scale}>{children}</Text>
</ButtonStyled>
)

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

Button.defaultProps = {
scales: 'normal',
kind: 'primary',
}
46 changes: 46 additions & 0 deletions examples/react-native/src/components/Button.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
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>
21 changes: 21 additions & 0 deletions examples/react-native/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.
2 changes: 1 addition & 1 deletion packages/docz-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"terser-webpack-plugin": "^1.1.0",
"titleize": "^1.0.1",
"url-loader": "^1.1.2",
"webpack": "^4.26.1",
"webpack": "^4.27.0",
"webpack-bundle-analyzer": "^3.0.3",
"webpack-chain": "^5.0.1",
"webpack-hot-client": "^4.1.1",
Expand Down
1 change: 1 addition & 0 deletions packages/docz-core/src/webpack/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export const createConfig = (args: Args, env: Env) => async (

config.resolve.alias.set('~db', paths.db)
config.resolve.alias.set('~imports', paths.importsJs)
config.resolve.alias.set('react-native$', 'react-native-web')

if (args.typescript) {
config.resolve.extensions
Expand Down
Loading

0 comments on commit f998874

Please sign in to comment.