Skip to content

Commit fd77e5d

Browse files
authored
Merge pull request #6 from MailOnline/feat/location
Feat/location
2 parents 60f0c86 + 5d66625 commit fd77e5d

25 files changed

+1034
-50
lines changed

.npmrc

Lines changed: 0 additions & 8 deletions
This file was deleted.

README.md

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
# mol-fe-react
1+
# libreact
22

3-
React utility belt.
3+
React standard library, must-have toolbox for any React project.
44

5-
- Collection of React goodies
6-
- Isomorphic - all components work in browser and Node
7-
- [See demos and docs](https://mailonline.github.io/mol-fe-react/)
5+
- Collection of React sensors, FaCCs, HOCs, context, lazy loading, and [other goodies](#contents).
6+
- Isomorphic - all components work in browser and Node.js (and some in `react-native`).
7+
- [See demos and docs](https://mailonline.github.io/libreact/).
88

99
## Installation
1010

1111
```shell
12-
npm install mol-fe-react --save
12+
npm install libreact --save
1313
```
1414

1515
## Usage
1616

1717
Import each utility individually to decrease your bundle size
1818

1919
```js
20-
import {mock} from 'mol-fe-react/lib/mock';
20+
import {mock} from 'libreact/lib/mock';
2121

2222
const MyComponent = mock();
2323
```
2424

25-
## Reference
25+
## Contents
2626

2727
- Dummies
2828
- [`mock()`](./docs/mock.md)
@@ -31,25 +31,30 @@ const MyComponent = mock();
3131
- [`delayed()`](./docs/delayed.md)
3232
- [`invert()`](./docs/invert.md)
3333
- Sensors
34-
- [`<SizeSensor>`](./docs/SizeSensor.md)
35-
- [`<WidthSensor>`](./docs/WidthSensor.md)
36-
- [`<ScrollSensor>`](./docs/ScrollSensor.md)
34+
- [`<BatterySensor>`](./docs/BatterySensor.md)
35+
- [`<MediaDeviceSensor>`](./docs/MediaDeviceSensor.md)
3736
- [`<MediaSensor>`](./docs/MediaSensor.md)
38-
- [`<WindowSizeSensor>`](./docs/WindowSizeSensor.md)
39-
- [`<WindowScrollSensor>`](./docs/WindowScrollSensor.md)
4037
- [`<NetworkSensor>`](./docs/NetworkSensor.md) and [`withNetwork()`](./docs/NetworkSensor.md#withnetwork)
41-
- [`<BatterySensor>`](./docs/BatterySensor.md)
4238
- [`<LightSensor>`](./docs/LightSensor.md)
43-
- [`<MediaDeviceSensor>`](./docs/MediaDeviceSensor.md)
39+
- [`<LocationSensor>`](./docs/LocationSensor.md)
40+
- [`<ScrollSensor>`](./docs/ScrollSensor.md)
41+
- [`<SizeSensor>`](./docs/SizeSensor.md)
42+
- `<ViewportSensor>`
43+
- [`<WidthSensor>`](./docs/WidthSensor.md)
44+
- [`<WindowScrollSensor>`](./docs/WindowScrollSensor.md)
45+
- [`<WindowSizeSensor>`](./docs/WindowSizeSensor.md)
4446
- Generators
47+
- [`<Audio>`](./docs/Audio.md)
48+
- [`<LocalStorage>`](./docs/LocalStorage.md)
49+
- `<Redirect>`
4550
- [`<Speak>`](./docs/Speak.md)
4651
- [`<Vibrate>`](./docs/Vibrate.md)
47-
- [`<LocalStorage>`](./docs/LocalStorage.md)
48-
- [`<Audio>`](./docs/Audio.md)
52+
- `<Video>`
4953
- Context
5054
- [`<Provider>`](./docs/context.md#provider), [`<Consumer>`](./docs/context.md#consumer), and [`withContext()`](./docs/context.md#withcontext)
5155
- [`<Theme>`](./docs/theme.md#theme), [`<Themed>`](./docs/theme.md#themed), and [`withTheme()`](./docs/theme.md#withtheme)
5256
- `<CssVars>`
57+
- [`<Router>`](./docs/route.md#router), [`<Route>`](./docs/route.md#route), [`go()`](./docs/route.md#go), and [`withRoute()`](./docs/route.md#withroute)
5358
- CSS resets
5459
- [`<CssResetEricMeyer>`](./docs/reset/CssResetEricMeyer.md)
5560
- [`<CssResetEricMeyerCondensed>`](./docs/reset/CssResetEricMeyerCondensed.md)

docs/Audio.md

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@ FaCC that creates an `<audio>` element to play audio tracks, re-renders on audio
55
## Usage
66

77
```jsx
8-
import {Audio} from 'mol-fe-react/lib/Audio';
8+
import {Audio} from 'libreact/lib/Audio';
99

1010
<Audio autoPlay src='https://www.soundhelix.com/examples/mp3/SoundHelix-Song-2.mp3'>{(control, state) => {
1111
JSON.stringify(state, null, 4)
1212
}}</Audio>
1313
```
1414

15+
1516
## Props
1617

1718
In addition to props below also accepts all [React's media events](https://reactjs.org/docs/events.html#media-events).
1819

1920
```tsx
20-
export interface IAudioProps {
21+
interface IAudioProps {
2122
src: string;
2223
autoPlay?: boolean;
2324
loop?: boolean;
@@ -36,6 +37,56 @@ export interface IAudioProps {
3637
- `volume` - optional, number, audio volume in `[0..1]` range, defaults to `1`.
3738
- `noJs` - optional, React element(s) to render insided the `<audio>` tag.
3839

40+
41+
## Arguments
42+
43+
The `children` function receives two arguments, `audio` instance as *controller* and `state`.
44+
45+
```jsx
46+
<Audio autoPlay src={src}>{(audio, state) =>
47+
48+
}</Audio>
49+
```
50+
51+
First argument is the `<Audio>` component instance with the following public signature.
52+
53+
```ts
54+
interface IAudio {
55+
el: HTMLAudioElement;
56+
play();
57+
pause();
58+
seek(time: number);
59+
volume(value: number);
60+
mute();
61+
unmute();
62+
}
63+
```
64+
65+
, where
66+
67+
- `el` - `<audio>` element DOM node.
68+
69+
The second argument is the state of the `<Audio>` component with the following signature.
70+
71+
```ts
72+
interface IAudioState {
73+
time?: number;
74+
duration?: number;
75+
isPlaying?: boolean;
76+
muted?: boolean;
77+
volume?: number;
78+
}
79+
```
80+
81+
, where
82+
83+
- `time` - current time in seconds.
84+
- `duration` - total audio track duration in seconds.
85+
- `isPlaying` - whether the audio track is currently playing.
86+
- `muted` - whether `muted` attribute is set on the audio element.
87+
- `volume` - current volume in range `[0..1]`.
88+
89+
3990
## Example
4091

4192
Play a sample audio track with control buttons.

docs/LocationSensor.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# `<LocationSensor>`
2+
3+
FaCC that uses [`Window.location`](https://developer.mozilla.org/en-US/docs/Web/API/Window/location) and
4+
[`Window.history`](https://developer.mozilla.org/en-US/docs/Web/API/Window/history) APIs to track
5+
page location and re-render on any changes.
6+
7+
## Usage
8+
9+
```jsx
10+
import {LocationSensor} from 'libreact/lib/LocationSensor';
11+
12+
<LocationSensor>{(location) =>
13+
<pre style={{fontFamily: 'monospace'}}>
14+
{JSON.stringify(location, null, 4)}
15+
</pre>
16+
}</LocationSensor>
17+
```
18+
19+
## Props
20+
21+
None.
22+
23+
## Reference
24+
25+
Returns location state object with the following signature
26+
27+
```ts
28+
interface ILocationSensorState {
29+
trigger: string;
30+
state?: any;
31+
length?: number;
32+
hash?: string;
33+
host?: string;
34+
hostname?: string;
35+
href?: string;
36+
origin?: string;
37+
pathname?: string;
38+
port?: string;
39+
protocol?: string;
40+
search?: string;
41+
}
42+
```

docs/NetworkSensor.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ FaCC that re-renders on network status change. Uses `navigator.onLine` and [`Net
55

66
## `<NetworkSensor>`
77

8-
FaCC that passes through its state to child function
8+
Passes through its state to the `children` function
99

1010
```ts
1111
interface INetworkSensorState {
@@ -28,8 +28,8 @@ None.
2828
```jsx
2929
import {NetworkSensor} from 'mol-fe-react/lib/NetworkSensor';
3030

31-
<NetworkSensor>{(status) =>
32-
JSON.strinfigy(status, null 4)
31+
<NetworkSensor>{(state) =>
32+
JSON.strinfigy(state, null 4)
3333
}</NetworkSensor>
3434
```
3535

@@ -52,7 +52,7 @@ Result
5252
- `downlink`, `downlinkMax`, `effectiveType`, `type`, `rtt` - properties as provided by [`NetworkInformation`](https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation).
5353

5454

55-
## `withNetwork`
55+
## `withNetwork()`
5656

5757
HOC that merges `<NetworkSensor>` state into props of the enhanced component.
5858

@@ -61,9 +61,13 @@ HOC that merges `<NetworkSensor>` state into props of the enhanced component.
6161
```jsx
6262
import {withNetwork} from 'mol-fe-react/lib/NetworkSensro';
6363

64-
const NetworkStatus = withNetwork((props) =>
64+
const NetworkStatusFormatter = (props) =>
6565
<pre style={{fontFamily: 'monospace'}}>
6666
{JSON.stringify(props, null, 4)}
67-
</pre>
67+
</pre>;
68+
69+
const NetworkStatus = withNetwork(NetworkStatusFormatter);
70+
71+
<NetworkStatus />
6872
);
6973
```

docs/mock.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Create a mock React component whose implementation can be postponed.
88
Create a mock and implement it
99

1010
```js
11+
import {mock} from 'libreact/lib/mock';
12+
1113
const Player = mock();
1214

1315
// Now you can already use <Player>.
@@ -28,17 +30,16 @@ const MySvg = mock({
2830
## Reference
2931

3032
```ts
31-
const mock: <TProps>(params?: ImockParams) => IMockConstructor<TProps>;
33+
mock: (params?: IMockParams) => IMockComponent;
3234

33-
interface ImockParams {
34-
loading?: React.ReactElement<any>;
35+
interface IMockParams {
36+
loading?: React.ReactElement;
3537
}
3638

37-
interface IMockComponent<TProps> {
38-
new (props: TProps, context): IMock<TProps>;
39-
implement(Implementation: React.Component<TProps, any> | React.SFC<TProps>);
39+
interface IMockComponent {
40+
implement(Implementation: React.Component | React.SFC);
4041
}
4142
```
4243

43-
- `loading` - React element to show while the is not implemented.
44+
- `loading` - React element to show while the mock is not implemented.
4445
- `.implement` - use this method to set the implementation of your mock coponent.

0 commit comments

Comments
 (0)