Skip to content

Commit 64cc445

Browse files
Matthias Waglergoloroden
Matthias Wagler
authored andcommitted
feat: Introduce styleguide. (#185)
1 parent a9c44d4 commit 64cc445

File tree

226 files changed

+7680
-3691
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

226 files changed

+7680
-3691
lines changed

.eslintignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
styleguide/out
2+
styleguide/.next
3+
14
test/shared/sampleApplication/out
25
test/shared/sampleApplication/.next

.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.dependabot
22
.github
33
test/
4+
styleguide/

README.md

+11-35
Original file line numberDiff line numberDiff line change
@@ -11,59 +11,35 @@ thenativeweb-ux provides UI components for the native web applications.
1111
| Dev dependencies | ![David](https://img.shields.io/david/dev/thenativeweb/thenativeweb-ux) |
1212
| Build | ![GitHub Actions](https://github.com/thenativeweb/thenativeweb-ux/workflows/Release/badge.svg?branch=master) |
1313
| License | ![GitHub](https://img.shields.io/github/license/thenativeweb/thenativeweb-ux) |
14-
1514
## Installation
1615

1716
```shell
18-
$ npm install thenativeweb-ux
17+
$ npm install thenativeweb-ux react react-dom next
1918
```
2019

21-
## Quick start
22-
23-
First you need to add a reference to your application. For a minimum setup, you have to reference the components `Application` and `ThemeProvider`:
20+
## Viewing the documentation
2421

25-
```javascript
26-
import { Application, ThemeProvider } from 'thenativeweb-ux';
27-
```
22+
For application developers there is a [styleguide](styleguide) that serves as the documentation of this module. It contains a quick start, and showcases all the available components. To run it on your local machine clone this repository, install its dependencies, and run the following command:
2823

29-
Then, inside your application's `render` function, setup the basic structure by wrapping the `Application` component inside a `ThemeProvider`.:
30-
31-
```jsx
32-
<ThemeProvider>
33-
<Application>
34-
{
35-
// ...
36-
}
37-
</Application>
38-
</ThemeProvider>
24+
```shell
25+
$ npm run start-styleguide
3926
```
4027

41-
By default, the `ThemeProvider` will create a _the native web_ theme, but you can also select other themes. Currently, the following themes are available:
42-
43-
- `thenativeweb`
44-
- `wolkenkit`
45-
46-
### Using components
47-
48-
Besides setting up the application itself, you may also use a variety of components. To use a component, you need to add a reference to it. E.g., to use the `Button` component, add the following line to your code:
49-
50-
```javascript
51-
import { Button } from 'thenativeweb-ux';
52-
```
28+
Then point your browser to `http://localhost:6060/`.
5329

54-
### Viewing the Next.js sample application
30+
## Viewing the Next.js sample application
5531

56-
The integration tests include a [Next.js sample application](test/shared/sampleApplication) that shows how the various components can be used from within a Next.js project. To run the sample application use the following command:
32+
The integration tests include a [Next.js sample application](test/shared/sampleApplication) that shows how components can be used from within a Next.js project. To run the sample application use the following command:
5733

5834
```shell
5935
$ npm run start-sample-application
6036
```
6137

62-
### Debugging integration tests
38+
## Debugging integration tests
6339

6440
This project uses [puppeteer](https://github.com/GoogleChrome/puppeteer) to verify that components render correctly inside a browser. By default these tests are run in headless mode. As debugging integration tests in headless mode can be painful there are two options to debug integration tests visually.
6541

66-
#### Viewing failing test pages in a browser
42+
### Viewing failing test pages in a browser
6743

6844
First, to debug a failing integration test, you can have a look at the failing test page in a browser without running the tests. For that run the sample application using the following command:
6945

@@ -73,7 +49,7 @@ $ npm run start-sample-application
7349

7450
Then point your browser to the failing test page and verify if it renders correctly.
7551

76-
#### Running tests with a UI and in slow motion
52+
### Running tests with a UI and in slow motion
7753

7854
Second, verifying that all the puppeteer commands are executed succesfully, it is much easier to do when puppeteer is not running in headless mode. To disable headless mode, set the environment variable `DEBUG` to `true`. This will start puppeteer in non-headless mode and slow down each operation:
7955

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { ComponentPreview } from '../../../components/documentation/ComponentPreview';
2+
import { DropdownOption } from '../../input/Dropdown';
3+
import { TransitionType } from './TransitionType';
4+
import { types } from './types';
5+
import { CheckBox, ControlGroup, ControlGroupItem, Dropdown, Form, Headline, Paragraph, Transition } from '../../..';
6+
import React, { ReactElement, useState } from 'react';
7+
8+
const transitionTypes = Object.keys(types).map((type): DropdownOption => ({ label: type, value: type }));
9+
10+
const Documentation = (): ReactElement => {
11+
const [ isBoxVisible, setIsBoxVisible ] = useState(true);
12+
const [ type, setType ] = useState(transitionTypes[0].value);
13+
14+
return (
15+
<React.Fragment>
16+
<Headline>Transition</Headline>
17+
18+
<Paragraph>
19+
Transition is a component for animating a single element while it enters
20+
or leaves your application. There&apos;s a set of built-in types you can
21+
use: <code>Fade</code>, <code>FadeInLeft</code>, <code>FadeInRight</code>, <code>Grow</code> and <code>Zoom</code>.
22+
Wrap the component that should be animated and use the
23+
boolean <code>in</code> property to animate in and out. Please note that
24+
you might have to set explicit dimensions to the parent of the animated
25+
component in order to prevent a page jumps.
26+
</Paragraph>
27+
28+
<ComponentPreview>
29+
<React.Fragment>
30+
<Form>
31+
<ControlGroup>
32+
<ControlGroupItem label='Transition type'>
33+
<Dropdown
34+
value={ type }
35+
36+
options={ transitionTypes }
37+
onChange={ (value: string): void => setType(value) }
38+
/>
39+
</ControlGroupItem>
40+
</ControlGroup>
41+
<ControlGroup>
42+
<ControlGroupItem label='Show box'>
43+
<CheckBox onChange={ (): void => setIsBoxVisible(!isBoxVisible) } id='checkbox-is-box-visible' />
44+
</ControlGroupItem>
45+
</ControlGroup>
46+
</Form>
47+
48+
<div style={{ width: 200, height: 200 }}>
49+
<Transition type={ type as TransitionType } in={ isBoxVisible }>
50+
<div
51+
style={{
52+
width: 200,
53+
height: 200,
54+
background: 'deeppink'
55+
}}
56+
>
57+
This box will be animated using {type}.
58+
</div>
59+
</Transition>
60+
</div>
61+
</React.Fragment>
62+
</ComponentPreview>
63+
</React.Fragment>
64+
);
65+
};
66+
67+
export { Documentation };

lib/components/animation/Transition/README.md

-66
This file was deleted.

lib/components/animation/Transition/types/Fade.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const handleEnter = function (node: HTMLElement): void {
88
anime({
99
targets: node,
1010
opacity: [ 0, 1 ],
11-
duration: defaults.duration,
11+
duration: 600,
1212
easing: defaults.easing
1313
});
1414
};
@@ -17,7 +17,7 @@ const handleExit = function (node: HTMLElement): void {
1717
anime({
1818
targets: node,
1919
opacity: [ 1, 0 ],
20-
duration: defaults.duration,
20+
duration: 600,
2121
easing: defaults.easing
2222
});
2323
};
@@ -31,7 +31,7 @@ const Fade: FunctionComponent<TransitionProps> = ({ children, key, in: fadeIn })
3131
unmountOnExit={ true }
3232
onEnter={ handleEnter }
3333
onExit={ handleExit }
34-
timeout={ defaults.duration }
34+
timeout={ 600 }
3535
>
3636
{ children }
3737
</Transition>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { ComponentPreview } from '../../../components/documentation/ComponentPreview';
2+
import { Button, Headline, Paragraph, TransitionGroup } from '../../..';
3+
import React, { ReactElement, useState } from 'react';
4+
5+
const Documentation = (): ReactElement => {
6+
const [ items, setItems ] = useState([ 'Thing 1' ]);
7+
8+
const addItem = (): void => {
9+
const newItems = [ ...items, `Thing ${items.length + 1}` ];
10+
11+
setItems(newItems);
12+
};
13+
14+
const removeItem = (): void => {
15+
const newItems = items.slice(0, -1);
16+
17+
setItems(newItems);
18+
};
19+
20+
return (
21+
<React.Fragment>
22+
<Headline>TransitionGroup</Headline>
23+
24+
<Paragraph>
25+
To transition an array of elements, use
26+
the <code>TransitionGroup</code> component. Please note that you have to
27+
set a unique key for each item in order to let React know which element
28+
has been added or removed.
29+
</Paragraph>
30+
31+
<ComponentPreview>
32+
<React.Fragment>
33+
<div style={{ display: 'flex' }}>
34+
<Button onClick={ addItem }>Add item</Button>
35+
<Button onClick={ removeItem }>Remove item</Button>
36+
</div>
37+
<TransitionGroup type='FadeInRight'>
38+
{ items.map((item): ReactElement => (
39+
<div
40+
style={{
41+
width: 100,
42+
height: 100,
43+
float: 'left',
44+
background: 'deeppink',
45+
marginRight: 20,
46+
marginTop: 20
47+
}}
48+
key={ item }
49+
>
50+
{item}
51+
</div>
52+
)) }
53+
</TransitionGroup>
54+
</React.Fragment>
55+
</ComponentPreview>
56+
</React.Fragment>
57+
);
58+
};
59+
60+
export { Documentation };

0 commit comments

Comments
 (0)