{"version":3,"file":"RadioButtonsStegComponent-DAPFRW97.js","sources":["../../../Features/Shared/Scripts/Components/RadioButtonValg.tsx","../../../Features/Shared/Scripts/Components/ValgDisplayFunctions.tsx","../../../Features/Shared/Scripts/Utilities/InputUtilities.ts","../../../Features/Shared/Scripts/Utilities/ElementUtilies.ts","../../../Features/Shared/Scripts/Components/RadioButtonsStegComponent.tsx"],"sourcesContent":["import React from 'react';\r\nimport contentResolver from '../Utilities/EpiContentResolver';\r\nimport { EpiContext } from '../Store/EpiContext/Types';\r\n\r\nexport interface RadioButtonValgModel<T> {\r\n id: string;\r\n value: string;\r\n tekst: keyof T;\r\n}\r\n\r\nexport function RadioButtonValg<T>(\r\n group: string,\r\n id: string,\r\n value: string,\r\n tekst: keyof T,\r\n isChecked: boolean,\r\n epiContext: EpiContext<T>,\r\n): JSX.Element {\r\n return (\r\n <div className=\"c-radio-input\" key={id}>\r\n <input\r\n type=\"radio\"\r\n name={group}\r\n value={value}\r\n id={id}\r\n checked={isChecked}\r\n aria-checked={isChecked}\r\n // eslint-disable-next-line @typescript-eslint/no-empty-function\r\n onChange={(): void => {}} // Nødvendig pga. react setter den som read only hvis denne mangler\r\n />\r\n <label htmlFor={id}>{contentResolver(epiContext, tekst)}</label>\r\n </div>\r\n );\r\n}\r\n","import React from 'react';\r\nimport { DisplayValue } from '../Models/Valg';\r\n\r\nexport function RadioButtonDisplay(gruppe: string, value: DisplayValue): JSX.Element {\r\n const id = `${gruppe}-svar-visning`;\r\n return (\r\n <div className=\"c-veileder__valgt-item\">\r\n <span className=\"c-veileder__tekst c-veileder__tekst--valg\" id={id}>\r\n {value.displayValue}\r\n </span>\r\n </div>\r\n );\r\n}\r\n\r\nexport function NumberInputDisplay(gruppe: string, value: DisplayValue): JSX.Element {\r\n const id = `${gruppe}-svar-visning`;\r\n return (\r\n <div className=\"c-veileder__valgt-item\">\r\n <span className=\"c-veileder__tekst c-veileder__tekst--valg\" id={id}>\r\n {value.displayValue}\r\n </span>\r\n </div>\r\n );\r\n}\r\n","export default function getLabelValue(inputElement: HTMLInputElement): string | undefined {\r\n const parent = inputElement.parentElement;\r\n if (parent != null) {\r\n const labels = parent.getElementsByTagName('label');\r\n const firstLabel = Array.from(labels).find(() => true);\r\n\r\n if (firstLabel && firstLabel.textContent != null) {\r\n return firstLabel.textContent;\r\n }\r\n }\r\n return undefined;\r\n}\r\n","export const hasParentWithClass = (element: Element, parentClass: string): boolean => {\r\n const parent = element.parentElement;\r\n if (parent != null) {\r\n return parent.classList.contains(parentClass) ? true : hasParentWithClass(parent, parentClass);\r\n }\r\n return false;\r\n};\r\n","/* eslint-disable jsx-a11y/no-static-element-interactions */\r\nimport React from 'react';\r\nimport { RadioButtonValg, RadioButtonValgModel } from './RadioButtonValg';\r\nimport { RadioButtonDisplay } from './ValgDisplayFunctions';\r\nimport VeilederStegComponent, { VeilederStegBaseProps, VeilederStegDefaultProps } from './VeilederStegComponent';\r\nimport getLabelValue from '../Utilities/InputUtilities';\r\nimport Valg from '../Models/Valg';\r\nimport { EpiAppStateMedSteg } from '../Store/Types';\r\nimport { connect } from 'react-redux';\r\nimport { EpiContext } from '../Store/EpiContext/Types';\r\nimport { setCollapsed } from '../Store/StegVisning/Actions';\r\nimport contentResolver from '../Utilities/EpiContentResolver';\r\nimport { hasParentWithClass } from '../Utilities/ElementUtilies';\r\n\r\ntype RadioButtonsStegOwnProps<T> = VeilederStegDefaultProps &\r\n VeilederStegBaseProps & {\r\n sporsmal: keyof T;\r\n value?: Valg<string>;\r\n valg: Array<RadioButtonValgModel<T>>;\r\n onInputChange(valg: Valg<string>): void;\r\n };\r\n\r\ntype RadioButtonsStegProps<T> = RadioButtonsStegOwnProps<T> & MapStateToProps<T> & MapDispatchToProps;\r\n\r\nclass RadioButtonsStegComponent<T> extends React.PureComponent<RadioButtonsStegProps<T>> {\r\n static defaultProps: VeilederStegDefaultProps = {\r\n neverCollapse: false,\r\n };\r\n\r\n constructor(props: RadioButtonsStegProps<T>) {\r\n super(props);\r\n\r\n this.onInputChange = this.onInputChange.bind(this);\r\n this.onMouseUp = this.onMouseUp.bind(this);\r\n }\r\n\r\n onMouseUp = (event: React.MouseEvent): void => {\r\n const { neverCollapse, sporsmalId, stegVisningSetCollapsed } = this.props;\r\n if (\r\n neverCollapse !== true &&\r\n event.target != null &&\r\n hasParentWithClass(event.target as Element, 'c-radio-input')\r\n ) {\r\n stegVisningSetCollapsed({ id: sporsmalId, isCollapsed: true });\r\n }\r\n };\r\n\r\n onInputChange = (e: React.FormEvent<HTMLDivElement>): void => {\r\n const { onInputChange } = this.props;\r\n const inputSource = e.target as HTMLInputElement;\r\n const newValue = {\r\n displayValue: getLabelValue(inputSource) as string,\r\n value: inputSource.value,\r\n id: inputSource.id,\r\n };\r\n\r\n onInputChange(newValue);\r\n };\r\n\r\n render(): JSX.Element {\r\n const {\r\n sporsmalId,\r\n valg,\r\n tittel,\r\n forklaring,\r\n sporsmal,\r\n neverCollapse,\r\n classModifier,\r\n customBottomRow,\r\n value,\r\n epiContext,\r\n } = this.props;\r\n\r\n const gruppe = sporsmalId;\r\n const radioValg = valg.map((v: RadioButtonValgModel<T>) =>\r\n RadioButtonValg<T>(gruppe, v.id, v.value, v.tekst, value ? value.id === v.id : false, epiContext),\r\n );\r\n\r\n const display = value ? RadioButtonDisplay(gruppe, value) : null;\r\n return (\r\n <VeilederStegComponent\r\n sporsmalId={sporsmalId}\r\n tittel={tittel}\r\n forklaring={forklaring}\r\n inputArea={\r\n <div className=\"c-veileder__inputomrade\">\r\n <fieldset className=\"c-veileder__fieldset\">\r\n <legend>\r\n <span className=\"c-veileder__undersporsmal\">{contentResolver(epiContext, sporsmal)}</span>\r\n </legend>\r\n <div className=\"c-veileder__radioknapper-container\" onMouseUp={this.onMouseUp} onChange={this.onInputChange}>\r\n {radioValg}\r\n </div>\r\n </fieldset>\r\n </div>\r\n }\r\n displayElement={display}\r\n canCollapse={value !== undefined}\r\n neverCollapse={neverCollapse}\r\n classModifier={classModifier}\r\n customBottomRow={customBottomRow}\r\n />\r\n );\r\n }\r\n}\r\n\r\ninterface MapStateToProps<T> {\r\n epiContext: EpiContext<T>;\r\n}\r\n\r\ninterface MapDispatchToProps {\r\n stegVisningSetCollapsed: typeof setCollapsed;\r\n}\r\n\r\nexport default function RadioButtonsStegContainer<T>() {\r\n return connect(\r\n (state: EpiAppStateMedSteg<T>): MapStateToProps<T> => {\r\n return {\r\n epiContext: state.epiContext,\r\n };\r\n },\r\n { stegVisningSetCollapsed: setCollapsed },\r\n )(RadioButtonsStegComponent as new (props: RadioButtonsStegProps<T>) => RadioButtonsStegComponent<T>);\r\n}\r\n"],"names":["jsxs","jsx","contentResolver"],"mappings":";;;;AAUO,SAAS,gBACZ,OACA,IACA,OACA,OACA,WACA,YACW;AAEP,SAAAA,kCAAA,KAAC,OAAI,EAAA,WAAU,iBACX,UAAA;AAAA,IAAAC,kCAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACG,MAAK;AAAA,QACL,MAAM;AAAA,QACN;AAAA,QACA;AAAA,QACA,SAAS;AAAA,QACT,gBAAc;AAAA,QAEd,UAAU,MAAY;AAAA,QAAA;AAAA,MAAC;AAAA,IAC3B;AAAA,0CACC,SAAM,EAAA,SAAS,IAAK,UAAgBC,QAAA,YAAY,KAAK,EAAE,CAAA;AAAA,EAAA,EAAA,GAXxB,EAYpC;AAER;AC9BgB,SAAA,mBAAmB,QAAgB,OAAkC;AAC3E,QAAA,KAAK,GAAG,MAAM;AAEhB,SAAAD,kCAAAA,IAAC,OAAI,EAAA,WAAU,0BACX,UAAAA,sCAAC,QAAK,EAAA,WAAU,6CAA4C,IACvD,UAAM,MAAA,aACX,CAAA,GACJ;AAER;AAEgB,SAAA,mBAAmB,QAAgB,OAAkC;AAC3E,QAAA,KAAK,GAAG,MAAM;AAEhB,SAAAA,kCAAAA,IAAC,OAAI,EAAA,WAAU,0BACX,UAAAA,sCAAC,QAAK,EAAA,WAAU,6CAA4C,IACvD,UAAM,MAAA,aACX,CAAA,GACJ;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