Skip to content

Commit

Permalink
add storybook docs addon; some minor updates and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lhz516 committed Jan 4, 2020
1 parent a444f4b commit 5721c86
Show file tree
Hide file tree
Showing 15 changed files with 918 additions and 390 deletions.
1 change: 1 addition & 0 deletions .storybook/addons.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
import '@storybook/addon-actions/register'
import '@storybook/addon-docs/register'
26 changes: 14 additions & 12 deletions .storybook/config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { configure, addDecorator } from '@storybook/react'
import { configureActions } from '@storybook/addon-actions';
import { withInfo } from '@storybook/addon-info'
import { configure, addParameters } from '@storybook/react'
import { DocsPage, DocsContainer } from '@storybook/addon-docs/blocks'

// Docs: https://github.com/storybooks/storybook/tree/master/addons/info
addDecorator(
withInfo({
header: true,
}),
)
function requireAll(requireContext) {
console.log(requireContext)
return requireContext.keys().map(requireContext);
}

configure(() => {
require('../stories/index')
}, module)
configure(require.context('../stories', true, /\.stories\.(js|mdx)$/), module)

addParameters({
docs: {
container: DocsContainer,
page: DocsPage,
},
})
17 changes: 17 additions & 0 deletions .storybook/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const path = require('path')
const createCompiler = require('@storybook/addon-docs/mdx-compiler-plugin')

// Storybook Webpack config doc: https://storybook.js.org/docs/configurations/custom-webpack-config/
module.exports = async ({ config }) => {
Expand Down Expand Up @@ -26,7 +27,23 @@ module.exports = async ({ config }) => {
}
})

config.module.rules.push({
test: /\.mdx$/,
use: [
{
loader: 'babel-loader',
},
{
loader: '@mdx-js/loader',
options: {
compilers: [createCompiler({})],
},
},
],
});

config.resolve.extensions.push('.tsx')
config.resolve.extensions.push('.mdx')

return config
}
36 changes: 23 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

![screenshot](./screenshot.png)

Live Demo: [Storybook](https://static.hanzluo.com/react-h5-audio-player-storybook/index.html)
Live Demo: [Storybook](https://static.hanzluo.com/react-h5-audio-player-storybook/index.html?path=/docs/layouts--default-story)

Supported browsers: Chrome, Firefox, Safari, Opera, Edge, IE (≥10)

Expand All @@ -24,6 +24,8 @@ Or
```jsx
import AudioPlayer from 'react-h5-audio-player';
import 'react-h5-audio-player/lib/styles.css';
// import 'react-h5-audio-player/lib/styles.less' Use LESS
// import 'react-h5-audio-player/src/styles.scss' Use SASS

const Player = () => (
<AudioPlayer
Expand All @@ -39,18 +41,23 @@ const Player = () => (

### HTML Audio Tag Native Attributes

| Props | Type | Default |
| -------- | :-----: | :-----: |
| src | String | '' |
| preload | String | 'auto' |
| autoPlay | Boolean | false |
| loop | Boolean | false |
| muted | Boolean | false |
| loop | Boolean | false |
| volume | Number | 1.0 |
| Props | Type | Default | Note |
| ----------- | :-----: | :-------: | :-------------------:|
| src | String | '' | |
| preload | String | 'auto' | |
| autoPlay | Boolean | false | Won't work on mobile |
| loop | Boolean | false | |
| muted | Boolean | false | |
| loop | Boolean | false | |
| volume | Number | 1.0 | Won't work on mobile |
| crossOrigin | String | undefined | |
| mediaGroup | String | undefined | |


More native attributes detail: [MDN Audio element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio)

The `controls` attribute defaults to `false` and should never be changed to `true` because this library is already providing UI.

### Other Props

#### showVolumeControl {Boolean} [true]
Expand Down Expand Up @@ -127,14 +134,17 @@ Called when the user taps play.

## UI Overwrites

React H5 Audio Player provides built-in class names and SASS variables for developers to overwrite.
React H5 Audio Player provides built-in class names and SASS/LESS variables for developers to overwrite.

### SASS variables

- $rhap_theme-color: #868686 !default;
- $rhap_background-color: #fff !default;
- $rhap_bar-color: #e4e4e4 !default;
- $rhap_time-color: #000 !default;
- $rhap_time-color: #333 !default;
- $rhap_font-family: inherit !default;

For LESS variables, just replace `$` with `@`.

## Advanced Usage

Expand All @@ -143,7 +153,7 @@ React H5 Audio Player provides built-in class names and SASS variables for devel
You can get direct access to the underlying audio element. First get a ref to ReactAudioPlayer:

```jsx
<ReactAudioPlayer ref={c => (this.player = c)} />
<ReactAudioPlayer ref={c => (this.player = c)} /> // Use `createRef` also works
```

Then you can access the audio element like this:
Expand Down
Loading

0 comments on commit 5721c86

Please sign in to comment.