@bifrostui/react 1.4.6 → 1.4.7

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 (39) hide show
  1. package/dist/CitySelector/CitySelectorCore.js +3 -3
  2. package/dist/ItemSelector/ItemSelector.css +120 -0
  3. package/dist/ItemSelector/ItemSelector.d.ts +4 -0
  4. package/dist/ItemSelector/ItemSelector.js +84 -0
  5. package/dist/ItemSelector/ItemSelector.miniapp.d.ts +5 -0
  6. package/dist/ItemSelector/ItemSelector.miniapp.js +125 -0
  7. package/dist/ItemSelector/ItemSelector.types.d.ts +40 -0
  8. package/dist/ItemSelector/ItemSelector.types.js +15 -0
  9. package/dist/ItemSelector/ItemSelectorCore.d.ts +5 -0
  10. package/dist/ItemSelector/ItemSelectorCore.js +217 -0
  11. package/dist/ItemSelector/Selector/index.css +11 -0
  12. package/dist/ItemSelector/Selector/index.d.ts +9 -0
  13. package/dist/ItemSelector/Selector/index.js +48 -0
  14. package/dist/ItemSelector/index.d.ts +2 -0
  15. package/dist/ItemSelector/index.js +41 -0
  16. package/dist/ItemSelector/miniapp.css +4 -0
  17. package/dist/Modal/Modal.miniapp.d.ts +1 -1
  18. package/dist/index.d.ts +1 -0
  19. package/dist/index.js +2 -0
  20. package/es/CitySelector/CitySelectorCore.js +3 -3
  21. package/es/ItemSelector/ItemSelector.css +120 -0
  22. package/es/ItemSelector/ItemSelector.d.ts +4 -0
  23. package/es/ItemSelector/ItemSelector.js +57 -0
  24. package/es/ItemSelector/ItemSelector.miniapp.d.ts +5 -0
  25. package/es/ItemSelector/ItemSelector.miniapp.js +98 -0
  26. package/es/ItemSelector/ItemSelector.types.d.ts +40 -0
  27. package/es/ItemSelector/ItemSelector.types.js +1 -0
  28. package/es/ItemSelector/ItemSelectorCore.d.ts +5 -0
  29. package/es/ItemSelector/ItemSelectorCore.js +190 -0
  30. package/es/ItemSelector/Selector/index.css +11 -0
  31. package/es/ItemSelector/Selector/index.d.ts +9 -0
  32. package/es/ItemSelector/Selector/index.js +19 -0
  33. package/es/ItemSelector/index.d.ts +2 -0
  34. package/es/ItemSelector/index.js +6 -0
  35. package/es/ItemSelector/miniapp.css +4 -0
  36. package/es/Modal/Modal.miniapp.d.ts +1 -1
  37. package/es/index.d.ts +1 -0
  38. package/es/index.js +1 -0
  39. package/package.json +5 -5
