@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,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ViewProps } from '@tarojs/components';
|
|
3
|
+
import './Modal.less';
|
|
4
|
+
declare const Modal: React.ForwardRefExoticComponent<Omit<ViewProps & {
|
|
5
|
+
open?: boolean;
|
|
6
|
+
container?: Element | (() => Element);
|
|
7
|
+
hideBackdrop?: boolean;
|
|
8
|
+
BackdropProps?: Partial<import("../Backdrop").BackdropProps>;
|
|
9
|
+
onClose?: (e: React.SyntheticEvent<Element, Event>, detail: import("./Modal.types").CloseDetail) => void;
|
|
10
|
+
disableScrollLock?: boolean;
|
|
11
|
+
disablePortal?: boolean;
|
|
12
|
+
keepMounted?: boolean;
|
|
13
|
+
} & import("../../../bui-types/src").ICommonProps & Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
14
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
15
|
+
}, keyof import("../../../bui-types/src").ICommonProps | "open" | "container" | "hideBackdrop" | "BackdropProps" | "onClose" | "disableScrollLock" | "disablePortal" | "keepMounted">, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
16
|
+
export default Modal;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
var _excluded = ["className", "open", "BackdropProps", "children", "container", "disablePortal", "disableScrollLock", "hideBackdrop", "onClose", "keepMounted"];
|
|
2
|
+
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); }
|
|
3
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
4
|
+
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."); }
|
|
5
|
+
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); }
|
|
6
|
+
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; }
|
|
7
|
+
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; } }
|
|
8
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
9
|
+
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; }
|
|
10
|
+
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; }
|
|
11
|
+
import { useForkRef } from '@bifrostui/utils';
|
|
12
|
+
import clsx from 'clsx';
|
|
13
|
+
import React, { useState } from 'react';
|
|
14
|
+
import { View } from '@tarojs/components';
|
|
15
|
+
import Backdrop from "../Backdrop";
|
|
16
|
+
import Portal from "../Portal";
|
|
17
|
+
import "./Modal.css";
|
|
18
|
+
var prefixCls = 'bui-modal';
|
|
19
|
+
var Modal = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
20
|
+
var className = props.className,
|
|
21
|
+
open = props.open,
|
|
22
|
+
BackdropProps = props.BackdropProps,
|
|
23
|
+
children = props.children,
|
|
24
|
+
container = props.container,
|
|
25
|
+
disablePortal = props.disablePortal,
|
|
26
|
+
disableScrollLock = props.disableScrollLock,
|
|
27
|
+
hideBackdrop = props.hideBackdrop,
|
|
28
|
+
onClose = props.onClose,
|
|
29
|
+
keepMounted = props.keepMounted,
|
|
30
|
+
others = _objectWithoutProperties(props, _excluded);
|
|
31
|
+
var modalRef = React.useRef(null);
|
|
32
|
+
var handleRef = useForkRef(modalRef, ref);
|
|
33
|
+
var _useState = useState(hideBackdrop || !open),
|
|
34
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
35
|
+
backdropExited = _useState2[0],
|
|
36
|
+
setBackDropExited = _useState2[1];
|
|
37
|
+
var mounted = open || !backdropExited || keepMounted;
|
|
38
|
+
var handleBackdropClick = function handleBackdropClick(event) {
|
|
39
|
+
if (event.target.id !== event.currentTarget.id) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (onClose) {
|
|
43
|
+
onClose(event, {
|
|
44
|
+
from: 'backdrop'
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
if (!mounted) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
return /*#__PURE__*/React.createElement(Portal, {
|
|
52
|
+
container: container,
|
|
53
|
+
disablePortal: disablePortal
|
|
54
|
+
}, /*#__PURE__*/React.createElement(View, _extends({
|
|
55
|
+
className: clsx(prefixCls, className),
|
|
56
|
+
ref: handleRef,
|
|
57
|
+
catchMove: !disableScrollLock
|
|
58
|
+
}, others), !hideBackdrop ? /*#__PURE__*/React.createElement(Backdrop, _extends({
|
|
59
|
+
open: open,
|
|
60
|
+
onClick: handleBackdropClick,
|
|
61
|
+
onEnter: function onEnter() {
|
|
62
|
+
return setBackDropExited(false);
|
|
63
|
+
},
|
|
64
|
+
onExited: function onExited() {
|
|
65
|
+
return setBackDropExited(true);
|
|
66
|
+
}
|
|
67
|
+
}, BackdropProps, {
|
|
68
|
+
className: clsx("".concat(prefixCls, "-backdrop"), BackdropProps === null || BackdropProps === void 0 ? void 0 : BackdropProps.className)
|
|
69
|
+
})) : null, (open || keepMounted) && children));
|
|
70
|
+
});
|
|
71
|
+
Modal.displayName = 'BuiModal';
|
|
72
|
+
Modal.defaultProps = {
|
|
73
|
+
open: false,
|
|
74
|
+
disablePortal: false,
|
|
75
|
+
disableScrollLock: false,
|
|
76
|
+
hideBackdrop: false
|
|
77
|
+
};
|
|
78
|
+
export default Modal;
|
|
@@ -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,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,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,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
|
+
}
|