@app-studio/web 0.8.64 → 0.8.65

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.
@@ -7641,90 +7641,147 @@
7641
7641
  Table.Container = TableContainer;
7642
7642
  Table.Template = TableView;
7643
7643
 
7644
- // Initializes a custom hook for managing tab states with an array of 'Tab' objects passed as properties.
7645
- var useTabsState = propTabs => {
7646
- var [isActive, setIsActive] = React.useState(propTabs[0]);
7647
- var [tabsState, setTabsState] = React.useState(propTabs);
7644
+ /**
7645
+ * Custom hook to manage the state of the active tab.
7646
+ * @param propTabs - The array of tab objects provided as props.
7647
+ * @param initialTabValue - The optional title of the tab to be initially active.
7648
+ * @returns An object containing the current activeTab and a function to update it.
7649
+ */
7650
+ var useTabsState = (propTabs, initialTabValue) => {
7651
+ // Find the initial tab based on initialTabValue, or default to the first tab.
7652
+ // Ensure propTabs is not empty before accessing index 0.
7653
+ var findInitialTab = () => {
7654
+ if (!propTabs || propTabs.length === 0) {
7655
+ return undefined; // No tabs, no initial active tab
7656
+ }
7657
+ if (initialTabValue !== undefined) {
7658
+ var foundTab = propTabs.find(tab => tab.title === initialTabValue);
7659
+ if (foundTab) {
7660
+ return foundTab;
7661
+ }
7662
+ // Warn if initialTabValue is provided but not found
7663
+ console.warn("Tabs: initialTabValue \"" + initialTabValue + "\" not found in tabs. Defaulting to the first tab.");
7664
+ }
7665
+ return propTabs[0]; // Default to the first tab
7666
+ };
7667
+ var [activeTab, setActiveTab] = React.useState(findInitialTab);
7668
+ // Effect to update the active tab if the initialTabValue prop changes
7669
+ // or if the tabs array changes and the current active tab is no longer valid.
7670
+ React.useEffect(() => {
7671
+ var newInitialTab = findInitialTab();
7672
+ // Update only if the calculated initial tab is different from the current active tab
7673
+ // or if the current active tab is no longer in the list (and there are tabs)
7674
+ var currentActiveTabStillValid = activeTab && propTabs.some(t => t.title === activeTab.title);
7675
+ if (newInitialTab && (!currentActiveTabStillValid || initialTabValue !== undefined && (activeTab == null ? void 0 : activeTab.title) !== initialTabValue)) {
7676
+ setActiveTab(newInitialTab);
7677
+ } else if (!newInitialTab && activeTab) {
7678
+ // Handle case where all tabs are removed
7679
+ setActiveTab(undefined);
7680
+ }
7681
+ }, [propTabs, initialTabValue]); // Rerun when tabs or initial title changes
7648
7682
  return {
7649
- isActive,
7650
- setIsActive,
7651
- tabsState,
7652
- setTabsState
7683
+ activeTab,
7684
+ setActiveTab
7653
7685
  };
7654
7686
  };
7655
7687
 
7656
- // Defines a functional component 'TabsView' with props of type 'TabsViewProps'.
7657
- var TabsView = props => {
7658
- // Destructures 'tabs', 'styles', 'isActive', 'setIsActive', 'tabsState', and 'setTabsState' from the component props.
7659
- var {
7660
- tabs,
7661
- styles,
7662
- isActive,
7663
- setIsActive,
7664
- tabsState,
7665
- setTabsState,
7688
+ /**
7689
+ * The presentation component for Tabs. Renders the UI based on props.
7690
+ */
7691
+ var TabsView = _ref => {
7692
+ var {
7693
+ tabs = [],
7694
+ // Default to empty array
7695
+ activeTab,
7696
+ handleTabClick,
7697
+ styles = {},
7698
+ // Default to empty object
7666
7699
  renderTab,
7667
7700
  renderContent
7668
- } = props;
7669
- // Declares a function 'moveSelectedTabToTop' that takes an index and modifies the tabs order.
7670
- var moveSelectedTabToTop = idx => {
7671
- // Creates a copy of the 'tabs' array from props to be altered.
7672
- var newTabs = [...tabs];
7673
- // Removes the tab at the provided index, effectively selecting this tab.
7674
- var selectedTab = newTabs.splice(idx, 1);
7675
- // Places the selected tab at the start of the 'newTabs' array.
7676
- newTabs.unshift(selectedTab[0]);
7677
- // Updates the state with the reordered tabs.
7678
- setTabsState(newTabs);
7679
- // Sets the active tab to the first tab in the 'newTabs' array.
7680
- setIsActive(newTabs[0]);
7681
- };
7682
- // Defines a function 'isContentActive' that checks if the given tab's content is to be displayed.
7683
- var isContentActive = tab => {
7684
- // Returns a boolean indicating if the given tab is identical to the first tab in 'tabsState'.
7685
- return tab.value === tabsState[0].value;
7686
- };
7687
- return /*#__PURE__*/React__default.createElement(Vertical, Object.assign({
7688
- width: "100%",
7689
- height: '100%'
7690
- }, styles == null ? void 0 : styles.container), /*#__PURE__*/React__default.createElement(Horizontal, Object.assign({}, styles == null ? void 0 : styles.headerTabs), tabs.map((tab, idx) => renderTab ? renderTab(tab, isContentActive(tab), idx) : (/*#__PURE__*/React__default.createElement(Button, Object.assign({
7691
- key: tab.title,
7692
- onClick: () => {
7693
- moveSelectedTabToTop(idx);
7694
- },
7695
- variant: isActive.value === tab.value ? 'filled' : 'ghost',
7696
- shape: "pillShaped",
7697
- cursor: "pointer",
7698
- isAuto: true,
7699
- margin: 10
7700
- }, styles == null ? void 0 : styles.tab, isActive.value === tab.value ? styles == null ? void 0 : styles.activeTab : {}), /*#__PURE__*/React__default.createElement(Text, Object.assign({}, styles == null ? void 0 : styles.title, isActive.value === tab.value ? styles == null ? void 0 : styles.activeText : {}), tab.title))))), /*#__PURE__*/React__default.createElement(View, Object.assign({
7701
- width: '100%',
7702
- height: "100%"
7703
- }, styles == null ? void 0 : styles.content), tabsState.map(renderContent ? renderContent : (tab, idx) => isContentActive(tab) && /*#__PURE__*/React__default.createElement(View, {
7704
- key: idx
7705
- }, tab.content))));
7701
+ } = _ref;
7702
+ // If there's no active tab (e.g., tabs array is empty), render nothing or a placeholder
7703
+ if (!activeTab) {
7704
+ // Optionally render a placeholder when no tabs are active/available
7705
+ // return <View {...styles.container}><Text>No tabs available.</Text></View>;
7706
+ return null; // Or simply render nothing
7707
+ }
7708
+ return (
7709
+ /*#__PURE__*/
7710
+ // Use Vertical layout for overall structure (tabs header above content)
7711
+ React__default.createElement(Vertical, Object.assign({
7712
+ width: "100%",
7713
+ height: '100%'
7714
+ }, styles.container), /*#__PURE__*/React__default.createElement(Horizontal, Object.assign({}, styles.headerTabs), tabs.map(tab => {
7715
+ // Determine if the current tab in the loop is the active one
7716
+ var isActive = tab.title === activeTab.title;
7717
+ // Prepare the onClick handler for this specific tab
7718
+ var onClick = () => handleTabClick(tab);
7719
+ // Use the custom renderTab function if provided
7720
+ if (renderTab) {
7721
+ return renderTab(tab, isActive, onClick);
7722
+ }
7723
+ // Default rendering for a tab button
7724
+ return /*#__PURE__*/React__default.createElement(Button, Object.assign({
7725
+ key: tab.title,
7726
+ onClick: onClick,
7727
+ borderBottomLeftRadius: 0,
7728
+ borderBottomRightRadius: 0
7729
+ }, styles.tab, isActive ? styles.activeTab : {}, {
7730
+ // Example: Set variant based on active state (can be overridden by styles)
7731
+ variant: isActive ? 'filled' : 'ghost',
7732
+ cursor: "pointer" // Ensure pointer cursor
7733
+ }), tab.icon, /*#__PURE__*/React__default.createElement(Text
7734
+ // Apply base title styles and merge activeText styles if this tab is active
7735
+ , Object.assign({}, styles.title, isActive ? styles.activeText : {}), tab.title));
7736
+ })), /*#__PURE__*/React__default.createElement(View, Object.assign({
7737
+ width: '100%',
7738
+ height: "100%"
7739
+ }, styles.content), renderContent ? renderContent(activeTab) :
7740
+ // Otherwise, render the content property from the active tab object
7741
+ activeTab.content))
7742
+ );
7706
7743
  };
7707
7744
 
7745
+ /**
7746
+ * Tabs component allows users to navigate between different sections of content.
7747
+ * It manages the active tab state and renders the corresponding content.
7748
+ */
7708
7749
  var TabsComponent = _ref => {
7709
7750
  var {
7710
7751
  tabs,
7711
- styles
7752
+ styles,
7753
+ initialTabValue,
7754
+ onTabChange,
7755
+ renderTab,
7756
+ renderContent
7712
7757
  } = _ref;
7713
- var {
7714
- isActive,
7715
- setIsActive,
7716
- tabsState,
7717
- setTabsState
7718
- } = useTabsState(tabs);
7758
+ // Use the custom hook to manage the active tab state
7759
+ var {
7760
+ activeTab,
7761
+ setActiveTab
7762
+ } = useTabsState(tabs, initialTabValue);
7763
+ // Handler function to change the active tab and trigger the callback
7764
+ var handleTabClick = tab => {
7765
+ // Only update state and call callback if the clicked tab is different from the current one
7766
+ if ((activeTab == null ? void 0 : activeTab.title) !== tab.title) {
7767
+ setActiveTab(tab);
7768
+ // Call the onTabChange callback if provided
7769
+ if (onTabChange) {
7770
+ onTabChange(tab);
7771
+ }
7772
+ }
7773
+ };
7774
+ // Render the presentation component with the necessary props
7719
7775
  return /*#__PURE__*/React__default.createElement(TabsView, {
7720
7776
  tabs: tabs,
7721
7777
  styles: styles,
7722
- isActive: isActive,
7723
- tabsState: tabsState,
7724
- setTabsState: setTabsState,
7725
- setIsActive: setIsActive
7778
+ activeTab: activeTab,
7779
+ handleTabClick: handleTabClick,
7780
+ renderTab: renderTab,
7781
+ renderContent: renderContent
7726
7782
  });
7727
7783
  };
7784
+ // Export the component wrapped in React.memo for performance optimization
7728
7785
  var Tabs = /*#__PURE__*/React__default.memo(TabsComponent);
7729
7786
 
7730
7787
  // Declares the useToggleState function which takes defaultToggled parameter to initialize the toggle state.