@bifrostui/react 1.0.5 → 1.1.5
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/ActionSheet/ActionSheet.less +31 -0
- package/dist/ActionSheet/ActionSheetItem.less +62 -0
- package/dist/Alert/index.less +112 -0
- package/dist/Avatar/Avatar.less +52 -0
- package/dist/Avatar/AvatarGroup.less +39 -0
- package/dist/Backdrop/{Backdrop.css → Backdrop.less} +4 -3
- package/dist/Badge/Badge.less +118 -0
- package/dist/Button/Button.less +244 -0
- package/dist/Calendar/Calendar.less +126 -0
- package/{es/Card/Card.css → dist/Card/Card.less} +1 -0
- package/dist/Card/CardHeader.less +53 -0
- package/dist/Checkbox/Checkbox.less +55 -0
- package/dist/CitySelector/CitySelector.d.ts +4 -0
- package/dist/CitySelector/CitySelector.js +36 -0
- package/dist/CitySelector/CitySelector.less +122 -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 +183 -0
- package/dist/CitySelector/Selector/index.d.ts +9 -0
- package/dist/CitySelector/Selector/index.js +22 -0
- package/dist/CitySelector/Selector/index.less +13 -0
- package/dist/CitySelector/index.d.ts +2 -0
- package/dist/CitySelector/index.js +34 -0
- package/dist/CitySelector/miniapp.less +4 -0
- package/dist/Countdown/Countdown.less +39 -0
- package/dist/Divider/Divider.less +50 -0
- package/dist/Drawer/Drawer.less +40 -0
- package/dist/IconButton/IconButton.less +167 -0
- package/dist/Image/index.less +40 -0
- package/dist/Input/Input.less +72 -0
- package/dist/List/{List.css → List.less} +1 -0
- package/dist/List/{ListItem.css → ListItem.less} +17 -6
- package/dist/List/{ListItemContent.css → ListItemContent.less} +7 -2
- package/dist/List/{ListItemFooter.css → ListItemFooter.less} +4 -3
- package/dist/Loading/Loading.less +40 -0
- package/dist/Modal/{Modal.css → Modal.less} +8 -6
- package/dist/Modal/Modal.miniapp.d.ts +16 -0
- package/dist/Modal/Modal.miniapp.js +73 -0
- package/dist/NavBar/NavBar.less +67 -0
- package/dist/Picker/Picker.d.ts +5 -0
- package/dist/Picker/Picker.js +155 -0
- package/dist/Picker/Picker.less +62 -0
- package/dist/Picker/Picker.types.d.ts +98 -0
- package/dist/Picker/Picker.types.js +5 -0
- package/dist/Picker/PickerPanel.d.ts +5 -0
- package/dist/Picker/PickerPanel.js +210 -0
- package/dist/Picker/PickerPanel.less +67 -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/Progress/Progress.less +24 -0
- package/dist/Radio/Radio.less +81 -0
- package/dist/Rating/Rating.less +64 -0
- package/dist/ScrollView/{ScrollView.css → ScrollView.less} +4 -0
- package/dist/Select/Select.less +105 -0
- package/dist/Skeleton/Skeleton.less +72 -0
- package/dist/Slider/Slider.less +108 -0
- package/dist/Stack/demo/index.less +27 -0
- package/dist/Steps/Step.less +228 -0
- package/{es/Steps/Steps.css → dist/Steps/Steps.less} +5 -3
- package/dist/Swiper/Swiper.less +25 -0
- package/dist/Switch/Switch.less +177 -0
- package/dist/TabBar/TabBarItem.less +54 -0
- package/dist/Tabs/Tab.js +1 -1
- package/dist/Tabs/Tab.less +60 -0
- package/dist/Tabs/TabPanel.less +11 -0
- package/dist/Tabs/Tabs.less +77 -0
- package/dist/Tag/Tag.less +119 -0
- package/dist/Tag/TagGroup.less +52 -0
- package/dist/TextArea/{TextArea.css → TextArea.less} +27 -19
- package/dist/index.d.ts +2 -0
- package/dist/index.js +22 -0
- package/es/ActionSheet/ActionSheet.less +31 -0
- package/es/ActionSheet/ActionSheetItem.less +62 -0
- package/es/Alert/index.less +112 -0
- package/es/Avatar/Avatar.less +52 -0
- package/es/Avatar/AvatarGroup.less +39 -0
- package/es/Backdrop/{Backdrop.css → Backdrop.less} +4 -3
- package/es/Badge/Badge.less +118 -0
- package/es/Button/Button.less +244 -0
- package/es/Calendar/Calendar.less +126 -0
- package/{dist/Card/Card.css → es/Card/Card.less} +1 -0
- package/es/Card/CardHeader.less +53 -0
- package/es/Checkbox/Checkbox.less +55 -0
- package/es/CitySelector/CitySelector.d.ts +4 -0
- package/es/CitySelector/CitySelector.js +36 -0
- package/es/CitySelector/CitySelector.less +122 -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 +194 -0
- package/es/CitySelector/Selector/index.d.ts +9 -0
- package/es/CitySelector/Selector/index.js +13 -0
- package/es/CitySelector/Selector/index.less +13 -0
- package/es/CitySelector/index.d.ts +2 -0
- package/es/CitySelector/index.js +2 -0
- package/es/CitySelector/miniapp.less +4 -0
- package/es/Countdown/Countdown.less +39 -0
- package/es/Divider/Divider.less +50 -0
- package/es/Drawer/Drawer.less +40 -0
- package/es/IconButton/IconButton.less +167 -0
- package/es/Image/index.less +40 -0
- package/es/Input/Input.less +72 -0
- package/es/List/{List.css → List.less} +1 -0
- package/es/List/{ListItem.css → ListItem.less} +17 -6
- package/es/List/{ListItemContent.css → ListItemContent.less} +7 -2
- package/es/List/{ListItemFooter.css → ListItemFooter.less} +4 -3
- package/es/Loading/Loading.less +40 -0
- package/es/Modal/{Modal.css → Modal.less} +8 -6
- package/es/Modal/Modal.miniapp.d.ts +16 -0
- package/es/Modal/Modal.miniapp.js +78 -0
- package/es/NavBar/NavBar.less +67 -0
- package/es/Picker/Picker.d.ts +5 -0
- package/es/Picker/Picker.js +171 -0
- package/es/Picker/Picker.less +62 -0
- package/es/Picker/Picker.types.d.ts +98 -0
- package/es/Picker/Picker.types.js +1 -0
- package/es/Picker/PickerPanel.d.ts +5 -0
- package/es/Picker/PickerPanel.js +234 -0
- package/es/Picker/PickerPanel.less +67 -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/Progress/Progress.less +24 -0
- package/es/Radio/Radio.less +81 -0
- package/es/Rating/Rating.less +64 -0
- package/es/ScrollView/{ScrollView.css → ScrollView.less} +4 -0
- package/es/Select/Select.less +105 -0
- package/es/Skeleton/Skeleton.less +72 -0
- package/es/Slider/Slider.less +108 -0
- package/es/Stack/demo/index.less +27 -0
- package/es/Steps/Step.less +228 -0
- package/{dist/Steps/Steps.css → es/Steps/Steps.less} +5 -3
- package/es/Swiper/Swiper.less +25 -0
- package/es/Switch/Switch.less +177 -0
- package/es/TabBar/TabBarItem.less +54 -0
- package/es/Tabs/Tab.js +1 -1
- package/es/Tabs/Tab.less +60 -0
- package/es/Tabs/TabPanel.less +11 -0
- package/es/Tabs/Tabs.less +77 -0
- package/es/Tag/Tag.less +119 -0
- package/es/Tag/TagGroup.less +52 -0
- package/es/TextArea/{TextArea.css → TextArea.less} +27 -19
- package/es/index.d.ts +2 -0
- package/es/index.js +3 -1
- package/package.json +6 -6
- package/dist/ActionSheet/ActionSheet.css +0 -27
- package/dist/ActionSheet/ActionSheetItem.css +0 -51
- package/dist/Alert/index.css +0 -89
- package/dist/Avatar/Avatar.css +0 -43
- package/dist/Avatar/AvatarGroup.css +0 -31
- package/dist/Badge/Badge.css +0 -95
- package/dist/Button/Button.css +0 -200
- package/dist/Calendar/Calendar.css +0 -105
- package/dist/Card/CardHeader.css +0 -45
- package/dist/Checkbox/Checkbox.css +0 -45
- package/dist/Countdown/Countdown.css +0 -28
- package/dist/Divider/Divider.css +0 -41
- package/dist/Drawer/Drawer.css +0 -35
- package/dist/IconButton/IconButton.css +0 -130
- package/dist/Image/index.css +0 -35
- package/dist/Input/Input.css +0 -59
- package/dist/Loading/Loading.css +0 -31
- package/dist/NavBar/NavBar.css +0 -57
- package/dist/Progress/Progress.css +0 -22
- package/dist/Radio/Radio.css +0 -65
- package/dist/Rating/Rating.css +0 -52
- package/dist/Select/Select.css +0 -89
- package/dist/Skeleton/Skeleton.css +0 -54
- package/dist/Slider/Slider.css +0 -95
- package/dist/Stack/demo/index.css +0 -23
- package/dist/Steps/Step.css +0 -174
- package/dist/Swiper/Swiper.css +0 -20
- package/dist/Switch/Switch.css +0 -127
- package/dist/TabBar/TabBarItem.css +0 -38
- package/dist/Tabs/Tab.css +0 -52
- package/dist/Tabs/TabPanel.css +0 -9
- package/dist/Tabs/Tabs.css +0 -56
- package/dist/Tag/Tag.css +0 -97
- package/dist/Tag/TagGroup.css +0 -43
- package/es/ActionSheet/ActionSheet.css +0 -27
- package/es/ActionSheet/ActionSheetItem.css +0 -51
- package/es/Alert/index.css +0 -89
- package/es/Avatar/Avatar.css +0 -43
- package/es/Avatar/AvatarGroup.css +0 -31
- package/es/Badge/Badge.css +0 -95
- package/es/Button/Button.css +0 -200
- package/es/Calendar/Calendar.css +0 -105
- package/es/Card/CardHeader.css +0 -45
- package/es/Checkbox/Checkbox.css +0 -45
- package/es/Countdown/Countdown.css +0 -28
- package/es/Divider/Divider.css +0 -41
- package/es/Drawer/Drawer.css +0 -35
- package/es/IconButton/IconButton.css +0 -130
- package/es/Image/index.css +0 -35
- package/es/Input/Input.css +0 -59
- package/es/Loading/Loading.css +0 -31
- package/es/NavBar/NavBar.css +0 -57
- package/es/Progress/Progress.css +0 -22
- package/es/Radio/Radio.css +0 -65
- package/es/Rating/Rating.css +0 -52
- package/es/Select/Select.css +0 -89
- package/es/Skeleton/Skeleton.css +0 -54
- package/es/Slider/Slider.css +0 -95
- package/es/Stack/demo/index.css +0 -23
- package/es/Steps/Step.css +0 -174
- package/es/Swiper/Swiper.css +0 -20
- package/es/Switch/Switch.css +0 -127
- package/es/TabBar/TabBarItem.css +0 -38
- package/es/Tabs/Tab.css +0 -52
- package/es/Tabs/TabPanel.css +0 -9
- package/es/Tabs/Tabs.css +0 -56
- package/es/Tag/Tag.css +0 -97
- package/es/Tag/TagGroup.css +0 -43
- /package/dist/Card/{CardContent.css → CardContent.less} +0 -0
- /package/dist/Card/{CardFooter.css → CardFooter.less} +0 -0
- /package/dist/List/{ListItemExtra.css → ListItemExtra.less} +0 -0
- /package/dist/List/{ListItemHeader.css → ListItemHeader.less} +0 -0
- /package/dist/Stack/{Stack.css → Stack.less} +0 -0
- /package/dist/TabBar/{TabBar.css → TabBar.less} +0 -0
- /package/es/Card/{CardContent.css → CardContent.less} +0 -0
- /package/es/Card/{CardFooter.css → CardFooter.less} +0 -0
- /package/es/List/{ListItemExtra.css → ListItemExtra.less} +0 -0
- /package/es/List/{ListItemHeader.css → ListItemHeader.less} +0 -0
- /package/es/Stack/{Stack.css → Stack.less} +0 -0
- /package/es/TabBar/{TabBar.css → TabBar.less} +0 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
var _excluded = ["className", "open", "title", "options", "value", "contentProps", "onConfirm", "onOptionChange", "onCancel", "onClose"];
|
|
3
|
+
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); }
|
|
4
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
5
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
6
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
7
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
8
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
9
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
10
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
12
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
13
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
14
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
15
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
16
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
17
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
18
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
19
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
20
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
21
|
+
import clsx from 'clsx';
|
|
22
|
+
import React, { useEffect, useState } from 'react';
|
|
23
|
+
import Drawer from "../Drawer";
|
|
24
|
+
import PickerPanel from "./PickerPanel";
|
|
25
|
+
import { formatOptions, pickerPanelType } from "./utils";
|
|
26
|
+
import "./Picker.css";
|
|
27
|
+
var prefixCls = 'bui-picker';
|
|
28
|
+
var Picker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
29
|
+
var className = props.className,
|
|
30
|
+
_props$open = props.open,
|
|
31
|
+
open = _props$open === void 0 ? false : _props$open,
|
|
32
|
+
title = props.title,
|
|
33
|
+
_props$options = props.options,
|
|
34
|
+
options = _props$options === void 0 ? [] : _props$options,
|
|
35
|
+
value = props.value,
|
|
36
|
+
contentProps = props.contentProps,
|
|
37
|
+
onConfirm = props.onConfirm,
|
|
38
|
+
onOptionChange = props.onOptionChange,
|
|
39
|
+
onCancel = props.onCancel,
|
|
40
|
+
onClose = props.onClose,
|
|
41
|
+
others = _objectWithoutProperties(props, _excluded);
|
|
42
|
+
var pickerType = pickerPanelType(options);
|
|
43
|
+
var _useState = useState([]),
|
|
44
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
45
|
+
columns = _useState2[0],
|
|
46
|
+
setColumns = _useState2[1];
|
|
47
|
+
var _useState3 = useState([]),
|
|
48
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
49
|
+
internalValue = _useState4[0],
|
|
50
|
+
setInternalValue = _useState4[1];
|
|
51
|
+
useEffect(function () {
|
|
52
|
+
if (!open) return;
|
|
53
|
+
|
|
54
|
+
// 初始化默认选中数据
|
|
55
|
+
var formatted = formatOptions(value, options);
|
|
56
|
+
var initialValue = [];
|
|
57
|
+
(formatted || []).forEach(function (item) {
|
|
58
|
+
var _item$;
|
|
59
|
+
initialValue.push(item === null || item === void 0 || (_item$ = item[0]) === null || _item$ === void 0 ? void 0 : _item$.value);
|
|
60
|
+
});
|
|
61
|
+
var defaultValue = value !== null && value !== void 0 && value.length ? value : initialValue;
|
|
62
|
+
if (defaultValue !== null && defaultValue !== void 0 && defaultValue.length) {
|
|
63
|
+
setInternalValue(defaultValue);
|
|
64
|
+
}
|
|
65
|
+
}, [open, value, options]);
|
|
66
|
+
useEffect(function () {
|
|
67
|
+
if (options !== null && options !== void 0 && options.length) {
|
|
68
|
+
var formatted = formatOptions(value, options);
|
|
69
|
+
setColumns(formatted);
|
|
70
|
+
}
|
|
71
|
+
}, [value, options]);
|
|
72
|
+
var confirm = function confirm(e) {
|
|
73
|
+
var payload = {
|
|
74
|
+
value: internalValue,
|
|
75
|
+
options: columns
|
|
76
|
+
};
|
|
77
|
+
onConfirm === null || onConfirm === void 0 || onConfirm(e, payload);
|
|
78
|
+
onClose === null || onClose === void 0 || onClose(e, _objectSpread({
|
|
79
|
+
from: 'confirm'
|
|
80
|
+
}, payload));
|
|
81
|
+
};
|
|
82
|
+
var cancel = function cancel(e) {
|
|
83
|
+
onCancel === null || onCancel === void 0 || onCancel(e);
|
|
84
|
+
onClose === null || onClose === void 0 || onClose(e, {
|
|
85
|
+
from: 'cancel',
|
|
86
|
+
value: internalValue,
|
|
87
|
+
options: columns
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
var updateItem = function updateItem(e, columnOption, columnIndex) {
|
|
91
|
+
var columnValues = (internalValue === null || internalValue === void 0 ? void 0 : internalValue.slice(0, columnIndex)) || [];
|
|
92
|
+
var colIndex = columnIndex;
|
|
93
|
+
var colOption = columnOption;
|
|
94
|
+
if (colOption && Object.keys(colOption).length) {
|
|
95
|
+
if (columnValues[columnIndex] === columnOption.value) return;
|
|
96
|
+
if (pickerType === 'cascade') {
|
|
97
|
+
var _colOption3;
|
|
98
|
+
columnValues[colIndex] = colOption.value || '';
|
|
99
|
+
while ((_colOption = colOption) !== null && _colOption !== void 0 && (_colOption = _colOption.children) !== null && _colOption !== void 0 && _colOption[0]) {
|
|
100
|
+
var _colOption, _colOption2;
|
|
101
|
+
columnValues[colIndex + 1] = colOption.children[0].value;
|
|
102
|
+
colIndex += 1;
|
|
103
|
+
colOption = _objectSpread({}, ((_colOption2 = colOption) === null || _colOption2 === void 0 || (_colOption2 = _colOption2.children) === null || _colOption2 === void 0 ? void 0 : _colOption2[0]) || {});
|
|
104
|
+
}
|
|
105
|
+
// 当前改变列的下一列 children 值为空
|
|
106
|
+
if ((_colOption3 = colOption) !== null && _colOption3 !== void 0 && (_colOption3 = _colOption3.children) !== null && _colOption3 !== void 0 && _colOption3.length) {
|
|
107
|
+
columnValues[columnIndex + 1] = '';
|
|
108
|
+
}
|
|
109
|
+
var conbineValues = [].concat(_toConsumableArray((internalValue === null || internalValue === void 0 ? void 0 : internalValue.slice(0, columnIndex)) || []), _toConsumableArray(columnValues.slice(columnIndex)));
|
|
110
|
+
var formatted = formatOptions(conbineValues, options);
|
|
111
|
+
setColumns(formatted);
|
|
112
|
+
setInternalValue(conbineValues);
|
|
113
|
+
onOptionChange === null || onOptionChange === void 0 || onOptionChange(e, {
|
|
114
|
+
value: conbineValues,
|
|
115
|
+
options: formatted,
|
|
116
|
+
currentOption: columnOption
|
|
117
|
+
});
|
|
118
|
+
} else {
|
|
119
|
+
var result = internalValue;
|
|
120
|
+
result[columnIndex] = columnOption.value;
|
|
121
|
+
setInternalValue(result);
|
|
122
|
+
onOptionChange === null || onOptionChange === void 0 || onOptionChange(e, {
|
|
123
|
+
value: result,
|
|
124
|
+
options: options,
|
|
125
|
+
currentOption: columnOption
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
var handleSelect = function handleSelect(e, _ref) {
|
|
131
|
+
var columnIndex = _ref.columnIndex,
|
|
132
|
+
columnOption = _ref.columnOption;
|
|
133
|
+
updateItem(e, columnOption, columnIndex);
|
|
134
|
+
};
|
|
135
|
+
var handleClose = function handleClose(e, data) {
|
|
136
|
+
onClose === null || onClose === void 0 || onClose(e, _objectSpread({
|
|
137
|
+
value: internalValue,
|
|
138
|
+
options: columns
|
|
139
|
+
}, data));
|
|
140
|
+
};
|
|
141
|
+
return /*#__PURE__*/React.createElement(Drawer, _extends({
|
|
142
|
+
ref: ref,
|
|
143
|
+
open: open,
|
|
144
|
+
className: clsx(prefixCls, className),
|
|
145
|
+
onClose: handleClose
|
|
146
|
+
}, others), /*#__PURE__*/React.createElement("div", _extends({}, contentProps, {
|
|
147
|
+
className: clsx("".concat(prefixCls, "-content"), contentProps === null || contentProps === void 0 ? void 0 : contentProps.className)
|
|
148
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
149
|
+
className: "".concat(prefixCls, "-header")
|
|
150
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
151
|
+
className: "".concat(prefixCls, "-cancel"),
|
|
152
|
+
onClick: cancel
|
|
153
|
+
}, "\u53D6\u6D88"), title && /*#__PURE__*/React.createElement("div", {
|
|
154
|
+
className: "".concat(prefixCls, "-title")
|
|
155
|
+
}, title), /*#__PURE__*/React.createElement("div", {
|
|
156
|
+
className: "".concat(prefixCls, "-confirm"),
|
|
157
|
+
onClick: confirm
|
|
158
|
+
}, "\u786E\u8BA4")), /*#__PURE__*/React.createElement("div", {
|
|
159
|
+
className: "".concat(prefixCls, "-container")
|
|
160
|
+
}, columns.map(function (column, index) {
|
|
161
|
+
return /*#__PURE__*/React.createElement(PickerPanel, {
|
|
162
|
+
key: index,
|
|
163
|
+
options: column,
|
|
164
|
+
columnIndex: index,
|
|
165
|
+
defaultValue: internalValue === null || internalValue === void 0 ? void 0 : internalValue[index],
|
|
166
|
+
onSelect: handleSelect
|
|
167
|
+
});
|
|
168
|
+
}))));
|
|
169
|
+
});
|
|
170
|
+
Picker.displayName = 'BuiPicker';
|
|
171
|
+
export default Picker;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
@import '~@bifrostui/styles/mixins/index.less';
|
|
2
|
+
|
|
3
|
+
.bui-picker {
|
|
4
|
+
--cancel-color: var(--bui-color-fg-default);
|
|
5
|
+
--cancel-font-size: var(--bui-title-size-4, 15px);
|
|
6
|
+
--confirm-color: var(--bui-color-primary);
|
|
7
|
+
--confirm-font-size: var(--bui-title-size-4, 15px);
|
|
8
|
+
--title-color: var(--bui-color-fg-default);
|
|
9
|
+
--title-font-size: var(--bui-title-size-3, 16px);
|
|
10
|
+
--title-font-weight: var(--bui-font-weight-medium, 500);
|
|
11
|
+
--panel-container-height: 260px;
|
|
12
|
+
--indicator-top: 108px;
|
|
13
|
+
--indicator-height: 36px;
|
|
14
|
+
--indicator-border-color: var(--bui-color-border-default);
|
|
15
|
+
--option-color: var(--bui-color-fg-default);
|
|
16
|
+
--option-font-size: var(--bui-title-size-4);
|
|
17
|
+
--option-height: 36px;
|
|
18
|
+
font-family: var(--bui-font-family);
|
|
19
|
+
|
|
20
|
+
.bui-drawer-content {
|
|
21
|
+
border-radius: var(--bui-shape-radius-drawer) var(--bui-shape-radius-drawer)
|
|
22
|
+
0 0;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
&-header {
|
|
26
|
+
height: 50px;
|
|
27
|
+
display: flex;
|
|
28
|
+
align-items: center;
|
|
29
|
+
justify-content: space-between;
|
|
30
|
+
padding: 0 var(--bui-spacing-lg);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
&-cancel {
|
|
34
|
+
width: 40px;
|
|
35
|
+
height: 100%;
|
|
36
|
+
font-size: var(--cancel-font-size);
|
|
37
|
+
text-align: center;
|
|
38
|
+
line-height: 50px;
|
|
39
|
+
color: var(--cancel-color);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
&-title {
|
|
43
|
+
font-size: var(--title-font-size);
|
|
44
|
+
color: var(--title-color);
|
|
45
|
+
font-weight: var(--title-font-weight);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
&-confirm {
|
|
49
|
+
width: 40px;
|
|
50
|
+
height: 100%;
|
|
51
|
+
font-size: var(--confirm-font-size);
|
|
52
|
+
text-align: center;
|
|
53
|
+
line-height: 50px;
|
|
54
|
+
color: var(--confirm-color);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
&-container {
|
|
58
|
+
width: 100%;
|
|
59
|
+
height: var(--panel-container-height);
|
|
60
|
+
display: flex;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -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 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
var _excluded = ["options", "defaultValue", "onSelect", "columnIndex"];
|
|
3
|
+
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); }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
8
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
10
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
11
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
12
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
14
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
15
|
+
import clsx from 'clsx';
|
|
16
|
+
import React, { useEffect, useState, useRef } from 'react';
|
|
17
|
+
import { useTouch, useForkRef, useTouchEmulator } from '@bifrostui/utils';
|
|
18
|
+
import "./PickerPanel.css";
|
|
19
|
+
var prefixCls = 'bui-picker-panel';
|
|
20
|
+
var PickerPanel = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
21
|
+
var _props$options = props.options,
|
|
22
|
+
options = _props$options === void 0 ? [] : _props$options,
|
|
23
|
+
defaultValue = props.defaultValue,
|
|
24
|
+
onSelect = props.onSelect,
|
|
25
|
+
columnIndex = props.columnIndex,
|
|
26
|
+
others = _objectWithoutProperties(props, _excluded);
|
|
27
|
+
var touch = useTouch();
|
|
28
|
+
var timer;
|
|
29
|
+
// 在手指离开屏幕时,如果和上一次 move 时的间隔小于 `INERTIA_TIME` 且 move 距离大于 `INERTIA_DISTANCE` 时,触发惯性滑动
|
|
30
|
+
var INERTIA_TIME = 300;
|
|
31
|
+
var INERTIA_DISTANCE = 15;
|
|
32
|
+
var DEFAULT_DURATION = 200;
|
|
33
|
+
var LINE_SPACING = 36;
|
|
34
|
+
var ROTATION = 20;
|
|
35
|
+
var TOUCH_END = 'end';
|
|
36
|
+
var _useState = useState(0),
|
|
37
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
38
|
+
startY = _useState2[0],
|
|
39
|
+
setStartY = _useState2[1];
|
|
40
|
+
var _useState3 = useState(1),
|
|
41
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
42
|
+
currIndex = _useState4[0],
|
|
43
|
+
setCurrIndex = _useState4[1];
|
|
44
|
+
var _useState5 = useState(0),
|
|
45
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
46
|
+
startTime = _useState6[0],
|
|
47
|
+
setStartTime = _useState6[1];
|
|
48
|
+
var _useState7 = useState(0),
|
|
49
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
50
|
+
touchTime = _useState8[0],
|
|
51
|
+
setTouchTime = _useState8[1];
|
|
52
|
+
var _useState9 = useState('0deg'),
|
|
53
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
54
|
+
touchDeg = _useState10[0],
|
|
55
|
+
setTouchDeg = _useState10[1];
|
|
56
|
+
var _useState11 = useState(0),
|
|
57
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
58
|
+
scrollDistance = _useState12[0],
|
|
59
|
+
setScrollDistance = _useState12[1];
|
|
60
|
+
var transformY = useRef(0);
|
|
61
|
+
var isVerticalMoving = useRef(false);
|
|
62
|
+
var PickerPanelRef = useRef(null);
|
|
63
|
+
var pickerPanelRef = useForkRef(PickerPanelRef, ref);
|
|
64
|
+
useTouchEmulator(PickerPanelRef.current);
|
|
65
|
+
var updateSelect = function updateSelect() {
|
|
66
|
+
var index = -1;
|
|
67
|
+
if (defaultValue) {
|
|
68
|
+
options.some(function (item, idx) {
|
|
69
|
+
if (item.value === defaultValue) {
|
|
70
|
+
index = idx;
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
return false;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
setCurrIndex(index === -1 ? 1 : index + 1);
|
|
77
|
+
var move = index === -1 ? 0 : index * LINE_SPACING;
|
|
78
|
+
setMove({
|
|
79
|
+
move: -move
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
useEffect(function () {
|
|
83
|
+
setScrollDistance(0);
|
|
84
|
+
transformY.current = 0;
|
|
85
|
+
updateSelect();
|
|
86
|
+
return function () {
|
|
87
|
+
clearTimeout(timer);
|
|
88
|
+
};
|
|
89
|
+
}, [options]);
|
|
90
|
+
var setTransform = function setTransform(type, deg) {
|
|
91
|
+
var time = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEFAULT_DURATION;
|
|
92
|
+
var translateY = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
93
|
+
var nTime = time;
|
|
94
|
+
if (type !== TOUCH_END) {
|
|
95
|
+
nTime = 0;
|
|
96
|
+
}
|
|
97
|
+
setTouchTime(nTime);
|
|
98
|
+
setTouchDeg(deg);
|
|
99
|
+
setScrollDistance(translateY);
|
|
100
|
+
};
|
|
101
|
+
var setMove = function setMove(config) {
|
|
102
|
+
var _ref = config || {},
|
|
103
|
+
move = _ref.move,
|
|
104
|
+
type = _ref.type,
|
|
105
|
+
time = _ref.time;
|
|
106
|
+
var updateMove = move + transformY.current;
|
|
107
|
+
if (type === TOUCH_END) {
|
|
108
|
+
// 限定滚动距离
|
|
109
|
+
if (updateMove > 0) {
|
|
110
|
+
updateMove = 0;
|
|
111
|
+
}
|
|
112
|
+
if (updateMove < -(options.length - 1) * LINE_SPACING) {
|
|
113
|
+
updateMove = -(options.length - 1) * LINE_SPACING;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// 设置滚动距离为LINE_SPACING的倍数值
|
|
117
|
+
var endMove = Math.round(updateMove / LINE_SPACING) * LINE_SPACING;
|
|
118
|
+
var deg = "".concat((Math.abs(Math.round(endMove / LINE_SPACING)) + 1) * ROTATION, "deg");
|
|
119
|
+
setTransform(type, deg, time, endMove);
|
|
120
|
+
setCurrIndex(Math.abs(Math.round(endMove / LINE_SPACING)) + 1);
|
|
121
|
+
} else {
|
|
122
|
+
var _deg = 0;
|
|
123
|
+
var currentDeg = (-updateMove / LINE_SPACING + 1) * ROTATION;
|
|
124
|
+
|
|
125
|
+
// picker 滚动的最大角度
|
|
126
|
+
var maxDeg = (options.length + 1) * ROTATION;
|
|
127
|
+
var minDeg = 0;
|
|
128
|
+
_deg = Math.min(Math.max(currentDeg, minDeg), maxDeg);
|
|
129
|
+
if (minDeg < _deg && _deg < maxDeg) {
|
|
130
|
+
setTransform('', "".concat(_deg, "deg"), undefined, updateMove);
|
|
131
|
+
setCurrIndex(Math.abs(Math.round(updateMove / LINE_SPACING)) + 1);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
// 惯性滚动距离
|
|
137
|
+
var momentum = function momentum(distance, duration) {
|
|
138
|
+
var nDistance = distance;
|
|
139
|
+
// 惯性滚动的速度
|
|
140
|
+
var speed = Math.abs(nDistance / duration);
|
|
141
|
+
// 惯性滚动的距离
|
|
142
|
+
nDistance = speed / 0.003 * (nDistance < 0 ? -1 : 1);
|
|
143
|
+
return nDistance;
|
|
144
|
+
};
|
|
145
|
+
var panelTouchStart = function panelTouchStart(event) {
|
|
146
|
+
touch.start(event);
|
|
147
|
+
setStartY(touch.deltaY.current);
|
|
148
|
+
setStartTime(Date.now());
|
|
149
|
+
transformY.current = scrollDistance;
|
|
150
|
+
};
|
|
151
|
+
var panelTouchMove = function panelTouchMove(event) {
|
|
152
|
+
touch.move(event);
|
|
153
|
+
if (touch.isVertical) {
|
|
154
|
+
isVerticalMoving.current = true;
|
|
155
|
+
event.preventDefault();
|
|
156
|
+
event.stopPropagation();
|
|
157
|
+
}
|
|
158
|
+
var move = touch.deltaY.current - startY;
|
|
159
|
+
setMove({
|
|
160
|
+
move: move
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
var panelTouchEnd = function panelTouchEnd() {
|
|
164
|
+
if (!isVerticalMoving.current) return;
|
|
165
|
+
var move = touch.deltaY.current - startY;
|
|
166
|
+
var moveTime = Date.now() - startTime;
|
|
167
|
+
if (moveTime <= INERTIA_TIME && Math.abs(move) > INERTIA_DISTANCE) {
|
|
168
|
+
// 惯性滚动
|
|
169
|
+
var distance = momentum(move, moveTime);
|
|
170
|
+
setMove({
|
|
171
|
+
move: distance,
|
|
172
|
+
type: TOUCH_END,
|
|
173
|
+
time: 1000
|
|
174
|
+
});
|
|
175
|
+
} else {
|
|
176
|
+
// 非惯性滚动
|
|
177
|
+
setMove({
|
|
178
|
+
move: move,
|
|
179
|
+
type: TOUCH_END
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
timer = setTimeout(function () {
|
|
183
|
+
touch.reset();
|
|
184
|
+
}, 0);
|
|
185
|
+
};
|
|
186
|
+
useEffect(function () {
|
|
187
|
+
var _PickerPanelRef$curre, _PickerPanelRef$curre2, _PickerPanelRef$curre3;
|
|
188
|
+
(_PickerPanelRef$curre = PickerPanelRef.current) === null || _PickerPanelRef$curre === void 0 || _PickerPanelRef$curre.addEventListener('touchstart', panelTouchStart);
|
|
189
|
+
(_PickerPanelRef$curre2 = PickerPanelRef.current) === null || _PickerPanelRef$curre2 === void 0 || _PickerPanelRef$curre2.addEventListener('touchmove', panelTouchMove);
|
|
190
|
+
(_PickerPanelRef$curre3 = PickerPanelRef.current) === null || _PickerPanelRef$curre3 === void 0 || _PickerPanelRef$curre3.addEventListener('touchend', panelTouchEnd);
|
|
191
|
+
return function () {
|
|
192
|
+
var _PickerPanelRef$curre4, _PickerPanelRef$curre5, _PickerPanelRef$curre6;
|
|
193
|
+
(_PickerPanelRef$curre4 = PickerPanelRef.current) === null || _PickerPanelRef$curre4 === void 0 || _PickerPanelRef$curre4.removeEventListener('touchstart', panelTouchStart);
|
|
194
|
+
(_PickerPanelRef$curre5 = PickerPanelRef.current) === null || _PickerPanelRef$curre5 === void 0 || _PickerPanelRef$curre5.removeEventListener('touchmove', panelTouchMove);
|
|
195
|
+
(_PickerPanelRef$curre6 = PickerPanelRef.current) === null || _PickerPanelRef$curre6 === void 0 || _PickerPanelRef$curre6.removeEventListener('touchend', panelTouchEnd);
|
|
196
|
+
};
|
|
197
|
+
});
|
|
198
|
+
var onTransitionEnd = function onTransitionEnd(e) {
|
|
199
|
+
isVerticalMoving.current = false;
|
|
200
|
+
setTouchTime(0);
|
|
201
|
+
onSelect === null || onSelect === void 0 || onSelect(e, {
|
|
202
|
+
columnOption: options === null || options === void 0 ? void 0 : options[Math.round(-scrollDistance / LINE_SPACING)],
|
|
203
|
+
columnIndex: columnIndex
|
|
204
|
+
});
|
|
205
|
+
};
|
|
206
|
+
return /*#__PURE__*/React.createElement("div", _extends({
|
|
207
|
+
className: prefixCls,
|
|
208
|
+
ref: pickerPanelRef,
|
|
209
|
+
onTouchStart: panelTouchStart,
|
|
210
|
+
onTouchMove: panelTouchMove,
|
|
211
|
+
onTouchEnd: panelTouchEnd
|
|
212
|
+
}, others), /*#__PURE__*/React.createElement("div", {
|
|
213
|
+
className: "".concat(prefixCls, "-roller"),
|
|
214
|
+
style: {
|
|
215
|
+
transition: "transform ".concat(touchTime, "ms cubic-bezier(0.17, 0.89, 0.45, 1)"),
|
|
216
|
+
transform: "rotate3d(1, 0, 0, ".concat(touchDeg, ")")
|
|
217
|
+
},
|
|
218
|
+
onTransitionEnd: onTransitionEnd
|
|
219
|
+
}, options.map(function (item, i) {
|
|
220
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
221
|
+
className: clsx("".concat(prefixCls, "-option"), _defineProperty({}, "".concat(prefixCls, "-option-hidden"), i + 1 <= currIndex - 8 || i + 1 >= currIndex + 8)),
|
|
222
|
+
key: "".concat(item === null || item === void 0 ? void 0 : item.value, "-").concat(i),
|
|
223
|
+
style: {
|
|
224
|
+
transform: "rotate3d(1, 0, 0, ".concat(-ROTATION * (i + 1), "deg) translate3d(0px, 0px, 104px)")
|
|
225
|
+
}
|
|
226
|
+
}, item === null || item === void 0 ? void 0 : item.label);
|
|
227
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
228
|
+
className: "".concat(prefixCls, "-mask")
|
|
229
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
230
|
+
className: "".concat(prefixCls, "-indicator")
|
|
231
|
+
}));
|
|
232
|
+
});
|
|
233
|
+
PickerPanel.displayName = 'BuiPickerPanel';
|
|
234
|
+
export default PickerPanel;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
@import '~@bifrostui/styles/mixins/index.less';
|
|
2
|
+
|
|
3
|
+
.bui-picker-panel {
|
|
4
|
+
flex: 1;
|
|
5
|
+
flex-shrink: 0;
|
|
6
|
+
position: relative;
|
|
7
|
+
font-family: var(--bui-font-family);
|
|
8
|
+
|
|
9
|
+
&-roller {
|
|
10
|
+
transform: rotate3d(1, 0, 0, 60deg);
|
|
11
|
+
transform-style: preserve-3d;
|
|
12
|
+
position: absolute;
|
|
13
|
+
top: var(--indicator-top);
|
|
14
|
+
width: 100%;
|
|
15
|
+
height: var(--option-height);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
&-mask {
|
|
19
|
+
position: absolute;
|
|
20
|
+
top: 0;
|
|
21
|
+
left: 0;
|
|
22
|
+
width: 100%;
|
|
23
|
+
height: 100%;
|
|
24
|
+
background-image: linear-gradient(
|
|
25
|
+
180deg,
|
|
26
|
+
var(--bui-color-bg-view-opacity-9),
|
|
27
|
+
var(--bui-color-bg-view-opacity-4)
|
|
28
|
+
),
|
|
29
|
+
linear-gradient(
|
|
30
|
+
0deg,
|
|
31
|
+
var(--bui-color-bg-view-opacity-9),
|
|
32
|
+
var(--bui-color-bg-view-opacity-4)
|
|
33
|
+
);
|
|
34
|
+
background-position: top, bottom;
|
|
35
|
+
background-size: 100% var(--indicator-top);
|
|
36
|
+
background-repeat: no-repeat;
|
|
37
|
+
transform: translateZ(0);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
&-indicator {
|
|
41
|
+
position: absolute;
|
|
42
|
+
top: var(--indicator-top);
|
|
43
|
+
height: var(--indicator-height);
|
|
44
|
+
width: 100%;
|
|
45
|
+
border-top: 1px solid var(--indicator-border-color);
|
|
46
|
+
border-bottom: 1px solid var(--indicator-border-color);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
&-option {
|
|
50
|
+
position: absolute;
|
|
51
|
+
top: 0;
|
|
52
|
+
left: 0;
|
|
53
|
+
text-align: center;
|
|
54
|
+
height: var(--option-height);
|
|
55
|
+
line-height: var(--option-height);
|
|
56
|
+
color: var(--option-color);
|
|
57
|
+
font-size: var(--option-font-size);
|
|
58
|
+
backface-visibility: hidden;
|
|
59
|
+
.ellipsis();
|
|
60
|
+
width: 100%;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
&-option-hidden {
|
|
64
|
+
visibility: hidden;
|
|
65
|
+
opacity: 0;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ICascadePickerOptionItem } from './Picker.types';
|
|
2
|
+
/**
|
|
3
|
+
* 根据第一列数据判断选择器类型
|
|
4
|
+
*/
|
|
5
|
+
export declare const pickerPanelType: (options?: any[]) => "multiple" | "single" | "cascade";
|
|
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[];
|