@entur/modal 1.7.73-beta.9 → 1.7.74

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/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;
package/dist/Modal.d.ts CHANGED
@@ -1,5 +1,4 @@
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;
@@ -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;
@@ -15,10 +15,10 @@ export type ModalContentProps = {
15
15
  [key: string]: any;
16
16
  };
17
17
  export declare const headingsMap: {
18
- extraSmall: <E extends React.ElementType = "h4">({ margin, children, as, ...rest }: import("@entur/typography").Heading4Props<E>) => JSX.Element;
19
- small: <E extends React.ElementType = "h3">({ margin, children, as, ...rest }: import("@entur/typography").Heading3Props<E>) => JSX.Element;
20
- medium: <E extends React.ElementType = "h2">({ margin, children, as, ...rest }: import("@entur/typography").Heading2Props<E>) => JSX.Element;
21
- large: <E extends React.ElementType = "h2">({ margin, children, as, ...rest }: import("@entur/typography").Heading2Props<E>) => JSX.Element;
22
- extraLarge: <E extends React.ElementType = "h2">({ margin, children, as, ...rest }: import("@entur/typography").Heading2Props<E>) => JSX.Element;
18
+ extraSmall: <E extends React.ElementType = "h4">({ margin, children, as, ...rest }: import('../../typography').Heading4Props<E>) => JSX.Element;
19
+ small: <E extends React.ElementType = "h3">({ margin, children, as, ...rest }: import('../../typography').Heading3Props<E>) => JSX.Element;
20
+ medium: <E extends React.ElementType = "h2">({ margin, children, as, ...rest }: import('../../typography').Heading2Props<E>) => JSX.Element;
21
+ large: <E extends React.ElementType = "h2">({ margin, children, as, ...rest }: import('../../typography').Heading2Props<E>) => JSX.Element;
22
+ extraLarge: <E extends React.ElementType = "h2">({ margin, children, as, ...rest }: import('../../typography').Heading2Props<E>) => JSX.Element;
23
23
  };
24
24
  export declare const ModalContent: React.FC<ModalContentProps>;
@@ -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;
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,165 @@
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 icons = require("@entur/icons");
6
+ const button = require("@entur/button");
7
+ const typography = require("@entur/typography");
8
+ const classNames = require("classnames");
9
+ const dialog = require("@reach/dialog");
10
+ const React = require("react");
11
+ const reactFocusLock = require("react-focus-lock");
12
+ const layout = require("@entur/layout");
13
+ const ModalOverlay = ({
14
+ className,
15
+ open,
16
+ ...rest
17
+ }) => /* @__PURE__ */ jsxRuntime.jsx(
18
+ dialog.DialogOverlay,
19
+ {
20
+ className: classNames("eds-modal__overlay", className),
21
+ isOpen: open,
22
+ ...rest
23
+ }
24
+ );
25
+ const headingsMap = {
26
+ extraSmall: typography.Heading4,
27
+ small: typography.Heading3,
28
+ medium: typography.Heading2,
29
+ large: typography.Heading2,
30
+ extraLarge: typography.Heading2
31
+ };
32
+ const ModalContent = ({
33
+ children,
34
+ className,
35
+ size,
36
+ title,
37
+ align = "start",
38
+ ...rest
39
+ }) => {
40
+ const Heading = headingsMap[size] || typography.Heading2;
41
+ const randomId = utils.useRandomId("eds-modal");
42
+ return /* @__PURE__ */ jsxRuntime.jsxs(
43
+ dialog.DialogContent,
44
+ {
45
+ className: classNames(
46
+ "eds-modal__content",
47
+ `eds-modal__content--size-${size}`,
48
+ `eds-modal__content--align-${align}`,
49
+ className
50
+ ),
51
+ "aria-labelledby": randomId,
52
+ ...rest,
53
+ children: [
54
+ title && /* @__PURE__ */ jsxRuntime.jsx(Heading, { margin: "bottom", as: "h2", id: randomId, children: title }),
55
+ children
56
+ ]
57
+ }
58
+ );
59
+ };
60
+ const Modal = ({
61
+ children,
62
+ closeLabel = "Lukk",
63
+ initialFocusRef,
64
+ open,
65
+ onDismiss,
66
+ size,
67
+ align = "start",
68
+ title,
69
+ closeOnClickOutside = true,
70
+ ...rest
71
+ }) => {
72
+ const randomId = utils.useRandomId("eds-modal");
73
+ const Heading = headingsMap[size] || typography.Heading2;
74
+ const showCloseButton = ["medium", "large", "extraLarge"].includes(size);
75
+ let handleOnDismiss;
76
+ if (onDismiss && closeOnClickOutside) {
77
+ handleOnDismiss = onDismiss;
78
+ }
79
+ return /* @__PURE__ */ jsxRuntime.jsx(
80
+ ModalOverlay,
81
+ {
82
+ open,
83
+ onDismiss: handleOnDismiss,
84
+ initialFocusRef,
85
+ children: /* @__PURE__ */ jsxRuntime.jsxs(ModalContent, { size, align, ...rest, children: [
86
+ showCloseButton && /* @__PURE__ */ jsxRuntime.jsx(
87
+ button.IconButton,
88
+ {
89
+ className: "eds-modal__close",
90
+ "aria-label": closeLabel,
91
+ onClick: onDismiss,
92
+ type: "button",
93
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.CloseIcon, {})
94
+ }
95
+ ),
96
+ title && /* @__PURE__ */ jsxRuntime.jsx(Heading, { margin: "bottom", as: "h2", id: randomId, children: title }),
97
+ children
98
+ ] })
99
+ }
100
+ );
101
+ };
102
+ const Drawer = ({
103
+ children,
104
+ className,
105
+ closeLabel = "Lukk skuff",
106
+ contrast = false,
107
+ open = true,
108
+ onDismiss,
109
+ title,
110
+ style,
111
+ overlay = false
112
+ }) => {
113
+ const titleId = utils.useRandomId("eds-drawer");
114
+ if (!open) {
115
+ return null;
116
+ }
117
+ const handleKeyDown = (e) => {
118
+ if (e.key === "Escape") {
119
+ e.stopPropagation();
120
+ onDismiss();
121
+ }
122
+ };
123
+ const Wrapper = contrast ? layout.Contrast : React.Fragment;
124
+ const ContentContainer = overlay ? dialog.DialogContent : "div";
125
+ return /* @__PURE__ */ jsxRuntime.jsx(
126
+ ConditionalWrapper,
127
+ {
128
+ condition: overlay,
129
+ wrapper: (children2) => /* @__PURE__ */ jsxRuntime.jsx(ModalOverlay, { open, onDismiss, children: children2 }),
130
+ children: /* @__PURE__ */ jsxRuntime.jsx(Wrapper, { children: /* @__PURE__ */ jsxRuntime.jsx(
131
+ ContentContainer,
132
+ {
133
+ "aria-labelledby": titleId,
134
+ className: classNames("eds-drawer", className),
135
+ onKeyDown: handleKeyDown,
136
+ style,
137
+ children: /* @__PURE__ */ jsxRuntime.jsxs(reactFocusLock.MoveFocusInside, { children: [
138
+ /* @__PURE__ */ jsxRuntime.jsx(
139
+ button.IconButton,
140
+ {
141
+ className: "eds-drawer__close-button",
142
+ onClick: onDismiss,
143
+ type: "button",
144
+ "aria-label": closeLabel,
145
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.CloseIcon, { "aria-hidden": true })
146
+ }
147
+ ),
148
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "eds-drawer__content", children: [
149
+ /* @__PURE__ */ jsxRuntime.jsx(typography.Heading3, { as: "h2", id: titleId, children: title }),
150
+ children
151
+ ] })
152
+ ] })
153
+ }
154
+ ) })
155
+ }
156
+ );
157
+ };
158
+ const ConditionalWrapper = ({ condition, wrapper, children }) => condition ? wrapper(children) : children;
159
+ utils.warnAboutMissingStyles("modal", "icons", "typography", "a11y", "button");
160
+ exports.Drawer = Drawer;
161
+ exports.Modal = Modal;
162
+ exports.ModalContent = ModalContent;
163
+ exports.ModalOverlay = ModalOverlay;
164
+ exports.headingsMap = headingsMap;
165
+ //# 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 from 'react';\nimport classNames from 'classnames';\nimport { DialogOverlay } from '@reach/dialog';\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 [key: string]: any;\n};\n\nexport const ModalOverlay: React.FC<ModalOverlayProps> = ({\n className,\n open,\n ...rest\n}) => (\n <DialogOverlay\n className={classNames('eds-modal__overlay', className)}\n isOpen={open}\n {...rest}\n />\n);\n","import React from 'react';\nimport classNames from 'classnames';\nimport { DialogContent } from '@reach/dialog';\nimport { Heading4, Heading3, Heading2 } from '@entur/typography';\nimport { useRandomId } from '@entur/utils';\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 [key: string]: any;\n};\n\nexport const headingsMap = {\n extraSmall: Heading4,\n small: Heading3,\n medium: Heading2,\n large: Heading2,\n extraLarge: Heading2,\n};\n\nexport const ModalContent: React.FC<ModalContentProps> = ({\n children,\n className,\n size,\n title,\n align = 'start',\n ...rest\n}) => {\n const Heading: React.ElementType = headingsMap[size] || Heading2;\n const randomId = useRandomId('eds-modal');\n return (\n <DialogContent\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={randomId}\n {...rest}\n >\n {title && (\n <Heading margin=\"bottom\" as=\"h2\" id={randomId}>\n {title}\n </Heading>\n )}\n {children}\n </DialogContent>\n );\n};\n","import React from 'react';\n\nimport { CloseIcon } from '@entur/icons';\nimport { IconButton } from '@entur/button';\nimport { Heading2 } from '@entur/typography';\nimport { useRandomId } from '@entur/utils';\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 lukkeknappen */\n initialFocusRef?: React.RefObject<HTMLElement>;\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 /** 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 /** Om modalen skal lukkes når man klikker på utsiden av den\n * @default true\n */\n closeOnClickOutside?: boolean;\n [key: string]: any;\n};\n\nexport const Modal: React.FC<ModalProps> = ({\n children,\n closeLabel = 'Lukk',\n initialFocusRef,\n open,\n onDismiss,\n size,\n align = 'start',\n title,\n closeOnClickOutside = true,\n ...rest\n}) => {\n const randomId = useRandomId('eds-modal');\n const Heading: React.ElementType = headingsMap[size] || Heading2;\n const showCloseButton = ['medium', 'large', 'extraLarge'].includes(size);\n\n let handleOnDismiss;\n if (onDismiss && closeOnClickOutside) {\n handleOnDismiss = onDismiss;\n }\n return (\n <ModalOverlay\n open={open}\n onDismiss={handleOnDismiss}\n initialFocusRef={initialFocusRef}\n >\n <ModalContent size={size} align={align} {...rest}>\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 {title && (\n <Heading margin=\"bottom\" as=\"h2\" id={randomId}>\n {title}\n </Heading>\n )}\n {children}\n </ModalContent>\n </ModalOverlay>\n );\n};\n","import React from 'react';\nimport classNames from 'classnames';\nimport { MoveFocusInside } from 'react-focus-lock';\nimport { Contrast } from '@entur/layout';\nimport { CloseIcon } from '@entur/icons';\nimport { Heading3 } from '@entur/typography';\nimport { useRandomId } from '@entur/utils';\nimport { IconButton } from '@entur/button';\n\nimport './Drawer.scss';\nimport { ModalOverlay } from './ModalOverlay';\nimport { DialogContent } from '@reach/dialog';\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: React.FC<DrawerProps> = ({\n children,\n className,\n closeLabel = 'Lukk skuff',\n contrast = false,\n open = true,\n onDismiss,\n title,\n style,\n overlay = false,\n}) => {\n const titleId = useRandomId('eds-drawer');\n\n if (!open) {\n return null;\n }\n\n const handleKeyDown = (e: React.KeyboardEvent) => {\n if (e.key === 'Escape') {\n e.stopPropagation();\n onDismiss();\n }\n };\n\n const Wrapper = contrast ? Contrast : React.Fragment;\n const ContentContainer = overlay ? DialogContent : 'div';\n return (\n <ConditionalWrapper\n condition={overlay}\n wrapper={(children: React.ReactNode) => (\n <ModalOverlay open={open} onDismiss={onDismiss}>\n {children}\n </ModalOverlay>\n )}\n >\n <Wrapper>\n <ContentContainer\n aria-labelledby={titleId}\n className={classNames('eds-drawer', className)}\n onKeyDown={handleKeyDown}\n style={style}\n >\n <MoveFocusInside>\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}>\n {title}\n </Heading3>\n {children}\n </div>\n </MoveFocusInside>\n </ContentContainer>\n </Wrapper>\n </ConditionalWrapper>\n );\n};\n\nconst ConditionalWrapper: React.FC<{\n condition: boolean;\n wrapper: (child: JSX.Element) => JSX.Element;\n children: React.ReactElement;\n}> = ({ condition, wrapper, children }) =>\n condition ? wrapper(children) : children;\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":["jsx","DialogOverlay","Heading4","Heading3","Heading2","useRandomId","jsxs","DialogContent","IconButton","CloseIcon","Contrast","children","MoveFocusInside","warnAboutMissingStyles"],"mappings":";;;;;;;;;;;;AAkBO,MAAM,eAA4C,CAAC;AAAA,EACxD;AAAA,EACA;AAAA,EACA,GAAG;AACL,MACEA,2BAAAA;AAAAA,EAACC,OAAAA;AAAAA,EAAA;AAAA,IACC,WAAW,WAAW,sBAAsB,SAAS;AAAA,IACrD,QAAQ;AAAA,IACP,GAAG;AAAA,EAAA;AACN;ACLK,MAAM,cAAc;AAAA,EACzB,YAAYC,WAAAA;AAAAA,EACZ,OAAOC,WAAAA;AAAAA,EACP,QAAQC,WAAAA;AAAAA,EACR,OAAOA,WAAAA;AAAAA,EACP,YAAYA,WAAAA;AACd;AAEO,MAAM,eAA4C,CAAC;AAAA,EACxD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,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N,+BAACG,WAAAA,UAAA,EAAS,IAAG,MAAK,IAAI,SACnB,UAAA,OACH;AAAA,cACC;AAAA,YAAA,EAAA,CACH;AAAA,UAAA,EAAA,CACF;AAAA,QAAA;AAAA,MAAA,EACF,CACF;AAAA,IAAA;AAAA,EAAA;AAGN;AAEA,MAAM,qBAID,CAAC,EAAE,WAAW,SAAS,eAC1B,YAAY,QAAQ,QAAQ,IAAI;AC1GlCU,MAAAA,uBAAuB,SAAS,SAAS,cAAc,QAAQ,QAAQ;;;;;;"}
package/dist/modal.esm.js CHANGED
@@ -1,173 +1,165 @@
1
- import { useRandomId, warnAboutMissingStyles } from '@entur/utils';
2
- import React from 'react';
3
- import { CloseIcon } from '@entur/icons';
4
- import { IconButton } from '@entur/button';
5
- import { Heading4, Heading3, Heading2 } from '@entur/typography';
6
- import classNames from 'classnames';
7
- import { DialogOverlay, DialogContent } from '@reach/dialog';
8
- import { MoveFocusInside } from 'react-focus-lock';
9
- import { Contrast } from '@entur/layout';
10
-
11
- function _extends() {
12
- return _extends = Object.assign ? Object.assign.bind() : function (n) {
13
- for (var e = 1; e < arguments.length; e++) {
14
- var t = arguments[e];
15
- for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
16
- }
17
- return n;
18
- }, _extends.apply(null, arguments);
19
- }
20
- function _objectWithoutPropertiesLoose(r, e) {
21
- if (null == r) return {};
22
- var t = {};
23
- for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
24
- if (-1 !== e.indexOf(n)) continue;
25
- t[n] = r[n];
1
+ import { useRandomId, warnAboutMissingStyles } from "@entur/utils";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { CloseIcon } from "@entur/icons";
4
+ import { IconButton } from "@entur/button";
5
+ import { Heading2, Heading3, Heading4 } from "@entur/typography";
6
+ import classNames from "classnames";
7
+ import { DialogOverlay, DialogContent } from "@reach/dialog";
8
+ import React from "react";
9
+ import { MoveFocusInside } from "react-focus-lock";
10
+ import { Contrast } from "@entur/layout";
11
+ const ModalOverlay = ({
12
+ className,
13
+ open,
14
+ ...rest
15
+ }) => /* @__PURE__ */ jsx(
16
+ DialogOverlay,
17
+ {
18
+ className: classNames("eds-modal__overlay", className),
19
+ isOpen: open,
20
+ ...rest
26
21
  }
27
- return t;
28
- }
29
-
30
- var _excluded$2 = ["className", "open"];
31
- var ModalOverlay = function ModalOverlay(_ref) {
32
- var className = _ref.className,
33
- open = _ref.open,
34
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$2);
35
- return React.createElement(DialogOverlay, _extends({
36
- className: classNames('eds-modal__overlay', className),
37
- isOpen: open
38
- }, rest));
39
- };
40
-
41
- var _excluded$1 = ["children", "className", "size", "title", "align"];
42
- var headingsMap = {
22
+ );
23
+ const headingsMap = {
43
24
  extraSmall: Heading4,
44
25
  small: Heading3,
45
26
  medium: Heading2,
46
27
  large: Heading2,
47
28
  extraLarge: Heading2
48
29
  };
