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 +57 -10
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +58 -12
- package/dist/index.esm.js.map +1 -1
- package/dist/styles/pesona-ui.css +1 -1
- package/dist/types/components/Tab/Tabs.d.ts +8 -3
- package/dist/types/components/Tab/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useEffect, useState, useRef, forwardRef, useCallback } from 'react';
|
|
1
|
+
import React, { useEffect, useState, useRef, useMemo, forwardRef, useCallback } from 'react';
|
|
2
2
|
import ReactDOM, { createPortal } from 'react-dom';
|
|
3
3
|
|
|
4
4
|
const Button = ({ type = 'button', className, children, ...rest }) => {
|
|
@@ -181,21 +181,67 @@ const Badge = ({ className, text }) => {
|
|
|
181
181
|
|
|
182
182
|
const Box = ({ children, className = '', ...rest }) => (React.createElement("div", { className: `box ${className}`, ...rest }, children));
|
|
183
183
|
|
|
184
|
-
const
|
|
184
|
+
const Tab = ({ children }) => React.createElement(React.Fragment, null, children);
|
|
185
|
+
const TabGroup = ({ children }) => React.createElement(React.Fragment, null, children);
|
|
186
|
+
const Tabs = ({ className = '', navClassName = '', contentClassName = '', children, activeTab, handleActiveTab, customHeader, }) => {
|
|
187
|
+
const { tabs, groups } = useMemo(() => {
|
|
188
|
+
const tabs = [];
|
|
189
|
+
const groups = [];
|
|
190
|
+
React.Children.forEach(children, (child) => {
|
|
191
|
+
if (!React.isValidElement(child))
|
|
192
|
+
return;
|
|
193
|
+
if (child.type === TabGroup) {
|
|
194
|
+
const groupTabs = [];
|
|
195
|
+
React.Children.forEach(child.props.children, (tabChild) => {
|
|
196
|
+
if (React.isValidElement(tabChild) && tabChild.type === Tab) {
|
|
197
|
+
tabs.push({
|
|
198
|
+
title: tabChild.props.title,
|
|
199
|
+
icon: tabChild.props.icon,
|
|
200
|
+
children: tabChild.props.children,
|
|
201
|
+
});
|
|
202
|
+
groupTabs.push(tabs.length - 1);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
groups.push({
|
|
206
|
+
title: child.props.title,
|
|
207
|
+
tabIndices: groupTabs,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
else if (child.type === Tab) {
|
|
211
|
+
tabs.push({
|
|
212
|
+
title: child.props.title,
|
|
213
|
+
icon: child.props.icon,
|
|
214
|
+
children: child.props.children,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
return { tabs, groups };
|
|
219
|
+
}, [children]);
|
|
220
|
+
useEffect(() => {
|
|
221
|
+
if (tabs.length > 0 && (activeTab < 0 || activeTab >= tabs.length)) {
|
|
222
|
+
handleActiveTab(0);
|
|
223
|
+
}
|
|
224
|
+
}, [tabs.length, activeTab, handleActiveTab]);
|
|
225
|
+
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) => {
|
|
226
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
227
|
+
e.preventDefault();
|
|
228
|
+
handleActiveTab(index);
|
|
229
|
+
}
|
|
230
|
+
} },
|
|
231
|
+
tab.icon && React.createElement("span", { className: "tab-icon" }, tab.icon),
|
|
232
|
+
React.createElement("span", { className: "tab-title" }, tab.title)));
|
|
185
233
|
return (React.createElement("div", { className: `card tabs ${className}` },
|
|
186
234
|
React.createElement("div", { className: `card-header ${navClassName}` },
|
|
187
235
|
customHeader,
|
|
188
|
-
React.createElement("div", { className: "nav-tabs", role: "tablist" },
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
React.createElement("div", { className: `card-body ${contentClassName || ''}` },
|
|
236
|
+
React.createElement("div", { className: "nav-tabs", role: "tablist" }, groups.length > 0
|
|
237
|
+
? groups.map((group) => (React.createElement(React.Fragment, { key: `group-${group.title}` },
|
|
238
|
+
React.createElement("legend", { className: "tab-item-legend" }, group.title),
|
|
239
|
+
group.tabIndices.map((tabIndex) => (renderTabItem(tabs[tabIndex], tabIndex))))))
|
|
240
|
+
: tabs.map((tab, i) => renderTabItem(tab, i)))),
|
|
241
|
+
React.createElement("div", { className: `card-body ${contentClassName}` },
|
|
195
242
|
React.createElement("div", { className: "tab-content" },
|
|
196
|
-
React.createElement("div", { className: "tab-panel" }, React.
|
|
243
|
+
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")))))));
|
|
197
244
|
};
|
|
198
|
-
const Tab = ({ children, title }) => (React.createElement(React.Fragment, { key: title }, children));
|
|
199
245
|
|
|
200
246
|
function getDefaultExportFromCjs (x) {
|
|
201
247
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
@@ -8669,5 +8715,5 @@ const TablePickSelectedItems = ({ count, selectedItem, selectedRows, }) => {
|
|
|
8669
8715
|
" Gunakan")));
|
|
8670
8716
|
};
|
|
8671
8717
|
|
|
8672
|
-
export { Accordion, AccordionSection, AccordionSectionBody, AccordionSectionFooter, Alert, Badge, Box, Button, Callout, Card, CardBody, CardFooter, CardHeader, Checkbox, CheckboxAgreement, CircularProgress, CircularProgressWithLabel, ClearInput, ConfirmationAlert, DatePicker, DivTable, DivTableBody, DivTableCell, DivTableFooter, DivTableHeader, DivTableRow, Dropdown, DropdownContent, DropdownDatePicker, DropdownMenu, DropdownToggle, FormCheckbox, FormContainer, FormGroup, FormRadio, Input, InputDate, InputFile, InputImageSize, InputTextArea, InputWysiwyg, LinearProgress, ListItem, ListView, LoadingBar, Modal, ModalBody, ModalFooter, ModalHeader, Popover, Radio, RadioButtonGroup, Select, SelectMultiple, SelectWithSearch, Spinner, Switch, Tab, Table, TableBody, TableCell, TableDeleteSelectedItems, TableFooter, TableHeader, TablePaginating, TablePickSelectedItems, TableRow, Tabs, Tooltip };
|
|
8718
|
+
export { Accordion, AccordionSection, AccordionSectionBody, AccordionSectionFooter, Alert, Badge, Box, Button, Callout, Card, CardBody, CardFooter, CardHeader, Checkbox, CheckboxAgreement, CircularProgress, CircularProgressWithLabel, ClearInput, ConfirmationAlert, DatePicker, DivTable, DivTableBody, DivTableCell, DivTableFooter, DivTableHeader, DivTableRow, Dropdown, DropdownContent, DropdownDatePicker, DropdownMenu, DropdownToggle, FormCheckbox, FormContainer, FormGroup, FormRadio, Input, InputDate, InputFile, InputImageSize, InputTextArea, InputWysiwyg, LinearProgress, ListItem, ListView, LoadingBar, Modal, ModalBody, ModalFooter, ModalHeader, Popover, Radio, RadioButtonGroup, Select, SelectMultiple, SelectWithSearch, Spinner, Switch, Tab, TabGroup, Table, TableBody, TableCell, TableDeleteSelectedItems, TableFooter, TableHeader, TablePaginating, TablePickSelectedItems, TableRow, Tabs, Tooltip };
|
|
8673
8719
|
//# sourceMappingURL=index.esm.js.map
|