|
| 1 | +import React, { useState } from 'react'; |
| 2 | +import { CmsContentDocument } from '../../../../../common/cms-documents/content'; |
| 3 | +import { Button, Checkbox, CheckboxGroup, Heading } from '@navikt/ds-react'; |
| 4 | +import { classNames } from '../../../../utils/classNames'; |
| 5 | +import { useAppState } from '../../../../context/app-state/useAppState'; |
| 6 | +import { ArrowDownRightIcon } from '@navikt/aksel-icons'; |
| 7 | + |
| 8 | +import style from './HtmlExporter.module.css'; |
| 9 | + |
| 10 | +type Props = { |
| 11 | + content: CmsContentDocument; |
| 12 | + hidden?: boolean; |
| 13 | +}; |
| 14 | + |
| 15 | +export const HtmlExporter = ({ content, hidden }: Props) => { |
| 16 | + const { appContext } = useAppState(); |
| 17 | + const { basePath } = appContext; |
| 18 | + |
| 19 | + const [versionKeysSelected, setVersionKeysSelected] = useState<string[]>([]); |
| 20 | + |
| 21 | + const pdfApi = `${basePath}/pdf`; |
| 22 | + |
| 23 | + const { versionKey, versions } = content; |
| 24 | + |
| 25 | + return ( |
| 26 | + <div className={classNames(style.exporter, hidden && style.hidden)}> |
| 27 | + <div className={style.topRow}> |
| 28 | + <Heading size={'small'} level={'3'}> |
| 29 | + {'Eksporter til PDF'} |
| 30 | + </Heading> |
| 31 | + <Button |
| 32 | + variant={'primary'} |
| 33 | + size={'small'} |
| 34 | + as={'a'} |
| 35 | + href={`${pdfApi}/single/${versionKey}`} |
| 36 | + icon={<ArrowDownRightIcon className={style.downloadCurrentIcon} />} |
| 37 | + iconPosition={'right'} |
| 38 | + className={style.downloadCurrent} |
| 39 | + > |
| 40 | + {'Last ned denne versjonen'} |
| 41 | + </Button> |
| 42 | + </div> |
| 43 | + <Button |
| 44 | + variant={'primary'} |
| 45 | + size={'small'} |
| 46 | + as={'a'} |
| 47 | + href={`${pdfApi}/multi/${versionKeysSelected.join(',')}`} |
| 48 | + disabled={versionKeysSelected.length === 0} |
| 49 | + > |
| 50 | + {'Last ned valgte versjoner'} |
| 51 | + </Button> |
| 52 | + <CheckboxGroup |
| 53 | + legend={'Last ned flere versjoner'} |
| 54 | + size={'small'} |
| 55 | + className={style.checkboxGroup} |
| 56 | + onChange={setVersionKeysSelected} |
| 57 | + > |
| 58 | + {versions.map((version) => { |
| 59 | + const dateTime = new Date(version.timestamp).toLocaleString('no'); |
| 60 | + return ( |
| 61 | + <Checkbox value={version.key} size={'small'} key={version.key}> |
| 62 | + {`${version.title} - [${dateTime}]`} |
| 63 | + </Checkbox> |
| 64 | + ); |
| 65 | + })} |
| 66 | + </CheckboxGroup> |
| 67 | + </div> |
| 68 | + ); |
| 69 | +}; |
0 commit comments