Skip to content

Commit 402f2e6

Browse files
committed
chore(stories): fix ts type
chore(stories): fix ts type
1 parent 62fe62c commit 402f2e6

File tree

6 files changed

+63
-49
lines changed

6 files changed

+63
-49
lines changed

src/components/Video/index.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
/* eslint-disable jsx-a11y/media-has-caption */
12
import React, { useState, useRef } from 'react';
23
import clsx from 'clsx';
34

4-
export interface VideoProps {
5+
export type VideoProps = React.VideoHTMLAttributes<HTMLVideoElement> & {
56
className?: string;
67
src?: string;
78
cover?: string;
89
duration?: string | number;
910
style?: React.CSSProperties;
1011
videoRef?: React.RefObject<HTMLVideoElement>;
1112
onClick?: (paused: boolean, event: React.MouseEvent) => void;
12-
onCoverLoad?: (event: React.SyntheticEvent) => void;
13-
}
13+
onCoverLoad?: (event: React.SyntheticEvent<HTMLImageElement, Event>) => void;
14+
};
1415

1516
export const Video: React.FC<VideoProps> = (props) => {
1617
const {
@@ -21,11 +22,14 @@ export const Video: React.FC<VideoProps> = (props) => {
2122
onClick,
2223
onCoverLoad,
2324
style,
24-
videoRef = useRef<HTMLVideoElement>(null),
25+
videoRef: outerVideoRef,
2526
children,
2627
...other
2728
} = props;
2829

30+
const localVideoRef = useRef<HTMLVideoElement>(null!);
31+
const videoRef = outerVideoRef || localVideoRef;
32+
2933
const [isPlayed, setIsPlayed] = useState(false);
3034
const [paused, setPaused] = useState(true);
3135

@@ -83,4 +87,4 @@ export const Video: React.FC<VideoProps> = (props) => {
8387
)}
8488
</div>
8589
);
86-
};
90+
};

storybook/stories/Carousel.stories.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { Meta } from '@storybook/react/types-6-0';
33

4-
import { Carousel } from '../../src';
4+
import { Carousel, CarouselProps, CarouselHandle } from '../../src';
55

66
export default {
77
title: 'Carousel',
@@ -17,7 +17,7 @@ const imgs = [
1717

1818
// const Template: Story<CarouselProps> = (args) => <Carousel {...args} />;
1919

20-
export const ManyImages = (ars) => (
20+
export const ManyImages = (ars: CarouselProps) => (
2121
<Carousel {...ars}>
2222
{imgs.map((img, i) => (
2323
<div key={i}>
@@ -42,9 +42,9 @@ ManyImages.args = {
4242
};
4343

4444
function TestMethods() {
45-
const carouselRef = React.useRef(null);
45+
const carouselRef = React.useRef<CarouselHandle>(null!);
4646

47-
function handleClick(e) {
47+
function handleClick(e: React.MouseEvent<HTMLAnchorElement, MouseEvent>) {
4848
console.log('click item:', e);
4949
}
5050

storybook/stories/ComponentProvider.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Meta } from '@storybook/react/types-6-0';
44
import * as ChatUI from '../../src';
55
import { ComponentsMap } from '../../src';
66

7-
const { ComponentsProvider, useComponents, LazyComponent } = ChatUI;
7+
const { ComponentsProvider, LazyComponent } = ChatUI;
88

99
export default {
1010
title: 'ComponentsProvider',

storybook/stories/ErrorBoundary.stories.tsx

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,14 @@ export default {
1616
],
1717
} as Meta;
1818

19-
export const WillCrashed = () => <BuggyCounter />;
20-
21-
export const NoFallback = () => (
22-
<ErrorBoundary>
23-
<BuggyCounter />
24-
</ErrorBoundary>
25-
);
26-
27-
export const FallbackComponent = () => (
28-
<div>
29-
<ErrorBoundary FallbackComponent={ErrorFallback}>
30-
<BuggyCounter />
31-
</ErrorBoundary>
32-
</div>
33-
);
34-
35-
export const NoError = (args) => (
36-
<ErrorBoundary {...args}>
37-
<p>no error</p>
38-
</ErrorBoundary>
39-
);
40-
4119
// https://codepen.io/gaearon/pen/wqvxGa?editors=0010
4220
class BuggyCounter extends React.Component<{}, { counter: number }> {
43-
state = { counter: 0 };
21+
constructor(props: {}) {
22+
super(props);
23+
this.state = {
24+
counter: 0,
25+
};
26+
}
4427

4528
handleClick = () => {
4629
this.setState(({ counter }) => ({
@@ -54,11 +37,20 @@ class BuggyCounter extends React.Component<{}, { counter: number }> {
5437
// Simulate a JS error
5538
throw new Error('I crashed!');
5639
}
57-
return <h1 onClick={this.handleClick}>{counter}</h1>;
40+
return (
41+
<button onClick={this.handleClick} type="button">
42+
{counter}
43+
</button>
44+
);
5845
}
5946
}
6047

61-
function ErrorFallback({ error, errorInfo }) {
48+
interface ErrorFallbackProps {
49+
error: Error;
50+
errorInfo: React.ErrorInfo;
51+
}
52+
53+
function ErrorFallback({ error, errorInfo }: ErrorFallbackProps) {
6254
return (
6355
<div>
6456
<h2>Something went wrong.</h2>
@@ -70,3 +62,25 @@ function ErrorFallback({ error, errorInfo }) {
7062
</div>
7163
);
7264
}
65+
66+
export const WillCrashed = () => <BuggyCounter />;
67+
68+
export const NoFallback = () => (
69+
<ErrorBoundary>
70+
<BuggyCounter />
71+
</ErrorBoundary>
72+
);
73+
74+
export const FallbackComponent = () => (
75+
<div>
76+
<ErrorBoundary FallbackComponent={ErrorFallback}>
77+
<BuggyCounter />
78+
</ErrorBoundary>
79+
</div>
80+
);
81+
82+
export const NoError = () => (
83+
<ErrorBoundary>
84+
<p>no error</p>
85+
</ErrorBoundary>
86+
);

storybook/stories/List.stories.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { Story, Meta } from '@storybook/react/types-6-0';
33

4-
import { List, ListItem, ListProps, ListItemProps } from '../../src';
4+
import { List, ListItem, ListProps } from '../../src';
55
import '../../src/styles/index.less';
66

77
export default {
@@ -14,12 +14,10 @@ export default {
1414

1515
export const Empty: Story<ListProps> = (args) => <List {...args} />;
1616

17-
export const ManyItems = (args: ListProps) => {
18-
return (
19-
<List {...args}>
20-
<ListItem content="item-1" />
21-
<ListItem content="item-2" />
22-
<ListItem content="item-3" />
23-
</List>
24-
);
25-
};
17+
export const ManyItems = (args: ListProps) => (
18+
<List {...args}>
19+
<ListItem content="item-1" />
20+
<ListItem content="item-2" />
21+
<ListItem content="item-3" />
22+
</List>
23+
);

storybook/stories/Video.stories.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React from 'react';
22
import { Story, Meta } from '@storybook/react/types-6-0';
33

44
import { Video, VideoProps } from '../../src';
5-
// import '../../src/components/Video/style.less';
65

76
export default {
87
title: 'Video',
@@ -14,8 +13,7 @@ const Template: Story<VideoProps> = (args) => <Video {...args} />;
1413
export const Default = Template.bind({});
1514
Default.args = {
1615
src: '//interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4',
17-
alt: 'flower',
1816
style: {
19-
width: '320px'
20-
}
17+
width: '320px',
18+
},
2119
};

0 commit comments

Comments
 (0)