@@ -0,0 +1,190 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+ var __objRest = (source, exclude) => {
18
+ var target = {};
19
+ for (var prop in source)
20
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
21
+ target[prop] = source[prop];
22
+ if (source != null && __getOwnPropSymbols)
23
+ for (var prop of __getOwnPropSymbols(source)) {
24
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
25
+ target[prop] = source[prop];
26
+ }
27
+ return target;
28
+ };
29
+ import React, { useState, useEffect, useRef } from "react";
30
+ import clsx from "clsx";
31
+ import { throttle, useForkRef, useTouchEmulator } from "@bifrostui/utils";
32
+ import ScrollView from "../ScrollView";
33
+ import Selector from "./Selector";
34
+ import "./ItemSelector.css";
35
+ const DEVIATION_HEIGHT = "6vmin";
36
+ const prefixCls = "bui-item-selector";
37
+ const ItemSelector = /* @__PURE__ */ React.forwardRef(
38
+ (props, ref) => {
39
+ const _a = props, {
40
+ className,
41
+ title: pageTitle,
42
+ items,
43
+ disableIndex,
44
+ touchHandler,
45
+ height,
46
+ onSelect,
47
+ onClose
48
+ } = _a, others = __objRest(_a, [
49
+ "className",
50
+ "title",
51
+ "items",
52
+ "disableIndex",
53
+ "touchHandler",
54
+ "height",
55
+ "onSelect",
56
+ "onClose"
57
+ ]);
58
+ const itemRef = useRef(null);
59
+ const nodeRef = useForkRef(ref, itemRef);
60
+ useTouchEmulator(itemRef.current);
61
+ const [codeGroup, setCodeGroup] = useState([]);
62
+ const [codeShow, setCodeShow] = useState(false);
63
+ const [targetId, setTargetId] = useState("");
64
+ const getGroupName = (item) => item.groupName || "";
65
+ const getIdxName = (item) => typeof item.indexName === "string" ? item.indexName : getGroupName(item);
66
+ const getIdxCode = (item) => typeof item.indexCode === "string" ? item.indexCode : getIdxName(item);
67
+ const renderTitle = (item) => {
68
+ const title = getGroupName(item);
69
+ return title ? /* @__PURE__ */ React.createElement(
70
+ "div",
71
+ {
72
+ className: "select-item-title",
73
+ id: disableIndex ? "" : getIdxCode(item)
74
+ },
75
+ title
76
+ ) : null;
77
+ };
78
+ useEffect(() => {
79
+ if (!items || (items == null ? void 0 : items.length) === 0 || codeGroup.length !== 0 || disableIndex) {
80
+ return;
81
+ }
82
+ setCodeGroup(
83
+ items.map((item) => {
84
+ return {
85
+ name: getIdxName(item),
86
+ code: getIdxCode(item)
87
+ };
88
+ })
89
+ );
90
+ }, [items]);
91
+ useEffect(() => {
92
+ if (codeGroup.length === 0)
93
+ return;
94
+ setCodeShow(true);
95
+ }, [codeGroup]);
96
+ const scrollToCode = (targetCode) => {
97
+ if (!targetCode)
98
+ return;
99
+ setTargetId((oldCode) => {
100
+ if (targetCode !== oldCode)
101
+ return targetCode;
102
+ return oldCode;
103
+ });
104
+ };
105
+ const touchCbk = (e) => {
106
+ e.stopPropagation();
107
+ touchHandler == null ? void 0 : touchHandler(e, scrollToCode, codeGroup);
108
+ };
109
+ const codeClickHandler = (rightCode) => {
110
+ setTargetId(rightCode);
111
+ };
112
+ const scrollHandler = throttle(() => {
113
+ if (targetId) {
114
+ setTargetId(void 0);
115
+ }
116
+ }, 500);
117
+ const closeHandler = (e) => {
118
+ onClose == null ? void 0 : onClose(e);
119
+ };
120
+ return /* @__PURE__ */ React.createElement("div", __spreadValues({ className: clsx(prefixCls, className), ref: nodeRef }, others), pageTitle ? /* @__PURE__ */ React.createElement("div", { className: `${prefixCls}-title` }, pageTitle, /* @__PURE__ */ React.createElement("div", { className: `${prefixCls}-btn-close`, onClick: closeHandler }, "\u2715")) : null, /* @__PURE__ */ React.createElement(
121
+ ScrollView,
122
+ {
123
+ scrollIntoView: targetId,
124
+ scrollY: true,
125
+ className: clsx(`${prefixCls}-scroll-view-container tph`, {
126
+ "container-has-title": pageTitle
127
+ }),
128
+ onScroll: scrollHandler
129
+ },
130
+ /* @__PURE__ */ React.createElement("div", { className: `${prefixCls}-all-item` }, (items == null ? void 0 : items.length) > 0 ? /* @__PURE__ */ React.createElement("div", { className: `${prefixCls}-list-container` }, items.map((item, itemGroupIndex) => {
131
+ if (!(item == null ? void 0 : item.groupName))
132
+ return null;
133
+ return /* @__PURE__ */ React.createElement("div", { key: itemGroupIndex }, renderTitle(item), item.isFlat ? /* @__PURE__ */ React.createElement("div", { className: "select-item-buttons" }, item.items.map((it, index) => {
134
+ return /* @__PURE__ */ React.createElement(
135
+ Selector,
136
+ {
137
+ key: index,
138
+ item: it,
139
+ onSelect: (e) => {
140
+ onSelect(e, { item: it, group: item });
141
+ }
142
+ }
143
+ );
144
+ })) : /* @__PURE__ */ React.createElement("ul", { className: `${prefixCls}-list` }, item.items.map((it, itemIndex) => {
145
+ return /* @__PURE__ */ React.createElement(
146
+ "li",
147
+ {
148
+ className: `${prefixCls}-list-item`,
149
+ key: itemIndex,
150
+ onClick: (e) => {
151
+ onSelect(e, { item: it, group: item });
152
+ }
153
+ },
154
+ it.name
155
+ );
156
+ })));
157
+ })) : null)
158
+ ), (codeGroup == null ? void 0 : codeGroup.length) > 0 && height ? /* @__PURE__ */ React.createElement(
159
+ "div",
160
+ {
161
+ className: clsx(`${prefixCls}-index-container`, {
162
+ "left-in": codeShow,
163
+ "item-index-has-title": pageTitle
164
+ })
165
+ },
166
+ /* @__PURE__ */ React.createElement("ul", { onTouchMove: touchCbk, className: `${prefixCls}-index-list` }, codeGroup.map((item, idx) => {
167
+ return item.name ? /* @__PURE__ */ React.createElement(
168
+ "li",
169
+ {
170
+ className: `${prefixCls}-index-item`,
171
+ key: idx,
172
+ "data-code": item.code,
173
+ onClick: () => {
174
+ codeClickHandler(item.code);
175
+ },
176
+ style: {
177
+ maxHeight: `calc((${height} - ${DEVIATION_HEIGHT}) / ${codeGroup.length})`
178
+ }
179
+ },
180
+ item.name
181
+ ) : null;
182
+ }))
183
+ ) : null);
184
+ }
185
+ );
186
+ ItemSelector.displayName = "BuiItemSelector";
187
+ var ItemSelectorCore_default = ItemSelector;
188
+ export {
189
+ ItemSelectorCore_default as default
190
+ };
@@ -0,0 +1,11 @@
1
+ .bui-item-selector-item {
2
+ width: var(--bui-item-selector-item-width);
3
+ height: var(--bui-item-selector-item-height);
4
+ display: inline-flex;
5
+ justify-content: center;
6
+ align-items: center;
7
+ border-radius: var(--bui-item-selector-item-border-radius);
8
+ margin: var(--bui-item-selector-item-margin);
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 { itemType } from '../ItemSelector.types';
3
+ import './index.less';
4
+ type propsType = {
5
+ item: itemType;
6
+ onSelect: (e: React.SyntheticEvent, item: itemType) => void;
7
+ };
8
+ declare const Selector: (props: propsType) => React.JSX.Element;
9
+ export default Selector;
@@ -0,0 +1,19 @@
1
+ import React from "react";
2
+ import "./index.css";
3
+ const Selector = (props) => {
4
+ const { item, onSelect } = props;
5
+ return /* @__PURE__ */ React.createElement(
6
+ "span",
7
+ {
8
+ className: "bui-item-selector-item",
9
+ onClick: (e) => {
10
+ onSelect == null ? void 0 : onSelect(e, item);
11
+ }
12
+ },
13
+ item.name
14
+ );
15
+ };
16
+ var Selector_default = Selector;
17
+ export {
18
+ Selector_default as default
19
+ };
@@ -0,0 +1,2 @@
1
+ export { default as ItemSelector, default } from './ItemSelector';
2
+ export * from './ItemSelector.types';
@@ -0,0 +1,6 @@
1
+ import { default as default2, default as default3 } from "./ItemSelector";
2
+ export * from "./ItemSelector.types";
3
+ export {
4
+ default2 as ItemSelector,
5
+ default3 as default
6
+ };
@@ -0,0 +1,4 @@
1
+ .bui-item-scroll-view-container {
2
+ height: 100%;
3
+ display: block;
4
+ }
@@ -12,5 +12,5 @@ declare const Modal: React.ForwardRefExoticComponent<Omit<ViewProps & {
12
12
  keepMounted?: boolean;
13
13
  } & import("@bifrostui/types").ICommonProps & Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
14
14
  ref?: React.Ref<HTMLDivElement>;
15
- }, keyof import("@bifrostui/types").ICommonProps | "container" | "open" | "disablePortal" | "hideBackdrop" | "BackdropProps" | "onClose" | "disableScrollLock" | "keepMounted">, "ref"> & React.RefAttributes<HTMLDivElement>>;
15
+ }, "open" | keyof import("@bifrostui/types").ICommonProps | "container" | "disablePortal" | "hideBackdrop" | "BackdropProps" | "onClose" | "disableScrollLock" | "keepMounted">, "ref"> & React.RefAttributes<HTMLDivElement>>;
16
16
  export default Modal;
