@helsenorge/designsystem-react 8.0.2 → 8.1.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/CHANGELOG.md +29 -0
- package/components/Close/styles.module.scss +5 -6
- package/components/ExpanderList/styles.module.scss +5 -6
- package/components/EyebrowHeader/styles.module.scss +1 -1
- package/components/EyebrowHeader/styles.module.scss.d.ts +9 -0
- package/components/FormGroup/styles.module.scss +2 -2
- package/components/HighlightPanel/styles.module.scss +5 -0
- package/components/HorizontalScroll/HorizontalScroll.js +16 -15
- package/components/HorizontalScroll/HorizontalScroll.js.map +1 -1
- package/components/Input/Input.d.ts +2 -0
- package/components/Input/Input.js +63 -51
- package/components/Input/Input.js.map +1 -1
- package/components/Input/styles.module.scss +2 -2
- package/components/Loader/Loader.d.ts +3 -3
- package/components/Loader/Loader.js +19 -20
- package/components/Loader/Loader.js.map +1 -1
- package/components/Loader/styles.module.scss +7 -7
- package/components/Modal/Modal.d.ts +1 -12
- package/components/Modal/Modal.js +81 -78
- package/components/Modal/Modal.js.map +1 -1
- package/components/Modal/styles.module.scss +3 -3
- package/components/Panel/styles.module.scss +2 -2
- package/components/PopOver/styles.module.scss +4 -5
- package/components/Table/styles.module.scss +3 -3
- package/components/Tabs/TabList/TabItem.d.ts +13 -0
- package/components/Tabs/TabList/TabItem.js +45 -0
- package/components/Tabs/TabList/TabItem.js.map +1 -0
- package/components/Tabs/TabList/TabList.js +23 -50
- package/components/Tabs/TabList/TabList.js.map +1 -1
- package/components/Tabs/Tabs.d.ts +3 -0
- package/components/Tabs/Tabs.js +45 -39
- package/components/Tabs/Tabs.js.map +1 -1
- package/components/Validation/ValidationSummary.js +20 -12
- package/components/Validation/ValidationSummary.js.map +1 -1
- package/hooks/usestopPropagation.d.ts +6 -0
- package/hooks/usestopPropagation.js +15 -0
- package/hooks/usestopPropagation.js.map +1 -0
- package/package.json +1 -1
- package/utils/refs.d.ts +1 -1
- package/utils/refs.js +5 -5
- package/utils/refs.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
1
|
+
## [8.1.0](https://github.com/helsenorge/designsystem/branchCompare?baseVersion=GTv8.0.2&targetVersion=GTv8.1.0) (2024-08-23)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
- mulig å skru av swiping i tabs ([45aac8f](https://github.com/helsenorge/designsystem/commit/45aac8f7358e77fe85467d826b54c052b01b3086)),
|
|
6
|
+
closes [#330586](https://github.com/helsenorge/designsystem/issues/330586)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- table kan brukes i tabs uten problemer med scrolling på mobil
|
|
11
|
+
([d28a280](https://github.com/helsenorge/designsystem/commit/d28a280d4afe56227a331334348d91aac5be6281)), closes
|
|
12
|
+
[#330555](https://github.com/helsenorge/designsystem/issues/330555)
|
|
13
|
+
- unngå blinking i tabs på mobil når man scroller
|
|
14
|
+
([2bddf20](https://github.com/helsenorge/designsystem/commit/2bddf2017f1067ba1b17473006b2103de630054e)), closes
|
|
15
|
+
[#330597](https://github.com/helsenorge/designsystem/issues/330597)
|
|
16
|
+
- validationsummary er ikke labelled by ikke-eksisterende element
|
|
17
|
+
([3ac0b88](https://github.com/helsenorge/designsystem/commit/3ac0b8822820ad47ac635da95b7d7377481f2f33)), closes
|
|
18
|
+
[#328895](https://github.com/helsenorge/designsystem/issues/328895)
|
|
19
|
+
|
|
20
|
+
## [8.0.2](https://github.com/helsenorge/designsystem/branchCompare?baseVersion=GTv8.0.1&targetVersion=GTv8.0.2) (2024-08-22)
|
|
21
|
+
|
|
22
|
+
### Bug Fixes
|
|
23
|
+
|
|
24
|
+
- lightbox uu forbedringer ([8026ee9](https://github.com/helsenorge/designsystem/commit/8026ee9fc1acb94cd1b9e9d12ff1a190beca31d3)), closes
|
|
25
|
+
[#329075](https://github.com/helsenorge/designsystem/issues/329075)
|
|
26
|
+
- radiobutton-scss bygger når designsystem tas i bruk
|
|
27
|
+
([867b0ec](https://github.com/helsenorge/designsystem/commit/867b0ec36002ed16fda4f7e6dae07bad4b805c46)), closes
|
|
28
|
+
[#330427](https://github.com/helsenorge/designsystem/issues/330427)
|
|
29
|
+
|
|
1
30
|
## [8.0.1](https://github.com/helsenorge/designsystem/branchCompare?baseVersion=GTv8.0.0&targetVersion=GTv8.0.1) (2024-08-15)
|
|
2
31
|
|
|
3
32
|
## 8.0.0-beta.6 (2024-08-15)
|
|
@@ -7,12 +7,6 @@
|
|
|
7
7
|
display: flex;
|
|
8
8
|
align-items: center;
|
|
9
9
|
justify-content: center;
|
|
10
|
-
|
|
11
|
-
@media (max-width: map.get($grid-breakpoints, sm)) {
|
|
12
|
-
height: 2.375rem;
|
|
13
|
-
width: 2.375rem;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
10
|
height: 3rem;
|
|
17
11
|
width: 3rem;
|
|
18
12
|
padding: 0;
|
|
@@ -20,6 +14,11 @@
|
|
|
20
14
|
background-color: transparent;
|
|
21
15
|
cursor: pointer;
|
|
22
16
|
|
|
17
|
+
@media (max-width: map.get($grid-breakpoints, sm)) {
|
|
18
|
+
height: 2.375rem;
|
|
19
|
+
width: 2.375rem;
|
|
20
|
+
}
|
|
21
|
+
|
|
23
22
|
&:hover,
|
|
24
23
|
&:active {
|
|
25
24
|
background-color: rgb(88 170 187 / 10%);
|
|
@@ -39,12 +39,6 @@
|
|
|
39
39
|
position: relative;
|
|
40
40
|
font-size: $font-size-sm;
|
|
41
41
|
line-height: $lineheight-size-sm;
|
|
42
|
-
|
|
43
|
-
@media (min-width: map.get($grid-breakpoints, md)) {
|
|
44
|
-
font-size: $font-size-md;
|
|
45
|
-
line-height: $lineheight-size-md;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
42
|
display: flex;
|
|
49
43
|
cursor: pointer;
|
|
50
44
|
font-weight: 600;
|
|
@@ -58,6 +52,11 @@
|
|
|
58
52
|
width: 100%;
|
|
59
53
|
outline: none;
|
|
60
54
|
|
|
55
|
+
@media (min-width: map.get($grid-breakpoints, md)) {
|
|
56
|
+
font-size: $font-size-md;
|
|
57
|
+
line-height: $lineheight-size-md;
|
|
58
|
+
}
|
|
59
|
+
|
|
61
60
|
&--banana {
|
|
62
61
|
background-color: $banana100;
|
|
63
62
|
}
|
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
@mixin content-wrapper-with-icon-flex {
|
|
9
9
|
display: flex;
|
|
10
10
|
flex-direction: column;
|
|
11
|
+
}
|
|
11
12
|
|
|
13
|
+
@mixin content-wrapper-with-icon-flex-responsive {
|
|
12
14
|
@media (min-width: map.get($grid-breakpoints, md)) {
|
|
13
15
|
flex-direction: row;
|
|
14
16
|
}
|
|
@@ -113,6 +115,7 @@
|
|
|
113
115
|
#{$panel}__content-wrapper {
|
|
114
116
|
@include content-wrapper-with-icon-flex;
|
|
115
117
|
@include content-wrapper-with-icon-padding;
|
|
118
|
+
@include content-wrapper-with-icon-flex-responsive;
|
|
116
119
|
|
|
117
120
|
@media (min-width: map.get($grid-breakpoints, lg)) {
|
|
118
121
|
padding-left: getSpacer(m);
|
|
@@ -123,6 +126,7 @@
|
|
|
123
126
|
&--has-icon#{&}--large {
|
|
124
127
|
#{$panel}__col {
|
|
125
128
|
@include content-wrapper-with-icon-flex;
|
|
129
|
+
@include content-wrapper-with-icon-flex-responsive;
|
|
126
130
|
}
|
|
127
131
|
#{$panel}__content-wrapper {
|
|
128
132
|
@include content-wrapper-with-icon-padding;
|
|
@@ -171,6 +175,7 @@
|
|
|
171
175
|
&--has-icon#{&}--fluid {
|
|
172
176
|
@include content-wrapper-with-icon-flex;
|
|
173
177
|
@include content-wrapper-with-icon-padding;
|
|
178
|
+
@include content-wrapper-with-icon-flex-responsive;
|
|
174
179
|
}
|
|
175
180
|
|
|
176
181
|
&__icon {
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import r, { useRef as e } from "react";
|
|
2
2
|
import i from "classnames";
|
|
3
3
|
import { useIsVisible as c } from "../../hooks/useIsVisible.js";
|
|
4
|
-
import { useSize as
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
import { useSize as p } from "../../hooks/useSize.js";
|
|
5
|
+
import { useStopPropagation as g } from "../../hooks/usestopPropagation.js";
|
|
6
|
+
import t from "../HorizontalScroll/styles.module.scss";
|
|
7
|
+
const m = "3px", x = ({ children: d, childWidth: _, testId: h, ...l }) => {
|
|
8
|
+
const o = e(null), a = e(null), s = e(null), u = c(a, 1, { root: o == null ? void 0 : o.current, rootMargin: m }, !0), f = c(s, 1, { root: o == null ? void 0 : o.current, rootMargin: m }, !0), { width: v = 0 } = p(o) || {}, z = _ > v, b = i(t.horizontalscroll__viewport, z && t["horizontalscroll__viewport--overflow"]), n = l["aria-label"] || l["aria-labelledby"];
|
|
9
|
+
return g(o, ["touchstart", "touchmove"]), /* @__PURE__ */ r.createElement("div", { className: t.horizontalscroll, "data-testid": h }, /* @__PURE__ */ r.createElement(
|
|
9
10
|
"div",
|
|
10
11
|
{
|
|
11
12
|
className: b,
|
|
12
|
-
ref:
|
|
13
|
+
ref: o,
|
|
13
14
|
tabIndex: n ? 0 : void 0,
|
|
14
15
|
role: n ? "region" : void 0,
|
|
15
16
|
...l
|
|
@@ -18,9 +19,9 @@ const d = "3px", O = ({ children: m, childWidth: _, testId: f, ...l }) => {
|
|
|
18
19
|
"div",
|
|
19
20
|
{
|
|
20
21
|
className: i(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
!
|
|
22
|
+
t.horizontalscroll__indicator,
|
|
23
|
+
t["horizontalscroll__indicator--left"],
|
|
24
|
+
!u && t["horizontalscroll__indicator--visible"]
|
|
24
25
|
)
|
|
25
26
|
}
|
|
26
27
|
),
|
|
@@ -28,19 +29,19 @@ const d = "3px", O = ({ children: m, childWidth: _, testId: f, ...l }) => {
|
|
|
28
29
|
"div",
|
|
29
30
|
{
|
|
30
31
|
className: i(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
!
|
|
32
|
+
t.horizontalscroll__indicator,
|
|
33
|
+
t["horizontalscroll__indicator--right"],
|
|
34
|
+
!f && t["horizontalscroll__indicator--visible"]
|
|
34
35
|
)
|
|
35
36
|
}
|
|
36
37
|
),
|
|
37
38
|
/* @__PURE__ */ r.createElement("div", { ref: a }),
|
|
38
|
-
|
|
39
|
+
d,
|
|
39
40
|
/* @__PURE__ */ r.createElement("div", { ref: s })
|
|
40
41
|
));
|
|
41
42
|
};
|
|
42
43
|
export {
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
x as HorizontalScroll,
|
|
45
|
+
x as default
|
|
45
46
|
};
|
|
46
47
|
//# sourceMappingURL=HorizontalScroll.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HorizontalScroll.js","sources":["../../../src/components/HorizontalScroll/HorizontalScroll.tsx"],"sourcesContent":["import React, { useRef } from 'react';\n\nimport classNames from 'classnames';\n\nimport { useIsVisible } from '../../hooks/useIsVisible';\nimport { useSize } from '../../hooks/useSize';\nimport { AriaLabelAttributes } from '../../utils/accessibility';\n\nimport styles from './styles.module.scss';\n\n// Scrolle-indikator vises/skjules når det er x px igjen til venstre eller høyre side\nconst ROOT_MARGIN_OFFSET = '3px';\n\ninterface HorizontalScrollProps {\n children?: React.ReactNode;\n /**\n * Bredden på elementet som potensielt vil scrolle horisontalt i px\n */\n childWidth: number;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nexport const HorizontalScroll: React.FC<HorizontalScrollProps & AriaLabelAttributes> = ({ children, childWidth, testId, ...rest }) => {\n const viewportRef = useRef<HTMLDivElement>(null);\n const leftRef = useRef<HTMLDivElement>(null);\n const rightRef = useRef<HTMLDivElement>(null);\n const leftIsVisible = useIsVisible(leftRef, 1, { root: viewportRef?.current, rootMargin: ROOT_MARGIN_OFFSET }, true);\n const rightIsVisible = useIsVisible(rightRef, 1, { root: viewportRef?.current, rootMargin: ROOT_MARGIN_OFFSET }, true);\n const { width: viewPortWidth = 0 } = useSize(viewportRef) || {};\n\n const isOverflowing = childWidth > viewPortWidth;\n const viewportClasses = classNames(styles.horizontalscroll__viewport, isOverflowing && styles['horizontalscroll__viewport--overflow']);\n const hasAriaAttributes = rest['aria-label'] || rest['aria-labelledby'];\n\n return (\n <div className={styles.horizontalscroll} data-testid={testId}>\n {/* viewport-diven må ta tabIndex for å løse et annet UU-problem, at div med overflow: scroll må kunne navigeres med keyboard. */}\n {/* Enten aria-label eller aria-labelledbyid må settes */}\n <div\n className={viewportClasses}\n ref={viewportRef}\n tabIndex={hasAriaAttributes ? 0 : undefined}\n role={hasAriaAttributes ? 'region' : undefined}\n {...rest}\n >\n <div\n className={classNames(\n styles.horizontalscroll__indicator,\n styles['horizontalscroll__indicator--left'],\n !leftIsVisible && styles['horizontalscroll__indicator--visible']\n )}\n />\n <div\n className={classNames(\n styles.horizontalscroll__indicator,\n styles['horizontalscroll__indicator--right'],\n !rightIsVisible && styles['horizontalscroll__indicator--visible']\n )}\n />\n <div ref={leftRef} />\n {children}\n <div ref={rightRef} />\n </div>\n </div>\n );\n};\n\nexport default HorizontalScroll;\n"],"names":["ROOT_MARGIN_OFFSET","HorizontalScroll","children","childWidth","testId","rest","viewportRef","useRef","leftRef","rightRef","leftIsVisible","useIsVisible","rightIsVisible","viewPortWidth","useSize","isOverflowing","viewportClasses","classNames","styles","hasAriaAttributes","React"],"mappings":"
|
|
1
|
+
{"version":3,"file":"HorizontalScroll.js","sources":["../../../src/components/HorizontalScroll/HorizontalScroll.tsx"],"sourcesContent":["import React, { useRef } from 'react';\n\nimport classNames from 'classnames';\n\nimport { useIsVisible } from '../../hooks/useIsVisible';\nimport { useSize } from '../../hooks/useSize';\nimport { useStopPropagation } from '../../hooks/usestopPropagation';\nimport { AriaLabelAttributes } from '../../utils/accessibility';\n\nimport styles from './styles.module.scss';\n\n// Scrolle-indikator vises/skjules når det er x px igjen til venstre eller høyre side\nconst ROOT_MARGIN_OFFSET = '3px';\n\ninterface HorizontalScrollProps {\n children?: React.ReactNode;\n /**\n * Bredden på elementet som potensielt vil scrolle horisontalt i px\n */\n childWidth: number;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nexport const HorizontalScroll: React.FC<HorizontalScrollProps & AriaLabelAttributes> = ({ children, childWidth, testId, ...rest }) => {\n const viewportRef = useRef<HTMLDivElement>(null);\n const leftRef = useRef<HTMLDivElement>(null);\n const rightRef = useRef<HTMLDivElement>(null);\n const leftIsVisible = useIsVisible(leftRef, 1, { root: viewportRef?.current, rootMargin: ROOT_MARGIN_OFFSET }, true);\n const rightIsVisible = useIsVisible(rightRef, 1, { root: viewportRef?.current, rootMargin: ROOT_MARGIN_OFFSET }, true);\n const { width: viewPortWidth = 0 } = useSize(viewportRef) || {};\n\n const isOverflowing = childWidth > viewPortWidth;\n const viewportClasses = classNames(styles.horizontalscroll__viewport, isOverflowing && styles['horizontalscroll__viewport--overflow']);\n const hasAriaAttributes = rest['aria-label'] || rest['aria-labelledby'];\n\n useStopPropagation(viewportRef, ['touchstart', 'touchmove']);\n\n return (\n <div className={styles.horizontalscroll} data-testid={testId}>\n {/* viewport-diven må ta tabIndex for å løse et annet UU-problem, at div med overflow: scroll må kunne navigeres med keyboard. */}\n {/* Enten aria-label eller aria-labelledbyid må settes */}\n <div\n className={viewportClasses}\n ref={viewportRef}\n tabIndex={hasAriaAttributes ? 0 : undefined}\n role={hasAriaAttributes ? 'region' : undefined}\n {...rest}\n >\n <div\n className={classNames(\n styles.horizontalscroll__indicator,\n styles['horizontalscroll__indicator--left'],\n !leftIsVisible && styles['horizontalscroll__indicator--visible']\n )}\n />\n <div\n className={classNames(\n styles.horizontalscroll__indicator,\n styles['horizontalscroll__indicator--right'],\n !rightIsVisible && styles['horizontalscroll__indicator--visible']\n )}\n />\n <div ref={leftRef} />\n {children}\n <div ref={rightRef} />\n </div>\n </div>\n );\n};\n\nexport default HorizontalScroll;\n"],"names":["ROOT_MARGIN_OFFSET","HorizontalScroll","children","childWidth","testId","rest","viewportRef","useRef","leftRef","rightRef","leftIsVisible","useIsVisible","rightIsVisible","viewPortWidth","useSize","isOverflowing","viewportClasses","classNames","styles","hasAriaAttributes","useStopPropagation","React"],"mappings":";;;;;;AAYA,MAAMA,IAAqB,OAYdC,IAA0E,CAAC,EAAE,UAAAC,GAAU,YAAAC,GAAY,QAAAC,GAAQ,GAAGC,QAAW;AAC9H,QAAAC,IAAcC,EAAuB,IAAI,GACzCC,IAAUD,EAAuB,IAAI,GACrCE,IAAWF,EAAuB,IAAI,GACtCG,IAAgBC,EAAaH,GAAS,GAAG,EAAE,MAAMF,KAAA,gBAAAA,EAAa,SAAS,YAAYN,EAAmB,GAAG,EAAI,GAC7GY,IAAiBD,EAAaF,GAAU,GAAG,EAAE,MAAMH,KAAA,gBAAAA,EAAa,SAAS,YAAYN,EAAmB,GAAG,EAAI,GAC/G,EAAE,OAAOa,IAAgB,MAAMC,EAAQR,CAAW,KAAK,IAEvDS,IAAgBZ,IAAaU,GAC7BG,IAAkBC,EAAWC,EAAO,4BAA4BH,KAAiBG,EAAO,sCAAsC,CAAC,GAC/HC,IAAoBd,EAAK,YAAY,KAAKA,EAAK,iBAAiB;AAEtE,SAAAe,EAAmBd,GAAa,CAAC,cAAc,WAAW,CAAC,mCAGxD,OAAI,EAAA,WAAWY,EAAO,kBAAkB,eAAad,EAGpD,GAAAiB,gBAAAA,EAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,WAAWL;AAAA,MACX,KAAKV;AAAA,MACL,UAAUa,IAAoB,IAAI;AAAA,MAClC,MAAMA,IAAoB,WAAW;AAAA,MACpC,GAAGd;AAAA,IAAA;AAAA,IAEJgB,gBAAAA,EAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,WAAWJ;AAAA,UACTC,EAAO;AAAA,UACPA,EAAO,mCAAmC;AAAA,UAC1C,CAACR,KAAiBQ,EAAO,sCAAsC;AAAA,QACjE;AAAA,MAAA;AAAA,IACF;AAAA,IACAG,gBAAAA,EAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,WAAWJ;AAAA,UACTC,EAAO;AAAA,UACPA,EAAO,oCAAoC;AAAA,UAC3C,CAACN,KAAkBM,EAAO,sCAAsC;AAAA,QAClE;AAAA,MAAA;AAAA,IACF;AAAA,IACAG,gBAAAA,EAAA,cAAC,OAAI,EAAA,KAAKb,EAAS,CAAA;AAAA,IAClBN;AAAA,IACDmB,gBAAAA,EAAA,cAAC,OAAI,EAAA,KAAKZ,EAAU,CAAA;AAAA,EAAA,CAExB;AAEJ;"}
|
|
@@ -19,6 +19,8 @@ export interface InputProps extends Pick<React.InputHTMLAttributes<HTMLInputElem
|
|
|
19
19
|
icon?: SvgIcon | IconName;
|
|
20
20
|
/** Places the icon to the right */
|
|
21
21
|
iconRight?: boolean;
|
|
22
|
+
/** Ref that is placed on the inputContainerRef */
|
|
23
|
+
inputContainerRef?: React.RefObject<HTMLDivElement>;
|
|
22
24
|
/** Ref that is placed on the inputWrapper */
|
|
23
25
|
inputWrapperRef?: React.RefObject<HTMLDivElement>;
|
|
24
26
|
/** Changes the color profile of the input */
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import r, { useRef as K, useState as $, useEffect as
|
|
1
|
+
import r, { useRef as K, useState as $, useEffect as Ce } from "react";
|
|
2
2
|
import v from "classnames";
|
|
3
|
-
import { FormMode as l, FormSize as
|
|
3
|
+
import { FormMode as l, FormSize as xe, IconSize as B, AnalyticsId as _e, AVERAGE_CHARACTER_WIDTH_PX as ve } from "../../constants.js";
|
|
4
4
|
import { useBreakpoint as ye, Breakpoint as Ee } from "../../hooks/useBreakpoint.js";
|
|
5
5
|
import { useUuid as U } from "../../hooks/useUuid.js";
|
|
6
6
|
import { getColor as F } from "../../theme/currys/color.js";
|
|
7
7
|
import { getAriaDescribedBy as ke } from "../../utils/accessibility.js";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import We from "../
|
|
8
|
+
import { mergeRefs as we } from "../../utils/refs.js";
|
|
9
|
+
import { ErrorWrapper as Ne } from "../ErrorWrapper/ErrorWrapper.js";
|
|
10
|
+
import { Icon as Ie } from "../Icon/Icon.js";
|
|
11
|
+
import { renderLabel as Re } from "../Label/Label.js";
|
|
12
|
+
import { LazyIcon as We } from "../LazyIcon/LazyIcon.js";
|
|
13
|
+
import Se from "../MaxCharacters/MaxCharacters.js";
|
|
13
14
|
import t from "../Input/styles.module.scss";
|
|
14
|
-
var
|
|
15
|
-
const
|
|
15
|
+
var ze = /* @__PURE__ */ ((e) => (e.text = "text", e.number = "number", e.email = "email", e.password = "password", e.search = "search", e.tel = "tel", e.url = "url", e.date = "date", e.time = "time", e))(ze || {});
|
|
16
|
+
const Ae = (e, s, p) => {
|
|
16
17
|
const i = s ? "1.5rem" : "2rem", f = s ? `${p}px` : "0px";
|
|
17
18
|
return `calc(${e * ve}px + ${i} + ${f} + 4px)`;
|
|
18
|
-
},
|
|
19
|
+
}, Ve = r.forwardRef((e, s) => {
|
|
19
20
|
const {
|
|
20
21
|
className: p,
|
|
21
22
|
defaultValue: i,
|
|
@@ -24,7 +25,7 @@ const ze = (e, s, p) => {
|
|
|
24
25
|
name: L,
|
|
25
26
|
transparent: M = !1,
|
|
26
27
|
icon: a,
|
|
27
|
-
iconRight:
|
|
28
|
+
iconRight: g,
|
|
28
29
|
inputId: P,
|
|
29
30
|
inputWrapperRef: H,
|
|
30
31
|
mode: c = l.onwhite,
|
|
@@ -48,27 +49,27 @@ const ze = (e, s, p) => {
|
|
|
48
49
|
maxCharacters: d,
|
|
49
50
|
maxText: te,
|
|
50
51
|
...ne
|
|
51
|
-
} = e, re = ye(), m = K(null), I = U(P), [R, W] = $(i || ""), [ae, oe] = $(void 0),
|
|
52
|
-
|
|
52
|
+
} = e, re = ye(), m = K(null), I = U(P), [R, W] = $(i || ""), [ae, oe] = $(void 0), b = K(!1), S = U(G), z = /^[0-9]$/;
|
|
53
|
+
Ce(() => {
|
|
53
54
|
W(i || "");
|
|
54
55
|
}, [i]);
|
|
55
|
-
const ie = c === l.ondark, ce = c === l.onblueberry, le = !!d && R.toString().length > d,
|
|
56
|
+
const ie = c === l.ondark, ce = c === l.onblueberry, le = !!d && R.toString().length > d, C = c === l.oninvalid || !!E || !!q || le, x = O === xe.large, se = M && c !== l.ondark && !C, ue = v(t["input-wrapper"], p), de = v(t["input-container"], {
|
|
56
57
|
[t["input-container--transparent"]]: se,
|
|
57
58
|
[t["input-container--on-blueberry"]]: ce,
|
|
58
59
|
[t["input-container--on-dark"]]: ie,
|
|
59
|
-
[t["input-container--invalid"]]:
|
|
60
|
-
[t["input-container--large"]]:
|
|
60
|
+
[t["input-container--invalid"]]: C,
|
|
61
|
+
[t["input-container--large"]]: x,
|
|
61
62
|
[t["input-container--disabled"]]: u,
|
|
62
63
|
[t["input-container--with-icon"]]: a
|
|
63
64
|
}), me = v(t["input-container__input"], {
|
|
64
|
-
[t["input-container__input--large"]]:
|
|
65
|
+
[t["input-container__input--large"]]: x,
|
|
65
66
|
[t["input-container__input--disabled"]]: u
|
|
66
|
-
}), A = u ? F("neutral", 700) : F("black"), _ = re === Ee.xs || !
|
|
67
|
+
}), A = u ? F("neutral", 700) : F("black"), _ = re === Ee.xs || !x ? B.XSmall : B.Small, V = () => {
|
|
67
68
|
if (a)
|
|
68
|
-
return typeof a == "string" ? /* @__PURE__ */ r.createElement(
|
|
69
|
+
return typeof a == "string" ? /* @__PURE__ */ r.createElement(We, { className: t["input-container__input__icon"], color: A, size: _, iconName: a }) : /* @__PURE__ */ r.createElement(Ie, { className: t["input-container__input__icon"], color: A, size: _, svgIcon: a });
|
|
69
70
|
}, pe = (n) => {
|
|
70
71
|
if (m && m.current && a) {
|
|
71
|
-
const o =
|
|
72
|
+
const o = g ? 0 : 1;
|
|
72
73
|
m.current.children[o].focus(), e.onClick && e.onClick(n);
|
|
73
74
|
}
|
|
74
75
|
}, fe = (n) => {
|
|
@@ -77,40 +78,51 @@ const ze = (e, s, p) => {
|
|
|
77
78
|
}, he = (n) => {
|
|
78
79
|
if (typeof y > "u" || h !== "number") return n.target.value;
|
|
79
80
|
const o = Number(n.target.value);
|
|
80
|
-
return !ae && !
|
|
81
|
-
}, be = (n) => {
|
|
82
|
-
z.test(n.key) && (g.current = !0), N && N(n);
|
|
81
|
+
return !ae && !b.current && (o === 1 || o === -1) && (n.target.value = y + ""), n.target.value;
|
|
83
82
|
}, ge = (n) => {
|
|
84
|
-
z.test(n.key) && (
|
|
85
|
-
},
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
z.test(n.key) && (b.current = !0), N && N(n);
|
|
84
|
+
}, be = (n) => {
|
|
85
|
+
z.test(n.key) && (b.current = !1);
|
|
86
|
+
}, D = k ? Ae(k, !!a, _) : void 0;
|
|
87
|
+
return /* @__PURE__ */ r.createElement(Ne, { errorText: E, errorTextId: S }, /* @__PURE__ */ r.createElement("div", { "data-testid": j, "data-analyticsid": _e.Input, className: ue, ref: H }, Re(X, I, c), /* @__PURE__ */ r.createElement("div", { className: t["content-wrapper"] }, /* @__PURE__ */ r.createElement(
|
|
88
|
+
"div",
|
|
88
89
|
{
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
90
|
+
onClick: pe,
|
|
91
|
+
ref: we([m, e.inputContainerRef]),
|
|
92
|
+
className: de,
|
|
93
|
+
style: { maxWidth: D }
|
|
94
|
+
},
|
|
95
|
+
!g && V(),
|
|
96
|
+
/* @__PURE__ */ r.createElement(
|
|
97
|
+
"input",
|
|
98
|
+
{
|
|
99
|
+
onChange: fe,
|
|
100
|
+
onKeyDown: ge,
|
|
101
|
+
onKeyUp: be,
|
|
102
|
+
name: L,
|
|
103
|
+
type: h,
|
|
104
|
+
defaultValue: i,
|
|
105
|
+
id: I,
|
|
106
|
+
className: me,
|
|
107
|
+
ref: s,
|
|
108
|
+
"aria-labelledby": e["aria-labelledby"] ?? void 0,
|
|
109
|
+
"aria-describedby": ke(e, S),
|
|
110
|
+
"aria-invalid": !!C,
|
|
111
|
+
disabled: u,
|
|
112
|
+
placeholder: f,
|
|
113
|
+
readOnly: J,
|
|
114
|
+
autoComplete: Q || "off",
|
|
115
|
+
required: Z,
|
|
116
|
+
autoFocus: ee,
|
|
117
|
+
...ne
|
|
118
|
+
}
|
|
119
|
+
),
|
|
120
|
+
g && V()
|
|
121
|
+
), /* @__PURE__ */ r.createElement("div", { className: t["content-wrapper__right-of-input"] }, Y)), d && /* @__PURE__ */ r.createElement(Se, { maxCharacters: d, length: R.toString().length, maxText: te, mode: c, maxWidth: D }), T));
|
|
110
122
|
});
|
|
111
|
-
|
|
123
|
+
Ve.displayName = "Input";
|
|
112
124
|
export {
|
|
113
|
-
|
|
114
|
-
|
|
125
|
+
ze as InputTypes,
|
|
126
|
+
Ve as default
|
|
115
127
|
};
|
|
116
128
|
//# sourceMappingURL=Input.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Input.js","sources":["../../../src/components/Input/Input.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react';\n\nimport cn from 'classnames';\n\nimport { FormMode, FormSize, AnalyticsId, AVERAGE_CHARACTER_WIDTH_PX } from '../../constants';\nimport { Breakpoint, useBreakpoint } from '../../hooks/useBreakpoint';\nimport { useUuid } from '../../hooks/useUuid';\nimport { getColor } from '../../theme/currys';\nimport { getAriaDescribedBy } from '../../utils/accessibility';\nimport ErrorWrapper from '../ErrorWrapper';\nimport Icon, { IconSize, SvgIcon } from '../Icon';\nimport { IconName } from '../Icons/IconNames';\nimport { renderLabel } from '../Label';\nimport LazyIcon from '../LazyIcon';\nimport MaxCharacters from '../MaxCharacters/MaxCharacters';\n\nimport styles from './styles.module.scss';\n\nexport interface InputProps\n extends Pick<\n React.InputHTMLAttributes<HTMLInputElement>,\n | 'disabled'\n | 'readOnly'\n | 'autoComplete'\n | 'name'\n | 'placeholder'\n | 'defaultValue'\n | 'required'\n | 'value'\n | 'min'\n | 'max'\n | 'aria-describedby'\n | 'aria-labelledby'\n | 'onBlur'\n | 'onClick'\n | 'onChange'\n | 'onFocus'\n | 'onKeyDown'\n | 'autoFocus'\n > {\n /** The number at which the input field starts when you increment or decrement it */\n baseIncrementValue?: number;\n /** Adds custom classes to the element. */\n className?: string;\n /** HMTL Input type */\n type?: keyof typeof InputTypes;\n /** input id */\n inputId?: string;\n /** Width of input field in characters (approximate) */\n width?: number;\n /** If true, the component will be transparent. */\n transparent?: boolean;\n /** Icon to be displayed next to the input field */\n icon?: SvgIcon | IconName;\n /** Places the icon to the right */\n iconRight?: boolean;\n /** Ref that is placed on the inputWrapper */\n inputWrapperRef?: React.RefObject<HTMLDivElement>;\n /** Changes the color profile of the input */\n mode?: keyof typeof FormMode;\n /** Changes the visuals of the input */\n size?: keyof typeof FormSize;\n /** Label of the input */\n label?: React.ReactNode;\n /** Activates Error style for the input */\n error?: boolean;\n /** Error text to show above the component */\n errorText?: string;\n /** Error text id */\n errorTextId?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Component shown after input */\n afterInputChildren?: React.ReactNode;\n /** Component shown to the right of input */\n rightOfInput?: React.ReactNode;\n /** max character limit in input */\n maxCharacters?: number;\n /** The text is displayed in the end of the text-counter */\n maxText?: string;\n}\n\nexport enum InputTypes {\n text = 'text',\n number = 'number',\n email = 'email',\n password = 'password',\n search = 'search',\n tel = 'tel',\n url = 'url',\n date = 'date',\n time = 'time',\n}\n\nconst getInputMaxWidth = (characters: number, hasIcon: boolean, iconSize: number): string => {\n const paddingWidth = hasIcon ? '1.5rem' : '2rem';\n const iconWidth = hasIcon ? `${iconSize}px` : '0px';\n const borderWidth = '4px';\n\n return `calc(${characters * AVERAGE_CHARACTER_WIDTH_PX}px + ${paddingWidth} + ${iconWidth} + ${borderWidth})`;\n};\n\nconst Input = React.forwardRef((props: InputProps, ref: React.Ref<HTMLInputElement>) => {\n const {\n className,\n defaultValue,\n placeholder,\n type = InputTypes.text,\n name,\n transparent = false,\n icon,\n iconRight,\n inputId,\n inputWrapperRef,\n mode = FormMode.onwhite,\n size,\n baseIncrementValue,\n label,\n error,\n errorText,\n errorTextId,\n testId,\n disabled,\n readOnly,\n autoComplete = 'off',\n afterInputChildren,\n rightOfInput,\n width,\n required,\n onChange,\n onKeyDown,\n autoFocus,\n maxCharacters,\n maxText,\n ...rest\n } = props;\n const breakpoint = useBreakpoint();\n const inputContainerRef = useRef<HTMLDivElement>(null);\n const inputIdState = useUuid(inputId);\n const [input, setInput] = useState(defaultValue || '');\n const [prevValue, setPrevValue] = useState<string | number | undefined>(undefined);\n const numKeyPressed = useRef<boolean>(false);\n const errorTextUuid = useUuid(errorTextId);\n const numRegex = /^[0-9]$/;\n\n useEffect(() => {\n setInput(defaultValue || '');\n }, [defaultValue]);\n\n const onDark = mode === FormMode.ondark;\n const onBlueberry = mode === FormMode.onblueberry;\n const maxCharactersExceeded = !!maxCharacters && input.toString().length > maxCharacters;\n const onError = mode === FormMode.oninvalid || !!errorText || !!error || maxCharactersExceeded;\n const isLarge = size === FormSize.large;\n const isTransparent = transparent && mode !== FormMode.ondark && !onError;\n\n const inputWrapperClass = cn(styles['input-wrapper'], className);\n\n const inputContainer = cn(styles['input-container'], {\n [styles['input-container--transparent']]: isTransparent,\n [styles['input-container--on-blueberry']]: onBlueberry,\n [styles['input-container--on-dark']]: onDark,\n [styles['input-container--invalid']]: onError,\n [styles['input-container--large']]: isLarge,\n [styles['input-container--disabled']]: disabled,\n [styles['input-container--with-icon']]: icon,\n });\n\n const inputClass = cn(styles['input-container__input'], {\n [styles['input-container__input--large']]: isLarge,\n [styles['input-container__input--disabled']]: disabled,\n });\n\n const iconColor = disabled ? getColor('neutral', 700) : getColor('black');\n const iconSize = breakpoint === Breakpoint.xs || !isLarge ? IconSize.XSmall : IconSize.Small;\n\n const renderIcon = (): React.ReactNode => {\n if (!icon) {\n return;\n }\n\n if (typeof icon === 'string') {\n return <LazyIcon className={styles['input-container__input__icon']} color={iconColor} size={iconSize} iconName={icon} />;\n }\n\n return <Icon className={styles['input-container__input__icon']} color={iconColor} size={iconSize} svgIcon={icon} />;\n };\n\n // eslint-disable-next-line\n const handleClick = (e: React.MouseEvent<any>): void => {\n if (inputContainerRef && inputContainerRef.current && icon) {\n const selectedChild = iconRight ? 0 : 1;\n const input = inputContainerRef.current.children[selectedChild] as HTMLInputElement;\n input.focus();\n\n props.onClick && props.onClick(e);\n }\n };\n\n const handleChange = (e: React.ChangeEvent<HTMLInputElement>): void => {\n const newValue = getIncrementValue(e);\n\n if (onChange) {\n onChange(e);\n }\n\n setInput(newValue);\n setPrevValue(newValue);\n };\n\n // Hvis bruker endrer number value med 1 og det skal startes på en annen verdi enn 0\n const getIncrementValue = (e: React.ChangeEvent<HTMLInputElement>): string => {\n if (typeof baseIncrementValue === 'undefined' || type !== 'number') return e.target.value;\n\n const valueAsNumber = Number(e.target.value);\n\n if (!prevValue && !numKeyPressed.current && (valueAsNumber === 1 || valueAsNumber === -1)) {\n e.target.value = baseIncrementValue + '';\n }\n\n return e.target.value;\n };\n\n const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>): void => {\n if (numRegex.test(e.key)) {\n numKeyPressed.current = true;\n }\n onKeyDown && onKeyDown(e);\n };\n\n const handleKeyUp = (e: React.KeyboardEvent<HTMLInputElement>): void => {\n if (numRegex.test(e.key)) {\n numKeyPressed.current = false;\n }\n };\n\n const maxWidth = width ? getInputMaxWidth(width, !!icon, iconSize) : undefined;\n\n return (\n <ErrorWrapper errorText={errorText} errorTextId={errorTextUuid}>\n <div data-testid={testId} data-analyticsid={AnalyticsId.Input} className={inputWrapperClass} ref={inputWrapperRef}>\n {renderLabel(label, inputIdState, mode as FormMode)}\n {/* input-elementet tillater keyboard-interaksjon */}\n <div className={styles['content-wrapper']}>\n {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */}\n <div onClick={handleClick} ref={inputContainerRef} className={inputContainer} style={{ maxWidth }}>\n {!iconRight && renderIcon()}\n <input\n onChange={handleChange}\n onKeyDown={handleKeyDown}\n onKeyUp={handleKeyUp}\n name={name}\n type={type}\n defaultValue={defaultValue}\n id={inputIdState}\n className={inputClass}\n ref={ref}\n aria-labelledby={props['aria-labelledby'] ?? undefined}\n aria-describedby={getAriaDescribedBy(props, errorTextUuid)}\n aria-invalid={!!onError}\n disabled={disabled}\n placeholder={placeholder}\n readOnly={readOnly}\n autoComplete={autoComplete || 'off'}\n required={required}\n // eslint-disable-next-line jsx-a11y/no-autofocus\n autoFocus={autoFocus}\n {...rest}\n />\n {iconRight && renderIcon()}\n </div>\n <div className={styles['content-wrapper__right-of-input']}>{rightOfInput}</div>\n </div>\n {maxCharacters && (\n <MaxCharacters maxCharacters={maxCharacters} length={input.toString().length} maxText={maxText} mode={mode} maxWidth={maxWidth} />\n )}\n {afterInputChildren}\n </div>\n </ErrorWrapper>\n );\n});\n\nInput.displayName = 'Input';\n\nexport default Input;\n"],"names":["InputTypes","getInputMaxWidth","characters","hasIcon","iconSize","paddingWidth","iconWidth","AVERAGE_CHARACTER_WIDTH_PX","Input","React","props","ref","className","defaultValue","placeholder","type","name","transparent","icon","iconRight","inputId","inputWrapperRef","mode","FormMode","size","baseIncrementValue","label","error","errorText","errorTextId","testId","disabled","readOnly","autoComplete","afterInputChildren","rightOfInput","width","required","onChange","onKeyDown","autoFocus","maxCharacters","maxText","rest","breakpoint","useBreakpoint","inputContainerRef","useRef","inputIdState","useUuid","input","setInput","useState","prevValue","setPrevValue","numKeyPressed","errorTextUuid","numRegex","useEffect","onDark","onBlueberry","maxCharactersExceeded","onError","isLarge","FormSize","isTransparent","inputWrapperClass","cn","styles","inputContainer","inputClass","iconColor","getColor","Breakpoint","IconSize","renderIcon","LazyIcon","Icon","handleClick","e","selectedChild","handleChange","newValue","getIncrementValue","valueAsNumber","handleKeyDown","handleKeyUp","maxWidth","ErrorWrapper","AnalyticsId","renderLabel","getAriaDescribedBy","MaxCharacters"],"mappings":";;;;;;;;;;;;;AAkFY,IAAAA,uBAAAA,OACVA,EAAA,OAAO,QACPA,EAAA,SAAS,UACTA,EAAA,QAAQ,SACRA,EAAA,WAAW,YACXA,EAAA,SAAS,UACTA,EAAA,MAAM,OACNA,EAAA,MAAM,OACNA,EAAA,OAAO,QACPA,EAAA,OAAO,QATGA,IAAAA,MAAA,CAAA,CAAA;AAYZ,MAAMC,KAAmB,CAACC,GAAoBC,GAAkBC,MAA6B;AACrF,QAAAC,IAAeF,IAAU,WAAW,QACpCG,IAAYH,IAAU,GAAGC,CAAQ,OAAO;AAGvC,SAAA,QAAQF,IAAaK,EAA0B,QAAQF,CAAY,MAAMC,CAAS;AAC3F,GAEME,KAAQC,EAAM,WAAW,CAACC,GAAmBC,MAAqC;AAChF,QAAA;AAAA,IACJ,WAAAC;AAAA,IACA,cAAAC;AAAA,IACA,aAAAC;AAAA,IACA,MAAAC,IAAO;AAAA,IACP,MAAAC;AAAA,IACA,aAAAC,IAAc;AAAA,IACd,MAAAC;AAAA,IACA,WAAAC;AAAA,IACA,SAAAC;AAAA,IACA,iBAAAC;AAAA,IACA,MAAAC,IAAOC,EAAS;AAAA,IAChB,MAAAC;AAAA,IACA,oBAAAC;AAAA,IACA,OAAAC;AAAA,IACA,OAAAC;AAAA,IACA,WAAAC;AAAA,IACA,aAAAC;AAAA,IACA,QAAAC;AAAA,IACA,UAAAC;AAAA,IACA,UAAAC;AAAA,IACA,cAAAC,IAAe;AAAA,IACf,oBAAAC;AAAA,IACA,cAAAC;AAAA,IACA,OAAAC;AAAA,IACA,UAAAC;AAAA,IACA,UAAAC;AAAA,IACA,WAAAC;AAAA,IACA,WAAAC;AAAA,IACA,eAAAC;AAAA,IACA,SAAAC;AAAA,IACA,GA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AAc,EAAA,eAAAnD,GAA8B,QAAQS,EAAM,SAAS,EAAE,QAAQ,SAAAR,IAAkB,MAAApB,GAAY,UAAAiE,EAAoB,CAAA,GAEjIrD,CACH,CACF;AAEJ,CAAC;AAED1B,GAAM,cAAc;"}
|
|
1
|
+
{"version":3,"file":"Input.js","sources":["../../../src/components/Input/Input.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react';\n\nimport cn from 'classnames';\n\nimport { FormMode, FormSize, AnalyticsId, AVERAGE_CHARACTER_WIDTH_PX } from '../../constants';\nimport { Breakpoint, useBreakpoint } from '../../hooks/useBreakpoint';\nimport { useUuid } from '../../hooks/useUuid';\nimport { getColor } from '../../theme/currys';\nimport { getAriaDescribedBy } from '../../utils/accessibility';\nimport { mergeRefs } from '../../utils/refs';\nimport ErrorWrapper from '../ErrorWrapper';\nimport Icon, { IconSize, SvgIcon } from '../Icon';\nimport { IconName } from '../Icons/IconNames';\nimport { renderLabel } from '../Label';\nimport LazyIcon from '../LazyIcon';\nimport MaxCharacters from '../MaxCharacters/MaxCharacters';\n\nimport styles from './styles.module.scss';\n\nexport interface InputProps\n extends Pick<\n React.InputHTMLAttributes<HTMLInputElement>,\n | 'disabled'\n | 'readOnly'\n | 'autoComplete'\n | 'name'\n | 'placeholder'\n | 'defaultValue'\n | 'required'\n | 'value'\n | 'min'\n | 'max'\n | 'aria-describedby'\n | 'aria-labelledby'\n | 'onBlur'\n | 'onClick'\n | 'onChange'\n | 'onFocus'\n | 'onKeyDown'\n | 'autoFocus'\n > {\n /** The number at which the input field starts when you increment or decrement it */\n baseIncrementValue?: number;\n /** Adds custom classes to the element. */\n className?: string;\n /** HMTL Input type */\n type?: keyof typeof InputTypes;\n /** input id */\n inputId?: string;\n /** Width of input field in characters (approximate) */\n width?: number;\n /** If true, the component will be transparent. */\n transparent?: boolean;\n /** Icon to be displayed next to the input field */\n icon?: SvgIcon | IconName;\n /** Places the icon to the right */\n iconRight?: boolean;\n /** Ref that is placed on the inputContainerRef */\n inputContainerRef?: React.RefObject<HTMLDivElement>;\n /** Ref that is placed on the inputWrapper */\n inputWrapperRef?: React.RefObject<HTMLDivElement>;\n /** Changes the color profile of the input */\n mode?: keyof typeof FormMode;\n /** Changes the visuals of the input */\n size?: keyof typeof FormSize;\n /** Label of the input */\n label?: React.ReactNode;\n /** Activates Error style for the input */\n error?: boolean;\n /** Error text to show above the component */\n errorText?: string;\n /** Error text id */\n errorTextId?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Component shown after input */\n afterInputChildren?: React.ReactNode;\n /** Component shown to the right of input */\n rightOfInput?: React.ReactNode;\n /** max character limit in input */\n maxCharacters?: number;\n /** The text is displayed in the end of the text-counter */\n maxText?: string;\n}\n\nexport enum InputTypes {\n text = 'text',\n number = 'number',\n email = 'email',\n password = 'password',\n search = 'search',\n tel = 'tel',\n url = 'url',\n date = 'date',\n time = 'time',\n}\n\nconst getInputMaxWidth = (characters: number, hasIcon: boolean, iconSize: number): string => {\n const paddingWidth = hasIcon ? '1.5rem' : '2rem';\n const iconWidth = hasIcon ? `${iconSize}px` : '0px';\n const borderWidth = '4px';\n\n return `calc(${characters * AVERAGE_CHARACTER_WIDTH_PX}px + ${paddingWidth} + ${iconWidth} + ${borderWidth})`;\n};\n\nconst Input = React.forwardRef((props: InputProps, ref: React.Ref<HTMLInputElement>) => {\n const {\n className,\n defaultValue,\n placeholder,\n type = InputTypes.text,\n name,\n transparent = false,\n icon,\n iconRight,\n inputId,\n inputWrapperRef,\n mode = FormMode.onwhite,\n size,\n baseIncrementValue,\n label,\n error,\n errorText,\n errorTextId,\n testId,\n disabled,\n readOnly,\n autoComplete = 'off',\n afterInputChildren,\n rightOfInput,\n width,\n required,\n onChange,\n onKeyDown,\n autoFocus,\n maxCharacters,\n maxText,\n ...rest\n } = props;\n const breakpoint = useBreakpoint();\n const inputContainerRef = useRef<HTMLDivElement>(null);\n const inputIdState = useUuid(inputId);\n const [input, setInput] = useState(defaultValue || '');\n const [prevValue, setPrevValue] = useState<string | number | undefined>(undefined);\n const numKeyPressed = useRef<boolean>(false);\n const errorTextUuid = useUuid(errorTextId);\n const numRegex = /^[0-9]$/;\n\n useEffect(() => {\n setInput(defaultValue || '');\n }, [defaultValue]);\n\n const onDark = mode === FormMode.ondark;\n const onBlueberry = mode === FormMode.onblueberry;\n const maxCharactersExceeded = !!maxCharacters && input.toString().length > maxCharacters;\n const onError = mode === FormMode.oninvalid || !!errorText || !!error || maxCharactersExceeded;\n const isLarge = size === FormSize.large;\n const isTransparent = transparent && mode !== FormMode.ondark && !onError;\n\n const inputWrapperClass = cn(styles['input-wrapper'], className);\n\n const inputContainer = cn(styles['input-container'], {\n [styles['input-container--transparent']]: isTransparent,\n [styles['input-container--on-blueberry']]: onBlueberry,\n [styles['input-container--on-dark']]: onDark,\n [styles['input-container--invalid']]: onError,\n [styles['input-container--large']]: isLarge,\n [styles['input-container--disabled']]: disabled,\n [styles['input-container--with-icon']]: icon,\n });\n\n const inputClass = cn(styles['input-container__input'], {\n [styles['input-container__input--large']]: isLarge,\n [styles['input-container__input--disabled']]: disabled,\n });\n\n const iconColor = disabled ? getColor('neutral', 700) : getColor('black');\n const iconSize = breakpoint === Breakpoint.xs || !isLarge ? IconSize.XSmall : IconSize.Small;\n\n const renderIcon = (): React.ReactNode => {\n if (!icon) {\n return;\n }\n\n if (typeof icon === 'string') {\n return <LazyIcon className={styles['input-container__input__icon']} color={iconColor} size={iconSize} iconName={icon} />;\n }\n\n return <Icon className={styles['input-container__input__icon']} color={iconColor} size={iconSize} svgIcon={icon} />;\n };\n\n // eslint-disable-next-line\n const handleClick = (e: React.MouseEvent<any>): void => {\n if (inputContainerRef && inputContainerRef.current && icon) {\n const selectedChild = iconRight ? 0 : 1;\n const input = inputContainerRef.current.children[selectedChild] as HTMLInputElement;\n input.focus();\n\n props.onClick && props.onClick(e);\n }\n };\n\n const handleChange = (e: React.ChangeEvent<HTMLInputElement>): void => {\n const newValue = getIncrementValue(e);\n\n if (onChange) {\n onChange(e);\n }\n\n setInput(newValue);\n setPrevValue(newValue);\n };\n\n // Hvis bruker endrer number value med 1 og det skal startes på en annen verdi enn 0\n const getIncrementValue = (e: React.ChangeEvent<HTMLInputElement>): string => {\n if (typeof baseIncrementValue === 'undefined' || type !== 'number') return e.target.value;\n\n const valueAsNumber = Number(e.target.value);\n\n if (!prevValue && !numKeyPressed.current && (valueAsNumber === 1 || valueAsNumber === -1)) {\n e.target.value = baseIncrementValue + '';\n }\n\n return e.target.value;\n };\n\n const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>): void => {\n if (numRegex.test(e.key)) {\n numKeyPressed.current = true;\n }\n onKeyDown && onKeyDown(e);\n };\n\n const handleKeyUp = (e: React.KeyboardEvent<HTMLInputElement>): void => {\n if (numRegex.test(e.key)) {\n numKeyPressed.current = false;\n }\n };\n\n const maxWidth = width ? getInputMaxWidth(width, !!icon, iconSize) : undefined;\n\n return (\n <ErrorWrapper errorText={errorText} errorTextId={errorTextUuid}>\n <div data-testid={testId} data-analyticsid={AnalyticsId.Input} className={inputWrapperClass} ref={inputWrapperRef}>\n {renderLabel(label, inputIdState, mode as FormMode)}\n {/* input-elementet tillater keyboard-interaksjon */}\n <div className={styles['content-wrapper']}>\n {/* eslint-disable-next-line jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */}\n <div\n onClick={handleClick}\n ref={mergeRefs([inputContainerRef, props.inputContainerRef])}\n className={inputContainer}\n style={{ maxWidth }}\n >\n {!iconRight && renderIcon()}\n <input\n onChange={handleChange}\n onKeyDown={handleKeyDown}\n onKeyUp={handleKeyUp}\n name={name}\n type={type}\n defaultValue={defaultValue}\n id={inputIdState}\n className={inputClass}\n ref={ref}\n aria-labelledby={props['aria-labelledby'] ?? undefined}\n aria-describedby={getAriaDescribedBy(props, errorTextUuid)}\n aria-invalid={!!onError}\n disabled={disabled}\n placeholder={placeholder}\n readOnly={readOnly}\n autoComplete={autoComplete || 'off'}\n required={required}\n // eslint-disable-next-line jsx-a11y/no-autofocus\n autoFocus={autoFocus}\n {...rest}\n />\n {iconRight && renderIcon()}\n </div>\n <div className={styles['content-wrapper__right-of-input']}>{rightOfInput}</div>\n </div>\n {maxCharacters && (\n <MaxCharacters maxCharacters={maxCharacters} length={input.toString().length} maxText={maxText} mode={mode} maxWidth={maxWidth} />\n )}\n {afterInputChildren}\n </div>\n </ErrorWrapper>\n );\n});\n\nInput.displayName = 'Input';\n\nexport default Input;\n"],"names":["InputTypes","getInputMaxWidth","characters","hasIcon","iconSize","paddingWidth","iconWidth","AVERAGE_CHARACTER_WIDTH_PX","Input","React","props","ref","className","defaultValue","placeholder","type","name","transparent","icon","iconRight","inputId","inputWrapperRef","mode","FormMode","size","baseIncrementValue","label","error","errorText","errorTextId","testId","disabled","readOnly","autoComplete","afterInputChildren","rightOfInput","width","required","onChange","onKeyDown","autoFocus","maxCharacters","maxText","rest","breakpoint","useBreakpoint","inputContainerRef","useRef","inputIdState","useUuid","input","setInput","useState","prevValue","setPrevValue","numKeyPressed","errorTextUuid","numRegex","useEffect","onDark","onBlueberry","maxCharactersExceeded","onError","isLarge","FormSize","isTransparent","inputWrapperClass","cn","styles","inputContainer","inputClass","iconColor","getColor","Breakpoint","IconSize","renderIcon","LazyIcon","Icon","handleClick","e","selectedChild","handleChange","newValue","getIncrementValue","valueAsNumber","handleKeyDown","handleKeyUp","maxWidth","ErrorWrapper","AnalyticsId","renderLabel","mergeRefs","getAriaDescribedBy","MaxCharacters"],"mappings":";;;;;;;;;;;;;;AAqFY,IAAAA,uBAAAA,OACVA,EAAA,OAAO,QACPA,EAAA,SAAS,UACTA,EAAA,QAAQ,SACRA,EAAA,WAAW,YACXA,EAAA,SAAS,UACTA,EAAA,MAAM,OACNA,EAAA,MAAM,OACNA,EAAA,OAAO,QACPA,EAAA,OAAO,QATGA,IAAAA,MAAA,CAAA,CAAA;AAYZ,MAAMC,KAAmB,CAACC,GAAoBC,GAAkBC,MAA6B;AACrF,QAAAC,IAAeF,IAAU,WAA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O,iBAAiB,EAEtC,GAAA3D,gBAAAA,EAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,SAASqE;AAAA,MACT,KAAKa,GAAU,CAAC7C,GAAmBpC,EAAM,iBAAiB,CAAC;AAAA,MAC3D,WAAW2D;AAAA,MACX,OAAO,EAAE,UAAAkB,EAAS;AAAA,IAAA;AAAA,IAEjB,CAACpE,KAAawD,EAAW;AAAA,IAC1BlE,gBAAAA,EAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,UAAUwE;AAAA,QACV,WAAWI;AAAA,QACX,SAASC;AAAA,QACT,MAAAtE;AAAA,QACA,MAAAD;AAAA,QACA,cAAAF;AAAA,QACA,IAAImC;AAAA,QACJ,WAAWsB;AAAA,QACX,KAAA3D;AAAA,QACA,mBAAiBD,EAAM,iBAAiB,KAAK;AAAA,QAC7C,oBAAkBkF,GAAmBlF,GAAO8C,CAAa;AAAA,QACzD,gBAAc,CAAC,CAACM;AAAA,QAChB,UAAA/B;AAAA,QACA,aAAAjB;AAAA,QACA,UAAAkB;AAAA,QACA,cAAcC,KAAgB;AAAA,QAC9B,UAAAI;AAAA,QAEA,WAAAG;AAAA,QACC,GAAGG;AAAA,MAAA;AAAA,IACN;AAAA,IACCxB,KAAawD,EAAW;AAAA,EAC3B,GACClE,gBAAAA,EAAA,cAAA,OAAA,EAAI,WAAW2D,EAAO,iCAAiC,EAAI,GAAAjC,CAAa,CAC3E,GACCM,KACChC,gBAAAA,EAAA,cAACoF,MAAc,eAAApD,GAA8B,QAAQS,EAAM,SAAA,EAAW,QAAQ,SAAAR,IAAkB,MAAApB,GAAY,UAAAiE,EAAA,CAAoB,GAEjIrD,CACH,CACF;AAEJ,CAAC;AAED1B,GAAM,cAAc;"}
|
|
@@ -7,7 +7,7 @@ export declare enum Overlay {
|
|
|
7
7
|
parent = "parent"
|
|
8
8
|
}
|
|
9
9
|
export interface LoaderProps {
|
|
10
|
-
/** Sets the color of the loader */
|
|
10
|
+
/** Sets the color of the loader. If overlay is used, the color will always be white. */
|
|
11
11
|
color?: LoaderColors;
|
|
12
12
|
/** Adds custom classes to the element. */
|
|
13
13
|
className?: string;
|
|
@@ -23,9 +23,9 @@ export interface LoaderProps {
|
|
|
23
23
|
inline?: boolean;
|
|
24
24
|
/** Loader is displayed with grey background covering the entire screen */
|
|
25
25
|
overlay?: keyof typeof Overlay;
|
|
26
|
-
/**
|
|
26
|
+
/** Individual id for loading icon (aria-labelledby). */
|
|
27
27
|
ariaLabelledById?: string;
|
|
28
|
-
/**
|
|
28
|
+
/** String that labels the current loading element */
|
|
29
29
|
ariaLabel?: string;
|
|
30
30
|
}
|
|
31
31
|
declare const Loader: React.FC<LoaderProps>;
|
|
@@ -3,26 +3,25 @@ import i from "classnames";
|
|
|
3
3
|
import { ZIndex as z, AnalyticsId as D } from "../../constants.js";
|
|
4
4
|
import { uuid as A } from "../../utils/uuid.js";
|
|
5
5
|
import e from "../Loader/styles.module.scss";
|
|
6
|
-
var B = /* @__PURE__ */ ((
|
|
7
|
-
const F = (
|
|
6
|
+
var B = /* @__PURE__ */ ((a) => (a.screen = "screen", a.parent = "parent", a))(B || {});
|
|
7
|
+
const F = (a) => {
|
|
8
8
|
const {
|
|
9
|
-
overlay:
|
|
10
|
-
|
|
11
|
-
size: d = "small",
|
|
9
|
+
overlay: t,
|
|
10
|
+
size: n = "small",
|
|
12
11
|
className: N = "",
|
|
13
12
|
labelId: m = A(),
|
|
14
|
-
testId:
|
|
15
|
-
center:
|
|
16
|
-
inline:
|
|
13
|
+
testId: h,
|
|
14
|
+
center: L,
|
|
15
|
+
inline: d,
|
|
17
16
|
ariaLabelledById: p,
|
|
18
17
|
ariaLabel: I = "Laster inn"
|
|
19
|
-
} =
|
|
20
|
-
[e["loader-wrapper--center"]]:
|
|
21
|
-
[e["loader-wrapper--overlay"]]:
|
|
22
|
-
[e["loader-wrapper--overlay-screen"]]:
|
|
23
|
-
[e["loader-wrapper--overlay-parent"]]:
|
|
24
|
-
[e["loader-wrapper--inline"]]:
|
|
25
|
-
}),
|
|
18
|
+
} = a, r = a.overlay ? "white" : a.color || "neutral", g = () => !(t === "parent" || d), [c, u] = S(g()), _ = n === "small", y = n === "medium", f = n === "large", x = i({
|
|
19
|
+
[e["loader-wrapper--center"]]: L,
|
|
20
|
+
[e["loader-wrapper--overlay"]]: t,
|
|
21
|
+
[e["loader-wrapper--overlay-screen"]]: t === "screen",
|
|
22
|
+
[e["loader-wrapper--overlay-parent"]]: t === "parent" && c,
|
|
23
|
+
[e["loader-wrapper--inline"]]: d && c
|
|
24
|
+
}), k = i(
|
|
26
25
|
e.loader,
|
|
27
26
|
{
|
|
28
27
|
[e["loader--small"]]: _,
|
|
@@ -43,16 +42,16 @@ const F = (t) => {
|
|
|
43
42
|
[e["loader__dot--white"]]: r === "white"
|
|
44
43
|
}), s = C(null);
|
|
45
44
|
return R(() => {
|
|
46
|
-
var v, E, b
|
|
47
|
-
|
|
48
|
-
}, []), /* @__PURE__ */ l.createElement("div", { className:
|
|
45
|
+
var v, w, E, b;
|
|
46
|
+
t === "parent" && ((w = (v = s.current) == null ? void 0 : v.parentElement) != null && w.style) && (s.current.parentElement.style.position = "relative", u(!0)), d && ((b = (E = s.current) == null ? void 0 : E.parentElement) != null && b.style) && (s.current.parentElement.style.display = "flex", u(!0));
|
|
47
|
+
}, []), /* @__PURE__ */ l.createElement("div", { className: x, ref: s, style: t === "screen" ? { zIndex: z.OverlayScreen } : {} }, c && /* @__PURE__ */ l.createElement(
|
|
49
48
|
"div",
|
|
50
49
|
{
|
|
51
|
-
"data-testid":
|
|
50
|
+
"data-testid": h,
|
|
52
51
|
"data-analyticsid": D.Loader,
|
|
53
52
|
role: "progressbar",
|
|
54
53
|
"aria-labelledby": p || m,
|
|
55
|
-
className:
|
|
54
|
+
className: k
|
|
56
55
|
},
|
|
57
56
|
/* @__PURE__ */ l.createElement("div", { className: o }),
|
|
58
57
|
/* @__PURE__ */ l.createElement("div", { className: o }),
|