@entur/modal 2.0.0-alpha.0 → 2.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  This package contains the different Modal components.
4
4
 
5
- > 💡 Looking for the [documentation](https://design.entur.no/komponenter/layout-and-surfaces/modals)?
5
+ > 💡 Looking for the [documentation](https://linje.entur.no/komponenter/layout-og-flater/modal)?
6
6
 
7
7
  ## Installation
8
8
 
@@ -14,4 +14,4 @@ yarn add @entur/modal
14
14
 
15
15
  ## Usage
16
16
 
17
- Please refer to the [documentation](https://design.entur.no/komponenter/layout-and-surfaces/modals) for usage information.
17
+ Please refer to the [documentation](https://linje.entur.no/komponenter/layout-og-flater/modal) for usage information.
package/dist/Drawer.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import React from 'react';
2
- import './Drawer.scss';
1
+ import { default as React } from 'react';
3
2
  export type DrawerProps = {
4
3
  /** Innholdet. Typisk tekst, lenker eller knapper */
5
4
  children: React.ReactNode;
@@ -26,4 +25,4 @@ export type DrawerProps = {
26
25
  /** Legger på et overlay over resten av siden */
27
26
  overlay?: boolean;
28
27
  };
29
- export declare const Drawer: React.FC<DrawerProps>;
28
+ export declare const Drawer: ({ children, className, closeLabel, contrast, open, onDismiss, title, style, overlay, }: DrawerProps) => import("react/jsx-runtime").JSX.Element | null;
package/dist/Modal.d.ts CHANGED
@@ -1,16 +1,19 @@
1
- import React from 'react';
2
- import './Modal.scss';
1
+ import { default as React } from 'react';
3
2
  export type ModalProps = {
4
3
  /** Innholdet i modalen */
5
4
  children: React.ReactNode;
6
5
  /** Skjermleser-label til lukk-knappen */
7
6
  closeLabel?: string;
8
- /** En ref til elementet som skal være fokusert når modalen åpnes. Defaulter til lukkeknappen */
7
+ /** En ref til elementet som skal være fokusert når modalen åpnes. Defaulter til tittelen, ellers første interaktive element */
9
8
  initialFocusRef?: React.RefObject<HTMLElement>;
10
- /** Flagg som sier om modalen er åpen */
9
+ /** Styrer om modalen er synlig */
11
10
  open?: boolean;
12
- /** Callback som kalles når brukeren ber om å lukke modalen */
13
- onDismiss?: () => void;
11
+ /** Callback som kalles når brukeren ber om å lukke modalen. Påkrevd: Esc og klikk utenfor lukker alltid (nettleserens innebygde atferd for native dialog) */
12
+ onDismiss: () => void;
13
+ /** Om lukkeknappen skal vises i øvre høyre hjørne
14
+ * @default true
15
+ */
16
+ showCloseButton?: boolean;
14
17
  /** Størrelsen på modalen */
15
18
  size: 'extraSmall' | 'small' | 'medium' | 'large' | 'extraLarge';
16
19
  /** Hvordan innholdet skal plasseres i modalen
@@ -19,10 +22,11 @@ export type ModalProps = {
19
22
  align?: 'start' | 'center' | 'end';
20
23
  /** Tittelen som vises i modalen */
21
24
  title?: React.ReactNode;
25
+ /** Tilgjengelig navn for modalen når title ikke er satt */
26
+ 'aria-label'?: string;
22
27
  /** Om modalen skal lukkes når man klikker på utsiden av den
23
28
  * @default true
24
29
  */
25
30
  closeOnClickOutside?: boolean;
26
- [key: string]: any;
27
- };
28
- export declare const Modal: React.FC<ModalProps>;
31
+ } & Omit<React.HTMLAttributes<HTMLDivElement>, 'title' | 'aria-label'>;
32
+ export declare const Modal: ({ children, closeLabel, initialFocusRef, open, onDismiss, size, align, title, closeOnClickOutside, showCloseButton, "aria-label": ariaLabel, ...rest }: ModalProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import { default as React } from 'react';
2
2
  export type ModalContentProps = {
3
3
  /** Innholdet i modalen */
4
4
  children: React.ReactNode;
@@ -12,13 +12,12 @@ export type ModalContentProps = {
12
12
  * @default 'start'
13
13
  */
14
14
  align?: 'start' | 'center' | 'end';
15
- [key: string]: any;
16
- };
15
+ } & Omit<React.HTMLAttributes<HTMLDivElement>, 'title'>;
17
16
  export declare const headingsMap: {
18
- extraSmall: <E extends React.ElementType<any> = "h4">({ margin, children, as, ...rest }: import("@entur/typography").Heading4Props<E>) => JSX.Element;
19
- small: <E_1 extends React.ElementType<any> = "h3">({ margin, children, as, ...rest }: import("@entur/typography").Heading3Props<E_1>) => JSX.Element;
20
- medium: <E_2 extends React.ElementType<any> = "h2">({ margin, children, as, ...rest }: import("@entur/typography").Heading2Props<E_2>) => JSX.Element;
21
- large: <E_2 extends React.ElementType<any> = "h2">({ margin, children, as, ...rest }: import("@entur/typography").Heading2Props<E_2>) => JSX.Element;
22
- extraLarge: <E_2 extends React.ElementType<any> = "h2">({ margin, children, as, ...rest }: import("@entur/typography").Heading2Props<E_2>) => JSX.Element;
17
+ extraSmall: <E extends React.ElementType = "h4">({ margin, children, as, ...rest }: import('../../typography').Heading4Props<E>) => JSX.Element;
18
+ small: <E extends React.ElementType = "h3">({ margin, children, as, ...rest }: import('../../typography').Heading3Props<E>) => JSX.Element;
19
+ medium: <E extends React.ElementType = "h2">({ margin, children, as, ...rest }: import('../../typography').Heading2Props<E>) => JSX.Element;
20
+ large: <E extends React.ElementType = "h2">({ margin, children, as, ...rest }: import('../../typography').Heading2Props<E>) => JSX.Element;
21
+ extraLarge: <E extends React.ElementType = "h2">({ margin, children, as, ...rest }: import('../../typography').Heading2Props<E>) => JSX.Element;
23
22
  };
24
- export declare const ModalContent: React.FC<ModalContentProps>;
23
+ export declare const ModalContent: ({ children, className, size, title, align, ...rest }: ModalContentProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import { default as React } from 'react';
2
2
  export type ModalOverlayProps = {
3
3
  /** Flagg som sier om modalen er åpen */
4
4
  open?: boolean;
@@ -10,6 +10,9 @@ export type ModalOverlayProps = {
10
10
  className?: string;
11
11
  /** En ref til elementet som skal være fokusert når modalen åpnes. Defaulter til lukkeknappen */
12
12
  initialFocusRef?: React.RefObject<HTMLElement>;
13
- [key: string]: any;
14
- };
15
- export declare const ModalOverlay: React.FC<ModalOverlayProps>;
13
+ /** Om modalen skal lukkes når man klikker utenfor den
14
+ * @default true
15
+ */
16
+ closeOnClickOutside?: boolean;
17
+ } & Omit<React.DialogHTMLAttributes<HTMLDialogElement>, 'open' | 'onClick'>;
18
+ export declare const ModalOverlay: ({ className, open, onDismiss, initialFocusRef, closeOnClickOutside, children, ...rest }: ModalOverlayProps) => React.ReactPortal | null;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import './index.scss';
2
1
  export * from './Modal';
3
2
  export * from './ModalOverlay';
4
3
  export * from './ModalContent';
@@ -0,0 +1,247 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const utils = require("@entur/utils");
4
+ const jsxRuntime = require("react/jsx-runtime");
5
+ const react = require("react");
6
+ const icons = require("@entur/icons");
7
+ const button = require("@entur/button");
8
+ const typography = require("@entur/typography");
9
+ const reactDom = require("react-dom");
10
+ const classNames = require("classnames");
11
+ const layout = require("@entur/layout");
12
+ const ModalOverlay = ({
13
+ className,
14
+ open,
15
+ onDismiss,
16
+ initialFocusRef,
17
+ closeOnClickOutside = true,
18
+ children,
19
+ ...rest
20
+ }) => {
21
+ const dialogRef = react.useRef(null);
22
+ react.useEffect(() => {
23
+ const dialog = dialogRef.current;
24
+ if (!dialog) return;
25
+ if (open && !dialog.open) {
26
+ dialog.showModal();
27
+ const target = initialFocusRef?.current ?? dialog.querySelector("[data-autofocus]") ?? dialog;
28
+ target.focus();
29
+ } else if (!open && dialog.open) {
30
+ dialog.close();
31
+ }
32
+ }, [open, initialFocusRef]);
33
+ react.useEffect(
34
+ function syncCancelEvent() {
35
+ const dialog = dialogRef.current;
36
+ if (!dialog || !onDismiss) return;
37
+ const handleCancel = (e) => {
38
+ e.preventDefault();
39
+ onDismiss();
40
+ };
41
+ dialog.addEventListener("cancel", handleCancel);
42
+ return () => dialog.removeEventListener("cancel", handleCancel);
43
+ },
44
+ [onDismiss]
45
+ );
46
+ const handleClick = react.useCallback(
47
+ (e) => {
48
+ if (!closeOnClickOutside) return;
49
+ if (e.target === dialogRef.current) onDismiss?.();
50
+ },
51
+ [onDismiss, closeOnClickOutside]
52
+ );
53
+ if (typeof document === "undefined") return null;
54
+ return reactDom.createPortal(
55
+ /* @__PURE__ */ jsxRuntime.jsx(layout.ContrastContext.Provider, { value: false, children: /* @__PURE__ */ jsxRuntime.jsx(
56
+ "dialog",
57
+ {
58
+ ref: dialogRef,
59
+ className: classNames("eds-modal__overlay", className),
60
+ ...rest,
61
+ onClick: handleClick,
62
+ children: open && children
63
+ }
64
+ ) }),
65
+ document.body
66
+ );
67
+ };
68
+ const headingsMap = {
69
+ extraSmall: typography.Heading4,
70
+ small: typography.Heading3,
71
+ medium: typography.Heading2,
72
+ large: typography.Heading2,
73
+ extraLarge: typography.Heading2
74
+ };
75
+ const ModalContent = ({
76
+ children,
77
+ className,
78
+ size,
79
+ title,
80
+ align = "start",
81
+ ...rest
82
+ }) => {
83
+ const Heading = headingsMap[size] || typography.Heading2;
84
+ const randomId = react.useId();
85
+ return /* @__PURE__ */ jsxRuntime.jsxs(
86
+ "div",
87
+ {
88
+ className: classNames(
89
+ "eds-modal__content",
90
+ `eds-modal__content--size-${size}`,
91
+ `eds-modal__content--align-${align}`,
92
+ className
93
+ ),
94
+ "aria-labelledby": title ? randomId : void 0,
95
+ ...rest,
96
+ children: [
97
+ title && /* @__PURE__ */ jsxRuntime.jsx(Heading, { margin: "bottom", as: "h2", id: randomId, children: title }),
98
+ children
99
+ ]
100
+ }
101
+ );
102
+ };
103
+ const Modal = ({
104
+ children,
105
+ closeLabel = "Lukk",
106
+ initialFocusRef,
107
+ open,
108
+ onDismiss,
109
+ size,
110
+ align = "start",
111
+ title,
112
+ closeOnClickOutside = true,
113
+ showCloseButton = true,
114
+ "aria-label": ariaLabel,
115
+ ...rest
116
+ }) => {
117
+ const randomId = react.useId();
118
+ const Heading = headingsMap[size] || typography.Heading2;
119
+ return /* @__PURE__ */ jsxRuntime.jsxs(
120
+ ModalOverlay,
121
+ {
122
+ open,
123
+ onDismiss,
124
+ closeOnClickOutside,
125
+ initialFocusRef,
126
+ className: `eds-modal__overlay--size-${size}`,
127
+ "aria-labelledby": title ? randomId : void 0,
128
+ "aria-label": !title ? ariaLabel : void 0,
129
+ children: [
130
+ showCloseButton && /* @__PURE__ */ jsxRuntime.jsx(
131
+ button.IconButton,
132
+ {
133
+ className: "eds-modal__close",
134
+ "aria-label": closeLabel,
135
+ onClick: onDismiss,
136
+ type: "button",
137
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.CloseIcon, {})
138
+ }
139
+ ),
140
+ /* @__PURE__ */ jsxRuntime.jsxs(ModalContent, { size, align, ...rest, children: [
141
+ title && /* @__PURE__ */ jsxRuntime.jsx(
142
+ Heading,
143
+ {
144
+ margin: "bottom",
145
+ as: "h2",
146
+ id: randomId,
147
+ tabIndex: -1,
148
+ "data-autofocus": initialFocusRef ? void 0 : "",
149
+ children: title
150
+ }
151
+ ),
152
+ children
153
+ ] })
154
+ ]
155
+ }
156
+ );
157
+ };
158
+ const Drawer = ({
159
+ children,
160
+ className,
161
+ closeLabel = "Lukk skuff",
162
+ contrast = false,
163
+ open = true,
164
+ onDismiss,
165
+ title,
166
+ style,
167
+ overlay = false
168
+ }) => {
169
+ const titleId = react.useId();
170
+ const drawerRef = react.useRef(null);
171
+ const previouslyFocusedRef = react.useRef(null);
172
+ react.useEffect(
173
+ function handleFocus() {
174
+ if (!open || overlay) return;
175
+ previouslyFocusedRef.current = document.activeElement;
176
+ drawerRef.current?.querySelector("[data-autofocus]")?.focus();
177
+ return () => {
178
+ if (previouslyFocusedRef.current instanceof HTMLElement) {
179
+ previouslyFocusedRef.current.focus();
180
+ }
181
+ };
182
+ },
183
+ [open, overlay]
184
+ );
185
+ const shouldRemoveFromDOM = !open && !overlay;
186
+ if (shouldRemoveFromDOM) return null;
187
+ function handleKeyDown(e) {
188
+ if (e.key === "Escape") {
189
+ e.stopPropagation();
190
+ onDismiss();
191
+ }
192
+ }
193
+ const Wrapper = contrast ? layout.Contrast : "div";
194
+ const nonModalDialogProps = {
195
+ role: "dialog",
196
+ "aria-modal": false,
197
+ "aria-labelledby": titleId
198
+ };
199
+ return /* @__PURE__ */ jsxRuntime.jsx(
200
+ utils.ConditionalWrapper,
201
+ {
202
+ condition: overlay,
203
+ wrapper: (children2) => /* @__PURE__ */ jsxRuntime.jsx(
204
+ ModalOverlay,
205
+ {
206
+ open,
207
+ onDismiss,
208
+ "aria-labelledby": titleId,
209
+ children: children2
210
+ }
211
+ ),
212
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
213
+ Wrapper,
214
+ {
215
+ ref: drawerRef,
216
+ ...!overlay && nonModalDialogProps,
217
+ className: classNames("eds-drawer", className),
218
+ onKeyDown: handleKeyDown,
219
+ style,
220
+ children: [
221
+ /* @__PURE__ */ jsxRuntime.jsx(
222
+ button.IconButton,
223
+ {
224
+ className: "eds-drawer__close-button",
225
+ onClick: onDismiss,
226
+ type: "button",
227
+ "aria-label": closeLabel,
228
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.CloseIcon, { "aria-hidden": true })
229
+ }
230
+ ),
231
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "eds-drawer__content", children: [
232
+ /* @__PURE__ */ jsxRuntime.jsx(typography.Heading3, { as: "h2", id: titleId, tabIndex: -1, "data-autofocus": "", children: title }),
233
+ children
234
+ ] })
235
+ ]
236
+ }
237
+ )
238
+ }
239
+ );
240
+ };
241
+ utils.warnAboutMissingStyles("modal", "icons", "typography", "a11y", "button");
242
+ exports.Drawer = Drawer;
243
+ exports.Modal = Modal;
244
+ exports.ModalContent = ModalContent;
245
+ exports.ModalOverlay = ModalOverlay;
246
+ exports.headingsMap = headingsMap;
247
+ //# sourceMappingURL=modal.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modal.cjs.js","sources":["../src/ModalOverlay.tsx","../src/ModalContent.tsx","../src/Modal.tsx","../src/Drawer.tsx","../src/index.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useRef } from 'react';\nimport { createPortal } from 'react-dom';\nimport classNames from 'classnames';\nimport { ContrastContext } from '@entur/layout';\n\nexport type ModalOverlayProps = {\n /** Flagg som sier om modalen er åpen */\n open?: boolean;\n /** Callback som kalles når brukeren ber om å lukke modalen */\n onDismiss?: () => void;\n /** Innholdet i modalen */\n children: React.ReactNode;\n /** Ekstra klassenavn */\n className?: string;\n /** En ref til elementet som skal være fokusert når modalen åpnes. Defaulter til lukkeknappen */\n initialFocusRef?: React.RefObject<HTMLElement>;\n /** Om modalen skal lukkes når man klikker utenfor den\n * @default true\n */\n closeOnClickOutside?: boolean;\n} & Omit<React.DialogHTMLAttributes<HTMLDialogElement>, 'open' | 'onClick'>;\n\nexport const ModalOverlay = ({\n className,\n open,\n onDismiss,\n initialFocusRef,\n closeOnClickOutside = true,\n children,\n ...rest\n}: ModalOverlayProps) => {\n const dialogRef = useRef<HTMLDialogElement>(null);\n\n // Toggle native dialog open state. Always stays in DOM so the browser can\n // manage initial focus storage + restore on close.\n useEffect(() => {\n const dialog = dialogRef.current;\n if (!dialog) return;\n if (open && !dialog.open) {\n dialog.showModal();\n const target =\n initialFocusRef?.current ??\n dialog.querySelector<HTMLElement>('[data-autofocus]') ??\n dialog;\n target.focus();\n } else if (!open && dialog.open) {\n dialog.close();\n }\n }, [open, initialFocusRef]);\n\n // Esc fires cancel — preventDefault so we route through onDismiss + state,\n // which triggers the effect above to call close() (native restore runs).\n useEffect(\n function syncCancelEvent() {\n const dialog = dialogRef.current;\n if (!dialog || !onDismiss) return;\n const handleCancel = (e: Event) => {\n e.preventDefault();\n onDismiss();\n };\n dialog.addEventListener('cancel', handleCancel);\n return () => dialog.removeEventListener('cancel', handleCancel);\n },\n [onDismiss],\n );\n\n const handleClick = useCallback(\n (e: React.MouseEvent<HTMLDialogElement>) => {\n if (!closeOnClickOutside) return;\n if (e.target === dialogRef.current) onDismiss?.();\n },\n [onDismiss, closeOnClickOutside],\n );\n\n if (typeof document === 'undefined') return null;\n\n return createPortal(\n <ContrastContext.Provider value={false}>\n <dialog\n ref={dialogRef}\n className={classNames('eds-modal__overlay', className)}\n {...rest}\n onClick={handleClick}\n >\n {open && children}\n </dialog>\n </ContrastContext.Provider>,\n document.body,\n );\n};\n","import React, { useId } from 'react';\nimport classNames from 'classnames';\nimport { Heading4, Heading3, Heading2 } from '@entur/typography';\n\nexport type ModalContentProps = {\n /** Innholdet i modalen */\n children: React.ReactNode;\n /** Ekstra klassenavn */\n className?: string;\n /** Størrelsen på modalen */\n size: 'extraSmall' | 'small' | 'medium' | 'large' | 'extraLarge';\n /** Tittelen som vises i modalen */\n title?: React.ReactNode;\n /** Hvordan innholdet skal plasseres i modalen\n * @default 'start'\n */\n align?: 'start' | 'center' | 'end';\n} & Omit<React.HTMLAttributes<HTMLDivElement>, 'title'>;\n\nexport const headingsMap = {\n extraSmall: Heading4,\n small: Heading3,\n medium: Heading2,\n large: Heading2,\n extraLarge: Heading2,\n};\n\nexport const ModalContent = ({\n children,\n className,\n size,\n title,\n align = 'start',\n ...rest\n}: ModalContentProps) => {\n const Heading: React.ElementType = headingsMap[size] || Heading2;\n const randomId = useId();\n return (\n <div\n className={classNames(\n 'eds-modal__content',\n `eds-modal__content--size-${size}`,\n `eds-modal__content--align-${align}`,\n className,\n )}\n aria-labelledby={title ? randomId : undefined}\n {...rest}\n >\n {title && (\n <Heading margin=\"bottom\" as=\"h2\" id={randomId}>\n {title}\n </Heading>\n )}\n {children}\n </div>\n );\n};\n","import React, { useId } from 'react';\n\nimport { CloseIcon } from '@entur/icons';\nimport { IconButton } from '@entur/button';\nimport { Heading2 } from '@entur/typography';\n\nimport { ModalOverlay } from './ModalOverlay';\nimport { ModalContent, headingsMap } from './ModalContent';\n\nimport './Modal.scss';\n\nexport type ModalProps = {\n /** Innholdet i modalen */\n children: React.ReactNode;\n /** Skjermleser-label til lukk-knappen */\n closeLabel?: string;\n /** En ref til elementet som skal være fokusert når modalen åpnes. Defaulter til tittelen, ellers første interaktive element */\n initialFocusRef?: React.RefObject<HTMLElement>;\n /** Styrer om modalen er synlig */\n open?: boolean;\n /** Callback som kalles når brukeren ber om å lukke modalen. Påkrevd: Esc og klikk utenfor lukker alltid (nettleserens innebygde atferd for native dialog) */\n onDismiss: () => void;\n /** Om lukkeknappen skal vises i øvre høyre hjørne\n * @default true\n */\n showCloseButton?: boolean;\n /** Størrelsen på modalen */\n size: 'extraSmall' | 'small' | 'medium' | 'large' | 'extraLarge';\n /** Hvordan innholdet skal plasseres i modalen\n * @default 'start'\n */\n align?: 'start' | 'center' | 'end';\n /** Tittelen som vises i modalen */\n title?: React.ReactNode;\n /** Tilgjengelig navn for modalen når title ikke er satt */\n 'aria-label'?: string;\n /** Om modalen skal lukkes når man klikker på utsiden av den\n * @default true\n */\n closeOnClickOutside?: boolean;\n} & Omit<React.HTMLAttributes<HTMLDivElement>, 'title' | 'aria-label'>;\n\nexport const Modal = ({\n children,\n closeLabel = 'Lukk',\n initialFocusRef,\n open,\n onDismiss,\n size,\n align = 'start',\n title,\n closeOnClickOutside = true,\n showCloseButton = true,\n 'aria-label': ariaLabel,\n ...rest\n}: ModalProps) => {\n const randomId = useId();\n const Heading: React.ElementType = headingsMap[size] || Heading2;\n\n return (\n <ModalOverlay\n open={open}\n onDismiss={onDismiss}\n closeOnClickOutside={closeOnClickOutside}\n initialFocusRef={initialFocusRef}\n className={`eds-modal__overlay--size-${size}`}\n aria-labelledby={title ? randomId : undefined}\n aria-label={!title ? ariaLabel : undefined}\n >\n {showCloseButton && (\n <IconButton\n className=\"eds-modal__close\"\n aria-label={closeLabel}\n onClick={onDismiss}\n type=\"button\"\n >\n <CloseIcon />\n </IconButton>\n )}\n <ModalContent size={size} align={align} {...rest}>\n {title && (\n <Heading\n margin=\"bottom\"\n as=\"h2\"\n id={randomId}\n tabIndex={-1}\n data-autofocus={initialFocusRef ? undefined : ''}\n >\n {title}\n </Heading>\n )}\n {children}\n </ModalContent>\n </ModalOverlay>\n );\n};\n","import React, { useEffect, useId, useRef } from 'react';\nimport classNames from 'classnames';\nimport { Contrast } from '@entur/layout';\nimport { CloseIcon } from '@entur/icons';\nimport { Heading3 } from '@entur/typography';\nimport { IconButton } from '@entur/button';\nimport { ConditionalWrapper } from '@entur/utils';\nimport { ModalOverlay } from './ModalOverlay';\n\nimport './Drawer.scss';\n\nexport type DrawerProps = {\n /** Innholdet. Typisk tekst, lenker eller knapper */\n children: React.ReactNode;\n /** Ekstra klassenavn */\n className?: string;\n /** Tekst som beskriver lukkeknappen for skjermlesere\n * @default 'Lukk skuff'\n */\n closeLabel?: string;\n /** Om draweren skal vises i mørk variant\n * @default false\n */\n contrast?: boolean;\n /** Callback som kalles når brukeren ønsker å lukke draweren */\n onDismiss: () => void;\n /** Om draweren er åpen eller ikke\n * @default true\n */\n open?: boolean;\n /** Tittel på toppen av draweren */\n title: string;\n /** Styling som sendes til Drawer */\n style?: React.CSSProperties;\n /** Legger på et overlay over resten av siden */\n overlay?: boolean;\n};\n\nexport const Drawer = ({\n children,\n className,\n closeLabel = 'Lukk skuff',\n contrast = false,\n open = true,\n onDismiss,\n title,\n style,\n overlay = false,\n}: DrawerProps) => {\n const titleId = useId();\n const drawerRef = useRef<HTMLDivElement>(null);\n const previouslyFocusedRef = useRef<Element | null>(null);\n\n useEffect(\n function handleFocus() {\n if (!open || overlay) return;\n previouslyFocusedRef.current = document.activeElement;\n drawerRef.current\n ?.querySelector<HTMLElement>('[data-autofocus]')\n ?.focus();\n\n return () => {\n if (previouslyFocusedRef.current instanceof HTMLElement) {\n previouslyFocusedRef.current.focus();\n }\n };\n },\n [open, overlay],\n );\n\n const shouldRemoveFromDOM = !open && !overlay;\n if (shouldRemoveFromDOM) return null;\n\n function handleKeyDown(e: React.KeyboardEvent) {\n if (e.key === 'Escape') {\n e.stopPropagation();\n onDismiss();\n }\n }\n\n const Wrapper = contrast ? Contrast : 'div';\n const nonModalDialogProps = {\n role: 'dialog' as const,\n 'aria-modal': false,\n 'aria-labelledby': titleId,\n };\n\n return (\n <ConditionalWrapper\n condition={overlay}\n wrapper={(children: React.ReactNode) => (\n <ModalOverlay\n open={open}\n onDismiss={onDismiss}\n aria-labelledby={titleId}\n >\n {children}\n </ModalOverlay>\n )}\n >\n <Wrapper\n ref={drawerRef}\n {...(!overlay && nonModalDialogProps)}\n className={classNames('eds-drawer', className)}\n onKeyDown={handleKeyDown}\n style={style}\n >\n <IconButton\n className=\"eds-drawer__close-button\"\n onClick={onDismiss}\n type=\"button\"\n aria-label={closeLabel}\n >\n <CloseIcon aria-hidden />\n </IconButton>\n <div className=\"eds-drawer__content\">\n <Heading3 as=\"h2\" id={titleId} tabIndex={-1} data-autofocus=\"\">\n {title}\n </Heading3>\n {children}\n </div>\n </Wrapper>\n </ConditionalWrapper>\n );\n};\n","import { warnAboutMissingStyles } from '@entur/utils';\nimport './index.scss';\n\nwarnAboutMissingStyles('modal', 'icons', 'typography', 'a11y', 'button');\n\nexport * from './Modal';\nexport * from './ModalOverlay';\nexport * from './ModalContent';\nexport * from './Drawer';\n"],"names":["useRef","useEffect","useCallback","createPortal","jsx","ContrastContext","Heading4","Heading3","Heading2","useId","jsxs","IconButton","CloseIcon","Contrast","ConditionalWrapper","children","warnAboutMissingStyles"],"mappings":";;;;;;;;;;;AAsBO,MAAM,eAAe,CAAC;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,sBAAsB;AAAA,EACtB;AAAA,EACA,GAAG;AACL,MAAyB;AACvB,QAAM,YAAYA,MAAAA,OAA0B,IAAI;AAIhDC,QAAAA,UAAU,MAAM;AACd,UAAM,SAAS,UAAU;AACzB,QAAI,CAAC,OAAQ;AACb,QAAI,QAAQ,CAAC,OAAO,MAAM;AACxB,aAAO,UAAA;AACP,YAAM,SACJ,iBAAiB,WACjB,OAAO,cAA2B,kBAAkB,KACpD;AACF,aAAO,MAAA;AAAA,IACT,WAAW,CAAC,QAAQ,OAAO,MAAM;AAC/B,aAAO,MAAA;AAAA,IACT;AAAA,EACF,GAAG,CAAC,MAAM,eAAe,CAA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