-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1172 from navikt/bytt-ut-gamalt-ekspanderbart-panel
Bytt ut gamalt ekspanderbart panel med ExpancionCard
- Loading branch information
Showing
6 changed files
with
24 additions
and
238 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 21 additions & 28 deletions
49
src/components/ekspandertbart-panel/metrikk-ekspanderbartpanel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,33 @@ | ||
import React, {PropsWithChildren, useState} from 'react'; | ||
import Ekspanderbartpanel from 'nav-frontend-ekspanderbartpanel'; | ||
import {logEvent} from '../../utils/frontend-logger'; | ||
import {finnSideNavn} from '../../middleware/metrics-middleware'; | ||
import hiddenIf from '../hidden-if/hidden-if'; | ||
import '../toolbar/toolbar.css'; | ||
import classNames from 'classnames'; | ||
import {EkspanderbartpanelBaseProps} from 'nav-frontend-ekspanderbartpanel/lib/ekspanderbartpanel-base'; | ||
import {PropsWithChildren, useState} from 'react'; | ||
import {ExpansionCard} from '@navikt/ds-react'; | ||
import {trackAmplitude} from '../../amplitude/amplitude'; | ||
|
||
interface MetrikkEkspanderbartpanelProps extends EkspanderbartpanelBaseProps { | ||
lamellNavn: string; | ||
interface Props { | ||
tittel: string; | ||
} | ||
|
||
function MetrikkEkspanderbartpanel({ | ||
lamellNavn, | ||
tittel, | ||
className, | ||
children | ||
}: PropsWithChildren<MetrikkEkspanderbartpanelProps>) { | ||
export function MetrikkEkspanderbartpanel({tittel, children}: PropsWithChildren<Props>) { | ||
const [isApen, setIsApen] = useState(true); | ||
|
||
const handleOnClick = () => { | ||
setIsApen(prevState => !prevState); | ||
logEvent('portefolje.metrikker.lamell', { | ||
navn: lamellNavn, | ||
apen: !isApen, | ||
sideNavn: finnSideNavn() | ||
trackAmplitude({ | ||
name: isApen ? 'accordion lukket' : 'accordion åpnet', | ||
data: { | ||
tekst: tittel | ||
} | ||
}); | ||
|
||
setIsApen(prevState => !prevState); | ||
}; | ||
|
||
return ( | ||
<div className={classNames('portefolje__ekspanderbarpanel', className)}> | ||
<Ekspanderbartpanel tittel={tittel} border={true} onClick={handleOnClick} apen={isApen} role="button"> | ||
{children} | ||
</Ekspanderbartpanel> | ||
</div> | ||
<ExpansionCard aria-labelledby="expancion-card-title" size="small" open={isApen}> | ||
<ExpansionCard.Header onClick={handleOnClick}> | ||
<ExpansionCard.Title id="expancion-card-title" size="small"> | ||
{tittel} | ||
</ExpansionCard.Title> | ||
</ExpansionCard.Header> | ||
<ExpansionCard.Content>{children}</ExpansionCard.Content> | ||
</ExpansionCard> | ||
); | ||
} | ||
|
||
export default hiddenIf(MetrikkEkspanderbartpanel); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters