@bifrostui/react 1.0.5 → 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.
Files changed (65) hide show
  1. package/dist/CitySelector/CitySelector.css +102 -0
  2. package/dist/CitySelector/CitySelector.d.ts +4 -0
  3. package/dist/CitySelector/CitySelector.js +36 -0
  4. package/dist/CitySelector/CitySelector.miniapp.d.ts +5 -0
  5. package/dist/CitySelector/CitySelector.miniapp.js +79 -0
  6. package/dist/CitySelector/CitySelector.types.d.ts +47 -0
  7. package/dist/CitySelector/CitySelector.types.js +5 -0
  8. package/dist/CitySelector/CitySelectorCore.d.ts +5 -0
  9. package/dist/CitySelector/CitySelectorCore.js +184 -0
  10. package/dist/CitySelector/Selector/index.css +11 -0
  11. package/dist/CitySelector/Selector/index.d.ts +9 -0
  12. package/dist/CitySelector/Selector/index.js +22 -0
  13. package/dist/CitySelector/index.d.ts +2 -0
  14. package/dist/CitySelector/index.js +34 -0
  15. package/dist/CitySelector/miniapp.css +4 -0
  16. package/dist/Modal/Modal.miniapp.d.ts +16 -0
  17. package/dist/Modal/Modal.miniapp.js +73 -0
  18. package/dist/Picker/Picker.css +53 -0
  19. package/dist/Picker/Picker.d.ts +5 -0
  20. package/dist/Picker/Picker.js +155 -0
  21. package/dist/Picker/Picker.types.d.ts +98 -0
  22. package/dist/Picker/Picker.types.js +5 -0
  23. package/dist/Picker/PickerPanel.css +54 -0
  24. package/dist/Picker/PickerPanel.d.ts +5 -0
  25. package/dist/Picker/PickerPanel.js +210 -0
  26. package/dist/Picker/index.d.ts +2 -0
  27. package/dist/Picker/index.js +34 -0
  28. package/dist/Picker/utils.d.ts +13 -0
  29. package/dist/Picker/utils.js +66 -0
  30. package/dist/Tabs/Tabs.css +2 -2
  31. package/dist/index.d.ts +2 -0
  32. package/dist/index.js +22 -0
  33. package/es/CitySelector/CitySelector.css +102 -0
  34. package/es/CitySelector/CitySelector.d.ts +4 -0
  35. package/es/CitySelector/CitySelector.js +36 -0
  36. package/es/CitySelector/CitySelector.miniapp.d.ts +5 -0
  37. package/es/CitySelector/CitySelector.miniapp.js +77 -0
  38. package/es/CitySelector/CitySelector.types.d.ts +47 -0
  39. package/es/CitySelector/CitySelector.types.js +1 -0
  40. package/es/CitySelector/CitySelectorCore.d.ts +5 -0
  41. package/es/CitySelector/CitySelectorCore.js +195 -0
  42. package/es/CitySelector/Selector/index.css +11 -0
  43. package/es/CitySelector/Selector/index.d.ts +9 -0
  44. package/es/CitySelector/Selector/index.js +13 -0
  45. package/es/CitySelector/index.d.ts +2 -0
  46. package/es/CitySelector/index.js +2 -0
  47. package/es/CitySelector/miniapp.css +4 -0
  48. package/es/Modal/Modal.miniapp.d.ts +16 -0
  49. package/es/Modal/Modal.miniapp.js +78 -0
  50. package/es/Picker/Picker.css +53 -0
  51. package/es/Picker/Picker.d.ts +5 -0
  52. package/es/Picker/Picker.js +171 -0
  53. package/es/Picker/Picker.types.d.ts +98 -0
  54. package/es/Picker/Picker.types.js +1 -0
  55. package/es/Picker/PickerPanel.css +54 -0
  56. package/es/Picker/PickerPanel.d.ts +5 -0
  57. package/es/Picker/PickerPanel.js +234 -0
  58. package/es/Picker/index.d.ts +2 -0
  59. package/es/Picker/index.js +2 -0
  60. package/es/Picker/utils.d.ts +13 -0
  61. package/es/Picker/utils.js +65 -0
  62. package/es/Tabs/Tabs.css +2 -2
  63. package/es/index.d.ts +2 -0
  64. package/es/index.js +3 -1
  65. package/package.json +6 -6
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.pickerPanelType = exports.formatOptions = exports.formatCascade = void 0;
7
+ /**
8
+ * 根据第一列数据判断选择器类型
9
+ */
10
+ const pickerPanelType = (options = []) => {
11
+ const firstColumn = options[0];
12
+
13
+ // 多列模式
14
+ if (Array.isArray(firstColumn)) {
15
+ return 'multiple';
16
+ }
17
+
18
+ // 级联模式
19
+ if (firstColumn?.children) {
20
+ return 'cascade';
21
+ }
22
+
23
+ // 单列模式
24
+ return 'single';
25
+ };
26
+
27
+ /**
28
+ * 格式化级联模式数据
29
+ */
30
+ exports.pickerPanelType = pickerPanelType;
31
+ const formatCascade = (columns, values) => {
32
+ const result = [];
33
+ let columnOptions = {
34
+ label: '',
35
+ value: '',
36
+ children: columns
37
+ };
38
+ let columnIndex = 0;
39
+ while (columnOptions?.children) {
40
+ const options = columnOptions.children;
41
+ const value = values?.[columnIndex];
42
+ let index = options.findIndex(item => item.value === value);
43
+ if (index === -1) index = 0;
44
+ columnOptions = columnOptions.children[index];
45
+ columnIndex += 1;
46
+ result.push(options);
47
+ }
48
+ return result;
49
+ };
50
+
51
+ /**
52
+ * 统一options数据格式
53
+ */
54
+ exports.formatCascade = formatCascade;
55
+ const formatOptions = (internalValue, options = []) => {
56
+ const panelType = pickerPanelType(options);
57
+ switch (panelType) {
58
+ case 'multiple':
59
+ return options;
60
+ case 'cascade':
61
+ return formatCascade(options, internalValue);
62
+ default:
63
+ return options;
64
+ }
65
+ };
66
+ exports.formatOptions = formatOptions;
@@ -44,11 +44,11 @@
44
44
  }
