@helsenorge/designsystem-react 8.6.0-beta.1 → 9.0.0-beta.0
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/Button.js +7 -7
- package/Button.js.map +1 -1
- package/CHANGELOG.md +1 -1
- package/Checkbox.js +42 -42
- package/Checkbox.js.map +1 -1
- package/ErrorWrapper.js.map +1 -1
- package/FormGroup.js +30 -30
- package/FormGroup.js.map +1 -1
- package/Icon.js +21 -21
- package/Icon.js.map +1 -1
- package/Input.js +98 -88
- package/Input.js.map +1 -1
- package/Label.js +9 -9
- package/Label.js.map +1 -1
- package/MaxCharacters.js +2 -2
- package/MaxCharacters.js.map +1 -1
- package/RadioButton.js +61 -61
- package/RadioButton.js.map +1 -1
- package/Select.js +34 -33
- package/Select.js.map +1 -1
- package/StatusDot.js +15 -15
- package/StatusDot.js.map +1 -1
- package/TabList.js +88 -53
- package/TabList.js.map +1 -1
- package/TabPanel.js +7 -7
- package/TabPanel.js.map +1 -1
- package/Textarea.js +59 -58
- package/Textarea.js.map +1 -1
- package/Trigger.js +33 -33
- package/Trigger.js.map +1 -1
- package/components/Button/Button.d.ts +2 -2
- package/components/Checkbox/Checkbox.d.ts +4 -3
- package/components/Checkbox/styles.module.scss +0 -14
- package/components/Checkbox/styles.module.scss.d.ts +0 -1
- package/components/Dropdown/Dropdown.d.ts +2 -2
- package/components/Dropdown/index.js +25 -25
- package/components/Dropdown/index.js.map +1 -1
- package/components/ErrorWrapper/ErrorWrapper.d.ts +3 -0
- package/components/ExpanderList/ExpanderList.d.ts +4 -6
- package/components/ExpanderList/index.js +118 -126
- package/components/ExpanderList/index.js.map +1 -1
- package/components/ExpanderList/styles.module.scss +164 -53
- package/components/ExpanderList/styles.module.scss.d.ts +29 -5
- package/components/FormGroup/FormGroup.d.ts +2 -2
- package/components/Icon/Icon.d.ts +4 -4
- package/components/Icons/NoAccess.js +7 -7
- package/components/Icons/NoAccess.js.map +1 -1
- package/components/Input/Input.d.ts +4 -3
- package/components/Label/Label.d.ts +4 -4
- package/components/Label/SubLabel.d.ts +2 -2
- package/components/MaxCharacters/MaxCharacters.d.ts +2 -2
- package/components/RadioButton/RadioButton.d.ts +5 -4
- package/components/RadioButton/styles.module.scss +0 -15
- package/components/RadioButton/styles.module.scss.d.ts +0 -1
- package/components/Select/Select.d.ts +4 -3
- package/components/SharingStatus/SharingStatus.d.ts +1 -1
- package/components/SharingStatus/index.js +5 -5
- package/components/SharingStatus/index.js.map +1 -1
- package/components/SharingStatus/styles.module.scss +0 -16
- package/components/SharingStatus/styles.module.scss.d.ts +0 -4
- package/components/StatusDot/StatusDot.d.ts +3 -3
- package/components/StatusDot/index.js +3 -3
- package/components/Tabs/TabList/TabList.d.ts +3 -3
- package/components/Tabs/TabList/styles.module.scss +63 -51
- package/components/Tabs/TabList/styles.module.scss.d.ts +7 -3
- package/components/Tabs/TabPanel/TabPanel.d.ts +1 -2
- package/components/Tabs/TabPanel/styles.module.scss +11 -26
- package/components/Tabs/TabPanel/styles.module.scss.d.ts +0 -2
- package/components/Tabs/Tabs.d.ts +3 -3
- package/components/Tabs/index.js +57 -72
- package/components/Tabs/index.js.map +1 -1
- package/components/Tabs/styles.module.scss +5 -9
- package/components/Tabs/styles.module.scss.d.ts +0 -1
- package/components/Textarea/Textarea.d.ts +4 -3
- package/components/Toggle/index.js +1222 -1180
- package/components/Toggle/index.js.map +1 -1
- package/components/Trigger/Trigger.d.ts +2 -2
- package/components/Validation/index.js +38 -32
- package/components/Validation/index.js.map +1 -1
- package/constants.d.ts +1 -1
- package/constants.js +1 -1
- package/constants.js.map +1 -1
- package/docs/FormExample/FormExample.d.ts +2 -1
- package/index.js +23 -23
- package/package.json +4 -4
- package/utils/component.d.ts +1 -0
- package/utils/component.js +7 -3
- package/utils/component.js.map +1 -1
package/Icon.js
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
1
|
import { jsxs as u, jsx as b } from "react/jsx-runtime";
|
|
2
2
|
import f from "react";
|
|
3
3
|
import y from "classnames";
|
|
4
|
-
import { IconSize as
|
|
4
|
+
import { IconSize as l, AnalyticsId as v } from "./constants.js";
|
|
5
5
|
import { useUuid as w } from "./hooks/useUuid.js";
|
|
6
6
|
const z = ({
|
|
7
7
|
size: a,
|
|
8
|
-
isHovered:
|
|
8
|
+
isHovered: e,
|
|
9
9
|
normal: n,
|
|
10
|
-
normalHover:
|
|
11
|
-
xSmall:
|
|
10
|
+
normalHover: o,
|
|
11
|
+
xSmall: r,
|
|
12
12
|
xSmallHover: t,
|
|
13
13
|
xxSmall: i,
|
|
14
|
-
xxSmallHover:
|
|
15
|
-
}) => a <=
|
|
14
|
+
xxSmallHover: s
|
|
15
|
+
}) => a <= l.XXSmall && i && s ? e ? s : i : a <= l.XSmall && r && t ? e ? t : r : e ? o : n, N = f.forwardRef((a, e) => {
|
|
16
16
|
const {
|
|
17
17
|
svgIcon: n,
|
|
18
|
-
ariaLabel:
|
|
19
|
-
className:
|
|
20
|
-
size: t =
|
|
18
|
+
ariaLabel: o,
|
|
19
|
+
className: r = "",
|
|
20
|
+
size: t = l.Small,
|
|
21
21
|
color: i = "black",
|
|
22
|
-
hoverColor:
|
|
23
|
-
isHovered:
|
|
24
|
-
|
|
22
|
+
hoverColor: s = i || "black",
|
|
23
|
+
isHovered: c = !1,
|
|
24
|
+
onColor: h,
|
|
25
25
|
testId: I,
|
|
26
26
|
...g
|
|
27
27
|
} = a, p = f.createElement(n, {
|
|
28
28
|
size: t,
|
|
29
|
-
isHovered:
|
|
30
|
-
|
|
31
|
-
}), d = w(), m =
|
|
29
|
+
isHovered: c,
|
|
30
|
+
onColor: h
|
|
31
|
+
}), d = w(), m = c ? s : i;
|
|
32
32
|
return /* @__PURE__ */ u(
|
|
33
33
|
"svg",
|
|
34
34
|
{
|
|
35
35
|
"data-testid": I,
|
|
36
36
|
"data-analyticsid": v.Icon,
|
|
37
|
-
ref:
|
|
38
|
-
className: y("hnds-style-icon",
|
|
39
|
-
role:
|
|
40
|
-
"aria-labelledby":
|
|
37
|
+
ref: e,
|
|
38
|
+
className: y("hnds-style-icon", r),
|
|
39
|
+
role: o ? "img" : "presentation",
|
|
40
|
+
"aria-labelledby": o ? d : void 0,
|
|
41
41
|
focusable: !1,
|
|
42
|
-
"aria-hidden":
|
|
42
|
+
"aria-hidden": o ? void 0 : !0,
|
|
43
43
|
viewBox: "0 0 48 48",
|
|
44
44
|
style: { minWidth: t, minHeight: t },
|
|
45
45
|
width: t,
|
|
@@ -48,7 +48,7 @@ const z = ({
|
|
|
48
48
|
color: m,
|
|
49
49
|
...g,
|
|
50
50
|
children: [
|
|
51
|
-
|
|
51
|
+
o && /* @__PURE__ */ b("title", { id: d, children: o }),
|
|
52
52
|
p
|
|
53
53
|
]
|
|
54
54
|
}
|
package/Icon.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Icon.js","sources":["../src/components/Icon/Icon.tsx"],"sourcesContent":["import React from 'react';\n\nimport classNames from 'classnames';\n\nimport { AnalyticsId,
|
|
1
|
+
{"version":3,"file":"Icon.js","sources":["../src/components/Icon/Icon.tsx"],"sourcesContent":["import React from 'react';\n\nimport classNames from 'classnames';\n\nimport { AnalyticsId, FormOnColor, IconSize } from '../../constants';\nimport { useUuid } from '../../hooks/useUuid';\nimport { StatusDotOnColor } from '../StatusDot';\n\nexport type SvgIcon = React.FC<SvgPathProps>;\n\nexport interface BaseIconProps {\n /* aria-label for the <svg> element. Used as <title> tag. */\n ariaLabel?: string;\n /* Changes the size of the icon. */\n size?: number;\n /* Changes the color of the icon. */\n color?: string;\n /* Changes the hover color of the icon. */\n hoverColor?: string;\n /* Adds custom classes to the element. */\n className?: string;\n /* Swaps the displayed icon to the hover version and changes its color. */\n isHovered?: boolean;\n /** Defines the color of the icon */\n onColor?: keyof typeof FormOnColor | StatusDotOnColor;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nexport interface IconProps extends BaseIconProps {\n /* Sets which icon should be displayed. */\n svgIcon: SvgIcon;\n}\n\nexport interface SvgPathProps {\n size: IconSize;\n isHovered: boolean;\n onColor?: keyof typeof FormOnColor | StatusDotOnColor;\n}\n\ninterface IconConfig {\n size: IconSize;\n isHovered: boolean;\n normal: React.ReactElement;\n normalHover: React.ReactElement;\n xSmall?: React.ReactElement;\n xSmallHover?: React.ReactElement;\n xxSmall?: React.ReactElement;\n xxSmallHover?: React.ReactElement;\n}\n\nexport const getIcon = ({\n size,\n isHovered,\n normal,\n normalHover,\n xSmall,\n xSmallHover,\n xxSmall,\n xxSmallHover,\n}: IconConfig): React.ReactElement => {\n if (size <= IconSize.XXSmall && xxSmall && xxSmallHover) {\n return isHovered ? xxSmallHover : xxSmall;\n }\n if (size <= IconSize.XSmall && xSmall && xSmallHover) {\n return isHovered ? xSmallHover : xSmall;\n }\n\n return isHovered ? normalHover : normal;\n};\n\nexport const Icon = React.forwardRef((props: IconProps, ref: React.ForwardedRef<SVGSVGElement>) => {\n const {\n svgIcon,\n ariaLabel,\n className = '',\n size = IconSize.Small,\n color = 'black',\n hoverColor = color || 'black',\n isHovered = false,\n onColor,\n testId,\n ...other\n } = props;\n\n const svgRaw = React.createElement(svgIcon, {\n size,\n isHovered,\n onColor,\n });\n\n const titleId = useUuid();\n const svgColor = isHovered ? hoverColor : color;\n\n return (\n <svg\n data-testid={testId}\n data-analyticsid={AnalyticsId.Icon}\n ref={ref}\n className={classNames(`hnds-style-icon`, className)}\n role={ariaLabel ? 'img' : 'presentation'}\n aria-labelledby={ariaLabel ? titleId : undefined}\n focusable={false}\n aria-hidden={ariaLabel ? undefined : true}\n viewBox=\"0 0 48 48\"\n style={{ minWidth: size, minHeight: size }}\n width={size}\n height={size}\n fill={svgColor}\n color={svgColor}\n {...other}\n >\n {ariaLabel && <title id={titleId}>{ariaLabel}</title>}\n {svgRaw}\n </svg>\n );\n});\n\nIcon.displayName = 'Icon';\n\nexport default Icon;\n"],"names":["getIcon","size","isHovered","normal","normalHover","xSmall","xSmallHover","xxSmall","xxSmallHover","IconSize","Icon","React","props","ref","svgIcon","ariaLabel","className","color","hoverColor","onColor","testId","other","svgRaw","titleId","useUuid","svgColor","jsxs","AnalyticsId","classNames","jsx"],"mappings":";;;;;AAmDO,MAAMA,IAAU,CAAC;AAAA,EACtB,MAAAC;AAAA,EACA,WAAAC;AAAA,EACA,QAAAC;AAAA,EACA,aAAAC;AAAA,EACA,QAAAC;AAAA,EACA,aAAAC;AAAA,EACA,SAAAC;AAAA,EACA,cAAAC;AACF,MACMP,KAAQQ,EAAS,WAAWF,KAAWC,IAClCN,IAAYM,IAAeD,IAEhCN,KAAQQ,EAAS,UAAUJ,KAAUC,IAChCJ,IAAYI,IAAcD,IAG5BH,IAAYE,IAAcD,GAGtBO,IAAOC,EAAM,WAAW,CAACC,GAAkBC,MAA2C;AAC3F,QAAA;AAAA,IACJ,SAAAC;AAAA,IACA,WAAAC;AAAA,IACA,WAAAC,IAAY;AAAA,IACZ,MAAAf,IAAOQ,EAAS;AAAA,IAChB,OAAAQ,IAAQ;AAAA,IACR,YAAAC,IAAaD,KAAS;AAAA,IACtB,WAAAf,IAAY;AAAA,IACZ,SAAAiB;AAAA,IACA,QAAAC;AAAA,IACA,GAAGC;AAAA,EACD,IAAAT,GAEEU,IAASX,EAAM,cAAcG,GAAS;AAAA,IAC1C,MAAAb;AAAA,IACA,WAAAC;AAAA,IACA,SAAAiB;AAAA,EAAA,CACD,GAEKI,IAAUC,KACVC,IAAWvB,IAAYgB,IAAaD;AAGxC,SAAA,gBAAAS;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,eAAaN;AAAA,MACb,oBAAkBO,EAAY;AAAA,MAC9B,KAAAd;AAAA,MACA,WAAWe,EAAW,mBAAmBZ,CAAS;AAAA,MAClD,MAAMD,IAAY,QAAQ;AAAA,MAC1B,mBAAiBA,IAAYQ,IAAU;AAAA,MACvC,WAAW;AAAA,MACX,eAAaR,IAAY,SAAY;AAAA,MACrC,SAAQ;AAAA,MACR,OAAO,EAAE,UAAUd,GAAM,WAAWA,EAAK;AAAA,MACzC,OAAOA;AAAA,MACP,QAAQA;AAAA,MACR,MAAMwB;AAAA,MACN,OAAOA;AAAA,MACN,GAAGJ;AAAA,MAEH,UAAA;AAAA,QAAAN,KAAc,gBAAAc,EAAA,SAAA,EAAM,IAAIN,GAAU,UAAUR,GAAA;AAAA,QAC5CO;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGP,CAAC;AAEDZ,EAAK,cAAc;"}
|
package/Input.js
CHANGED
|
@@ -1,140 +1,150 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
1
|
+
import { jsx as s, jsxs as _ } from "react/jsx-runtime";
|
|
2
|
+
import _e, { useRef as $, useState as L, useEffect as ye } from "react";
|
|
3
3
|
import y from "classnames";
|
|
4
|
-
import {
|
|
5
|
-
import { useBreakpoint as we, Breakpoint as
|
|
6
|
-
import { useUuid as
|
|
7
|
-
import { getColor as
|
|
8
|
-
import { getAriaDescribedBy as
|
|
9
|
-
import { mergeRefs as
|
|
10
|
-
import { E as
|
|
11
|
-
import { I as
|
|
12
|
-
import { a as
|
|
13
|
-
import { L as
|
|
14
|
-
import { M as
|
|
4
|
+
import { FormOnColor as c, FormSize as Ne, IconSize as B, AnalyticsId as ke, AVERAGE_CHARACTER_WIDTH_PX as Ie } from "./constants.js";
|
|
5
|
+
import { useBreakpoint as we, Breakpoint as Re } from "./hooks/useBreakpoint.js";
|
|
6
|
+
import { useUuid as U } from "./hooks/useUuid.js";
|
|
7
|
+
import { getColor as F } from "./theme/currys/color.js";
|
|
8
|
+
import { getAriaDescribedBy as We } from "./utils/accessibility.js";
|
|
9
|
+
import { mergeRefs as Se } from "./utils/refs.js";
|
|
10
|
+
import { E as Ee } from "./ErrorWrapper.js";
|
|
11
|
+
import { I as ze } from "./Icon.js";
|
|
12
|
+
import { a as Ae } from "./Label.js";
|
|
13
|
+
import { L as Ve } from "./LazyIcon.js";
|
|
14
|
+
import { M as De } from "./MaxCharacters.js";
|
|
15
15
|
import t from "./components/Input/styles.module.scss";
|
|
16
|
-
var
|
|
17
|
-
const
|
|
16
|
+
var Ke = /* @__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))(Ke || {});
|
|
17
|
+
const $e = (e, l, p) => {
|
|
18
18
|
const o = l ? "1.5rem" : "2rem", f = l ? `${p}px` : "0px";
|
|
19
19
|
return `calc(${e * Ie}px + ${o} + ${f} + 4px)`;
|
|
20
|
-
},
|
|
20
|
+
}, Le = _e.forwardRef((e, l) => {
|
|
21
21
|
const {
|
|
22
22
|
className: p,
|
|
23
23
|
defaultValue: o,
|
|
24
24
|
placeholder: f,
|
|
25
25
|
type: h = "text",
|
|
26
|
-
name:
|
|
27
|
-
transparent:
|
|
28
|
-
icon:
|
|
26
|
+
name: M,
|
|
27
|
+
transparent: O = !1,
|
|
28
|
+
icon: n,
|
|
29
29
|
iconRight: g,
|
|
30
|
-
inputId:
|
|
31
|
-
inputWrapperRef:
|
|
32
|
-
|
|
33
|
-
size:
|
|
34
|
-
baseIncrementValue:
|
|
30
|
+
inputId: P,
|
|
31
|
+
inputWrapperRef: j,
|
|
32
|
+
onColor: i = c.onwhite,
|
|
33
|
+
size: H,
|
|
34
|
+
baseIncrementValue: N,
|
|
35
35
|
label: X,
|
|
36
36
|
error: q,
|
|
37
|
-
errorText:
|
|
37
|
+
errorText: k,
|
|
38
38
|
errorTextId: G,
|
|
39
|
-
|
|
39
|
+
errorWrapperClassName: J,
|
|
40
|
+
testId: Q,
|
|
40
41
|
disabled: u,
|
|
41
|
-
readOnly:
|
|
42
|
-
autoComplete:
|
|
43
|
-
afterInputChildren:
|
|
44
|
-
rightOfInput:
|
|
45
|
-
width:
|
|
46
|
-
required:
|
|
47
|
-
onChange:
|
|
42
|
+
readOnly: T,
|
|
43
|
+
autoComplete: Y = "off",
|
|
44
|
+
afterInputChildren: Z,
|
|
45
|
+
rightOfInput: ee,
|
|
46
|
+
width: I,
|
|
47
|
+
required: te,
|
|
48
|
+
onChange: w,
|
|
48
49
|
onKeyDown: R,
|
|
49
|
-
autoFocus:
|
|
50
|
+
autoFocus: re,
|
|
50
51
|
maxCharacters: d,
|
|
51
52
|
maxText: ne,
|
|
52
|
-
inputContainerRef:
|
|
53
|
-
...
|
|
54
|
-
} = e,
|
|
55
|
-
|
|
53
|
+
inputContainerRef: ae,
|
|
54
|
+
...oe
|
|
55
|
+
} = e, ie = we(), m = $(null), W = U(P), [S, E] = L(o || ""), [se, ce] = L(void 0), b = $(!1), z = U(G), A = /^[0-9]$/;
|
|
56
|
+
ye(() => {
|
|
56
57
|
E(o || "");
|
|
57
58
|
}, [o]);
|
|
58
|
-
const
|
|
59
|
-
[t["input-container--transparent"]]:
|
|
60
|
-
[t["input-container--on-blueberry"]]:
|
|
61
|
-
[t["input-container--on-dark"]]:
|
|
62
|
-
[t["input-container--invalid"]]:
|
|
63
|
-
[t["input-container--large"]]:
|
|
59
|
+
const le = i === c.ondark, ue = i === c.onblueberry, de = !!d && S.toString().length > d, C = i === c.oninvalid || !!k || !!q || de, x = H === Ne.large, me = O && i !== c.ondark && !C, pe = y(t["input-wrapper"], p), fe = y(t["input-container"], {
|
|
60
|
+
[t["input-container--transparent"]]: me,
|
|
61
|
+
[t["input-container--on-blueberry"]]: ue,
|
|
62
|
+
[t["input-container--on-dark"]]: le,
|
|
63
|
+
[t["input-container--invalid"]]: C,
|
|
64
|
+
[t["input-container--large"]]: x,
|
|
64
65
|
[t["input-container--disabled"]]: u,
|
|
65
|
-
[t["input-container--with-icon"]]:
|
|
66
|
-
}),
|
|
67
|
-
[t["input-container__input--large"]]:
|
|
66
|
+
[t["input-container--with-icon"]]: n
|
|
67
|
+
}), he = y(t["input-container__input"], {
|
|
68
|
+
[t["input-container__input--large"]]: x,
|
|
68
69
|
[t["input-container__input--disabled"]]: u
|
|
69
|
-
}), V = u ?
|
|
70
|
-
if (
|
|
71
|
-
return typeof
|
|
72
|
-
},
|
|
73
|
-
if (m && m.current &&
|
|
70
|
+
}), V = u ? F("neutral", 700) : F("black"), v = ie === Re.xs || !x ? B.XSmall : B.Small, D = () => {
|
|
71
|
+
if (n)
|
|
72
|
+
return typeof n == "string" ? /* @__PURE__ */ s(Ve, { className: t["input-container__input__icon"], color: V, size: v, iconName: n }) : /* @__PURE__ */ s(ze, { className: t["input-container__input__icon"], color: V, size: v, svgIcon: n });
|
|
73
|
+
}, ge = (r) => {
|
|
74
|
+
if (m && m.current && n) {
|
|
74
75
|
const a = g ? 0 : 1;
|
|
75
|
-
m.current.children[a].focus(), e.onClick && e.onClick(
|
|
76
|
+
m.current.children[a].focus(), e.onClick && e.onClick(r);
|
|
76
77
|
}
|
|
77
|
-
},
|
|
78
|
-
const a =
|
|
79
|
-
|
|
80
|
-
},
|
|
81
|
-
if (typeof
|
|
82
|
-
const a = Number(
|
|
83
|
-
return !
|
|
84
|
-
}, xe = (
|
|
85
|
-
A.test(
|
|
86
|
-
},
|
|
87
|
-
A.test(
|
|
88
|
-
}, K =
|
|
89
|
-
return /* @__PURE__ */
|
|
90
|
-
|
|
78
|
+
}, be = (r) => {
|
|
79
|
+
const a = Ce(r);
|
|
80
|
+
w && w(r), E(a), ce(a);
|
|
81
|
+
}, Ce = (r) => {
|
|
82
|
+
if (typeof N > "u" || h !== "number") return r.target.value;
|
|
83
|
+
const a = Number(r.target.value);
|
|
84
|
+
return !se && !b.current && (a === 1 || a === -1) && (r.target.value = N + ""), r.target.value;
|
|
85
|
+
}, xe = (r) => {
|
|
86
|
+
A.test(r.key) && (b.current = !0), R && R(r);
|
|
87
|
+
}, ve = (r) => {
|
|
88
|
+
A.test(r.key) && (b.current = !1);
|
|
89
|
+
}, K = I ? $e(I, !!n, v) : void 0;
|
|
90
|
+
return /* @__PURE__ */ s(Ee, { className: J, errorText: k, errorTextId: z, children: /* @__PURE__ */ _("div", { "data-testid": Q, "data-analyticsid": ke.Input, className: pe, ref: j, children: [
|
|
91
|
+
Ae(X, W, i),
|
|
91
92
|
/* @__PURE__ */ _("div", { className: t["content-wrapper"], children: [
|
|
92
93
|
/* @__PURE__ */ _(
|
|
93
94
|
"div",
|
|
94
95
|
{
|
|
95
|
-
onClick:
|
|
96
|
-
ref:
|
|
97
|
-
className:
|
|
96
|
+
onClick: ge,
|
|
97
|
+
ref: Se([m, ae]),
|
|
98
|
+
className: fe,
|
|
98
99
|
style: { maxWidth: K },
|
|
99
100
|
children: [
|
|
100
101
|
!g && D(),
|
|
101
|
-
/* @__PURE__ */
|
|
102
|
+
/* @__PURE__ */ s(
|
|
102
103
|
"input",
|
|
103
104
|
{
|
|
104
|
-
onChange:
|
|
105
|
+
onChange: be,
|
|
105
106
|
onKeyDown: xe,
|
|
106
|
-
onKeyUp:
|
|
107
|
-
name:
|
|
107
|
+
onKeyUp: ve,
|
|
108
|
+
name: M,
|
|
108
109
|
type: h,
|
|
109
110
|
defaultValue: o,
|
|
110
111
|
id: W,
|
|
111
|
-
className:
|
|
112
|
+
className: he,
|
|
112
113
|
ref: l,
|
|
113
114
|
"aria-labelledby": e["aria-labelledby"] ?? void 0,
|
|
114
|
-
"aria-describedby":
|
|
115
|
-
"aria-invalid": !!
|
|
115
|
+
"aria-describedby": We(e, z),
|
|
116
|
+
"aria-invalid": !!C,
|
|
116
117
|
disabled: u,
|
|
117
118
|
placeholder: f,
|
|
118
|
-
readOnly:
|
|
119
|
-
autoComplete:
|
|
120
|
-
required:
|
|
121
|
-
autoFocus:
|
|
122
|
-
...
|
|
119
|
+
readOnly: T,
|
|
120
|
+
autoComplete: Y || "off",
|
|
121
|
+
required: te,
|
|
122
|
+
autoFocus: re,
|
|
123
|
+
...oe
|
|
123
124
|
}
|
|
124
125
|
),
|
|
125
126
|
g && D()
|
|
126
127
|
]
|
|
127
128
|
}
|
|
128
129
|
),
|
|
129
|
-
/* @__PURE__ */
|
|
130
|
+
/* @__PURE__ */ s("div", { className: t["content-wrapper__right-of-input"], children: ee })
|
|
130
131
|
] }),
|
|
131
|
-
d && /* @__PURE__ */
|
|
132
|
-
|
|
132
|
+
d && /* @__PURE__ */ s(
|
|
133
|
+
De,
|
|
134
|
+
{
|
|
135
|
+
maxCharacters: d,
|
|
136
|
+
length: S.toString().length,
|
|
137
|
+
maxText: ne,
|
|
138
|
+
onColor: i,
|
|
139
|
+
maxWidth: K
|
|
140
|
+
}
|
|
141
|
+
),
|
|
142
|
+
Z
|
|
133
143
|
] }) });
|
|
134
144
|
});
|
|
135
|
-
|
|
145
|
+
Le.displayName = "Input";
|
|
136
146
|
export {
|
|
137
|
-
|
|
138
|
-
|
|
147
|
+
Le as I,
|
|
148
|
+
Ke as a
|
|
139
149
|
};
|
|
140
150
|
//# sourceMappingURL=Input.js.map
|
package/Input.js.map
CHANGED
|
@@ -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 { 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 inputContainerRef,\n ...rest\n } = props;\n const breakpoint = useBreakpoint();\n const inputContainerRefLocal = 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 (inputContainerRefLocal && inputContainerRefLocal.current && icon) {\n const selectedChild = iconRight ? 0 : 1;\n const input = inputContainerRefLocal.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([inputContainerRefLocal, 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","inputContainerRef","rest","breakpoint","useBreakpoint","inputContainerRefLocal","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","jsx","LazyIcon","Icon","handleClick","e","selectedChild","handleChange","newValue","getIncrementValue","valueAsNumber","handleKeyDown","handleKeyUp","maxWidth","Error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B;AAAA,wBACC,OAAI,EAAA,WAAWP,EAAO,iCAAiC,GAAI,UAAalC,GAAA;AAAA,IAAA,GAC3E;AAAA,IACCM,KACE,gBAAAoC,EAAAmB,IAAA,EAAc,eAAAvD,GAA8B,QAAQU,EAAM,SAAA,EAAW,QAAQ,SAAAT,IAAkB,MAAApB,GAAY,UAAAmE,EAAoB,CAAA;AAAA,IAEjIvD;AAAA,EAAA,EACH,CAAA,EACF,CAAA;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 { FormOnColor, 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, { ErrorWrapperClassNameProps } 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 ErrorWrapperClassNameProps,\n 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 onColor?: keyof typeof FormOnColor;\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 onColor = FormOnColor.onwhite,\n size,\n baseIncrementValue,\n label,\n error,\n errorText,\n errorTextId,\n errorWrapperClassName,\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 inputContainerRef,\n ...rest\n } = props;\n const breakpoint = useBreakpoint();\n const inputContainerRefLocal = 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 = onColor === FormOnColor.ondark;\n const onBlueberry = onColor === FormOnColor.onblueberry;\n const maxCharactersExceeded = !!maxCharacters && input.toString().length > maxCharacters;\n const onError = onColor === FormOnColor.oninvalid || !!errorText || !!error || maxCharactersExceeded;\n const isLarge = size === FormSize.large;\n const isTransparent = transparent && onColor !== FormOnColor.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 (inputContainerRefLocal && inputContainerRefLocal.current && icon) {\n const selectedChild = iconRight ? 0 : 1;\n const input = inputContainerRefLocal.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 className={errorWrapperClassName} errorText={errorText} errorTextId={errorTextUuid}>\n <div data-testid={testId} data-analyticsid={AnalyticsId.Input} className={inputWrapperClass} ref={inputWrapperRef}>\n {renderLabel(label, inputIdState, onColor as FormOnColor)}\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([inputContainerRefLocal, 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\n maxCharacters={maxCharacters}\n length={input.toString().length}\n maxText={maxText}\n onColor={onColor}\n maxWidth={maxWidth}\n />\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","onColor","FormOnColor","size","baseIncrementValue","label","error","errorText","errorTextId","errorWrapperClassName","testId","disabled","readOnly","autoComplete","afterInputChildren","rightOfInput","width","required","onChange","onKeyDown","autoFocus","maxCharacters","maxText","inputContainerRef","rest","breakpoint","useBreakpoint","inputContainerRefLocal","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","jsx","LazyIcon","Icon","handleClick","e","selectedChild","handleChange","newValue","getIncrementValue","valueAsNumber","handleKeyDown","handleKeyUp","maxWidth","ErrorWrapper","jsxs","AnalyticsId","renderLabel","mergeRefs","getAriaDescribedBy","M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WAAWP,EAAO,iCAAiC,GAAI,UAAalC,IAAA;AAAA,IAAA,GAC3E;AAAA,IACCM,KACC,gBAAAoC;AAAA,MAACmB;AAAA,MAAA;AAAA,QACC,eAAAvD;AAAA,QACA,QAAQU,EAAM,SAAA,EAAW;AAAA,QACzB,SAAAT;AAAA,QACA,SAAArB;AAAA,QACA,UAAAoE;AAAA,MAAA;AAAA,IACF;AAAA,IAEDvD;AAAA,EAAA,EACH,CAAA,EACF,CAAA;AAEJ,CAAC;AAED3B,GAAM,cAAc;"}
|
package/Label.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { jsxs as m, Fragment as x, jsx as t } from "react/jsx-runtime";
|
|
2
2
|
import S from "react";
|
|
3
3
|
import y from "classnames";
|
|
4
|
-
import { AnalyticsId as L,
|
|
4
|
+
import { AnalyticsId as L, FormOnColor as u } from "./constants.js";
|
|
5
5
|
import { S as N } from "./Spacer.js";
|
|
6
6
|
import a from "./components/Label/styles.module.scss";
|
|
7
7
|
import { isComponent as b } from "./utils/component.js";
|
|
8
8
|
import { S as z } from "./StatusDot.js";
|
|
9
|
-
const A = ({ className: e, id: r,
|
|
9
|
+
const A = ({ className: e, id: r, onColor: s, sublabelTexts: n, testId: o }) => {
|
|
10
10
|
const l = (p) => n && n.map((c, h) => {
|
|
11
11
|
const F = y(a.label, a["label--sublabel"], {
|
|
12
12
|
[a["label--semibold"]]: c.type === "semibold",
|
|
@@ -26,10 +26,10 @@ const A = ({ className: e, id: r, mode: s, sublabelTexts: n, testId: o }) => {
|
|
|
26
26
|
}), r;
|
|
27
27
|
}, J = (e, r, s) => /* @__PURE__ */ t(x, { children: e && b(e, f) ? S.cloneElement(e, {
|
|
28
28
|
htmlFor: r,
|
|
29
|
-
|
|
30
|
-
}) : typeof e == "string" && /* @__PURE__ */ t(f, { labelTexts: [{ text: e, type: "semibold" }], htmlFor: r,
|
|
29
|
+
onColor: s
|
|
30
|
+
}) : typeof e == "string" && /* @__PURE__ */ t(f, { labelTexts: [{ text: e, type: "semibold" }], htmlFor: r, onColor: s }) }), K = (e, r, s, n, o, l, i, d) => /* @__PURE__ */ t(x, { children: e && b(e, f) ? S.cloneElement(e, {
|
|
31
31
|
htmlFor: s,
|
|
32
|
-
|
|
32
|
+
onColor: n,
|
|
33
33
|
children: r,
|
|
34
34
|
labelClassName: y(o, e.props.labelClassName),
|
|
35
35
|
labelTextClassName: l,
|
|
@@ -41,7 +41,7 @@ const A = ({ className: e, id: r, mode: s, sublabelTexts: n, testId: o }) => {
|
|
|
41
41
|
{
|
|
42
42
|
labelTexts: [{ text: e }],
|
|
43
43
|
htmlFor: s,
|
|
44
|
-
|
|
44
|
+
onColor: n,
|
|
45
45
|
labelClassName: o,
|
|
46
46
|
labelTextClassName: l,
|
|
47
47
|
sublabelWrapperClassName: i,
|
|
@@ -56,7 +56,7 @@ const A = ({ className: e, id: r, mode: s, sublabelTexts: n, testId: o }) => {
|
|
|
56
56
|
labelTextClassName: l,
|
|
57
57
|
labelId: i,
|
|
58
58
|
labelTexts: d,
|
|
59
|
-
|
|
59
|
+
onColor: p = u.onwhite,
|
|
60
60
|
statusDot: c,
|
|
61
61
|
sublabel: h,
|
|
62
62
|
sublabelWrapperClassName: F,
|
|
@@ -85,12 +85,12 @@ const A = ({ className: e, id: r, mode: s, sublabelTexts: n, testId: o }) => {
|
|
|
85
85
|
] }) }),
|
|
86
86
|
/* @__PURE__ */ m("div", { className: F, children: [
|
|
87
87
|
h && b(h, A) && S.cloneElement(h, {
|
|
88
|
-
|
|
88
|
+
onColor: p
|
|
89
89
|
}),
|
|
90
90
|
c && b(c, z) && /* @__PURE__ */ m(x, { children: [
|
|
91
91
|
/* @__PURE__ */ t(N, { size: "3xs" }),
|
|
92
92
|
S.cloneElement(c, {
|
|
93
|
-
|
|
93
|
+
onColor: p === u.ondark ? "ondark" : "onwhite"
|
|
94
94
|
})
|
|
95
95
|
] })
|
|
96
96
|
] })
|
package/Label.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Label.js","sources":["../src/components/Label/SubLabel.tsx","../src/components/Label/Label.tsx"],"sourcesContent":["import React from 'react';\n\nimport cn from 'classnames';\n\nimport { LabelText } from './Label';\nimport { AnalyticsId, FormMode } from '../../constants';\nimport Spacer from '../Spacer';\n\nimport styles from './styles.module.scss';\n\nexport interface SublabelProps {\n /** Adds custom classes to the element. */\n className?: string;\n /** id that is placed on the wrapper */\n id: string;\n /** Array of sublabel strings. Can be of type semibold or normal */\n mode?: FormMode;\n /** Array of sublabel strings. Can be of type semibold or normal */\n sublabelTexts?: LabelText[];\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nexport const Sublabel: React.FC<SublabelProps> = ({ className, id, mode, sublabelTexts, testId }) => {\n const mapSublabels = (hideFromScreenReader?: boolean): React.ReactNode => {\n return (\n sublabelTexts &&\n sublabelTexts.map((sublabelText, index) => {\n const labelClasses = cn(styles.label, styles['label--sublabel'], {\n [styles['label--semibold']]: sublabelText.type === 'semibold',\n [styles['label--on-dark']]: mode === FormMode.ondark,\n });\n return (\n hideFromScreenReader === sublabelText.hideFromScreenReader && (\n <span className={labelClasses} key={index}>\n {sublabelText.text}\n </span>\n )\n );\n })\n );\n };\n\n const subLabels = mapSublabels();\n const ariaHiddenSublabels = mapSublabels(true);\n\n return (\n <>\n <Spacer size={'3xs'} />\n {subLabels && (\n <div className={className} id={id} data-testid={testId} data-analyticsid={AnalyticsId.Sublabel}>\n {subLabels}\n </div>\n )}\n {ariaHiddenSublabels && (\n <div className={className} data-testid={testId}>\n {ariaHiddenSublabels}\n </div>\n )}\n </>\n );\n};\n","import React, { FunctionComponent } from 'react';\n\nimport cn from 'classnames';\n\nimport { Sublabel, SublabelProps } from './SubLabel';\nimport { AnalyticsId, FormMode } from '../../constants';\nimport { isComponent } from '../../utils/component';\nimport Spacer from '../Spacer';\nimport StatusDot, { StatusDotProps } from '../StatusDot';\n\nimport styles from './styles.module.scss';\n\nexport type LabelText = {\n hideFromScreenReader?: boolean;\n text: string;\n type?: 'semibold' | 'normal';\n};\n\nexport interface LabelProps {\n /** Component shown after label - discourage use of this */\n afterLabelChildren?: React.ReactNode;\n /** Adds custom classes to the element. */\n children?: React.ReactNode;\n /** Adds custom classes to the label tag. */\n labelClassName?: string;\n /** Adds custom classes to the label text. */\n labelTextClassName?: string;\n /** Adds custom classes to the element. */\n className?: string;\n /** Id that is put on the \"for\" attribute of the label */\n htmlFor?: string;\n /** Id som plasseres på <label/> */\n labelId?: string;\n /** Array of main label strings. Can be of type semibold or normal */\n labelTexts: LabelText[];\n /** Array of sublabel strings. Can be of type semibold or normal */\n mode?: keyof typeof FormMode;\n /** StatusDot placed underneath the last sublabel */\n statusDot?: React.ReactNode;\n /** Sublabel component */\n sublabel?: React.ReactNode;\n /** Adds custom classes to the div wrapping the sublabels. */\n sublabelWrapperClassName?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nexport const getLabelText = (label: React.ReactNode): string => {\n let allLabelText = '';\n\n if (isComponent<LabelProps>(label, Label)) {\n label.props.labelTexts.forEach(labelText => {\n allLabelText += !labelText.hideFromScreenReader ? labelText.text : '';\n });\n }\n\n return allLabelText;\n};\n\nexport const renderLabel = (label: React.ReactNode, inputId: string, mode: FormMode): React.ReactNode => {\n return (\n <>\n {label && isComponent<LabelProps>(label, Label)\n ? React.cloneElement(label, {\n htmlFor: inputId,\n mode: mode,\n })\n : typeof label === 'string' && <Label labelTexts={[{ text: label, type: 'semibold' }]} htmlFor={inputId} mode={mode} />}\n </>\n );\n};\n\nexport const renderLabelAsParent = (\n label: React.ReactNode,\n children: React.ReactNode,\n inputId: string,\n mode: FormMode,\n labelClassName?: string,\n labelTextClassName?: string,\n sublabelWrapperClassName?: string,\n large?: boolean\n): React.ReactNode => {\n return (\n <>\n {label && isComponent<LabelProps>(label, Label)\n ? React.cloneElement(label, {\n htmlFor: inputId,\n mode: mode,\n children: children,\n labelClassName: cn(labelClassName, label.props.labelClassName),\n labelTextClassName: labelTextClassName,\n sublabelWrapperClassName: sublabelWrapperClassName,\n sublabel: large ? undefined : label.props.sublabel,\n statusDot: large ? undefined : label.props.statusDot,\n })\n : typeof label === 'string' && (\n <Label\n labelTexts={[{ text: label }]}\n htmlFor={inputId}\n mode={mode}\n labelClassName={labelClassName}\n labelTextClassName={labelTextClassName}\n sublabelWrapperClassName={sublabelWrapperClassName}\n >\n {children}\n </Label>\n )}\n </>\n );\n};\n\nconst Label: FunctionComponent<LabelProps> = ({\n afterLabelChildren,\n children,\n className,\n htmlFor,\n labelClassName,\n labelTextClassName,\n labelId,\n labelTexts,\n mode = FormMode.onwhite,\n statusDot,\n sublabel,\n sublabelWrapperClassName,\n testId,\n}) => {\n const hasChildren = children && typeof children !== 'undefined';\n const labelWrapperClasses = cn(\n styles['label-wrapper'],\n { [styles['label-wrapper--no-bottom-margin']]: hasChildren, [styles['label-wrapper--after-label-children']]: afterLabelChildren },\n className\n );\n\n const mapLabels = (): React.ReactNode => {\n return labelTexts.map((labelText, index) => {\n const labelClasses = cn(\n styles.label,\n {\n [styles['label--semibold']]: labelText.type === 'semibold',\n [styles['label--on-dark']]: mode === FormMode.ondark,\n },\n labelTextClassName\n );\n return (\n <span aria-hidden={labelText.hideFromScreenReader} className={labelClasses} key={index}>\n {labelText.text}\n </span>\n );\n });\n };\n\n return (\n <div className={labelWrapperClasses}>\n <div>\n <label className={labelClassName} id={labelId} htmlFor={htmlFor} data-testid={testId} data-analyticsid={AnalyticsId.Label}>\n <span className={styles['label-content-wrapper']}>\n {children}\n <span className={styles.label__texts}>{mapLabels()}</span>\n </span>\n </label>\n <div className={sublabelWrapperClassName}>\n {sublabel &&\n isComponent<SublabelProps>(sublabel, Sublabel) &&\n React.cloneElement(sublabel, {\n mode: mode as FormMode,\n })}\n {statusDot && isComponent<StatusDotProps>(statusDot, StatusDot) && (\n <>\n <Spacer size={'3xs'} />\n {React.cloneElement(statusDot, {\n mode: mode === FormMode.ondark ? 'ondark' : 'onwhite',\n })}\n </>\n )}\n </div>\n </div>\n {afterLabelChildren && <div className={styles['after-label-children']}>{afterLabelChildren}</div>}\n </div>\n );\n};\n\nexport default Label;\n"],"names":["Sublabel","className","id","mode","sublabelTexts","testId","mapSublabels","hideFromScreenReader","sublabelText","index","labelClasses","cn","styles","FormMode","jsx","subLabels","ariaHiddenSublabels","jsxs","Fragment","Spacer","AnalyticsId","getLabelText","label","allLabelText","isComponent","Label","labelText","renderLabel","inputId","React","renderLabelAsParent","children","labelClassName","labelTextClassName","sublabelWrapperClassName","large","afterLabelChildren","htmlFor","labelId","labelTexts","statusDot","sublabel","hasChildren","labelWrapperClasses","mapLabels","StatusDot"],"mappings":";;;;;;;;AAuBa,MAAAA,IAAoC,CAAC,EAAE,WAAAC,GAAW,IAAAC,GAAI,MAAAC,GAAM,eAAAC,GAAe,QAAAC,QAAa;AAC7F,QAAAC,IAAe,CAACC,MAElBH,KACAA,EAAc,IAAI,CAACI,GAAcC,MAAU;AACzC,UAAMC,IAAeC,EAAGC,EAAO,OAAOA,EAAO,iBAAiB,GAAG;AAAA,MAC/D,CAACA,EAAO,iBAAiB,CAAC,GAAGJ,EAAa,SAAS;AAAA,MACnD,CAACI,EAAO,gBAAgB,CAAC,GAAGT,MAASU,EAAS;AAAA,IAAA,CAC/C;AAEC,WAAAN,MAAyBC,EAAa,wBACpC,gBAAAM,EAAC,UAAK,WAAWJ,GACd,UAAaF,EAAA,KAAA,GADoBC,CAEpC;AAAA,EAAA,CAGL,GAICM,IAAYT,KACZU,IAAsBV,EAAa,EAAI;AAE7C,SAEI,gBAAAW,EAAAC,GAAA,EAAA,UAAA;AAAA,IAAC,gBAAAJ,EAAAK,GAAA,EAAO,MAAM,MAAO,CAAA;AAAA,IACpBJ,KACE,gBAAAD,EAAA,OAAA,EAAI,WAAAb,GAAsB,IAAAC,GAAQ,eAAaG,GAAQ,oBAAkBe,EAAY,UACnF,UACHL,EAAA,CAAA;AAAA,IAEDC,KACE,gBAAAF,EAAA,OAAA,EAAI,WAAAb,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EAAO,cAAe,eAAY;AAAA,MAAA,EAAA,CACrD,EACF,CAAA;AAAA,MACA,gBAAAK,EAAC,OAAI,EAAA,WAAWiB,GACb,UAAA;AAAA,QAAAO,KACCjB,EAA2BiB,GAAUzC,CAAQ,KAC7C6B,EAAM,aAAaY,GAAU;AAAA,UAC3B,MAAAtC;AAAA,QAAA,CACD;AAAA,QACFqC,KAAahB,EAA4BgB,GAAWK,CAAS,KAE1D,gBAAA5B,EAAAC,GAAA,EAAA,UAAA;AAAA,UAAC,gBAAAJ,EAAAK,GAAA,EAAO,MAAM,MAAO,CAAA;AAAA,UACpBU,EAAM,aAAaW,GAAW;AAAA,YAC7B,MAAMrC,MAASU,EAAS,SAAS,WAAW;AAAA,UAAA,CAC7C;AAAA,QAAA,GACH;AAAA,MAAA,GAEJ;AAAA,IAAA,GACF;AAAA,IACCuB,KAAuB,gBAAAtB,EAAA,OAAA,EAAI,WAAWF,EAAO,sBAAsB,GAAI,UAAmBwB,GAAA;AAAA,EAC7F,EAAA,CAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"Label.js","sources":["../src/components/Label/SubLabel.tsx","../src/components/Label/Label.tsx"],"sourcesContent":["import React from 'react';\n\nimport cn from 'classnames';\n\nimport { LabelText } from './Label';\nimport { AnalyticsId, FormOnColor } from '../../constants';\nimport Spacer from '../Spacer';\n\nimport styles from './styles.module.scss';\n\nexport interface SublabelProps {\n /** Adds custom classes to the element. */\n className?: string;\n /** id that is placed on the wrapper */\n id: string;\n /** Array of sublabel strings. Can be of type semibold or normal */\n onColor?: FormOnColor;\n /** Array of sublabel strings. Can be of type semibold or normal */\n sublabelTexts?: LabelText[];\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nexport const Sublabel: React.FC<SublabelProps> = ({ className, id, onColor, sublabelTexts, testId }) => {\n const mapSublabels = (hideFromScreenReader?: boolean): React.ReactNode => {\n return (\n sublabelTexts &&\n sublabelTexts.map((sublabelText, index) => {\n const labelClasses = cn(styles.label, styles['label--sublabel'], {\n [styles['label--semibold']]: sublabelText.type === 'semibold',\n [styles['label--on-dark']]: onColor === FormOnColor.ondark,\n });\n return (\n hideFromScreenReader === sublabelText.hideFromScreenReader && (\n <span className={labelClasses} key={index}>\n {sublabelText.text}\n </span>\n )\n );\n })\n );\n };\n\n const subLabels = mapSublabels();\n const ariaHiddenSublabels = mapSublabels(true);\n\n return (\n <>\n <Spacer size={'3xs'} />\n {subLabels && (\n <div className={className} id={id} data-testid={testId} data-analyticsid={AnalyticsId.Sublabel}>\n {subLabels}\n </div>\n )}\n {ariaHiddenSublabels && (\n <div className={className} data-testid={testId}>\n {ariaHiddenSublabels}\n </div>\n )}\n </>\n );\n};\n","import React, { FunctionComponent } from 'react';\n\nimport cn from 'classnames';\n\nimport { Sublabel, SublabelProps } from './SubLabel';\nimport { AnalyticsId, FormOnColor } from '../../constants';\nimport { isComponent } from '../../utils/component';\nimport Spacer from '../Spacer';\nimport StatusDot, { StatusDotProps } from '../StatusDot';\n\nimport styles from './styles.module.scss';\n\nexport type LabelText = {\n hideFromScreenReader?: boolean;\n text: string;\n type?: 'semibold' | 'normal';\n};\n\nexport interface LabelProps {\n /** Component shown after label - discourage use of this */\n afterLabelChildren?: React.ReactNode;\n /** Adds custom classes to the element. */\n children?: React.ReactNode;\n /** Adds custom classes to the label tag. */\n labelClassName?: string;\n /** Adds custom classes to the label text. */\n labelTextClassName?: string;\n /** Adds custom classes to the element. */\n className?: string;\n /** Id that is put on the \"for\" attribute of the label */\n htmlFor?: string;\n /** Id som plasseres på <label/> */\n labelId?: string;\n /** Array of main label strings. Can be of type semibold or normal */\n labelTexts: LabelText[];\n /** Array of sublabel strings. Can be of type semibold or normal */\n onColor?: keyof typeof FormOnColor;\n /** StatusDot placed underneath the last sublabel */\n statusDot?: React.ReactNode;\n /** Sublabel component */\n sublabel?: React.ReactNode;\n /** Adds custom classes to the div wrapping the sublabels. */\n sublabelWrapperClassName?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nexport const getLabelText = (label: React.ReactNode): string => {\n let allLabelText = '';\n\n if (isComponent<LabelProps>(label, Label)) {\n label.props.labelTexts.forEach(labelText => {\n allLabelText += !labelText.hideFromScreenReader ? labelText.text : '';\n });\n }\n\n return allLabelText;\n};\n\nexport const renderLabel = (label: React.ReactNode, inputId: string, onColor: FormOnColor): React.ReactNode => {\n return (\n <>\n {label && isComponent<LabelProps>(label, Label)\n ? React.cloneElement(label, {\n htmlFor: inputId,\n onColor,\n })\n : typeof label === 'string' && <Label labelTexts={[{ text: label, type: 'semibold' }]} htmlFor={inputId} onColor={onColor} />}\n </>\n );\n};\n\nexport const renderLabelAsParent = (\n label: React.ReactNode,\n children: React.ReactNode,\n inputId: string,\n onColor: FormOnColor,\n labelClassName?: string,\n labelTextClassName?: string,\n sublabelWrapperClassName?: string,\n large?: boolean\n): React.ReactNode => {\n return (\n <>\n {label && isComponent<LabelProps>(label, Label)\n ? React.cloneElement(label, {\n htmlFor: inputId,\n onColor,\n children: children,\n labelClassName: cn(labelClassName, label.props.labelClassName),\n labelTextClassName: labelTextClassName,\n sublabelWrapperClassName: sublabelWrapperClassName,\n sublabel: large ? undefined : label.props.sublabel,\n statusDot: large ? undefined : label.props.statusDot,\n })\n : typeof label === 'string' && (\n <Label\n labelTexts={[{ text: label }]}\n htmlFor={inputId}\n onColor={onColor}\n labelClassName={labelClassName}\n labelTextClassName={labelTextClassName}\n sublabelWrapperClassName={sublabelWrapperClassName}\n >\n {children}\n </Label>\n )}\n </>\n );\n};\n\nconst Label: FunctionComponent<LabelProps> = ({\n afterLabelChildren,\n children,\n className,\n htmlFor,\n labelClassName,\n labelTextClassName,\n labelId,\n labelTexts,\n onColor = FormOnColor.onwhite,\n statusDot,\n sublabel,\n sublabelWrapperClassName,\n testId,\n}) => {\n const hasChildren = children && typeof children !== 'undefined';\n const labelWrapperClasses = cn(\n styles['label-wrapper'],\n { [styles['label-wrapper--no-bottom-margin']]: hasChildren, [styles['label-wrapper--after-label-children']]: afterLabelChildren },\n className\n );\n\n const mapLabels = (): React.ReactNode => {\n return labelTexts.map((labelText, index) => {\n const labelClasses = cn(\n styles.label,\n {\n [styles['label--semibold']]: labelText.type === 'semibold',\n [styles['label--on-dark']]: onColor === FormOnColor.ondark,\n },\n labelTextClassName\n );\n return (\n <span aria-hidden={labelText.hideFromScreenReader} className={labelClasses} key={index}>\n {labelText.text}\n </span>\n );\n });\n };\n\n return (\n <div className={labelWrapperClasses}>\n <div>\n <label className={labelClassName} id={labelId} htmlFor={htmlFor} data-testid={testId} data-analyticsid={AnalyticsId.Label}>\n <span className={styles['label-content-wrapper']}>\n {children}\n <span className={styles.label__texts}>{mapLabels()}</span>\n </span>\n </label>\n <div className={sublabelWrapperClassName}>\n {sublabel &&\n isComponent<SublabelProps>(sublabel, Sublabel) &&\n React.cloneElement(sublabel, {\n onColor: onColor as FormOnColor,\n })}\n {statusDot && isComponent<StatusDotProps>(statusDot, StatusDot) && (\n <>\n <Spacer size={'3xs'} />\n {React.cloneElement(statusDot, {\n onColor: onColor === FormOnColor.ondark ? 'ondark' : 'onwhite',\n })}\n </>\n )}\n </div>\n </div>\n {afterLabelChildren && <div className={styles['after-label-children']}>{afterLabelChildren}</div>}\n </div>\n );\n};\n\nexport default Label;\n"],"names":["Sublabel","className","id","onColor","sublabelTexts","testId","mapSublabels","hideFromScreenReader","sublabelText","index","labelClasses","cn","styles","FormOnColor","jsx","subLabels","ariaHiddenSublabels","jsxs","Fragment","Spacer","AnalyticsId","getLabelText","label","allLabelText","isComponent","Label","labelText","renderLabel","inputId","React","renderLabelAsParent","children","labelClassName","labelTextClassName","sublabelWrapperClassName","large","afterLabelChildren","htmlFor","labelId","labelTexts","statusDot","sublabel","hasChildren","labelWrapperClasses","mapLabels","StatusDot"],"mappings":";;;;;;;;AAuBa,MAAAA,IAAoC,CAAC,EAAE,WAAAC,GAAW,IAAAC,GAAI,SAAAC,GAAS,eAAAC,GAAe,QAAAC,QAAa;AAChG,QAAAC,IAAe,CAACC,MAEl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tB,EAAA,OAAA,EAAI,WAAWF,EAAO,sBAAsB,GAAI,UAAmBwB,GAAA;AAAA,EAC7F,EAAA,CAAA;AAEJ;"}
|
package/MaxCharacters.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as n } from "react/jsx-runtime";
|
|
2
2
|
import l from "classnames";
|
|
3
|
-
import {
|
|
3
|
+
import { FormOnColor as p } from "./constants.js";
|
|
4
4
|
import r from "./components/MaxCharacters/styles.module.scss";
|
|
5
|
-
const h = ({ maxCharacters: a, maxText: o, length: s,
|
|
5
|
+
const h = ({ maxCharacters: a, maxText: o, length: s, onColor: e, maxWidth: c }) => {
|
|
6
6
|
const t = s / a, i = l(r["max-characters"], {
|
|
7
7
|
[r["max-characters--on-dark"]]: e === p.ondark,
|
|
8
8
|
[r["max-characters--invalid"]]: t > 1
|
package/MaxCharacters.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MaxCharacters.js","sources":["../src/components/MaxCharacters/MaxCharacters.tsx"],"sourcesContent":["import React from 'react';\n\nimport classNames from 'classnames';\n\nimport {
|
|
1
|
+
{"version":3,"file":"MaxCharacters.js","sources":["../src/components/MaxCharacters/MaxCharacters.tsx"],"sourcesContent":["import React from 'react';\n\nimport classNames from 'classnames';\n\nimport { FormOnColor } from '../../constants';\n\nimport styles from './styles.module.scss';\n\ninterface MaxCharactersProps {\n /** Current input length */\n length: number;\n /** max character limit in textarea */\n maxCharacters: number;\n /** The text is displayed in the end of the text-counter */\n maxText?: string;\n /** Changes the visuals of the textarea */\n onColor?: keyof typeof FormOnColor;\n /** Max width of the component */\n maxWidth?: string;\n}\n\nconst MaxCharacters: React.FC<MaxCharactersProps> = ({ maxCharacters, maxText, length, onColor, maxWidth }) => {\n const progress = length / maxCharacters;\n\n const counterTextClass = classNames(styles['max-characters'], {\n [styles[`max-characters--on-dark`]]: onColor === FormOnColor.ondark,\n [styles[`max-characters--invalid`]]: progress > 1,\n });\n\n const ariaLevel = progress > 0.95 ? 'polite' : 'off';\n\n return (\n <div aria-live={ariaLevel} aria-atomic={'true'} className={counterTextClass} style={{ maxWidth }}>\n {`${length}/${maxCharacters} ${maxText ? maxText : 'tegn'}`}\n </div>\n );\n};\n\nexport default MaxCharacters;\n"],"names":["MaxCharacters","maxCharacters","maxText","length","onColor","maxWidth","progress","counterTextClass","classNames","styles","FormOnColor","ariaLevel","jsx"],"mappings":";;;;AAqBM,MAAAA,IAA8C,CAAC,EAAE,eAAAC,GAAe,SAAAC,GAAS,QAAAC,GAAQ,SAAAC,GAAS,UAAAC,QAAe;AAC7G,QAAMC,IAAWH,IAASF,GAEpBM,IAAmBC,EAAWC,EAAO,gBAAgB,GAAG;AAAA,IAC5D,CAACA,EAAO,yBAAyB,CAAC,GAAGL,MAAYM,EAAY;AAAA,IAC7D,CAACD,EAAO,yBAAyB,CAAC,GAAGH,IAAW;AAAA,EAAA,CACjD,GAEKK,IAAYL,IAAW,OAAO,WAAW;AAG7C,SAAA,gBAAAM,EAAC,SAAI,aAAWD,GAAW,eAAa,QAAQ,WAAWJ,GAAkB,OAAO,EAAE,UAAAF,KACnF,UAAA,GAAGF,CAAM,IAAIF,CAAa,IAAIC,KAAoB,MAAM,GAC3D,CAAA;AAEJ;"}
|