Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(Overlay): ts & docs & test tools #4805

Closed
wants to merge 11 commits into from
9 changes: 6 additions & 3 deletions components/overlay/__docs__/demo/backdrop/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { Overlay, Button } from '@alifd/next';
import type { OverlayProps, OverlayState } from '@alifd/next/lib/overlay/types';
import type { ButtonProps } from '@alifd/next/lib/button';

class Demo extends React.Component {
constructor(props) {
class Demo extends React.Component<OverlayProps, OverlayState> {
btn: ButtonProps;
constructor(props: OverlayProps) {
super(props);

this.state = {
Expand All @@ -29,7 +32,7 @@ class Demo extends React.Component {
<Button
onClick={this.onClick}
ref={ref => {
this.btn = ref;
this.btn = ref as ButtonProps;
}}
>
Open
Expand Down
10 changes: 7 additions & 3 deletions components/overlay/__docs__/demo/baisc/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { Overlay, Button } from '@alifd/next';
import type { OverlayProps, OverlayState } from '@alifd/next/lib/overlay/types';
eamonzym marked this conversation as resolved.
Show resolved Hide resolved
import type { ButtonProps } from '@alifd/next/lib/button';

class Demo extends React.Component {
constructor(props) {
class Demo extends React.Component<OverlayProps, OverlayState> {
btn: ButtonProps;

constructor(props: OverlayProps) {
super(props);

this.state = {
Expand All @@ -29,7 +33,7 @@ class Demo extends React.Component {
<Button
onClick={this.onClick}
ref={ref => {
this.btn = ref;
this.btn = ref as ButtonProps;
}}
>
Toggle visible
Expand Down
28 changes: 20 additions & 8 deletions components/overlay/__docs__/demo/controlled/index.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { Overlay, Button } from '@alifd/next';
import type { PopupProps } from '@alifd/next/lib/overlay/types';
eamonzym marked this conversation as resolved.
Show resolved Hide resolved
import type { ButtonProps } from '@alifd/next/lib/button';

const { Popup } = Overlay;

class Demo extends React.Component {
constructor(props) {
interface DemoState {
visible?: boolean;
groupVisible?: boolean;
}

class Demo extends React.Component<PopupProps, DemoState> {
btn1: ButtonProps;
btn2: ButtonProps;
overlay1: HTMLSpanElement;
overlay2: HTMLSpanElement;

constructor(props: PopupProps) {
super(props);

this.state = {
visible: false,
};
}

onVisibleChange = visible => {
onVisibleChange = (visible: boolean) => {
this.setState({
visible,
});
};

onGroupVisibleChange = groupVisible => {
onGroupVisibleChange = (groupVisible: boolean) => {
this.setState({
groupVisible,
});
Expand Down Expand Up @@ -47,7 +59,7 @@ class Demo extends React.Component {
<Button
style={{ marginRight: '50px' }}
ref={ref => {
this.btn1 = ref;
this.btn1 = ref as ButtonProps;
eamonzym marked this conversation as resolved.
Show resolved Hide resolved
}}
>
Paired Popup 1
Expand All @@ -61,7 +73,7 @@ class Demo extends React.Component {
<span
className="overlay-demo"
ref={ref => {
this.overlay1 = ref;
this.overlay1 = ref as HTMLSpanElement;
eamonzym marked this conversation as resolved.
Show resolved Hide resolved
}}
>
Hello World From Popup!
Expand All @@ -72,7 +84,7 @@ class Demo extends React.Component {
trigger={
<Button
ref={ref => {
this.btn2 = ref;
this.btn2 = ref as ButtonProps;
eamonzym marked this conversation as resolved.
Show resolved Hide resolved
}}
>
Paired Popup 2
Expand All @@ -86,7 +98,7 @@ class Demo extends React.Component {
<span
className="overlay-demo"
ref={ref => {
this.overlay2 = ref;
this.overlay2 = ref as HTMLSpanElement;
eamonzym marked this conversation as resolved.
Show resolved Hide resolved
}}
>
Hello World From Popup!
Expand Down
8 changes: 7 additions & 1 deletion components/overlay/__docs__/demo/scroll-debug/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ const style = {

function TableDemo() {
const columns = [1, 2, 3].map(v => {
return { dataIndex: `data${v}`, title: `Data${v}`, width: 200 };
return { dataIndex: `data${v}`, title: `Data${v}`, width: 200 } as {
eamonzym marked this conversation as resolved.
Show resolved Hide resolved
dataIndex?: string;
title: string;
width: number;
lock?: 'left' | 'right';
cell?: any;
};
});
columns.unshift({
dataIndex: 'id',
Expand Down
18 changes: 9 additions & 9 deletions components/overlay/__docs__/demo/scroll/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ const App = () => {
v2
cache
triggerType="click"
overlay={<div style={style}>position: {JSON.stringify(position)}</div>}
onPosition={result => {
overlay={!(<div style={style}>position: {JSON.stringify(position)}</div>)}
eamonzym marked this conversation as resolved.
Show resolved Hide resolved
onPosition={(result: HTMLElement) => {
const { style } = result;
console.log(result);
setPosition(style);
Expand All @@ -46,9 +46,9 @@ const App = () => {
v2
cache
triggerType="click"
overlay={<div style={style}>position: {JSON.stringify(position12)}</div>}
container={trigger => trigger.parentNode}
onPosition={result => {
overlay={!(<div style={style}>position: {JSON.stringify(position12)}</div>)}
eamonzym marked this conversation as resolved.
Show resolved Hide resolved
container={(trigger: HTMLElement) => trigger.parentNode}
onPosition={(result: HTMLElement) => {
const { style } = result;
console.log(result);
setPosition12(style);
Expand All @@ -60,9 +60,9 @@ const App = () => {
v2
cache
triggerType="click"
overlay={<div style={style}>position: {JSON.stringify(position13)}</div>}
overlay={!(<div style={style}>position: {JSON.stringify(position13)}</div>)}
eamonzym marked this conversation as resolved.
Show resolved Hide resolved
followTrigger
onPosition={result => {
onPosition={(result: HTMLElement) => {
const { style } = result;
console.log(result);
setPosition13(style);
Expand All @@ -74,8 +74,8 @@ const App = () => {
<Popup
v2
triggerType="click"
overlay={<div style={style}>position: {JSON.stringify(position2)}</div>}
onPosition={({ style }) => {
overlay={!(<div style={style}>position: {JSON.stringify(position2)}</div>)}
eamonzym marked this conversation as resolved.
Show resolved Hide resolved
onPosition={({ style }: HTMLElement) => {
setPosition2(style);
}}
>
Expand Down
Loading
Loading