Skip to content

Commit 7bff4a5

Browse files
committed
docs: add <Audio> reference
1 parent c932f97 commit 7bff4a5

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const MyComponent = mock();
4040
- [`<Speak>`](./docs/Speak.md)
4141
- [`<Vibrate>`](./docs/Vibrate.md)
4242
- [`<LocalStorage>`](./docs/LocalStorage.md)
43+
- [`<Audio>`](./docs/Audio.md)
4344
- Context
4445
- [`<Provider>`](./docs/context.md#provider), [`<Consumer>`](./docs/context.md#consumer), and [`withContext()`](./docs/context.md#withcontext)
4546
- [`<Theme>`](./docs/theme.md#theme), [`<Themed>`](./docs/theme.md#themed), and [`withTheme()`](./docs/theme.md#withtheme)

docs/Audio.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# `<Audio>`
2+
3+
FaCC that creates an `<audio>` element to play audio tracks, re-renders on audio state changes.
4+
5+
## Usage
6+
7+
```jsx
8+
import {Audio} from 'mol-fe-react/lib/Audio';
9+
10+
<Audio autoplay src='https://www.soundhelix.com/examples/mp3/SoundHelix-Song-2.mp3'>{(control, state) => {
11+
JSON.stringify(state, null, 4)
12+
}}</Audio>
13+
```
14+
15+
## Props
16+
17+
In addition to props below also accepts all [React's media events](https://reactjs.org/docs/events.html#media-events).
18+
19+
```tsx
20+
export interface IAudioProps {
21+
src: string;
22+
autoplay?: boolean;
23+
loop?: boolean;
24+
muted?: boolean;
25+
preload?: 'none' | 'metadata' | 'auto';
26+
volume?: number;
27+
noJs?: React.ReactElement<any>;
28+
}
29+
```
30+
31+
- `src` - required, string, audio source file URL.
32+
- `autoplay` - optional, boolean, whether to autoplay audio, defaults to `false`.
33+
- `loop` - optional, boolean, whether to repeat the track when it ends, defaults to `false`.
34+
- `muted` - optional, boolean, whether to mute the audio, defaults to `false`.
35+
- `preload` - optional, string, `<audio>` element preload attribute.
36+
- `volume` - optional, number, audio volume in `[0..1]` range, defaults to `1`.
37+
- `noJs` - optional, React element(s) to render insided the `<audio>` tag.
38+
39+
## Example
40+
41+
Play a sample audio track with control buttons.
42+
43+
```jsx
44+
<Audio src='https://www.soundhelix.com/examples/mp3/SoundHelix-Song-2.mp3'>{(audio, state) =>
45+
<div>
46+
<button onClick={audio.play}>Play</button>
47+
<button onClick={audio.pause}>Pause</button>
48+
<button onClick={() => audio.seek(state.time - 5)}>Seek -</button>
49+
<button onClick={() => audio.seek(state.time + 5)}>Seek +</button>
50+
<button onClick={() => audio.volume(state.volume - 0.05)}>Volume -</button>
51+
<button onClick={() => audio.volume(state.volume + 0.05)}>Volume +</button>
52+
<button onClick={audio.mute}>Mute</button>
53+
<button onClick={audio.unmute}>Unmute</button>
54+
</div>
55+
}</Audio>
56+
```

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export * from './LightSensor';
1818
// Generators
1919
export * from './Speak';
2020
export * from './Vibrate';
21+
export * from './LocalStorage';
22+
export * from './Audio';
2123

2224
// Context
2325
export * from './context';

0 commit comments

Comments
 (0)