49
- var ModalContent = function ModalContent(_ref) {
50
- var children = _ref.children,
51
- className = _ref.className,
52
- size = _ref.size,
53
- title = _ref.title,
54
- _ref$align = _ref.align,
55
- align = _ref$align === void 0 ? 'start' : _ref$align,
56
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$1);
57
- var Heading = headingsMap[size] || Heading2;
58
- var randomId = useRandomId('eds-modal');
59
- return React.createElement(DialogContent, _extends({
60
- className: classNames('eds-modal__content', "eds-modal__content--size-" + size, "eds-modal__content--align-" + align, className),
61
- "aria-labelledby": randomId
62
- }, rest), title && React.createElement(Heading, {
63
- margin: "bottom",
64
- as: "h2",
65
- id: randomId
66
- }, title), children);
30
+ const ModalContent = ({
31
+ children,
32
+ className,
33
+ size,
34
+ title,
35
+ align = "start",
36
+ ...rest
37
+ }) => {
38
+ const Heading = headingsMap[size] || Heading2;
39
+ const randomId = useRandomId("eds-modal");
40
+ return /* @__PURE__ */ jsxs(
41
+ DialogContent,
42
+ {
43
+ className: classNames(
44
+ "eds-modal__content",
45
+ `eds-modal__content--size-${size}`,
46
+ `eds-modal__content--align-${align}`,
47
+ className
48
+ ),
49
+ "aria-labelledby": randomId,
50
+ ...rest,
51
+ children: [
52
+ title && /* @__PURE__ */ jsx(Heading, { margin: "bottom", as: "h2", id: randomId, children: title }),
53
+ children
54
+ ]
55
+ }
56
+ );
67
57
  };
