Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

refactor(ui): refactoring CanvasIcon (#121)

白熱dba8024755b2
diff --git a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderDashDot.tsx b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderDashDot.tsx
index fcf401ef4d..0a5e42fe4d 100644
--- a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderDashDot.tsx
+++ b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderDashDot.tsx
@@ -1,36 +1,11 @@
-import { Component } from 'react';
-import { JSXComponent } from '../../../BaseComponent';
-import { IconComponent } from '../../../Interfaces';
import { CanvasIcon } from '../CanvasIcon';
interface IProps {
width?: string;
height?: string;
}
-interface IState {}
-class BorderDashDot extends Component<IProps, IState> {
- render() {
- const { width = '100', height = '10' } = this.props;
- return (
- <CanvasIcon
- width={width}
- height={height}
- type="DashDot"
- hv="h"
- mSt={0}
- mEd={5}
- lineSt={100}
- lineEd={5}
- />
- );
- }
+export function BorderDashDot(props: IProps) {
+ const { width = '100', height = '10' } = props;
+ return <CanvasIcon width={width} height={height} type="DashDot" hv="h" mSt={0} mEd={5} lineSt={100} lineEd={5} />;
}
-
-export class UniverBorderDashDot implements IconComponent {
- render(): JSXComponent<IProps> {
- return BorderDashDot;
- }
-}
-
-export default BorderDashDot;
diff --git a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderDashDotDot.tsx b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderDashDotDot.tsx
index 3c5e5e02ef..dd5196315d 100644
--- a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderDashDotDot.tsx
+++ b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderDashDotDot.tsx
@@ -1,36 +1,11 @@
-import { Component } from 'react';
-import { JSXComponent } from '../../../BaseComponent';
-import { IconComponent } from '../../../Interfaces';
import { CanvasIcon } from '../CanvasIcon';
interface IProps {
width?: string;
height?: string;
}
-interface IState {}
-class BorderDashDotDot extends Component<IProps, IState> {
- render() {
- const { width = '100', height = '10' } = this.props;
- return (
- <CanvasIcon
- width={width}
- height={height}
- type="DashDotDot"
- hv="h"
- mSt={0}
- mEd={5}
- lineSt={100}
- lineEd={5}
- />
- );
- }
+export function BorderDashDotDot(props: IProps) {
+ const { width = '100', height = '10' } = props;
+ return <CanvasIcon width={width} height={height} type="DashDotDot" hv="h" mSt={0} mEd={5} lineSt={100} lineEd={5} />;
}
-
-export class UniverBorderDashDotDot implements IconComponent {
- render(): JSXComponent<IProps> {
- return BorderDashDotDot;
- }
-}
-
-export default BorderDashDotDot;
diff --git a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderDashed.tsx b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderDashed.tsx
index 1cce10f771..90e2b7e951 100644
--- a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderDashed.tsx
+++ b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderDashed.tsx
@@ -1,36 +1,11 @@
-import { Component } from 'react';
-import { JSXComponent } from '../../../BaseComponent';
-import { IconComponent } from '../../../Interfaces';
import { CanvasIcon } from '../CanvasIcon';
interface IProps {
width?: string;
height?: string;
}
-interface IState {}
-class BorderDashed extends Component<IProps, IState> {
- render() {
- const { width = '100', height = '10' } = this.props;
- return (
- <CanvasIcon
- width={width}
- height={height}
- type="Dashed"
- hv="h"
- mSt={0}
- mEd={5}
- lineSt={100}
- lineEd={5}
- />
- );
- }
+export function BorderDashed(props: IProps) {
+ const { width = '100', height = '10' } = props;
+ return <CanvasIcon width={width} height={height} type="Dashed" hv="h" mSt={0} mEd={5} lineSt={100} lineEd={5} />;
}
-
-export class UniverBorderDashed implements IconComponent {
- render(): JSXComponent<IProps> {
- return BorderDashed;
- }
-}
-
-export default BorderDashed;
diff --git a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderDotted.tsx b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderDotted.tsx
index bf7f52d028..686f691105 100644
--- a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderDotted.tsx
+++ b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderDotted.tsx
@@ -1,36 +1,11 @@
-import { Component } from 'react';
-import { JSXComponent } from '../../../BaseComponent';
-import { IconComponent } from '../../../Interfaces';
import { CanvasIcon } from '../CanvasIcon';
interface IProps {
width?: string;
height?: string;
}
-interface IState {}
-class BorderDotted extends Component<IProps, IState> {
- render() {
- const { width = '100', height = '10' } = this.props;
- return (
- <CanvasIcon
- width={width}
- height={height}
- type="Dotted"
- hv="h"
- mSt={0}
- mEd={5}
- lineSt={100}
- lineEd={5}
- />
- );
- }
+export function BorderDotted(props: IProps) {
+ const { width = '100', height = '10' } = props;
+ return <CanvasIcon width={width} height={height} type="Dotted" hv="h" mSt={0} mEd={5} lineSt={100} lineEd={5} />;
}
-
-export class UniverBorderDotted implements IconComponent {
- render(): JSXComponent<IProps> {
- return BorderDotted;
- }
-}
-
-export default BorderDotted;
diff --git a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderHair.tsx b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderHair.tsx
index ad6e431330..a14c62d5b3 100644
--- a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderHair.tsx
+++ b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderHair.tsx
@@ -1,36 +1,11 @@
-import { Component } from 'react';
-import { JSXComponent } from '../../../BaseComponent';
-import { IconComponent } from '../../../Interfaces';
import { CanvasIcon } from '../CanvasIcon';
interface IProps {
width?: string;
height?: string;
}
-interface IState {}
-class BorderHair extends Component<IProps, IState> {
- render() {
- const { width = '100', height = '10' } = this.props;
- return (
- <CanvasIcon
- width={width}
- height={height}
- type="Hair"
- hv="h"
- mSt={0}
- mEd={5}
- lineSt={100}
- lineEd={5}
- />
- );
- }
+export function BorderHair(props: IProps) {
+ const { width = '100', height = '10' } = props;
+ return <CanvasIcon width={width} height={height} type="Hair" hv="h" mSt={0} mEd={5} lineSt={100} lineEd={5} />;
}
-
-export class UniverBorderHair implements IconComponent {
- render(): JSXComponent<IProps> {
- return BorderHair;
- }
-}
-
-export default BorderHair;
diff --git a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderMedium.tsx b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderMedium.tsx
index 07b6521568..5412b3c29e 100644
--- a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderMedium.tsx
+++ b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderMedium.tsx
@@ -1,36 +1,11 @@
-import { Component } from 'react';
-import { JSXComponent } from '../../../BaseComponent';
-import { IconComponent } from '../../../Interfaces';
import { CanvasIcon } from '../CanvasIcon';
interface IProps {
width?: string;
height?: string;
}
-interface IState {}
-class BorderMedium extends Component<IProps, IState> {
- render() {
- const { width = '100', height = '10' } = this.props;
- return (
- <CanvasIcon
- width={width}
- height={height}
- type="Medium"
- hv="h"
- mSt={0}
- mEd={5}
- lineSt={100}
- lineEd={5}
- />
- );
- }
+export function BorderMedium(props: IProps) {
+ const { width = '100', height = '10' } = props;
+ return <CanvasIcon width={width} height={height} type="Medium" hv="h" mSt={0} mEd={5} lineSt={100} lineEd={5} />;
}
-
-export class UniverBorderMedium implements IconComponent {
- render(): JSXComponent<IProps> {
- return BorderMedium;
- }
-}
-
-export default BorderMedium;
diff --git a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderMediumDashDot.tsx b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderMediumDashDot.tsx
index c3f207e810..aabb182d64 100644
--- a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderMediumDashDot.tsx
+++ b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderMediumDashDot.tsx
@@ -1,36 +1,11 @@
-import { Component } from 'react';
-import { JSXComponent } from '../../../BaseComponent';
-import { IconComponent } from '../../../Interfaces';
import { CanvasIcon } from '../CanvasIcon';
interface IProps {
width?: string;
height?: string;
}
-interface IState {}
-class BorderMediumDashDot extends Component<IProps, IState> {
- render() {
- const { width = '100', height = '10' } = this.props;
- return (
- <CanvasIcon
- width={width}
- height={height}
- type="MediumDashDot"
- hv="h"
- mSt={0}
- mEd={5}
- lineSt={100}
- lineEd={5}
- />
- );
- }
+export function BorderMediumDashDot(props: IProps) {
+ const { width = '100', height = '10' } = props;
+ return <CanvasIcon width={width} height={height} type="MediumDashDot" hv="h" mSt={0} mEd={5} lineSt={100} lineEd={5} />;
}
-
-export class UniverBorderMediumDashDot implements IconComponent {
- render(): JSXComponent<IProps> {
- return BorderMediumDashDot;
- }
-}
-
-export default BorderMediumDashDot;
diff --git a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderMediumDashDotDot.tsx b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderMediumDashDotDot.tsx
index d490749baa..e7100261f3 100644
--- a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderMediumDashDotDot.tsx
+++ b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderMediumDashDotDot.tsx
@@ -1,35 +1,11 @@
-import { Component } from 'react';
-import { JSXComponent } from '../../../BaseComponent';
-import { IconComponent } from '../../../Interfaces';
import { CanvasIcon } from '../CanvasIcon';
interface IProps {
width?: string;
height?: string;
}
-interface IState {}
-class BorderMediumDashDotDot extends Component<IProps, IState> {
- render() {
- const { width = '100', height = '10' } = this.props;
- return (
- <CanvasIcon
- width={width}
- height={height}
- type="MediumDashDotDot"
- hv="h"
- mSt={0}
- mEd={5}
- lineSt={100}
- lineEd={5}
- />
- );
- }
+export function BorderMediumDashDotDot(props: IProps) {
+ const { width = '100', height = '10' } = props;
+ return <CanvasIcon width={width} height={height} type="MediumDashDotDot" hv="h" mSt={0} mEd={5} lineSt={100} lineEd={5} />;
}
-export class UniverBorderMediumDashDotDot implements IconComponent {
- render(): JSXComponent<IProps> {
- return BorderMediumDashDotDot;
- }
-}
-
-export default BorderMediumDashDotDot;
diff --git a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderMediumDashed.tsx b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderMediumDashed.tsx
index 8ca17163d8..bcf78e3c05 100644
--- a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderMediumDashed.tsx
+++ b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderMediumDashed.tsx
@@ -1,36 +1,11 @@
-import { Component } from 'react';
-import { JSXComponent } from '../../../BaseComponent';
-import { IconComponent } from '../../../Interfaces';
import { CanvasIcon } from '../CanvasIcon';
interface IProps {
width?: string;
height?: string;
}
-interface IState {}
-class BorderMediumDashed extends Component<IProps, IState> {
- render() {
- const { width = '100', height = '10' } = this.props;
- return (
- <CanvasIcon
- width={width}
- height={height}
- type="MediumDashed"
- hv="h"
- mSt={0}
- mEd={5}
- lineSt={100}
- lineEd={5}
- />
- );
- }
+export function BorderMediumDashed(props: IProps) {
+ const { width = '100', height = '10' } = props;
+ return <CanvasIcon width={width} height={height} type="MediumDashed" hv="h" mSt={0} mEd={5} lineSt={100} lineEd={5} />;
}
-
-export class UniverBorderMediumDashed implements IconComponent {
- render(): JSXComponent<IProps> {
- return BorderMediumDashed;
- }
-}
-
-export default BorderMediumDashed;
diff --git a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderThick.tsx b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderThick.tsx
index 20c37facae..2daaf1152e 100644
--- a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderThick.tsx
+++ b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderThick.tsx
@@ -1,36 +1,11 @@
-import { Component } from 'react';
-import { JSXComponent } from '../../../BaseComponent';
-import { IconComponent } from '../../../Interfaces';
import { CanvasIcon } from '../CanvasIcon';
interface IProps {
width?: string;
height?: string;
}
-interface IState {}
-class BorderThick extends Component<IProps, IState> {
- render() {
- const { width = '100', height = '10' } = this.props;
- return (
- <CanvasIcon
- width={width}
- height={height}
- type="Thick"
- hv="h"
- mSt={0}
- mEd={5}
- lineSt={100}
- lineEd={5}
- />
- );
- }
+export function BorderThick(props: IProps) {
+ const { width = '100', height = '10' } = props;
+ return <CanvasIcon width={width} height={height} type="Thick" hv="h" mSt={0} mEd={5} lineSt={100} lineEd={5} />;
}
-
-export class UniverBorderThick implements IconComponent {
- render(): JSXComponent<IProps> {
- return BorderThick;
- }
-}
-
-export default BorderThick;
diff --git a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderThin.tsx b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderThin.tsx
index 10da63d201..bd8b7e1672 100644
--- a/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderThin.tsx
+++ b/packages/base-ui/src/Components/CanvasIcon/BorderLine/BorderThin.tsx
@@ -1,36 +1,11 @@
-import { Component } from 'react';
-import { JSXComponent } from '../../../BaseComponent';
-import { IconComponent } from '../../../Interfaces';
import { CanvasIcon } from '../CanvasIcon';
interface IProps {
width?: string;
height?: string;
}
-interface IState {}
-class BorderThin extends Component<IProps, IState> {
- render() {
- const { width = '100', height = '10' } = this.props;
- return (
- <CanvasIcon
- width={width}
- height={height}
- type="Thin"
- hv="h"
- mSt={0}
- mEd={5}
- lineSt={100}
- lineEd={5}
- />
- );
- }
+export function BorderThin(props: IProps) {
+ const { width = '100', height = '10' } = props;
+ return <CanvasIcon width={width} height={height} type="Thin" hv="h" mSt={0} mEd={5} lineSt={100} lineEd={5} />;
}
-
-export class UniverBorderThin implements IconComponent {
- render(): JSXComponent<IProps> {
- return BorderThin;
- }
-}
-
-export default BorderThin;
diff --git a/packages/base-ui/src/Components/CanvasIcon/BorderLine/index.ts b/packages/base-ui/src/Components/CanvasIcon/BorderLine/index.ts
index 7b71f9002c..289252f4d7 100644
--- a/packages/base-ui/src/Components/CanvasIcon/BorderLine/index.ts
+++ b/packages/base-ui/src/Components/CanvasIcon/BorderLine/index.ts
@@ -1,25 +1,11 @@
-import BorderThin from './BorderThin';
-import BorderHair from './BorderHair';
-import BorderDotted from './BorderDotted';
-import BorderDashed from './BorderDashed';
-import BorderDashDot from './BorderDashDot';
-import BorderDashDotDot from './BorderDashDotDot';
-import BorderMedium from './BorderMedium';
-import BorderMediumDashed from './BorderMediumDashed';
-import BorderMediumDashDot from './BorderMediumDashDot';
-import BorderMediumDashDotDot from './BorderMediumDashDotDot';
-import BorderThick from './BorderThick';
-
-export {
- BorderThin,
- BorderHair,
- BorderDotted,
- BorderDashed,
- BorderDashDot,
- BorderDashDotDot,
- BorderMedium,
- BorderMediumDashed,
- BorderMediumDashDot,
- BorderMediumDashDotDot,
- BorderThick,
-};
+export * from './BorderDashDot';
+export * from './BorderDashDotDot';
+export * from './BorderDashed';
+export * from './BorderDotted';
+export * from './BorderHair';
+export * from './BorderMedium';
+export * from './BorderMediumDashDot';
+export * from './BorderMediumDashDotDot';
+export * from './BorderMediumDashed';
+export * from './BorderThick';
+export * from './BorderThin';
diff --git a/packages/base-ui/src/Components/CanvasIcon/CanvasIcon.tsx b/packages/base-ui/src/Components/CanvasIcon/CanvasIcon.tsx
index 69de1b564f..38d3049828 100644
--- a/packages/base-ui/src/Components/CanvasIcon/CanvasIcon.tsx
+++ b/packages/base-ui/src/Components/CanvasIcon/CanvasIcon.tsx
@@ -1,5 +1,4 @@
import { useEffect, useRef } from 'react';
-import Style from './index.module.less';
type IProps = {
width: string;
@@ -11,10 +10,9 @@ type IProps = {
lineSt: number;
lineEd: number;
};
-type IState = {};
export function CanvasIcon(props: IProps) {
- const { type, hv, mSt: m_st, mEd: m_ed, lineSt: line_st, lineEd: line_ed } = props
+ const { type, hv, mSt: m_st, mEd: m_ed, lineSt: line_st, lineEd: line_ed } = props;
const canvasRef = useRef<HTMLCanvasElement>(null);
@@ -23,7 +21,7 @@ export function CanvasIcon(props: IProps) {
const ctx = canvasRef.current.getContext('2d')!;
setLineDash(ctx);
- }, [])
+ }, []);
/**
*
@@ -36,23 +34,6 @@ export function CanvasIcon(props: IProps) {
* @param line_ed End Y
*/
function setLineDash(ctx: CanvasRenderingContext2D) {
- // const borderType: { [index: string]: string } = {
- // '0': 'none',
- // '1': 'Thin',
- // '2': 'Hair',
- // '3': 'Dotted',
- // '4': 'Dashed',
- // '5': 'DashDot',
- // '6': 'DashDotDot',
- // '7': 'Double',
- // '8': 'Medium',
- // '9': 'MediumDashed',
- // '10': 'MediumDashDot',
- // '11': 'MediumDashDotDot',
- // '12': 'SlantedDashDot',
- // '13': 'Thick',
- // };
-
try {
if (type === 'Hair') {
ctx.setLineDash([1, 2]);
@@ -97,5 +78,5 @@ export function CanvasIcon(props: IProps) {
ctx.closePath();
}
- return <canvas ref={canvasRef} className={Style.canvas} width={props.width} height={props.height} />;
+ return <canvas ref={canvasRef} width={props.width} height={props.height} />;
}
diff --git a/packages/base-ui/src/Components/CanvasIcon/index.module.less b/packages/base-ui/src/Components/CanvasIcon/index.module.less
deleted file mode 100644
index 54f1626d63..0000000000
--- a/packages/base-ui/src/Components/CanvasIcon/index.module.less
+++ /dev/null
@@ -1,3 +0,0 @@
-.canvas {
- // border: 1px solid #ccc;
-}