Skip to content

Commit

Permalink
Merge pull request #760 from neontribe/styleguide
Browse files Browse the repository at this point in the history
feat: add styleguide
  • Loading branch information
falconx authored Jun 8, 2020
2 parents 8df1774 + 4232cf7 commit da4908d
Show file tree
Hide file tree
Showing 42 changed files with 2,263 additions and 1,039 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"build:testable": "CI= REACT_APP_MOCKS=true yarn build",
"migrate": "migrate-mongo up",
"generate": "node -r dotenv/config ./src/api/db/manage/generate/index.js --confirm",
"areas": "node -r dotenv/config ./src/api/db/manage/areaToDatabase/index.js"
"areas": "node -r dotenv/config ./src/api/db/manage/areaToDatabase/index.js",
"styleguide": "styleguidist server"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -108,6 +109,7 @@
"puppeteer": "3.3.0",
"react-app-rewired": "2.1.6",
"react-scripts": "3.4.1",
"react-styleguidist": "11.0.8",
"serve": "11.3.1",
"source-map-explorer": "2.4.2",
"stylelint": "13.6.0",
Expand Down
1 change: 1 addition & 0 deletions src/components/Box.js → src/components/Box/Box.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ Box.propTypes = {
...createPropTypes(border.propNames),
};

/** @component */
export default Box;
19 changes: 19 additions & 0 deletions src/components/Box/Box.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Implements