package/es/index.d.ts CHANGED
@@ -40,6 +40,7 @@ export * from './Loading';
40
40
  export * from './TabBar';
41
41
  export * from './Countdown';
42
42
  export * from './CitySelector';
43
+ export * from './ItemSelector';
43
44
  export * from './Picker';
44
45
  export * from './CollapsePanel';
45
46
  export * from './Breadcrumb';
package/es/index.js CHANGED
@@ -40,6 +40,7 @@ export * from "./Loading";
40
40
  export * from "./TabBar";
41
41
  export * from "./Countdown";
42
42
  export * from "./CitySelector";
43
+ export * from "./ItemSelector";
43
44
  export * from "./Picker";
44
45
  export * from "./CollapsePanel";
45
46
  export * from "./Breadcrumb";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bifrostui/react",
3
- "version": "1.4.6",
3
+ "version": "1.4.7",
4
4
  "description": "React components for building mobile application",
5
5
  "homepage": "http://bui.taopiaopiao.com",
6
6
  "license": "MIT",
@@ -33,10 +33,10 @@
33
33
  "clsx": "^1.2.1",
34
34
  "dayjs": "^1.11.7",
35
35
  "swiper": "^8.1.5",
36
- "@bifrostui/icons": "1.4.6",
37
- "@bifrostui/styles": "1.4.6",
38
- "@bifrostui/utils": "1.4.6",
39
- "@bifrostui/types": "1.4.6"
36
+ "@bifrostui/styles": "1.4.7",
37
+ "@bifrostui/icons": "1.4.7",
38
+ "@bifrostui/types": "1.4.7",
39
+ "@bifrostui/utils": "1.4.7"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "@tarojs/components": "^3.0.0",