45
45
  .bui-tabs-mask-left {
46
46
  left: 0;
47
- background: linear-gradient(to right, var(--bui-color-white), rgba(255, 255, 255, 0));
47
+ background: linear-gradient(to right, var(--bui-color-bg-view), rgba(255, 255, 255, 0));
48
48
  }
49
49
  .bui-tabs-mask-right {
50
50
  right: 0;
51
- background: linear-gradient(to left, var(--bui-color-white), rgba(255, 255, 255, 0));
51
+ background: linear-gradient(to left, var(--bui-color-bg-view), rgba(255, 255, 255, 0));
52
52
  }
53
53
  .bui-tabline-invisible {
54
54
  visibility: hidden;
package/dist/index.d.ts CHANGED
@@ -36,3 +36,5 @@ export * from './NavBar';
36
36
  export * from './Loading';
37
37
  export * from './TabBar';
38
38
  export * from './Countdown';
39
+ export * from './CitySelector';
40
+ export * from './Picker';
package/dist/index.js CHANGED
@@ -420,4 +420,26 @@ Object.keys(_Countdown).forEach(function (key) {
420
420
  return _Countdown[key];
421
421
  }
422
422
  });
423
+ });
424
+ var _CitySelector = require("./CitySelector");
425
+ Object.keys(_CitySelector).forEach(function (key) {
426
+ if (key === "default" || key === "__esModule") return;
427
+ if (key in exports && exports[key] === _CitySelector[key]) return;
428
+ Object.defineProperty(exports, key, {
429
+ enumerable: true,
430
+ get: function () {
431
+ return _CitySelector[key];
432
+ }
433
+ });
434
+ });
435
+ var _Picker = require("./Picker");
436
+ Object.keys(_Picker).forEach(function (key) {
437
+ if (key === "default" || key === "__esModule") return;
438
+ if (key in exports && exports[key] === _Picker[key]) return;
439
+ Object.defineProperty(exports, key, {
440
+ enumerable: true,
441
+ get: function () {
442
+ return _Picker[key];
443
+ }
444
+ });
423
445
  });
