Skip to content

Commit fa01143

Browse files
wewoormumiao
authored andcommitted
refactor(api): refactor the molecule API and interfaces
1. Re design the molecule API for development, 2. rename the component props name BREAKING CHANGE: different invoke methods based on molecule API fix #143, fix #153
1 parent b26c532 commit fa01143

File tree

97 files changed

+694
-580
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+694
-580
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ All notable changes to this project will be documented in this file. See [standa
2424
- explorer service add ([9963180](https://github.com/DTStack/molecule/commit/9963180e4007f5182ebf4f305e505ef79e54d864))
2525
- export the shadowClassName of contextView ([7875f19](https://github.com/DTStack/molecule/commit/7875f19107ba0c63fc81fd62c86fbcefe2cca82e))
2626
- extract editor modified logic to extensions ([#138](https://github.com/DTStack/molecule/issues/138)) ([70aafcf](https://github.com/DTStack/molecule/commit/70aafcf30ccb9af536babdb5fbb7c5961050de68))
27-
- extract ITab interface to tabComponent ([3645f46](https://github.com/DTStack/molecule/commit/3645f466bb4cd05647140e1eb16c780bb0f7e3d3))
27+
- extract ITabProps interface to tabComponent ([3645f46](https://github.com/DTStack/molecule/commit/3645f466bb4cd05647140e1eb16c780bb0f7e3d3))
2828
- extract logic to extensions ([cd47341](https://github.com/DTStack/molecule/commit/cd473417a31870132bee8add434ebb2e0631b545))
2929
- extract overside tabDataInterface ([c7a6857](https://github.com/DTStack/molecule/commit/c7a6857be5f5a02812b1913b365dbfb645a1bcc1))
3030
- extract TreeViewUtil to help file ([883de0f](https://github.com/DTStack/molecule/commit/883de0fba6241c1378a399608cd251cc710149ab))

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"prettier": "prettier --ignore-unknown .",
1919
"pretty-quick": "pretty-quick",
2020
"release": "standard-version",
21-
"docs": "typedoc --entryPoints src/index.ts --out docs/api",
21+
"docs": "typedoc --entryPoints src/index.ts --out docs/api --name 'Molecule API'",
2222
"web": "webpack serve --env prod --config ./build/web.js"
2323
},
2424
"keywords": [

src/components/actionBar/__tests__/actionBar.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
22
import { render, screen } from '@testing-library/react';
33
import renderer from 'react-test-renderer';
44

5-
import ActionBar from '../index';
5+
import { ActionBar } from '../index';
66

77
const mockData = [
88
{

src/components/actionBar/index.tsx

+13-13
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,34 @@ import {
88
} from 'mo/common/className';
99
import { useContextMenu } from 'mo/components/contextMenu';
1010
import { select } from 'mo/common/dom';
11-
import { IMenuItem, Menu } from 'mo/components/menu';
11+
import { IMenuItemProps, Menu } from 'mo/components/menu';
1212
import { mergeFunctions } from 'mo/common/utils';
1313

14-
export interface IActionBarItem<T = any> {
14+
export interface IActionBarItemProps<T = any> {
1515
id?: string;
1616
name?: string;
1717
title?: string;
1818
iconName?: string;
1919
disabled?: boolean;
2020
checked?: boolean;
2121
data?: T;
22-
contextMenu?: IMenuItem[];
22+
contextMenu?: IMenuItemProps[];
2323
className?: string;
2424
onContextMenuClick?: (
2525
e: React.MouseEvent,
26-
item: IMenuItem | undefined
26+
item: IMenuItemProps | undefined
2727
) => void;
28-
onClick?(event: React.MouseEvent, item: IActionBarItem): void;
28+
onClick?(event: React.MouseEvent, item: IActionBarItemProps): void;
2929
}
3030

31-
export interface IActionBar<T = any> {
32-
data: IActionBarItem<T>[];
31+
export interface IActionBarProps<T = any> {
32+
data: IActionBarItemProps<T>[];
3333
className?: string;
3434
onContextMenuClick?: (
3535
e: React.MouseEvent,
36-
item: IMenuItem | undefined
36+
item: IMenuItemProps | undefined
3737
) => void;
38-
onClick?(event: React.MouseEvent, item: IActionBarItem): void;
38+
onClick?(event: React.MouseEvent, item: IActionBarItemProps): void;
3939
}
4040

4141
const defaultActionBarClassName = prefixClaName('action-bar');
@@ -48,7 +48,7 @@ const itemDisabledClassName = getBEMModifier(itemClassName, 'disabled');
4848
const itemCheckedClassName = getBEMModifier(itemClassName, 'checked');
4949
const labelClassName = getBEMElement(defaultActionBarClassName, 'label');
5050

51-
export function ActionBarItem(props: IActionBarItem) {
51+
export function ActionBarItem(props: IActionBarItemProps) {
5252
const {
5353
id,
5454
title,
@@ -71,7 +71,7 @@ export function ActionBarItem(props: IActionBarItem) {
7171
let contextViewMenu;
7272

7373
const onClickMenuItem = useCallback(
74-
(e: React.MouseEvent, item: IMenuItem | undefined) => {
74+
(e: React.MouseEvent, item: IMenuItemProps | undefined) => {
7575
onContextMenuClick?.(e, item);
7676
contextViewMenu?.dispose();
7777
},
@@ -118,7 +118,7 @@ export function ActionBarItem(props: IActionBarItem) {
118118
);
119119
}
120120

121-
export default function ActionBar<T = any>(props: IActionBar<T>) {
121+
export function ActionBar<T = any>(props: IActionBarProps<T>) {
122122
const {
123123
data = [],
124124
onClick,
@@ -129,7 +129,7 @@ export default function ActionBar<T = any>(props: IActionBar<T>) {
129129

130130
const claNames = classNames(defaultActionBarClassName, className);
131131

132-
const items = data.map((item: IActionBarItem<T>, index) => (
132+
const items = data.map((item: IActionBarItemProps<T>, index) => (
133133
<ActionBarItem
134134
key={item.id}
135135
{...item}

src/components/breadcrumb/index.tsx

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
import * as React from 'react';
22
import { prefixClaName, classNames, getBEMElement } from 'mo/common/className';
33
import { ComponentProps } from 'react';
4-
import { Icon } from '../icon';
5-
6-
export interface IBreadcrumbItem {
4+
import { Icon } from 'mo/components';
5+
export interface IBreadcrumbItemProps {
76
id: string;
87
href?: string;
98
name?: string;
10-
icon?: typeof Icon;
9+
icon?: ReactNode;
1110
className?: string;
12-
render?(item: IBreadcrumbItem): ReactNode;
11+
render?(item: IBreadcrumbItemProps): ReactNode;
1312
}
1413

15-
export interface IBreadcrumb extends ComponentProps<'div'> {
16-
routes: IBreadcrumbItem[];
17-
separator?: typeof Icon;
18-
onClick?(event: React.MouseEvent, item?: IBreadcrumbItem): void;
14+
export interface IBreadcrumbProps extends ComponentProps<'div'> {
15+
routes: IBreadcrumbItemProps[];
16+
separator?: ReactNode;
17+
onClick?(event: React.MouseEvent, item?: IBreadcrumbItemProps): void;
1918
}
2019

2120
export const defaultBreadcrumbClassName = prefixClaName('breadcrumb');
@@ -30,10 +29,10 @@ export const breadcrumbLabelClassName = getBEMElement(
3029
'label'
3130
);
3231

33-
export function Breadcrumb(props: IBreadcrumb) {
32+
export function Breadcrumb(props: IBreadcrumbProps) {
3433
const { onClick, className, separator, routes = [], ...extra } = props;
3534

36-
const getEvents = (item: IBreadcrumbItem) => {
35+
const getEvents = (item: IBreadcrumbItemProps) => {
3736
return {
3837
onClick: function (e: React.MouseEvent) {
3938
onClick?.(e, item);
@@ -46,7 +45,7 @@ export function Breadcrumb(props: IBreadcrumb) {
4645
const sep = separator || <Icon type="chevron-right" />;
4746
return (
4847
<div className={claNames} {...extra}>
49-
{routes.map((route: IBreadcrumbItem, index: number) => (
48+
{routes.map((route: IBreadcrumbItemProps, index: number) => (
5049
<a
5150
key={route.id}
5251
className={classNames(

src/components/button/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
22
import { classNames, getBEMModifier, prefixClaName } from 'mo/common/className';
33

44
type BtnSizeType = 'normal' | 'large';
5-
export interface IButton extends React.ComponentProps<'a'> {
5+
export interface IButtonProps extends React.ComponentProps<'a'> {
66
disabled?: boolean;
77
size?: BtnSizeType;
88
onClick?(event: React.MouseEvent): void;
@@ -16,7 +16,7 @@ const disableButtonClassName = getBEMModifier(
1616
'disabled'
1717
);
1818

19-
export function Button(props: React.PropsWithChildren<IButton>) {
19+
export function Button(props: React.PropsWithChildren<IButtonProps>) {
2020
const { className, children, size = 'normal', ...custom } = props;
2121

2222
const disabled = props.disabled ? disableButtonClassName : null;

src/components/checkbox/checkbox.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ import * as React from 'react';
22
import { ComponentProps } from 'react';
33
import { prefixClaName, classNames, getBEMElement } from 'mo/common/className';
44

5-
export interface ICheckbox extends ComponentProps<any> {
5+
export interface ICheckboxProps extends ComponentProps<any> {
66
id: string;
77
value?: string;
88
children?: ReactNode;
9-
onChange?(e: React.ChangeEvent, options?: ICheckbox): void;
9+
onChange?(e: React.ChangeEvent, options?: ICheckboxProps): void;
1010
}
1111

1212
export const checkboxClassName = prefixClaName('checkbox');
1313
const checkboxLabelClassName = getBEMElement(checkboxClassName, 'label');
1414
const checkboxInputClassName = getBEMElement(checkboxClassName, 'input');
1515

16-
export function Checkbox(props: ICheckbox) {
16+
export function Checkbox(props: ICheckboxProps) {
1717
const { className, id, children, value, onChange, ...custom } = props;
1818

1919
const claNames = classNames(checkboxClassName, className);

src/components/collapse/index.tsx

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import { useState } from 'react';
3-
import RcCollapse, { Panel } from 'rc-collapse';
4-
import Toolbar from 'mo/components/toolbar';
3+
import RcCollapse, { Panel as CollapsePanel } from 'rc-collapse';
4+
import { Toolbar } from 'mo/components/toolbar';
55
import { Icon } from 'mo/components/icon';
66
import {
77
prefixClaName,
@@ -32,9 +32,8 @@ export const contentPaddingClassName = getBEMModifier(
3232
const initState = {
3333
activePanelKeys: [],
3434
};
35-
const Collapse: React.FunctionComponent<ICollapseProps> = (
36-
props: ICollapseProps
37-
) => {
35+
36+
export function Collapse(props: ICollapseProps) {
3837
const [state, setState] = useState<IState>(initState);
3938
const {
4039
className,
@@ -76,7 +75,7 @@ const Collapse: React.FunctionComponent<ICollapseProps> = (
7675
)}
7776
>
7877
{data.map((panel) => (
79-
<Panel
78+
<CollapsePanel
8079
key={panel.id}
8180
header={panel.name}
8281
className={panel.className}
@@ -91,12 +90,11 @@ const Collapse: React.FunctionComponent<ICollapseProps> = (
9190
}
9291
>
9392
{render(panel.renderPanel)}
94-
</Panel>
93+
</CollapsePanel>
9594
))}
9695
</RcCollapse>
9796
</div>
9897
);
99-
};
98+
}
10099

101-
export { Panel };
102-
export default Collapse;
100+
export { CollapsePanel };

src/components/contextMenu/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import * as React from 'react';
22
import { HTMLElementType } from 'mo/common/dom';
33
import { useContextView } from 'mo/components/contextView';
44

5-
export interface IContextMenu {
5+
export interface IContextMenuProps {
66
anchor: HTMLElementType;
77
render: () => React.ReactNode;
88
}
99

10-
export function useContextMenu(props: IContextMenu) {
10+
export function useContextMenu(props: IContextMenuProps) {
1111
const { anchor, render } = props;
1212

1313
if (!anchor) {

src/components/dialog/actionButton.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
2-
import { Button, IButton } from 'mo/components/button';
3-
export interface ActionButtonProps extends IButton {
2+
import { Button, IButtonProps } from 'mo/components/button';
3+
export interface ActionButtonProps extends IButtonProps {
44
actionFn?: (...args: any[]) => any | PromiseLike<any>;
55
closeModal: Function;
66
}

src/components/dialog/confirmDialog.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
getBEMModifier,
66
prefixClaName,
77
} from 'mo/common/className';
8-
import Dialog, { IModalFuncProps } from './modal';
8+
import { Modal as Dialog, IModalFuncProps } from './modal';
99
import ActionButton from './actionButton';
1010

1111
interface ConfirmDialogProps extends IModalFuncProps {

src/components/dialog/index.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import OriginModal, { IModalFuncProps, destroyFns } from './modal';
1+
import {
2+
Modal as OriginModal,
3+
IModalProps,
4+
IModalFuncProps,
5+
destroyFns,
6+
} from './modal';
27
import confirm, {
38
withWarn,
49
withConfirm,
@@ -31,4 +36,4 @@ Modal.destroyAll = function destroyAllFn() {
3136
}
3237
};
3338

34-
export default Modal;
39+
export { Modal, IModalFuncProps, IModalProps };

src/components/dialog/modal.tsx

+6-8
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import {
99
getBEMModifier,
1010
} from 'mo/common/className';
1111
import { Icon } from 'mo/components/icon';
12-
import { Button, IButton } from 'mo/components/button';
12+
import { Button, IButtonProps } from 'mo/components/button';
1313
export interface IModalProps extends IDialogPropTypes {
1414
onOk?: (e: React.MouseEvent<HTMLElement>) => void;
1515
onCancel?: (e: React.SyntheticEvent<Element, Event>) => void;
1616
centered?: boolean;
1717
cancelText?: React.ReactNode;
1818
okText?: React.ReactNode;
19-
okButtonProps?: IButton;
20-
cancelButtonProps?: IButton;
19+
okButtonProps?: IButtonProps;
20+
cancelButtonProps?: IButtonProps;
2121
okCancel?: boolean;
2222
}
2323
export interface IModalFuncProps extends IDialogPropTypes {
@@ -27,8 +27,8 @@ export interface IModalFuncProps extends IDialogPropTypes {
2727
content?: React.ReactNode;
2828
onOk?: (...args: any[]) => any;
2929
onCancel?: (...args: any[]) => void;
30-
okButtonProps?: IButton;
31-
cancelButtonProps?: IButton;
30+
okButtonProps?: IButtonProps;
31+
cancelButtonProps?: IButtonProps;
3232
centered?: boolean;
3333
okCancel?: boolean;
3434
type?: string;
@@ -61,7 +61,7 @@ const closeIconToRender = (
6161
</span>
6262
);
6363

64-
const Modal: React.FC<IModalProps> = (props) => {
64+
export const Modal: React.FC<IModalProps> = (props: IModalProps) => {
6565
const handleCancel = (e: React.SyntheticEvent<Element, Event>) => {
6666
const { onCancel } = props;
6767
onCancel?.(e);
@@ -115,5 +115,3 @@ const Modal: React.FC<IModalProps> = (props) => {
115115
/>
116116
);
117117
};
118-
119-
export default Modal;

src/components/dropdown/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
getPositionByPlacement,
99
} from 'mo/common/dom';
1010

11-
export interface IDropDown extends React.ComponentProps<'div'> {
11+
export interface IDropDownProps extends React.ComponentProps<'div'> {
1212
overlay: ReactNode;
1313
trigger?: TriggerEvent;
1414
placement?: PlacementType;
@@ -18,7 +18,7 @@ export interface IDropDown extends React.ComponentProps<'div'> {
1818
const defaultDropDownClassName = prefixClaName('drop-down');
1919

2020
export const DropDown = React.forwardRef(
21-
(props: React.PropsWithChildren<IDropDown>, ref) => {
21+
(props: React.PropsWithChildren<IDropDownProps>, ref) => {
2222
const {
2323
className,
2424
overlay,

src/components/icon/index.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import { classNames, prefixClaName } from 'mo/common/className';
21
import * as React from 'react';
2+
import { classNames, prefixClaName } from 'mo/common/className';
33
import 'vscode-codicons/dist/codicon.css';
4+
import { ComponentProps } from 'react';
45

5-
export interface IIcon extends HTMLElementProps {
6+
export interface IIconProps extends ComponentProps<'span'> {
67
type: string;
78
onClick?: (e: React.MouseEvent) => void;
89
}
910

10-
export function Icon(props: IIcon): React.ReactElement {
11+
export function Icon(props: IIconProps) {
1112
const { className, type, ...restProps } = props;
1213
return (
1314
<span

0 commit comments

Comments
 (0)