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