pesona-ui 1.0.10 → 1.0.12

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/index.cjs.js CHANGED
@@ -183,21 +183,67 @@ const Badge = ({ className, text }) => {
183
183
 
184
184
  const Box = ({ children, className = '', ...rest }) => (React.createElement("div", { className: `box ${className}`, ...rest }, children));
185
185
 
186
- const Tabs = ({ className, navClassName, contentClassName, children, activeTab, handleActiveTab, customHeader, }) => {
186
+ const Tab = ({ children }) => React.createElement(React.Fragment, null, children);
187
+ const TabGroup = ({ children }) => React.createElement(React.Fragment, null, children);
188
+ const Tabs = ({ className = '', navClassName = '', contentClassName = '', children, activeTab, handleActiveTab, customHeader, }) => {
189
+ const { tabs, groups } = React.useMemo(() => {
190
+ const tabs = [];
191
+ const groups = [];
192
+ React.Children.forEach(children, (child) => {
193
+ if (!React.isValidElement(child))
194
+ return;
195
+ if (child.type === TabGroup) {
196
+ const groupTabs = [];
197
+ React.Children.forEach(child.props.children, (tabChild) => {
198
+ if (React.isValidElement(tabChild) && tabChild.type === Tab) {
199
+ tabs.push({
200
+ title: tabChild.props.title,
201
+ icon: tabChild.props.icon,
202
+ children: tabChild.props.children,
203
+ });
204
+ groupTabs.push(tabs.length - 1);
205
+ }
206
+ });
207
+ groups.push({
208
+ title: child.props.title,
209
+ tabIndices: groupTabs,
210
+ });
211
+ }
212
+ else if (child.type === Tab) {
213
+ tabs.push({
214
+ title: child.props.title,
215
+ icon: child.props.icon,
216
+ children: child.props.children,
217
+ });
218
+ }
219
+ });
220
+ return { tabs, groups };
221
+ }, [children]);
222
+ React.useEffect(() => {
223
+ if (tabs.length > 0 && (activeTab < 0 || activeTab >= tabs.length)) {
224
+ handleActiveTab(0);
225
+ }
226
+ }, [tabs.length, activeTab, handleActiveTab]);
227
+ const renderTabItem = (tab, index) => (React.createElement("div", { key: `tab-nav-${index}`, className: `tab-item ${index === activeTab ? 'active' : ''}`, onClick: () => handleActiveTab(index), role: "button", tabIndex: 0, onKeyDown: (e) => {
228
+ if (e.key === 'Enter' || e.key === ' ') {
229
+ e.preventDefault();
230
+ handleActiveTab(index);
231
+ }
232
+ } },
233
+ tab.icon && React.createElement("span", { className: "tab-icon" }, tab.icon),
234
+ React.createElement("span", { className: "tab-title" }, tab.title)));
187
235
  return (React.createElement("div", { className: `card tabs ${className}` },
188
236
  React.createElement("div", { className: `card-header ${navClassName}` },
189
237
  customHeader,
190
- React.createElement("div", { className: "nav-tabs", role: "tablist" }, React.Children.map(children, (child, index) => (React.createElement("div", { key: child.props.title, className: `tab-item ${index === activeTab ? 'active' : ''}`, onClick: () => handleActiveTab(index), role: "button", tabIndex: 0, onKeyDown: (e) => {
191
- if (e.key === 'Enter' || e.key === ' ')
192
- handleActiveTab(index);
193
- } },
194
- child.props.icon && child.props.icon,
195
- child.props.title))))),
196
- React.createElement("div", { className: `card-body ${contentClassName || ''}` },
238
+ React.createElement("div", { className: "nav-tabs", role: "tablist" }, groups.length > 0
239
+ ? groups.map((group) => (React.createElement(React.Fragment, { key: `group-${group.title}` },
240
+ React.createElement("legend", { className: "tab-item-legend" }, group.title),
241
+ group.tabIndices.map((tabIndex) => (renderTabItem(tabs[tabIndex], tabIndex))))))
242
+ : tabs.map((tab, i) => renderTabItem(tab, i)))),
243
+ React.createElement("div", { className: `card-body ${contentClassName}` },
197
244
  React.createElement("div", { className: "tab-content" },
198
- React.createElement("div", { className: "tab-panel" }, React.Children.map(children, (child, index) => (index === activeTab ? child : null)))))));
245
+ React.createElement("div", { className: "tab-panel" }, tabs[activeTab] ? (React.createElement("div", { key: `tab-content-${activeTab}` }, tabs[activeTab].children)) : (React.createElement("div", null, "No content available")))))));
199
246
  };
200
- const Tab = ({ children, title }) => (React.createElement(React.Fragment, { key: title }, children));
201
247
 
202
248
  function getDefaultExportFromCjs (x) {
203
249
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
@@ -8729,6 +8775,7 @@ exports.SelectWithSearch = SelectWithSearch;
8729
8775
  exports.Spinner = Spinner;
8730
8776
  exports.Switch = Switch;
8731
8777
  exports.Tab = Tab;
8778
+ exports.TabGroup = TabGroup;
8732
8779
  exports.Table = Table;
8733
8780
  exports.TableBody = TableBody;
8734
8781
  exports.TableCell = TableCell;