@laser-ui/components 1.3.0 → 1.4.0

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/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
4
4
 
5
+ # [1.4.0](https://github.com/laser-ui/laser-ui/compare/v1.3.0...v1.4.0) (2024-10-10)
6
+
7
+ ### Features
8
+
9
+ - **components:** tabs support `lazyLoading` ([f23b605](https://github.com/laser-ui/laser-ui/commit/f23b605cf8d935c8221b962cd352808d05ce2b75))
10
+
5
11
  # [1.3.0](https://github.com/laser-ui/laser-ui/compare/v1.2.0...v1.3.0) (2024-09-27)
6
12
 
7
13
  **Note:** Version bump only for package @laser-ui/components
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@laser-ui/components",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "React components.",
5
5
  "keywords": [
6
6
  "ui",
@@ -40,5 +40,5 @@
40
40
  "access": "public",
41
41
  "directory": "../../dist/libs/components"
42
42
  },
43
- "gitHead": "4d23c9e48d8e44d78673367640d213d6f5f585ca"
43
+ "gitHead": "e2186ab2e70beb344c2e51a9d0425f0663164056"
44
44
  }
package/tabs/Tabs.js CHANGED
@@ -6,15 +6,15 @@ import { checkScrollEnd, findNested } from '@laser-ui/utils';
6
6
  import AddOutlined from '@material-design-icons/svg/outlined/add.svg?react';
7
7
  import CloseOutlined from '@material-design-icons/svg/outlined/close.svg?react';
8
8
  import MoreHorizOutlined from '@material-design-icons/svg/outlined/more_horiz.svg?react';
9
- import { isUndefined, nth } from 'lodash';
10
- import { forwardRef, useEffect, useId, useImperativeHandle, useRef, useState } from 'react';
9
+ import { isNull, isUndefined, nth } from 'lodash';
10
+ import { forwardRef, useEffect, useId, useImperativeHandle, useMemo, useRef, useState } from 'react';
11
11
  import { CLASSES } from './vars';
12
12
  import { Dropdown } from '../dropdown';
13
13
  import { useComponentProps, useControlled, useNamespace, useStyled, useTranslation } from '../hooks';
14
14
  import { Icon } from '../icon';
15
15
  import { mergeCS } from '../utils';
16
16
  function TabsFC(props, ref) {
17
- const _a = useComponentProps('Tabs', props), { styleOverrides, styleProvider, list, active: activeProp, defaultActive, pattern, placement = 'top', center = false, size = 'medium', addible = false, onActiveChange, onAddClick, onClose } = _a, restProps = __rest(_a, ["styleOverrides", "styleProvider", "list", "active", "defaultActive", "pattern", "placement", "center", "size", "addible", "onActiveChange", "onAddClick", "onClose"]);
17
+ const _a = useComponentProps('Tabs', props), { styleOverrides, styleProvider, list, active: activeProp, defaultActive: _defaultActive, pattern, placement = 'top', center = false, size = 'medium', addible = false, lazyLoading = true, onActiveChange, onAddClick, onClose } = _a, restProps = __rest(_a, ["styleOverrides", "styleProvider", "list", "active", "defaultActive", "pattern", "placement", "center", "size", "addible", "lazyLoading", "onActiveChange", "onAddClick", "onClose"]);
18
18
  const namespace = useNamespace();
19
19
  const styled = useStyled(CLASSES, { tabs: styleProvider === null || styleProvider === void 0 ? void 0 : styleProvider.tabs }, styleOverrides);
20
20
  const { t } = useTranslation();
@@ -31,18 +31,35 @@ function TabsFC(props, ref) {
31
31
  const [scrollEnd, setScrollEnd] = useState(false);
32
32
  const iconSize = size === 'small' ? 16 : size === 'large' ? 20 : 18;
33
33
  const isHorizontal = placement === 'top' || placement === 'bottom';
34
- const [active, changeActive] = useControlled(defaultActive !== null && defaultActive !== void 0 ? defaultActive : (() => {
34
+ const defaultActive = useMemo(() => {
35
+ if (!isUndefined(_defaultActive)) {
36
+ return _defaultActive;
37
+ }
35
38
  for (const tab of list) {
36
39
  if (!tab.disabled) {
37
40
  return tab.id;
38
41
  }
39
42
  }
40
43
  return null;
41
- }), activeProp, (id) => {
44
+ }, []);
45
+ const [active, changeActive] = useControlled(defaultActive, activeProp, (id) => {
46
+ panelLoaded.current.add(id);
42
47
  if (onActiveChange) {
43
48
  onActiveChange(id, findNested(list, (item) => item.id === id));
44
49
  }
45
50
  });
51
+ const panelLoaded = useRef(new Set(isNull(defaultActive) ? [] : [defaultActive]));
52
+ const newPanelLoaded = new Set();
53
+ const panels = list.map((item) => {
54
+ const { id: itemId, panel: itemPanel } = item;
55
+ const hidden = itemId !== active;
56
+ const loaded = panelLoaded.current.has(itemId);
57
+ if (loaded) {
58
+ newPanelLoaded.add(itemId);
59
+ }
60
+ return (_createElement("div", Object.assign({}, styled('tabs__tabpanel'), { key: itemId, id: getPanelId(itemId), tabIndex: 0, hidden: hidden, role: "tabpanel", "aria-labelledby": getTabId(itemId) }), lazyLoading && hidden && !loaded ? null : itemPanel));
61
+ });
62
+ panelLoaded.current = newPanelLoaded;
46
63
  const refreshTabs = () => {
47
64
  const tablistWrapperEl = tablistWrapperRef.current;
48
65
  if (tablistWrapperEl) {
@@ -240,9 +257,6 @@ function TabsFC(props, ref) {
240
257
  'tabs__button.is-end': scrollEnd,
241
258
  }), { "aria-label": t('More'), children: _jsx(Icon, { size: iconSize, children: _jsx(MoreHorizOutlined, {}) }) })) })), addible && (_jsx("div", Object.assign({}, styled('tabs__button', 'tabs__button--add'), { role: "button", "aria-label": t('Add'), onClick: () => {
242
259
  onAddClick === null || onAddClick === void 0 ? void 0 : onAddClick();
243
- }, children: _jsx(Icon, { size: iconSize, children: _jsx(AddOutlined, {}) }) })))] }))), _jsx("div", Object.assign({}, styled(pattern === 'wrap' ? 'tabs__wrap-indicator' : pattern === 'slider' ? 'tabs__slider-indicator' : 'tabs__indicator'), { ref: indicatorRef }))] })) })), list.map((item) => {
244
- const { id: itemId, panel: itemPanel } = item;
245
- return (_createElement("div", Object.assign({}, styled('tabs__tabpanel'), { key: itemId, id: getPanelId(itemId), tabIndex: 0, hidden: itemId !== active, role: "tabpanel", "aria-labelledby": getTabId(itemId) }), itemPanel));
246
- })] })));
260
+ }, children: _jsx(Icon, { size: iconSize, children: _jsx(AddOutlined, {}) }) })))] }))), _jsx("div", Object.assign({}, styled(pattern === 'wrap' ? 'tabs__wrap-indicator' : pattern === 'slider' ? 'tabs__slider-indicator' : 'tabs__indicator'), { ref: indicatorRef }))] })) })), panels] })));
247
261
  }
248
262
  export const Tabs = forwardRef(TabsFC);
package/tabs/types.d.ts CHANGED
@@ -22,6 +22,7 @@ export interface TabsProps<ID extends React.Key, T extends TabsItem<ID>> extends
22
22
  center?: boolean;
23
23
  size?: Size;
24
24
  addible?: boolean;
25
+ lazyLoading?: boolean;
25
26
  onActiveChange?: (id: ID, origin: T) => void;
26
27
  onAddClick?: () => void;
27
28
  onClose?: (id: ID, origin: T) => void;