@thecb/components 11.4.0-beta.0 → 11.4.1-beta.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thecb/components",
3
- "version": "11.4.0-beta.0",
3
+ "version": "11.4.1-beta.0",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "typings": "dist/index.d.ts",
@@ -1,4 +1,4 @@
1
- import React, { useState, Fragment } from "react";
1
+ import React, { useState, Fragment, useEffect } from "react";
2
2
  import { Stack, Box, Cluster } from "../../atoms/layouts";
3
3
  import { themeComponent } from "../../../util/themeUtils";
4
4
  import { fallbackValues } from "./Tabs.theme";
@@ -6,11 +6,20 @@ import Tab from "../../atoms/tab";
6
6
 
7
7
  const HORIZONTAL = "horizontal";
8
8
 
9
- const Tabs = ({
10
- tabsConfig,
11
- tabsDisplayMode // can be either HORIZONTAL or VERTICAL
12
- }) => {
13
- const [activeTab, toggleActiveTab] = useState(tabsConfig.tabs[0].label);
9
+ const Tabs = ({ tabsConfig, tabsDisplayMode = HORIZONTAL, ...props }) => {
10
+ const [activeTab, toggleActiveTab] = useState(
11
+ tabsConfig.tabs[0]?.label || null
12
+ );
13
+
14
+ useEffect(() => {
15
+ const currentTabExists = tabsConfig.tabs.some(
16
+ tab => tab.label === activeTab
17
+ );
18
+
19
+ if (!activeTab || !currentTabExists) {
20
+ toggleActiveTab(tabsConfig.tabs[0]?.label || null);
21
+ }
22
+ }, [tabsConfig, activeTab]);
14
23
 
15
24
  const createTabs = (tabConfig, activeTab) => {
16
25
  return tabConfig.tabs.map(tab => {
@@ -25,7 +34,7 @@ const Tabs = ({
25
34
  });
26
35
  };
27
36
 
28
- const showHorozontal = (tabsConfig, activeTab) => {
37
+ const showHorizontal = (tabsConfig, activeTab) => {
29
38
  return (
30
39
  <Cluster justify={"space-around"}>
31
40
  {createTabs(tabsConfig, activeTab)}
@@ -38,10 +47,10 @@ const Tabs = ({
38
47
  };
39
48
 
40
49
  return (
41
- <Box className="tabs">
50
+ <Box className="tabs" {...props}>
42
51
  <Box className="tab-list">
43
52
  {tabsDisplayMode == HORIZONTAL
44
- ? showHorozontal(tabsConfig, activeTab)
53
+ ? showHorizontal(tabsConfig, activeTab)
45
54
  : showVertical(tabsConfig, activeTab)}
46
55
  </Box>
47
56
  <Box className="tab-content">
@@ -0,0 +1,21 @@
1
+ import React from "react";
2
+ import Expand from "../../../util/expand";
3
+
4
+ export interface TabConfig {
5
+ label: string;
6
+ content: React.ReactNode;
7
+ }
8
+
9
+ export interface TabsConfigObject {
10
+ tabs: TabConfig[];
11
+ }
12
+
13
+ export interface TabsProps {
14
+ tabsConfig: TabsConfigObject;
15
+ tabsDisplayMode?: "horizontal" | "vertical";
16
+ }
17
+
18
+ export declare const Tabs: React.FC<Expand<TabsProps> &
19
+ React.HTMLAttributes<HTMLElement>>;
20
+
21
+ export default Tabs;