@pisell/materials 1.10.5 → 1.10.6

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.
@@ -62,11 +62,15 @@ var PisellSuperTabs = function PisellSuperTabs(props, ref) {
62
62
  activeKey = _useTabsState.activeKey,
63
63
  handleTabChange = _useTabsState.handleTabChange;
64
64
  var scrollItemByRowKey = function scrollItemByRowKey(key) {
65
- var item = document.querySelector(".pisell-super-tabs-item-".concat(id, "-").concat(key));
66
- console.log(".pisell-super-tabs-item-".concat(id, "-").concat(key));
65
+ var _containerRef$current;
66
+ var item = Array.from(((_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.querySelectorAll('[data-pisell-super-tabs-key]')) || []).find(function (element) {
67
+ return element.dataset.pisellSuperTabsKey === key;
68
+ });
67
69
  if (item) {
68
70
  item.scrollIntoView({
69
- behavior: 'smooth'
71
+ behavior: 'smooth',
72
+ block: 'nearest',
73
+ inline: 'nearest'
70
74
  });
71
75
  }
72
76
  };
@@ -140,6 +144,7 @@ var PisellSuperTabs = function PisellSuperTabs(props, ref) {
140
144
  // 包裹点击事件处理
141
145
  return /*#__PURE__*/React.createElement("div", {
142
146
  key: key,
147
+ "data-pisell-super-tabs-key": key,
143
148
  className: classNames('pisell-super-tabs-item', "pisell-super-tabs-item-".concat(id, "-").concat(key), {
144
149
  'pisell-super-tabs-item--active': active
145
150
  }, tabItemClassName),
@@ -7,6 +7,10 @@ export interface PisellTabbarTemplate1Props extends PisellTabbarProps {
7
7
  direction?: PisellTabbarTemplate1Direction;
8
8
  /** 是否在每个层级展示自动生成的 All 分类;默认保持展示。 */
9
9
  showAllItem?: boolean;
10
+ /** 是否展示一级分类中自动生成的搜索入口;默认保持展示。 */
11
+ showSearchItem?: boolean;
12
+ /** 外部切换选中项时,是否自动把一级分类滚动到可视区域。 */
13
+ scrollActiveItemIntoView?: boolean;
10
14
  }
11
15
  declare const _default: React.ForwardRefExoticComponent<PisellTabbarTemplate1Props & React.RefAttributes<unknown>>;
12
16
  export default _default;
@@ -85,9 +85,14 @@ var PisellTabbar = function PisellTabbar(props, ref) {
85
85
  _props$direction = props.direction,
86
86
  direction = _props$direction === void 0 ? 'horizontal' : _props$direction,
87
87
  _props$showAllItem = props.showAllItem,
88
- showAllItem = _props$showAllItem === void 0 ? true : _props$showAllItem;
88
+ showAllItem = _props$showAllItem === void 0 ? true : _props$showAllItem,
89
+ _props$showSearchItem = props.showSearchItem,
90
+ showSearchItem = _props$showSearchItem === void 0 ? true : _props$showSearchItem,
91
+ _props$scrollActiveIt = props.scrollActiveItemIntoView,
92
+ scrollActiveItemIntoView = _props$scrollActiveIt === void 0 ? false : _props$scrollActiveIt;
89
93
  var isVertical = direction === 'vertical';
90
94
  var containerRef = useRef(null);
95
+ var level1TabsRef = useRef(null);
91
96
  var searchRef = useRef(null);
92
97
  var firstCategoryKey = (_dataSource$0$id = (_dataSource$ = dataSource[0]) === null || _dataSource$ === void 0 ? void 0 : _dataSource$.id) !== null && _dataSource$0$id !== void 0 ? _dataSource$0$id : (_dataSource$2 = dataSource[0]) === null || _dataSource$2 === void 0 ? void 0 : _dataSource$2.key;
93
98
  var initialActiveKey = value !== null && value !== void 0 ? value : showAllItem ? getDefaultActiveKey(dataSource, 'id') : firstCategoryKey !== undefined ? [firstCategoryKey] : [];
@@ -145,6 +150,16 @@ var PisellTabbar = function PisellTabbar(props, ref) {
145
150
  _useState2 = _slicedToArray(_useState, 2),
146
151
  isSearchOpen = _useState2[0],
147
152
  setIsSearchOpen = _useState2[1];
153
+ useEffect(function () {
154
+ if (!scrollActiveItemIntoView || level1Value == null) return;
155
+ var animationFrame = requestAnimationFrame(function () {
156
+ var _level1TabsRef$curren, _level1TabsRef$curren2;
157
+ (_level1TabsRef$curren = level1TabsRef.current) === null || _level1TabsRef$curren === void 0 || (_level1TabsRef$curren2 = _level1TabsRef$curren.scrollItemByRowKey) === null || _level1TabsRef$curren2 === void 0 || _level1TabsRef$curren2.call(_level1TabsRef$curren, String(level1Value));
158
+ });
159
+ return function () {
160
+ return cancelAnimationFrame(animationFrame);
161
+ };
162
+ }, [level1Value, scrollActiveItemIntoView]);
148
163
 
149
164
  /**
150
165
  * 打开搜索模式
@@ -357,7 +372,7 @@ var PisellTabbar = function PisellTabbar(props, ref) {
357
372
  */
358
373
  var level1DataSource = useMemo(function () {
359
374
  var categoryItems = dataSource.length ? addDataSourceItemsByKey(dataSource, LEVEL_ADD_ITEMS.level1.filter(function (itemKey) {
360
- return showAllItem || itemKey !== 'all';
375
+ return (showAllItem || itemKey !== 'all') && (showSearchItem || itemKey !== 'search');
361
376
  })) : [];
362
377
  var actionItems = (level1Actions || []).map(function (action, index) {
363
378
  return {
@@ -378,7 +393,7 @@ var PisellTabbar = function PisellTabbar(props, ref) {
378
393
  return isVertical ? full.filter(function (item) {
379
394
  return (item === null || item === void 0 ? void 0 : item.key) !== 'expand';
380
395
  }) : full;
381
- }, [dataSource, isSearchOpen, isVertical, level1Actions, showAllItem]);
396
+ }, [dataSource, isSearchOpen, isVertical, level1Actions, showAllItem, showSearchItem]);
382
397
 
383
398
  /**
384
399
  * 渲染一级 Tab Item
@@ -646,6 +661,7 @@ var PisellTabbar = function PisellTabbar(props, ref) {
646
661
  style: style,
647
662
  ref: containerRef
648
663
  }, /*#__PURE__*/React.createElement(SuperTabs, {
664
+ ref: level1TabsRef,
649
665
  isControlled: true,
650
666
  id: tabbarId,
651
667
  className: classNames('pisell-tabbar__level', 'pisell-tabbar__level--1'),
@@ -84,10 +84,18 @@ var PisellSuperTabs = (props, ref) => {
84
84
  isControlled: isControlled ?? false
85
85
  });
86
86
  const scrollItemByRowKey = (key) => {
87
- const item = document.querySelector(`.pisell-super-tabs-item-${id}-${key}`);
88
- console.log(`.pisell-super-tabs-item-${id}-${key}`);
87
+ var _a2;
88
+ const item = Array.from(
89
+ ((_a2 = containerRef.current) == null ? void 0 : _a2.querySelectorAll(
90
+ "[data-pisell-super-tabs-key]"
91
+ )) || []
92
+ ).find((element) => element.dataset.pisellSuperTabsKey === key);
89
93
  if (item) {
90
- item.scrollIntoView({ behavior: "smooth" });
94
+ item.scrollIntoView({
95
+ behavior: "smooth",
96
+ block: "nearest",
97
+ inline: "nearest"
98
+ });
91
99
  }
92
100
  };
93
101
  (0, import_react.useImperativeHandle)(ref, () => {
@@ -180,6 +188,7 @@ var PisellSuperTabs = (props, ref) => {
180
188
  "div",
181
189
  {
182
190
  key,
191
+ "data-pisell-super-tabs-key": key,
183
192
  className: (0, import_classnames.default)(
184
193
  "pisell-super-tabs-item",
185
194
  `pisell-super-tabs-item-${id}-${key}`,
@@ -7,6 +7,10 @@ export interface PisellTabbarTemplate1Props extends PisellTabbarProps {
7
7
  direction?: PisellTabbarTemplate1Direction;
8
8
  /** 是否在每个层级展示自动生成的 All 分类;默认保持展示。 */
9
9
  showAllItem?: boolean;
10
+ /** 是否展示一级分类中自动生成的搜索入口;默认保持展示。 */
11
+ showSearchItem?: boolean;
12
+ /** 外部切换选中项时,是否自动把一级分类滚动到可视区域。 */
13
+ scrollActiveItemIntoView?: boolean;
10
14
  }
11
15
  declare const _default: React.ForwardRefExoticComponent<PisellTabbarTemplate1Props & React.RefAttributes<unknown>>;
12
16
  export default _default;
@@ -81,10 +81,13 @@ var PisellTabbar = (props, ref) => {
81
81
  searchProps,
82
82
  level1Actions,
83
83
  direction = "horizontal",
84
- showAllItem = true
84
+ showAllItem = true,
85
+ showSearchItem = true,
86
+ scrollActiveItemIntoView = false
85
87
  } = props;
86
88
  const isVertical = direction === "vertical";
87
89
  const containerRef = (0, import_react.useRef)(null);
90
+ const level1TabsRef = (0, import_react.useRef)(null);
88
91
  const searchRef = (0, import_react.useRef)(null);
89
92
  const firstCategoryKey = ((_a = dataSource[0]) == null ? void 0 : _a.id) ?? ((_b = dataSource[0]) == null ? void 0 : _b.key);
90
93
  const initialActiveKey = value ?? (showAllItem ? (0, import_utils.getDefaultActiveKey)(dataSource, "id") : firstCategoryKey !== void 0 ? [firstCategoryKey] : []);
@@ -116,6 +119,14 @@ var PisellTabbar = (props, ref) => {
116
119
  return getActiveKey(2);
117
120
  }, [activeKey]);
118
121
  const [isSearchOpen, setIsSearchOpen] = (0, import_react.useState)(false);
122
+ (0, import_react.useEffect)(() => {
123
+ if (!scrollActiveItemIntoView || level1Value == null) return;
124
+ const animationFrame = requestAnimationFrame(() => {
125
+ var _a2, _b2;
126
+ (_b2 = (_a2 = level1TabsRef.current) == null ? void 0 : _a2.scrollItemByRowKey) == null ? void 0 : _b2.call(_a2, String(level1Value));
127
+ });
128
+ return () => cancelAnimationFrame(animationFrame);
129
+ }, [level1Value, scrollActiveItemIntoView]);
119
130
  const openSearchMode = () => {
120
131
  setCacheActiveKey(activeKey);
121
132
  _setActiveKey([]);
@@ -340,7 +351,7 @@ var PisellTabbar = (props, ref) => {
340
351
  const categoryItems = dataSource.length ? (0, import_utils.addDataSourceItemsByKey)(
341
352
  dataSource,
342
353
  import_constants.LEVEL_ADD_ITEMS.level1.filter(
343
- (itemKey) => showAllItem || itemKey !== "all"
354
+ (itemKey) => (showAllItem || itemKey !== "all") && (showSearchItem || itemKey !== "search")
344
355
  )
345
356
  ) : [];
346
357
  const actionItems = (level1Actions || []).map((action, index) => ({
@@ -356,7 +367,14 @@ var PisellTabbar = (props, ref) => {
356
367
  }
357
368
  return isVertical ? full.filter((item) => (item == null ? void 0 : item.key) !== "expand") : full;
358
369
  },
359
- [dataSource, isSearchOpen, isVertical, level1Actions, showAllItem]
370
+ [
371
+ dataSource,
372
+ isSearchOpen,
373
+ isVertical,
374
+ level1Actions,
375
+ showAllItem,
376
+ showSearchItem
377
+ ]
360
378
  );
361
379
  const renderLevel1Item = (0, import_react.useCallback)(
362
380
  (itemProps) => {
@@ -658,6 +676,7 @@ var PisellTabbar = (props, ref) => {
658
676
  /* @__PURE__ */ import_react.default.createElement(
659
677
  import_PisellSuperTabs.default,
660
678
  {
679
+ ref: level1TabsRef,
661
680
  isControlled: true,
662
681
  id: tabbarId,
663
682
  className: (0, import_classnames.default)(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/materials",
3
- "version": "1.10.5",
3
+ "version": "1.10.6",
4
4
  "scripts": {
5
5
  "dev:tailwind-css": "tailwindcss -c ./tailwind.materials.config.cjs --postcss ./postcss.materials-tailwind.cjs -i ./src/tailwind-input.css -o ./src/pisell-materials.tw.css --watch",
6
6
  "build:tailwind-css:once": "tailwindcss -c ./tailwind.materials.config.cjs --postcss ./postcss.materials-tailwind.cjs -i ./src/tailwind-input.css -o ./src/pisell-materials.tw.css",