@bifrostui/react 1.2.9-beta.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Calendar/Calendar.js +48 -2
- package/dist/Calendar/Calendar.types.d.ts +12 -0
- package/dist/Countdown/Countdown.js +3 -0
- package/dist/Dialog/Dialog.d.ts +5 -0
- package/dist/Dialog/Dialog.js +140 -0
- package/dist/Dialog/Dialog.types.d.ts +98 -0
- package/dist/Dialog/Dialog.types.js +15 -0
- package/dist/Dialog/FunctionalDialog.d.ts +3 -0
- package/dist/Dialog/FunctionalDialog.js +168 -0
- package/dist/Dialog/index.css +66 -0
- package/dist/Dialog/index.d.ts +2 -0
- package/dist/Dialog/index.js +41 -0
- package/dist/Modal/Modal.miniapp.d.ts +1 -1
- package/dist/Radio/Radio.js +1 -1
- package/dist/Radio/RadioButtonIcon.d.ts +1 -6
- package/dist/Radio/RadioButtonIcon.js +0 -3
- package/dist/Toast/FunctionalToast.d.ts +3 -0
- package/dist/Toast/FunctionalToast.js +159 -0
- package/dist/Toast/Toast.css +55 -0
- package/dist/Toast/Toast.d.ts +5 -0
- package/dist/Toast/Toast.js +117 -0
- package/dist/Toast/Toast.types.d.ts +87 -0
- package/dist/Toast/Toast.types.js +15 -0
- package/dist/Toast/index.d.ts +2 -0
- package/dist/Toast/index.js +41 -0
- package/dist/Transition/Transition.miniapp.js +7 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -1
- package/es/Calendar/Calendar.js +54 -3
- package/es/Calendar/Calendar.types.d.ts +12 -0
- package/es/Countdown/Countdown.js +3 -0
- package/es/Dialog/Dialog.d.ts +5 -0
- package/es/Dialog/Dialog.js +113 -0
- package/es/Dialog/Dialog.types.d.ts +98 -0
- package/es/Dialog/Dialog.types.js +1 -0
- package/es/Dialog/FunctionalDialog.d.ts +3 -0
- package/es/Dialog/FunctionalDialog.js +141 -0
- package/es/Dialog/index.css +66 -0
- package/es/Dialog/index.d.ts +2 -0
- package/es/Dialog/index.js +6 -0
- package/es/Modal/Modal.miniapp.d.ts +1 -1
- package/es/Radio/Radio.js +1 -1
- package/es/Radio/RadioButtonIcon.d.ts +1 -6
- package/es/Radio/RadioButtonIcon.js +0 -3
- package/es/Toast/FunctionalToast.d.ts +3 -0
- package/es/Toast/FunctionalToast.js +132 -0
- package/es/Toast/Toast.css +55 -0
- package/es/Toast/Toast.d.ts +5 -0
- package/es/Toast/Toast.js +95 -0
- package/es/Toast/Toast.types.d.ts +87 -0
- package/es/Toast/Toast.types.js +1 -0
- package/es/Toast/index.d.ts +2 -0
- package/es/Toast/index.js +6 -0
- package/es/Transition/Transition.miniapp.js +7 -1
- package/es/index.d.ts +2 -0
- package/es/index.js +2 -0
- package/package.json +5 -5
|
@@ -67,6 +67,7 @@ var import_isoWeek = __toESM(require("dayjs/plugin/isoWeek"));
|
|
|
67
67
|
var import_react = __toESM(require("react"));
|
|
68
68
|
var import_Calendar = require("./Calendar.css");
|
|
69
69
|
var import_utils2 = require("./utils");
|
|
70
|
+
const Picker = (0, import_react.lazy)(() => import("../Picker"));
|
|
70
71
|
import_dayjs.default.extend(import_isoWeek.default);
|
|
71
72
|
const SUNDAY_WEEK_DATA = ["\u65E5", "\u4E00", "\u4E8C", "\u4E09", "\u56DB", "\u4E94", "\u516D"];
|
|
72
73
|
const classes = {
|
|
@@ -87,10 +88,12 @@ const Calendar = /* @__PURE__ */ import_react.default.forwardRef(
|
|
|
87
88
|
mode,
|
|
88
89
|
hideDaysOutsideCurrentMonth,
|
|
89
90
|
disabledDate,
|
|
91
|
+
enableSelectYear,
|
|
90
92
|
highlightDate,
|
|
91
93
|
dateRender,
|
|
92
94
|
weekRender,
|
|
93
95
|
onMonthChange,
|
|
96
|
+
onYearChange,
|
|
94
97
|
onChange
|
|
95
98
|
} = _a, others = __objRest(_a, [
|
|
96
99
|
"className",
|
|
@@ -101,10 +104,12 @@ const Calendar = /* @__PURE__ */ import_react.default.forwardRef(
|
|
|
101
104
|
"mode",
|
|
102
105
|
"hideDaysOutsideCurrentMonth",
|
|
103
106
|
"disabledDate",
|
|
107
|
+
"enableSelectYear",
|
|
104
108
|
"highlightDate",
|
|
105
109
|
"dateRender",
|
|
106
110
|
"weekRender",
|
|
107
111
|
"onMonthChange",
|
|
112
|
+
"onYearChange",
|
|
108
113
|
"onChange"
|
|
109
114
|
]);
|
|
110
115
|
const isRangeMode = mode === "range";
|
|
@@ -115,6 +120,7 @@ const Calendar = /* @__PURE__ */ import_react.default.forwardRef(
|
|
|
115
120
|
minDate,
|
|
116
121
|
maxDate
|
|
117
122
|
);
|
|
123
|
+
const [openPicker, setOpenPicker] = (0, import_react.useState)(false);
|
|
118
124
|
const [renderMonth, setRenderMonth] = (0, import_react.useState)(() => {
|
|
119
125
|
const initMonth = formattedValue === void 0 ? formattedDefaultValue == null ? void 0 : formattedDefaultValue[0] : formattedValue == null ? void 0 : formattedValue[0];
|
|
120
126
|
return (0, import_dayjs.default)(initMonth || minDate).toDate();
|
|
@@ -177,6 +183,19 @@ const Calendar = /* @__PURE__ */ import_react.default.forwardRef(
|
|
|
177
183
|
});
|
|
178
184
|
return list;
|
|
179
185
|
};
|
|
186
|
+
const getYearsList = () => {
|
|
187
|
+
const result = [];
|
|
188
|
+
let startTime = new Date(minDate).getFullYear();
|
|
189
|
+
const endTime = new Date(maxDate).getFullYear();
|
|
190
|
+
while (endTime - startTime >= 0) {
|
|
191
|
+
result.push({
|
|
192
|
+
label: startTime,
|
|
193
|
+
value: startTime
|
|
194
|
+
});
|
|
195
|
+
startTime += 1;
|
|
196
|
+
}
|
|
197
|
+
return result;
|
|
198
|
+
};
|
|
180
199
|
const getDayClassName = ({ day: itemDate, disabled }) => {
|
|
181
200
|
let result = "";
|
|
182
201
|
if (disabled)
|
|
@@ -269,6 +288,23 @@ const Calendar = /* @__PURE__ */ import_react.default.forwardRef(
|
|
|
269
288
|
});
|
|
270
289
|
}
|
|
271
290
|
};
|
|
291
|
+
const onClickDate = (e) => {
|
|
292
|
+
if (!enableSelectYear) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
e.stopPropagation();
|
|
296
|
+
setOpenPicker(true);
|
|
297
|
+
getYearsList();
|
|
298
|
+
};
|
|
299
|
+
const onClosePicker = (e, data2) => {
|
|
300
|
+
const selectYear = data2.value[0];
|
|
301
|
+
e.stopPropagation();
|
|
302
|
+
setRenderMonth((0, import_dayjs.default)(renderMonth).set("year", selectYear).toDate());
|
|
303
|
+
onYearChange == null ? void 0 : onYearChange(e, {
|
|
304
|
+
year: selectYear
|
|
305
|
+
});
|
|
306
|
+
setOpenPicker(false);
|
|
307
|
+
};
|
|
272
308
|
let data = {};
|
|
273
309
|
if (isRangeMode) {
|
|
274
310
|
data = {
|
|
@@ -296,7 +332,7 @@ const Calendar = /* @__PURE__ */ import_react.default.forwardRef(
|
|
|
296
332
|
className: `${classes.handler}-btn-icon`,
|
|
297
333
|
htmlColor: isMinMonth && "#cccccc"
|
|
298
334
|
}
|
|
299
|
-
)), /* @__PURE__ */ import_react.default.createElement("div", { className: `${classes.handler}-text
|
|
335
|
+
)), /* @__PURE__ */ import_react.default.createElement("div", { className: `${classes.handler}-text`, onClick: onClickDate }, (0, import_dayjs.default)(renderMonth).format("YYYY/MM")), /* @__PURE__ */ import_react.default.createElement("div", { onClick: onClickNext, className: `${classes.handler}-btn` }, /* @__PURE__ */ import_react.default.createElement(
|
|
300
336
|
import_icons.CaretRightIcon,
|
|
301
337
|
{
|
|
302
338
|
className: `${classes.handler}-btn-icon`,
|
|
@@ -306,13 +342,23 @@ const Calendar = /* @__PURE__ */ import_react.default.forwardRef(
|
|
|
306
342
|
/* @__PURE__ */ import_react.default.createElement("div", { className: classes.week }, SUNDAY_WEEK_DATA == null ? void 0 : SUNDAY_WEEK_DATA.map((w) => {
|
|
307
343
|
return weekRender ? weekRender(w) : /* @__PURE__ */ import_react.default.createElement("div", { key: w, className: `${classes.week}-item` }, w);
|
|
308
344
|
})),
|
|
309
|
-
/* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_clsx.default)(`${classes.root}-month`) }, renderDayList())
|
|
345
|
+
/* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_clsx.default)(`${classes.root}-month`) }, renderDayList()),
|
|
346
|
+
enableSelectYear && /* @__PURE__ */ import_react.default.createElement(import_react.Suspense, { fallback: null }, /* @__PURE__ */ import_react.default.createElement(
|
|
347
|
+
Picker,
|
|
348
|
+
{
|
|
349
|
+
options: [getYearsList()],
|
|
350
|
+
open: openPicker,
|
|
351
|
+
value: [(0, import_dayjs.default)(renderMonth).year()],
|
|
352
|
+
onClose: onClosePicker
|
|
353
|
+
}
|
|
354
|
+
))
|
|
310
355
|
);
|
|
311
356
|
}
|
|
312
357
|
);
|
|
313
358
|
Calendar.displayName = "BuiCalendar";
|
|
314
359
|
Calendar.defaultProps = {
|
|
315
360
|
hideDaysOutsideCurrentMonth: false,
|
|
361
|
+
enableSelectYear: false,
|
|
316
362
|
mode: "single",
|
|
317
363
|
minDate: (0, import_dayjs.default)((0, import_dayjs.default)().format("YYYYMMDD")).add(0, "month").toDate(),
|
|
318
364
|
maxDate: (0, import_dayjs.default)((0, import_dayjs.default)().format("YYYYMMDD")).add(11, "month").toDate(),
|
|
@@ -12,6 +12,10 @@ export interface ICalendarMonthChangeData {
|
|
|
12
12
|
/** 操作类型,prev: 点击上个月 next: 点击下个月 */
|
|
13
13
|
type: 'prev' | 'next';
|
|
14
14
|
}
|
|
15
|
+
export interface ICalendarYearChangeData {
|
|
16
|
+
/** 切换后的年份 */
|
|
17
|
+
year: number;
|
|
18
|
+
}
|
|
15
19
|
export type ICalendarMode = 'single' | 'range';
|
|
16
20
|
export type ICalendarValue = Date | Date[] | null;
|
|
17
21
|
export type CalendarProps<D extends React.ElementType = 'div', P = {}> = OverrideProps<{
|
|
@@ -61,6 +65,14 @@ export type CalendarProps<D extends React.ElementType = 'div', P = {}> = Overrid
|
|
|
61
65
|
* 自定义周单元格的内容
|
|
62
66
|
*/
|
|
63
67
|
weekRender?: (week: string) => React.ReactNode;
|
|
68
|
+
/**
|
|
69
|
+
* 是否开启选择年
|
|
70
|
+
*/
|
|
71
|
+
enableSelectYear?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* 年份发生变化的回调
|
|
74
|
+
*/
|
|
75
|
+
onYearChange?: (e: React.SyntheticEvent, data: ICalendarYearChangeData) => void;
|
|
64
76
|
/**
|
|
65
77
|
* 月份发生变化的回调
|
|
66
78
|
*/
|
|
@@ -112,6 +112,9 @@ const Countdown = (0, import_react.forwardRef)((props, ref) => {
|
|
|
112
112
|
if (serverTimestamp && endTimestamp) {
|
|
113
113
|
setStartTime(serverTimestamp);
|
|
114
114
|
setEndTime(endTimestamp);
|
|
115
|
+
} else if (endTimestamp) {
|
|
116
|
+
setStartTime(Date.now());
|
|
117
|
+
setEndTime(endTimestamp);
|
|
115
118
|
}
|
|
116
119
|
}, [serverTimestamp, endTimestamp]);
|
|
117
120
|
const defaultRender = (timeIns) => {
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __objRest = (source, exclude) => {
|
|
25
|
+
var target = {};
|
|
26
|
+
for (var prop in source)
|
|
27
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
if (source != null && __getOwnPropSymbols)
|
|
30
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
31
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
32
|
+
target[prop] = source[prop];
|
|
33
|
+
}
|
|
34
|
+
return target;
|
|
35
|
+
};
|
|
36
|
+
var __export = (target, all) => {
|
|
37
|
+
for (var name in all)
|
|
38
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
39
|
+
};
|
|
40
|
+
var __copyProps = (to, from, except, desc) => {
|
|
41
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
42
|
+
for (let key of __getOwnPropNames(from))
|
|
43
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
44
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
45
|
+
}
|
|
46
|
+
return to;
|
|
47
|
+
};
|
|
48
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
49
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
50
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
51
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
52
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
53
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
54
|
+
mod
|
|
55
|
+
));
|
|
56
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
57
|
+
var Dialog_exports = {};
|
|
58
|
+
__export(Dialog_exports, {
|
|
59
|
+
default: () => Dialog_default
|
|
60
|
+
});
|
|
61
|
+
module.exports = __toCommonJS(Dialog_exports);
|
|
62
|
+
var import_react = __toESM(require("react"));
|
|
63
|
+
var import_clsx = __toESM(require("clsx"));
|
|
64
|
+
var import_Input = require("../Input");
|
|
65
|
+
var import_Button = require("../Button");
|
|
66
|
+
var import_Modal = __toESM(require("../Modal"));
|
|
67
|
+
var import_index = require("./index.css");
|
|
68
|
+
const prefixCls = "bui-dialog";
|
|
69
|
+
const Dialog = /* @__PURE__ */ import_react.default.forwardRef((props, ref) => {
|
|
70
|
+
const _a = props, {
|
|
71
|
+
open,
|
|
72
|
+
onOk,
|
|
73
|
+
onClose,
|
|
74
|
+
header,
|
|
75
|
+
message,
|
|
76
|
+
type,
|
|
77
|
+
confirmText,
|
|
78
|
+
cancelText,
|
|
79
|
+
placeholder,
|
|
80
|
+
InputProps,
|
|
81
|
+
className
|
|
82
|
+
} = _a, others = __objRest(_a, [
|
|
83
|
+
"open",
|
|
84
|
+
"onOk",
|
|
85
|
+
"onClose",
|
|
86
|
+
"header",
|
|
87
|
+
"message",
|
|
88
|
+
"type",
|
|
89
|
+
"confirmText",
|
|
90
|
+
"cancelText",
|
|
91
|
+
"placeholder",
|
|
92
|
+
"InputProps",
|
|
93
|
+
"className"
|
|
94
|
+
]);
|
|
95
|
+
const InputRef = (0, import_react.useRef)(null);
|
|
96
|
+
const footerNode = /* @__PURE__ */ import_react.default.createElement("div", { className: `${prefixCls}-body-footer` }, /* @__PURE__ */ import_react.default.createElement(
|
|
97
|
+
import_Button.Button,
|
|
98
|
+
{
|
|
99
|
+
variant: "text",
|
|
100
|
+
onClick: onClose,
|
|
101
|
+
className: `${prefixCls}-body-button`
|
|
102
|
+
},
|
|
103
|
+
cancelText || "\u53D6\u6D88"
|
|
104
|
+
), /* @__PURE__ */ import_react.default.createElement(
|
|
105
|
+
import_Button.Button,
|
|
106
|
+
{
|
|
107
|
+
variant: "text",
|
|
108
|
+
color: "primary",
|
|
109
|
+
onClick: () => {
|
|
110
|
+
var _a2;
|
|
111
|
+
onOk((_a2 = InputRef == null ? void 0 : InputRef.current) == null ? void 0 : _a2.value);
|
|
112
|
+
},
|
|
113
|
+
className: `${prefixCls}-body-button`
|
|
114
|
+
},
|
|
115
|
+
confirmText || "\u786E\u5B9A"
|
|
116
|
+
));
|
|
117
|
+
const inputNode = type === "prompt" && /* @__PURE__ */ import_react.default.createElement(
|
|
118
|
+
import_Input.Input,
|
|
119
|
+
__spreadProps(__spreadValues({}, InputProps), {
|
|
120
|
+
inputRef: InputRef,
|
|
121
|
+
className: `${prefixCls}-body-input`,
|
|
122
|
+
placeholder: `${placeholder || "\u8BF7\u5728\u6B64\u5904\u8F93\u5165"}`
|
|
123
|
+
})
|
|
124
|
+
);
|
|
125
|
+
if (!open)
|
|
126
|
+
return null;
|
|
127
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
128
|
+
import_Modal.default,
|
|
129
|
+
__spreadProps(__spreadValues({}, others), {
|
|
130
|
+
open: true,
|
|
131
|
+
className: (0, import_clsx.default)(prefixCls, className),
|
|
132
|
+
disablePortal: true,
|
|
133
|
+
onClose,
|
|
134
|
+
ref
|
|
135
|
+
}),
|
|
136
|
+
/* @__PURE__ */ import_react.default.createElement("div", { className: `${prefixCls}-body` }, header && /* @__PURE__ */ import_react.default.createElement("h1", { className: `${prefixCls}-body-title` }, header), message && /* @__PURE__ */ import_react.default.createElement("div", { className: `${prefixCls}-body-desc` }, message), inputNode, footerNode)
|
|
137
|
+
);
|
|
138
|
+
});
|
|
139
|
+
Dialog.displayName = "BuiDialog";
|
|
140
|
+
var Dialog_default = Dialog;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { ModalProps } from '../Modal/Modal.types';
|
|
3
|
+
import { InputProps } from '../Input/Input.types';
|
|
4
|
+
/**
|
|
5
|
+
* 对话框类型
|
|
6
|
+
*/
|
|
7
|
+
export type DialogType = 'confirm' | 'prompt';
|
|
8
|
+
export type Dispatch = (action: boolean, val?: string) => void;
|
|
9
|
+
export interface DialogProps extends ModalProps {
|
|
10
|
+
/**
|
|
11
|
+
* 对话框类型
|
|
12
|
+
* @default confirm
|
|
13
|
+
*/
|
|
14
|
+
type?: DialogType;
|
|
15
|
+
/**
|
|
16
|
+
* 自定义标题
|
|
17
|
+
*/
|
|
18
|
+
header?: ReactNode;
|
|
19
|
+
/**
|
|
20
|
+
* 自定义内容
|
|
21
|
+
*/
|
|
22
|
+
message?: ReactNode;
|
|
23
|
+
/**
|
|
24
|
+
* 输入框占位文本
|
|
25
|
+
*/
|
|
26
|
+
placeholder?: string;
|
|
27
|
+
/**
|
|
28
|
+
* 透传给内部Input组件的属性
|
|
29
|
+
*/
|
|
30
|
+
InputProps?: Partial<InputProps>;
|
|
31
|
+
/**
|
|
32
|
+
* 确认文本内容
|
|
33
|
+
*/
|
|
34
|
+
confirmText?: ReactNode;
|
|
35
|
+
/**
|
|
36
|
+
* 取消文本内容
|
|
37
|
+
*/
|
|
38
|
+
cancelText?: ReactNode;
|
|
39
|
+
/**
|
|
40
|
+
* 确认回调
|
|
41
|
+
*/
|
|
42
|
+
onOk?: (val?: string) => void;
|
|
43
|
+
/**
|
|
44
|
+
* 取消回调
|
|
45
|
+
*/
|
|
46
|
+
onClose?: () => void;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 函数式调用配置参数
|
|
50
|
+
*/
|
|
51
|
+
export type DialogOptions = Omit<DialogProps, 'placeholder' | 'inputProps' | 'onOk' | 'onClose'> & {
|
|
52
|
+
/**
|
|
53
|
+
* 确认回调
|
|
54
|
+
*/
|
|
55
|
+
onConfirm?: (val?: string) => void | Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* 取消回调
|
|
58
|
+
*/
|
|
59
|
+
onCancel?: () => void | Promise<void>;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* prompt函数式调用配置参数
|
|
63
|
+
*/
|
|
64
|
+
export type PromptOptions = (DialogOptions & {
|
|
65
|
+
/**
|
|
66
|
+
* 输入框占位文本
|
|
67
|
+
*/
|
|
68
|
+
placeholder?: string;
|
|
69
|
+
/**
|
|
70
|
+
* 内部<input>标签的标准属性
|
|
71
|
+
*/
|
|
72
|
+
inputProps?: React.InputHTMLAttributes<HTMLInputElement>;
|
|
73
|
+
}) | string;
|
|
74
|
+
/**
|
|
75
|
+
* confirm函数式调用配置参数
|
|
76
|
+
*/
|
|
77
|
+
export type ConfirmOptions = DialogOptions | string;
|
|
78
|
+
/**
|
|
79
|
+
* Dialog函数式调用返回值类型
|
|
80
|
+
*/
|
|
81
|
+
export type DialogPromise = Promise<boolean | string>;
|
|
82
|
+
/**
|
|
83
|
+
* Dialog Instance
|
|
84
|
+
*/
|
|
85
|
+
export interface DialogInstance {
|
|
86
|
+
/**
|
|
87
|
+
* 直接调用显示确认框 Dialog
|
|
88
|
+
*/
|
|
89
|
+
(options: ConfirmOptions): DialogPromise;
|
|
90
|
+
/**
|
|
91
|
+
* 显示确认框 Dialog.confirm
|
|
92
|
+
*/
|
|
93
|
+
confirm?: (options: ConfirmOptions) => DialogPromise;
|
|
94
|
+
/**
|
|
95
|
+
* 显示提示对话框 Dialog.prompt
|
|
96
|
+
*/
|
|
97
|
+
prompt?: (options: PromptOptions, val?: string) => DialogPromise;
|
|
98
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var Dialog_types_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(Dialog_types_exports);
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __objRest = (source, exclude) => {
|
|
25
|
+
var target = {};
|
|
26
|
+
for (var prop in source)
|
|
27
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
if (source != null && __getOwnPropSymbols)
|
|
30
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
31
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
32
|
+
target[prop] = source[prop];
|
|
33
|
+
}
|
|
34
|
+
return target;
|
|
35
|
+
};
|
|
36
|
+
var __export = (target, all) => {
|
|
37
|
+
for (var name in all)
|
|
38
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
39
|
+
};
|
|
40
|
+
var __copyProps = (to, from, except, desc) => {
|
|
41
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
42
|
+
for (let key of __getOwnPropNames(from))
|
|
43
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
44
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
45
|
+
}
|
|
46
|
+
return to;
|
|
47
|
+
};
|
|
48
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
49
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
50
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
51
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
52
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
53
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
54
|
+
mod
|
|
55
|
+
));
|
|
56
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
57
|
+
var __async = (__this, __arguments, generator) => {
|
|
58
|
+
return new Promise((resolve, reject) => {
|
|
59
|
+
var fulfilled = (value) => {
|
|
60
|
+
try {
|
|
61
|
+
step(generator.next(value));
|
|
62
|
+
} catch (e) {
|
|
63
|
+
reject(e);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var rejected = (value) => {
|
|
67
|
+
try {
|
|
68
|
+
step(generator.throw(value));
|
|
69
|
+
} catch (e) {
|
|
70
|
+
reject(e);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
74
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
var FunctionalDialog_exports = {};
|
|
78
|
+
__export(FunctionalDialog_exports, {
|
|
79
|
+
default: () => FunctionalDialog_default
|
|
80
|
+
});
|
|
81
|
+
module.exports = __toCommonJS(FunctionalDialog_exports);
|
|
82
|
+
var import_react = __toESM(require("react"));
|
|
83
|
+
var import_utils = require("@bifrostui/utils");
|
|
84
|
+
var import_Dialog = __toESM(require("./Dialog"));
|
|
85
|
+
const { isValidElement, Component } = import_react.default;
|
|
86
|
+
const formatProps = (props) => {
|
|
87
|
+
if (typeof props === "string" || isValidElement(props)) {
|
|
88
|
+
return { message: props };
|
|
89
|
+
}
|
|
90
|
+
return props;
|
|
91
|
+
};
|
|
92
|
+
const DialogGenerator = (options) => {
|
|
93
|
+
const rootWrapper = document.createElement("div");
|
|
94
|
+
const rootElement = (0, import_utils.getRootElement)();
|
|
95
|
+
rootElement.appendChild(rootWrapper);
|
|
96
|
+
const DialogComponent = () => {
|
|
97
|
+
const _a = options, { onConfirm, onCancel } = _a, others = __objRest(_a, ["onConfirm", "onCancel"]);
|
|
98
|
+
const [visible, setVisible] = (0, import_react.useState)(false);
|
|
99
|
+
const close = (0, import_react.useCallback)(() => {
|
|
100
|
+
setVisible(false);
|
|
101
|
+
setTimeout(() => {
|
|
102
|
+
const unmountRes = (0, import_utils.unmount)(rootWrapper);
|
|
103
|
+
if (unmountRes && rootWrapper.parentNode) {
|
|
104
|
+
rootWrapper.parentNode.removeChild(rootWrapper);
|
|
105
|
+
}
|
|
106
|
+
}, 150);
|
|
107
|
+
}, [rootWrapper]);
|
|
108
|
+
(0, import_react.useEffect)(() => {
|
|
109
|
+
setVisible(true);
|
|
110
|
+
}, []);
|
|
111
|
+
const dispatch = (action, val) => __async(void 0, null, function* () {
|
|
112
|
+
if (action === true) {
|
|
113
|
+
try {
|
|
114
|
+
yield onConfirm == null ? void 0 : onConfirm(val);
|
|
115
|
+
} catch (error) {
|
|
116
|
+
}
|
|
117
|
+
} else if (action === false) {
|
|
118
|
+
try {
|
|
119
|
+
yield onCancel == null ? void 0 : onCancel();
|
|
120
|
+
} catch (error) {
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
close();
|
|
124
|
+
});
|
|
125
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
126
|
+
import_Dialog.default,
|
|
127
|
+
__spreadProps(__spreadValues({}, others), {
|
|
128
|
+
open: visible,
|
|
129
|
+
onOk: (val) => dispatch(true, val),
|
|
130
|
+
onClose: () => dispatch(false)
|
|
131
|
+
})
|
|
132
|
+
);
|
|
133
|
+
};
|
|
134
|
+
return (0, import_utils.render)(/* @__PURE__ */ import_react.default.createElement(DialogComponent, null), rootWrapper);
|
|
135
|
+
};
|
|
136
|
+
const Dialog = (props) => {
|
|
137
|
+
const options = formatProps(props);
|
|
138
|
+
const _a = options, { onConfirm, onCancel } = _a, rest = __objRest(_a, ["onConfirm", "onCancel"]);
|
|
139
|
+
return new Promise((resolve) => {
|
|
140
|
+
DialogGenerator(__spreadProps(__spreadValues({}, rest), {
|
|
141
|
+
onConfirm: (val) => __async(void 0, null, function* () {
|
|
142
|
+
yield onConfirm == null ? void 0 : onConfirm(val);
|
|
143
|
+
if (rest.type === "prompt")
|
|
144
|
+
resolve(val);
|
|
145
|
+
else
|
|
146
|
+
resolve(true);
|
|
147
|
+
}),
|
|
148
|
+
onCancel: () => __async(void 0, null, function* () {
|
|
149
|
+
yield onCancel == null ? void 0 : onCancel();
|
|
150
|
+
resolve(false);
|
|
151
|
+
})
|
|
152
|
+
}));
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
Dialog.prototype = Component.prototype;
|
|
156
|
+
const confirm = (options) => {
|
|
157
|
+
return Dialog(__spreadValues({
|
|
158
|
+
type: "confirm"
|
|
159
|
+
}, formatProps(options)));
|
|
160
|
+
};
|
|
161
|
+
const prompt = (options) => {
|
|
162
|
+
return Dialog(__spreadValues({
|
|
163
|
+
type: "prompt"
|
|
164
|
+
}, formatProps(options)));
|
|
165
|
+
};
|
|
166
|
+
Dialog.confirm = confirm;
|
|
167
|
+
Dialog.prompt = prompt;
|
|
168
|
+
var FunctionalDialog_default = Dialog;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
.bui-dialog {
|
|
2
|
+
--max-width: 300px;
|
|
3
|
+
--border-radius: var(--bui-shape-radius-drawer);
|
|
4
|
+
--header-font-size: var(--bui-title-size-2);
|
|
5
|
+
--message-font-size: var(--bui-title-size-4);
|
|
6
|
+
display: flex;
|
|
7
|
+
align-items: center;
|
|
8
|
+
justify-content: center;
|
|
9
|
+
}
|
|
10
|
+
.bui-dialog-body {
|
|
11
|
+
padding-top: 21px;
|
|
12
|
+
min-width: var(--max-width);
|
|
13
|
+
margin: 0 auto;
|
|
14
|
+
border-radius: var(--border-radius);
|
|
15
|
+
background-clip: padding-box;
|
|
16
|
+
background-color: var(--bui-color-bg-view);
|
|
17
|
+
line-height: 21px;
|
|
18
|
+
}
|
|
19
|
+
.bui-dialog-body-title {
|
|
20
|
+
padding: 0 40px 9px;
|
|
21
|
+
font-size: var(--header-font-size);
|
|
22
|
+
text-align: center;
|
|
23
|
+
color: var(--bui-color-fg-default);
|
|
24
|
+
font-weight: 500;
|
|
25
|
+
}
|
|
26
|
+
.bui-dialog-body-title + .bui-dialog-body-footer {
|
|
27
|
+
margin-top: 6px;
|
|
28
|
+
}
|
|
29
|
+
.bui-dialog-body-desc {
|
|
30
|
+
padding: 0 24px;
|
|
31
|
+
color: var(--bui-color-fg-muted);
|
|
32
|
+
font-size: var(--message-font-size);
|
|
33
|
+
text-align: center;
|
|
34
|
+
}
|
|
35
|
+
.bui-dialog-body-desc:first-child {
|
|
36
|
+
padding-top: 0;
|
|
37
|
+
}
|
|
38
|
+
.bui-dialog-body-footer {
|
|
39
|
+
margin-top: 15px;
|
|
40
|
+
border-top: 1px solid rgba(0, 0, 0, 0.05);
|
|
41
|
+
display: -webkit-box;
|
|
42
|
+
display: flex;
|
|
43
|
+
}
|
|
44
|
+
.bui-dialog-body-input {
|
|
45
|
+
width: calc(100% - 48px);
|
|
46
|
+
margin: 14px 24px 0;
|
|
47
|
+
}
|
|
48
|
+
.bui-dialog-body-button {
|
|
49
|
+
flex: 1;
|
|
50
|
+
display: block;
|
|
51
|
+
width: 100%;
|
|
52
|
+
height: 53px;
|
|
53
|
+
line-height: 25px;
|
|
54
|
+
padding: 12px 0 13px;
|
|
55
|
+
font-size: 17px;
|
|
56
|
+
background: 0 0;
|
|
57
|
+
border: 0;
|
|
58
|
+
outline: 0;
|
|
59
|
+
border-left: 1px solid rgba(0, 0, 0, 0.05);
|
|
60
|
+
border-radius: 0;
|
|
61
|
+
text-align: center;
|
|
62
|
+
box-sizing: border-box;
|
|
63
|
+
}
|
|
64
|
+
.bui-dialog-body-button:active {
|
|
65
|
+
background-color: rgba(54, 57, 64, 0.05);
|
|
66
|
+
}
|