@@ -0,0 +1,102 @@
1
+ .bui-city-selector {
2
+ font-family: var(--bui-font-family);
3
+ height: 100%;
4
+ position: relative;
5
+ }
6
+ .bui-city-selector-title {
7
+ width: 100%;
8
+ height: 45px;
9
+ color: var(--bui-color-fg-default);
10
+ font-size: var(--bui-title-size-3);
11
+ line-height: 45px;
12
+ text-align: center;
13
+ position: sticky;
14
+ top: 0;
15
+ z-index: 1004;
16
+ border-bottom: solid 1px var(--bui-color-border-default);
17
+ background-color: var(--bui-color-bg-view);
18
+ }
19
+ .bui-city-selector-btn-close {
20
+ position: absolute;
21
+ top: 0;
22
+ right: 0;
23
+ width: 45px;
24
+ height: 45px;
25
+ color: var(--bui-color-fg-muted);
26
+ text-align: center;
27
+ font-size: 20px;
28
+ }
29
+ .bui-city-selector-scroll-view-container {
30
+ height: 100%;
31
+ }
32
+ .bui-city-selector-scroll-view-container.container-has-title {
33
+ height: calc(100% - 45px);
34
+ }
35
+ .bui-city-selector-all-city {
36
+ min-height: 500px;
37
+ font-size: var(--bui-text-size-2);
38
+ width: 100%;
39
+ background: var(--bui-color-bg-view);
40
+ align-self: flex-start;
41
+ }
42
+ .bui-city-selector-all-city .select-city-buttons {
43
+ display: flex;
44
+ flex-flow: wrap;
45
+ padding-left: 3px;
46
+ padding-top: 7.5px;
47
+ }
48
+ .bui-city-selector-all-city .select-city-title {
49
+ font-size: var(--bui-title-size-4);
50
+ line-height: 15px;
51
+ font-weight: 600;
52
+ padding-left: var(--bui-spacing-lg);
53
+ padding-top: 9px;
54
+ }
55
+ .bui-city-selector-list {
56
+ padding-left: var(--bui-spacing-lg);
57
+ list-style-type: none;
58
+ }
59
+ .bui-city-selector-list-item {
60
+ height: 45px;
61
+ font-size: var(--bui-title-size-4);
62
+ display: flex;
63
+ align-items: center;
64
+ }
65
+ .bui-city-selector-list-item:not(:last-child) {
66
+ border-bottom: 0.5px solid var(--bui-color-border-default);
67
+ }
68
+ .bui-city-selector-index-container {
69
+ z-index: 1001;
70
+ position: absolute;
71
+ white-space: nowrap;
72
+ right: 0;
73
+ top: 50%;
74
+ width: 40px;
75
+ will-change: transform;
76
+ transform: translate(0, -50%);
77
+ transition: opacity 0.2s ease-out, transform 0.2s ease-out;
78
+ }
79
+ .bui-city-selector-index-container.left-in {
80
+ opacity: 1;
81
+ transform: translate(0, -50%);
82
+ }
83
+ .bui-city-selector-index-container.city-index-has-title {
84
+ top: calc(50% + 22.5px);
85
+ }
86
+ .bui-city-selector-index-container ul {
87
+ margin: 0;
88
+ padding: 0;
89
+ float: left;
90
+ width: 100%;
91
+ touch-action: none;
92
+ }
93
+ .bui-city-selector-index-container li {
94
+ list-style: none;
95
+ height: 20px;
96
+ text-align: center;
97
+ font-size: var(--bui-text-size-3);
98
+ color: var(--bui-color-info, --bui-color-info);
99
+ display: flex;
100
+ align-items: center;
101
+ justify-content: center;
102
+ }
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import { CitySelectorProps } from './CitySelector.types';
3
+ declare const CitySelector: React.ForwardRefExoticComponent<Omit<CitySelectorProps, "ref"> & React.RefAttributes<HTMLDivElement>>;
4
+ export default CitySelector;
@@ -0,0 +1,36 @@
1
+ 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); }
2
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
+ 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."); }
4
+ 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); }
5
+ 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; }
6
+ 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; } }
7
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
8
+ import React, { useEffect, useState } from 'react';
9
+ import CitySelectorCore from "./CitySelectorCore";
10
+ var CitySelector = /*#__PURE__*/React.forwardRef(function (props, ref) {
11
+ var cities = props.cities;
12
+ var _useState = useState(''),
13
+ _useState2 = _slicedToArray(_useState, 2),
14
+ height = _useState2[0],
15
+ setHeight = _useState2[1];
16
+ var touchHandler = function touchHandler(e, scrollToCode) {
17
+ var _t$dataset;
18
+ var t = document.elementFromPoint(e.changedTouches[0].clientX, e.changedTouches[0].clientY);
19
+ var code = t === null || t === void 0 || (_t$dataset = t.dataset) === null || _t$dataset === void 0 ? void 0 : _t$dataset.code;
20
+ scrollToCode(code);
21
+ };
22
+ useEffect(function () {
23
+ var _document$querySelect;
24
+ if (!(cities !== null && cities !== void 0 && cities.length) || height) return;
25
+ var screenHeight = window.innerHeight || document.documentElement.clientHeight;
26
+ var domHeight = (_document$querySelect = document.querySelector('.bui-city-selector-scroll-view-container')) === null || _document$querySelect === void 0 ? void 0 : _document$querySelect.getBoundingClientRect().height;
27
+ setHeight("".concat(domHeight / screenHeight * 100, "vh"));
28
+ }, [cities]);
29
+ return /*#__PURE__*/React.createElement(CitySelectorCore, _extends({}, props, {
30
+ ref: ref,
31
+ touchHandler: touchHandler,
32
+ height: height
33
+ }));
34
+ });
35
+ CitySelector.displayName = 'BuiCitySelector';
36
+ export default CitySelector;
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import { CitySelectorProps } from './CitySelector.types';
3
+ import './miniapp.less';
4
+ declare const CitySelector: React.ForwardRefExoticComponent<Omit<CitySelectorProps, "ref"> & React.RefAttributes<HTMLDivElement>>;
5
+ export default CitySelector;
@@ -0,0 +1,77 @@
1
+ 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); }
2
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
+ 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."); }
4
+ 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); }
5
+ 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; }
6
+ 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; } }
7
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
8
+ import React, { useEffect, useRef, useState } from 'react';
9
+ import Taro from '@tarojs/taro';
10
+ import CitySelectorCore from "./CitySelectorCore";
11
+ import "./miniapp.css";
12
+ var CitySelector = /*#__PURE__*/React.forwardRef(function (props, ref) {
13
+ var cities = props.cities;
14
+ var containerTop = useRef(0);
15
+ var codeHeight = useRef(0);
16
+ var _useState = useState(''),
17
+ _useState2 = _slicedToArray(_useState, 2),
18
+ height = _useState2[0],
19
+ setHeight = _useState2[1];
20
+ var queryContainerTop = function queryContainerTop(cbk) {
21
+ var query = Taro.createSelectorQuery();
22
+ query.select('.bui-city-selector-index-container').boundingClientRect();
23
+ query.exec(function (res) {
24
+ var _res$;
25
+ containerTop.current = (_res$ = res[0]) === null || _res$ === void 0 ? void 0 : _res$.top;
26
+ cbk === null || cbk === void 0 || cbk();
27
+ });
28
+ };
29
+ useEffect(function () {
30
+ if ((cities === null || cities === void 0 ? void 0 : cities.length) === 0 || codeHeight.current) return;
31
+ // 演示获取字母高度
32
+ setTimeout(function () {
33
+ var query = Taro.createSelectorQuery();
34
+ query.select('.bui-city-selector-index-item').boundingClientRect();
35
+ query.exec(function (res) {
36
+ var _res$2;
37
+ codeHeight.current = (_res$2 = res[0]) === null || _res$2 === void 0 ? void 0 : _res$2.height;
38
+ });
39
+ }, 300);
40
+ }, [cities, height]);
41
+ useEffect(function () {
42
+ if (!(cities !== null && cities !== void 0 && cities.length) || height) return;
43
+ var _Taro$getSystemInfoSy = Taro.getSystemInfoSync(),
44
+ screenHeight = _Taro$getSystemInfoSy.screenHeight;
45
+ var query = Taro.createSelectorQuery();
46
+ query.select('.bui-city-selector-scroll-view-container').boundingClientRect();
47
+ query.exec(function (codeRect) {
48
+ var _codeRect$;
49
+ var domHeight = codeRect === null || codeRect === void 0 || (_codeRect$ = codeRect[0]) === null || _codeRect$ === void 0 ? void 0 : _codeRect$.height;
50
+ setHeight("".concat(domHeight / screenHeight * 100, "vh"));
51
+ });
52
+ }, [cities]);
53
+ var parseIndex = function parseIndex(length, index) {
54
+ if (index <= 0) return 0;
55
+ if (index >= length - 1) return length - 1;
56
+ return index;
57
+ };
58
+ var pxToCode = function pxToCode(clientY, scrollToCode, codeGroup) {
59
+ var index = Math.floor((clientY - containerTop.current) / codeHeight.current);
60
+ index = parseIndex(codeGroup.length, index);
61
+ var codeItem = codeGroup[index];
62
+ scrollToCode(codeItem.code || codeItem);
63
+ };
64
+ var touchHandler = function touchHandler(event, scrollToCode, codeGroup) {
65
+ var clientY = event.changedTouches[0].clientY;
66
+ queryContainerTop(function () {
67
+ pxToCode(clientY, scrollToCode, codeGroup);
68
+ });
69
+ };
70
+ return /*#__PURE__*/React.createElement(CitySelectorCore, _extends({}, props, {
71
+ ref: ref,
72
+ touchHandler: touchHandler,
73
+ height: height
74
+ }));
75
+ });
76
+ CitySelector.displayName = 'BuiCitySelector';
77
+ export default CitySelector;
@@ -0,0 +1,47 @@
1
+ /// <reference types="react" />
2
+ import { OverrideProps } from '@bifrostui/types';
3
+ export type cityType = {
4
+ /** 城市名 */
5
+ name: string;
6
+ /** 城市名id */
7
+ code: string;
8
+ };
9
+ export type allCityItemType = {
10
+ /** 城市列表 */
11
+ cities: cityType[];
12
+ /** 索引字母 */
13
+ groupName: string;
14
+ };
15
+ export type CitySelectorProps<D extends React.ElementType = 'div', P = {}> = OverrideProps<{
16
+ props: P & {
17
+ /** 当前城市信息 */
18
+ selectedCity?: cityType;
19
+ /** 当前城市栏的title */
20
+ selectedCityGroupName?: string;
21
+ /** 定位城市信息 */
22
+ currentCity?: cityType;
23
+ /** 定位城市栏的title */
24
+ currentCityGroupName?: string;
25
+ /** 热门城市信息 */
26
+ hotCities?: cityType[];
27
+ /** 热门城市栏的title */
28
+ hotCitiesGroupName?: string;
29
+ /** 城市列表 */
30
+ cities: allCityItemType[];
31
+ /** 禁用展示索引 默认false 即展示索引 */
32
+ disableIndex?: boolean;
33
+ /** 头部标题 */
34
+ title?: string;
35
+ /** 选择城市回调 */
36
+ onSelect: (e: React.SyntheticEvent, data: {
37
+ city: cityType;
38
+ }) => void;
39
+ /** 和title配合使用,头部右侧的关闭回调 */
40
+ onClose?: (e: React.SyntheticEvent) => void;
41
+ };
42
+ defaultComponent: D;
43
+ }, D>;
44
+ export type CitySelectorCoreProps = CitySelectorProps & {
45
+ touchHandler: any;
46
+ height?: string;
47
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import { CitySelectorCoreProps } from './CitySelector.types';
3
+ import './CitySelector.less';
4
+ declare const CitySelector: React.ForwardRefExoticComponent<Omit<CitySelectorCoreProps, "ref"> & React.RefAttributes<HTMLDivElement>>;
5
+ export default CitySelector;
@@ -0,0 +1,195 @@
1
+ var _excluded = ["className", "title", "selectedCity", "selectedCityGroupName", "currentCity", "currentCityGroupName", "hotCities", "hotCitiesGroupName", "cities", "disableIndex", "touchHandler", "height", "onSelect", "onClose", "ref"];
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 React, { useState, useEffect, useRef } from 'react';
12
+ import clsx from 'clsx';
13
+ import { throttle, useForkRef, useTouchEmulator } from '@bifrostui/utils';
14
+ import { ScrollView } from "../ScrollView";
15
+ import Selector from "./Selector";
16
+ import "./CitySelector.css";
17
+
18
+ // 误差偏移量
19
+ var DEVIATION_HEIGHT = '6vmin';
20
+ var GPS_TYPE = {
21
+ title: '定位',
22
+ code: 'GPS'
23
+ };
24
+ var CURRENT_TYPE = {
25
+ title: '当前',
26
+ code: 'CRRT'
27
+ };
28
+ var HOT_CITY_TYPE = {
29
+ title: '热门',
30
+ code: 'HOT'
31
+ };
32
+ var prefixCls = 'bui-city-selector';
33
+ var CitySelector = /*#__PURE__*/React.forwardRef(function (props, ref) {
34
+ var className = props.className,
35
+ pageTitle = props.title,
36
+ selectedCity = props.selectedCity,
37
+ _props$selectedCityGr = props.selectedCityGroupName,
38
+ selectedCityGroupName = _props$selectedCityGr === void 0 ? '当前城市' : _props$selectedCityGr,
39
+ currentCity = props.currentCity,
40
+ _props$currentCityGro = props.currentCityGroupName,
41
+ currentCityGroupName = _props$currentCityGro === void 0 ? '定位城市' : _props$currentCityGro,
42
+ hotCities = props.hotCities,
43
+ _props$hotCitiesGroup = props.hotCitiesGroupName,
44
+ hotCitiesGroupName = _props$hotCitiesGroup === void 0 ? '热门城市' : _props$hotCitiesGroup,
45
+ cities = props.cities,
46
+ disableIndex = props.disableIndex,
47
+ touchHandler = props.touchHandler,
48
+ height = props.height,
49
+ onSelect = props.onSelect,
50
+ onClose = props.onClose,
51
+ propsRef = props.ref,
52
+ others = _objectWithoutProperties(props, _excluded);
53
+ var cityRef = useRef(null);
54
+ var nodeRef = useForkRef(ref, propsRef, cityRef);
55
+ useTouchEmulator(cityRef.current);
56
+ var _useState = useState([]),
57
+ _useState2 = _slicedToArray(_useState, 2),
58
+ codeGroup = _useState2[0],
59
+ setCodeGroup = _useState2[1];
60
+ var _useState3 = useState(false),
61
+ _useState4 = _slicedToArray(_useState3, 2),
62
+ codeShow = _useState4[0],
63
+ setCodeShow = _useState4[1];
64
+ var _useState5 = useState(''),
65
+ _useState6 = _slicedToArray(_useState5, 2),
66
+ targetId = _useState6[0],
67
+ setTargetId = _useState6[1];
68
+
69
+ // 提取字母
70
+ useEffect(function () {
71
+ if (!cities || (cities === null || cities === void 0 ? void 0 : cities.length) === 0 || codeGroup.length !== 0 || disableIndex) return;
72
+ var newGroup = [];
73
+ if (selectedCity) {
74
+ newGroup.push(CURRENT_TYPE);
75
+ }
76
+ if (currentCity) {
77
+ newGroup.push(GPS_TYPE);
78
+ }
79
+ if (hotCities) {
80
+ newGroup.push(HOT_CITY_TYPE);
81
+ }
82
+ cities.forEach(function (item) {
83
+ newGroup.push(item.groupName.toUpperCase());
84
+ });
85
+ setCodeGroup(newGroup);
86
+ }, [cities, selectedCity, currentCity, hotCities]);
87
+
88
+ // 计算每个code的top
89
+ useEffect(function () {
90
+ if (codeGroup.length === 0) return;
91
+ setCodeShow(true);
92
+ }, [codeGroup]);
93
+ var selectHandler = function selectHandler(e, city) {
94
+ onSelect(e, {
95
+ city: city
96
+ });
97
+ };
98
+ var scrollToCode = function scrollToCode(targetCode) {
99
+ if (!targetCode) return;
100
+ setTargetId(function (oldCode) {
101
+ if (targetCode !== oldCode) return targetCode;
102
+ return oldCode;
103
+ });
104
+ };
105
+ var touchCbk = function touchCbk(e) {
106
+ e.stopPropagation();
107
+ touchHandler === null || touchHandler === void 0 || touchHandler(e, scrollToCode, codeGroup);
108
+ };
109
+ var codeClickHandler = function codeClickHandler(rightCode) {
110
+ setTargetId(rightCode);
111
+ };
112
+ var scrollHandler = throttle(function () {
113
+ if (targetId) {
114
+ setTargetId(undefined);
115
+ }
116
+ }, 500);
117
+ var closeHandler = function closeHandler(e) {
118
+ onClose === null || onClose === void 0 || onClose(e);
119
+ };
120
+ var renderTitile = function renderTitile(title, titleCode) {
121
+ var parseTitle = (titleCode || title).toUpperCase();
122
+ return /*#__PURE__*/React.createElement("div", {
123
+ className: "select-city-title",
124
+ id: disableIndex ? '' : parseTitle
125
+ }, title.toUpperCase());
126
+ };
127
+ var renderCity = function renderCity(citys, title, titleCode) {
128
+ return /*#__PURE__*/React.createElement("div", null, renderTitile(title, titleCode), /*#__PURE__*/React.createElement("div", {
129
+ className: "select-city-buttons"
130
+ }, citys.map(function (city, index) {
131
+ return /*#__PURE__*/React.createElement(Selector, {
132
+ key: index,
133
+ city: city,
134
+ onSelect: selectHandler
135
+ });
136
+ })));
137
+ };
138
+ return /*#__PURE__*/React.createElement("div", _extends({
139
+ className: clsx(prefixCls, className),
140
+ ref: nodeRef
141
+ }, others), pageTitle ? /*#__PURE__*/React.createElement("div", {
142
+ className: "".concat(prefixCls, "-title")
143
+ }, pageTitle, /*#__PURE__*/React.createElement("div", {
144
+ className: "".concat(prefixCls, "-btn-close"),
145
+ onClick: closeHandler
146
+ }, "\u2715")) : null, /*#__PURE__*/React.createElement(ScrollView, {
147
+ scrollIntoView: targetId,
148
+ scrollY: true,
149
+ className: clsx("".concat(prefixCls, "-scroll-view-container tph"), {
150
+ 'container-has-title': pageTitle
151
+ }),
152
+ onScroll: scrollHandler
153
+ }, /*#__PURE__*/React.createElement("div", {
154
+ className: "".concat(prefixCls, "-all-city")
155
+ }, selectedCity ? renderCity([selectedCity], selectedCityGroupName, CURRENT_TYPE.code) : null, currentCity ? renderCity([currentCity], currentCityGroupName, GPS_TYPE.code) : null, (hotCities === null || hotCities === void 0 ? void 0 : hotCities.length) > 0 ? renderCity(hotCities, hotCitiesGroupName, HOT_CITY_TYPE.code) : null, (cities === null || cities === void 0 ? void 0 : cities.length) > 0 ? /*#__PURE__*/React.createElement("div", {
156
+ className: "".concat(prefixCls, "-list-container")
157
+ }, cities.map(function (item, cityGroupIndex) {
158
+ if (!(item !== null && item !== void 0 && item.groupName)) return null;
159
+ return /*#__PURE__*/React.createElement("div", {
160
+ key: cityGroupIndex
161
+ }, renderTitile(item.groupName, item.groupName), /*#__PURE__*/React.createElement("ul", {
162
+ className: "".concat(prefixCls, "-list")
163
+ }, item.cities.map(function (city, cityIndex) {
164
+ return /*#__PURE__*/React.createElement("li", {
165
+ className: "".concat(prefixCls, "-list-item"),
166
+ key: cityIndex,
167
+ onClick: function onClick(e) {
168
+ selectHandler(e, city);
169
+ }
170
+ }, city.name);
171
+ })));
172
+ })) : null)), (codeGroup === null || codeGroup === void 0 ? void 0 : codeGroup.length) > 0 && height ? /*#__PURE__*/React.createElement("div", {
173
+ className: clsx("".concat(prefixCls, "-index-container"), {
174
+ 'left-in': codeShow,
175
+ 'city-index-has-title': pageTitle
176
+ })
177
+ }, /*#__PURE__*/React.createElement("ul", {
178
+ onTouchMove: touchCbk,
179
+ className: "".concat(prefixCls, "-index-list")
180
+ }, codeGroup.map(function (item, chartIndex) {
181
+ return /*#__PURE__*/React.createElement("li", {
182
+ className: "".concat(prefixCls, "-index-item"),
183
+ key: chartIndex,
184
+ "data-code": item.code || item,
185
+ onClick: function onClick() {
186
+ codeClickHandler(item.code || item);
187
+ },
188
+ style: {
189
+ maxHeight: "calc((".concat(height, " - ").concat(DEVIATION_HEIGHT, ") / ").concat(codeGroup.length, ")")
190
+ }
191
+ }, item.title || item);
192
+ }))) : null);
193
+ });
194
+ CitySelector.displayName = 'BuiCitySelector';
195
+ export default CitySelector;
@@ -0,0 +1,11 @@
1
+ .bui-city-selector-item {
2
+ width: 111px;
3
+ height: 36px;
4
+ display: inline-flex;
5
+ justify-content: center;
6
+ align-items: center;
7
+ border-radius: 20px;
8
+ margin: 4.5px 0 4.5px 9px;
9
+ background-color: var(--bui-color-bg-default);
10
+ font-size: var(--bui-text-size-2);
11
+ }
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ import { cityType } from '../CitySelector.types';
3
+ import './index.less';
4
+ type propsType = {
5
+ city: cityType;
6
+ onSelect: (e: React.SyntheticEvent, city: cityType) => void;
7
+ };
8
+ declare const Selector: (props: propsType) => React.JSX.Element;
9
+ export default Selector;
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import "./index.css";
3
+ var Selector = function Selector(props) {
4
+ var city = props.city,
5
+ onSelect = props.onSelect;
6
+ return /*#__PURE__*/React.createElement("span", {
7
+ className: "bui-city-selector-item",
8
+ onClick: function onClick(e) {
9
+ onSelect === null || onSelect === void 0 || onSelect(e, city);
10
+ }
11
+ }, city.name);
12
+ };
13
+ export default Selector;
@@ -0,0 +1,2 @@
1
+ export { default as CitySelector, default } from './CitySelector';
2
+ export * from './CitySelector.types';
@@ -0,0 +1,2 @@
1
+ export { default as CitySelector, default } from "./CitySelector";
2
+ export * from "./CitySelector.types";
@@ -0,0 +1,4 @@
1
+ .bui-city-scroll-view-container {
2
+ height: 100%;
3
+ display: block;
4
+ }