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

chore: 完善 Modal、Popup 指令调用 #1056

Merged
merged 4 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/zarm/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ describe('index', () => {
"Modal": Object {
"$$typeof": Symbol(react.forward_ref),
"alert": [Function],
"clear": [Function],
"confirm": [Function],
"defaultProps": Object {
"actions": Array [],
Expand All @@ -273,6 +274,7 @@ describe('index', () => {
"width": "70%",
},
"render": [Function],
"show": [Function],
},
"NavBar": Object {
"$$typeof": Symbol(react.forward_ref),
Expand Down Expand Up @@ -336,6 +338,7 @@ describe('index', () => {
},
"Popup": Object {
"$$typeof": Symbol(react.forward_ref),
"clear": [Function],
"defaultProps": Object {
"destroy": true,
"direction": "bottom",
Expand All @@ -344,6 +347,7 @@ describe('index', () => {
"visible": false,
},
"render": [Function],
"show": [Function],
},
"Progress": Object {
"$$typeof": Symbol(react.forward_ref),
Expand Down
41 changes: 0 additions & 41 deletions packages/zarm/src/alert/Alert.tsx

This file was deleted.

10 changes: 0 additions & 10 deletions packages/zarm/src/alert/__tests__/index.test.tsx

This file was deleted.

5 changes: 0 additions & 5 deletions packages/zarm/src/alert/index.ts

This file was deleted.

8 changes: 0 additions & 8 deletions packages/zarm/src/alert/interface.ts

This file was deleted.

3 changes: 0 additions & 3 deletions packages/zarm/src/alert/locale/en_US.tsx

This file was deleted.

3 changes: 0 additions & 3 deletions packages/zarm/src/alert/locale/zh_CN.tsx

This file was deleted.

7 changes: 0 additions & 7 deletions packages/zarm/src/alert/style/component.scss

This file was deleted.

2 changes: 0 additions & 2 deletions packages/zarm/src/alert/style/index.scss

This file was deleted.

3 changes: 0 additions & 3 deletions packages/zarm/src/alert/style/index.tsx

This file was deleted.

20 changes: 9 additions & 11 deletions packages/zarm/src/config-provider/locale/en_US.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import ActionSheet from '../../action-sheet/locale/en_US';
import Alert from '../../alert/locale/en_US';
import Confirm from '../../confirm/locale/en_US';
import DatePicker from '../../date-picker/locale/en_US';
import Calendar from '../../calendar/locale/en_US';
import CascaderView from '../../cascader-view/locale/en_US';
import Cascader from '../../cascader/locale/en_US';
import DatePickerView from '../../date-picker-view/locale/en_US';
import DatePicker from '../../date-picker/locale/en_US';
import DateSelect from '../../date-select/locale/en_US';
import ImagePreview from '../../image-preview/locale/en_US';
import Image from '../../image/locale/en_US';
import Keyboard from '../../keyboard/locale/en_US';
import Modal from '../../modal/locale/en_US';
import Picker from '../../picker/locale/en_US';
import Cascader from '../../cascader/locale/en_US';
import CascaderView from '../../cascader-view/locale/en_US';
import Pull from '../../pull/locale/en_US';
import SearchBar from '../../search-bar/locale/en_US';
import Select from '../../select/locale/en_US';
import Keyboard from '../../keyboard/locale/en_US';
import ImagePreview from '../../image-preview/locale/en_US';
import Image from '../../image/locale/en_US';
import Calendar from '../../calendar/locale/en_US';

export default {
locale: 'en-US',
ActionSheet,
Alert,
Confirm,
Modal,
DatePicker,
DatePickerView,
DateSelect,
Expand Down
20 changes: 9 additions & 11 deletions packages/zarm/src/config-provider/locale/zh_CN.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import ActionSheet from '../../action-sheet/locale/zh_CN';
import Alert from '../../alert/locale/zh_CN';
import Confirm from '../../confirm/locale/zh_CN';
import DatePicker from '../../date-picker/locale/zh_CN';
import Calendar from '../../calendar/locale/zh_CN';
import CascaderView from '../../cascader-view/locale/zh_CN';
import Cascader from '../../cascader/locale/zh_CN';
import DatePickerView from '../../date-picker-view/locale/zh_CN';
import DatePicker from '../../date-picker/locale/zh_CN';
import DateSelect from '../../date-select/locale/zh_CN';
import ImagePreview from '../../image-preview/locale/zh_CN';
import Image from '../../image/locale/zh_CN';
import Keyboard from '../../keyboard/locale/zh_CN';
import Modal from '../../modal/locale/zh_CN';
import Picker from '../../picker/locale/zh_CN';
import Cascader from '../../cascader/locale/zh_CN';
import CascaderView from '../../cascader-view/locale/zh_CN';
import Pull from '../../pull/locale/zh_CN';
import SearchBar from '../../search-bar/locale/zh_CN';
import Select from '../../select/locale/zh_CN';
import Keyboard from '../../keyboard/locale/zh_CN';
import ImagePreview from '../../image-preview/locale/zh_CN';
import Image from '../../image/locale/zh_CN';
import Calendar from '../../calendar/locale/zh_CN';

export default {
locale: 'zh-CN',
ActionSheet,
Alert,
Confirm,
Modal,
DatePicker,
DatePickerView,
DateSelect,
Expand Down
47 changes: 0 additions & 47 deletions packages/zarm/src/confirm/Confirm.tsx

This file was deleted.

5 changes: 0 additions & 5 deletions packages/zarm/src/confirm/index.ts

This file was deleted.

10 changes: 0 additions & 10 deletions packages/zarm/src/confirm/interface.ts

This file was deleted.

7 changes: 0 additions & 7 deletions packages/zarm/src/confirm/style/component.scss

This file was deleted.

2 changes: 0 additions & 2 deletions packages/zarm/src/confirm/style/index.scss

This file was deleted.

3 changes: 0 additions & 3 deletions packages/zarm/src/confirm/style/index.tsx

This file was deleted.

8 changes: 2 additions & 6 deletions packages/zarm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ export { default as ActionSheet } from './action-sheet';
export type { ActionSheetCssVars, ActionSheetItemProps, ActionSheetProps } from './action-sheet';
export { default as Affix } from './affix';
export type { AffixCssVars, AffixProps } from './affix';
// export { default as Alert } from './alert';
export type { AlertProps } from './alert';
export { default as BackTop } from './back-top';
export type { BackTopCssVars, BackTopProps } from './back-top';
export { default as Badge } from './badge';
Expand All @@ -30,13 +28,11 @@ export { default as Collapse } from './collapse';
export type { CollapseItemProps, CollapseProps } from './collapse';
export { default as ConfigProvider } from './config-provider';
export type { ConfigProviderProps } from './config-provider';
export type { ConfirmProps } from './confirm';
export { default as CustomInput } from './custom-input';
export type { CustomInputCssVars, CustomInputProps } from './custom-input';
export { default as DatePicker } from './date-picker';
export type { DatePickerProps } from './date-picker';
export { default as DatePickerView } from './date-picker-view';
// export { default as Confirm } from './confirm';
export type { DatePickerViewProps } from './date-picker-view';
export { default as DateSelect } from './date-select';
export type { DateSelectProps } from './date-select';
Expand Down Expand Up @@ -66,7 +62,7 @@ export type { MaskCssVars, MaskProps } from './mask';
export { default as Message } from './message';
export type { MessageCssVars, MessageProps } from './message';
export { default as Modal } from './modal';
export type { ModalCssVars, ModalProps } from './modal';
export type { ModalCssVars, ModalProps, ModalShowProps, ModalAlertProps, ModalConfirmProps } from './modal';
export { default as NavBar } from './nav-bar';
export type { NavBarCssVars, NavBarProps } from './nav-bar';
export { default as NoticeBar } from './notice-bar';
Expand All @@ -81,7 +77,7 @@ export { default as PinchZoom } from './pinch-zoom';
export type { PinchZoomProps } from './pinch-zoom';
export { default as Popper } from './popper';
export { default as Popup } from './popup';
export type { PopupProps } from './popup';
export type { PopupProps, PopupShowProps } from './popup';
export { default as Progress } from './progress';
export type { ProgressCssVars, ProgressProps } from './progress';
export { default as Pull } from './pull';
Expand Down
43 changes: 28 additions & 15 deletions packages/zarm/src/modal/Alert.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
import { createBEM } from '@zarm-design/bem';
import * as React from 'react';
import type { AlertProps } from '../alert';
import Alert from '../alert';
import { renderImperatively } from '../utils/dom';
import { getRuntimeConfig } from '../config-provider';
import { ModalShowProps, show } from './methods';

const alert = (props: Omit<AlertProps, 'visible'>) => {
export interface ModalAlertProps extends Omit<ModalShowProps, 'actions'> {
confirmText?: React.ReactNode;
onConfirm?: () => boolean | void | Promise<boolean | void>;
}

export const alert = (props: ModalAlertProps) => {
const { className, animationType = 'zoom', confirmText, onConfirm, ...rest } = props;
const { prefixCls, locale } = getRuntimeConfig();
const bem = createBEM('alert', { prefixCls });
return new Promise((resolve) => {
const { close } = renderImperatively(
<Alert
{...props}
onConfirm={async () => {
const result = await props.onConfirm?.();
if (result === false) return;
close();
resolve(null);
}}
/>,
);
const { close } = show({
...rest,
className: bem([className]),
animationType,
actions: [
{
text: confirmText || locale?.Modal.confirmText,
onClick: async () => {
const result = await props.onConfirm?.();
if (result === false) return;
close();
resolve(null);
},
},
],
});
});
};

Expand Down
Loading