@redneckz/wildless-cms-uni-blocks 0.4.2 → 0.4.3
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/bundle/blocks.schema.json +1 -1
- package/bundle/bundle.umd.js +59 -31
- package/bundle/bundle.umd.min.js +1 -1
- package/dist/components/Tabs/Tabs.d.ts +2 -1
- package/dist/components/Tabs/Tabs.js +3 -3
- package/dist/components/Tabs/Tabs.js.map +1 -1
- package/dist/components/Tabs/TabsContent.d.ts +8 -2
- package/dist/components/Tabs/renderGroupTab.d.ts +4 -0
- package/dist/components/Tabs/renderGroupTab.js +18 -0
- package/dist/components/Tabs/renderGroupTab.js.map +1 -0
- package/dist/components/Tabs/renderLinkTab.d.ts +8 -0
- package/dist/components/Tabs/renderLinkTab.js +7 -0
- package/dist/components/Tabs/renderLinkTab.js.map +1 -0
- package/dist/components/Tabs/renderTab.d.ts +5 -5
- package/dist/components/Tabs/renderTab.js +14 -14
- package/dist/components/Tabs/renderTab.js.map +1 -1
- package/dist/components/Tabs/tabItemClasses.d.ts +6 -0
- package/dist/components/Tabs/tabItemClasses.js +9 -0
- package/dist/components/Tabs/tabItemClasses.js.map +1 -0
- package/dist/ui-kit/BlockWrapper.js +10 -1
- package/dist/ui-kit/BlockWrapper.js.map +1 -1
- package/lib/common.css +1 -1
- package/lib/components/Tabs/Tabs.d.ts +2 -1
- package/lib/components/Tabs/Tabs.js +3 -3
- package/lib/components/Tabs/Tabs.js.map +1 -1
- package/lib/components/Tabs/TabsContent.d.ts +8 -2
- package/lib/components/Tabs/renderGroupTab.d.ts +4 -0
- package/lib/components/Tabs/renderGroupTab.js +15 -0
- package/lib/components/Tabs/renderGroupTab.js.map +1 -0
- package/lib/components/Tabs/renderLinkTab.d.ts +8 -0
- package/lib/components/Tabs/renderLinkTab.js +4 -0
- package/lib/components/Tabs/renderLinkTab.js.map +1 -0
- package/lib/components/Tabs/renderTab.d.ts +5 -5
- package/lib/components/Tabs/renderTab.js +14 -14
- package/lib/components/Tabs/renderTab.js.map +1 -1
- package/lib/components/Tabs/tabItemClasses.d.ts +6 -0
- package/lib/components/Tabs/tabItemClasses.js +7 -0
- package/lib/components/Tabs/tabItemClasses.js.map +1 -0
- package/lib/ui-kit/BlockWrapper.js +10 -1
- package/lib/ui-kit/BlockWrapper.js.map +1 -1
- package/mobile/bundle/bundle.umd.js +10 -1
- package/mobile/bundle/bundle.umd.min.js +1 -1
- package/mobile/dist/components/Tabs/Tabs.d.ts +2 -1
- package/mobile/dist/components/Tabs/Tabs.js +3 -3
- package/mobile/dist/components/Tabs/Tabs.js.map +1 -1
- package/mobile/dist/components/Tabs/TabsContent.d.ts +8 -2
- package/mobile/dist/components/Tabs/renderGroupTab.d.ts +4 -0
- package/mobile/dist/components/Tabs/renderGroupTab.js +18 -0
- package/mobile/dist/components/Tabs/renderGroupTab.js.map +1 -0
- package/mobile/dist/components/Tabs/renderLinkTab.d.ts +8 -0
- package/mobile/dist/components/Tabs/renderLinkTab.js +7 -0
- package/mobile/dist/components/Tabs/renderLinkTab.js.map +1 -0
- package/mobile/dist/components/Tabs/renderTab.d.ts +5 -5
- package/mobile/dist/components/Tabs/renderTab.js +14 -14
- package/mobile/dist/components/Tabs/renderTab.js.map +1 -1
- package/mobile/dist/components/Tabs/tabItemClasses.d.ts +6 -0
- package/mobile/dist/components/Tabs/tabItemClasses.js +9 -0
- package/mobile/dist/components/Tabs/tabItemClasses.js.map +1 -0
- package/mobile/dist/ui-kit/BlockWrapper.js +10 -1
- package/mobile/dist/ui-kit/BlockWrapper.js.map +1 -1
- package/mobile/lib/components/Tabs/Tabs.d.ts +2 -1
- package/mobile/lib/components/Tabs/Tabs.js +3 -3
- package/mobile/lib/components/Tabs/Tabs.js.map +1 -1
- package/mobile/lib/components/Tabs/TabsContent.d.ts +8 -2
- package/mobile/lib/components/Tabs/renderGroupTab.d.ts +4 -0
- package/mobile/lib/components/Tabs/renderGroupTab.js +15 -0
- package/mobile/lib/components/Tabs/renderGroupTab.js.map +1 -0
- package/mobile/lib/components/Tabs/renderLinkTab.d.ts +8 -0
- package/mobile/lib/components/Tabs/renderLinkTab.js +4 -0
- package/mobile/lib/components/Tabs/renderLinkTab.js.map +1 -0
- package/mobile/lib/components/Tabs/renderTab.d.ts +5 -5
- package/mobile/lib/components/Tabs/renderTab.js +14 -14
- package/mobile/lib/components/Tabs/renderTab.js.map +1 -1
- package/mobile/lib/components/Tabs/tabItemClasses.d.ts +6 -0
- package/mobile/lib/components/Tabs/tabItemClasses.js +7 -0
- package/mobile/lib/components/Tabs/tabItemClasses.js.map +1 -0
- package/mobile/lib/ui-kit/BlockWrapper.js +10 -1
- package/mobile/lib/ui-kit/BlockWrapper.js.map +1 -1
- package/mobile/src/components/Tabs/Tabs.example.json +3 -3
- package/mobile/src/components/Tabs/Tabs.tsx +5 -4
- package/mobile/src/components/Tabs/TabsContent.ts +9 -2
- package/mobile/src/components/Tabs/renderGroupTab.tsx +51 -0
- package/mobile/src/components/Tabs/renderLinkTab.tsx +25 -0
- package/mobile/src/components/Tabs/renderTab.tsx +18 -38
- package/mobile/src/components/Tabs/tabItemClasses.ts +7 -0
- package/mobile/src/ui-kit/BlockWrapper.tsx +12 -1
- package/package.json +1 -1
- package/src/components/Tabs/Tabs.example.json +3 -3
- package/src/components/Tabs/Tabs.fixture.tsx +3 -3
- package/src/components/Tabs/Tabs.tsx +5 -4
- package/src/components/Tabs/TabsContent.ts +9 -2
- package/src/components/Tabs/renderGroupTab.tsx +51 -0
- package/src/components/Tabs/renderLinkTab.tsx +25 -0
- package/src/components/Tabs/renderTab.tsx +18 -38
- package/src/components/Tabs/tabItemClasses.ts +7 -0
- package/src/ui-kit/BlockWrapper.tsx +12 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlockWrapper.js","sourceRoot":"","sources":["../../src/ui-kit/BlockWrapper.tsx"],"names":[],"mappings":";;;AAAA,+CAAwC;AACxC,uDAAkE;AAElE,mDAAgD;AAEh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IAAI,KAAK,OAAO,EAAE;YAC1B,oBAAoB,CAAC,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;SACvF;aAAM;YACL,oBAAoB,CAAC,IAAI,CAAC,CAAC;YAC3B,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;SAC5B;IACH,CAAC,CAAC,EACJ,CAAC,MAAM,CAAC,CACT,CAAC;IAEF,IAAI,CAAC,iBAAiB,EAAE;QACtB,OAAO,IAAI,CAAC;KACb;IAED,OAAO,MAAM,CAAC,CAAC,CAAC,CACd,uBAAC,uBAAuB,IACtB,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,SAAS,EACpB,gBAAgB,EAAE,yCAAmB,EACrC,eAAe,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE,EACjC,MAAM,EAAE,MAAM,YAEb,QAAQ,GACe,CAC3B,CAAC,CAAC,CAAC,CACF,uBAAC,GAAG,IAAC,SAAS,EAAE,SAAS,YAAG,QAAQ,GAAO,CAC5C,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,SAAS,aAAa,CAAC,KAAc;IACnC,UAAU,CAAC,GAAG,EAAE,CACd,UAAU,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,KAAK,EAAE,CAAC,EAAE,cAAc,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CACxF,CAAC;AACJ,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { UniBlockProps } from '../../types';
|
|
2
|
-
import type { TabsContent } from './TabsContent';
|
|
2
|
+
import type { TabsContent, TabType } from './TabsContent';
|
|
3
3
|
export interface TabActivationEvent {
|
|
4
|
+
type?: TabType;
|
|
4
5
|
label?: string;
|
|
5
6
|
}
|
|
6
7
|
export interface TabsProps extends TabsContent, UniBlockProps {
|
|
@@ -7,11 +7,11 @@ import { renderTab } from './renderTab.js';
|
|
|
7
7
|
export const Tabs = JSX((props) => {
|
|
8
8
|
const { context, className, tabs, page, showCounter } = props;
|
|
9
9
|
const [currentTab, setCurrentTab] = useState(tabs ? tabs[0] : undefined);
|
|
10
|
-
useEffect(() => EventBus.inst.subject('tab', { label: currentTab?.
|
|
10
|
+
useEffect(() => EventBus.inst.subject('tab', { label: currentTab?.ref }), [currentTab]);
|
|
11
11
|
const handleClick = (selectedTab) => {
|
|
12
|
-
EventBus.inst.fire('tab', { label: selectedTab.
|
|
12
|
+
EventBus.inst.fire('tab', { type: selectedTab.type, label: selectedTab.ref });
|
|
13
13
|
setCurrentTab(selectedTab);
|
|
14
14
|
};
|
|
15
|
-
return (_jsx(BlockWrapper, { context: context, className: `mb-2 box-border flex gap-x-1 ${className}`, role: "tablist", children: tabs?.map(renderTab({ onClick: handleClick, currentTab, page, showCounter })) }));
|
|
15
|
+
return (_jsx(BlockWrapper, { context: context, className: `mb-2 box-border flex gap-x-1 ${className}`, role: "tablist", children: tabs?.map(renderTab({ onClick: handleClick, currentTab, page, showCounter, context })) }));
|
|
16
16
|
});
|
|
17
17
|
//# sourceMappingURL=Tabs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tabs.js","sourceRoot":"","sources":["../../../src/components/Tabs/Tabs.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"Tabs.js","sourceRoot":"","sources":["../../../src/components/Tabs/Tabs.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,C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CAAC,CAAC,CAAC"}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
export declare type TabType = 'group' | 'link';
|
|
1
2
|
/**
|
|
2
3
|
* @title Таб
|
|
3
4
|
*/
|
|
4
5
|
export interface Tab {
|
|
5
|
-
/** @title
|
|
6
|
-
|
|
6
|
+
/** @title Тег или ссылка */
|
|
7
|
+
ref?: string;
|
|
8
|
+
/**
|
|
9
|
+
* @title Тип
|
|
10
|
+
* @enumNames ['Группирующий', 'Ссылочный']
|
|
11
|
+
*/
|
|
12
|
+
type?: TabType;
|
|
7
13
|
/** @title Название */
|
|
8
14
|
title?: string;
|
|
9
15
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "@redneckz/uni-jsx/jsx-runtime";
|
|
2
|
+
import { ACTIVE_LINK_CLASSES, ACTIVE_TEXT_CLASSES, INACTIVE_LINK_CLASSES, INACTIVE_TEXT_CLASSES, LINK_CLASSES, TEXT_CLASSES, } from './tabItemClasses.js';
|
|
3
|
+
const BADGE_CLASSES = 'min-w-[22px] w-[22px] h-[22px] rounded-full text-xs ml-2';
|
|
4
|
+
const ACTIVE_BADGE_CLASSES = 'bg-white/30 text-white';
|
|
5
|
+
const INACTIVE_BADGE_CLASSES = 'bg-main-divider text-secondary-text group-hover:text-primary-main';
|
|
6
|
+
export const renderGroupTab = ({ onClick, currentTab, showCounter, page }) => (tab, i) => {
|
|
7
|
+
const active = currentTab === tab;
|
|
8
|
+
const count = tab.ref
|
|
9
|
+
? page?.blocks?.filter((block) => block?.labels?.includes(tab.ref)).length
|
|
10
|
+
: page?.blocks?.length;
|
|
11
|
+
return (_jsx("div", { className: `${LINK_CLASSES} ${active ? ACTIVE_LINK_CLASSES : INACTIVE_LINK_CLASSES}`, role: "tab", "aria-selected": active, onClick: () => onClick(tab), children: _jsxs("div", { className: "flex flex-1 items-center justify-center", children: [tab?.title ? renderTitle(tab.title, active) : null, showCounter && count ? renderCount(count, active) : null] }) }, String(i)));
|
|
12
|
+
};
|
|
13
|
+
const renderTitle = (title, active) => (_jsx("h3", { className: `${TEXT_CLASSES} ${active ? ACTIVE_TEXT_CLASSES : INACTIVE_TEXT_CLASSES}`, children: title }));
|
|
14
|
+
const renderCount = (count, active) => (_jsx("div", { className: `${BADGE_CLASSES} ${active ? ACTIVE_BADGE_CLASSES : INACTIVE_BADGE_CLASSES}`, children: count }));
|
|
15
|
+
//# sourceMappingURL=renderGroupTab.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderGroupTab.js","sourceRoot":"","sources":["../../../src/components/Tabs/renderGroupTab.tsx"],"names":[],"mappings":";AACA,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACrB,YAAY,EACZ,YAAY,GACb,MAAM,kBAAkB,CAAC;AAG1B,MAAM,aAAa,GAAG,0DAA0D,CAAC;AACjF,MAAM,oBAAoB,GAAG,wBAAwB,CAAC;AACtD,MAAM,sBAAsB,GAAG,mEAAmE,CAAC;AAEnG,MAAM,CAAC,MAAM,cAAc,GACzB,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,IAAI,EAAkB,EAAE,EAAE,CAC/D,CAAC,GAAQ,EAAE,CAAS,EAAE,EAAE;IACtB,MAAM,MAAM,GAAG,UAAU,KAAK,GAAG,CAAC;IAElC,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG;QACnB,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAa,CAAC,CAAC,CAAC,MAAM;QACpF,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC;IAEzB,OAAO,CACL,cAEE,SAAS,EAAE,GAAG,YAAY,IAAI,MAAM,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,qBAAqB,EAAE,EACpF,IAAI,EAAC,KAAK,mBACK,MAAM,EACrB,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,YAE3B,eAAK,SAAS,EAAC,yCAAyC,aACrD,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,EAClD,WAAW,IAAI,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,IACrD,IATD,MAAM,CAAC,CAAC,CAAC,CAUV,CACP,CAAC;AACJ,CAAC,CAAC;AAEJ,MAAM,WAAW,GAAG,CAAC,KAAa,EAAE,MAAe,EAAE,EAAE,CAAC,CACtD,aAAI,SAAS,EAAE,GAAG,YAAY,IAAI,MAAM,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,qBAAqB,EAAE,YACrF,KAAK,GACH,CACN,CAAC;AAEF,MAAM,WAAW,GAAG,CAAC,KAAa,EAAE,MAAe,EAAE,EAAE,CAAC,CACtD,cAAK,SAAS,EAAE,GAAG,aAAa,IAAI,MAAM,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,sBAAsB,EAAE,YACzF,KAAK,GACF,CACP,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { LinkProps } from '../../model/LinkProps';
|
|
3
|
+
export interface RenderLinkTabProps extends LinkProps {
|
|
4
|
+
active?: boolean;
|
|
5
|
+
onClick?: () => void;
|
|
6
|
+
i: number;
|
|
7
|
+
}
|
|
8
|
+
export declare const renderLinkTab: ({ text, onClick, href, target, i }: RenderLinkTabProps) => JSX.Element;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { jsx as _jsx } from "@redneckz/uni-jsx/jsx-runtime";
|
|
2
|
+
import { INACTIVE_LINK_CLASSES, INACTIVE_TEXT_CLASSES, LINK_CLASSES, TEXT_CLASSES, } from './tabItemClasses.js';
|
|
3
|
+
export const renderLinkTab = ({ text, onClick, href, target = '_self', i }) => (_jsx("a", { className: `${LINK_CLASSES} ${INACTIVE_LINK_CLASSES}`, target: target, href: href, onClick: onClick, children: _jsx("span", { className: `${TEXT_CLASSES} ${INACTIVE_TEXT_CLASSES}`, children: text }) }, String(i)));
|
|
4
|
+
//# sourceMappingURL=renderLinkTab.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderLinkTab.js","sourceRoot":"","sources":["../../../src/components/Tabs/renderLinkTab.tsx"],"names":[],"mappings":";AACA,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,YAAY,EACZ,YAAY,GACb,MAAM,kBAAkB,CAAC;AAQ1B,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,EAAE,CAAC,EAAsB,EAAE,EAAE,CAAC,CACjG,YAEE,SAAS,EAAE,GAAG,YAAY,IAAI,qBAAqB,EAAE,EACrD,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,OAAO,YAEhB,eAAM,SAAS,EAAE,GAAG,YAAY,IAAI,qBAAqB,EAAE,YAAG,IAAI,GAAQ,IANrE,MAAM,CAAC,CAAC,CAAC,CAOZ,CACL,CAAC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { ContentPageDef } from '../../types';
|
|
3
|
+
import type { ContentPageContext } from '../ContentPage/ContentPageContext';
|
|
3
4
|
import type { Tab } from './TabsContent';
|
|
4
|
-
interface RenderTabProps {
|
|
5
|
-
onClick:
|
|
5
|
+
export interface RenderTabProps {
|
|
6
|
+
onClick: (tab: Tab) => void;
|
|
6
7
|
currentTab?: Tab;
|
|
7
8
|
page?: ContentPageDef;
|
|
8
9
|
showCounter?: boolean;
|
|
10
|
+
context: ContentPageContext;
|
|
9
11
|
}
|
|
10
|
-
declare
|
|
11
|
-
export declare const renderTab: ({ onClick, currentTab, showCounter, page }: RenderTabProps) => (tab: Tab, i: number) => JSX.Element;
|
|
12
|
-
export {};
|
|
12
|
+
export declare const renderTab: ({ onClick, currentTab, showCounter, page, context }: RenderTabProps) => (tab: Tab, i: number) => JSX.Element;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return (
|
|
1
|
+
import { useLink } from '../../hooks/useLink.js';
|
|
2
|
+
import { isURL } from '../../utils/url.js';
|
|
3
|
+
import { renderGroupTab } from './renderGroupTab.js';
|
|
4
|
+
import { renderLinkTab } from './renderLinkTab.js';
|
|
5
|
+
export const renderTab = ({ onClick, currentTab, showCounter, page, context }) => (tab, i) => {
|
|
6
|
+
const { useRouter, handlerDecorator } = context;
|
|
7
|
+
const router = useRouter();
|
|
8
|
+
if (isURL(tab?.ref)) {
|
|
9
|
+
return renderLinkTab({
|
|
10
|
+
...useLink({ router, handlerDecorator }, { href: tab.ref, text: tab.title }),
|
|
11
|
+
i,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
return renderGroupTab({ onClick, currentTab, showCounter, page, context })(tab, i);
|
|
15
15
|
};
|
|
16
16
|
//# sourceMappingURL=renderTab.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderTab.js","sourceRoot":"","sources":["../../../src/components/Tabs/renderTab.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"renderTab.js","sourceRoot":"","sources":["../../../src/components/Tabs/renderTab.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAWhD,MAAM,CAAC,MAAM,SAAS,GACpB,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAkB,EAAE,EAAE,CACxE,CAAC,GAAQ,EAAE,CAAS,EAAE,EAAE;IACtB,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC;IAChD,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAE3B,IAAI,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE;QACnB,OAAO,aAAa,CAAC;YACnB,GAAG,OAAO,CAAC,EAAE,MAAM,EAAE,gBAAgB,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC;YAC5E,CAAC;SACF,CAAC,CAAC;KACJ;IAED,OAAO,cAAc,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;AACrF,CAAC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const LINK_CLASSES = "h-12 flex-1 flex items-center justify-center cursor-pointer";
|
|
2
|
+
export declare const ACTIVE_LINK_CLASSES = "bg-primary-main";
|
|
3
|
+
export declare const INACTIVE_LINK_CLASSES = "group bg-white";
|
|
4
|
+
export declare const TEXT_CLASSES = "font-sans text-m";
|
|
5
|
+
export declare const ACTIVE_TEXT_CLASSES = "text-white";
|
|
6
|
+
export declare const INACTIVE_TEXT_CLASSES = "text-secondary-text group-hover:text-primary-main";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const LINK_CLASSES = 'h-12 flex-1 flex items-center justify-center cursor-pointer';
|
|
2
|
+
export const ACTIVE_LINK_CLASSES = 'bg-primary-main';
|
|
3
|
+
export const INACTIVE_LINK_CLASSES = 'group bg-white';
|
|
4
|
+
export const TEXT_CLASSES = 'font-sans text-m';
|
|
5
|
+
export const ACTIVE_TEXT_CLASSES = 'text-white';
|
|
6
|
+
export const INACTIVE_TEXT_CLASSES = 'text-secondary-text group-hover:text-primary-main';
|
|
7
|
+
//# sourceMappingURL=tabItemClasses.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tabItemClasses.js","sourceRoot":"","sources":["../../../src/components/Tabs/tabItemClasses.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,YAAY,GAAG,6DAA6D,CAAC;AAC1F,MAAM,CAAC,MAAM,mBAAmB,GAAG,iBAAiB,CAAC;AACrD,MAAM,CAAC,MAAM,qBAAqB,GAAG,gBAAgB,CAAC;AAEtD,MAAM,CAAC,MAAM,YAAY,GAAG,kBAAkB,CAAC;AAC/C,MAAM,CAAC,MAAM,mBAAmB,GAAG,YAAY,CAAC;AAChD,MAAM,CAAC,MAAM,qBAAqB,GAAG,mDAAmD,CAAC"}
|
|
@@ -8,11 +8,20 @@ export const BlockWrapper = JSX(({ anchor, className, context, children, tag = '
|
|
|
8
8
|
const { IntersectionObserverTag } = context;
|
|
9
9
|
const [shouldRenderBlock, setShouldRenderBlock] = useState(true);
|
|
10
10
|
useEffect(() => EventBus.inst.subscribe('tab', (event) => {
|
|
11
|
-
|
|
11
|
+
if (event.type === 'group') {
|
|
12
|
+
setShouldRenderBlock(!labels?.length || !event.label || labels.includes(event.label));
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
setShouldRenderBlock(true);
|
|
16
|
+
scrollToBlock(event.label);
|
|
17
|
+
}
|
|
12
18
|
}), [labels]);
|
|
13
19
|
if (!shouldRenderBlock) {
|
|
14
20
|
return null;
|
|
15
21
|
}
|
|
16
22
|
return anchor ? (_jsx(IntersectionObserverTag, { tag: tag, className: className, observerCallback: changeHashOnObserve, observerOptions: { threshold: 1 }, anchor: anchor, children: children })) : (_jsx(Tag, { className: className, children: children }));
|
|
17
23
|
});
|
|
24
|
+
function scrollToBlock(label) {
|
|
25
|
+
setTimeout(() => globalThis.document.getElementById(`#${label}`)?.scrollIntoView({ behavior: 'smooth' }));
|
|
26
|
+
}
|
|
18
27
|
//# sourceMappingURL=BlockWrapper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlockWrapper.js","sourceRoot":"","sources":["../../src/ui-kit/BlockWrapper.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAElE,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AASnE,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,CAC7B,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,GAAG,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE;IACpE,MAAM,GAAG,GAAQ,GAAG,CAAC;IAErB,MAAM,EAAE,uBAAuB,EAAE,GAAG,OAAO,CAAC;IAC5C,MAAM,CAAC,iBAAiB,EAAE,oBAAoB,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAEjE,SAAS,CACP,GAAG,EAAE,CACH,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;QACvC,oBAAoB,CAAC,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"BlockWrapper.js","sourceRo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AgB,EAAE,mBAAmB,EACrC,eAAe,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE,EACjC,MAAM,EAAE,MAAM,YAEb,QAAQ,GACe,CAC3B,CAAC,CAAC,CAAC,CACF,KAAC,GAAG,IAAC,SAAS,EAAE,SAAS,YAAG,QAAQ,GAAO,CAC5C,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,SAAS,aAAa,CAAC,KAAc;IACnC,UAAU,CAAC,GAAG,EAAE,CACd,UAAU,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,KAAK,EAAE,CAAC,EAAE,cAAc,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CACxF,CAAC;AACJ,CAAC"}
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
"showCounter": true,
|
|
3
3
|
"tabs": [
|
|
4
4
|
{
|
|
5
|
-
"
|
|
5
|
+
"ref": "tab1",
|
|
6
6
|
"title": "Вкладка 1"
|
|
7
7
|
},
|
|
8
8
|
{
|
|
9
|
-
"
|
|
9
|
+
"ref": "tab2",
|
|
10
10
|
"title": "Вкладка 2"
|
|
11
11
|
},
|
|
12
12
|
{
|
|
13
|
-
"
|
|
13
|
+
"ref": "tab3",
|
|
14
14
|
"title": "Вкладка 3"
|
|
15
15
|
}
|
|
16
16
|
]
|
|
@@ -4,9 +4,10 @@ import { EventBus } from '../../EventBus/EventBus';
|
|
|
4
4
|
import type { UniBlockProps } from '../../types';
|
|
5
5
|
import { BlockWrapper } from '../../ui-kit/BlockWrapper';
|
|
6
6
|
import { renderTab } from './renderTab';
|
|
7
|
-
import type { Tab, TabsContent } from './TabsContent';
|
|
7
|
+
import type { Tab, TabsContent, TabType } from './TabsContent';
|
|
8
8
|
|
|
9
9
|
export interface TabActivationEvent {
|
|
10
|
+
type?: TabType;
|
|
10
11
|
label?: string;
|
|
11
12
|
}
|
|
12
13
|
|
|
@@ -17,10 +18,10 @@ export const Tabs = JSX<TabsProps>((props) => {
|
|
|
17
18
|
|
|
18
19
|
const [currentTab, setCurrentTab] = useState(tabs ? tabs[0] : undefined);
|
|
19
20
|
|
|
20
|
-
useEffect(() => EventBus.inst.subject('tab', { label: currentTab?.
|
|
21
|
+
useEffect(() => EventBus.inst.subject('tab', { label: currentTab?.ref }), [currentTab]);
|
|
21
22
|
|
|
22
23
|
const handleClick = (selectedTab: Tab) => {
|
|
23
|
-
EventBus.inst.fire('tab', { label: selectedTab.
|
|
24
|
+
EventBus.inst.fire('tab', { type: selectedTab.type, label: selectedTab.ref });
|
|
24
25
|
setCurrentTab(selectedTab);
|
|
25
26
|
};
|
|
26
27
|
|
|
@@ -30,7 +31,7 @@ export const Tabs = JSX<TabsProps>((props) => {
|
|
|
30
31
|
className={`mb-2 box-border flex gap-x-1 ${className}`}
|
|
31
32
|
role="tablist"
|
|
32
33
|
>
|
|
33
|
-
{tabs?.map(renderTab({ onClick: handleClick, currentTab, page, showCounter }))}
|
|
34
|
+
{tabs?.map(renderTab({ onClick: handleClick, currentTab, page, showCounter, context }))}
|
|
34
35
|
</BlockWrapper>
|
|
35
36
|
);
|
|
36
37
|
});
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
+
export type TabType = 'group' | 'link';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* @title Таб
|
|
3
5
|
*/
|
|
4
6
|
export interface Tab {
|
|
5
|
-
/** @title
|
|
6
|
-
|
|
7
|
+
/** @title Тег или ссылка */
|
|
8
|
+
ref?: string;
|
|
9
|
+
/**
|
|
10
|
+
* @title Тип
|
|
11
|
+
* @enumNames ['Группирующий', 'Ссылочный']
|
|
12
|
+
*/
|
|
13
|
+
type?: TabType;
|
|
7
14
|
/** @title Название */
|
|
8
15
|
title?: string;
|
|
9
16
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { RenderTabProps } from './renderTab';
|
|
2
|
+
import {
|
|
3
|
+
ACTIVE_LINK_CLASSES,
|
|
4
|
+
ACTIVE_TEXT_CLASSES,
|
|
5
|
+
INACTIVE_LINK_CLASSES,
|
|
6
|
+
INACTIVE_TEXT_CLASSES,
|
|
7
|
+
LINK_CLASSES,
|
|
8
|
+
TEXT_CLASSES,
|
|
9
|
+
} from './tabItemClasses';
|
|
10
|
+
import { Tab } from './TabsContent';
|
|
11
|
+
|
|
12
|
+
const BADGE_CLASSES = 'min-w-[22px] w-[22px] h-[22px] rounded-full text-xs ml-2';
|
|
13
|
+
const ACTIVE_BADGE_CLASSES = 'bg-white/30 text-white';
|
|
14
|
+
const INACTIVE_BADGE_CLASSES = 'bg-main-divider text-secondary-text group-hover:text-primary-main';
|
|
15
|
+
|
|
16
|
+
export const renderGroupTab =
|
|
17
|
+
({ onClick, currentTab, showCounter, page }: RenderTabProps) =>
|
|
18
|
+
(tab: Tab, i: number) => {
|
|
19
|
+
const active = currentTab === tab;
|
|
20
|
+
|
|
21
|
+
const count = tab.ref
|
|
22
|
+
? page?.blocks?.filter((block) => block?.labels?.includes(tab.ref as string)).length
|
|
23
|
+
: page?.blocks?.length;
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<div
|
|
27
|
+
key={String(i)}
|
|
28
|
+
className={`${LINK_CLASSES} ${active ? ACTIVE_LINK_CLASSES : INACTIVE_LINK_CLASSES}`}
|
|
29
|
+
role="tab"
|
|
30
|
+
aria-selected={active}
|
|
31
|
+
onClick={() => onClick(tab)}
|
|
32
|
+
>
|
|
33
|
+
<div className="flex flex-1 items-center justify-center">
|
|
34
|
+
{tab?.title ? renderTitle(tab.title, active) : null}
|
|
35
|
+
{showCounter && count ? renderCount(count, active) : null}
|
|
36
|
+
</div>
|
|
37
|
+
</div>
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const renderTitle = (title: string, active: boolean) => (
|
|
42
|
+
<h3 className={`${TEXT_CLASSES} ${active ? ACTIVE_TEXT_CLASSES : INACTIVE_TEXT_CLASSES}`}>
|
|
43
|
+
{title}
|
|
44
|
+
</h3>
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const renderCount = (count: number, active: boolean) => (
|
|
48
|
+
<div className={`${BADGE_CLASSES} ${active ? ACTIVE_BADGE_CLASSES : INACTIVE_BADGE_CLASSES}`}>
|
|
49
|
+
{count}
|
|
50
|
+
</div>
|
|
51
|
+
);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { LinkProps } from '../../model/LinkProps';
|
|
2
|
+
import {
|
|
3
|
+
INACTIVE_LINK_CLASSES,
|
|
4
|
+
INACTIVE_TEXT_CLASSES,
|
|
5
|
+
LINK_CLASSES,
|
|
6
|
+
TEXT_CLASSES,
|
|
7
|
+
} from './tabItemClasses';
|
|
8
|
+
|
|
9
|
+
export interface RenderLinkTabProps extends LinkProps {
|
|
10
|
+
active?: boolean;
|
|
11
|
+
onClick?: () => void;
|
|
12
|
+
i: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const renderLinkTab = ({ text, onClick, href, target = '_self', i }: RenderLinkTabProps) => (
|
|
16
|
+
<a
|
|
17
|
+
key={String(i)}
|
|
18
|
+
className={`${LINK_CLASSES} ${INACTIVE_LINK_CLASSES}`}
|
|
19
|
+
target={target}
|
|
20
|
+
href={href}
|
|
21
|
+
onClick={onClick}
|
|
22
|
+
>
|
|
23
|
+
<span className={`${TEXT_CLASSES} ${INACTIVE_TEXT_CLASSES}`}>{text}</span>
|
|
24
|
+
</a>
|
|
25
|
+
);
|
|
@@ -1,51 +1,31 @@
|
|
|
1
|
+
import { useLink } from '../../hooks/useLink';
|
|
1
2
|
import type { ContentPageDef } from '../../types';
|
|
3
|
+
import { isURL } from '../../utils/url';
|
|
4
|
+
import type { ContentPageContext } from '../ContentPage/ContentPageContext';
|
|
5
|
+
import { renderGroupTab } from './renderGroupTab';
|
|
6
|
+
import { renderLinkTab } from './renderLinkTab';
|
|
2
7
|
import type { Tab } from './TabsContent';
|
|
3
8
|
|
|
4
|
-
interface RenderTabProps {
|
|
5
|
-
onClick:
|
|
9
|
+
export interface RenderTabProps {
|
|
10
|
+
onClick: (tab: Tab) => void;
|
|
6
11
|
currentTab?: Tab;
|
|
7
12
|
page?: ContentPageDef;
|
|
8
13
|
showCounter?: boolean;
|
|
14
|
+
context: ContentPageContext;
|
|
9
15
|
}
|
|
10
16
|
|
|
11
|
-
type OnTabClick = (tab: Tab) => void;
|
|
12
|
-
|
|
13
|
-
const badgeStyle = 'min-w-[22px] w-[22px] h-[22px] rounded-full text-xs-light ml-2';
|
|
14
|
-
|
|
15
17
|
export const renderTab =
|
|
16
|
-
({ onClick, currentTab, showCounter, page }: RenderTabProps) =>
|
|
18
|
+
({ onClick, currentTab, showCounter, page, context }: RenderTabProps) =>
|
|
17
19
|
(tab: Tab, i: number) => {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
const tabBg = isActive ? 'bg-primary-main' : 'group bg-white';
|
|
21
|
-
const tabText = `text-m-light ${
|
|
22
|
-
isActive ? 'text-white' : 'text-secondary-text group-hover:text-primary-main'
|
|
23
|
-
}`;
|
|
24
|
-
const counterBlockStyle = `${badgeStyle}
|
|
25
|
-
${
|
|
26
|
-
isActive
|
|
27
|
-
? 'bg-white/30 text-white'
|
|
28
|
-
: 'bg-main-divider text-secondary-text group-hover:text-primary-main'
|
|
29
|
-
}`;
|
|
20
|
+
const { useRouter, handlerDecorator } = context;
|
|
21
|
+
const router = useRouter();
|
|
30
22
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
23
|
+
if (isURL(tab?.ref)) {
|
|
24
|
+
return renderLinkTab({
|
|
25
|
+
...useLink({ router, handlerDecorator }, { href: tab.ref, text: tab.title }),
|
|
26
|
+
i,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
34
29
|
|
|
35
|
-
return (
|
|
36
|
-
<div
|
|
37
|
-
key={String(i)}
|
|
38
|
-
className={`flex h-12 w-full flex-1 cursor-pointer mr-2 last:mr-0 box-content ${tabBg}`}
|
|
39
|
-
role="tab"
|
|
40
|
-
aria-selected={isActive}
|
|
41
|
-
onClick={() => onClick(tab)}
|
|
42
|
-
>
|
|
43
|
-
<div className="flex flex-1 items-center justify-center">
|
|
44
|
-
{tab?.title ? <h3 className={tabText}>{tab?.title}</h3> : null}
|
|
45
|
-
{showCounter ? (
|
|
46
|
-
<div className={`flex items-center justify-center ${counterBlockStyle}`}>{count}</div>
|
|
47
|
-
) : null}
|
|
48
|
-
</div>
|
|
49
|
-
</div>
|
|
50
|
-
);
|
|
30
|
+
return renderGroupTab({ onClick, currentTab, showCounter, page, context })(tab, i);
|
|
51
31
|
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const LINK_CLASSES = 'h-12 flex-1 flex items-center justify-center cursor-pointer';
|
|
2
|
+
export const ACTIVE_LINK_CLASSES = 'bg-primary-main';
|
|
3
|
+
export const INACTIVE_LINK_CLASSES = 'group bg-white';
|
|
4
|
+
|
|
5
|
+
export const TEXT_CLASSES = 'font-sans text-m';
|
|
6
|
+
export const ACTIVE_TEXT_CLASSES = 'text-white';
|
|
7
|
+
export const INACTIVE_TEXT_CLASSES = 'text-secondary-text group-hover:text-primary-main';
|
|
@@ -22,7 +22,12 @@ export const BlockWrapper = JSX<BlockWrapperProps>(
|
|
|
22
22
|
useEffect(
|
|
23
23
|
() =>
|
|
24
24
|
EventBus.inst.subscribe('tab', (event) => {
|
|
25
|
-
|
|
25
|
+
if (event.type === 'group') {
|
|
26
|
+
setShouldRenderBlock(!labels?.length || !event.label || labels.includes(event.label));
|
|
27
|
+
} else {
|
|
28
|
+
setShouldRenderBlock(true);
|
|
29
|
+
scrollToBlock(event.label);
|
|
30
|
+
}
|
|
26
31
|
}),
|
|
27
32
|
[labels],
|
|
28
33
|
);
|
|
@@ -46,3 +51,9 @@ export const BlockWrapper = JSX<BlockWrapperProps>(
|
|
|
46
51
|
);
|
|
47
52
|
},
|
|
48
53
|
);
|
|
54
|
+
|
|
55
|
+
function scrollToBlock(label?: string) {
|
|
56
|
+
setTimeout(() =>
|
|
57
|
+
globalThis.document.getElementById(`#${label}`)?.scrollIntoView({ behavior: 'smooth' }),
|
|
58
|
+
);
|
|
59
|
+
}
|
package/package.json
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
"showCounter": true,
|
|
3
3
|
"tabs": [
|
|
4
4
|
{
|
|
5
|
-
"
|
|
5
|
+
"ref": "tab1",
|
|
6
6
|
"title": "Вкладка 1"
|
|
7
7
|
},
|
|
8
8
|
{
|
|
9
|
-
"
|
|
9
|
+
"ref": "tab2",
|
|
10
10
|
"title": "Вкладка 2"
|
|
11
11
|
},
|
|
12
12
|
{
|
|
13
|
-
"
|
|
13
|
+
"ref": "tab3",
|
|
14
14
|
"title": "Вкладка 3"
|
|
15
15
|
}
|
|
16
16
|
]
|
|
@@ -8,9 +8,9 @@ export default {
|
|
|
8
8
|
context={context}
|
|
9
9
|
className="col-span-12"
|
|
10
10
|
tabs={[
|
|
11
|
-
{
|
|
12
|
-
{
|
|
13
|
-
{
|
|
11
|
+
{ ref: 'tab1', title: 'Вкладка 1' },
|
|
12
|
+
{ ref: 'tab2', title: 'Вкладка 2' },
|
|
13
|
+
{ ref: 'https://google.com', title: 'Вкладка 3' },
|
|
14
14
|
]}
|
|
15
15
|
/>
|
|
16
16
|
</div>
|
|
@@ -4,9 +4,10 @@ import { EventBus } from '../../EventBus/EventBus';
|
|
|
4
4
|
import type { UniBlockProps } from '../../types';
|
|
5
5
|
import { BlockWrapper } from '../../ui-kit/BlockWrapper';
|
|
6
6
|
import { renderTab } from './renderTab';
|
|
7
|
-
import type { Tab, TabsContent } from './TabsContent';
|
|
7
|
+
import type { Tab, TabsContent, TabType } from './TabsContent';
|
|
8
8
|
|
|
9
9
|
export interface TabActivationEvent {
|
|
10
|
+
type?: TabType;
|
|
10
11
|
label?: string;
|
|
11
12
|
}
|
|
12
13
|
|
|
@@ -17,10 +18,10 @@ export const Tabs = JSX<TabsProps>((props) => {
|
|
|
17
18
|
|
|
18
19
|
const [currentTab, setCurrentTab] = useState(tabs ? tabs[0] : undefined);
|
|
19
20
|
|
|
20
|
-
useEffect(() => EventBus.inst.subject('tab', { label: currentTab?.
|
|
21
|
+
useEffect(() => EventBus.inst.subject('tab', { label: currentTab?.ref }), [currentTab]);
|
|
21
22
|
|
|
22
23
|
const handleClick = (selectedTab: Tab) => {
|
|
23
|
-
EventBus.inst.fire('tab', { label: selectedTab.
|
|
24
|
+
EventBus.inst.fire('tab', { type: selectedTab.type, label: selectedTab.ref });
|
|
24
25
|
setCurrentTab(selectedTab);
|
|
25
26
|
};
|
|
26
27
|
|
|
@@ -30,7 +31,7 @@ export const Tabs = JSX<TabsProps>((props) => {
|
|
|
30
31
|
className={`mb-2 box-border flex gap-x-1 ${className}`}
|
|
31
32
|
role="tablist"
|
|
32
33
|
>
|
|
33
|
-
{tabs?.map(renderTab({ onClick: handleClick, currentTab, page, showCounter }))}
|
|
34
|
+
{tabs?.map(renderTab({ onClick: handleClick, currentTab, page, showCounter, context }))}
|
|
34
35
|
</BlockWrapper>
|
|
35
36
|
);
|
|
36
37
|
});
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
+
export type TabType = 'group' | 'link';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* @title Таб
|
|
3
5
|
*/
|
|
4
6
|
export interface Tab {
|
|
5
|
-
/** @title
|
|
6
|
-
|
|
7
|
+
/** @title Тег или ссылка */
|
|
8
|
+
ref?: string;
|
|
9
|
+
/**
|
|
10
|
+
* @title Тип
|
|
11
|
+
* @enumNames ['Группирующий', 'Ссылочный']
|
|
12
|
+
*/
|
|
13
|
+
type?: TabType;
|
|
7
14
|
/** @title Название */
|
|
8
15
|
title?: string;
|
|
9
16
|
}
|