@homecode/ui 4.18.22 → 4.18.24

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.
@@ -1,16 +1,19 @@
1
- import { useState, useCallback, createElement } from 'react';
1
+ import { useState, useEffect, useCallback, createElement } from 'react';
2
2
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
3
  import cn from 'classnames';
4
4
  import { Button } from '../Button/Button.js';
5
5
  import { ButtonGroup } from '../ButtonGroup/ButtonGroup.js';
6
6
  import S from './Tabs.styl.js';
7
7
 
8
- function isId(id) {
9
- return ['string', 'number'].includes(typeof id);
10
- }
8
+ const isId = id => ['string', 'number'].includes(typeof id);
11
9
  function Tabs(props) {
12
- const { size = 'm', className, contentClassName, items, hideTabsIfSingle = true, onChange, renderAll, activeId: initialId, children, ...rest } = props;
10
+ const { size = 'm', className, contentClassName, items, hideTabsIfSingle = false, onChange, renderAll, activeId: initialId, children, ...rest } = props;
13
11
  const [activeId, setActiveId] = useState(isId(initialId) ? initialId : items[0].id);
12
+ useEffect(() => {
13
+ if (isId(initialId)) {
14
+ setActiveId(initialId);
15
+ }
16
+ }, [initialId]);
14
17
  const onTabClick = useCallback((e, { id, onClick } = {}) => {
15
18
  // @ts-ignore
16
19
  if (onClick && !onClick(e)) {
@@ -21,18 +24,16 @@ function Tabs(props) {
21
24
  onChange?.(id);
22
25
  }, []);
23
26
  const tabsContent = [];
24
- const tabsButtons = items.length === 1 && hideTabsIfSingle
25
- ? []
26
- : items.map((params) => {
27
- const { id, label, forceRender, content, contentClassName: currContentClassName, ...rest } = params;
28
- const isActive = activeId === id;
29
- const tabContent = typeof content === 'function' ? content() : content;
30
- if (renderAll || forceRender || isActive) {
31
- tabsContent.push(jsx("div", { className: cn(contentClassName, currContentClassName, !isActive && S.inactive), children: tabContent }, id));
32
- }
33
- return (createElement(Button, { ...rest, size: size, key: id, onClick: e => onTabClick(e, params), checked: isActive }, label));
34
- });
35
- const tabs = (jsx(ButtonGroup, { className: className, ...rest, children: tabsButtons }));
27
+ const tabsButtons = items.map((params) => {
28
+ const { id, label, forceRender, content, contentClassName: currContentClassName, ...rest } = params;
29
+ const isActive = activeId === id;
30
+ const tabContent = typeof content === 'function' ? content() : content;
31
+ if (renderAll || forceRender || isActive) {
32
+ tabsContent.push(jsx("div", { className: cn(contentClassName, currContentClassName, !isActive && S.inactive), children: tabContent }, id));
33
+ }
34
+ return (createElement(Button, { ...rest, size: size, key: id, onClick: e => onTabClick(e, params), checked: isActive }, label));
35
+ });
36
+ const tabs = tabsButtons.length === 1 && hideTabsIfSingle ? null : (jsx(ButtonGroup, { className: className, ...rest, children: tabsButtons }));
36
37
  if (typeof children === 'function') {
37
38
  return children({
38
39
  tabs,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homecode/ui",
3
- "version": "4.18.22",
3
+ "version": "4.18.24",
4
4
  "description": "React UI components library",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",