@homecode/ui 4.18.21 → 4.18.22

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