@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
|
@@ -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
|
+
}
|