Skip to content

Commit c85ee18

Browse files
committed
storybook 7
1 parent 13963e9 commit c85ee18

14 files changed

+4966
-4316
lines changed

.storybook/main.js

Lines changed: 26 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,37 @@
1-
const createCompiler = require('@storybook/addon-docs/mdx-compiler-plugin');
2-
const path = require('path')
1+
import path from 'path';
32

4-
module.exports = {
5-
stories: ['../stories/**/*.stories.mdx', '../stories/**/*.stories.js'],
3+
export default {
4+
stories: [
5+
'../stories/**/*.mdx',
6+
'../stories/**/*.stories.@(ts|tsx)',
7+
],
68

7-
addons: ['@storybook/addon-docs/register', '@storybook/addon-actions/register'],
9+
addons: [
10+
'@storybook/addon-docs',
11+
'@storybook/addon-actions',
12+
'@storybook/addon-mdx-gfm'
13+
],
814

9-
webpackFinal: async config => {
15+
framework: {
16+
name: '@storybook/react-webpack5',
17+
options: {}
18+
},
19+
20+
docs: {
21+
autodocs: true
22+
},
23+
24+
webpackFinal: async (config) => {
1025
config.module.rules.push({
1126
test: /\.scss$/,
12-
use: ['style-loader', 'css-loader', 'sass-loader'],
13-
include: path.resolve(__dirname, '../src'),
14-
})
15-
16-
config.module.rules.push({
17-
test: /\.tsx?$/,
18-
use: {
19-
loader: 'babel-loader',
20-
options: {
21-
presets: [
22-
'@babel/preset-env',
23-
'@babel/preset-react',
24-
['@babel/preset-typescript', {
25-
isTSX: true,
26-
allExtensions: true
27-
}]
28-
],
29-
plugins: ['@babel/plugin-proposal-class-properties']
30-
}
31-
}
32-
})
33-
34-
config.module.rules.push({
35-
test: /\.mdx$/,
3627
use: [
37-
{
38-
loader: 'babel-loader',
39-
},
40-
{
41-
loader: '@mdx-js/loader',
42-
options: {
43-
compilers: [createCompiler({})],
44-
},
45-
},
28+
'style-loader',
29+
'css-loader',
30+
'sass-loader'
4631
],
32+
include: path.resolve(__dirname, '../'),
4733
});
48-
49-
config.module.rules.push({
50-
test: /\.[tj]sx$/,
51-
loader: require.resolve('@storybook/source-loader'),
52-
exclude: [/node_modules/],
53-
enforce: 'pre',
54-
})
5534

56-
config.resolve.extensions.push('.tsx')
57-
config.resolve.extensions.push('.ts')
58-
59-
return config
35+
return config;
6036
},
6137
};

.storybook/preview.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { addParameters } from '@storybook/react'
2-
import { DocsPage, DocsContainer } from '@storybook/addon-docs/blocks'
1+
import { DocsPage, DocsContainer } from '@storybook/blocks'
2+
import '../src/styles.scss'
33

4-
addParameters({
4+
export const parameters = {
55
docs: {
66
container: DocsContainer,
77
page: DocsPage,
88
},
9-
})
9+
}

package.json

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
"lint": "eslint src --fix --ext .ts,.tsx",
1717
"test": "jest --env=jsdom",
1818
"cov": "jest --env=jsdom --coverage",
19-
"storybook": "NODE_OPTIONS=--openssl-legacy-provider start-storybook -p 9000",
20-
"build:storybook": "NODE_OPTIONS=--openssl-legacy-provider build-storybook -c .storybook -o docs",
19+
"storybook": "sb dev -p 9000",
20+
"build:storybook": "sb build -c .storybook -o docs",
2121
"prepare": "husky install"
2222
},
2323
"lint-staged": {
@@ -61,7 +61,7 @@
6161
},
6262
"dependencies": {
6363
"@babel/runtime": "^7.10.2",
64-
"@iconify/react": "^4.1.1"
64+
"@iconify/react": "^5"
6565
},
6666
"devDependencies": {
6767
"@babel/cli": "^7.10.1",
@@ -72,9 +72,13 @@
7272
"@babel/preset-react": "^7.10.1",
7373
"@babel/preset-typescript": "^7.10.1",
7474
"@cfaester/enzyme-adapter-react-18": "^0.8.0",
75-
"@storybook/addon-actions": "^6.1.14",
76-
"@storybook/addon-docs": "^6.1.14",
77-
"@storybook/react": "^6.1.14",
75+
"@storybook/addon-actions": "7.6.20",
76+
"@storybook/addon-docs": "7.6.20",
77+
"@storybook/addon-mdx-gfm": "7.6.20",
78+
"@storybook/blocks": "^7",
79+
"@storybook/cli": "^7",
80+
"@storybook/react": "7.6.20",
81+
"@storybook/react-webpack5": "7.6.20",
7882
"@types/events": "^3.0.0",
7983
"@types/react": "^19",
8084
"@typescript-eslint/eslint-plugin": "^4.20.0",
@@ -93,14 +97,14 @@
9397
"jest-environment-jsdom": "^29.7.0",
9498
"less-plugin-sass2less": "^1.2.0",
9599
"lint-staged": "^10.2.10",
96-
"node-sass": "^7.0.1",
97100
"npm-run-all": "^4.1.5",
98101
"prettier": "^2.0.5",
99102
"react": "^18",
100103
"react-dom": "^18",
101104
"sass": "^1.26.8",
102105
"sass-loader": "^10.2.0",
103106
"static-server": "^2.2.1",
107+
"style-loader": "^4.0.0",
104108
"typescript": "^4.2.3",
105109
"webpack": "^4.43.0",
106110
"webpack-cli": "^3.3.11"

src/index.tsx

Lines changed: 41 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -142,49 +142,20 @@ interface I18nAriaLabels {
142142
}
143143

144144
class H5AudioPlayer extends Component<PlayerProps> {
145-
static defaultProps: PlayerProps = {
146-
autoPlay: false,
147-
autoPlayAfterSrcChange: true,
148-
listenInterval: 1000,
149-
progressJumpStep: 5000,
150-
progressJumpSteps: {}, // define when removing progressJumpStep
151-
volumeJumpStep: 0.1,
152-
loop: false,
153-
muted: false,
154-
preload: 'auto',
155-
progressUpdateInterval: 20,
156-
defaultCurrentTime: '--:--',
157-
defaultDuration: '--:--',
158-
timeFormat: 'auto',
159-
volume: 1,
160-
className: '',
161-
showJumpControls: true,
162-
showSkipControls: false,
163-
showDownloadProgress: true,
164-
showFilledProgress: true,
165-
showFilledVolume: false,
166-
customIcons: {},
167-
customProgressBarSection: [RHAP_UI.CURRENT_TIME, RHAP_UI.PROGRESS_BAR, RHAP_UI.DURATION],
168-
customControlsSection: [RHAP_UI.ADDITIONAL_CONTROLS, RHAP_UI.MAIN_CONTROLS, RHAP_UI.VOLUME_CONTROLS],
169-
customAdditionalControls: [RHAP_UI.LOOP],
170-
customVolumeControls: [RHAP_UI.VOLUME],
171-
layout: 'stacked',
172-
hasDefaultKeyBindings: true,
173-
i18nAriaLabels: {
174-
player: 'Audio player',
175-
progressControl: 'Audio progress control',
176-
volumeControl: 'Volume control',
177-
play: 'Play',
178-
pause: 'Pause',
179-
rewind: 'Rewind',
180-
forward: 'Forward',
181-
previous: 'Previous',
182-
next: 'Skip',
183-
loop: 'Disable loop',
184-
loopOff: 'Enable loop',
185-
volume: 'Mute',
186-
volumeMute: 'Unmute',
187-
},
145+
static defaultI18nAriaLabels: I18nAriaLabels = {
146+
player: 'Audio player',
147+
progressControl: 'Audio progress control',
148+
volumeControl: 'Volume control',
149+
play: 'Play',
150+
pause: 'Pause',
151+
rewind: 'Rewind',
152+
forward: 'Forward',
153+
previous: 'Previous',
154+
next: 'Skip',
155+
loop: 'Disable loop',
156+
loopOff: 'Enable loop',
157+
volume: 'Mute',
158+
volumeMute: 'Unmute',
188159
}
189160

190161
audio = createRef<HTMLAudioElement>()
@@ -193,7 +164,7 @@ class H5AudioPlayer extends Component<PlayerProps> {
193164

194165
container = createRef<HTMLDivElement>()
195166

196-
lastVolume: number = this.props.volume // To store the volume before clicking mute button
167+
lastVolume: number = this.props.volume ?? 1 // To store the volume before clicking mute button
197168

198169
listenTracker?: number // Determine whether onListen event should be called continuously
199170

@@ -328,7 +299,7 @@ class H5AudioPlayer extends Component<PlayerProps> {
328299
}
329300

330301
handleKeyDown = (e: React.KeyboardEvent): void => {
331-
if (this.props.hasDefaultKeyBindings) {
302+
if (this.props.hasDefaultKeyBindings ?? true) {
332303
switch (e.key) {
333304
case ' ':
334305
if (e.target === this.container.current || e.target === this.progressBar.current) {
@@ -366,26 +337,26 @@ class H5AudioPlayer extends Component<PlayerProps> {
366337

367338
renderUIModule = (comp: CustomUIModule, key: Key): ReactElement => {
368339
const {
369-
defaultCurrentTime,
370-
progressUpdateInterval,
371-
showDownloadProgress,
372-
showFilledProgress,
373-
showFilledVolume,
374-
defaultDuration,
375-
customIcons,
376-
showSkipControls,
340+
defaultCurrentTime = '--:--',
341+
progressUpdateInterval = 20,
342+
showDownloadProgress = true,
343+
showFilledProgress = true,
344+
showFilledVolume = false,
345+
defaultDuration = '--:--',
346+
customIcons = {},
347+
showSkipControls = false,
377348
onClickPrevious,
378349
onClickNext,
379350
onChangeCurrentTimeError,
380-
showJumpControls,
381-
customAdditionalControls,
382-
customVolumeControls,
383-
muted,
384-
timeFormat,
385-
volume: volumeProp,
386-
loop: loopProp,
351+
showJumpControls = true,
352+
customAdditionalControls = [RHAP_UI.LOOP],
353+
customVolumeControls = [RHAP_UI.VOLUME],
354+
muted = false,
355+
timeFormat = 'auto',
356+
volume: volumeProp = 1,
357+
loop: loopProp = false,
387358
mse,
388-
i18nAriaLabels,
359+
i18nAriaLabels = H5AudioPlayer.defaultI18nAriaLabels,
389360
} = this.props
390361

391362
switch (comp) {
@@ -563,7 +534,7 @@ class H5AudioPlayer extends Component<PlayerProps> {
563534
if (!isValidElement(comp)) {
564535
return null
565536
}
566-
return comp.key ? comp : cloneElement(comp as ReactElement, { key })
537+
return comp.key ? comp : cloneElement(comp, { key })
567538
}
568539
}
569540

@@ -696,21 +667,21 @@ class H5AudioPlayer extends Component<PlayerProps> {
696667

697668
render(): ReactNode {
698669
const {
699-
className,
670+
className = '',
700671
src,
701-
loop: loopProp,
702-
preload,
703-
autoPlay,
672+
loop: loopProp = false,
673+
preload = 'auto',
674+
autoPlay = false,
704675
crossOrigin,
705676
mediaGroup,
706677
header,
707678
footer,
708-
layout,
709-
customProgressBarSection,
710-
customControlsSection,
679+
layout = 'stacked',
680+
customProgressBarSection = [RHAP_UI.CURRENT_TIME, RHAP_UI.PROGRESS_BAR, RHAP_UI.DURATION],
681+
customControlsSection = [RHAP_UI.ADDITIONAL_CONTROLS, RHAP_UI.MAIN_CONTROLS, RHAP_UI.VOLUME_CONTROLS],
711682
children,
712683
style,
713-
i18nAriaLabels,
684+
i18nAriaLabels = H5AudioPlayer.defaultI18nAriaLabels,
714685
} = this.props
715686
const loop = this.audio.current ? this.audio.current.loop : loopProp
716687
const loopClass = loop ? 'rhap_loop--on' : 'rhap_loop--off'

stories/actions.stories.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Meta, Story, Preview } from '@storybook/addon-docs/blocks'
1+
import { Meta, Story, Canvas } from '@storybook/blocks'
22
import { action } from '@storybook/addon-actions'
33
import { SAMPLE_MP3_URL } from './utils'
44
import AudioPlayer from '../src/index.tsx'
@@ -11,7 +11,7 @@ Different event listeners of the player
1111

1212
Go to `Canvas` tab to see `Actions` logger
1313

14-
<Preview>
14+
<Canvas>
1515
<Story name="Actions">
1616
<AudioPlayer
1717
onAbort={action('onAbort')}
@@ -38,4 +38,4 @@ Go to `Canvas` tab to see `Actions` logger
3838
src="https://assets.alllq.in/prod/AQ/content/audios/EnglishFluency/U1/A5/6-3-te.mp3"
3939
/>
4040
</Story>
41-
</Preview>
41+
</Canvas>

stories/config.stories.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Meta, Story, Canvas } from '@storybook/addon-docs/blocks';
1+
import { Meta, Story, Canvas } from '@storybook/blocks';
22
import { SAMPLE_MP3_URL } from './utils'
33
import AudioPlayer from '../src/index.tsx'
44

stories/edge-cases.stories.mdx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import { Meta, Story, Preview, Description } from '@storybook/addon-docs/blocks'
1+
import { Meta, Story, Canvas, Description } from '@storybook/blocks'
22
import { action } from '@storybook/addon-actions'
33
import { SAMPLE_MP3_URL } from './utils'
44
import AudioPlayer from '../src/index.tsx'
55

66
<Meta title="Edge Cases" component={AudioPlayer} />
77

8-
<Props of={AudioPlayer} />
9-
108
# Edge Cases
119

1210
Edge Cases of the player
@@ -15,28 +13,28 @@ Edge Cases of the player
1513

1614
No error is fired, and no console error
1715

18-
<Preview>
16+
<Canvas>
1917
<Story name="No src">
2018
<AudioPlayer onError={action('onError')} onPlayError={action('onPlayError')} />
2119
</Story>
22-
</Preview>
20+
</Canvas>
2321

2422
#### Empty string src
2523

2624
`onError` will be fired, no browser console error
2725

28-
<Preview>
26+
<Canvas>
2927
<Story name="Empty string src">
3028
<AudioPlayer src='' onError={action('onError')} onPlayError={action('onPlayError')} />
3129
</Story>
32-
</Preview>
30+
</Canvas>
3331

3432
#### Invalid url src
3533

3634
`onError` will be fired with browser console error
3735

38-
<Preview>
36+
<Canvas>
3937
<Story name="Invalid src">
4038
<AudioPlayer src="https://invalidsrc.com/nothing.mp3" onError={action('onError')} onPlayError={action('onPlayError')} />
4139
</Story>
42-
</Preview>
40+
</Canvas>

stories/index.stories.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
import '../src/styles.scss'
2+
3+
export default {}

0 commit comments

Comments
 (0)