68
-
69
- var _excluded = ["children", "closeLabel", "initialFocusRef", "open", "onDismiss", "size", "align", "title", "closeOnClickOutside"];
70
- var Modal = function Modal(_ref) {
71
- var children = _ref.children,
72
- _ref$closeLabel = _ref.closeLabel,
73
- closeLabel = _ref$closeLabel === void 0 ? 'Lukk' : _ref$closeLabel,
74
- initialFocusRef = _ref.initialFocusRef,
75
- open = _ref.open,
76
- onDismiss = _ref.onDismiss,
77
- size = _ref.size,
78
- _ref$align = _ref.align,
79
- align = _ref$align === void 0 ? 'start' : _ref$align,
80
- title = _ref.title,
81
- _ref$closeOnClickOuts = _ref.closeOnClickOutside,
82
- closeOnClickOutside = _ref$closeOnClickOuts === void 0 ? true : _ref$closeOnClickOuts,
83
- rest = _objectWithoutPropertiesLoose(_ref, _excluded);
84
- var randomId = useRandomId('eds-modal');
85
- var Heading = headingsMap[size] || Heading2;
86
- var showCloseButton = ['medium', 'large', 'extraLarge'].includes(size);
87
- var handleOnDismiss;
58
+ const Modal = ({
59
+ children,
60
+ closeLabel = "Lukk",
61
+ initialFocusRef,
62
+ open,
63
+ onDismiss,
64
+ size,
65
+ align = "start",
66
+ title,
67
+ closeOnClickOutside = true,
68
+ ...rest
69
+ }) => {
70
+ const randomId = useRandomId("eds-modal");
71
+ const Heading = headingsMap[size] || Heading2;
72
+ const showCloseButton = ["medium", "large", "extraLarge"].includes(size);
73
+ let handleOnDismiss;
88
74
  if (onDismiss && closeOnClickOutside) {
89
75
  handleOnDismiss = onDismiss;
90
76
  }
91
- return React.createElement(ModalOverlay, {
92
- open: open,
93
- onDismiss: handleOnDismiss,
94
- initialFocusRef: initialFocusRef
95
- }, React.createElement(ModalContent, _extends({
96
- size: size,
97
- align: align
98
- }, rest), showCloseButton && React.createElement(IconButton, {
99
- className: "eds-modal__close",
100
- "aria-label": closeLabel,
101
- onClick: onDismiss,
102
- type: "button"
103
- }, React.createElement(CloseIcon, null)), title && React.createElement(Heading, {
104
- margin: "bottom",
105
- as: "h2",
106
- id: randomId
107
- }, title), children));
77
+ return /* @__PURE__ */ jsx(
78
+ ModalOverlay,
79
+ {
80
+ open,
81
+ onDismiss: handleOnDismiss,
82
+ initialFocusRef,
83
+ children: /* @__PURE__ */ jsxs(ModalContent, { size, align, ...rest, children: [
84
+ showCloseButton && /* @__PURE__ */ jsx(
85
+ IconButton,
86
+ {
87
+ className: "eds-modal__close",
88
+ "aria-label": closeLabel,
89
+ onClick: onDismiss,
90
+ type: "button",
91
+ children: /* @__PURE__ */ jsx(CloseIcon, {})
92
+ }
93
+ ),
94
+ title && /* @__PURE__ */ jsx(Heading, { margin: "bottom", as: "h2", id: randomId, children: title }),
95
+ children
96
+ ] })
97
+ }
98
+ );
108
99
  };
109
-
110
- var Drawer = function Drawer(_ref) {
111
- var children = _ref.children,
112
- className = _ref.className,
113
- _ref$closeLabel = _ref.closeLabel,
114
- closeLabel = _ref$closeLabel === void 0 ? 'Lukk skuff' : _ref$closeLabel,
115
- _ref$contrast = _ref.contrast,
116
- contrast = _ref$contrast === void 0 ? false : _ref$contrast,
117
- _ref$open = _ref.open,
118
- open = _ref$open === void 0 ? true : _ref$open,
119
- onDismiss = _ref.onDismiss,
120
- title = _ref.title,
121
- style = _ref.style,
122
- _ref$overlay = _ref.overlay,
123
- overlay = _ref$overlay === void 0 ? false : _ref$overlay;
124
- var titleId = useRandomId('eds-drawer');
100
+ const Drawer = ({
101
+ children,
102
+ className,
103
+ closeLabel = "Lukk skuff",
104
+ contrast = false,
105
+ open = true,
106
+ onDismiss,
107
+ title,
108
+ style,
109
+ overlay = false
110
+ }) => {
111
+ const titleId = useRandomId("eds-drawer");
125
112
  if (!open) {
126
113
  return null;
127
114
  }
128
- var handleKeyDown = function handleKeyDown(e) {
129
- if (e.key === 'Escape') {
115
+ const handleKeyDown = (e) => {
116
+ if (e.key === "Escape") {
130
117
  e.stopPropagation();
131
118
  onDismiss();
132
119
  }
133
120
  };
134
- var Wrapper = contrast ? Contrast : React.Fragment;
135
- var ContentContainer = overlay ? DialogContent : 'div';
136
- return React.createElement(ConditionalWrapper, {
137
- condition: overlay,
138
- wrapper: function wrapper(children) {
139
- return React.createElement(ModalOverlay, {
140
- open: open,
141
- onDismiss: onDismiss
142
- }, children);
121
+ const Wrapper = contrast ? Contrast : React.Fragment;
122
+ const ContentContainer = overlay ? DialogContent : "div";
123
+ return /* @__PURE__ */ jsx(
124
+ ConditionalWrapper,
125
+ {
126
+ condition: overlay,
127
+ wrapper: (children2) => /* @__PURE__ */ jsx(ModalOverlay, { open, onDismiss, children: children2 }),
128
+ children: /* @__PURE__ */ jsx(Wrapper, { children: /* @__PURE__ */ jsx(
129
+ ContentContainer,
130
+ {
131
+ "aria-labelledby": titleId,
132
+ className: classNames("eds-drawer", className),
133
+ onKeyDown: handleKeyDown,
134
+ style,
135
+ children: /* @__PURE__ */ jsxs(MoveFocusInside, { children: [
136
+ /* @__PURE__ */ jsx(
137
+ IconButton,
138
+ {
139
+ className: "eds-drawer__close-button",
140
+ onClick: onDismiss,
141
+ type: "button",
142
+ "aria-label": closeLabel,
143
+ children: /* @__PURE__ */ jsx(CloseIcon, { "aria-hidden": true })
144
+ }
145
+ ),
146
+ /* @__PURE__ */ jsxs("div", { className: "eds-drawer__content", children: [
147
+ /* @__PURE__ */ jsx(Heading3, { as: "h2", id: titleId, children: title }),
148
+ children
149
+ ] })
150
+ ] })
151
+ }
152
+ ) })
143
153
  }
144
- }, React.createElement(Wrapper, null, React.createElement(ContentContainer, {
145
- "aria-labelledby": titleId,
146
- className: classNames('eds-drawer', className),
147
- onKeyDown: handleKeyDown,
148
- style: style
149
- }, React.createElement(MoveFocusInside, null, React.createElement(IconButton, {
150
- className: "eds-drawer__close-button",
151
- onClick: onDismiss,
152
- type: "button",
153
- "aria-label": closeLabel
154
- }, React.createElement(CloseIcon, {
155
- "aria-hidden": true
156
- })), React.createElement("div", {
157
- className: "eds-drawer__content"
158
- }, React.createElement(Heading3, {
159
- as: "h2",
160
- id: titleId
161
- }, title), children)))));
154
+ );
162
155
  };
163
- var ConditionalWrapper = function ConditionalWrapper(_ref2) {
164
- var condition = _ref2.condition,
165
- wrapper = _ref2.wrapper,
166
- children = _ref2.children;
167
- return condition ? wrapper(children) : children;
156
+ const ConditionalWrapper = ({ condition, wrapper, children }) => condition ? wrapper(children) : children;
157
+ warnAboutMissingStyles("modal", "icons", "typography", "a11y", "button");
158
+ export {
159
+ Drawer,
160
+ Modal,
161
+ ModalContent,
162
+ ModalOverlay,
163
+ headingsMap
168
164
  };
169
-
170
- warnAboutMissingStyles('modal', 'icons', 'typography', 'a11y', 'button');
171
-
172
- export { Drawer, Modal, ModalContent, ModalOverlay, headingsMap };
173
165
  //# sourceMappingURL=modal.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"modal.esm.js","sources":["../src/ModalOverlay.tsx","../src/ModalContent.tsx","../src/Modal.tsx","../src/Drawer.tsx","../src/index.tsx"],"sourcesContent":["import React from 'react';\nimport classNames from 'classnames';\nimport { DialogOverlay } from '@reach/dialog';\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 [key: string]: any;\n};\n\nexport const ModalOverlay: React.FC<ModalOverlayProps> = ({\n className,\n open,\n ...rest\n}) => (\n <DialogOverlay\n className={classNames('eds-modal__overlay', className)}\n isOpen={open}\n {...rest}\n />\n);\n","import React from 'react';\nimport classNames from 'classnames';\nimport { DialogContent } from '@reach/dialog';\nimport { Heading4, Heading3, Heading2 } from '@entur/typography';\nimport { useRandomId } from '@entur/utils';\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 [key: string]: any;\n};\n\nexport const headingsMap = {\n extraSmall: Heading4,\n small: Heading3,\n medium: Heading2,\n large: Heading2,\n extraLarge: Heading2,\n};\n\nexport const ModalContent: React.FC<ModalContentProps> = ({\n children,\n className,\n size,\n title,\n align = 'start',\n ...rest\n}) => {\n const Heading: React.ElementType = headingsMap[size] || Heading2;\n const randomId = useRandomId('eds-modal');\n return (\n <DialogContent\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={randomId}\n {...rest}\n >\n {title && (\n <Heading margin=\"bottom\" as=\"h2\" id={randomId}>\n {title}\n </Heading>\n )}\n {children}\n </DialogContent>\n );\n};\n","import React from 'react';\n\nimport { CloseIcon } from '@entur/icons';\nimport { IconButton } from '@entur/button';\nimport { Heading2 } from '@entur/typography';\nimport { useRandomId } from '@entur/utils';\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 lukkeknappen */\n initialFocusRef?: React.RefObject<HTMLElement>;\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 /** 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 /** Om modalen skal lukkes når man klikker på utsiden av den\n * @default true\n */\n closeOnClickOutside?: boolean;\n [key: string]: any;\n};\n\nexport const Modal: React.FC<ModalProps> = ({\n children,\n closeLabel = 'Lukk',\n initialFocusRef,\n open,\n onDismiss,\n size,\n align = 'start',\n title,\n closeOnClickOutside = true,\n ...rest\n}) => {\n const randomId = useRandomId('eds-modal');\n const Heading: React.ElementType = headingsMap[size] || Heading2;\n const showCloseButton = ['medium', 'large', 'extraLarge'].includes(size);\n\n let handleOnDismiss;\n if (onDismiss && closeOnClickOutside) {\n handleOnDismiss = onDismiss;\n }\n return (\n <ModalOverlay\n open={open}\n onDismiss={handleOnDismiss}\n initialFocusRef={initialFocusRef}\n >\n <ModalContent size={size} align={align} {...rest}>\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 {title && (\n <Heading margin=\"bottom\" as=\"h2\" id={randomId}>\n {title}\n </Heading>\n )}\n {children}\n </ModalContent>\n </ModalOverlay>\n );\n};\n","import React from 'react';\nimport classNames from 'classnames';\nimport { MoveFocusInside } from 'react-focus-lock';\nimport { Contrast } from '@entur/layout';\nimport { CloseIcon } from '@entur/icons';\nimport { Heading3 } from '@entur/typography';\nimport { useRandomId } from '@entur/utils';\nimport { IconButton } from '@entur/button';\n\nimport './Drawer.scss';\nimport { ModalOverlay } from './ModalOverlay';\nimport { DialogContent } from '@reach/dialog';\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: React.FC<DrawerProps> = ({\n children,\n className,\n closeLabel = 'Lukk skuff',\n contrast = false,\n open = true,\n onDismiss,\n title,\n style,\n overlay = false,\n}) => {\n const titleId = useRandomId('eds-drawer');\n\n if (!open) {\n return null;\n }\n\n const handleKeyDown = (e: React.KeyboardEvent) => {\n if (e.key === 'Escape') {\n e.stopPropagation();\n onDismiss();\n }\n };\n\n const Wrapper = contrast ? Contrast : React.Fragment;\n const ContentContainer = overlay ? DialogContent : 'div';\n return (\n <ConditionalWrapper\n condition={overlay}\n wrapper={(children: React.ReactNode) => (\n <ModalOverlay open={open} onDismiss={onDismiss}>\n {children}\n </ModalOverlay>\n )}\n >\n <Wrapper>\n <ContentContainer\n aria-labelledby={titleId}\n className={classNames('eds-drawer', className)}\n onKeyDown={handleKeyDown}\n style={style}\n >\n <MoveFocusInside>\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}>\n {title}\n </Heading3>\n {children}\n </div>\n </MoveFocusInside>\n </ContentContainer>\n </Wrapper>\n </ConditionalWrapper>\n );\n};\n\nconst ConditionalWrapper: React.FC<{\n condition: boolean;\n wrapper: (child: JSX.Element) => JSX.Element;\n children: React.ReactElement;\n}> = ({ condition, wrapper, children }) =>\n condition ? wrapper(children) : children;\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":["ModalOverlay","_ref","className","open","rest","_objectWithoutPropertiesLoose","_excluded","React","createElement","DialogOverlay","_extends","classNames","isOpen","headingsMap","extraSmall","Heading4","small","Heading3","medium","Heading2","large","extraLarge","ModalContent","children","size","title","_ref$align","align","Heading","randomId","useRandomId","DialogContent","margin","as","id","Modal","_ref$closeLabel","closeLabel","initialFocusRef","onDismiss","_ref$closeOnClickOuts","closeOnClickOutside","showCloseButton","includes","handleOnDismiss","IconButton","onClick","type","CloseIcon","Drawer","_ref$contrast","contrast","_ref$open","style","_ref$overlay","overlay","titleId","handleKeyDown","e","key","stopPropagation","Wrapper","Contrast","Fragment","ContentContainer","ConditionalWrapper","condition","wrapper","onKeyDown","MoveFocusInside","_ref2","warnAboutMissingStyles"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAkBaA,YAAY,GAAgC,SAA5CA,YAAYA,CAAAC,IAAA,EAAA;AAAA,EAAA,IACvBC,SAAS,GAAAD,IAAA,CAATC,SAAS;IACTC,IAAI,GAAAF,IAAA,CAAJE,IAAI;AACDC,IAAAA,IAAI,GAAAC,6BAAA,CAAAJ,IAAA,EAAAK,WAAA,CAAA,CAAA;AAAA,EAAA,OAEPC,KAAA,CAAAC,aAAA,CAACC,aAAa,EAAAC,QAAA,CAAA;AACZR,IAAAA,SAAS,EAAES,UAAU,CAAC,oBAAoB,EAAET,SAAS,CAAC;AACtDU,IAAAA,MAAM,EAAET,IAAAA;GACJC,EAAAA,IAAI,CAAA,CACR,CAAA;AAAA;;;ACLG,IAAMS,WAAW,GAAG;AACzBC,EAAAA,UAAU,EAAEC,QAAQ;AACpBC,EAAAA,KAAK,EAAEC,QAAQ;AACfC,EAAAA,MAAM,EAAEC,QAAQ;AAChBC,EAAAA,KAAK,EAAED,QAAQ;AACfE,EAAAA,UAAU,EAAEF,QAAAA;EACb;IAEYG,YAAY,GAAgC,SAA5CA,YAAYA,CAAArB,IAAA,EAO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C,0BAA0B;AACpC4C,IAAAA,OAAO,EAAEP,SAAS;AAClBQ,IAAAA,IAAI,EAAC,QAAQ;kBACDV,UAAAA;AAAU,GAAA,EAEtB9B,KAAC,CAAAC,aAAA,CAAAwC,SAAS;;IAAe,CACd,EACbzC,KAAK,CAAAC,aAAA,CAAA,KAAA,EAAA;AAAAN,IAAAA,SAAS,EAAC,qBAAA;AAAqB,GAAA,EAClCK,KAAC,CAAAC,aAAA,CAAAS,QAAQ,EAAC;AAAAgB,IAAAA,EAAE,EAAC,IAAI;AAACC,IAAAA,EAAE,EAAEsB,OAAAA;GACnB,EAAA/B,KAAK,CACG,EACVF,QAAQ,CACL,CACU,CACD,CACX,CACS,CAAA;AAEzB,EAAC;AAED,IAAM0C,kBAAkB,GAInB,SAJCA,kBAAkBA,CAAAK,KAAA,EAAA;AAAA,EAAA,IAIhBJ,SAAS,GAAAI,KAAA,CAATJ,SAAS;IAAEC,OAAO,GAAAG,KAAA,CAAPH,OAAO;IAAE5C,QAAQ,GAAA+C,KAAA,CAAR/C,QAAQ,CAAA;AAAA,EAAA,OAClC2C,SAAS,GAAGC,OAAO,CAAC5C,QAAQ,CAAC,GAAGA,QAAQ,CAAA;AAAA,CAAA;;AC1G1CgD,sBAAsB,CAAC,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,CAAC;;;;"}
1
+ {"version":3,"file":"modal.esm.js","sources":["../src/ModalOverlay.tsx","../src/ModalContent.tsx","../src/Modal.tsx","../src/Drawer.tsx","../src/index.tsx"],"sourcesContent":["import React from 'react';\nimport classNames from 'classnames';\nimport { DialogOverlay } from '@reach/dialog';\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 [key: string]: any;\n};\n\nexport const ModalOverlay: React.FC<ModalOverlayProps> = ({\n className,\n open,\n ...rest\n}) => (\n <DialogOverlay\n className={classNames('eds-modal__overlay', className)}\n isOpen={open}\n {...rest}\n />\n);\n","import React from 'react';\nimport classNames from 'classnames';\nimport { DialogContent } from '@reach/dialog';\nimport { Heading4, Heading3, Heading2 } from '@entur/typography';\nimport { useRandomId } from '@entur/utils';\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 [key: string]: any;\n};\n\nexport const headingsMap = {\n extraSmall: Heading4,\n small: Heading3,\n medium: Heading2,\n large: Heading2,\n extraLarge: Heading2,\n};\n\nexport const ModalContent: React.FC<ModalContentProps> = ({\n children,\n className,\n size,\n title,\n align = 'start',\n ...rest\n}) => {\n const Heading: React.ElementType = headingsMap[size] || Heading2;\n const randomId = useRandomId('eds-modal');\n return (\n <DialogContent\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={randomId}\n {...rest}\n >\n {title && (\n <Heading margin=\"bottom\" as=\"h2\" id={randomId}>\n {title}\n </Heading>\n )}\n {children}\n </DialogContent>\n );\n};\n","import React from 'react';\n\nimport { CloseIcon } from '@entur/icons';\nimport { IconButton } from '@entur/button';\nimport { Heading2 } from '@entur/typography';\nimport { useRandomId } from '@entur/utils';\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 lukkeknappen */\n initialFocusRef?: React.RefObject<HTMLElement>;\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 /** 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 /** Om modalen skal lukkes når man klikker på utsiden av den\n * @default true\n */\n closeOnClickOutside?: boolean;\n [key: string]: any;\n};\n\nexport const Modal: React.FC<ModalProps> = ({\n children,\n closeLabel = 'Lukk',\n initialFocusRef,\n open,\n onDismiss,\n size,\n align = 'start',\n title,\n closeOnClickOutside = true,\n ...rest\n}) => {\n const randomId = useRandomId('eds-modal');\n const Heading: React.ElementType = headingsMap[size] || Heading2;\n const showCloseButton = ['medium', 'large', 'extraLarge'].includes(size);\n\n let handleOnDismiss;\n if (onDismiss && closeOnClickOutside) {\n handleOnDismiss = onDismiss;\n }\n return (\n <ModalOverlay\n open={open}\n onDismiss={handleOnDismiss}\n initialFocusRef={initialFocusRef}\n >\n <ModalContent size={size} align={align} {...rest}>\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 {title && (\n <Heading margin=\"bottom\" as=\"h2\" id={randomId}>\n {title}\n </Heading>\n )}\n {children}\n </ModalContent>\n </ModalOverlay>\n );\n};\n","import React from 'react';\nimport classNames from 'classnames';\nimport { MoveFocusInside } from 'react-focus-lock';\nimport { Contrast } from '@entur/layout';\nimport { CloseIcon } from '@entur/icons';\nimport { Heading3 } from '@entur/typography';\nimport { useRandomId } from '@entur/utils';\nimport { IconButton } from '@entur/button';\n\nimport './Drawer.scss';\nimport { ModalOverlay } from './ModalOverlay';\nimport { DialogContent } from '@reach/dialog';\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: React.FC<DrawerProps> = ({\n children,\n className,\n closeLabel = 'Lukk skuff',\n contrast = false,\n open = true,\n onDismiss,\n title,\n style,\n overlay = false,\n}) => {\n const titleId = useRandomId('eds-drawer');\n\n if (!open) {\n return null;\n }\n\n const handleKeyDown = (e: React.KeyboardEvent) => {\n if (e.key === 'Escape') {\n e.stopPropagation();\n onDismiss();\n }\n };\n\n const Wrapper = contrast ? Contrast : React.Fragment;\n const ContentContainer = overlay ? DialogContent : 'div';\n return (\n <ConditionalWrapper\n condition={overlay}\n wrapper={(children: React.ReactNode) => (\n <ModalOverlay open={open} onDismiss={onDismiss}>\n {children}\n </ModalOverlay>\n )}\n >\n <Wrapper>\n <ContentContainer\n aria-labelledby={titleId}\n className={classNames('eds-drawer', className)}\n onKeyDown={handleKeyDown}\n style={style}\n >\n <MoveFocusInside>\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}>\n {title}\n </Heading3>\n {children}\n </div>\n </MoveFocusInside>\n </ContentContainer>\n </Wrapper>\n </ConditionalWrapper>\n );\n};\n\nconst ConditionalWrapper: React.FC<{\n condition: boolean;\n wrapper: (child: JSX.Element) => JSX.Element;\n children: React.ReactElement;\n}> = ({ condition, wrapper, children }) =>\n condition ? wrapper(children) : children;\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":["children"],"mappings":";;;;;;;;;;AAkBO,MAAM,eAA4C,CAAC;AAAA,EACxD;AAAA,EACA;AAAA,EACA,GAAG;AACL,MACE;AAAA,EAAC;AAAA,EAAA;AAAA,IACC,WAAW,WAAW,sBAAsB,SAAS;AAAA,IACrD,QAAQ;AAAA,IACP,GAAG;AAAA,EAAA;AACN;ACLK,MAAM,cAAc;AAAA,EACzB,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,YAAY;AACd;AAEO,MAAM,eAA4C,CAAC;AAAA,EACxD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,QAAQ;AAAA,EACR,GAAG;AACL,MAAM;AACJ,QAAM,UAA6B,YAAY,IAAI,KAAK;AACxD,QAAM,WAAW,YAAY,WAAW;AACxC,SACE;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,WAAW;AAAA,QACT;AAAA,QACA,4BAA4B,IAAI;AAAA,QAChC,6BAA6B,KAAK;AAAA,QAClC;AAAA,MAAA;AAAA,MAEF,mBAAiB;AAAA,MAChB,GAAG;AAAA,MAEH,UAAA;AAAA,QAAA,SACC,oBAAC,WAAQ,QAAO,UAAS,IAAG,MAAK,IAAI,UAClC,UAAA,MAAA,CACH;AAAA,QAED;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGP;ACrBO,MAAM,QAA8B,CAAC;AAAA,EAC1C;AAAA,EACA,aAAa;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,QAAQ;AAAA,EAC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Y,WACvB,UAAAA,WACH;AAAA,MAGF,8BAAC,SAAA,EACC,UAAA;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,mBAAiB;AAAA,UACjB,WAAW,WAAW,cAAc,SAAS;AAAA,UAC7C,WAAW;AAAA,UACX;AAAA,UAEA,+BAAC,iBAAA,EACC,UAAA;AAAA,YAAA;AAAA,cAAC;AAAA,cAAA;AAAA,gBACC,WAAU;AAAA,gBACV,SAAS;AAAA,gBACT,MAAK;AAAA,gBACL,cAAY;AAAA,gBAEZ,UAAA,oBAAC,WAAA,EAAU,eAAW,KAAA,CAAC;AAAA,cAAA;AAAA,YAAA;AAAA,YAEzB,qBAAC,OAAA,EAAI,WAAU,uBACb,UAAA;AAAA,cAAA,oBAAC,UAAA,EAAS,IAAG,MAAK,IAAI,SACnB,UAAA,OACH;AAAA,cACC;AAAA,YAAA,EAAA,CACH;AAAA,UAAA,EAAA,CACF;AAAA,QAAA;AAAA,MAAA,EACF,CACF;AAAA,IAAA;AAAA,EAAA;AAGN;AAEA,MAAM,qBAID,CAAC,EAAE,WAAW,SAAS,eAC1B,YAAY,QAAQ,QAAQ,IAAI;AC1GlC,uBAAuB,SAAS,SAAS,cAAc,QAAQ,QAAQ;"}
package/dist/styles.css CHANGED
@@ -1,113 +1,5 @@
1
1
  /* DO NOT CHANGE!*/
2
2
  /* This file is automatically generated from @entur/tokens! Changes will be overwritten. */
3
- :root {
4
- --reach-dialog: 1;
5
- }
6
-
7
- .eds-modal__overlay {
8
- background: rgba(0, 0, 0, 0.5);
9
- bottom: 0;
10
- display: flex;
11
- left: 0;
12
- overflow: hidden;
13
- position: fixed;
14
- right: 0;
15
- top: 0;
16
- z-index: 30;
17
- animation: fadeInOverlay;
18
- animation-duration: 0.2s;
19
- animation-timing-function: ease-in-out;
20
- }
21
- .eds-modal__content {
22
- background: var(--components-modal-modal-standard-fill);
23
- border: 1px solid var(--components-modal-modal-standard-border);
24
- border-radius: 0.75rem;
25
- color: var(--components-modal-modal-standard-text);
26
- margin: auto;
27
- padding: 1.5rem;
28
- position: relative;
29
- width: 100%;
30
- max-height: 90vh;
31
- overflow: auto;
32
- z-index: 40;
33
- animation: slideInContent;
34
- animation-duration: 0.2s;
35
- animation-timing-function: ease-in-out;
36
- }
37
- .eds-modal__content--align-center {
38
- display: flex;
39
- flex-direction: column;
40
- align-items: center;
41
- text-align: center;
42
- }
43
- .eds-modal__content--align-end {
44
- display: flex;
45
- flex-direction: column;
46
- align-items: flex-end;
47
- }
48
- .eds-modal__content--size-extraSmall {
49
- max-width: 21rem;
50
- padding: 1.5rem;
51
- }
52
- .eds-modal__content--size-small {
53
- max-width: 28.125rem;
54
- padding: 2.5rem;
55
- }
56
- .eds-modal__content--size-medium {
57
- max-width: 45rem;
58
- padding: 3rem;
59
- }
60
- .eds-modal__content--size-large {
61
- max-width: 56.25rem;
62
- padding: 3rem;
63
- }
64
- .eds-modal__content--size-extraLarge {
65
- max-width: 78.75rem;
66
- padding: 3rem;
67
- }
68
- .eds-modal__content::-webkit-scrollbar {
69
- width: 16px;
70
- }
71
- .eds-modal__content::-webkit-scrollbar-track {
72
- margin-top: 0.5rem;
73
- margin-bottom: 0.5rem;
74
- }
75
- .eds-modal__content::-webkit-scrollbar-thumb {
76
- background-color: lightgrey;
77
- border: 4px solid transparent;
78
- border-radius: 8px;
79
- background-clip: padding-box;
80
- }
81
- .eds-modal__content::-webkit-scrollbar-thumb:hover {
82
- background-color: grey;
83
- }
84
- .eds-modal__close {
85
- position: absolute;
86
- top: 1rem;
87
- right: 1rem;
88
- color: var(--components-modal-modal-standard-icon);
89
- }
90
-
91
- @keyframes fadeInOverlay {
92
- from {
93
- opacity: 0;
94
- }
95
- to {
96
- opacity: 1;
97
- }
98
- }
99
- @keyframes slideInContent {
100
- from {
101
- top: 5rem;
102
- opacity: 0;
103
- }
104
- to {
105
- top: 0%;
106
- opacity: 1;
107
- }
108
- }
109
- /* DO NOT CHANGE!*/
110
- /* This file is automatically generated from @entur/tokens! Changes will be overwritten. */
111
3
  /* DO NOT CHANGE!*/
112
4
  /* This file is automatically generated from @entur/tokens! Changes will be overwritten. */
113
5
  /* DO NOT CHANGE!*/
@@ -282,8 +174,113 @@
282
174
 
283
175
  :root {
284
176
  --eds-modal: 1;
177
+ }/* DO NOT CHANGE!*/
178
+ /* This file is automatically generated from @entur/tokens! Changes will be overwritten. */
179
+ :root {
180
+ --reach-dialog: 1;
285
181
  }
286
- /* DO NOT CHANGE!*/
182
+
183
+ .eds-modal__overlay {
184
+ background: rgba(0, 0, 0, 0.5);
185
+ bottom: 0;
186
+ display: flex;
187
+ left: 0;
188
+ overflow: hidden;
189
+ position: fixed;
190
+ right: 0;
191
+ top: 0;
192
+ z-index: 30;
193
+ animation: fadeInOverlay;
194
+ animation-duration: 0.2s;
195
+ animation-timing-function: ease-in-out;
196
+ }
197
+ .eds-modal__content {
198
+ background: var(--components-modal-modal-standard-fill);
199
+ border: 1px solid var(--components-modal-modal-standard-border);
200
+ border-radius: 0.75rem;
201
+ color: var(--components-modal-modal-standard-text);
202
+ margin: auto;
203
+ padding: 1.5rem;
204
+ position: relative;
205
+ width: 100%;
206
+ max-height: 90vh;
207
+ overflow: auto;
208
+ z-index: 40;
209
+ animation: slideInContent;
210
+ animation-duration: 0.2s;
211
+ animation-timing-function: ease-in-out;
212
+ }
213
+ .eds-modal__content--align-center {
214
+ display: flex;
215
+ flex-direction: column;
216
+ align-items: center;
217
+ text-align: center;
218
+ }
219
+ .eds-modal__content--align-end {
220
+ display: flex;
221
+ flex-direction: column;
222
+ align-items: flex-end;
223
+ }
224
+ .eds-modal__content--size-extraSmall {
225
+ max-width: 21rem;
226
+ padding: 1.5rem;
227
+ }
228
+ .eds-modal__content--size-small {
229
+ max-width: 28.125rem;
230
+ padding: 2.5rem;
231
+ }
232
+ .eds-modal__content--size-medium {
233
+ max-width: 45rem;
234
+ padding: 3rem;
235
+ }
236
+ .eds-modal__content--size-large {
237
+ max-width: 56.25rem;
238
+ padding: 3rem;
239
+ }
240
+ .eds-modal__content--size-extraLarge {
241
+ max-width: 78.75rem;
242
+ padding: 3rem;
243
+ }
244
+ .eds-modal__content::-webkit-scrollbar {
245
+ width: 16px;
246
+ }
247
+ .eds-modal__content::-webkit-scrollbar-track {
248
+ margin-block: 0.5rem;
249
+ }
250
+ .eds-modal__content::-webkit-scrollbar-thumb {
251
+ background-color: lightgrey;
252
+ border: 4px solid transparent;
253
+ border-radius: 8px;
254
+ background-clip: padding-box;
255
+ }
256
+ .eds-modal__content::-webkit-scrollbar-thumb:hover {
257
+ background-color: grey;
258
+ }
259
+ .eds-modal__close {
260
+ position: absolute;
261
+ top: 1rem;
262
+ right: 1rem;
263
+ color: var(--components-modal-modal-standard-icon);
264
+ }
265
+
266
+ @keyframes fadeInOverlay {
267
+ from {
268
+ opacity: 0;
269
+ }
270
+ to {
271
+ opacity: 1;
272
+ }
273
+ }
274
+ @keyframes slideInContent {
275
+ from {
276
+ top: 5rem;
277
+ opacity: 0;
278
+ }
279
+ to {
280
+ top: 0%;
281
+ opacity: 1;
282
+ }
283
+ }/* DO NOT CHANGE!*/
287
284
  /* This file is automatically generated from @entur/tokens! Changes will be overwritten. */
288
285
  .eds-drawer {
289
286
  animation: slideFromRight forwards ease-out 0.1s;
@@ -320,4 +317,4 @@
320
317
  box-shadow: 0 0.0625rem 0.1875rem rgba(0, 0, 0, 0.25);
321
318
  transform: 0;
322
319
  }
323
- }
320
+ }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@entur/modal",
3
- "version": "1.7.73-beta.9",
3
+ "version": "1.7.74",
4
4
  "license": "EUPL-1.2",
5
- "main": "dist/index.js",
5
+ "main": "dist/modal.cjs.js",
6
6
  "module": "dist/modal.esm.js",
7
- "typings": "dist/index.d.ts",
7
+ "types": "dist/index.d.ts",
8
8
  "files": [
9
9
  "dist"
10
10
  ],
@@ -17,29 +17,39 @@
17
17
  "access": "public"
18
18
  },
19
19
  "scripts": {
20
- "start": "dts watch --noClean",
21
- "build": "dts build",
22
- "test": "dts test",
23
- "lint": "dts lint src"
20
+ "start": "vite build --watch",
21
+ "build": "vite build",
22
+ "test": "jest",
23
+ "lint": "eslint src"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "react": ">=16.8.0",
27
27
  "react-dom": ">=16.8.0"
28
28
  },
29
29
  "dependencies": {
30
- "@entur/a11y": "^0.2.99",
31
- "@entur/button": "^3.3.13-beta.9",
32
- "@entur/icons": "^8.0.0",
33
- "@entur/layout": "^3.1.9-beta.9",
34
- "@entur/tokens": "^3.19.1",
35
- "@entur/typography": "^1.10.0-beta.9",
36
- "@entur/utils": "^0.12.3",
37
- "@reach/dialog": "^0.16.0",
38
- "classnames": "^2.3.1",
39
- "react-focus-lock": "^2.9.1"
30
+ "@entur/a11y": "^0.2.101",
31
+ "@entur/button": "^3.3.14",
32
+ "@entur/icons": "^8.0.2",
33
+ "@entur/layout": "^3.1.10",
34
+ "@entur/tokens": "^3.19.3",
35
+ "@entur/typography": "^1.9.14",
36
+ "@entur/utils": "^0.12.5",
37
+ "@reach/dialog": "^0.16.2",
38
+ "classnames": "^2.5.1",
39
+ "react-focus-lock": "^2.13.6"
40
40
  },
41
41
  "devDependencies": {
42
- "dts-cli": "2.0.5"
42
+ "@testing-library/jest-dom": "^5.17.0",
43
+ "@testing-library/react": "^10.4.9",
44
+ "@testing-library/user-event": "14.6.1",
45
+ "@vitejs/plugin-react": "^5.0.1",
46
+ "eslint": "^7.32.0",
47
+ "jest": "^29.0.0",
48
+ "jest-environment-jsdom": "^29.0.0",
49
+ "ts-jest": "^29.0.0",
50
+ "typescript": "^5.9.2",
51
+ "vite": "^7.1.3",
52
+ "vite-plugin-dts": "^4.5.4"
43
53
  },
44
- "gitHead": "6f685d2e4ac13bdaf9c6480f9e7922c9d8f4619c"
54
+ "gitHead": "5dd9d318f1d79f6f522f978de27b551fda1e91cc"
45
55
  }
package/dist/index.js DELETED
@@ -1,8 +0,0 @@
1
-
2
- 'use strict'
3
-
4
- if (process.env.NODE_ENV === 'production') {
5
- module.exports = require('./modal.cjs.production.min.js')
6
- } else {
7
- module.exports = require('./modal.cjs.development.js')
8
- }
@@ -1,181 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var utils = require('@entur/utils');
6
- var React = require('react');
7
- var icons = require('@entur/icons');
8
- var button = require('@entur/button');
9
- var typography = require('@entur/typography');
10
- var classNames = require('classnames');
11
- var dialog = require('@reach/dialog');
12
- var reactFocusLock = require('react-focus-lock');
13
- var layout = require('@entur/layout');
14
-
15
- function _extends() {
16
- return _extends = Object.assign ? Object.assign.bind() : function (n) {
17
- for (var e = 1; e < arguments.length; e++) {
18
- var t = arguments[e];
19
- for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
20
- }
21
- return n;
22
- }, _extends.apply(null, arguments);
23
- }
24
- function _objectWithoutPropertiesLoose(r, e) {
25
- if (null == r) return {};
26
- var t = {};
27
- for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
28
- if (-1 !== e.indexOf(n)) continue;
29
- t[n] = r[n];
30
- }
31
- return t;
32
- }
33
-
34
- var _excluded$2 = ["className", "open"];
35
- var ModalOverlay = function ModalOverlay(_ref) {
36
- var className = _ref.className,
37
- open = _ref.open,
38
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$2);
39
- return React.createElement(dialog.DialogOverlay, _extends({
40
- className: classNames('eds-modal__overlay', className),
41
- isOpen: open
42
- }, rest));
43
- };
44
-
45
- var _excluded$1 = ["children", "className", "size", "title", "align"];
46
- var headingsMap = {
47
- extraSmall: typography.Heading4,
48
- small: typography.Heading3,
49
- medium: typography.Heading2,
50
- large: typography.Heading2,
51
- extraLarge: typography.Heading2
52
- };
53
- var ModalContent = function ModalContent(_ref) {
54
- var children = _ref.children,
55
- className = _ref.className,
56
- size = _ref.size,
57
- title = _ref.title,
58
- _ref$align = _ref.align,
59
- align = _ref$align === void 0 ? 'start' : _ref$align,
60
- rest = _objectWithoutPropertiesLoose(_ref, _excluded$1);
61
- var Heading = headingsMap[size] || typography.Heading2;
62
- var randomId = utils.useRandomId('eds-modal');
63
- return React.createElement(dialog.DialogContent, _extends({
64
- className: classNames('eds-modal__content', "eds-modal__content--size-" + size, "eds-modal__content--align-" + align, className),
65
- "aria-labelledby": randomId
66
- }, rest), title && React.createElement(Heading, {
67
- margin: "bottom",
68
- as: "h2",
69
- id: randomId
70
- }, title), children);
71
- };
72
-
73
- var _excluded = ["children", "closeLabel", "initialFocusRef", "open", "onDismiss", "size", "align", "title", "closeOnClickOutside"];
74
- var Modal = function Modal(_ref) {
75
- var children = _ref.children,
76
- _ref$closeLabel = _ref.closeLabel,
77
- closeLabel = _ref$closeLabel === void 0 ? 'Lukk' : _ref$closeLabel,
78
- initialFocusRef = _ref.initialFocusRef,
79
- open = _ref.open,
80
- onDismiss = _ref.onDismiss,
81
- size = _ref.size,
82
- _ref$align = _ref.align,
83
- align = _ref$align === void 0 ? 'start' : _ref$align,
84
- title = _ref.title,
85
- _ref$closeOnClickOuts = _ref.closeOnClickOutside,
86
- closeOnClickOutside = _ref$closeOnClickOuts === void 0 ? true : _ref$closeOnClickOuts,
87
- rest = _objectWithoutPropertiesLoose(_ref, _excluded);
88
- var randomId = utils.useRandomId('eds-modal');
89
- var Heading = headingsMap[size] || typography.Heading2;
90
- var showCloseButton = ['medium', 'large', 'extraLarge'].includes(size);
91
- var handleOnDismiss;
92
- if (onDismiss && closeOnClickOutside) {
93
- handleOnDismiss = onDismiss;
94
- }
95
- return React.createElement(ModalOverlay, {
96
- open: open,
97
- onDismiss: handleOnDismiss,
98
- initialFocusRef: initialFocusRef
99
- }, React.createElement(ModalContent, _extends({
100
- size: size,
101
- align: align
102
- }, rest), showCloseButton && React.createElement(button.IconButton, {
103
- className: "eds-modal__close",
104
- "aria-label": closeLabel,
105
- onClick: onDismiss,
106
- type: "button"
107
- }, React.createElement(icons.CloseIcon, null)), title && React.createElement(Heading, {
108
- margin: "bottom",
109
- as: "h2",
110
- id: randomId
111
- }, title), children));
112
- };
113
-
114
- var Drawer = function Drawer(_ref) {
115
- var children = _ref.children,
116
- className = _ref.className,
117
- _ref$closeLabel = _ref.closeLabel,
118
- closeLabel = _ref$closeLabel === void 0 ? 'Lukk skuff' : _ref$closeLabel,
119
- _ref$contrast = _ref.contrast,
120
- contrast = _ref$contrast === void 0 ? false : _ref$contrast,
121
- _ref$open = _ref.open,
122
- open = _ref$open === void 0 ? true : _ref$open,
123
- onDismiss = _ref.onDismiss,
124
- title = _ref.title,
125
- style = _ref.style,
126
- _ref$overlay = _ref.overlay,
127
- overlay = _ref$overlay === void 0 ? false : _ref$overlay;
128
- var titleId = utils.useRandomId('eds-drawer');
129
- if (!open) {
130
- return null;
131
- }
132
- var handleKeyDown = function handleKeyDown(e) {
133
- if (e.key === 'Escape') {
134
- e.stopPropagation();
135
- onDismiss();
136
- }
137
- };
138
- var Wrapper = contrast ? layout.Contrast : React.Fragment;
139
- var ContentContainer = overlay ? dialog.DialogContent : 'div';
140
- return React.createElement(ConditionalWrapper, {
141
- condition: overlay,
142
- wrapper: function wrapper(children) {
143
- return React.createElement(ModalOverlay, {
144
- open: open,
145
- onDismiss: onDismiss
146
- }, children);
147
- }
148
- }, React.createElement(Wrapper, null, React.createElement(ContentContainer, {
149
- "aria-labelledby": titleId,
150
- className: classNames('eds-drawer', className),
151
- onKeyDown: handleKeyDown,
152
- style: style
153
- }, React.createElement(reactFocusLock.MoveFocusInside, null, React.createElement(button.IconButton, {
154
- className: "eds-drawer__close-button",
155
- onClick: onDismiss,
156
- type: "button",
157
- "aria-label": closeLabel
158
- }, React.createElement(icons.CloseIcon, {
159
- "aria-hidden": true
160
- })), React.createElement("div", {
161
- className: "eds-drawer__content"
162
- }, React.createElement(typography.Heading3, {
163
- as: "h2",
164
- id: titleId
165
- }, title), children)))));
166
- };
167
- var ConditionalWrapper = function ConditionalWrapper(_ref2) {
168
- var condition = _ref2.condition,
169
- wrapper = _ref2.wrapper,
170
- children = _ref2.children;
171
- return condition ? wrapper(children) : children;
172
- };
173
-
174
- utils.warnAboutMissingStyles('modal', 'icons', 'typography', 'a11y', 'button');
175
-
176
- exports.Drawer = Drawer;
177
- exports.Modal = Modal;
178
- exports.ModalContent = ModalContent;
179
- exports.ModalOverlay = ModalOverlay;
180
- exports.headingsMap = headingsMap;
181
- //# sourceMappingURL=modal.cjs.development.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"modal.cjs.development.js","sources":["../src/ModalOverlay.tsx","../src/ModalContent.tsx","../src/Modal.tsx","../src/Drawer.tsx","../src/index.tsx"],"sourcesContent":["import React from 'react';\nimport classNames from 'classnames';\nimport { DialogOverlay } from '@reach/dialog';\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 [key: string]: any;\n};\n\nexport const ModalOverlay: React.FC<ModalOverlayProps> = ({\n className,\n open,\n ...rest\n}) => (\n <DialogOverlay\n className={classNames('eds-modal__overlay', className)}\n isOpen={open}\n {...rest}\n />\n);\n","import React from 'react';\nimport classNames from 'classnames';\nimport { DialogContent } from '@reach/dialog';\nimport { Heading4, Heading3, Heading2 } from '@entur/typography';\nimport { useRandomId } from '@entur/utils';\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 [key: string]: any;\n};\n\nexport const headingsMap = {\n extraSmall: Heading4,\n small: Heading3,\n medium: Heading2,\n large: Heading2,\n extraLarge: Heading2,\n};\n\nexport const ModalContent: React.FC<ModalContentProps> = ({\n children,\n className,\n size,\n title,\n align = 'start',\n ...rest\n}) => {\n const Heading: React.ElementType = headingsMap[size] || Heading2;\n const randomId = useRandomId('eds-modal');\n return (\n <DialogContent\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={randomId}\n {...rest}\n >\n {title && (\n <Heading margin=\"bottom\" as=\"h2\" id={randomId}>\n {title}\n </Heading>\n )}\n {children}\n </DialogContent>\n );\n};\n","import React from 'react';\n\nimport { CloseIcon } from '@entur/icons';\nimport { IconButton } from '@entur/button';\nimport { Heading2 } from '@entur/typography';\nimport { useRandomId } from '@entur/utils';\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 lukkeknappen */\n initialFocusRef?: React.RefObject<HTMLElement>;\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 /** 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 /** Om modalen skal lukkes når man klikker på utsiden av den\n * @default true\n */\n closeOnClickOutside?: boolean;\n [key: string]: any;\n};\n\nexport const Modal: React.FC<ModalProps> = ({\n children,\n closeLabel = 'Lukk',\n initialFocusRef,\n open,\n onDismiss,\n size,\n align = 'start',\n title,\n closeOnClickOutside = true,\n ...rest\n}) => {\n const randomId = useRandomId('eds-modal');\n const Heading: React.ElementType = headingsMap[size] || Heading2;\n const showCloseButton = ['medium', 'large', 'extraLarge'].includes(size);\n\n let handleOnDismiss;\n if (onDismiss && closeOnClickOutside) {\n handleOnDismiss = onDismiss;\n }\n return (\n <ModalOverlay\n open={open}\n onDismiss={handleOnDismiss}\n initialFocusRef={initialFocusRef}\n >\n <ModalContent size={size} align={align} {...rest}>\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 {title && (\n <Heading margin=\"bottom\" as=\"h2\" id={randomId}>\n {title}\n </Heading>\n )}\n {children}\n </ModalContent>\n </ModalOverlay>\n );\n};\n","import React from 'react';\nimport classNames from 'classnames';\nimport { MoveFocusInside } from 'react-focus-lock';\nimport { Contrast } from '@entur/layout';\nimport { CloseIcon } from '@entur/icons';\nimport { Heading3 } from '@entur/typography';\nimport { useRandomId } from '@entur/utils';\nimport { IconButton } from '@entur/button';\n\nimport './Drawer.scss';\nimport { ModalOverlay } from './ModalOverlay';\nimport { DialogContent } from '@reach/dialog';\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: React.FC<DrawerProps> = ({\n children,\n className,\n closeLabel = 'Lukk skuff',\n contrast = false,\n open = true,\n onDismiss,\n title,\n style,\n overlay = false,\n}) => {\n const titleId = useRandomId('eds-drawer');\n\n if (!open) {\n return null;\n }\n\n const handleKeyDown = (e: React.KeyboardEvent) => {\n if (e.key === 'Escape') {\n e.stopPropagation();\n onDismiss();\n }\n };\n\n const Wrapper = contrast ? Contrast : React.Fragment;\n const ContentContainer = overlay ? DialogContent : 'div';\n return (\n <ConditionalWrapper\n condition={overlay}\n wrapper={(children: React.ReactNode) => (\n <ModalOverlay open={open} onDismiss={onDismiss}>\n {children}\n </ModalOverlay>\n )}\n >\n <Wrapper>\n <ContentContainer\n aria-labelledby={titleId}\n className={classNames('eds-drawer', className)}\n onKeyDown={handleKeyDown}\n style={style}\n >\n <MoveFocusInside>\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}>\n {title}\n </Heading3>\n {children}\n </div>\n </MoveFocusInside>\n </ContentContainer>\n </Wrapper>\n </ConditionalWrapper>\n );\n};\n\nconst ConditionalWrapper: React.FC<{\n condition: boolean;\n wrapper: (child: JSX.Element) => JSX.Element;\n children: React.ReactElement;\n}> = ({ condition, wrapper, children }) =>\n condition ? wrapper(children) : children;\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":["ModalOverlay","_ref","className","open","rest","_objectWithoutPropertiesLoose","_excluded","React","createElement","DialogOverlay","_extends","classNames","isOpen","headingsMap","extraSmall","Heading4","small","Heading3","medium","Heading2","large","extraLarge","ModalContent","children","size","title","_ref$align","align","Heading","randomId","useRandomId","DialogContent","margin","as","id","Modal","_ref$closeLabel","closeLabel","initialFocusRef","onDismiss","_ref$closeOnClickOuts","closeOnClickOutside","showCloseButton","includes","handleOnDismiss","IconButton","onClick","type","CloseIcon","Drawer","_ref$contrast","contrast","_ref$open","style","_ref$overlay","overlay","titleId","handleKeyDown","e","key","stopPropagation","Wrapper","Contrast","Fragment","ContentContainer","ConditionalWrapper","condition","wrapper","onKeyDown","MoveFocusInside","_ref2","warnAboutMissingStyles"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAkBaA,YAAY,GAAgC,SAA5CA,YAAYA,CAAAC,IAAA,EAAA;AAAA,EAAA,IACvBC,SAAS,GAAAD,IAAA,CAATC,SAAS;IACTC,IAAI,GAAAF,IAAA,CAAJE,IAAI;AACDC,IAAAA,IAAI,GAAAC,6BAAA,CAAAJ,IAAA,EAAAK,WAAA,CAAA,CAAA;AAAA,EAAA,OAEPC,KAAA,CAAAC,aAAA,CAACC,oBAAa,EAAAC,QAAA,CAAA;AACZR,IAAAA,SAAS,EAAES,UAAU,CAAC,oBAAoB,EAAET,SAAS,CAAC;AACtDU,IAAAA,MAAM,EAAET,IAAAA;GACJC,EAAAA,IAAI,CAAA,CACR,CAAA;AAAA;;;ACLG,IAAMS,WAAW,GAAG;AACzBC,EAAAA,UAAU,EAAEC,mBAAQ;AACpBC,EAAAA,KAAK,EAAEC,mBAAQ;AACfC,EAAAA,MAAM,EAAEC,mBAAQ;AAChBC,EAAAA,KAAK,EAAED,mBAAQ;AACfE,EAAAA,UAAU,EAAEF,mBAAAA;EACb;IAEYG,YAAY,GAAgC,SAA5CA,YAAYA,CAAArB,IAAA,EAOpB;AAAA,EAAA,IANHsB,QAAQ,GAAAtB,IAAA,CAARsB,QAAQ;IACRrB,SAAS,GAAAD,IAAA,CAATC,SAAS;IACTsB,IAAI,GAAAvB,IAAA,CAAJuB,IAAI;IACJC,KAAK,GAAAxB,IAAA,CAALwB,KAAK;IAAAC,UAAA,GAAAzB,IAAA,CACL0B,KAAK;AAALA,IAAAA,KAAK,GAAAD,UAAA,KAAG,KAAA,CAAA,GAAA,OAAO,GAAAA,UAAA;AACZtB,IAAAA,IAAI,GAAAC,6BAAA,CAAAJ,IAAA,EAAAK,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,IAAAA,EAAE,EAAEsB,OAAAA;GACnB,EAAA/B,KAAK,CACG,EACVF,QAAQ,CACL,CACU,CACD,CACX,CACS,CAAA;AAEzB,EAAC;AAED,IAAM0C,kBAAkB,GAInB,SAJCA,kBAAkBA,CAAAK,KAAA,EAAA;AAAA,EAAA,IAIhBJ,SAAS,GAAAI,KAAA,CAATJ,SAAS;IAAEC,OAAO,GAAAG,KAAA,CAAPH,OAAO;IAAE5C,QAAQ,GAAA+C,KAAA,CAAR/C,QAAQ,CAAA;AAAA,EAAA,OAClC2C,SAAS,GAAGC,OAAO,CAAC5C,QAAQ,CAAC,GAAGA,QAAQ,CAAA;AAAA,CAAA;;AC1G1CgD,4BAAsB,CAAC,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,CAAC;;;;;;;;"}
@@ -1,2 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@entur/utils"),n=require("react"),a=require("@entur/icons"),t=require("@entur/button"),r=require("@entur/typography"),i=require("classnames"),l=require("@reach/dialog"),o=require("react-focus-lock"),s=require("@entur/layout");function c(){return c=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var a=arguments[n];for(var t in a)({}).hasOwnProperty.call(a,t)&&(e[t]=a[t])}return e},c.apply(null,arguments)}function d(e,n){if(null==e)return{};var a={};for(var t in e)if({}.hasOwnProperty.call(e,t)){if(-1!==n.indexOf(t))continue;a[t]=e[t]}return a}var u=["className","open"],m=function(e){var a=e.className,t=e.open,r=d(e,u);return n.createElement(l.DialogOverlay,c({className:i("eds-modal__overlay",a),isOpen:t},r))},g=["children","className","size","title","align"],p={extraSmall:r.Heading4,small:r.Heading3,medium:r.Heading2,large:r.Heading2,extraLarge:r.Heading2},v=function(a){var t=a.children,o=a.className,s=a.size,u=a.title,m=a.align,v=void 0===m?"start":m,f=d(a,g),y=p[s]||r.Heading2,b=e.useRandomId("eds-modal");return n.createElement(l.DialogContent,c({className:i("eds-modal__content","eds-modal__content--size-"+s,"eds-modal__content--align-"+v,o),"aria-labelledby":b},f),u&&n.createElement(y,{margin:"bottom",as:"h2",id:b},u),t)},f=["children","closeLabel","initialFocusRef","open","onDismiss","size","align","title","closeOnClickOutside"],y=function(e){var n=e.children;return e.condition?(0,e.wrapper)(n):n};e.warnAboutMissingStyles("modal","icons","typography","a11y","button"),exports.Drawer=function(c){var d=c.children,u=c.className,g=c.closeLabel,p=void 0===g?"Lukk skuff":g,v=c.contrast,f=void 0!==v&&v,b=c.open,E=void 0===b||b,h=c.onDismiss,_=c.title,O=c.style,k=c.overlay,w=void 0!==k&&k,N=e.useRandomId("eds-drawer");return E?n.createElement(y,{condition:w,wrapper:function(e){return n.createElement(m,{open:E,onDismiss:h},e)}},n.createElement(f?s.Contrast:n.Fragment,null,n.createElement(w?l.DialogContent:"div",{"aria-labelledby":N,className:i("eds-drawer",u),onKeyDown:function(e){"Escape"===e.key&&(e.stopPropagation(),h())},style:O},n.createElement(o.MoveFocusInside,null,n.createElement(t.IconButton,{className:"eds-drawer__close-button",onClick:h,type:"button","aria-label":p},n.createElement(a.CloseIcon,{"aria-hidden":!0})),n.createElement("div",{className:"eds-drawer__content"},n.createElement(r.Heading3,{as:"h2",id:N},_),d))))):null},exports.Modal=function(i){var l,o=i.children,s=i.closeLabel,u=void 0===s?"Lukk":s,g=i.initialFocusRef,y=i.open,b=i.onDismiss,E=i.size,h=i.align,_=void 0===h?"start":h,O=i.title,k=i.closeOnClickOutside,w=void 0===k||k,N=d(i,f),x=e.useRandomId("eds-modal"),C=p[E]||r.Heading2,D=["medium","large","extraLarge"].includes(E);return b&&w&&(l=b),n.createElement(m,{open:y,onDismiss:l,initialFocusRef:g},n.createElement(v,c({size:E,align:_},N),D&&n.createElement(t.IconButton,{className:"eds-modal__close","aria-label":u,onClick:b,type:"button"},n.createElement(a.CloseIcon,null)),O&&n.createElement(C,{margin:"bottom",as:"h2",id:x},O),o))},exports.ModalContent=v,exports.ModalOverlay=m,exports.headingsMap=p;
2
- //# sourceMappingURL=modal.cjs.production.min.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"modal.cjs.production.min.js","sources":["../src/ModalOverlay.tsx","../src/ModalContent.tsx","../src/Drawer.tsx","../src/index.tsx","../src/Modal.tsx"],"sourcesContent":["import React from 'react';\nimport classNames from 'classnames';\nimport { DialogOverlay } from '@reach/dialog';\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 [key: string]: any;\n};\n\nexport const ModalOverlay: React.FC<ModalOverlayProps> = ({\n className,\n open,\n ...rest\n}) => (\n <DialogOverlay\n className={classNames('eds-modal__overlay', className)}\n isOpen={open}\n {...rest}\n />\n);\n","import React from 'react';\nimport classNames from 'classnames';\nimport { DialogContent } from '@reach/dialog';\nimport { Heading4, Heading3, Heading2 } from '@entur/typography';\nimport { useRandomId } from '@entur/utils';\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 [key: string]: any;\n};\n\nexport const headingsMap = {\n extraSmall: Heading4,\n small: Heading3,\n medium: Heading2,\n large: Heading2,\n extraLarge: Heading2,\n};\n\nexport const ModalContent: React.FC<ModalContentProps> = ({\n children,\n className,\n size,\n title,\n align = 'start',\n ...rest\n}) => {\n const Heading: React.ElementType = headingsMap[size] || Heading2;\n const randomId = useRandomId('eds-modal');\n return (\n <DialogContent\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={randomId}\n {...rest}\n >\n {title && (\n <Heading margin=\"bottom\" as=\"h2\" id={randomId}>\n {title}\n </Heading>\n )}\n {children}\n </DialogContent>\n );\n};\n","import React from 'react';\nimport classNames from 'classnames';\nimport { MoveFocusInside } from 'react-focus-lock';\nimport { Contrast } from '@entur/layout';\nimport { CloseIcon } from '@entur/icons';\nimport { Heading3 } from '@entur/typography';\nimport { useRandomId } from '@entur/utils';\nimport { IconButton } from '@entur/button';\n\nimport './Drawer.scss';\nimport { ModalOverlay } from './ModalOverlay';\nimport { DialogContent } from '@reach/dialog';\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: React.FC<DrawerProps> = ({\n children,\n className,\n closeLabel = 'Lukk skuff',\n contrast = false,\n open = true,\n onDismiss,\n title,\n style,\n overlay = false,\n}) => {\n const titleId = useRandomId('eds-drawer');\n\n if (!open) {\n return null;\n }\n\n const handleKeyDown = (e: React.KeyboardEvent) => {\n if (e.key === 'Escape') {\n e.stopPropagation();\n onDismiss();\n }\n };\n\n const Wrapper = contrast ? Contrast : React.Fragment;\n const ContentContainer = overlay ? DialogContent : 'div';\n return (\n <ConditionalWrapper\n condition={overlay}\n wrapper={(children: React.ReactNode) => (\n <ModalOverlay open={open} onDismiss={onDismiss}>\n {children}\n </ModalOverlay>\n )}\n >\n <Wrapper>\n <ContentContainer\n aria-labelledby={titleId}\n className={classNames('eds-drawer', className)}\n onKeyDown={handleKeyDown}\n style={style}\n >\n <MoveFocusInside>\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}>\n {title}\n </Heading3>\n {children}\n </div>\n </MoveFocusInside>\n </ContentContainer>\n </Wrapper>\n </ConditionalWrapper>\n );\n};\n\nconst ConditionalWrapper: React.FC<{\n condition: boolean;\n wrapper: (child: JSX.Element) => JSX.Element;\n children: React.ReactElement;\n}> = ({ condition, wrapper, children }) =>\n condition ? wrapper(children) : children;\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","import React from 'react';\n\nimport { CloseIcon } from '@entur/icons';\nimport { IconButton } from '@entur/button';\nimport { Heading2 } from '@entur/typography';\nimport { useRandomId } from '@entur/utils';\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 lukkeknappen */\n initialFocusRef?: React.RefObject<HTMLElement>;\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 /** 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 /** Om modalen skal lukkes når man klikker på utsiden av den\n * @default true\n */\n closeOnClickOutside?: boolean;\n [key: string]: any;\n};\n\nexport const Modal: React.FC<ModalProps> = ({\n children,\n closeLabel = 'Lukk',\n initialFocusRef,\n open,\n onDismiss,\n size,\n align = 'start',\n title,\n closeOnClickOutside = true,\n ...rest\n}) => {\n const randomId = useRandomId('eds-modal');\n const Heading: React.ElementType = headingsMap[size] || Heading2;\n const showCloseButton = ['medium', 'large', 'extraLarge'].includes(size);\n\n let handleOnDismiss;\n if (onDismiss && closeOnClickOutside) {\n handleOnDismiss = onDismiss;\n }\n return (\n <ModalOverlay\n open={open}\n onDismiss={handleOnDismiss}\n initialFocusRef={initialFocusRef}\n >\n <ModalContent size={size} align={align} {...rest}>\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 {title && (\n <Heading margin=\"bottom\" as=\"h2\" id={randomId}>\n {title}\n </Heading>\n )}\n {children}\n </ModalContent>\n </ModalOverlay>\n );\n};\n"],"names":["ModalOverlay","_ref","className","open","rest","_objectWithoutPropertiesLoose","_excluded","React","createElement","DialogOverlay","_extends","classNames","isOpen","headingsMap","extraSmall","Heading4","small","Heading3","medium","Heading2","large","extraLarge","ModalContent","children","size","title","_ref$align","align","Heading","randomId","useRandomId","DialogContent","margin","as","id","ConditionalWrapper","_ref2","condition","wrapper","warnAboutMissingStyles","_ref$closeLabel","closeLabel","_ref$contrast","contrast","_ref$open","onDismiss","style","_ref$overlay","overlay","titleId","Contrast","Fragment","onKeyDown","e","key","stopPropagation","MoveFocusInside","IconButton","onClick","type","CloseIcon","handleOnDismiss","initialFocusRef","_ref$closeOnClickOuts","closeOnClickOutside","showCloseButton","includes"],"mappings":"qrBAkBaA,EAA4C,SAAhCC,GAAA,IACvBC,EAASD,EAATC,UACAC,EAAIF,EAAJE,KACGC,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