Skip to content

Commit

Permalink
fix: 优化 withGuide ts 定义 (#1934)
Browse files Browse the repository at this point in the history
* chore: update dumi-theme-antv (#1890)

* feat: 优化 withGuide ts 类型

* fix: 修复 ts 类型错误

* Revert "chore: update dumi-theme-antv (#1890)"

This reverts commit 450be5a.

---------

Co-authored-by: Frank William <[email protected]>
Co-authored-by: 不狸 <[email protected]>
  • Loading branch information
3 people authored and zengyue committed Mar 6, 2024
1 parent 482bbbb commit 524b506
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 44 deletions.
7 changes: 4 additions & 3 deletions packages/f2/src/components/guide/views/Arc.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { jsx, ArcStyleProps } from '@antv/f-engine';
import { deepMix } from '@antv/util';
import { GuideProps } from '../withGuide';

type ArcGuideProps = {
export interface ArcGuideProps extends GuideProps {
points?: { x: number; y: number }[] | null;
style?: ArcStyleProps;
style?: Partial<ArcStyleProps> | ((record?) => Partial<ArcStyleProps>);
theme?: any;
};
}

export default (props: ArcGuideProps) => {
const { theme = {} } = props;
Expand Down
13 changes: 7 additions & 6 deletions packages/f2/src/components/guide/views/Image.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { jsx, ImageStyleProps } from '@antv/f-engine';
import { deepMix } from '@antv/util';
import { GuideProps } from '../withGuide';

type ImageGuideProps = {
export interface ImageGuideProps extends GuideProps {
src: string;
points?: { x: number; y: number }[] | null;
attrs?: ImageStyleProps;
style?: ImageStyleProps;
offsetX?: number;
offsetY?: number;
};
style?: Partial<ImageStyleProps> | ((record?) => Partial<ImageStyleProps>);
offsetX?: number | string;
offsetY?: number | string;
}

const defaultProps: ImageGuideProps = {
const defaultProps: Omit<ImageGuideProps, "records"> = {
offsetX: 0,
offsetY: 0,
points: [],
Expand Down
11 changes: 6 additions & 5 deletions packages/f2/src/components/guide/views/Line.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { jsx, LineStyleProps } from '@antv/f-engine';
import { GuideProps } from '../withGuide';
import { isArray, deepMix } from '@antv/util';

type LineGuideProps = {
export interface LineGuideProps extends GuideProps {
points?: { x: number; y: number }[] | null;
style?: LineStyleProps;
offsetX?: number | number[];
offsetY?: number | number[];
style?: Partial<LineStyleProps> | ((record?) => Partial<LineStyleProps>);
offsetX?: number | string | (number | string)[];
offsetY?: number | string | (number | string)[];
theme?: any;
};
}

export default (props: LineGuideProps, context) => {
const { theme = {} } = props;
Expand Down
15 changes: 8 additions & 7 deletions packages/f2/src/components/guide/views/Lottie.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { jsx, AnimationProps } from '@antv/f-engine';
import { deepMix } from '@antv/util';
import Lottie from '@antv/f-lottie';
import { GuideProps } from '../withGuide';

type LottieGuideProps = {
export interface LottieGuideProps extends GuideProps {
points?: { x: number; y: number }[] | null;
data?: string;
offsetX?: number | number[];
offsetY?: number | number[];
animation: AnimationProps;
options: {
offsetX?: number | string | (string | number)[];
offsetY?: number | string | (string | number)[];
animation: AnimationProps | ((points?, chart?) => AnimationProps);
options?: {
loop: boolean | number;
autoplay: boolean;
};
};
}

const defaultProps: LottieGuideProps = {
const defaultProps: Omit<LottieGuideProps, 'records'> = {
offsetX: 0,
offsetY: 0,
points: [],
Expand Down
11 changes: 6 additions & 5 deletions packages/f2/src/components/guide/views/Point.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { jsx, CircleStyleProps } from '@antv/f-engine';
import { deepMix } from '@antv/util';
import { GuideProps } from '../withGuide';

type PointGuideProps = {
style?: CircleStyleProps;
offsetX?: number;
offsetY?: number;
export interface PointGuideProps extends GuideProps {
style?: Partial<CircleStyleProps> | ((record?) => Partial<CircleStyleProps>);
offsetX?: number | string;
offsetY?: number | string;
points?: { x: number; y: number }[] | null;
theme?: any;
};
}

export default (props: PointGuideProps, context) => {
const { theme } = props;
Expand Down
7 changes: 4 additions & 3 deletions packages/f2/src/components/guide/views/Rect.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { jsx, RectStyleProps } from '@antv/f-engine';
import { deepMix } from '@antv/util';
import { GuideProps } from '../withGuide';

type RectGuideProps = {
export interface RectGuideProps extends GuideProps {
points?: { x: number; y: number }[] | null;
style?: RectStyleProps;
style?: Partial<RectStyleProps> | ((record?) => Partial<RectStyleProps>);
theme?: any;
};
}

export default (props: RectGuideProps) => {
const { theme = {} } = props;
Expand Down
11 changes: 6 additions & 5 deletions packages/f2/src/components/guide/views/Tag.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { jsx, Component, computeLayout } from '@antv/f-engine';
import { GuideProps } from '../withGuide';

interface TagGuideProps {
export interface TagGuideProps extends GuideProps {
points?: { x: number; y: number }[] | null;
canvasWidth?: number;
canvasHeight?: number;
offsetX?: number;
offsetY?: number;
offsetX?: number | string;
offsetY?: number | string;
autoAdjust?: boolean;
/**
* 箭头的方向
Expand All @@ -29,7 +30,7 @@ interface TagGuideProps {
textStyle?: any;
}

const defaultProps: TagGuideProps = {
const defaultProps: Omit<TagGuideProps, "records"> = {
offsetX: 0,
offsetY: 0,
points: [],
Expand Down Expand Up @@ -75,7 +76,7 @@ const Label = ({ content, background, textStyle }) => {
</rect>
);
};
export default class Tag extends Component {
export default class Tag extends Component<TagGuideProps> {
render() {
const { props, context } = this;
const { px2hd } = context;
Expand Down
11 changes: 6 additions & 5 deletions packages/f2/src/components/guide/views/Text.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { jsx, TextStyleProps } from '@antv/f-engine';
import { GuideProps } from '../withGuide';
import { deepMix } from '@antv/util';

type TextGuideProps = {
export interface TextGuideProps extends GuideProps {
points?: { x: number; y: number }[] | null;
content: string | number;
style?: TextStyleProps;
offsetX?: number;
offsetY?: number;
style?: Partial<TextStyleProps> | ((record?) => Partial<TextStyleProps>);
offsetX?: number | string;
offsetY?: number | string;
theme?: any;
};
}

export default (props: TextGuideProps, context) => {
const { theme = {} } = props;
Expand Down
10 changes: 5 additions & 5 deletions packages/f2/src/components/guide/withGuide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ export interface GuideProps {
[key: string]: any;
}

export default (View: ComponentType) => {
return class Guide<IProps extends GuideProps = GuideProps> extends Component<
IProps & ChartChildProps
> {
export default function<IProps extends GuideProps = GuideProps>(
View: ComponentType<IProps & ChartChildProps>
): ComponentType<IProps & ChartChildProps> {
return class Guide extends Component<IProps & ChartChildProps> {
chart: Chart;

constructor(props: IProps & ChartChildProps) {
Expand Down Expand Up @@ -101,4 +101,4 @@ export default (View: ComponentType) => {
);
}
};
};
}

0 comments on commit 524b506

Please sign in to comment.