Skip to content

Commit

Permalink
update empty tab logic
Browse files Browse the repository at this point in the history
  • Loading branch information
razvanMiu committed Aug 26, 2024
1 parent d532df2 commit f859684
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 174 deletions.
9 changes: 7 additions & 2 deletions src/components/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { compose } from 'redux';
import { withRouter } from 'react-router';
import { StyleWrapperView } from '@eeacms/volto-block-style/StyleWrapper';
import { TABS_BLOCK } from '@eeacms/volto-tabs-block/constants';
import { getParentTabFromHash } from '@eeacms/volto-tabs-block/helpers';
import {
isTabEmpty,
getParentTabFromHash,
} from '@eeacms/volto-tabs-block/helpers';
import { DefaultView } from './templates/default';
import { withScrollToTarget } from '@eeacms/volto-tabs-block/hocs';

Expand All @@ -19,8 +22,10 @@ const View = (props) => {
const metadata = props.metadata || props.properties;
const template = data.variation || 'default';
const tabsData = data.data || {};
const tabsList = tabsData.blocks_layout?.items || [];
const tabs = tabsData.blocks || {};
const tabsList = (tabsData.blocks_layout?.items || []).filter((tab) => {
return data.hideEmptyTabs ? !isTabEmpty(tabs[tab]) : true;
});
const [activeTab, setActiveTab] = React.useState(tabsList?.[0]);
const activeTabIndex = tabsList.indexOf(activeTab);
const tabData = tabs[activeTab] || {};
Expand Down
113 changes: 53 additions & 60 deletions src/components/templates/accordion/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ import config from '@plone/volto/registry';
import Tabs from 'react-responsive-tabs';
import { AssetTab } from '@eeacms/volto-tabs-block/components';
import { TABS_BLOCK } from '@eeacms/volto-tabs-block/constants';
import {
getParentTabFromHash,
isTabEmpty,
} from '@eeacms/volto-tabs-block/helpers';
import { getParentTabFromHash } from '@eeacms/volto-tabs-block/helpers';
import { withScrollToTarget } from '@eeacms/volto-tabs-block/hocs';

import '@eeacms/volto-tabs-block/less/menu.less';
Expand Down Expand Up @@ -60,63 +57,59 @@ const View = (props) => {
tabs_width < initialWidth,
);

const items = tabsList
.filter((tab) => {
return data.hideEmptyTabs ? isTabEmpty(tabs[tab]) : true;
})
.map((tab, index) => {
const defaultTitle = `Tab ${index + 1}`;
const active = activeTabIndex === index;
const tabSettings = tabs[tab];
const { title, assetType } = tabSettings;
const tabIndex = index + 1;
const tabTitle = title || defaultTitle;

return {
title: (
<>
{semanticIcon ? (
<Icon
className={active ? semanticIcon.opened : semanticIcon.closed}
/>
) : (
<VoltoIcon
name={active ? icons.opened : icons.closed}
size={icons.size}
/>
)}
{assetType ? (
<AssetTab
props={tabSettings}
tabTitle={tabTitle}
tabIndex={tabIndex}
/>
) : (
<span className="menu-item-text">{title || defaultTitle}</span>
)}
</>
),
content: (
<Tab
{...props}
tab={tab}
content={tabs[tab]}
aria-hidden={false}
title={tabs[tab]?.title || `Tab ${tabsList.indexOf(tab) + 1}`}
/>
),
key: tab,
tabClassName: cx(
{
active,
},
isAccordion ? 'title accordion-title' : 'ui item title',
),
panelClassName: cx('ui attached segment tab content', {
const items = tabsList.map((tab, index) => {
const defaultTitle = `Tab ${index + 1}`;
const active = activeTabIndex === index;
const tabSettings = tabs[tab];
const { title, assetType } = tabSettings;
const tabIndex = index + 1;
const tabTitle = title || defaultTitle;

return {
title: (
<>
{semanticIcon ? (
<Icon
className={active ? semanticIcon.opened : semanticIcon.closed}
/>
) : (
<VoltoIcon
name={active ? icons.opened : icons.closed}
size={icons.size}
/>
)}
{assetType ? (
<AssetTab
props={tabSettings}
tabTitle={tabTitle}
tabIndex={tabIndex}
/>
) : (
<span className="menu-item-text">{title || defaultTitle}</span>
)}
</>
),
content: (
<Tab
{...props}
tab={tab}
content={tabs[tab]}
aria-hidden={false}
title={tabs[tab]?.title || `Tab ${tabsList.indexOf(tab) + 1}`}
/>
),
key: tab,
tabClassName: cx(
{
active,
}),
};
});
},
isAccordion ? 'title accordion-title' : 'ui item title',
),
panelClassName: cx('ui attached segment tab content', {
active,
}),
};
});

React.useEffect(() => {
setMounted(true);
Expand Down
31 changes: 13 additions & 18 deletions src/components/templates/carousel/HorizontalView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { withRouter } from 'react-router';
import loadable from '@loadable/component';
import cx from 'classnames';
import { Icon, RenderBlocks } from '@plone/volto/components';
import { isTabEmpty } from '@eeacms/volto-tabs-block/helpers';

import rightArrowSVG from '@eeacms/volto-tabs-block/icons/right-key.svg';
import leftArrowSVG from '@eeacms/volto-tabs-block/icons/left-key.svg';
Expand Down Expand Up @@ -148,23 +147,19 @@ const View = (props) => {
carouselDiv.setAttribute('tabindex', '0');
}, []);

const panes = tabsList
.filter((tab) => {
return data.hideEmptyTabs ? isTabEmpty(tabs[tab]) : true;
})
.map((tab, _index) => {
return {
id: tab,
renderItem: (
<RenderBlocks
key={`slide-${tab}`}
{...props}
metadata={metadata}
content={tabs[tab]}
/>
),
};
});
const panes = tabsList.map((tab, _index) => {
return {
id: tab,
renderItem: (
<RenderBlocks
key={`slide-${tab}`}
{...props}
metadata={metadata}
content={tabs[tab]}
/>
),
};
});

return (
<>
Expand Down
31 changes: 13 additions & 18 deletions src/components/templates/carousel/VerticalView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { withRouter } from 'react-router';
import loadable from '@loadable/component';
import cx from 'classnames';
import { RenderBlocks } from '@plone/volto/components';
import { isTabEmpty } from '@eeacms/volto-tabs-block/helpers';

import 'slick-carousel/slick/slick.css';
import 'slick-carousel/slick/slick-theme.css';
Expand All @@ -30,23 +29,19 @@ const View = (props) => {
verticalSwiping: true,
};

const panes = tabsList
.filter((tab) => {
return data.hideEmptyTabs ? isTabEmpty(tabs[tab]) : true;
})
.map((tab, _index) => {
return {
id: tab,
renderItem: (
<RenderBlocks
{...props}
metadata={metadata}
content={tabs[tab]}
key={`slide-${tab}`}
/>
),
};
});
const panes = tabsList.map((tab, _index) => {
return {
id: tab,
renderItem: (
<RenderBlocks
{...props}
metadata={metadata}
content={tabs[tab]}
key={`slide-${tab}`}
/>
),
};
});

return (
<>
Expand Down
66 changes: 29 additions & 37 deletions src/components/templates/default/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
SimpleMarkdown,
getMenuPosition,
} from '@eeacms/volto-tabs-block/utils';
import { isTabEmpty } from '@eeacms/volto-tabs-block/helpers';

import { isInternalURL, flattenToAppURL } from '@plone/volto/helpers';

Expand Down Expand Up @@ -184,46 +183,39 @@ const View = (props) => {
menuTabular,
menuText,
menuAlign,
hideEmptyTabs,
} = data;
const isContainer = align === 'full';

const panes = tabsList
.filter((tab) => {
return hideEmptyTabs ? isTabEmpty(tabs[tab]) : true;
})
.map((tab, index) => {
return {
id: tab,
menuItem: (
<MenuItem
{...props}
key={tab}
tab={tab}
index={index}
tabsTitle={title}
tabsDescription={description}
blockId={props?.id || ''}
/>
),
pane: (
<Tab.Pane key={tab} as={isContainer ? Container : undefined}>
<div
id={tabs[tab]?.title || `Tab ${tabsList.indexOf(tab) + 1}`}
className="tab-name"
>
<div tabIndex={0} role="tabpanel" id={'tab-pane-' + tab}>
<RenderBlocks
{...props}
metadata={metadata}
content={tabs[tab]}
/>
</div>
const panes = tabsList.map((tab, index) => {
return {
id: tab,
menuItem: (
<MenuItem
{...props}
key={tab}
tab={tab}
index={index}
tabsTitle={title}
tabsDescription={description}
blockId={props?.id || ''}
/>
),
pane: (
<Tab.Pane key={tab} as={isContainer ? Container : undefined}>
<div id={tabs[tab]?.title || `Tab ${index + 1}`} className="tab-name">
<div tabIndex={0} role="tabpanel" id={'tab-pane-' + tab}>
<RenderBlocks
{...props}
metadata={metadata}
content={tabs[tab]}
/>
</div>
</Tab.Pane>
),
};
});
</div>
</Tab.Pane>
),
};
});
console.log('HERE ==>', activeTabIndex);

return (
<>
Expand Down
Loading

0 comments on commit f859684

Please sign in to comment.