@@ -6,7 +6,7 @@ import { ConditionalWrap } from '@Common/Helper'
66import { ReactComponent as ICExpand } from '@Icons/ic-expand.svg'
77
88import { Collapse } from '../Collapse'
9- import { CollapsibleListProps } from './CollapsibleList.types'
9+ import { CollapsibleListItem , CollapsibleListProps } from './CollapsibleList.types'
1010import './CollapsibleList.scss'
1111
1212const renderWithTippy = ( tippyProps : TippyProps ) => ( children : React . ReactElement ) => (
@@ -18,6 +18,68 @@ const renderWithTippy = (tippyProps: TippyProps) => (children: React.ReactElemen
1818export const CollapsibleList = ( { config, onCollapseBtnClick } : CollapsibleListProps ) => {
1919 const { pathname } = useLocation ( )
2020
21+ const getTabContent = ( item : CollapsibleListItem ) => {
22+ const { title, subtitle, iconConfig } = item
23+ return (
24+ < >
25+ < div className = "flexbox-col flex-grow-1 mw-none dc__align-start" >
26+ < span className = "collapsible__item__title dc__truncate fs-13 lh-20" > { title } </ span >
27+ { subtitle && < span className = "dc__truncate fw-4 lh-1-5 cn-7" > { subtitle } </ span > }
28+ </ div >
29+ { iconConfig && (
30+ < ConditionalWrap
31+ condition = { ! ! iconConfig . tooltipProps }
32+ wrap = { renderWithTippy ( iconConfig . tooltipProps ) }
33+ >
34+ < iconConfig . Icon
35+ { ...iconConfig . props }
36+ className = { `icon-dim-20 dc__no-shrink cursor ${ iconConfig . props ?. className || '' } ` }
37+ />
38+ </ ConditionalWrap >
39+ ) }
40+ </ >
41+ )
42+ }
43+
44+ const getTabItem = ( item : CollapsibleListItem ) => {
45+ const { title, href, isActive, onClick, tabType } = item
46+ if ( tabType === 'navLink' ) {
47+ return (
48+ < NavLink
49+ key = { title }
50+ to = { href }
51+ className = "collapsible__item flexbox dc__align-items-center dc__gap-8 dc__no-decor br-4 py-6 px-8 cursor"
52+ onClick = { ( e ) => {
53+ // Prevent navigation to the same page
54+ if ( href === pathname ) {
55+ e . preventDefault ( )
56+ }
57+ onClick ?.( e )
58+ } }
59+ >
60+ { getTabContent ( item ) }
61+ </ NavLink >
62+ )
63+ }
64+ // Since is active is boolean we need to explicitly handle for null
65+ return (
66+ < button
67+ key = { title }
68+ className = { `collapsible__item flexbox dc__align-items-center dc__gap-8 dc__no-decor br-4 py-6 px-8 cursor ${ isActive ? 'active' : '' } dc__unset-button-styles w-100` }
69+ onClick = { ( e ) => {
70+ // Prevent navigation to the same page
71+ if ( isActive ) {
72+ e . preventDefault ( )
73+ }
74+ onClick ?.( e )
75+ } }
76+ type = "button"
77+ >
78+ { getTabContent ( item ) }
79+ </ button >
80+ )
81+ }
82+
2183 return (
2284 < div className = "mw-none bcn-0" >
2385 { config . map ( ( { id, header, headerIconConfig, items, noItemsText, isExpanded } ) => (
@@ -61,40 +123,7 @@ export const CollapsibleList = ({ config, onCollapseBtnClick }: CollapsibleListP
61123 </ span >
62124 </ div >
63125 ) : (
64- items . map ( ( { title, href, iconConfig, subtitle, onClick } ) => (
65- < NavLink
66- key = { title }
67- to = { href }
68- className = "collapsible__item flexbox dc__align-items-center dc__gap-8 dc__no-decor br-4 py-6 px-8 cursor"
69- onClick = { ( e ) => {
70- // Prevent navigation to the same page
71- if ( href === pathname ) {
72- e . preventDefault ( )
73- }
74- onClick ?.( e )
75- } }
76- >
77- < div className = "flexbox-col flex-grow-1 mw-none" >
78- < span className = "collapsible__item__title dc__truncate fs-13 lh-20" >
79- { title }
80- </ span >
81- { subtitle && (
82- < span className = "dc__truncate fw-4 lh-1-5 cn-7" > { subtitle } </ span >
83- ) }
84- </ div >
85- { iconConfig && (
86- < ConditionalWrap
87- condition = { ! ! iconConfig . tooltipProps }
88- wrap = { renderWithTippy ( iconConfig . tooltipProps ) }
89- >
90- < iconConfig . Icon
91- { ...iconConfig . props }
92- className = { `icon-dim-20 dc__no-shrink cursor ${ iconConfig . props ?. className || '' } ` }
93- />
94- </ ConditionalWrap >
95- ) }
96- </ NavLink >
97- ) )
126+ items . map ( ( item ) => getTabItem ( item ) )
98127 ) }
99128 </ div >
100129 </ Collapse >
0 commit comments