|
1 | 1 | /* eslint-disable no-param-reassign */ |
2 | 2 | import React from 'react'; |
3 | 3 | import useCioAutocomplete from '../../../hooks/useCioAutocomplete'; |
4 | | -import { isRecommendationsSection } from '../../../typeGuards'; |
| 4 | +import { isCustomSection, isRecommendationsSection } from '../../../typeGuards'; |
5 | 5 | import { Item } from '../../../types'; |
6 | | -import { getStoryParams, toKebabCase } from '../../../utils'; |
| 6 | +import { camelToStartCase, getStoryParams, toKebabCase } from '../../../utils'; |
7 | 7 |
|
8 | 8 | export function HooksTemplate(args) { |
9 | 9 | const { |
@@ -119,32 +119,41 @@ export function HooksTemplate(args) { |
119 | 119 | if (!section?.data?.length) { |
120 | 120 | return null; |
121 | 121 | } |
| 122 | + |
122 | 123 | const { type, displayName } = section; |
123 | | - let sectionName = section.displayName; |
| 124 | + const sectionListingType = isCustomSection(section) |
| 125 | + ? 'custom' |
| 126 | + : toKebabCase(section.indexSectionName || section.data[0]?.section || 'Products'); |
124 | 127 |
|
| 128 | + let sectionTitle: string; |
125 | 129 | switch (type) { |
126 | 130 | case 'recommendations': |
127 | | - sectionName = section.podId; |
| 131 | + sectionTitle = section.podId; |
128 | 132 | break; |
129 | 133 | case 'custom': |
130 | | - sectionName = toKebabCase(displayName); |
| 134 | + sectionTitle = displayName; |
131 | 135 | break; |
132 | 136 | case 'autocomplete': |
133 | | - sectionName = section.indexSectionName; |
| 137 | + sectionTitle = section.indexSectionName; |
134 | 138 | break; |
135 | 139 | default: |
136 | | - sectionName = section.indexSectionName; |
| 140 | + sectionTitle = section.indexSectionName; |
137 | 141 | break; |
138 | 142 | } |
139 | 143 |
|
140 | | - const recommendationsSection = isRecommendationsSection(section) |
141 | | - ? section.indexSectionName |
142 | | - : ''; |
| 144 | + if (displayName) { |
| 145 | + sectionTitle = displayName; |
| 146 | + } |
| 147 | + |
| 148 | + let sectionClassNames = toKebabCase(sectionListingType); |
| 149 | + if (isRecommendationsSection(section)) { |
| 150 | + sectionClassNames += ` ${toKebabCase(section.podId)}`; |
| 151 | + } |
143 | 152 |
|
144 | 153 | return ( |
145 | | - <div key={sectionName} className={`${sectionName} ${recommendationsSection}`}> |
| 154 | + <div key={sectionTitle} className={sectionClassNames}> |
146 | 155 | <div {...getSectionProps(section)}> |
147 | | - <h5 className='cio-sectionName'>{section.displayName || sectionName}</h5> |
| 156 | + <h5 className='cio-section-name'>{camelToStartCase(sectionTitle)}</h5> |
148 | 157 | <div className='cio-section-items'> |
149 | 158 | {section?.data?.map((item) => renderItem(item))} |
150 | 159 | </div> |
@@ -271,32 +280,38 @@ function YourComponent() { |
271 | 280 | if (!section?.data?.length) { |
272 | 281 | return null; |
273 | 282 | } |
| 283 | +
|
274 | 284 | const { type, displayName } = section; |
275 | | - let sectionName = section.displayName; |
| 285 | + let sectionTitle: string; |
276 | 286 |
|
277 | 287 | switch (type) { |
278 | 288 | case 'recommendations': |
279 | | - sectionName = section.podId; |
| 289 | + sectionTitle = section.podId; |
280 | 290 | break; |
281 | 291 | case 'custom': |
282 | | - sectionName = toKebabCase(displayName); |
| 292 | + sectionTitle = displayName; |
283 | 293 | break; |
284 | 294 | case 'autocomplete': |
285 | | - sectionName = section.indexSectionName; |
| 295 | + sectionTitle = section.indexSectionName; |
286 | 296 | break; |
287 | 297 | default: |
288 | | - sectionName = section.indexSectionName; |
| 298 | + sectionTitle = section.indexSectionName; |
289 | 299 | break; |
290 | 300 | } |
291 | 301 |
|
292 | | - const recommendationsSection = isRecommendationsSection(section) |
293 | | - ? section.indexSectionName |
294 | | - : ''; |
| 302 | + if (displayName) { |
| 303 | + sectionTitle = displayName; |
| 304 | + } |
| 305 | +
|
| 306 | + let sectionClassNames = toKebabCase(sectionTitle); |
| 307 | + if (isRecommendationsSection(section)) { |
| 308 | + sectionClassNames += \` \${toKebabCase(section.indexSectionName)}\`; |
| 309 | + } |
295 | 310 |
|
296 | 311 | return ( |
297 | | - <div key={sectionName} className={\`\${sectionName} \${recommendationsSection}\`}> |
| 312 | + <div key={sectionTitle} className={sectionClassNames}> |
298 | 313 | <div {...getSectionProps(section)}> |
299 | | - <h5 className='cio-sectionName'>{sectionName}</h5> |
| 314 | + <h5 className='cio-section-name'>{camelToStartCase(sectionTitle)}</h5> |
300 | 315 | <div className='cio-section-items'> |
301 | 316 | {section?.data?.map((item) => renderItem(item))} |
302 | 317 | </div> |
|
0 commit comments