hi-tm 0.20.4 → 0.20.6

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.
@@ -1,17 +1,22 @@
1
1
  import React from "react";
2
- declare const Tabs: ({ data, tabHandler, inLineCSS, onClick, activeId, }: {
3
- data: {
4
- id: number;
5
- content: string;
6
- name: string;
7
- }[];
8
- tabHandler?: (tab: {
9
- id: number;
10
- content: string;
11
- name: string;
12
- }) => void;
2
+ interface Badge {
3
+ tabId: number;
4
+ count: number;
5
+ badgeColor: string;
6
+ textColor: string;
7
+ }
8
+ interface Tab {
9
+ id: number;
10
+ content: string;
11
+ name: string;
12
+ }
13
+ declare const Tabs: ({ data, badges, tabHandler, inLineCSS, onClick, activeId, renderTab, }: {
14
+ data: Tab[];
15
+ badges?: Badge[];
16
+ tabHandler?: (tab: Tab) => void;
13
17
  inLineCSS?: object;
14
18
  onClick?: (id: number) => void;
15
19
  activeId?: number;
20
+ renderTab?: (tab: Tab, badge?: Badge) => React.ReactNode;
16
21
  }) => React.JSX.Element;
17
22
  export default Tabs;
@@ -34,9 +34,8 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  const react_1 = __importStar(require("react"));
37
- const Tabs = ({ data, tabHandler, inLineCSS, onClick, activeId, }) => {
37
+ const Tabs = ({ data, badges = [], tabHandler, inLineCSS, onClick, activeId, renderTab, }) => {
38
38
  const [activeTab, setActiveTab] = (0, react_1.useState)(0);
39
- // Effect to update active tab when activeId prop changes
40
39
  (0, react_1.useEffect)(() => {
41
40
  if (activeId !== undefined) {
42
41
  const index = data.findIndex((tab) => tab.id === activeId);
@@ -45,12 +44,17 @@ const Tabs = ({ data, tabHandler, inLineCSS, onClick, activeId, }) => {
45
44
  }
46
45
  }
47
46
  }, [activeId, data]);
48
- return (react_1.default.createElement("ul", { style: inLineCSS || {}, className: "flex flex-row items-center justify-start bg-white gap-5", dir: "rtl" }, data.map((tab, index) => (react_1.default.createElement("li", { key: index, className: `flex h-full w-fit cursor-pointer flex-row items-center justify-center px-[10px] pb-1 ${activeTab === index ? "border-b-2 border-blue-500" : ""} `, onClick: () => {
49
- setActiveTab(index);
50
- if (tabHandler)
51
- tabHandler(tab);
52
- if (onClick)
53
- onClick(tab.id);
54
- } }, tab.content)))));
47
+ return (react_1.default.createElement("ul", { style: inLineCSS || {}, className: "flex flex-row items-center justify-start bg-white gap-5", dir: "rtl" }, data.map((tab, index) => {
48
+ const badge = badges.find((b) => b.tabId === tab.id);
49
+ return (react_1.default.createElement("li", { key: index, className: `flex h-full w-fit cursor-pointer flex-row items-center justify-center px-[10px] pb-1 relative ${activeTab === index ? "border-b-2 border-blue-500" : ""}`, onClick: () => {
50
+ setActiveTab(index);
51
+ if (tabHandler)
52
+ tabHandler(tab);
53
+ if (onClick)
54
+ onClick(tab.id);
55
+ } }, renderTab ? (renderTab(tab, badge)) : (react_1.default.createElement("div", { className: "flex items-center gap-2" },
56
+ tab.content,
57
+ badge && (react_1.default.createElement("span", { className: `absolute -top-2 -left-2 inline-flex items-center justify-center px-1.5 py-0.5 text-xxs font-bold leading-none rounded-full ${badge.textColor} ${badge.badgeColor}` }, badge.count))))));
58
+ })));
55
59
  };
56
60
  exports.default = Tabs;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hi-tm",
3
- "version": "0.20.4",
3
+ "version": "0.20.6",
4
4
  "styles": "dist/styles/globals.css",
5
5
  "main": "dist/index.js",
6
6
  "exports": {