* [space](https://styled-system.com/api#space)
* [color](https://styled-system.com/api#color)
* [layout](https://styled-system.com/api#layout)
* [flexbox](https://styled-system.com/api#flexbox)
* [position](https://styled-system.com/api#position)
* [border](https://styled-system.com/api#border)

### Usage

```jsx
<Box
width={[1, 1 / 2]}
p={3}
borderWidth={2}
borderStyle="solid"
>Content here!</Box>
```
3 changes: 3 additions & 0 deletions src/components/Box/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Box from './Box';

export default Box;
5 changes: 3 additions & 2 deletions src/components/Button.js → src/components/Button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React from 'react';
import styled from '@emotion/styled';
import { variant } from 'styled-system';

import Box from './Box';
import Text from './Text';
import Box from '../Box';
import Text from '../Text';

const BUTTON_HEIGHT = 34;

Expand Down Expand Up @@ -88,4 +88,5 @@ Button.defaultProps = {
as: 'button',
};

/** @component */
export default Button;
19 changes: 19 additions & 0 deletions src/components/Button/Button.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Primary

```jsx
<Button>Click me!</Button>
```

### Seconary

```jsx
<Button variant="secondary">Click me!</Button>
```

### Link

The most common use can would be combine the `link` variant with `as="a"` to render the component as an anchor element.

```jsx
<Button as="a" href="" variant="link">Click me!</Button>
```
3 changes: 3 additions & 0 deletions src/components/Button/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Button from './Button';

export default Button;
17 changes: 17 additions & 0 deletions src/components/ConditionalWrap/ConditionalWrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import PropTypes from 'prop-types';

/** @visibleName Conditional Wrap */
const ConditionalWrap = ({ condition, children, wrap }) =>
condition ? React.cloneElement(wrap(children)) : children;

ConditionalWrap.propTypes = {
/** The condition to pass for `children` to be wrappe */
condition: PropTypes.bool.isRequired,
/** ender prop with `children` as the only argument. Invoked when the `condition` is true */
wrap: PropTypes.func.isRequired,
children: PropTypes.node.isRequired,
};

/** @component */
export default ConditionalWrap;
15 changes: 15 additions & 0 deletions src/components/ConditionalWrap/ConditionalWrap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
An abstraction which makes it simple to conditionally wrap content, whilst avoiding a duplicated definition of the content.

### Usage

In this scenario the content would be wrapped inside a modal, but only for mobile devices.

```jsx static
<ConditionalWrap
condition={isMobile}
wrap={children => <Modal>{children}</Modal>}
children={
<p>Content here!</p>
}
/>
```
3 changes: 3 additions & 0 deletions src/components/ConditionalWrap/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import ConditionalWrap from './ConditionalWrap';

export default ConditionalWrap;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import Box from './Box';
import Box from '../Box';

const Divider = (props) => (
<Box
Expand All @@ -15,4 +15,5 @@ const Divider = (props) => (
/>
);

/** @component */
export default Divider;
3 changes: 3 additions & 0 deletions src/components/Divider/Divider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```jsx
<Divider />
```
3 changes: 3 additions & 0 deletions src/components/Divider/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Divider from './Divider';

export default Divider;
7 changes: 5 additions & 2 deletions src/components/Drawer.js → src/components/Drawer/Drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React from 'react';
import PropTypes from 'prop-types';
import { motion } from 'framer-motion';

import Box from './Box';
import Portal from './Portal';
import Box from '../Box';
import Portal from '../Portal';

const MENU_HEIGHT = 60; // px

Expand Down Expand Up @@ -54,12 +54,15 @@ const Drawer = ({ visible, animateFrom, ...props }) => {
};

Drawer.propTypes = {
/** Determines whether the drawer is on screen */
visible: PropTypes.bool,
/** Direction to animate from */
animateFrom: PropTypes.oneOf(['left', 'right']),
};

Drawer.defaultProps = {
animateFrom: 'right',
};

/** @component */
export default Drawer;
20 changes: 20 additions & 0 deletions src/components/Drawer/Drawer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
```jsx
import Button from '../Button';
import Spacer from '../Spacer';

const [isVisible, setIsVisible] = React.useState(false);

<>
<Button onClick={() => setIsVisible(true)}>Open drawer</Button>
<Drawer
visible={isVisible}
animateFrom="right"
>
<p>Drawer content here!</p>

<Spacer mt={3} />

<Button onClick={() => setIsVisible(false)}>Close drawer</Button>
</Drawer>
</>
```
3 changes: 3 additions & 0 deletions src/components/Drawer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Drawer from './Drawer';

export default Drawer;
5 changes: 4 additions & 1 deletion src/components/Icon.js → src/components/Icon/Icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import styled from '@emotion/styled';
import { color } from 'styled-system';
import { createPropTypes } from '@styled-system/prop-types';

const Icon = styled(FontAwesomeIcon)(color);
const Icon = styled(FontAwesomeIcon)`
${color}
`;

Icon.propTypes = {
...createPropTypes(color.propNames),
};

/** @component */
export default Icon;
7 changes: 7 additions & 0 deletions src/components/Icon/Icon.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Implements [FontAwesomeIcon](https://github.com/FortAwesome/react-fontawesome).

```jsx
import { faBars } from '@fortawesome/free-solid-svg-icons';

<Icon icon={faBars} size="2x" />
```
3 changes: 3 additions & 0 deletions src/components/Icon/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Icon from './Icon';

export default Icon;
11 changes: 0 additions & 11 deletions src/components/Loading.js

This file was deleted.

3 changes: 3 additions & 0 deletions src/components/Logo/Logo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```jsx
<Logo />
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { faTimes } from '@fortawesome/free-solid-svg-icons';

import Box from './Box';
import Text from './Text';
import Icon from './Icon';
import Spacer from './Spacer';
import Box from '../Box';
import Text from '../Text';
import Icon from '../Icon';
import Spacer from '../Spacer';

const Notification = ({ allowClose, children }) => {
const [isVisible, setIsVisible] = useState(true);
Expand Down Expand Up @@ -47,7 +47,11 @@ const Notification = ({ allowClose, children }) => {
};

Notification.propTypes = {
/** Allow the notification to be closed */
allowClose: PropTypes.bool,
/** The notification message */
children: PropTypes.node,
};

/** @component */
export default Notification;
13 changes: 13 additions & 0 deletions src/components/Notification/Notification.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
```jsx
<Notification>
Please wait whilst we fetch some data&hellip;
</Notification>
```

### Allow close

```jsx
<Notification allowClose>
Please wait whilst we fetch some data&hellip;
</Notification>
```
3 changes: 3 additions & 0 deletions src/components/Notification/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Notification from './Notification';

export default Notification;
Loading

1 comment on commit da4908d

@vercel
Copy link

@vercel vercel bot commented on da4908d Jun 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.