1
- import React , { useEffect , useId , useRef , useState } from 'react' ;
1
+ import React , { useEffect , useRef , useState } from 'react' ;
2
2
import { ExpansionCard } from '@navikt/ds-react' ;
3
3
import { BarChartIcon , BriefcaseClockIcon , CalendarIcon , TasklistIcon } from '@navikt/aksel-icons' ;
4
4
import { AnalyticsEvents , logAmplitudeEvent } from 'utils/amplitude' ;
5
5
import { classNames } from 'utils/classnames' ;
6
6
import { smoothScrollToTarget } from 'utils/scroll-to' ;
7
7
import { Shortcuts , useShortcuts } from 'utils/useShortcuts' ;
8
+ import {
9
+ ProcessingTimesVisibilityType ,
10
+ ProductDetailType ,
11
+ } from 'types/content-props/product-details' ;
12
+ import { usePageContentProps } from 'store/pageContext' ;
13
+ import { translator } from 'translations' ;
8
14
9
15
import style from './Expandable.module.scss' ;
10
16
@@ -14,7 +20,8 @@ type Props = {
14
20
analyticsOriginTag ?: string ;
15
21
className ?: string ;
16
22
children : React . ReactNode ;
17
- expandableType ?: 'processing_times' | 'payout_dates' | 'rates' | 'documentation_requirements' ;
23
+ expandableType ?: ProductDetailType ;
24
+ visibilityType ?: ProcessingTimesVisibilityType ;
18
25
} ;
19
26
20
27
export const Expandable = ( {
@@ -24,10 +31,11 @@ export const Expandable = ({
24
31
children,
25
32
className,
26
33
expandableType,
34
+ visibilityType,
27
35
} : Props ) => {
28
36
const [ isOpen , setIsOpen ] = useState ( false ) ;
29
37
const accordionRef = useRef < HTMLDivElement | null > ( null ) ;
30
- const componentId = useId ( ) ;
38
+ const { language } = usePageContentProps ( ) ;
31
39
32
40
useShortcuts ( {
33
41
shortcut : Shortcuts . SEARCH ,
@@ -71,16 +79,16 @@ export const Expandable = ({
71
79
} ;
72
80
73
81
const getHeaderIcon = ( ) => {
74
- if ( expandableType === 'processing_times' ) {
82
+ if ( expandableType === ProductDetailType . PROCESSING_TIMES ) {
75
83
return < BriefcaseClockIcon aria-hidden className = { style . headerIcon } /> ;
76
84
}
77
- if ( expandableType === 'payout_dates' ) {
85
+ if ( expandableType === ProductDetailType . PAYOUT_DATES ) {
78
86
return < CalendarIcon aria-hidden className = { style . headerIcon } /> ;
79
87
}
80
- if ( expandableType === 'rates' ) {
88
+ if ( expandableType === ProductDetailType . RATES ) {
81
89
return < BarChartIcon aria-hidden className = { style . headerIcon } /> ;
82
90
}
83
- if ( expandableType === 'documentation_requirements' ) {
91
+ if ( expandableType === ProductDetailType . DOC_REQUIREMENTS ) {
84
92
return < TasklistIcon aria-hidden className = { style . headerIcon } /> ;
85
93
}
86
94
return null ;
@@ -105,6 +113,14 @@ export const Expandable = ({
105
113
// This is the wrong use of this component, but some legacy pages have still to
106
114
// be upradet editorial wise.
107
115
const isLegacyUsage = ! expandableType ;
116
+ const getProductDetailsLabel = translator ( 'productDetailTypes' , language ) ;
117
+ const getVisibilityLabel = translator ( 'processingTimesVisibilityTypes' , language ) ;
118
+ const label =
119
+ expandableType === ProductDetailType . PROCESSING_TIMES &&
120
+ visibilityType &&
121
+ `${ getProductDetailsLabel ( ProductDetailType . PROCESSING_TIMES ) } ${ getVisibilityLabel (
122
+ visibilityType
123
+ ) } `;
108
124
109
125
return (
110
126
< ExpansionCard
@@ -113,9 +129,9 @@ export const Expandable = ({
113
129
ref = { accordionRef }
114
130
onToggle = { toggleExpandCollapse }
115
131
open = { isOpen }
116
- aria-labelledby = { componentId }
132
+ aria-label = { label || title }
117
133
>
118
- < ExpansionCard . Header className = { style . header } id = { componentId } >
134
+ < ExpansionCard . Header className = { style . header } >
119
135
{ getHeaderIcon ( ) }
120
136
< div className = { style . headerTitle } > { title } </ div >
121
137
</ ExpansionCard . Header >
0 commit comments