@bifrostui/react 1.0.4 → 1.1.1
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/CitySelector/CitySelector.css +102 -0
- package/dist/CitySelector/CitySelector.d.ts +4 -0
- package/dist/CitySelector/CitySelector.js +36 -0
- package/dist/CitySelector/CitySelector.miniapp.d.ts +5 -0
- package/dist/CitySelector/CitySelector.miniapp.js +79 -0
- package/dist/CitySelector/CitySelector.types.d.ts +47 -0
- package/dist/CitySelector/CitySelector.types.js +5 -0
- package/dist/CitySelector/CitySelectorCore.d.ts +5 -0
- package/dist/CitySelector/CitySelectorCore.js +184 -0
- package/dist/CitySelector/Selector/index.css +11 -0
- package/dist/CitySelector/Selector/index.d.ts +9 -0
- package/dist/CitySelector/Selector/index.js +22 -0
- package/dist/CitySelector/index.d.ts +2 -0
- package/dist/CitySelector/index.js +34 -0
- package/dist/CitySelector/miniapp.css +4 -0
- package/dist/Modal/Modal.miniapp.d.ts +16 -0
- package/dist/Modal/Modal.miniapp.js +73 -0
- package/dist/Picker/Picker.css +53 -0
- package/dist/Picker/Picker.d.ts +5 -0
- package/dist/Picker/Picker.js +155 -0
- package/dist/Picker/Picker.types.d.ts +98 -0
- package/dist/Picker/Picker.types.js +5 -0
- package/dist/Picker/PickerPanel.css +54 -0
- package/dist/Picker/PickerPanel.d.ts +5 -0
- package/dist/Picker/PickerPanel.js +210 -0
- package/dist/Picker/index.d.ts +2 -0
- package/dist/Picker/index.js +34 -0
- package/dist/Picker/utils.d.ts +13 -0
- package/dist/Picker/utils.js +66 -0
- package/dist/Tabs/Tabs.css +2 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +22 -0
- package/es/CitySelector/CitySelector.css +102 -0
- package/es/CitySelector/CitySelector.d.ts +4 -0
- package/es/CitySelector/CitySelector.js +36 -0
- package/es/CitySelector/CitySelector.miniapp.d.ts +5 -0
- package/es/CitySelector/CitySelector.miniapp.js +77 -0
- package/es/CitySelector/CitySelector.types.d.ts +47 -0
- package/es/CitySelector/CitySelector.types.js +1 -0
- package/es/CitySelector/CitySelectorCore.d.ts +5 -0
- package/es/CitySelector/CitySelectorCore.js +195 -0
- package/es/CitySelector/Selector/index.css +11 -0
- package/es/CitySelector/Selector/index.d.ts +9 -0
- package/es/CitySelector/Selector/index.js +13 -0
- package/es/CitySelector/index.d.ts +2 -0
- package/es/CitySelector/index.js +2 -0
- package/es/CitySelector/miniapp.css +4 -0
- package/es/Modal/Modal.miniapp.d.ts +16 -0
- package/es/Modal/Modal.miniapp.js +78 -0
- package/es/Picker/Picker.css +53 -0
- package/es/Picker/Picker.d.ts +5 -0
- package/es/Picker/Picker.js +171 -0
- package/es/Picker/Picker.types.d.ts +98 -0
- package/es/Picker/Picker.types.js +1 -0
- package/es/Picker/PickerPanel.css +54 -0
- package/es/Picker/PickerPanel.d.ts +5 -0
- package/es/Picker/PickerPanel.js +234 -0
- package/es/Picker/index.d.ts +2 -0
- package/es/Picker/index.js +2 -0
- package/es/Picker/utils.d.ts +13 -0
- package/es/Picker/utils.js +65 -0
- package/es/Tabs/Tabs.css +2 -2
- package/es/index.d.ts +2 -0
- package/es/index.js +3 -1
- package/package.json +6 -6
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
.bui-picker {
|
|
2
|
+
--cancel-color: var(--bui-color-fg-default);
|
|
3
|
+
--cancel-font-size: var(--bui-title-size-4, 15px);
|
|
4
|
+
--confirm-color: var(--bui-color-primary);
|
|
5
|
+
--confirm-font-size: var(--bui-title-size-4, 15px);
|
|
6
|
+
--title-color: var(--bui-color-fg-default);
|
|
7
|
+
--title-font-size: var(--bui-title-size-3, 16px);
|
|
8
|
+
--title-font-weight: var(--bui-font-weight-medium, 500);
|
|
9
|
+
--panel-container-height: 260px;
|
|
10
|
+
--indicator-top: 108px;
|
|
11
|
+
--indicator-height: 36px;
|
|
12
|
+
--indicator-border-color: var(--bui-color-border-default);
|
|
13
|
+
--option-color: var(--bui-color-fg-default);
|
|
14
|
+
--option-font-size: var(--bui-title-size-4);
|
|
15
|
+
--option-height: 36px;
|
|
16
|
+
font-family: var(--bui-font-family);
|
|
17
|
+
}
|
|
18
|
+
.bui-picker .bui-drawer-content {
|
|
19
|
+
border-radius: var(--bui-shape-radius-drawer) var(--bui-shape-radius-drawer) 0 0;
|
|
20
|
+
}
|
|
21
|
+
.bui-picker-header {
|
|
22
|
+
height: 50px;
|
|
23
|
+
display: flex;
|
|
24
|
+
align-items: center;
|
|
25
|
+
justify-content: space-between;
|
|
26
|
+
padding: 0 var(--bui-spacing-lg);
|
|
27
|
+
}
|
|
28
|
+
.bui-picker-cancel {
|
|
29
|
+
width: 40px;
|
|
30
|
+
height: 100%;
|
|
31
|
+
font-size: var(--cancel-font-size);
|
|
32
|
+
text-align: center;
|
|
33
|
+
line-height: 50px;
|
|
34
|
+
color: var(--cancel-color);
|
|
35
|
+
}
|
|
36
|
+
.bui-picker-title {
|
|
37
|
+
font-size: var(--title-font-size);
|
|
38
|
+
color: var(--title-color);
|
|
39
|
+
font-weight: var(--title-font-weight);
|
|
40
|
+
}
|
|
41
|
+
.bui-picker-confirm {
|
|
42
|
+
width: 40px;
|
|
43
|
+
height: 100%;
|
|
44
|
+
font-size: var(--confirm-font-size);
|
|
45
|
+
text-align: center;
|
|
46
|
+
line-height: 50px;
|
|
47
|
+
color: var(--confirm-color);
|
|
48
|
+
}
|
|
49
|
+
.bui-picker-container {
|
|
50
|
+
width: 100%;
|
|
51
|
+
height: var(--panel-container-height);
|
|
52
|
+
display: flex;
|
|
53
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _clsx = _interopRequireDefault(require("clsx"));
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _Drawer = _interopRequireDefault(require("../Drawer"));
|
|
10
|
+
var _PickerPanel = _interopRequireDefault(require("./PickerPanel"));
|
|
11
|
+
var _utils = require("./utils");
|
|
12
|
+
require("./Picker.css");
|
|
13
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
14
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
17
|
+
const prefixCls = 'bui-picker';
|
|
18
|
+
const Picker = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
|
|
19
|
+
const {
|
|
20
|
+
className,
|
|
21
|
+
open = false,
|
|
22
|
+
title,
|
|
23
|
+
options = [],
|
|
24
|
+
value,
|
|
25
|
+
contentProps,
|
|
26
|
+
onConfirm,
|
|
27
|
+
onOptionChange,
|
|
28
|
+
onCancel,
|
|
29
|
+
onClose,
|
|
30
|
+
...others
|
|
31
|
+
} = props;
|
|
32
|
+
const pickerType = (0, _utils.pickerPanelType)(options);
|
|
33
|
+
const [columns, setColumns] = (0, _react.useState)([]);
|
|
34
|
+
const [internalValue, setInternalValue] = (0, _react.useState)([]);
|
|
35
|
+
(0, _react.useEffect)(() => {
|
|
36
|
+
if (!open) return;
|
|
37
|
+
|
|
38
|
+
// 初始化默认选中数据
|
|
39
|
+
const formatted = (0, _utils.formatOptions)(value, options);
|
|
40
|
+
const initialValue = [];
|
|
41
|
+
(formatted || []).forEach(item => {
|
|
42
|
+
initialValue.push(item?.[0]?.value);
|
|
43
|
+
});
|
|
44
|
+
const defaultValue = value?.length ? value : initialValue;
|
|
45
|
+
if (defaultValue?.length) {
|
|
46
|
+
setInternalValue(defaultValue);
|
|
47
|
+
}
|
|
48
|
+
}, [open, value, options]);
|
|
49
|
+
(0, _react.useEffect)(() => {
|
|
50
|
+
if (options?.length) {
|
|
51
|
+
const formatted = (0, _utils.formatOptions)(value, options);
|
|
52
|
+
setColumns(formatted);
|
|
53
|
+
}
|
|
54
|
+
}, [value, options]);
|
|
55
|
+
const confirm = e => {
|
|
56
|
+
const payload = {
|
|
57
|
+
value: internalValue,
|
|
58
|
+
options: columns
|
|
59
|
+
};
|
|
60
|
+
onConfirm?.(e, payload);
|
|
61
|
+
onClose?.(e, {
|
|
62
|
+
from: 'confirm',
|
|
63
|
+
...payload
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
const cancel = e => {
|
|
67
|
+
onCancel?.(e);
|
|
68
|
+
onClose?.(e, {
|
|
69
|
+
from: 'cancel',
|
|
70
|
+
value: internalValue,
|
|
71
|
+
options: columns
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
const updateItem = (e, columnOption, columnIndex) => {
|
|
75
|
+
const columnValues = internalValue?.slice(0, columnIndex) || [];
|
|
76
|
+
let colIndex = columnIndex;
|
|
77
|
+
let colOption = columnOption;
|
|
78
|
+
if (colOption && Object.keys(colOption).length) {
|
|
79
|
+
if (columnValues[columnIndex] === columnOption.value) return;
|
|
80
|
+
if (pickerType === 'cascade') {
|
|
81
|
+
columnValues[colIndex] = colOption.value || '';
|
|
82
|
+
while (colOption?.children?.[0]) {
|
|
83
|
+
columnValues[colIndex + 1] = colOption.children[0].value;
|
|
84
|
+
colIndex += 1;
|
|
85
|
+
colOption = {
|
|
86
|
+
...(colOption?.children?.[0] || {})
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
// 当前改变列的下一列 children 值为空
|
|
90
|
+
if (colOption?.children?.length) {
|
|
91
|
+
columnValues[columnIndex + 1] = '';
|
|
92
|
+
}
|
|
93
|
+
const conbineValues = [...(internalValue?.slice(0, columnIndex) || []), ...columnValues.slice(columnIndex)];
|
|
94
|
+
const formatted = (0, _utils.formatOptions)(conbineValues, options);
|
|
95
|
+
setColumns(formatted);
|
|
96
|
+
setInternalValue(conbineValues);
|
|
97
|
+
onOptionChange?.(e, {
|
|
98
|
+
value: conbineValues,
|
|
99
|
+
options: formatted,
|
|
100
|
+
currentOption: columnOption
|
|
101
|
+
});
|
|
102
|
+
} else {
|
|
103
|
+
const result = internalValue;
|
|
104
|
+
result[columnIndex] = columnOption.value;
|
|
105
|
+
setInternalValue(result);
|
|
106
|
+
onOptionChange?.(e, {
|
|
107
|
+
value: result,
|
|
108
|
+
options,
|
|
109
|
+
currentOption: columnOption
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const handleSelect = (e, {
|
|
115
|
+
columnIndex,
|
|
116
|
+
columnOption
|
|
117
|
+
}) => {
|
|
118
|
+
updateItem(e, columnOption, columnIndex);
|
|
119
|
+
};
|
|
120
|
+
const handleClose = (e, data) => {
|
|
121
|
+
onClose?.(e, {
|
|
122
|
+
value: internalValue,
|
|
123
|
+
options: columns,
|
|
124
|
+
...data
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
return /*#__PURE__*/_react.default.createElement(_Drawer.default, _extends({
|
|
128
|
+
ref: ref,
|
|
129
|
+
open: open,
|
|
130
|
+
className: (0, _clsx.default)(prefixCls, className),
|
|
131
|
+
onClose: handleClose
|
|
132
|
+
}, others), /*#__PURE__*/_react.default.createElement("div", _extends({}, contentProps, {
|
|
133
|
+
className: (0, _clsx.default)(`${prefixCls}-content`, contentProps?.className)
|
|
134
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
135
|
+
className: `${prefixCls}-header`
|
|
136
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
137
|
+
className: `${prefixCls}-cancel`,
|
|
138
|
+
onClick: cancel
|
|
139
|
+
}, "\u53D6\u6D88"), title && /*#__PURE__*/_react.default.createElement("div", {
|
|
140
|
+
className: `${prefixCls}-title`
|
|
141
|
+
}, title), /*#__PURE__*/_react.default.createElement("div", {
|
|
142
|
+
className: `${prefixCls}-confirm`,
|
|
143
|
+
onClick: confirm
|
|
144
|
+
}, "\u786E\u8BA4")), /*#__PURE__*/_react.default.createElement("div", {
|
|
145
|
+
className: `${prefixCls}-container`
|
|
146
|
+
}, columns.map((column, index) => /*#__PURE__*/_react.default.createElement(_PickerPanel.default, {
|
|
147
|
+
key: index,
|
|
148
|
+
options: column,
|
|
149
|
+
columnIndex: index,
|
|
150
|
+
defaultValue: internalValue?.[index],
|
|
151
|
+
onSelect: handleSelect
|
|
152
|
+
})))));
|
|
153
|
+
});
|
|
154
|
+
Picker.displayName = 'BuiPicker';
|
|
155
|
+
var _default = exports.default = Picker;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { OverrideProps } from '@bifrostui/types';
|
|
3
|
+
import { DrawerProps } from '../Drawer/Drawer.types';
|
|
4
|
+
export interface IPickerOptionItem {
|
|
5
|
+
/**
|
|
6
|
+
* 选项的文字内容
|
|
7
|
+
*/
|
|
8
|
+
label?: string | number;
|
|
9
|
+
/**
|
|
10
|
+
* 选项对应唯一的值
|
|
11
|
+
*/
|
|
12
|
+
value: string | number;
|
|
13
|
+
}
|
|
14
|
+
export type ICascadePickerOptionItem = IPickerOptionItem & {
|
|
15
|
+
/**
|
|
16
|
+
* 用于级联选项
|
|
17
|
+
*/
|
|
18
|
+
children?: ICascadePickerOptionItem[];
|
|
19
|
+
};
|
|
20
|
+
export type PickerProps<D extends React.ElementType = 'div', P = DrawerProps> = OverrideProps<{
|
|
21
|
+
props: P & {
|
|
22
|
+
/**
|
|
23
|
+
* 是否展示选择器
|
|
24
|
+
* @default false
|
|
25
|
+
*/
|
|
26
|
+
open?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* 标题
|
|
29
|
+
*/
|
|
30
|
+
title?: string;
|
|
31
|
+
/**
|
|
32
|
+
* 列表数据
|
|
33
|
+
* @default []
|
|
34
|
+
*/
|
|
35
|
+
options?: IPickerOptionItem[][] | ICascadePickerOptionItem[];
|
|
36
|
+
/**
|
|
37
|
+
* 选中的值
|
|
38
|
+
*/
|
|
39
|
+
value?: (string | number)[];
|
|
40
|
+
/**
|
|
41
|
+
* 内部内容DOM节点上的Props
|
|
42
|
+
*/
|
|
43
|
+
contentProps?: React.HTMLAttributes<HTMLDivElement>;
|
|
44
|
+
/**
|
|
45
|
+
* 点击确认按钮时候回调
|
|
46
|
+
*/
|
|
47
|
+
onConfirm?: (e: React.SyntheticEvent, data: {
|
|
48
|
+
value: (string | number)[];
|
|
49
|
+
options: ICascadePickerOptionItem[];
|
|
50
|
+
}) => void;
|
|
51
|
+
/**
|
|
52
|
+
* 选项值变更时的回调
|
|
53
|
+
*/
|
|
54
|
+
onOptionChange?: (e: React.SyntheticEvent, data: {
|
|
55
|
+
value: (string | number)[];
|
|
56
|
+
options: IPickerOptionItem[][] | ICascadePickerOptionItem[];
|
|
57
|
+
currentOption: ICascadePickerOptionItem;
|
|
58
|
+
}) => void;
|
|
59
|
+
/**
|
|
60
|
+
* 点击取消按钮时候回调
|
|
61
|
+
*/
|
|
62
|
+
onCancel?: (e: React.SyntheticEvent) => void;
|
|
63
|
+
/**
|
|
64
|
+
* 关闭选择器时执行
|
|
65
|
+
*/
|
|
66
|
+
onClose?: (e: React.SyntheticEvent, data: {
|
|
67
|
+
from: string;
|
|
68
|
+
value: (string | number)[];
|
|
69
|
+
options: IPickerOptionItem[][] | ICascadePickerOptionItem[];
|
|
70
|
+
}) => void;
|
|
71
|
+
};
|
|
72
|
+
defaultComponent: D;
|
|
73
|
+
}, D>;
|
|
74
|
+
export type PickerPanelProps<D extends React.ElementType = 'div', P = {}> = OverrideProps<{
|
|
75
|
+
props: P & {
|
|
76
|
+
/**
|
|
77
|
+
* 单列面板的列表数据
|
|
78
|
+
* @default []
|
|
79
|
+
*/
|
|
80
|
+
options?: IPickerOptionItem[][] | ICascadePickerOptionItem[];
|
|
81
|
+
/**
|
|
82
|
+
* 默认值
|
|
83
|
+
*/
|
|
84
|
+
defaultValue?: string | number;
|
|
85
|
+
/**
|
|
86
|
+
* 列索引
|
|
87
|
+
*/
|
|
88
|
+
columnIndex?: number;
|
|
89
|
+
/**
|
|
90
|
+
* 选择选项时的回调
|
|
91
|
+
*/
|
|
92
|
+
onSelect?: (e: React.SyntheticEvent, data: {
|
|
93
|
+
columnOption: IPickerOptionItem[] | ICascadePickerOptionItem;
|
|
94
|
+
columnIndex: number;
|
|
95
|
+
}) => void;
|
|
96
|
+
};
|
|
97
|
+
defaultComponent: D;
|
|
98
|
+
}, D>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
.bui-picker-panel {
|
|
2
|
+
flex: 1;
|
|
3
|
+
flex-shrink: 0;
|
|
4
|
+
position: relative;
|
|
5
|
+
font-family: var(--bui-font-family);
|
|
6
|
+
}
|
|
7
|
+
.bui-picker-panel-roller {
|
|
8
|
+
transform: rotate3d(1, 0, 0, 60deg);
|
|
9
|
+
transform-style: preserve-3d;
|
|
10
|
+
position: absolute;
|
|
11
|
+
top: var(--indicator-top);
|
|
12
|
+
width: 100%;
|
|
13
|
+
height: var(--option-height);
|
|
14
|
+
}
|
|
15
|
+
.bui-picker-panel-mask {
|
|
16
|
+
position: absolute;
|
|
17
|
+
top: 0;
|
|
18
|
+
left: 0;
|
|
19
|
+
width: 100%;
|
|
20
|
+
height: 100%;
|
|
21
|
+
background-image: linear-gradient(180deg, var(--bui-color-bg-view-opacity-9), var(--bui-color-bg-view-opacity-4)), linear-gradient(0deg, var(--bui-color-bg-view-opacity-9), var(--bui-color-bg-view-opacity-4));
|
|
22
|
+
background-position: top, bottom;
|
|
23
|
+
background-size: 100% var(--indicator-top);
|
|
24
|
+
background-repeat: no-repeat;
|
|
25
|
+
transform: translateZ(0);
|
|
26
|
+
}
|
|
27
|
+
.bui-picker-panel-indicator {
|
|
28
|
+
position: absolute;
|
|
29
|
+
top: var(--indicator-top);
|
|
30
|
+
height: var(--indicator-height);
|
|
31
|
+
width: 100%;
|
|
32
|
+
border-top: 1px solid var(--indicator-border-color);
|
|
33
|
+
border-bottom: 1px solid var(--indicator-border-color);
|
|
34
|
+
}
|
|
35
|
+
.bui-picker-panel-option {
|
|
36
|
+
position: absolute;
|
|
37
|
+
top: 0;
|
|
38
|
+
left: 0;
|
|
39
|
+
text-align: center;
|
|
40
|
+
height: var(--option-height);
|
|
41
|
+
line-height: var(--option-height);
|
|
42
|
+
color: var(--option-color);
|
|
43
|
+
font-size: var(--option-font-size);
|
|
44
|
+
backface-visibility: hidden;
|
|
45
|
+
width: auto;
|
|
46
|
+
overflow: hidden;
|
|
47
|
+
text-overflow: ellipsis;
|
|
48
|
+
white-space: nowrap;
|
|
49
|
+
width: 100%;
|
|
50
|
+
}
|
|
51
|
+
.bui-picker-panel-option-hidden {
|
|
52
|
+
visibility: hidden;
|
|
53
|
+
opacity: 0;
|
|
54
|
+
}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _clsx = _interopRequireDefault(require("clsx"));
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _utils = require("@bifrostui/utils");
|
|
10
|
+
require("./PickerPanel.css");
|
|
11
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
12
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
15
|
+
const prefixCls = 'bui-picker-panel';
|
|
16
|
+
const PickerPanel = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
|
|
17
|
+
const {
|
|
18
|
+
options = [],
|
|
19
|
+
defaultValue,
|
|
20
|
+
onSelect,
|
|
21
|
+
columnIndex,
|
|
22
|
+
...others
|
|
23
|
+
} = props;
|
|
24
|
+
const touch = (0, _utils.useTouch)();
|
|
25
|
+
let timer;
|
|
26
|
+
// 在手指离开屏幕时,如果和上一次 move 时的间隔小于 `INERTIA_TIME` 且 move 距离大于 `INERTIA_DISTANCE` 时,触发惯性滑动
|
|
27
|
+
const INERTIA_TIME = 300;
|
|
28
|
+
const INERTIA_DISTANCE = 15;
|
|
29
|
+
const DEFAULT_DURATION = 200;
|
|
30
|
+
const LINE_SPACING = 36;
|
|
31
|
+
const ROTATION = 20;
|
|
32
|
+
const TOUCH_END = 'end';
|
|
33
|
+
const [startY, setStartY] = (0, _react.useState)(0);
|
|
34
|
+
const [currIndex, setCurrIndex] = (0, _react.useState)(1);
|
|
35
|
+
const [startTime, setStartTime] = (0, _react.useState)(0);
|
|
36
|
+
const [touchTime, setTouchTime] = (0, _react.useState)(0);
|
|
37
|
+
const [touchDeg, setTouchDeg] = (0, _react.useState)('0deg');
|
|
38
|
+
const [scrollDistance, setScrollDistance] = (0, _react.useState)(0);
|
|
39
|
+
const transformY = (0, _react.useRef)(0);
|
|
40
|
+
const isVerticalMoving = (0, _react.useRef)(false);
|
|
41
|
+
const PickerPanelRef = (0, _react.useRef)(null);
|
|
42
|
+
const pickerPanelRef = (0, _utils.useForkRef)(PickerPanelRef, ref);
|
|
43
|
+
(0, _utils.useTouchEmulator)(PickerPanelRef.current);
|
|
44
|
+
const updateSelect = () => {
|
|
45
|
+
let index = -1;
|
|
46
|
+
if (defaultValue) {
|
|
47
|
+
options.some((item, idx) => {
|
|
48
|
+
if (item.value === defaultValue) {
|
|
49
|
+
index = idx;
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
setCurrIndex(index === -1 ? 1 : index + 1);
|
|
56
|
+
const move = index === -1 ? 0 : index * LINE_SPACING;
|
|
57
|
+
setMove({
|
|
58
|
+
move: -move
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
(0, _react.useEffect)(() => {
|
|
62
|
+
setScrollDistance(0);
|
|
63
|
+
transformY.current = 0;
|
|
64
|
+
updateSelect();
|
|
65
|
+
return () => {
|
|
66
|
+
clearTimeout(timer);
|
|
67
|
+
};
|
|
68
|
+
}, [options]);
|
|
69
|
+
const setTransform = (type, deg, time = DEFAULT_DURATION, translateY = 0) => {
|
|
70
|
+
let nTime = time;
|
|
71
|
+
if (type !== TOUCH_END) {
|
|
72
|
+
nTime = 0;
|
|
73
|
+
}
|
|
74
|
+
setTouchTime(nTime);
|
|
75
|
+
setTouchDeg(deg);
|
|
76
|
+
setScrollDistance(translateY);
|
|
77
|
+
};
|
|
78
|
+
const setMove = config => {
|
|
79
|
+
const {
|
|
80
|
+
move,
|
|
81
|
+
type,
|
|
82
|
+
time
|
|
83
|
+
} = config || {};
|
|
84
|
+
let updateMove = move + transformY.current;
|
|
85
|
+
if (type === TOUCH_END) {
|
|
86
|
+
// 限定滚动距离
|
|
87
|
+
if (updateMove > 0) {
|
|
88
|
+
updateMove = 0;
|
|
89
|
+
}
|
|
90
|
+
if (updateMove < -(options.length - 1) * LINE_SPACING) {
|
|
91
|
+
updateMove = -(options.length - 1) * LINE_SPACING;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// 设置滚动距离为LINE_SPACING的倍数值
|
|
95
|
+
const endMove = Math.round(updateMove / LINE_SPACING) * LINE_SPACING;
|
|
96
|
+
const deg = `${(Math.abs(Math.round(endMove / LINE_SPACING)) + 1) * ROTATION}deg`;
|
|
97
|
+
setTransform(type, deg, time, endMove);
|
|
98
|
+
setCurrIndex(Math.abs(Math.round(endMove / LINE_SPACING)) + 1);
|
|
99
|
+
} else {
|
|
100
|
+
let deg = 0;
|
|
101
|
+
const currentDeg = (-updateMove / LINE_SPACING + 1) * ROTATION;
|
|
102
|
+
|
|
103
|
+
// picker 滚动的最大角度
|
|
104
|
+
const maxDeg = (options.length + 1) * ROTATION;
|
|
105
|
+
const minDeg = 0;
|
|
106
|
+
deg = Math.min(Math.max(currentDeg, minDeg), maxDeg);
|
|
107
|
+
if (minDeg < deg && deg < maxDeg) {
|
|
108
|
+
setTransform('', `${deg}deg`, undefined, updateMove);
|
|
109
|
+
setCurrIndex(Math.abs(Math.round(updateMove / LINE_SPACING)) + 1);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// 惯性滚动距离
|
|
115
|
+
const momentum = (distance, duration) => {
|
|
116
|
+
let nDistance = distance;
|
|
117
|
+
// 惯性滚动的速度
|
|
118
|
+
const speed = Math.abs(nDistance / duration);
|
|
119
|
+
// 惯性滚动的距离
|
|
120
|
+
nDistance = speed / 0.003 * (nDistance < 0 ? -1 : 1);
|
|
121
|
+
return nDistance;
|
|
122
|
+
};
|
|
123
|
+
const panelTouchStart = event => {
|
|
124
|
+
touch.start(event);
|
|
125
|
+
setStartY(touch.deltaY.current);
|
|
126
|
+
setStartTime(Date.now());
|
|
127
|
+
transformY.current = scrollDistance;
|
|
128
|
+
};
|
|
129
|
+
const panelTouchMove = event => {
|
|
130
|
+
touch.move(event);
|
|
131
|
+
if (touch.isVertical) {
|
|
132
|
+
isVerticalMoving.current = true;
|
|
133
|
+
event.preventDefault();
|
|
134
|
+
event.stopPropagation();
|
|
135
|
+
}
|
|
136
|
+
const move = touch.deltaY.current - startY;
|
|
137
|
+
setMove({
|
|
138
|
+
move
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
const panelTouchEnd = () => {
|
|
142
|
+
if (!isVerticalMoving.current) return;
|
|
143
|
+
const move = touch.deltaY.current - startY;
|
|
144
|
+
const moveTime = Date.now() - startTime;
|
|
145
|
+
if (moveTime <= INERTIA_TIME && Math.abs(move) > INERTIA_DISTANCE) {
|
|
146
|
+
// 惯性滚动
|
|
147
|
+
const distance = momentum(move, moveTime);
|
|
148
|
+
setMove({
|
|
149
|
+
move: distance,
|
|
150
|
+
type: TOUCH_END,
|
|
151
|
+
time: 1000
|
|
152
|
+
});
|
|
153
|
+
} else {
|
|
154
|
+
// 非惯性滚动
|
|
155
|
+
setMove({
|
|
156
|
+
move,
|
|
157
|
+
type: TOUCH_END
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
timer = setTimeout(() => {
|
|
161
|
+
touch.reset();
|
|
162
|
+
}, 0);
|
|
163
|
+
};
|
|
164
|
+
(0, _react.useEffect)(() => {
|
|
165
|
+
PickerPanelRef.current?.addEventListener('touchstart', panelTouchStart);
|
|
166
|
+
PickerPanelRef.current?.addEventListener('touchmove', panelTouchMove);
|
|
167
|
+
PickerPanelRef.current?.addEventListener('touchend', panelTouchEnd);
|
|
168
|
+
return () => {
|
|
169
|
+
PickerPanelRef.current?.removeEventListener('touchstart', panelTouchStart);
|
|
170
|
+
PickerPanelRef.current?.removeEventListener('touchmove', panelTouchMove);
|
|
171
|
+
PickerPanelRef.current?.removeEventListener('touchend', panelTouchEnd);
|
|
172
|
+
};
|
|
173
|
+
});
|
|
174
|
+
const onTransitionEnd = e => {
|
|
175
|
+
isVerticalMoving.current = false;
|
|
176
|
+
setTouchTime(0);
|
|
177
|
+
onSelect?.(e, {
|
|
178
|
+
columnOption: options?.[Math.round(-scrollDistance / LINE_SPACING)],
|
|
179
|
+
columnIndex
|
|
180
|
+
});
|
|
181
|
+
};
|
|
182
|
+
return /*#__PURE__*/_react.default.createElement("div", _extends({
|
|
183
|
+
className: prefixCls,
|
|
184
|
+
ref: pickerPanelRef,
|
|
185
|
+
onTouchStart: panelTouchStart,
|
|
186
|
+
onTouchMove: panelTouchMove,
|
|
187
|
+
onTouchEnd: panelTouchEnd
|
|
188
|
+
}, others), /*#__PURE__*/_react.default.createElement("div", {
|
|
189
|
+
className: `${prefixCls}-roller`,
|
|
190
|
+
style: {
|
|
191
|
+
transition: `transform ${touchTime}ms cubic-bezier(0.17, 0.89, 0.45, 1)`,
|
|
192
|
+
transform: `rotate3d(1, 0, 0, ${touchDeg})`
|
|
193
|
+
},
|
|
194
|
+
onTransitionEnd: onTransitionEnd
|
|
195
|
+
}, options.map((item, i) => /*#__PURE__*/_react.default.createElement("div", {
|
|
196
|
+
className: (0, _clsx.default)(`${prefixCls}-option`, {
|
|
197
|
+
[`${prefixCls}-option-hidden`]: i + 1 <= currIndex - 8 || i + 1 >= currIndex + 8
|
|
198
|
+
}),
|
|
199
|
+
key: `${item?.value}-${i}`,
|
|
200
|
+
style: {
|
|
201
|
+
transform: `rotate3d(1, 0, 0, ${-ROTATION * (i + 1)}deg) translate3d(0px, 0px, 104px)`
|
|
202
|
+
}
|
|
203
|
+
}, item?.label))), /*#__PURE__*/_react.default.createElement("div", {
|
|
204
|
+
className: `${prefixCls}-mask`
|
|
205
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
206
|
+
className: `${prefixCls}-indicator`
|
|
207
|
+
}));
|
|
208
|
+
});
|
|
209
|
+
PickerPanel.displayName = 'BuiPickerPanel';
|
|
210
|
+
var _default = exports.default = PickerPanel;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
Picker: true
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "Picker", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return _Picker.default;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(exports, "default", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () {
|
|
18
|
+
return _Picker.default;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
var _Picker = _interopRequireDefault(require("./Picker"));
|
|
22
|
+
var _Picker2 = require("./Picker.types");
|
|
23
|
+
Object.keys(_Picker2).forEach(function (key) {
|
|
24
|
+
if (key === "default" || key === "__esModule") return;
|
|
25
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
26
|
+
if (key in exports && exports[key] === _Picker2[key]) return;
|
|
27
|
+
Object.defineProperty(exports, key, {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function () {
|
|
30
|
+
return _Picker2[key];
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ICascadePickerOptionItem } from './Picker.types';
|
|
2
|
+
/**
|
|
3
|
+
* 根据第一列数据判断选择器类型
|
|
4
|
+
*/
|
|
5
|
+
export declare const pickerPanelType: (options?: any[]) => "multiple" | "cascade" | "single";
|
|
6
|
+
/**
|
|
7
|
+
* 格式化级联模式数据
|
|
8
|
+
*/
|
|
9
|
+
export declare const formatCascade: (columns: ICascadePickerOptionItem[], values?: (number | string)[]) => ICascadePickerOptionItem[][];
|
|
10
|
+
/**
|
|
11
|
+
* 统一options数据格式
|
|
12
|
+
*/
|
|
13
|
+
export declare const formatOptions: (internalValue: any, options?: any[]) => any[];
|